1184 lines
61 KiB
PHP
1184 lines
61 KiB
PHP
<?php
|
||
|
||
namespace App\Http\Controllers\Server\Admin;
|
||
|
||
use App\Models\Circle;
|
||
use App\Models\CircleJoinUser;
|
||
use App\Models\CircleUser;
|
||
use App\Models\CircleWechat;
|
||
use App\Models\MerchantAccount;
|
||
use App\Models\ProfileCourtship;
|
||
use App\Models\RequestContactRecode;
|
||
use App\Models\User;
|
||
use App\Models\Wechat;
|
||
use EasyWeChat\Factory;
|
||
use Illuminate\Http\JsonResponse;
|
||
use Illuminate\Http\Request;
|
||
use App\Http\Controllers\Controller;
|
||
use Illuminate\Support\Facades\DB;
|
||
use Illuminate\Support\Facades\Redis;
|
||
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
||
|
||
|
||
class CircleController extends Controller
|
||
{
|
||
|
||
/**
|
||
* 创建更新圈子
|
||
*/
|
||
public function createCircle(Request $request) {
|
||
try {
|
||
$name = $request->name;
|
||
$title = $request->title;
|
||
$pic = $request->pic;
|
||
$circle_id = $request->circle_id;
|
||
if (config('app.debug')) {
|
||
if (!$name || !$title) {
|
||
return $this->failure('参数不全');
|
||
}
|
||
}
|
||
if(!$request->account_id){
|
||
return $this->failure('商家信息不存在');
|
||
}
|
||
if ($circle_id) {
|
||
$circle = Circle::where('id', $circle_id)->where('merchant_id', $request->account_id)->where('id',$circle_id)
|
||
->update(['name' => $name, 'title' => $title, 'pic' => $pic,
|
||
'real_name_type'=>$request->real_name_type,
|
||
'real_people_type'=>$request->real_people_type,
|
||
'contact_type'=>$request->contact_type,
|
||
'reward_type'=>$request->reward_type,
|
||
'audit_type'=>$request->audit_type,
|
||
'sex_type'=>$request->sex_type,
|
||
'birthday_type'=>$request->birthday_type,
|
||
'belief_type'=>$request->belief_type,
|
||
'income_type'=>$request->income_type,
|
||
'industry_type'=>$request->industry_type,
|
||
'degree_type'=>$request->degree_type,
|
||
'graduate_school_type'=>$request->graduate_school_type,
|
||
'h_car_type'=>$request->circle_location == 1 ?$request->h_car_type:0,
|
||
'h_housing_type'=>$request->circle_location == 1 ?$request->h_housing_type:0,
|
||
'birthday_required_type'=>$request->birthday_required_type,
|
||
'property_required_type'=>$request->circle_location == 1 ?$request->property_required_type:0,
|
||
'degree_required_type'=>$request->degree_required_type,
|
||
'wechat_type'=>$request->circle_location == 1 ?$request->wechat_type:0,
|
||
'mobile_type'=>$request->circle_location == 1 ?$request->mobile_type:0,
|
||
'qq_type'=>$request->circle_location == 1 ?$request->qq_type:0,
|
||
'other_contact'=>$request->circle_location == 1 ?$request->other_contact:0,
|
||
'affective_state_type'=>$request->affective_state_type,
|
||
'belief_required_type'=>$request->belief_required_type,
|
||
'nickname_type'=>$request->nickname_type,
|
||
'affective_state_required_type'=>$request->affective_state_required_type,
|
||
'address_type'=>$request->address_type,
|
||
'user_list_type'=> $request->user_list_type,
|
||
]);
|
||
} else {
|
||
$open_id = null;
|
||
$circle = Circle::where('merchant_id', $request->account_id)->Create([
|
||
'merchant_id'=>$request->account_id,
|
||
'name' => $name,'pic' => $pic, 'title' => $title,
|
||
'real_name_type'=>$request->real_name_type,
|
||
'real_people_type'=>$request->real_people_type,
|
||
'contact_type'=>$request->contact_type,
|
||
'reward_type'=>$request->reward_type,
|
||
'audit_type'=>$request->audit_type,
|
||
'sex_type'=>$request->sex_type,
|
||
'birthday_type'=>$request->birthday_type,
|
||
'belief_type'=>$request->belief_type,
|
||
'income_type'=>$request->income_type,
|
||
'industry_type'=>$request->industry_type,
|
||
'degree_type'=>$request->degree_type,
|
||
'graduate_school_type'=>$request->graduate_school_type,
|
||
'h_car_type'=>$request->circle_location == 1 ?$request->h_car_type:0,
|
||
'h_housing_type'=>$request->circle_location == 1 ?$request->h_housing_type:0,
|
||
'birthday_required_type'=>$request->birthday_required_type,
|
||
'property_required_type'=>$request->circle_location == 1 ?$request->property_required_type:0,
|
||
'degree_required_type'=>$request->degree_required_type,
|
||
'wechat_type'=>$request->circle_location == 1 ?$request->wechat_type:0,
|
||
'mobile_type'=>$request->circle_location == 1 ?$request->mobile_type:0,
|
||
'qq_type'=>$request->circle_location == 1 ?$request->qq_type:0,
|
||
'other_contact'=>$request->circle_location == 1 ?$request->other_contact:0,
|
||
'affective_state_type'=>$request->affective_state_type,
|
||
'belief_required_type'=>$request->belief_required_type,
|
||
'nickname_type'=>$request->nickname_type,
|
||
'affective_state_required_type'=>$request->affective_state_required_type,
|
||
'address_type'=>$request->address_type,
|
||
'user_list_type'=>$request->user_list_type,
|
||
'circle_location' => $request->circle_location,
|
||
]);
|
||
$app_id = 'wxa13c904615976bb4';
|
||
$secret = '0f269652df4dcd22d9f0bcdd72a18496';
|
||
$config = [
|
||
'app_id' => $app_id,
|
||
'secret' => $secret,
|
||
// 下面为可选项
|
||
// 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
|
||
'response_type' => 'array',
|
||
'log' => [
|
||
'level' => 'debug',
|
||
'file' => storage_path('logs/wechat.log'), //这个必须要有,要不调试有问题,你都会找不到原因
|
||
],
|
||
];
|
||
$circle_id = $circle->id;
|
||
$path = time() . rand(11111, 99999) . 'group_qrocde.png';
|
||
$qrcode_path = storage_path("qrcode/" . $path);
|
||
if($request->circle_location == 1) {
|
||
$app = Factory::miniProgram($config);
|
||
$data = [];
|
||
$data['is_hyaline'] = true;
|
||
$data['env_version'] = 'release';
|
||
$response = $app->app_code->get('/pages/tabBar/welcome?circle_id=' . $circle_id .
|
||
'&merchant_id=' . $request->account_id, $data);
|
||
$response->saveAs(storage_path('qrcode'), $path);
|
||
}else if($request->circle_location == 2){
|
||
$url = 'https://date.fulllinkai.com/h5/#/invitationJoIn?circle_id='.$circle_id;
|
||
//二维码图片
|
||
QrCode::format('png')->margin(1)->size(600)->generate($url,$qrcode_path);
|
||
}
|
||
$path = date('Y') . date('m') . "/" . date('d');
|
||
$rand = \CommonUtilsService::getTradeNO();
|
||
$object = $path . "/" . $rand . '.png';
|
||
$ossClient = new \OSS\OssClient(config('alioss.id'), config('alioss.secret'), config('alioss.host'));
|
||
$ossClient->uploadFile(config('alioss.buckets.picture'), $object, $qrcode_path);
|
||
$file_url = 'https://' . config('alioss.picture_domain') . '/' . $object;
|
||
if ($file_url) {
|
||
$circle->qr_code = $file_url;
|
||
$circle->save();
|
||
}
|
||
try {
|
||
unlink($qrcode_path);
|
||
} catch (\Exception $e) {
|
||
return $this->failure($e->getMessage());
|
||
}
|
||
|
||
}
|
||
return $this->success('ok', $circle);
|
||
}catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 用户列表
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function getCircleUserList(Request $request){
|
||
try {
|
||
$audit_status = $request->audit_status;
|
||
$circle_id = $request->circle_id;
|
||
$keyword = $request->keyword;
|
||
$nopage = $request->nopage;
|
||
$circle = Circle::find($circle_id);
|
||
if($circle->circle_location == 1) {
|
||
$user = CircleJoinUser::where('circle_id', $circle_id)->with(['love_user:id,photo,sex,name,nickname,industry,is_approved,is_real_approved,is_educate_approved,card_num,mobile,industry_sub',
|
||
'love_user_profile:user_id,birthday,belief,income,degree,other_contact,wechat_id,graduate_school,h_car,province,city,h_housing,wechat_id,qq,stature'])
|
||
->with('circle_user:id,affective_state,mate_condition')
|
||
->when(isset($audit_status), function ($query) use ($audit_status) {
|
||
$query->where('audit_status', $audit_status);
|
||
});
|
||
if ($keyword) {
|
||
$user = $user->whereHas('love_user', function ($query) use ($keyword) {
|
||
$query->where('name', 'like', "%$keyword%")
|
||
->orWhere('nickname', 'like', "%$keyword%")
|
||
->orWhere('mobile', 'like', "%$keyword%");
|
||
});
|
||
}
|
||
if ($nopage) {
|
||
$user = $user->orderBy('id', 'desc')->get();
|
||
} else {
|
||
$user = $user->orderBy('id', 'desc')->paginate();
|
||
}
|
||
}else{
|
||
$user = CircleJoinUser::where('circle_id', $circle_id)
|
||
->with('user_info')
|
||
->when(isset($audit_status), function ($query) use ($audit_status) {
|
||
$query->where('audit_status', $audit_status);
|
||
});
|
||
if ($keyword) {
|
||
$user = $user->whereHas('user_info', function ($query) use ($keyword) {
|
||
$query->where('nickname', 'like', "%$keyword%");
|
||
});
|
||
}
|
||
if ($nopage) {
|
||
$user = $user->orderBy('id', 'desc')->get();
|
||
} else {
|
||
$user = $user->orderBy('id', 'desc')->paginate();
|
||
}
|
||
}
|
||
return $this->success('ok', $user);
|
||
}catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 用户详情
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function getCircleUserDetails(Request $request){
|
||
try {
|
||
$user_id = $request->user_id;
|
||
$circle_id = $request->circle_id;
|
||
$circle = Circle::find($circle_id);
|
||
if($circle){
|
||
if($circle->circle_location == 1){
|
||
$user = CircleJoinUser::where('circle_id', $circle_id) ->with(['love_user:id,photo,sex,name,nickname,industry,is_approved,is_real_approved,is_educate_approved,card_num,mobile,industry_sub',
|
||
'love_user_profile:user_id,birthday,belief,income,degree,other_contact,wechat_id,graduate_school,h_car,province,city,h_housing,wechat_id,qq,stature'])
|
||
->with('circle_user:id,affective_state,mate_condition')
|
||
->with('circle')
|
||
->where('user_id',$user_id)
|
||
->first();
|
||
}else{
|
||
$user = CircleJoinUser::where('circle_id', $circle_id)
|
||
->with('user_info')
|
||
->with('circle_user:id,affective_state,mate_condition')
|
||
->with('circle')
|
||
->where('user_id',$user_id)
|
||
->first();
|
||
}
|
||
}else{
|
||
return $this->failure('圈子不存在');
|
||
}
|
||
|
||
return $this->success('ok', $user);
|
||
}catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 圈子列表
|
||
* @param Request $request
|
||
* @return JsonResponse|string
|
||
*/
|
||
public function getCircleList(Request $request){
|
||
try {
|
||
$keyword = $request->keyword;
|
||
$nopage = $request->nopage;
|
||
$user = Circle::where('merchant_id', $request->account_id)
|
||
->when($keyword, function ($query) use ($keyword) {
|
||
$query->where('name', 'like', "%$keyword%");
|
||
});
|
||
if ($nopage) {
|
||
$user = $user->orderBy('id', 'desc')->get();
|
||
} else {
|
||
$user = $user->orderBy('id', 'desc')->paginate();
|
||
}
|
||
return $this->success('ok', $user);
|
||
}catch (\Exception $e) {
|
||
$this->getError($e);
|
||
return $this->failure('服务器休息中,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取圈子信息
|
||
*/
|
||
public function getCircleDetails(Request $request){
|
||
$circle_id = $request->circle_id;
|
||
$info = Circle::where('id',$circle_id)->where('merchant_id',$request->account_id)
|
||
->first();
|
||
return $this->success('ok',$info);
|
||
}
|
||
|
||
/**
|
||
* 圈子用户审核
|
||
*/
|
||
public function circleUserAudit(Request $request){
|
||
$circle_id = $request->circle_id;
|
||
$user_id = $request->user_id;
|
||
$audit_status = $request->audit_status;
|
||
$circle = Circle::where('merchant_id',$request->account_id)->where('id',$circle_id)->first();
|
||
if(!$circle){
|
||
return $this->failure('圈子不存在');
|
||
}
|
||
$CircleJoinUser = CircleJoinUser::where('circle_id',$circle->id)->where('user_id',$user_id)
|
||
->first();
|
||
if($CircleJoinUser){
|
||
$CircleJoinUser->audit_status = $audit_status;
|
||
$CircleJoinUser->save();
|
||
$data['type'] = 'audit_notification';
|
||
$data['type_id'] = $CircleJoinUser->id;
|
||
$data['status'] = $audit_status;
|
||
try {
|
||
Redis::select(6);
|
||
Redis::lpush('fuyin_universal_notification', json_encode($data));
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
}
|
||
}
|
||
return $this->success('ok');
|
||
}
|
||
|
||
/**
|
||
* 删除圈子
|
||
*/
|
||
public function deleteCircle(Request $request){
|
||
$circle_id = $request->circle_id;
|
||
Circle::where('merchant_id',$request->account_id)->where('id',$circle_id)->delete();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
/**
|
||
* 删除用户
|
||
*/
|
||
public function deleteUser(Request $request){
|
||
$circle_id = $request->circle_id;
|
||
$user_id = $request->user_id;
|
||
CircleJoinUser::where('merchant_id',$request->account_id)->where('circle_id',$circle_id)
|
||
->where('user_id',$user_id)
|
||
->delete();
|
||
return $this->success('ok');
|
||
}
|
||
|
||
/**
|
||
* 申请地址列表
|
||
*/
|
||
public function getRequestContactList(Request $request){
|
||
$circle_id = $request->circle_id;
|
||
$circle = Circle::where('merchant_id',$request->account_id)->where('id',$circle_id)->first();
|
||
if(!$circle){
|
||
return $this->failure('圈子不存在');
|
||
}
|
||
$circle = Circle::find($circle_id);
|
||
if($circle->circle_location == 1){
|
||
$list = RequestContactRecode::where('circle_id',$circle_id)
|
||
->where('user_type','wechat')
|
||
->with('source_user.love_user:id,name,circle_avatar,mobile,sex')
|
||
->whereHas('source_user.love_user_profile')
|
||
->whereHas('target_user.love_user_profile')
|
||
->with('source_user.love_user_profile:user_id,other_contact,wechat_id,qq')
|
||
->with('target_user.love_user:id,name,circle_avatar,mobile,sex')
|
||
->with('target_user.love_user_profile:user_id,other_contact,wechat_id,qq')
|
||
->select('id','target_user_id','source_user_id','created_at')
|
||
->paginate();
|
||
}else{
|
||
$list = RequestContactRecode::where('circle_id',$circle_id)
|
||
->where('user_type','email')
|
||
->with(['source_email_user','target_email_user',])
|
||
->select('id','target_user_id','source_user_id','created_at')
|
||
->paginate();
|
||
}
|
||
|
||
return $this->success('ok',$list);
|
||
}
|
||
|
||
/**
|
||
* 申请用户匹配
|
||
*/
|
||
public function getRequestContactUserMatch(Request $request){
|
||
$circle_id = $request->circle_id;
|
||
$source_user_id = $request->source_user_id;
|
||
$target_user_id = $request->target_user_id;
|
||
$circle = Circle::where('merchant_id',$request->account_id)->where('id',$circle_id)->first();
|
||
if(!$circle){
|
||
return $this->failure('圈子不存在');
|
||
}
|
||
$source_user = CircleUser::where('id', $source_user_id)
|
||
->whereHas('love_user_profile')
|
||
->with('love_user:id,photo,sex,nickname,industry,is_real_approved,is_educate_approved,industry_sub,mobile')
|
||
->with('love_user_profile:user_id,birthday,belief,income,qq,degree,province,city,stature,wechat_id,qq,other_contact,graduate_school,stature,resident_province,resident_city,h_car,h_housing')
|
||
->first();
|
||
$target_user = CircleUser::where('id', $target_user_id)
|
||
->whereHas('love_user_profile')
|
||
->with('love_user:id,photo,sex,nickname,industry,is_real_approved,is_educate_approved,industry_sub,mobile')
|
||
->with('love_user_profile:user_id,birthday,belief,income,qq,degree,province,city,stature,wechat_id,qq,other_contact,graduate_school,stature,resident_province,resident_city,h_car,h_housing')
|
||
->first();
|
||
if(!$source_user || !$target_user){
|
||
return $this->failure('用户资料不全');
|
||
}
|
||
$source_user->match = $this->diff($source_user,$target_user,$circle);
|
||
$target_user->match = $this->diff($target_user,$source_user,$circle);
|
||
if (!empty($source_user->love_user_profile)) {
|
||
if (!empty($source_user->love_user_profile->birthday)) {
|
||
$year = date('y', strtotime($source_user->love_user_profile->birthday));
|
||
$source_user->love_user_profile->year = $year;
|
||
} else {
|
||
$source_user->love_user_profile->year = null;
|
||
}
|
||
}
|
||
if (!empty($target_user->love_user_profile)) {
|
||
if (!empty($target_user->love_user_profile->birthday)) {
|
||
$year = date('y', strtotime($target_user->love_user_profile->birthday));
|
||
$target_user->love_user_profile->year = $year;
|
||
} else {
|
||
$target_user->love_user_profile->year = null;
|
||
}
|
||
}
|
||
return $this->success('ok',compact('source_user','target_user'));
|
||
}
|
||
|
||
/**
|
||
* 单个用户匹配
|
||
* @param Request $request
|
||
* @return JsonResponse
|
||
*/
|
||
public function singleUserMatch(Request $request){
|
||
$user_id = $request->user_id;
|
||
$circle_id = $request->circle_id;
|
||
$circle = Circle::where('merchant_id',$request->account_id)->where('id',$circle_id)->first();
|
||
if(!$circle){
|
||
return $this->failure('圈子不存在');
|
||
}
|
||
$user = CircleUser::where('id', $user_id)
|
||
->with('love_user:id,photo,sex,nickname,industry,is_real_approved,is_educate_approved,industry_sub,mobile')
|
||
->with('love_user_profile:user_id,birthday,belief,income,qq,degree,province,city,stature,wechat_id,qq,other_contact,graduate_school,stature,resident_province,resident_city')
|
||
->select('id','love_user_id','affective_state','mate_condition')
|
||
->first();
|
||
if($user && $user->love_user && $user->love_user->sex){
|
||
$users = CircleJoinUser::where('circle_id',$circle_id)
|
||
->where('audit_status',1)->whereHas('love_user',function ($query) use($user){
|
||
$query->where('sex','!=',$user->love_user->sex);
|
||
})
|
||
->with('love_user:id,photo,sex,nickname,industry,is_real_approved,is_educate_approved,industry_sub,mobile')
|
||
->with('circle_user:id,love_user_id,affective_state,mate_condition')
|
||
->with('love_user_profile:user_id,birthday,belief,income,qq,degree,province,city,stature,wechat_id,qq,other_contact,graduate_school,stature,resident_province,resident_city,h_car,h_housing')
|
||
->select('id','user_id','love_user_id')
|
||
->get();
|
||
$items = collect();
|
||
foreach ($users as $key => $val){
|
||
$match = $this->diff($user,$val,$circle);
|
||
$match['percentum'] = str_replace('%','',$match['percentum']);
|
||
$match['target_user_id'] = $val->user_id;
|
||
$items->push($match);
|
||
}
|
||
$items = $items->sortByDesc(function ($item) { //排序
|
||
return $item['percentum'];
|
||
})->take(15);
|
||
$items = array_values($items->toArray());
|
||
foreach ($items as $item_key => $item) {
|
||
foreach ($users as $key => $val){
|
||
if($item['target_user_id'] == $val->user_id){
|
||
$items[$item_key]['user'] = $val;
|
||
if (!empty($val->love_user_profile)) {
|
||
if (!empty($val->love_user_profile->birthday)) {
|
||
$year = date('y', strtotime($val->love_user_profile->birthday));
|
||
$val->love_user_profile->year = $year;
|
||
} else {
|
||
$val->love_user_profile->year = null;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}else{
|
||
$items = [];
|
||
}
|
||
return $this->success('ok',$items);
|
||
}
|
||
|
||
/**
|
||
* 比较两个用户的差异
|
||
* @param $require_user
|
||
* @param $source_user
|
||
* @param $circle
|
||
* @return array
|
||
*/
|
||
private function diff($require_user,$source_user,$circle){ //$require_user 提要求的用户 $source_user 比较的用户
|
||
//判断是不是必填项
|
||
if($circle->birthday_required_type == 1){
|
||
$require['birthday_required_type'] = 1;
|
||
}
|
||
if($circle->property_required_type == 1){
|
||
$require['property_required_type'] = 1;
|
||
}
|
||
if($circle->belief_required_type == 1){
|
||
$require['belief_required_type'] = 1;
|
||
}
|
||
if($circle->degree_required_type == 1){
|
||
$require['degree_required_type'] = 1;
|
||
}
|
||
if($circle->affective_state_required_type == 1){
|
||
$require['affective_state_required_type'] = 1;
|
||
}
|
||
$total = sizeof($require);
|
||
|
||
if($total == 0 ){
|
||
$match = [
|
||
'affective_state' => 1,
|
||
'belief' => 1,
|
||
'birthday' => 1,
|
||
'degree' => 1,
|
||
'property' => 1,
|
||
'percentum' => '100%',
|
||
'percent' => 100
|
||
];
|
||
return $match;
|
||
}
|
||
if(!$require_user->mate_condition){
|
||
$match = [
|
||
'affective_state' => 1,
|
||
'belief' => 1,
|
||
'birthday' => 1,
|
||
'degree' => 1,
|
||
'property' => 1,
|
||
'percentum' => '100%',
|
||
'percent' => 100
|
||
];
|
||
return $match;
|
||
}
|
||
if($require['affective_state_required_type']) {
|
||
if ($require_user->mate_condition->affective_state_required == '婚姻不限' || empty($require_user->mate_condition->affective_state_required)) {
|
||
$match['affective_state'] = 1;
|
||
} elseif ($require_user->mate_condition->affective_state_required) {
|
||
$married = [
|
||
0 => '未知', 1 =>'未婚', 2=> '离异无孩', 3=> '离异带孩' , 4=>'离异不带孩' , 5 =>'丧偶' ,
|
||
];
|
||
if($require_user->mate_condition->affective_state_required == $source_user->affective_state){
|
||
$match['affective_state'] = 1;
|
||
}else{
|
||
$match['affective_state'] = 0;
|
||
}
|
||
|
||
}
|
||
}
|
||
if($require['belief_required_type']) {
|
||
if ($require_user->mate_condition->belief_required == '信仰不限' || empty($require_user->mate_condition->belief_required)) {
|
||
$match['belief'] = 1;
|
||
} elseif ($require_user->mate_condition->belief_required == $source_user->love_user_profile->belief) {
|
||
$match['belief'] = 1;
|
||
} else {
|
||
$match['belief'] = 0;
|
||
}
|
||
}
|
||
if($require['property_required_type']) {
|
||
if ($require_user->mate_condition->property_required == '财产不限' || empty($require_user->mate_condition->property_required)) {
|
||
$match['property'] = 1;
|
||
} elseif ($require_user->mate_condition->property_required == '有房有车') {
|
||
if ($source_user->love_user_profile->h_housing == 1 && $source_user->love_user_profile->h_car == 1 ){
|
||
$match['property'] = 1;
|
||
}else{
|
||
$match['property'] = 0;
|
||
}
|
||
} elseif ($require_user->mate_condition->property_required == '有车' && $source_user->love_user_profile->h_car == 1) {
|
||
$match['property'] = 1;
|
||
} elseif ($require_user->mate_condition->property_required == '有房' && $source_user->love_user_profile->h_housing == 1) {
|
||
$match['property'] = 1;
|
||
}else{
|
||
$match['property'] = 0;
|
||
}
|
||
}
|
||
if($require['birthday_required_type']) {
|
||
if ($require_user->mate_condition->birthday_required == '年龄不限' || empty($require_user->mate_condition->birthday_required)) {
|
||
$match['birthday'] = 1;
|
||
} elseif ($require_user->mate_condition->birthday_required) {
|
||
list($min_age, $max_age) = explode('-', $require_user->mate_condition->birthday_required);
|
||
$min_age = str_replace('岁', '', $min_age);
|
||
$max_age = str_replace('岁', '', $max_age);
|
||
$min_age = (date('Y') - $min_age) . '-01-01';
|
||
$max_age = (date('Y') - $max_age) . '-01-01';
|
||
$user_time_stamp = strtotime($source_user->love_user_profile->birthday);
|
||
if($user_time_stamp <= strtotime($min_age) && $user_time_stamp >= strtotime($max_age) ){
|
||
$match['birthday'] = 1;
|
||
}else{
|
||
$match['birthday'] = 0;
|
||
}
|
||
} else {
|
||
$match['birthday'] = 0;
|
||
}
|
||
}
|
||
if($require['degree_required_type']) {
|
||
//双方学历转数字便于比较
|
||
if ($require_user->mate_condition->degree_required == '学历不限' || empty($require_user->mate_condition->degree_required)) {
|
||
$match['degree'] = 1;
|
||
} elseif ($require_user->mate_condition->degree_required == $source_user->love_user_profile->degree) {
|
||
$match['degree'] = 1;
|
||
} else {
|
||
$degree = [
|
||
'其他' => 0, '小学' => 1, '初中' => 2, '初中及初中以下' => 2, '中专' => 4, '高中' => 4,
|
||
'高中/中专' => 4, '大专' => 5, '专科' => 5, '本科' => 6, '硕士' => 7,'硕士以上' => 7, '博士' => 8,
|
||
];
|
||
if(!in_array($require_user->love_user_profile->degree,$degree)){
|
||
throw new \Exception('此学历不在数组中,学历='.$source_user->love_user_profile->degree);
|
||
}
|
||
if(!in_array($source_user->love_user_profile->degree,$degree)){
|
||
throw new \Exception('此学历不在数组中,学历='.$source_user->love_user_profile->degree);
|
||
}
|
||
if(!$source_user->love_user_profile->degree || !$require_user->love_user_profile->degree){
|
||
$match['degree'] = 0;
|
||
}else{
|
||
$need = $degree[$require_user->mate_condition->degree_required];
|
||
$has = $degree[$source_user->love_user_profile->degree];
|
||
if($has >= $need ){
|
||
$match['degree'] = 1;
|
||
}else{
|
||
$match['degree'] = 0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
$a = 0;
|
||
foreach ($match as $key => $val){
|
||
if($val == 1){
|
||
$a += 1;
|
||
}
|
||
}
|
||
$match['percent'] = round($a / $total * 100,2);
|
||
$match['percentum'] = round($a / $total * 100,2).'%';
|
||
return $match;
|
||
}
|
||
|
||
/**
|
||
* 圈内用户分析
|
||
*/
|
||
public function getCircleUserAnalyse(Request $request){
|
||
try {
|
||
$circle_id = $request->circle_id;
|
||
$loveUserIds = CircleJoinUser::where('circle_id', $circle_id)->pluck('love_user_id')->toArray();
|
||
$userIds = CircleJoinUser::where('circle_id', $circle_id)->pluck('user_id')->toArray();
|
||
$total = sizeof($loveUserIds);
|
||
//性别
|
||
$sex_array_temp = User::whereIn('id', $loveUserIds)->selectRaw('sex,Count(*) as count')->whereNotNull('sex')
|
||
->groupBy("sex")->get()->toArray();
|
||
if (sizeof($sex_array_temp) == 0) {
|
||
$sex ['name'] = '男';
|
||
$sex ['value'] = 0;
|
||
$sex_array[] = $sex;
|
||
$sex ['name'] = '女';
|
||
$sex ['value'] = 0;
|
||
$sex_array[] = $sex;
|
||
} else {
|
||
foreach ($sex_array_temp as $key => $val) {
|
||
if ($val['sex'] == 1) {
|
||
$sex['name'] = '男';
|
||
$sex['value'] = $val['count'];
|
||
$sex_array[] = $sex;
|
||
$sex = [];
|
||
} elseif ($val['sex'] == 2) {
|
||
$sex['name'] = '女';
|
||
$sex['value'] = $val['count'];
|
||
$sex_array[] = $sex;
|
||
$sex = [];
|
||
} else {
|
||
$sex['name'] = '未知';
|
||
$sex['value'] = $val['count'];
|
||
$sex_array[] = $sex;
|
||
$sex = [];
|
||
}
|
||
}
|
||
}
|
||
//情感状态
|
||
$affective_state_array_temp = CircleUser::whereIn('id',$userIds)->selectRaw('affective_state,Count(*) as count')
|
||
->whereNotNull('affective_state')->groupBy("affective_state")->get()->toArray();
|
||
$affective_state_array = [];
|
||
foreach ($affective_state_array_temp as $key => $val){
|
||
if($val['affective_state'] == null){
|
||
$array_temp['name'] = '未填写';
|
||
$array_temp['value'] = $val['count'];
|
||
}else{
|
||
$array_temp['name'] = $val['affective_state'];
|
||
$array_temp['value'] = $val['count'];
|
||
}
|
||
$affective_state_array[] = $array_temp;
|
||
$array_temp = [];
|
||
}
|
||
$man_ids = User::whereIn('id', $loveUserIds)->where('sex', 1)->pluck('id');
|
||
$woman_ids = User::whereIn('id', $loveUserIds)->where('sex', 2)->pluck('id');;
|
||
|
||
$income_array_temp['5w以下'] = $income_array_temp['5~10w'] = $income_array_temp['10~15w'] = $income_array_temp['15~30w'] = $income_array_temp['30~50w'] =
|
||
$income_array_temp['50~100w'] = $income_array_temp['100~500w'] = $income_array_temp['100~500w'] = $income_array_temp['500w以上'] = 0;
|
||
|
||
//收入比例
|
||
$man_income_array_temp = ProfileCourtship::whereIn('user_id', $man_ids)->whereNotNull('income')->select('income', 'user_id')->get()->toArray();
|
||
foreach ($man_income_array_temp as $income) {
|
||
if ($income['income'] == '5w以下') {
|
||
$income_array_temp['5w以下'] = $income_array_temp['5w以下'] + 1;
|
||
$man_income_user_ids['5w以下'][] = $income['user_id'];
|
||
}
|
||
if ($income['income'] == '5~10w') {
|
||
$income_array_temp['5~10w'] = $income_array_temp['5~10w'] + 1;
|
||
$man_income_user_ids['5~10w'][] = $income['user_id'];
|
||
}
|
||
if ($income['income'] == '10~15w') {
|
||
$income_array_temp['10~15w'] = $income_array_temp['10~15w'] + 1;
|
||
$man_income_user_ids['10~15w'][] = $income['user_id'];
|
||
}
|
||
if ($income['income'] == '15~30w') {
|
||
$income_array_temp['15~30w'] = $income_array_temp['15~30w'] + 1;
|
||
$man_income_user_ids['15~30w'][] = $income['user_id'];
|
||
}
|
||
if ($income['income'] == '30~50w') {
|
||
$income_array_temp['30~50w'] = $income_array_temp['30~50w'] + 1;
|
||
$man_income_user_ids['30~50w'][] = $income['user_id'];
|
||
}
|
||
if ($income['income'] == '50~100w') {
|
||
$income_array_temp['50~100w'] = $income_array_temp['50~100w'] + 1;
|
||
$man_income_user_ids['50~100w'][] = $income['user_id'];
|
||
}
|
||
if ($income['income'] == '100~500w') {
|
||
$income_array_temp['100~500w'] = $income_array_temp['100~500w'] + 1;
|
||
$man_income_user_ids['100~500w'][] = $income['user_id'];
|
||
}
|
||
if ($income['income'] == '500w以上') {
|
||
$income_array_temp['500w以上'] = $income_array_temp['500w以上'] + 1;
|
||
$man_income_user_ids['500w以上'][] = $income['user_id'];
|
||
}
|
||
}
|
||
$man_income_array = $income_array_temp;
|
||
|
||
$woman_income_user_ids = [];
|
||
$income_array_temp['5w以下'] = $income_array_temp['5~10w'] = $income_array_temp['10~15w'] = $income_array_temp['15~30w'] = $income_array_temp['30~50w'] =
|
||
$income_array_temp['50~100w'] = $income_array_temp['100~500w'] = $income_array_temp['100~500w'] = $income_array_temp['500w以上'] = 0;
|
||
$woman_income_array_temp = ProfileCourtship::whereIn('user_id', $woman_ids)->whereNotNull('income')->select('income', 'user_id')->get()->toArray();
|
||
foreach ($woman_income_array_temp as $income) {
|
||
if ($income['income'] == '5w以下') {
|
||
$income_array_temp['5w以下'] = $income_array_temp['5w以下'] + 1;
|
||
$woman_income_user_ids['5w以下'][] = $income['user_id'];
|
||
}
|
||
if ($income['income'] == '5~10w') {
|
||
$income_array_temp['5~10w'] = $income_array_temp['5~10w'] + 1;
|
||
$woman_income_user_ids['5~10w'][] = $income['user_id'];
|
||
}
|
||
if ($income['income'] == '10~15w') {
|
||
$income_array_temp['10~15w'] = $income_array_temp['10~15w'] + 1;
|
||
$woman_income_user_ids['10~15w'][] = $income['user_id'];
|
||
}
|
||
if ($income['income'] == '15~30w') {
|
||
$income_array_temp['15~30w'] = $income_array_temp['15~30w'] + 1;
|
||
$woman_income_user_ids['15~30w'][] = $income['user_id'];
|
||
}
|
||
if ($income['income'] == '30~50w') {
|
||
$income_array_temp['30~50w'] = $income_array_temp['30~50w'] + 1;
|
||
$woman_income_user_ids['30~50w'][] = $income['user_id'];
|
||
}
|
||
if ($income['income'] == '50~100w') {
|
||
$income_array_temp['50~100w'] = $income_array_temp['50~100w'] + 1;
|
||
$woman_income_user_ids['50~100w'][] = $income['user_id'];
|
||
}
|
||
if ($income['income'] == '100~500w') {
|
||
$income_array_temp['100~500w'] = $income_array_temp['100~500w'] + 1;
|
||
$woman_income_user_ids['100~500w'][] = $income['user_id'];
|
||
}
|
||
if ($income['income'] == '500w以上') {
|
||
$income_array_temp['500w以上'] = $income_array_temp['500w以上'] + 1;
|
||
$woman_income_user_ids['500w以上'][] = $income['user_id'];
|
||
}
|
||
}
|
||
$woman_income_array = $income_array_temp;
|
||
|
||
$income_array_temp['5w以下'] = $income_array_temp['5~10w'] = $income_array_temp['10~15w'] = $income_array_temp['15~30w'] = $income_array_temp['30~50w'] =
|
||
$income_array_temp['50~100w'] = $income_array_temp['100~500w'] = $income_array_temp['100~500w'] = $income_array_temp['500w以上'] = 0;
|
||
$property_array['有房有车'] = $property_array['有房无车'] = $property_array['无房有车'] = $property_array['无房无车'] = 0;
|
||
foreach ($income_array_temp as $key => $val) {
|
||
if (!isset($woman_income_user_ids[$key])) {
|
||
$property_array['有房有车'] = $property_array['有房无车'] = $property_array['无房有车'] = $property_array['无房无车'] = 0;
|
||
} else {
|
||
$woman_property_array_temp = ProfileCourtship::whereIn('user_id', $woman_income_user_ids[$key])->select('h_car', 'h_housing')->get()->toArray();
|
||
foreach ($woman_property_array_temp as $item) {
|
||
if ($item['h_car'] == 1 && $item['h_housing'] == 1) {
|
||
$property_array['有房有车'] = $property_array['有房有车'] + 1;
|
||
} elseif ($item['h_car'] == 0 && $item['h_housing'] == 1) {
|
||
$property_array['有房无车'] = $property_array['有房无车'] + 1;
|
||
} elseif ($item['h_car'] == 1 && $item['h_housing'] == 0) {
|
||
$property_array['无房有车'] = $property_array['无房有车'] + 1;
|
||
} elseif ($item['h_car'] == 0 && $item['h_housing'] == 0) {
|
||
$property_array['无房无车'] = $property_array['无房无车'] + 1;
|
||
}
|
||
}
|
||
}
|
||
$woman_property_array[$key] = $property_array;
|
||
$property_array['有房有车'] = $property_array['有房无车'] = $property_array['无房有车'] = $property_array['无房无车'] = 0;
|
||
}
|
||
|
||
$income_array_temp['5w以下'] = $income_array_temp['5~10w'] = $income_array_temp['10~15w'] = $income_array_temp['15~30w'] = $income_array_temp['30~50w'] =
|
||
$income_array_temp['50~100w'] = $income_array_temp['100~500w'] = $income_array_temp['100~500w'] = $income_array_temp['500w以上'] = 0;
|
||
$property_array['有房有车'] = $property_array['有房无车'] = $property_array['无房有车'] = $property_array['无房无车'] = 0;
|
||
foreach ($income_array_temp as $key => $val) {
|
||
if (!isset($man_income_user_ids[$key])) {
|
||
$property_array['有房有车'] = $property_array['有房无车'] = $property_array['无房有车'] = $property_array['无房无车'] = 0;
|
||
} else {
|
||
$man_property_array_temp = ProfileCourtship::whereIn('user_id', $man_income_user_ids[$key])->select('h_car', 'h_housing')->get()->toArray();
|
||
foreach ($man_property_array_temp as $item) {
|
||
if ($item['h_car'] == 1 && $item['h_housing'] == 1) {
|
||
$property_array['有房有车'] = $property_array['有房有车'] + 1;
|
||
} elseif ($item['h_car'] == 0 && $item['h_housing'] == 1) {
|
||
$property_array['有房无车'] = $property_array['有房无车'] + 1;
|
||
} elseif ($item['h_car'] == 1 && $item['h_housing'] == 0) {
|
||
$property_array['无房有车'] = $property_array['无房有车'] + 1;
|
||
} elseif ($item['h_car'] == 0 && $item['h_housing'] == 0) {
|
||
$property_array['无房无车'] = $property_array['无房无车'] + 1;
|
||
}
|
||
}
|
||
}
|
||
$man_property_array[$key] = $property_array;
|
||
$property_array['有房有车'] = $property_array['有房无车'] = $property_array['无房有车'] = $property_array['无房无车'] = 0;
|
||
}
|
||
/**
|
||
//所在地比例
|
||
$province_array = ProfileCourtship::whereIn('user_id', $loveUserIds)->selectRaw('province,Count(*) as count')->groupBy("province")->get()->toArray();
|
||
foreach ($province_array as $key => $val) {
|
||
$province_array[$key]['percentum'] = round($val['count'] / $total * 100, 2) . '%';
|
||
}
|
||
//出生地比例
|
||
$resident_province_array = ProfileCourtship::whereIn('user_id', $loveUserIds)->selectRaw('resident_province,Count(*) as count')->groupBy("resident_province")->get()->toArray();
|
||
foreach ($resident_province_array as $key => $val) {
|
||
$resident_province_array[$key]['percentum'] = round($val['count'] / $total * 100, 2) . '%';
|
||
}
|
||
**/
|
||
//身高
|
||
$man_statures_temp = ProfileCourtship::whereIn('user_id', $man_ids)->whereNotNull('stature')->pluck('stature')->toArray();
|
||
$stature_array_temp['140cm以下'] = $stature_array_temp['140-145cm'] = $stature_array_temp['146-150cm'] =
|
||
$stature_array_temp['151-155cm'] = $stature_array_temp['156-160cm'] = $stature_array_temp['161-165cm'] =
|
||
$stature_array_temp['166-170cm'] = $stature_array_temp['171-175cm'] = $stature_array_temp['176-180cm'] =
|
||
$stature_array_temp['181cm以上'] = 0;
|
||
foreach ($man_statures_temp as $key => $val) {
|
||
if ($val <= 140) {
|
||
$stature_array_temp['140cm以下'] = $stature_array_temp['140cm以下'] + 1;
|
||
}
|
||
if ($val >= 140 && $val <= 145) {
|
||
$stature_array_temp['140-145cm'] = $stature_array_temp['140-145cm'] + 1;
|
||
}
|
||
if ($val >= 146 && $val <= 150) {
|
||
$stature_array_temp['146-150cm'] = $stature_array_temp['146-150cm'] + 1;
|
||
}
|
||
if ($val >= 151 && $val <= 155) {
|
||
$stature_array_temp['151-155cm'] = $stature_array_temp['151-155cm'] + 1;
|
||
}
|
||
if ($val >= 156 && $val <= 160) {
|
||
$stature_array_temp['156-160cm'] = $stature_array_temp['156-160cm'] + 1;
|
||
}
|
||
if ($val >= 161 && $val <= 165) {
|
||
$stature_array_temp['161-165cm'] = $stature_array_temp['161-165cm'] + 1;
|
||
}
|
||
if ($val >= 166 && $val <= 170) {
|
||
$stature_array_temp['166-170cm'] = $stature_array_temp['166-170cm'] + 1;
|
||
}
|
||
if ($val >= 171 && $val <= 175) {
|
||
$stature_array_temp['171-175cm'] = $stature_array_temp['171-175cm'] + 1;
|
||
}
|
||
if ($val >= 176 && $val <= 180) {
|
||
$stature_array_temp['176-180cm'] = $stature_array_temp['176-180cm'] + 1;
|
||
}
|
||
if ($val >= 181) {
|
||
$stature_array_temp['181cm以上'] = $stature_array_temp['181cm以上'] + 1;
|
||
}
|
||
}
|
||
foreach ($stature_array_temp as $key => $val) {
|
||
$man_stature_array[$key] = $val;
|
||
}
|
||
$stature_array_temp['140cm以下'] = $stature_array_temp['140-145cm'] = $stature_array_temp['146-150cm'] =
|
||
$stature_array_temp['151-155cm'] = $stature_array_temp['156-160cm'] = $stature_array_temp['161-165cm'] =
|
||
$stature_array_temp['166-170cm'] = $stature_array_temp['171-175cm'] = $stature_array_temp['176-180cm'] =
|
||
$stature_array_temp['181cm以上'] = 0;
|
||
$woman_statures_temp = ProfileCourtship::whereIn('user_id', $woman_ids)->whereNotNull('stature')->pluck('stature')->toArray();
|
||
foreach ($woman_statures_temp as $key => $val) {
|
||
if ($val <= 140) {
|
||
$stature_array_temp['140cm以下'] = $stature_array_temp['140cm以下'] + 1;
|
||
}
|
||
if ($val >= 140 && $val <= 145) {
|
||
$stature_array_temp['140-145cm'] = $stature_array_temp['140-145cm'] + 1;
|
||
}
|
||
if ($val >= 146 && $val <= 150) {
|
||
$stature_array_temp['146-150cm'] = $stature_array_temp['146-150cm'] + 1;
|
||
}
|
||
if ($val >= 151 && $val <= 155) {
|
||
$stature_array_temp['151-155cm'] = $stature_array_temp['151-155cm'] + 1;
|
||
}
|
||
if ($val >= 156 && $val <= 160) {
|
||
$stature_array_temp['156-160cm'] = $stature_array_temp['156-160cm'] + 1;
|
||
}
|
||
if ($val >= 161 && $val <= 165) {
|
||
$stature_array_temp['161-165cm'] = $stature_array_temp['161-165cm'] + 1;
|
||
}
|
||
if ($val >= 166 && $val <= 170) {
|
||
$stature_array_temp['166-170cm'] = $stature_array_temp['166-170cm'] + 1;
|
||
}
|
||
if ($val >= 171 && $val <= 175) {
|
||
$stature_array_temp['171-175cm'] = $stature_array_temp['171-175cm'] + 1;
|
||
}
|
||
if ($val >= 176 && $val <= 180) {
|
||
$stature_array_temp['176-180cm'] = $stature_array_temp['176-180cm'] + 1;
|
||
}
|
||
if ($val >= 181) {
|
||
$stature_array_temp['181cm以上'] = $stature_array_temp['181cm以上'] + 1;
|
||
}
|
||
}
|
||
foreach ($stature_array_temp as $key => $val) {
|
||
$woman_stature_array[$key] = $val;
|
||
}
|
||
|
||
//年龄
|
||
$man_birthdays = ProfileCourtship::whereIn('user_id', $man_ids)->whereNotNull('birthday')->select('birthday', 'user_id')->get()->toArray();
|
||
$birthday_array_temp['20岁以下'] = $birthday_array_temp['20-25岁'] = $birthday_array_temp['26-30岁'] =
|
||
$birthday_array_temp['31-35岁'] = $birthday_array_temp['36-40岁'] = $birthday_array_temp['41-45岁'] =
|
||
$birthday_array_temp['46-50岁'] = $birthday_array_temp['51-55岁'] = $birthday_array_temp['56-60岁'] =
|
||
$birthday_array_temp['60岁以上'] = 0;
|
||
$now = date('Y');
|
||
foreach ($man_birthdays as $key => $val) {
|
||
if (!$val['birthday']) {
|
||
continue;
|
||
}
|
||
$year = date('Y', strtotime($val['birthday']));
|
||
$age = $now - $year;
|
||
if ($age < 20) {
|
||
$birthday_array_temp['20岁以下'] = $birthday_array_temp['20岁以下'] + 1;
|
||
$man_birthday_user_ids['20岁以下'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 21 && $age <= 25) {
|
||
$birthday_array_temp['20-25岁'] = $birthday_array_temp['20-25岁'] + 1;
|
||
$man_birthday_user_ids['20-25岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 26 && $age <= 30) {
|
||
$birthday_array_temp['26-30岁'] = $birthday_array_temp['26-30岁'] + 1;
|
||
$man_birthday_user_ids['26-30岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 31 && $age <= 35) {
|
||
$birthday_array_temp['31-35岁'] = $birthday_array_temp['31-35岁'] + 1;
|
||
$man_birthday_user_ids['31-35岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 36 && $age <= 40) {
|
||
$birthday_array_temp['36-40岁'] = $birthday_array_temp['36-40岁'] + 1;
|
||
$man_birthday_user_ids['36-40岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 41 && $age <= 45) {
|
||
$birthday_array_temp['41-45岁'] = $birthday_array_temp['41-45岁'] + 1;
|
||
$man_birthday_user_ids['41-45岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 46 && $age <= 50) {
|
||
$birthday_array_temp['46-50岁'] = $birthday_array_temp['46-50岁'] + 1;
|
||
$man_birthday_user_ids['46-50岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 51 && $age <= 55) {
|
||
$birthday_array_temp['51-55岁'] = $birthday_array_temp['51-55岁'] + 1;
|
||
$man_birthday_user_ids['51-55岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 56 && $age <= 60) {
|
||
$birthday_array_temp['56-60岁'] = $birthday_array_temp['56-60岁'] + 1;
|
||
$man_birthday_user_ids['56-60岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 61) {
|
||
$birthday_array_temp['60岁以上'] = $birthday_array_temp['60岁以上'] + 1;
|
||
$man_birthday_user_ids['60岁以上'][] = $val['user_id'];
|
||
}
|
||
}
|
||
$man_birthday_array = $birthday_array_temp;
|
||
|
||
$woman_birthdays = ProfileCourtship::whereIn('user_id', $woman_ids)->whereNotNull('birthday')->select('birthday', 'user_id')->get()->toArray();
|
||
$birthday_array_temp['20岁以下'] = $birthday_array_temp['20-25岁'] = $birthday_array_temp['26-30岁'] =
|
||
$birthday_array_temp['31-35岁'] = $birthday_array_temp['36-40岁'] = $birthday_array_temp['41-45岁'] =
|
||
$birthday_array_temp['46-50岁'] = $birthday_array_temp['51-55岁'] = $birthday_array_temp['56-60岁'] =
|
||
$birthday_array_temp['60岁以上'] = 0;
|
||
$now = date('Y');
|
||
foreach ($woman_birthdays as $key => $val) {
|
||
if (!$val['birthday']) {
|
||
continue;
|
||
}
|
||
$year = date('Y', strtotime($val['birthday']));
|
||
$age = $now - $year;
|
||
if ($age < 20) {
|
||
$birthday_array_temp['20岁以下'] = $birthday_array_temp['20岁以下'] + 1;
|
||
$woman_birthday_user_ids['20岁以下'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 21 && $age <= 25) {
|
||
$birthday_array_temp['20-25岁'] = $birthday_array_temp['20-25岁'] + 1;
|
||
$woman_birthday_user_ids['20-25岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 26 && $age <= 30) {
|
||
$birthday_array_temp['26-30岁'] = $birthday_array_temp['26-30岁'] + 1;
|
||
$woman_birthday_user_ids['26-30岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 31 && $age <= 35) {
|
||
$birthday_array_temp['31-35岁'] = $birthday_array_temp['31-35岁'] + 1;
|
||
$woman_birthday_user_ids['31-35岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 36 && $age <= 40) {
|
||
$birthday_array_temp['36-40岁'] = $birthday_array_temp['36-40岁'] + 1;
|
||
$woman_birthday_user_ids['36-40岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 41 && $age <= 45) {
|
||
$birthday_array_temp['41-45岁'] = $birthday_array_temp['41-45岁'] + 1;
|
||
$woman_birthday_user_ids['41-45岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 46 && $age <= 50) {
|
||
$birthday_array_temp['46-50岁'] = $birthday_array_temp['46-50岁'] + 1;
|
||
$woman_birthday_user_ids['46-50岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 51 && $age <= 55) {
|
||
$birthday_array_temp['51-55岁'] = $birthday_array_temp['51-55岁'] + 1;
|
||
$woman_birthday_user_ids['51-55岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 56 && $age <= 60) {
|
||
$birthday_array_temp['56-60岁'] = $birthday_array_temp['56-60岁'] + 1;
|
||
$woman_birthday_user_ids['56-60岁'][] = $val['user_id'];
|
||
}
|
||
if ($age >= 61) {
|
||
$birthday_array_temp['60岁以上'] = $birthday_array_temp['60岁以上'] + 1;
|
||
$woman_birthday_user_ids['60岁以上'][] = $val['user_id'];
|
||
}
|
||
}
|
||
$woman_birthday_array = $birthday_array_temp;
|
||
|
||
$birthday_array_temp['20岁以下'] = $birthday_array_temp['20-25岁'] = $birthday_array_temp['26-30岁'] =
|
||
$birthday_array_temp['31-35岁'] = $birthday_array_temp['36-40岁'] = $birthday_array_temp['41-45岁'] =
|
||
$birthday_array_temp['46-50岁'] = $birthday_array_temp['51-55岁'] = $birthday_array_temp['56-60岁'] =
|
||
$birthday_array_temp['60岁以上'] = 0;
|
||
|
||
$degree['其他'] = $degree['高中'] = $degree['大专'] = $degree['本科'] = $degree['硕士'] = $degree['博士'] = 0;
|
||
foreach ($birthday_array_temp as $key => $val) {
|
||
if (!isset($man_birthday_user_ids[$key])) {
|
||
$man_degree[$key] = $degree;
|
||
} else {
|
||
$man_degree_temp = ProfileCourtship::whereIn('user_id', $man_birthday_user_ids[$key])->whereNotNull('degree')->pluck('degree')->toArray();
|
||
foreach ($man_degree_temp as $man_key => $man_val) {
|
||
$match = 0;
|
||
foreach ($degree as $degree_key => $degree_val) {
|
||
if ($man_val == $degree_key) {
|
||
$degree[$degree_key] = $degree[$degree_key] + 1;
|
||
$match = 1;
|
||
break;
|
||
}
|
||
}
|
||
if ($match == 0) {
|
||
$degree['其他'] = $degree['其他'] + 1;
|
||
$match = 0;
|
||
}
|
||
}
|
||
$man_degree[$key] = $degree;
|
||
$degree['其他'] = $degree['高中'] = $degree['大专'] = $degree['本科'] = $degree['硕士'] = $degree['博士'] = 0;
|
||
}
|
||
}
|
||
|
||
$birthday_array_temp['20岁以下'] = $birthday_array_temp['20-25岁'] = $birthday_array_temp['26-30岁'] =
|
||
$birthday_array_temp['31-35岁'] = $birthday_array_temp['36-40岁'] = $birthday_array_temp['41-45岁'] =
|
||
$birthday_array_temp['46-50岁'] = $birthday_array_temp['51-55岁'] = $birthday_array_temp['56-60岁'] =
|
||
$birthday_array_temp['60岁以上'] = 0;
|
||
$degree['其他'] = $degree['高中'] = $degree['大专'] = $degree['本科'] = $degree['硕士'] = $degree['博士'] = 0;
|
||
foreach ($birthday_array_temp as $key => $val) {
|
||
if (!isset($woman_birthday_user_ids[$key])) {
|
||
$woman_degree[$key] = $degree;
|
||
} else {
|
||
$woman_degree_temp = ProfileCourtship::whereIn('user_id', $woman_birthday_user_ids[$key])->whereNotNull('degree')->pluck('degree')->toArray();
|
||
foreach ($woman_degree_temp as $woman_key => $woman_val) {
|
||
$match = 0;
|
||
foreach ($degree as $degree_key => $degree_val) {
|
||
if ($woman_val == $degree_key) {
|
||
$degree[$degree_key] = $degree[$degree_key] + 1;
|
||
$match = 1;
|
||
break;
|
||
}
|
||
}
|
||
if ($match == 0) {
|
||
$degree['其他'] = $degree['其他'] + 1;
|
||
$match = 0;
|
||
}
|
||
}
|
||
$woman_degree[$key] = $degree;
|
||
$degree['其他'] = $degree['高中'] = $degree['大专'] = $degree['本科'] = $degree['硕士'] = $degree['博士'] = 0;
|
||
}
|
||
}
|
||
return $this->success('ok', compact('sex_array', 'man_income_array', 'woman_income_array',
|
||
'man_birthday_array','woman_birthday_array', 'woman_degree', 'man_degree',
|
||
'affective_state_array', 'man_stature_array', 'woman_stature_array','man_property_array','woman_property_array'));
|
||
}catch (\Exception $e){
|
||
$this->getError($e);
|
||
return $this->failure('数据获取失败,请稍后再试');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 圈子内部匹配
|
||
*/
|
||
public function getCircleUserMatch(Request $request){
|
||
$circle_id = $request->circle_id;
|
||
$circle = Circle::where('merchant_id',$request->account_id)->where('id',$circle_id)->first();
|
||
$join_user_ids = CircleJoinUser::where('circle_id',$circle_id)->where('audit_status',1)->pluck('user_id');
|
||
$join_man_users = CircleUser::whereIn('id',$join_user_ids)
|
||
->with('love_user:id,photo,sex,nickname,industry,is_real_approved,is_educate_approved,industry_sub,mobile')
|
||
->with('love_user_profile:user_id,birthday,belief,income,qq,degree,province,city,stature,wechat_id,qq,other_contact,graduate_school,stature,resident_province,resident_city')
|
||
->select('id','love_user_id','affective_state','mate_condition')
|
||
->whereHas('love_user_profile')
|
||
->whereHas('love_user',function ($query){
|
||
$query->where('sex',1);
|
||
})
|
||
->get();
|
||
$join_woman_users = CircleUser::whereIn('id',$join_user_ids)
|
||
->with('love_user:id,photo,sex,nickname,industry,is_real_approved,is_educate_approved,industry_sub,mobile')
|
||
->with('love_user_profile:user_id,birthday,belief,income,qq,degree,province,city,stature,wechat_id,qq,other_contact,graduate_school,stature,resident_province,resident_city')
|
||
->select('id','love_user_id','affective_state','mate_condition')
|
||
->whereHas('love_user_profile')
|
||
->whereHas('love_user',function ($query){
|
||
$query->where('sex',2);
|
||
})
|
||
->get();
|
||
foreach ($join_man_users as $man_key => $man_val) {
|
||
if (!empty($man_val->love_user_profile)) {
|
||
if (!empty($man_val->love_user_profile->birthday)) {
|
||
$year = date('y', strtotime($man_val->love_user_profile->birthday));
|
||
$man_val->love_user_profile->year = $year;
|
||
} else {
|
||
$man_val->love_user_profile->year = null;
|
||
}
|
||
}
|
||
$man_array[$man_val->id] = $man_val;
|
||
}
|
||
foreach ($join_woman_users as $woman_key => $woman_val) {
|
||
if (!empty($woman_val->love_user_profile)) {
|
||
if (!empty($woman_val->love_user_profile->birthday)) {
|
||
$year = date('y', strtotime($woman_val->love_user_profile->birthday));
|
||
$woman_val->love_user_profile->year = $year;
|
||
} else {
|
||
$woman_val->love_user_profile->year = null;
|
||
}
|
||
}
|
||
$woman_array[$woman_val->id] = $woman_val;
|
||
}
|
||
$man_match_user= [];
|
||
$match_info = [];
|
||
//男生的要求,女生能不能满足
|
||
foreach ($join_man_users as $man_key => $man_val){
|
||
foreach ($join_woman_users as $woman_key => $woman_val){
|
||
$match = $this->diff($man_val,$woman_val,$circle);
|
||
if($match['percent']>=80){
|
||
$man['man'] = $man_val->id;
|
||
$man['woman'] = $woman_val->id;
|
||
$man['match'] = $match['percent'];
|
||
$man_match_user[] = $man;
|
||
$match_info[$man_val->id.'_'.$woman_val->id] = $match;
|
||
}
|
||
}
|
||
}
|
||
$woman_match_user= [];
|
||
//女生的要求,男生能不能满足
|
||
foreach ($join_woman_users as $woman_key => $woman_val){
|
||
foreach ($join_man_users as $man_key => $man_val){
|
||
$match = $this->diff($woman_val,$man_val,$circle);
|
||
if($match['percent']>=80){
|
||
$woman['man'] = $man_val->id;
|
||
$woman['woman'] = $woman_val->id;
|
||
$woman['match'] = $match['percent'];
|
||
$woman_match_user[] = $woman;
|
||
$match_info[$woman_val->id.'_'.$man_val->id] = $match;
|
||
}
|
||
}
|
||
}
|
||
$match = [];
|
||
$temp = [];
|
||
foreach ($man_match_user as $man_key => $man_val){
|
||
if(!$man_val){
|
||
break;
|
||
}
|
||
foreach ($woman_match_user as $woman_key => $woman_val){
|
||
if(!$woman_val){
|
||
continue;
|
||
}
|
||
if($woman_val['man'] == $man_val['man'] && $woman_val['woman'] == $man_val['woman']){
|
||
$temp['man'] = $man_array[$man_val['man']];
|
||
$temp['woman'] = $woman_array[$woman_val['woman']];
|
||
$temp['source'] = $match_info[$man_val['man'].'_'.$woman_val['woman']];
|
||
$temp['target'] = $match_info[$woman_val['woman'].'_'.$man_val['man']];
|
||
$match[] = $temp;
|
||
$temp = [];
|
||
}
|
||
}
|
||
}
|
||
return $this->success('ok',$match);
|
||
}
|
||
|
||
}
|