Zory преди 1 седмица
родител
ревизия
ac322b12b2
променени са 6 файла, в които са добавени 188 реда и са изтрити 8 реда
  1. 37 0
      app/controller/admin/Order.php
  2. 3 0
      app/controller/api/Order.php
  3. 58 5
      app/controller/api/Service.php
  4. 1 0
      app/controller/common/Login.php
  5. 65 3
      app/controller/service/Service.php
  6. 24 0
      app/functions.php

+ 37 - 0
app/controller/admin/Order.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace app\controller\admin;
+
+use app\extra\basic\Base;
+use app\middleware\AuthMiddleware;
+use app\service\saas\OrderService;
+use DI\Attribute\Inject;
+use LinFly\Annotation\Attributes\Route\Controller;
+use LinFly\Annotation\Attributes\Route\GetMapping;
+use LinFly\Annotation\Attributes\Route\Middleware;
+use support\Request;
+use support\Response;
+
+
+#[Controller("/api/order"),Middleware(AuthMiddleware::class)]
+class Order extends Base
+{
+
+    #[Inject]
+    protected OrderService $service;
+
+    #[GetMapping('list')]
+    public function getOrderList(Request $request): Response
+    {
+        try {
+            $param = $request->all();
+            $data = $this->service->setModel()->getList($param,['product' => function($query){
+                $query->field("product_id,product_name");
+            }]);
+            return successTrans("success.data",pageFormat($data),200);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+}

+ 3 - 0
app/controller/api/Order.php

@@ -37,6 +37,9 @@ class Order extends Base
             if (!empty($param['size'])) {
                 $param['pageSize'] = $param['size'];
             }
+            if ($param['status'] > 0) {
+                $param['status'] = $param['status'] - 1;
+            }
             $param['openid'] = $request->user['openid'];
             $data = $this->service->setModel()->getList($param);
             return successTrans("success.data",pageFormat($data));

+ 58 - 5
app/controller/api/Service.php

@@ -16,6 +16,7 @@ use LinFly\Annotation\Attributes\Route\Middleware;
 use LinFly\Annotation\Attributes\Route\PostMapping;
 use support\Request;
 use support\Response;
+use Webman\Push\Api;
 
 
 #[Controller("/dy/service"),Middleware(AuthMiddleware::class)]
@@ -83,11 +84,35 @@ class Service extends Base
                 return "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png";
             },'time' => function($resp,$data){
                 return strtotime($data['create_at']) * 1000;
-            }])->paginate([
+            }])->order("id","desc")->paginate([
                 "list_rows" => 10,
                 "page"      => 1
             ]);
-            return $this->encode("ok",['store' => $store,'code' => 1,'sendId' => $request->user['openid'],'msg' => pageFormat($msg)]); // 客服在线
+            return $this->encode("ok",['store' => $store,'code' => 1,'sendId' => $request->user['openid'],'msg' => pageFormatMsg($msg),"serviceId" => $service['id']]); // 客服在线
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+    #[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);
+            $msg = (new SaasChatMsg)->where(['openid' => $request->user['openid'],'poi_id' => $param['poi']])->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;
+            }])->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());
         }
@@ -102,10 +127,38 @@ class Service extends Base
     public function sendMsg(Request $request): Response
     {
         try {
-            $param = $request->all();
-
-            return error("err");
+            $param = $this->_valid([
+                "content.require"   => trans("empty.require"),
+                "groupId.require"   => trans("empty.require"),
+                "type.require"      => trans("empty.require"),
+                "sendId.require"    => trans("empty.require"),
+            ],"post");
+            if (!is_array($param)) return error($param);
+            $state = (new SaasChatMsg)->insertGetId([
+                "source"    => 1,
+                "openid"    => $request->user['openid'],
+                "content"   => is_array($param['content'])?json_encode($param['content']):$param['content'],
+                "type"      => $param['type'],
+                "msgId"     => time(),
+                "poi_id"    => $param['groupId'],
+                "service_id" => $param['sendId'],
+            ]);
+            $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("service-{$param['sendId']}","message",[
+                "type"  =>  $param['type'],
+                "time"  =>  time() * 1000,
+                "msgId" => time(),
+                "content"   => is_array($param['content'])?json_encode($param['content']):$param['content'],
+                "source" => 1,
+                "avatar"    => "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png",
+                "poi_id"    => $param['groupId'],
+                "openid"  => $request->user['openid'],
+                "service_id"  => $param['sendId'],
+                "create_at"  => formatTime(time()),
+            ]);
+            return successTrans("success.data");
         } catch (\Throwable $throwable) {
+            echo $throwable->getMessage()."\n";
             return error($throwable->getMessage());
         }
     }

+ 1 - 0
app/controller/common/Login.php

@@ -107,6 +107,7 @@ class Login extends Base
             }
             return successTrans("success.data",[
                 "username"  => $userData['username'],
+                "userId"    => $userData['id'],
                 "truename"  => $userData['truename'],
                 "vip_at"    => $userData['vip_end'],
                 "agent_id"  => $userData['agent_id'],

+ 65 - 3
app/controller/service/Service.php

@@ -11,8 +11,10 @@ use DI\Attribute\Inject;
 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;
+use Webman\Push\Api;
 
 
 #[Controller("/api/service/chat"),Middleware(AuthMiddleware::class)]
@@ -34,13 +36,13 @@ class Service extends Base
             $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");
+                $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,"create_at"=> formatTime(date("Y-m-d H:i:s",time()))];
+                    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']),'type' => $last['type']];
+                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";
             }]);
@@ -50,4 +52,64 @@ class Service extends Base
         }
     }
 
+    #[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;
+            }])->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());
+        }
+    }
+
+    #[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"     => 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" => 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());
+        }
+    }
+
 }

+ 24 - 0
app/functions.php

@@ -360,6 +360,30 @@ if (!function_exists("pageFormat")) {
     }
 }
 
+if (!function_exists("pageFormatMsg")) {
+    /**
+     * @param $data
+     * @param int $size
+     * @return array {page:"",pageSize:"",rows:[],total:""}
+     */
+    function pageFormatMsg($data, int $size = 10): array
+    {
+        if (empty($data)) return [];
+        $rowsData = [];
+        if ($data->total() > 0) {
+            foreach ($data as $key=>$row) {
+                $rowsData[$key] = $row->toArray();
+            }
+        }
+        return [
+            'total'     => $data->total(),
+            'page'      => $data->currentPage(),
+            'pageSize'  => $size,
+            'rows'      => list_sort_by($rowsData,"id","asc")
+        ];
+    }
+}
+
 
 if(!function_exists('format_money')){
     function format_money($str,$len = '2',$append = ""): string