Browse Source

删除客户

shish 1 năm trước cách đây
mục cha
commit
e47714e7d3

+ 27 - 0
app-ghs/controllers/LiveOrderController.php

@@ -152,4 +152,31 @@ class LiveOrderController extends BaseController
         util::complete('添加成功');
     }
 
+    //删除客户 ssh 20241005
+    public function actionDelCustom()
+    {
+        $post = Yii::$app->request->post();
+        $id = $post['id'] ?? 0;
+        $customId = $post['customId'] ?? 0;
+        $custom = CustomClass::getById($customId, true);
+        if (empty($custom)) {
+            util::fail('没有找到客户');
+        }
+        if ($custom->ownMainId != $this->mainId) {
+            util::fail('不是你的客户');
+        }
+        $live = LiveOrderClass::getById($id, true);
+        if (empty($live)) {
+            util::fail('没有找到记录');
+        }
+        if ($live->mainId != $this->mainId) {
+            util::fail('不是你的记录');
+        }
+        if ($live->switchOrder == 1) {
+            util::fail('已转订单,不能删除');
+        }
+        LiveOrderClass::delCustom($custom, $live);
+        util::complete('添加成功');
+    }
+
 }

+ 20 - 0
biz-ghs/live/classes/LiveOrderClass.php

@@ -13,6 +13,26 @@ class LiveOrderClass extends BaseClass
 
     public static $baseFile = '\bizGhs\live\models\LiveOrder';
 
+    public static function delCustom($custom, $live)
+    {
+        $customId = $custom->id ?? 0;
+        $orderSn = $live->orderSn ?? '';
+        $customList = LiveOrderCustomClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+        $num = 0;
+        if (!empty($customList)) {
+            foreach ($customList as $it) {
+                $currentCustomId = $it->customId ?? 0;
+                if ($currentCustomId == $customId) {
+                    $num = $it->num ?? 0;
+                    $it->delete();
+                }
+            }
+        }
+        $live->customNum = bcsub($live->customNum, 1);
+        $live->itemNum = bcsub($live->itemNum, $num);
+        $live->save();
+    }
+
     public static function addCustom($params, $custom, $live)
     {
         $customId = $custom->id ?? 0;