Zory 1 bulan lalu
induk
melakukan
6ce7505938

+ 1 - 0
app/controller/api/Goods.php

@@ -60,6 +60,7 @@ class Goods extends Base
             $param['openid'] = $request->user['openid'];
             $param['sku_name'] = $param['name'];
             $param['poi_id'] = $goods['poi_id'];
+            $param['goods_id'] = $goods['id'];
             $state = (new SaasOrder)->setAutoData($param);
             if (!$state) return error("提交订单失败");
             return success("提交成功",['order' => $param['order_sn']]);

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

@@ -3,6 +3,7 @@
 namespace app\controller\api;
 
 use app\extra\basic\Base;
+use app\extra\dyLife\Crypt;
 use app\extra\dyMini\Pay;
 use app\middleware\AuthMiddleware;
 use app\model\saas\SaasOrder;
@@ -43,6 +44,30 @@ class Order extends Base
     }
 
 
+    #[PostMapping("refund")]
+    public function orderRefund(Request $request): Response
+    {
+        try {
+            $param = $this->_valid([
+                "order.require" => trans("empty.require"),
+                "refund.require" => trans("empty.require"),
+            ],$request->method());
+            if (!is_array($param)) return error($param);
+            $order = $this->model->where("order_sn",$param['order'])->with(['product','poi'])->findOrEmpty();
+            if ($order->isEmpty()) return errorTrans("empty.data");
+            if ($order['openid'] <> $request->user['openid']) return errorTrans("empty.data");
+            if ($order['status'] <> 1) return error("当前订单不支持退款");
+            $order->status = 4;
+            $order->refund_apply = getDateFull();
+            $state = $order->save();
+            if (!$state) return errorTrans("error.data");
+            return successTrans("提交申请成功");
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+
     #[GetMapping('detail')]
     public function getDataDetail(Request $request): Response
     {
@@ -113,4 +138,50 @@ class Order extends Base
         }
     }
 
+    #[PostMapping("mobile")]
+    public function getOrderMobile(Request $request)
+    {
+        try {
+            $param = $request->post();
+            $mobile = [];
+            if (!empty($param['code'])) {
+                $mobileStr = (new Crypt)->config($this->getDyConfig())->token()->getMobile($param['code']);
+                if (!empty($mobileStr)) {
+                    $mobile = $this->decrypt2code(sConf('wechat.min_private_key'), $mobileStr);
+                }
+            }
+            $mobileStr = "";
+            if (!empty($mobile['purePhoneNumber'])) {
+                $mobileStr = $mobile['purePhoneNumber'];
+            }
+            return success("ok",['mobile' => $mobileStr]);
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+    protected function decrypt2code($private_key, $ciphertext_str) {
+        // 解码 base64 密文
+        $ciphertext = base64_decode($ciphertext_str);
+
+        // 使用私钥解密
+        openssl_private_decrypt($ciphertext, $plaintext, $private_key, OPENSSL_PKCS1_PADDING);
+
+        if ($plaintext === false) {
+            return [];
+        }
+        return json_decode($plaintext,true);
+    }
+
+
+    protected function decrypt($encrypted_data, $session_key, $iv) {
+        $data = base64_decode($encrypted_data);
+        $key = base64_decode($session_key);
+        $iv_decoded = base64_decode($iv);
+        // 使用 AES-256-CBC 模式解密
+        $decrypted = openssl_decrypt($data, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv_decoded);
+
+        return $decrypted;
+    }
+
 }

+ 31 - 3
app/controller/api/Service.php

@@ -4,8 +4,12 @@ namespace app\controller\api;
 
 use app\extra\basic\Base;
 use app\middleware\AuthMiddleware;
+use app\model\saas\SaasChatMsg;
+use app\model\saas\SaasChatStore;
 use app\model\saas\SaasStore;
 use app\model\system\SystemUser;
+use app\service\saas\ChatStoreService;
+use DI\Attribute\Inject;
 use LinFly\Annotation\Attributes\Route\Controller;
 use LinFly\Annotation\Attributes\Route\GetMapping;
 use LinFly\Annotation\Attributes\Route\Middleware;
@@ -18,17 +22,33 @@ use support\Response;
 class Service extends Base
 {
 
+    #[Inject]
+    protected ChatStoreService $service;
 
     /**
      * 获取客服列表-已聊过的
      * @param Request $request
-     * @return Response|void
+     * @return Response
      */
     #[GetMapping("list")]
-    public function getServiceList(Request $request)
+    public function getServiceList(Request $request): Response
     {
         try {
-            
+            $param = $request->all();
+            if (!empty($param['size'])) {
+                $param['pageSize'] = $param['size'];
+            }
+            $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();
+                if ($last->isEmpty()) {
+                    return ["content"=>"无","create_at"=> formatTime(date("Y-m-d H:i:s",time()))];
+                }
+                return ["content"=> $last['content'],"create_at"=> formatTime($last['create_at'])];
+            },'avatar' => function(){
+                return "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png";
+            }]);
+            return successTrans("success.data",pageFormat($list));
         } catch (\Throwable $throwable) {
             return error($throwable->getMessage());
         }
@@ -46,6 +66,14 @@ class Service extends Base
             $param = $request->all();
             $store = (new SaasStore)->where("poi_id",$param['poi'])->findOrEmpty();
             if ($store->isEmpty()) return error("店铺不存在");
+            $chatStore = (new SaasChatStore)->where(['poi_id'=> $store['poi_id'],"openid" => $request->user['openid']])->findOrEmpty();
+            if ($chatStore->isEmpty()) {
+                $chatStore->insertGetId([
+                    "poi_id"    => $store['poi_id'],
+                    "poi_name"  => $store['poi_name'],
+                    "openid"    => $request->user['openid']
+                ]);
+            }
             // 获取在线客服
             $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]); // 无客服在线

