userCon = $userCon; } /** * 消息首页 * @param Request $request [description] * @return [type] [description] */ public function noticeHome(Request $request) { try { //福恋助手 $assistant = $this->userCon->lastAssistantMessage(); //最近访问 $visit = $this->userCon->lastVisit($request); //系统通知 $system = $this->userCon->lastNotice(); //联系人 $linkmen = []; // $linkmen = $this->userCon->messageLinkmen($request); //最新好友请求 $greetLog = $this->userCon->lastGreetLog(); return $this->success('ok', compact('assistant', 'visit', 'system', 'linkmen', 'greetLog')); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取消息信息失败,请稍后再试'); } } /** * 消息首页 * 只展示未读数 * @param Request $request [description] * @return [type] [description] */ public function noticeHomeV2(Request $request) { try { //系统消息未读数 $system_count = $this->userCon->systemNoticeCount($type='system'); if (empty($system_count) && !is_numeric($system_count)) throw new \Exception("获取系统未读消息失败", 1); $friend_count = $this->userCon->systemNoticeCount($type='friend'); if (empty($friend_count) && !is_numeric($friend_count)) throw new \Exception("获取好友请求未读消息失败", 1); $follow_count = $this->userCon->systemNoticeCount($type='follow'); if (empty($follow_count) && !is_numeric($follow_count)) throw new \Exception("获取关注未读消息失败", 1); $friend_deal_count = LinkingRequest::whereHas('linking_user')->where('user_id', auth()->id())->where('status', 0)->count(); //福恋助手 $assistant = $this->userCon->lastAssistantMessage(); //来访未读数 $preview_count = auth()->user()->userPreview()->whereHas('previewUser', function($sql) { $sql->where('hidden_profile', 'NONE'); })->where('status', 0)->count(); return $this->success('ok', compact('system_count', 'friend_count', 'follow_count', 'preview_count', 'assistant', 'friend_deal_count')); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取消息失败'); } } /** * 小助手消息 * @param Request $request [description] * @return [type] [description] */ public function assistantNotices(Request $request) { try { $user_id = auth()->id(); $messages = AssistantUser::with('assistantUser:id,nickname,photo')->where('user_id', $user_id)->where('assistant_user_id',1)->select('id', 'user_id', 'assistant_user_id', 'content', 'created_at')->orderBy('id', 'desc')->paginate(); AssistantUser::where('user_id', $user_id)->where('assistant_user_id',1)->where('status',0)->update(['status'=>1]); return $this->success('ok', $messages); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取小助手消息失败'); } } /** * 系统消息 * @param Request $request [description] * @return [type] [description] */ public function systemNotices(Request $request) { try { $user_id = auth()->id(); if($request->test==true&&$request->user_id) $user_id = $request->user_id; $notices = Notice::with('otherUser:id,nickname,photo,app_avatar,is_approved,rank_id,sex')->whereHas('otherUser', function($sql){ $sql->where('hidden_profile', '<>', 'ALLSEX'); }); $type = $request->input('type'); $update_notices = Notice::where('user_id', $user_id); $time = time(); if ($type) { if ($type != 'system') { $notices = $notices->where('type', $type); $update_notices = $update_notices->where('type', $type); }else{ $notices = $notices->where('type', '<>', 'friend')->where('type', '<>', 'follow')->where('type', '<>', 'wechat'); $update_notices = $update_notices->where('type', '<>', 'friend')->where('type', '<>', 'follow'); } }else{ $notices = $notices->where('type', '<>', 'friend'); $update_notices = $update_notices->where('type', '<>', 'friend'); } $notices = $notices->where('user_id', $user_id)->select('id', 'user_id', 'send_user_id', 'type', 'type_id','content','message', 'status', 'created_at')->orderBy('created_at', 'desc')->paginate(); foreach ($notices as $notice) { $ProfileCourtship = ProfileCourtship::where('user_id', $notice->send_user_id)->first(); if(!$ProfileCourtship)continue ; $birthday = $ProfileCourtship->birthday; $notice->city = $ProfileCourtship->city; $notice->otherUser->birthday = $birthday ; $notice->otherUser->age = $birthday?\CommonUtilsService::getAge($birthday):0; $notice->type_id = (int)$notice->type_id; $notice->otherUser->photo = $notice->otherUser->userAvatar(); //超级会员 $notice->otherUser->isSuperRank = $notice->otherUser->isSuperRank(); if ($type == 'friend') { $notice->deal_status = LinkingRequest::where('user_id', $user_id)->where('user_linking_id', $notice->otherUser->id)->orderBy('id', 'desc')->value('status'); } if ($notice->type == 'friend' && $notice->status == 0 && $notice->type != 2) { $day = date('d', $time - strtotime($notice->created_at)); if ($day > 7) { $expired_id[] = $notice->id; $notice->deal_status = 2; } } unset($notice->otherUser->wechat); switch ($notice->type) { case 'follow': $title = $notice->otherUser->nickname.'关注了你'; $body = '点击查看>>'; break; case 'moment': case 'like': case 'comment': case "temp": case "vote": $title = $notice->content; $body = '点击查看>>'; break; case 'gift': $title = $notice->content; $body = '点击查看>>'; $notice->type_id = $notice->send_user_id; break; case 'remind_profile_photo': $title = '交友卡片-补充信息提醒通知'; $body = $notice->content.'>>点击完善'; break; case 'system': $title = $notice->content; $body = ''; break; case 'marketing': $title = $notice->content; $body = '请前往微信"福恋"小程序查看'; break; default: $title = ''; $body = ''; break; } $notice->title = $title; $notice->body = $body; } $update_notices->where('status', 0)->update(['status'=>1]); return $this->success('ok', $notices); } catch (\Exception $e) { $this->getError($e); return $this->failure('获取系统通知失败,请稍后再试'); } } }