user(); //是否是好友 if ($request->user) { $other_user = User::find($request->user); $request->other_user = $other_user; if ($request->user == User::LOVE_GPT_USER_ID){ return $next($request); } if (empty($other_user) || $other_user->hidden_profile != 'NONE') return $this->failure("消息发送失败,用户已关闭资料"); //是否是客服 $servicer_ids = UserInfo::where('is_service_client', 1)->pluck('user_id')->toArray(); if (in_array($user->id, $servicer_ids)) return $next($request); if (in_array($other_user->id, $servicer_ids)) return $next($request); //查看是否被禁言 $date = date('Y-m-d H:i:s'); $history = BannedHistory::where('user_id',$user->id)->where('type','chat')->where('end_time', ">", $date)->first(); if ($history) return $this->failure('你被禁止聊天至'.$history->end_time); //聊天内容 $content = $request->input('content'); if (empty($content) && $request->content_type == 'text') return $this->failure('请输入信息!'); if (empty($request->content_type)) return $this->failure("消息发送失败,请选择消息类型"); //是否是好友 $result = $user->isFriend($other_user); if (empty($result)) return $this->failure('该用户还不是你的好友。'); //是否真人认证 if ($user->is_real_approved != 1) return $this->failure("消息发送失败,还未通过真人认证"); //敏感词汇过滤 $result = \CommonUtilsService::checkoutTextArray([$content]); if($result['code'] == 1) return $this->failure('消息发送失败,'.$result['cause']); } return $next($request); } catch (\Exception $e) { $this->getError($e); return $this->failure("服务器休息,请稍后再试"); } } public function fail($msg, $code = 3, $path='', $operate='', $notice='') { $result = [ 'code'=> $code, 'path'=> $path, 'message'=> $msg, 'operate'=> $operate, 'notice'=> $notice, ]; return Response()->json($result); } }