+ 38 - 0
app/controller/api/User.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace app\controller\api;
+
+use app\extra\basic\Base;
+use app\middleware\AuthMiddleware;
+use app\model\saas\SaasUserOpen;
+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("/dy/user"),Middleware(AuthMiddleware::class)]
+class User extends Base
+{
+
+
+    #[Inject]
+    protected SaasUserOpen $model;
+
+    #[GetMapping("data")]
+    public function getUserData(Request $request): Response
+    {
+        try {
+            $data = $this->model->where("openid",$request->user['openid'])->field("openid,nickname")->append(['avatar'])->withAttr(['avatar' => function () {
+                return "https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png";
+            }])->findOrEmpty();
+            if ($data->isEmpty()) return errorTrans("error.data");
+            return success("ok",$data->toArray());
+        } catch (\Throwable $th) {
+            return error($th->getMessage());
+        }
+    }
+
+}

+ 1 - 1
app/extra/dyMini/Pay.php

@@ -12,7 +12,7 @@ class Pay extends BasicLife
     {
         $url = "https://developer.toutiao.com/api/apps/ecpay/v1/create_order";
         $param = [
-            "out_order_no"  => $data['order_sn'],
+            "out_order_no"  => $data['order_sn'].rand(1000,9999),
             "total_amount"  => (int) $data['total'],
             "subject"       => $data['name'],
             "body"          => $data['name'],

+ 28 - 0
app/functions.php

@@ -517,4 +517,32 @@ if (!function_exists("extractNodesClean"))
         }
         return $result;
     }
+}
+if (!function_exists("formatTime"))
+{
+    /**
+     * 格式化时间:今天、昨天、前天、正常日期
+     * @param string $timestamp 时间戳 或 日期字符串
+     * @return string
+     */
+    function formatTime(string $timestamp): string
+    {
+        // 先统一转成时间戳
+        $time = is_numeric($timestamp) ? $timestamp : strtotime($timestamp);
+
+        $today = strtotime('today');       // 今天 00:00
+        $yesterday = strtotime('yesterday'); // 昨天 00:00
+        $beforeYesterday = strtotime('-2 days'); // 前天 00:00
+
+        if ($time >= $today) {
+            return '今天';
+        } elseif ($time >= $yesterday) {
+            return '昨天';
+        } elseif ($time >= $beforeYesterday) {
+            return '前天';
+        } else {
+            // 其他时间返回正常格式
+            return date('Y-m-d', $time);
+        }
+    }
 }

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

@@ -0,0 +1,46 @@
+<?php
+
+namespace app\model\saas;
+
+use app\extra\basic\Model;
+
+
+/**
+ * @property integer $id (主键)
+ * @property mixed $openid 
+ * @property mixed $poi_id 店铺ID
+ * @property string $poi_name 店铺名称
+ * @property mixed $create_at
+ */
+class SaasChatStore 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_chat_store";
+    
+    /**
+     * 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;
+
+
+}

+ 36 - 0
app/service/saas/ChatStoreService.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace app\service\saas;
+
+use app\extra\basic\Service;
+use app\model\saas\SaasChatStore;
+
+class ChatStoreService extends Service
+{
+    /**
+     *
+     * @return $this
+     */
+    public function setModel()
+    {
+        $this->mode = (new SaasChatStore);
+        return $this;
+    }
+
+
+    /**
+     *
+     * @param array $param
+     * @return array
+     */
+    public function searchFilter(array $param = []): array
+    {
+        $filter = [];
+        !empty($param['openid']) && $filter[] = ["openid", '=', $param['openid']];
+        !empty($param['status']) && $filter[] = ["status", '=', $param['status']];
+        !empty($param['type']) && $filter[] = ["type", '=', $param['type']];
+        !empty($param['name']) && $filter[] = ["poi_name", 'like', "%{$param['name']}%"];
+        return $filter;
+    }
+
+}

TEMPAT SAMPAH
归档.zip