Jelajahi Sumber

0810-1531-h01

Zory 1 bulan lalu
induk
melakukan
f953b8f400

+ 1 - 1
app/controller/api/Auth.php

@@ -45,7 +45,7 @@ class Auth extends Base
             echo getDateFull()."登录手机号信息\n";
             echo json_encode($param)."\n";
             $sessionKey = (new Crypt)->config($this->getDyConfig())->getSessionKey($param['login']);
-            if (empty($sessionKey)) return error("授权登录失败-m");
+            if (empty($sessionKey)) return error("请重新进入再试");
             if (!empty($param['code'])) {
                 $mobileStr = (new Crypt)->config($this->getDyConfig())->token()->getMobile($param['code']);
             } else {

+ 101 - 0
app/controller/api/Msg.php

@@ -0,0 +1,101 @@
+<?php
+
+namespace app\controller\api;
+
+use app\extra\basic\Base;
+use app\middleware\AuthMiddleware;
+use app\model\saas\SaasChatMsg;
+use app\model\saas\SaasService;
+use app\model\saas\SaasStore;
+use LinFly\Annotation\Attributes\Route\Controller;
+use LinFly\Annotation\Attributes\Route\GetMapping;
+use LinFly\Annotation\Attributes\Route\Middleware;
+use LinFly\Annotation\Attributes\Route\PostMapping;
+use support\Request;
+use support\Response;
+
+
+#[Controller("/dy/msg"),Middleware(AuthMiddleware::class)]
+class Msg extends Base
+{
+
+    protected int $isUser = 1;
+
+    #[PostMapping("checkIn")]
+    public function checkIn(Request $request): Response
+    {
+        try {
+            $param = $request->all();
+            $store = (new SaasStore)->where("poi_id",$param['poi'])->findOrEmpty();
+            if ($store->isEmpty()) return error("店铺不存在");
+            // 获取最新的10条聊天记录
+            $userAvatar = $request->user['avatar'];
+            $msg = (new SaasChatMsg)->where(['openid' => $request->user['openid'],'poi_id' => $store['poi_id'],'is_user' => $this->isUser])->append(['avatar','time','userType'])->withAttr(['avatar' => function($data,$resp) use($userAvatar){
+                if ($resp['source'] == 1) { // 用户
+                    return $userAvatar??'';
+                } else {
+                    return sConf("service.logo");
+                }
+            },'time' => function($resp,$data){
+                return strtotime($data['create_at']) * 1000;
+            },'userType' => function($data,$resp) {
+                if ($resp['source'] == 1) { // 用户
+                    return 'self';
+                } else {
+                    return 'friend';
+                }
+            }])->order("id","desc")->paginate([
+                "list_rows" => 10,
+                "page"      => 1
+            ]);
+            $star = (new SaasService)->where("poi_id",$param['poi'])->with(['quick'])->findOrEmpty();
+            return $this->encode("ok",[
+                "msg" => pageFormatMsg($msg),
+                "avatar"    => [
+                    "self"      => $userAvatar,
+                    "friend"    => empty($store['poi_logo']) ? sConf("service.logo") : $store['poi_logo'],
+                ],
+                "quick" => $star,
+                "store" => ['name' => $store['poi_name'],"chat_id" => $store['poi_id']]
+            ]);
+        } catch (\Throwable $throwable) {
+            return error($throwable);
+        }
+    }
+
+    #[GetMapping("msg")]
+    public function getMessageList(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "poi.require"   => trans("empty.require"),
+                "page.default"  => 1,
+                "size.default"  => 10
+            ],$request->method());
+            if (!is_array($param)) return error($param);
+            $userAvatar = $request->user['avatar'];
+            $msg = (new SaasChatMsg)->where(['openid' => $request->user['openid'],'poi_id' => $param['poi'],'is_user' => $this->isUser])->append(['avatar','time','userType'])->withAttr(['avatar' => function($data,$resp) use($userAvatar){
+                if ($resp['source'] == 1) {
+                    return $userAvatar??'';
+                } else {
+                    return sConf("service.logo");
+                }
+            },'time' => function($resp,$data){
+                return strtotime($data['create_at']) * 1000;
+            },'userType' => function($data,$resp) {
+                if ($resp['source'] == 1) { // 用户
+                    return 'self';
+                } else {
+                    return 'friend';
+                }
+            }])->order("id","desc")->paginate([
+                "list_rows" => $param['size']??10,
+                "page"      => $param['page']??1,
+            ]);
+            return $this->encode("ok",pageFormat($msg));
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+}

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

@@ -90,7 +90,17 @@ class Service extends Base
             ]);
             // 获取在线客服
             $service = (new SystemUser)->where(['store_id' => $param['poi'],"type" => 3,"is_line" => 1])->order("last_msg_at","asc")->findOrEmpty();
