all(); if (!empty($param['size'])) { $param['pageSize'] = $param['size']; } $param['openid'] = $request->user['openid']; $list = $this->service->setModel()->getList($param,null,true,['last','avatar'],['last' => function($data,$resp) use($param){ $last = (new SaasChatMsg)->where("poi_id",$resp['poi_id'])->where("openid",$param['openid'])->order("create_at desc")->field("content,create_at,type")->findOrEmpty(); if ($last->isEmpty()) { return ['type' => "text","content"=>"无",'num' => 0,"create_at"=> formatTime(date("Y-m-d H:i:s",time()))]; } return ["content"=> $last['content'],'num' => 0,"create_at"=> formatTime($last['create_at']),'type' => $last['type']]; },'avatar' => function(){ return "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png"; }]); return successTrans("success.data",pageFormat($list)); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } /** * 分配客服 * @param Request $request * @return Response */ #[PostMapping("shareout")] public function shareUser2Mer(Request $request): Response { try { $param = $request->all(); $store = (new SaasStore)->where("poi_id",$param['poi'])->findOrEmpty(); if ($store->isEmpty()) return error("店铺不存在"); $chatStore = (new SaasChatStore)->where(['poi_id'=> $store['poi_id'],"openid" => $request->user['openid']])->findOrEmpty(); if ($chatStore->isEmpty()) { $chatStore->insertGetId([ "poi_id" => $store['poi_id'], "poi_name" => $store['poi_name'], "openid" => $request->user['openid'] ]); } // 获取在线客服 $service = (new SystemUser)->where("store_id",$param['poi'])->where("type",3)->where("is_line",1)->findOrEmpty(); if ($service->isEmpty()) return $this->encode("ok",['store' => $store,'code' => 3]); // 无客服在线 // 获取最新的10条聊天记录 $msg = (new SaasChatMsg)->where(['openid' => $request->user['openid'],'poi_id' => $store['poi_id']])->append(['avatar','time'])->withAttr(['avatar' => function(){ return "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png"; },'time' => function($resp,$data){ return strtotime($data['create_at']) * 1000; }])->paginate([ "list_rows" => 10, "page" => 1 ]); return $this->encode("ok",['store' => $store,'code' => 1,'sendId' => $request->user['openid'],'msg' => pageFormat($msg)]); // 客服在线 } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } }