浏览代码

add - 取消抖音订单

liugc 11 月之前
父节点
当前提交
6c2fd0b31c
共有 3 个文件被更改,包括 52 次插入3 次删除
  1. 16 1
      app/api/controller/DouYinController.php
  2. 25 0
      app/api/service/DouYinService.php
  3. 11 2
      app/common/lists/BaseDataLists.php

+ 16 - 1
app/api/controller/DouYinController.php

@@ -161,7 +161,22 @@ class DouYinController extends BaseApiController
             return $this->fail($e->getMessage());
         }
     }
-
+    /**
+     * 取消订单
+     * @return \think\response\Json
+     * @author liugc <466014217@qq.com>
+     * @date 2025/5/22 14:35
+     */
+    public function cancelOrder()
+    {
+        try {
+            $params = $this->request->post(); // order_number
+            DouYinService::cancelOrder($params);
+            return $this->success();
+        } catch (\Exception $e) {
+            return $this->fail($e->getMessage());
+        }
+    }
     /**
      * 支付回调
      * @return \think\response\Json

+ 25 - 0
app/api/service/DouYinService.php

@@ -121,6 +121,31 @@ class DouYinService
         }
     }
 
+
+    public static function cancelOrder($params)
+    {
+        // $params['order_number']
+        Db::startTrans();
+        try {
+            $order = DouyinOrder::where('order_number', $params['order_number'])->findOrEmpty();
+            if(!$order->isEmpty()){
+                if($order->order_status == 1 && $order->pay_status == 0){
+                    $order->order_status = 4;
+                    $order->save();
+                }else{
+                    throw new \Exception('订单状态不可取消!');
+                }
+            }
+            Db::commit();
+            return $order['id'];
+        } catch (\Exception $e) {
+            Db::rollback();
+            throw new \Exception($e->getMessage());
+        }
+    }
+
+
+
     public static function payNotify($params)
     {
             //Log::write(json_encode($params));

+ 11 - 2
app/common/lists/BaseDataLists.php

@@ -70,6 +70,12 @@ abstract class BaseDataLists implements ListsInterface
 
         $this->params = $this->request->param();
 
+        $this->initController();
+    }
+
+
+    public function initController()
+    {
         //初始化租户
         $this->initTenant();
 
@@ -86,7 +92,6 @@ abstract class BaseDataLists implements ListsInterface
         $this->initExport();
     }
 
-
     public function initTenant()
     {
         if(!empty($this->request->adminInfo['tenant_id'])){
@@ -232,9 +237,13 @@ abstract class BaseDataLists implements ListsInterface
     public function setParams($params): self
     {
         $this->params = $params;
+        $this->initController();
         return $this;
     }
-
+    public function getParams(): array
+    {
+        return $this->params;
+    }
     public function setExcelComplexFields(): array
     {
         return [];