Browse Source

添加客户

shish 1 year ago
parent
commit
a6b6bfc223

+ 38 - 7
app-ghs/controllers/LiveOrderController.php

@@ -2,6 +2,7 @@
 
 namespace ghs\controllers;
 
+use bizGhs\custom\classes\CustomClass;
 use bizGhs\live\classes\LiveOrderClass;
 use bizGhs\live\classes\LiveOrderCustomClass;
 use bizGhs\product\classes\ProductClass;
@@ -108,17 +109,47 @@ class LiveOrderController extends BaseController
     public function actionGetDetail()
     {
         $get = Yii::$app->request->get();
-        $id = $get['id']??0;
-        $live = LiveOrderClass::getById($id,true);
-        if(empty($live)){
+        $id = $get['id'] ?? 0;
+        $live = LiveOrderClass::getById($id, true);
+        if (empty($live)) {
             util::fail('没有找到记录');
         }
-        if($live->mainId != $this->mainId){
+        if ($live->mainId != $this->mainId) {
             util::fail('不是你的记录');
         }
-        $orderSn = $live->orderSn??'';
-        $customList = LiveOrderCustomClass::getAllByCondition(['orderSn'=>$orderSn],null,'*');
-        util::success(['customList'=>$customList,'info'=>$live]);
+        $orderSn = $live->orderSn ?? '';
+        $customList = LiveOrderCustomClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
+        util::success(['customList' => $customList, 'info' => $live]);
+    }
+
+    //添加客户 ssh 20241005
+    public function actionAddCustom()
+    {
+        $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->mainId != $this->mainId) {
+            util::fail('不是你的客户');
+        }
+        $num = $post['num'] ?? 0;
+        $price = $post['price'] ?? 0;
+        $live = LiveOrderClass::getById($id, true);
+        if (empty($live)) {
+            util::fail('没有找到记录');
+        }
+        if ($live->mainId != $this->mainId) {
+            util::fail('不是你的记录');
+        }
+        if ($live->switchOrder == 1) {
+            util::fail('已转订单,不能添加');
+        }
+        $params = ['num' => $num, 'price' => $price];
+        LiveOrderClass::addCustom($params, $custom, $live);
+        util::complete('添加成功');
     }
 
 }

+ 13 - 0
app-ghs/controllers/LiveOrderCustomController.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace ghs\controllers;
+
+use common\components\dateUtil;
+use common\components\stringUtil;
+use common\components\util;
+use Yii;
+
+class LiveOrderCustomController extends BaseController
+{
+
+}

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

@@ -13,6 +13,39 @@ class LiveOrderClass extends BaseClass
 
     public static $baseFile = '\bizGhs\live\models\LiveOrder';
 
+    public static function addCustom($params, $custom, $live)
+    {
+        $customId = $custom->id ?? 0;
+        $orderSn = $live->orderSn ?? '';
+        $customList = LiveOrderCustomClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
+        if (!empty($customList)) {
+            foreach ($customList as $it) {
+                $currentCustomId = $it->customId ?? 0;
+                if ($currentCustomId == $customId) {
+                    util::fail('客户已经存在');
+                }
+            }
+        }
+        $customName = $custom->name ?? '';
+        $num = $params['num'] ?? 0;
+        $unitPrice = $params['price'] ?? 0;
+        $price = bcmul($unitPrice, $num, 2);
+        $data = [
+            'mainId' => $live->mainId,
+            'orderSn' => $orderSn,
+            'customName' => $customName,
+            'customId' => $customId,
+            'num' => $num,
+            'unitPrice' => $unitPrice,
+            'unitName' => '',
+            'price' => $price,
+        ];
+        LiveOrderCustomClass::add($data, true);
+        $live->customNum = bcadd($live->customNum, 1);
+        $live->itemNum = bcadd($live->itemNum, $num);
+        $live->save();
+    }
+
     public static function getOrderList($where)
     {
         $data = self::getList('*', $where, 'addTime DESC');