-            if ($service->isEmpty()) return $this->encode("ok",['store' => $store,'code' => 3,'sendId' => $request->user['openid'],'msg' => pageFormatMsg($msg),"serviceId" => 0]); // 无客服在线
+            if ($service->isEmpty()) return $this->encode("ok",[
+                'store'     => $store,
+                'code'      => 3,
+                'sendId'    => $request->user['openid'],
+                'msg'       => pageFormatMsg($msg),
+                "noService" => [
+                    "msg"   => "当前无在线客服,请拨打商家电话 {$store['service_mobile']}",
+                    "logo"  => sConf("service.logo")
+                ],
+                "serviceId" => 0
+            ]); // 无客服在线
             if ($chatStore->isEmpty()) {
                 $chatStore->insertGetId([
                     "poi_id"    => $store['poi_id'],

+ 91 - 0
app/controller/merchant/Setting.php

@@ -0,0 +1,91 @@
+<?php
+
+namespace app\controller\merchant;
+
+use app\extra\basic\Base;
+use app\middleware\AuthMiddleware;
+use app\model\saas\SaasService;
+use app\model\saas\SaasServiceQuick;
+use LinFly\Annotation\Attributes\Route\Controller;
+use LinFly\Annotation\Attributes\Route\GetMapping;
+use LinFly\Annotation\Attributes\Route\Middleware;
+use LinFly\Annotation\Attributes\Route\PostMapping;
+use support\Request;
+use support\Response;
+
+#[Controller("/api/merchant/setting"),Middleware(AuthMiddleware::class)]
+class Setting extends Base
+{
+
+
+    #[GetMapping('data')]
+    public function getSetData(Request $request): Response
+    {
+        try {
+            $data = (new SaasService)->where("poi_id",$request->user['store_id'])->with(['quick'])->findOrEmpty();
+            return success("ok",$data->toArray());
+        } catch (\Throwable $th) {
+            return error($th->getMessage());
+        }
+    }
+
+
+    #[PostMapping('save')]
+    public function setSetData(Request $request): Response
+    {
+        try {
+            $param = $request->post();
+            if (empty($param['type'])) return errorTrans("empty.require");
+            $data = (new SaasService)->where("poi_id",$request->user['store_id'])->findOrEmpty();
+            if ($data->isEmpty()) {
+                $state = $data->strict(false)->insertGetId([
+                    "poi_id"        => $request->user['store_id'],
+                    $param['type']  => ($param['type']=='quick'?json_encode($param['content']):$param['content'])
+                ]);
+            } else {
+                $state = $data->strict(false)->save([
+                    $param['type'] => ($param['type']=='quick'?json_encode($param['content']):$param['content'])
+                ]);
+            }
+            if (!$state) return errorTrans("error.data");
+            return successTrans("success.data");
+        } catch (\Throwable $th) {
+            return error($th->getMessage());
+        }
+    }
+
+    #[PostMapping('quick')]
+    public function setQuickData(Request $request): Response
+    {
+        try {
+            $param = $request->post();
+            $param['poi_id'] = $request->user['store_id'];
+            $state = (new SaasServiceQuick)->setAutoData($param);
+            if (!$state) return errorTrans("error.data");
+            return successTrans("success.data");
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+
+    #[PostMapping('del')]
+    public function delQuickData(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "id.require"    => trans("empty.require"),
+            ],$request->method());
+            if (!is_array($param)) return error($param);
+            $quick = (new SaasServiceQuick)->where("id",$param["id"])->findOrEmpty();
+            if ($quick->isEmpty()) return errorTrans("error.data");
+            if ($quick['poi_id'] <> $request->user['store_id']) return errorTrans("error.data");
+            $state = $quick->delete();
+            if (!$state) return errorTrans("error.data");
+            return successTrans("success.data");
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+}

+ 52 - 0
app/model/saas/SaasService.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace app\model\saas;
+
+use app\extra\basic\Model;
+use think\model\relation\HasMany;
+
+
+/**
+ * @property integer $id (主键)
+ * @property mixed $poi_id 
+ * @property string $star_msg 
+ * @property mixed $quick 
+ * @property string $unline_msg 
+ * @property mixed $create_at
+ */
+class SaasService extends Model
+{
+    /**
+     * The connection name for the model.
+     *
+     * @var string|null
+     */
+    protected $connection = 'mysql';
+    
+    /**
+     * The table associated with the model.
+     *
+     * @var string
+     */
+    protected string $table = "saas_service";
+    
+    /**
+     * The primary key associated with the table.
+     *
+     * @var string
+     */
+    protected string $primaryKey = "id";
+    
+    /**
+     * Indicates if the model should be timestamped.
+     *
+     * @var bool
+     */
+    public bool $timestamps = false;
+
+    public function quick(): HasMany
+    {
+        return $this->hasMany(SaasServiceQuick::class,"poi_id","poi_id");
+    }
+
+}

+ 46 - 0
app/model/saas/SaasServiceQuick.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace app\model\saas;
+
+use app\extra\basic\Model;
+
+
+/**
+ * @property integer $id (主键)
+ * @property integer $poi_id 
+ * @property string $question 
+ * @property string $answer 
+ * @property mixed $create_at
+ */
+class SaasServiceQuick extends Model
+{
+    /**
+     * The connection name for the model.
+     *
+     * @var string|null
+     */
+    protected $connection = 'mysql';
+    
+    /**
+     * The table associated with the model.
+     *
+     * @var string
+     */
+    protected string $table = "saas_service_quick";
+    
+    /**
+     * The primary key associated with the table.
+     *
+     * @var string
+     */
+    protected string $primaryKey = "id";
+    
+    /**
+     * Indicates if the model should be timestamped.
+     *
+     * @var bool
+     */
+    public bool $timestamps = false;
+
+
+}

+ 37 - 36
app/queue/redis/slow/ImportOrder.php

@@ -40,49 +40,50 @@ class ImportOrder implements Consumer
             $excelData= [];
             $expressData = [];
             foreach ($sheetData as $rowIndex => $row) {
-                if ($rowIndex > 0 && !empty($row['A'])) {
+                if ($rowIndex > 0 && !empty($row['A']) && !empty($row['C'])) {
                     $excelData[$rowIndex] = $row;
                 }
             }
-            print_r($excelData);
             if (!empty($excelData)) {
                 foreach (array_values(array_filter($excelData)) as $key=>$val) {
-                    $order = $orderMode->where("order_sn",trim($val['A']))->findOrEmpty();
-                    if ($order->isEmpty()) {
-                        continue;
-                    }
-                    $order->express_status = 2;
-                    $order->save();
-                    $express = (new SaasOrderExpress)->where("express_sn",trim($val['C']))->findOrEmpty();
-                    if ($express->isEmpty()) {
-                        // 发送一条发货消息给用户
-                        $lastMsg = (new SaasChatMsg)->where(['openid' => $order['openid'],'poi_id' => $order['poi_id']])->order("id desc")->findOrEmpty();
-                        if ($lastMsg->isEmpty()) {
-                            $serviceUser = (new SystemUser)->where(['store_id' => $order['poi_id'],"type" => 3])->order("last_msg_at","asc")->findOrEmpty();
-                            $lastServiceId = $serviceUser['id'];
-                        } else {
-                            $lastServiceId = $lastMsg['service_id'];
+                    if (!empty(trim($val['C'])) && !empty(trim($val['A']))) {
+                        $order = $orderMode->where("order_sn",trim($val['A']))->findOrEmpty();
+                        if ($order->isEmpty()) {
+                            continue;
                         }
-                        $expressName = "";
-                        if (isset($val['D'])) {
-                            $expressName = "({$val['D']})";
+                        $order->express_status = 2;
+                        $order->save();
+                        $express = (new SaasOrderExpress)->where("express_sn",trim($val['C']))->findOrEmpty();
+                        if ($express->isEmpty()) {
+                            // 发送一条发货消息给用户
+                            $lastMsg = (new SaasChatMsg)->where(['openid' => $order['openid'],'poi_id' => $order['poi_id']])->order("id desc")->findOrEmpty();
+                            if ($lastMsg->isEmpty()) {
+                                $serviceUser = (new SystemUser)->where(['store_id' => $order['poi_id'],"type" => 3])->order("last_msg_at","asc")->findOrEmpty();
+                                $lastServiceId = $serviceUser['id'];
+                            } else {
+                                $lastServiceId = $lastMsg['service_id'];
+                            }
+                            $expressName = "";
+                            if (isset($val['D'])) {
+                                $expressName = "({$val['D']})";
+                            }
+                            (new SaasChatMsg)->insertGetId([
+                                'openid' => $order['openid'],
+                                'poi_id' => $order['poi_id'],
+                                "source"    => 2,
+                                "service_id" => $lastServiceId,
+                                "msgId"     => md5($order['openid'].time()),
+                                "content"   => "您的订单({$val['A']})预计3日内到你手中,快递单号:{$val['C']} {$expressName}",
+                                "type"      => "text"
+                            ]);
+                            $expressData[$key] = [
+                                "order_sn"      => trim($val['A']),
+                                "express_sn"    => trim($val['C']),
+                                "mobile"        => trim($val['B']),
+                                "express_name"  => $val['D']?trim($val['D']):'',
+                                "last_at"       => getDateFull()
+                            ];
                         }
-                        (new SaasChatMsg)->insertGetId([
-                            'openid' => $order['openid'],
-                            'poi_id' => $order['poi_id'],
-                            "source"    => 2,
-                            "service_id" => $lastServiceId,
-                            "msgId"     => md5($order['openid'].time()),
-                            "content"   => "您的订单({$val['A']})预计3日内到你手中,快递单号:{$val['C']} {$expressName}",
-                            "type"      => "text"
-                        ]);
-                        $expressData[$key] = [
-                            "order_sn"      => trim($val['A']),
-                            "express_sn"    => trim($val['C']),
-                            "mobile"        => trim($val['B']),
-                            "express_name"  => $val['D']?trim($val['D']):'',
-                            "last_at"       => getDateFull()
-                        ];
                     }
                 }
             }