all(); $param['poi_id'] = $request->user['store_id']; $param['service_id'] = $request->user['id']; $data = $this->service->setModel()->getList($param,['user' => function($query){ $query->field("openid,nickname,mobile,create_at"); }],true,['last','avatar'],['last' => function($data,$resp) use($param){ $last = (new SaasChatMsg)->where(["poi_id" => $resp['poi_id'],"service_id" => $param['service_id'],"openid" => $resp['openid']])->order("create_at desc")->field("content,create_at,type")->findOrEmpty(); if ($last->isEmpty()) { return ['type' => "text","content"=>"无",'num' => 0,'time' => time(),"create_at"=> formatTime(date("Y-m-d H:i:s",time()))]; } return ["content"=> $last['content'],'num' => 0,"create_at"=> formatTime($last['create_at']),"time"=> strtotime($last['create_at']),'type' => $last['type']]; },'avatar' => function(){ return "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png"; }]); return successTrans(100010,pageFormat($data),200); } catch (\Throwable $th) { return error($th->getMessage()); } } #[GetMapping('msg')] public function getMessageData(Request $request): Response { try { $param = $request->all(); $msg = (new SaasChatMsg)->where(['openid' => $param['openid'],'poi_id' => $request->user['store_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; }])->with(['nick' => function ($query) { $query->field("id,truename"); },'user' => function ($query) { $query->field("openid,nickname"); }])->order("id","desc")->paginate([ "list_rows" => $param['size'] ?? 10, "page" => $param['page'] ?? 1, ]); return successTrans(100010,pageFormatMsg($msg),200); } catch (\Throwable $th) { return error($th->getMessage()); } } #[GetMapping('order')] public function getMsgOrder(Request $request) { try { $param = $this->_valid([ "msgId.require" => trans("empty.require") ]); if (!is_array($param)) return error($param); $productType = $this->goodsService->productType(); $chatStore = $this->model->where("id",$param['msgId'])->with(['orders' => function($query) use($productType){ $query->field("*")->with(['product' => function($query) use($productType){ $query->field("product_id,product_name,product_type")->append(['types'])->withAttr(['types' => function($query,$resp) use($productType){ $productTypeArr = []; foreach ($productType as $val) { $productTypeArr[$val['key']] = $val['name']; } return $productTypeArr[$resp['product_type']]??''; }]); }]); }])->findOrEmpty(); if ($chatStore->isEmpty()) return error("error"); return success("ok",['order' => $chatStore['orders']]); } catch (\Throwable $th) { return error($th->getMessage()); } } #[PostMapping('send')] public function sendMessageData(Request $request): Response { try { $param = $this->_valid([ "content.require" => trans("empty.require"), "groupId.require" => trans("empty.require"), "openid.require" => trans("empty.require"), "type.require" => trans("empty.require"), ],"post"); if (!is_array($param)) return error($param); $str = preg_replace('/\s+/','',$param['content']); if (empty($str)) return error("请勿发送空消息"); $state = (new SaasChatMsg)->insertGetId([ "source" => 2, "openid" => $param['openid'], "content" => is_array($param['content'])?json_encode($param['content']):$param['content'], "type" => $param['type'], "msgId" => md5($param['openid'].time()), "poi_id" => $param['groupId'], "service_id" => $request->user['id'], ]); $api = new Api('http://127.0.0.1:3232', config('plugin.webman.push.app.app_key'),config('plugin.webman.push.app.app_secret')); $api->trigger("user-{$param['openid']}","message",[ "type" => $param['type'], "time" => time() * 1000, "msgId" => md5($param['openid'].time()), "content" => is_array($param['content'])?json_encode($param['content']):$param['content'], "source" => 2, "avatar" => "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png", "poi_id" => $param['groupId'], "openid" => $param['openid'], "service_id" => $request->user['id'], "create_at" => formatTime(time()), ]); return successTrans("success.data",['time' => formatTime(time())]); } catch (\Throwable $th) { return error($th->getMessage()); } } #[PostMapping('send/price')] public function sendPriceData(Request $request): Response { try { $param = $this->_valid([ "name.require" => trans("empty.require"), "price.require" => trans("empty.require"), "groupId.require" => trans("empty.require"), "openid.require" => trans("empty.require"), "type.require" => trans("empty.require"), ],"post"); if (!is_array($param)) return error($param); $orderSn = CodeExtend::uniqidDate(18,"P"); $msgId = md5($param['openid'].time()); $priceState = (new SaasOrderPrice)->insertGetId([ "openid" => $param['openid'], "poi_id" => $param['groupId'], "service_id" => $request->user['id'], "name" => $param['name'], "price" => $param['price'] * 100, "image" => "https://jymini.oss-cn-guangzhou.aliyuncs.com/mini/chajia.jpg", "order_sn" => $orderSn, "msgId" => $msgId, ]); if (!$priceState) return errorTrans("error.data"); $msgData = [ "img" => "https://jymini.oss-cn-guangzhou.aliyuncs.com/mini/chajia.jpg", "name" => $param['name'], "order" => $orderSn, "price" => $param['price'], "msgId" => $msgId, "status" => 0 ]; $state = (new SaasChatMsg)->insertGetId([ "source" => 2, "openid" => $param['openid'], "content" => json_encode($msgData), "type" => $param['type'], "msgId" => $msgId, "poi_id" => $param['groupId'], "service_id" => $request->user['id'], ]); if (!$state) return errorTrans("error.data"); $api = new Api('http://127.0.0.1:3232', config('plugin.webman.push.app.app_key'),config('plugin.webman.push.app.app_secret')); $api->trigger("user-{$param['openid']}","message",[ "type" => $param['type'], "time" => time() * 1000, "msgId" => $msgId, "content" => json_encode($msgData), "source" => 2, "avatar" => "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png", "poi_id" => $param['groupId'], "openid" => $param['openid'], "service_id" => $request->user['id'], "create_at" => formatTime(time()), ]); return successTrans("success.data",$msgData); } catch (\Throwable $throwable) { return error($throwable->getMessage()); } } }