zory 2 veckor sedan
förälder
incheckning
b79634cad8
1 ändrade filer med 13 tillägg och 4 borttagningar
  1. 13 4
      app/controller/api/Service.php

+ 13 - 4
app/controller/api/Service.php

@@ -40,11 +40,11 @@ class Service extends Base
             }
             $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")->findOrEmpty();
+                $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 ["content"=>"无",'num' => 0,"create_at"=> formatTime(date("Y-m-d H:i:s",time()))];
+                    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'])];
+                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";
             }]);
@@ -77,7 +77,16 @@ class Service extends Base
             // 获取在线客服
             $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]); // 无客服在线
-            return $this->encode("ok",['store' => $store,'code' => 1]); // 客服在线
+            // 获取最新的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());
         }