Jelajahi Sumber

'2333209933-12'

zory 4 hari lalu
induk
melakukan
645d7081c8

+ 8 - 1
app/controller/api/Service.php

@@ -86,8 +86,15 @@ class Service extends Base
                     "poi_id"    => $store['poi_id'],
                     "poi_name"  => $store['poi_name'],
                     "openid"    => $request->user['openid'],
-                    "service_id"    => $service['id']
+                    "service_id"    => $service['id'],
+                    "order"    => $param['order']??'',
+                    "goods"    => $param['goods']??''
                 ]);
+            } else {
+                $chatStore->service_id = $service['id'];
+                $chatStore->order = $param['order']??'';
+                $chatStore->goods = $param['goods']??'';
+                $chatStore->save();
             }
             return $this->encode("ok",['store' => $store,'code' => 1,'sendId' => $request->user['openid'],'msg' => pageFormatMsg($msg),"serviceId" => $service['id']]); // 客服在线
         } catch (\Throwable $throwable) {

+ 33 - 0
app/controller/service/Service.php

@@ -9,6 +9,7 @@ use app\model\saas\SaasChatMsg;
 use app\model\saas\SaasChatStore;
 use app\model\saas\SaasOrderPrice;
 use app\service\saas\ChatStoreService;
+use app\service\saas\GoodsService;
 use DI\Attribute\Inject;
 use LinFly\Annotation\Attributes\Route\Controller;
 use LinFly\Annotation\Attributes\Route\GetMapping;
@@ -29,6 +30,10 @@ class Service extends Base
     #[Inject]
     protected SaasChatStore $model;
 
+
+    #[Inject]
+    protected GoodsService $goodsService;
+
     #[GetMapping('list')]
     public function getServiceData(Request $request): Response
     {
@@ -77,6 +82,34 @@ class Service extends Base
         }
     }
 
+
+    #[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
     {

+ 11 - 0
app/model/saas/SaasChatStore.php

@@ -56,4 +56,15 @@ class SaasChatStore extends Model
         return $this->hasOne(SystemUser::class,"id","service_id");
     }
 
+
+    public function orders(): HasOne
+    {
+        return $this->hasOne(SaasOrder::class,"order_sn","order");
+    }
+
+    public function good(): HasOne
+    {
+        return $this->hasOne(SaasGoods::class,"product_id","goods");
+    }
+
 }