user(); if ($user->type == 'single') { //用户性别 $user_sex = ProfileCourtship::where('user_id', $user->id)->value('sex'); if ($user_sex == 1) { $other_sex = 2; }elseif ($user_sex == 2) { $other_sex = 1; }else{ return $this->failure('请在个人信息修改性别'); } $matches = GoodMatch::with('courtship')->where('sex', $other_sex)->orderBy('id', 'desc'); }else{ $matches = GoodMatch::with('courtship')->orderBy('id', 'desc'); } // $type = $request->input('type'); // if ($type == 'recommend') { // $matches = $matches->where('is_recommend', 1); // } $matches = $matches->whereHas('user',function($sql) { $sql->where('type', 'single'); })->where('status', 1)->paginate(10); foreach ($matches as $match) { $user = User::where('id', $match->user_id)->first(); if (empty($user)) { continue; } $match->name = $user->name; $match->is_approve = $user->is_approve; $wechat = Wechat::where('user_id', $user->id)->select('avatar', 'avatar2')->first(); if (!empty($wechat)) { $avatar = $wechat->avatar2?$wechat->avatar2:$wechat->avatar; }else{ if ($user->sex == 1) { $avatar = 'http://images.ufutx.com/201811/12/0e8b72aae6fa640d9e73ed312edeebf3.png'; }else { $avatar = 'http://images.ufutx.com/201811/12/dddd79aa2c2fc6a6f35e641f6b8fb8f5.png'; } } $match->avatar = $avatar; $match->industry_sub = $user->industry_sub; if (empty($match->courtship)) { // $match->courtship->age = '未知'; }else{ $match->courtship->age = $this->getAge($match->courtship->birthday); } } return $this->success('ok', $matches); } /** * 申请加入佳偶 * @param Request $request [description] * @return [type] [description] */ public function joinGoodMatch(Request $request) { $user = auth()->user(); if ($user->type != 'single') { return $this->failure('只有单身可申请加入'); } $user_sex = ProfileCourtship::where('user_id', $user->id)->value('sex'); GoodMatch::create([ 'user_id'=>$user->id, 'sex'=>$user_sex, 'is_recommend'=>0, 'status'=>0, ]); //TODO 通知管理员 return $this->success('ok'); } /** * 约见列表 */ public function appointments(Request $request) { $active_appointments = Appointment::where('type', 'active')->get(); foreach ($active_appointments as $appointment) { $appointment->desc = json_decode($appointment->desc); } $passive_appointments = Appointment::where('type', 'passive')->get(); foreach ($passive_appointments as $appointment) { $appointment->desc = json_decode($appointment->desc); } return $this->success('ok', compact('active_appointments', 'passive_appointments')); } public function applyMatchmaker(Request $request) { $user = auth()->user(); $maker = Matchmaker::where('user_id', $user->id)->where('status', '<>', -1)->first(); if ($maker) { return $this->success('ok'); } $maker = new Matchmaker(); $maker->user_id = $user->id; $maker->status = 0; $maker->save(); //TODO 通知管理员 return $this->success('ok'); } public function makerClient() { $makers = Matchmaker::all(); foreach ($makers as $maker) { $from_openid = Wechat::where('user_id', $maker->user_id)->value('openid'); if (empty($from_openid)) { continue; } $user_ids = User::where('from_openid', $from_openid)->pluck('id'); foreach ($user_ids as $user_id) { MatchmakerClient::firstOrCreate([ 'user_id'=>$maker->user_id, 'client_user_id'=>$user_id, 'status'=>1, ]); } } return $this->success('ok'); } }