Browse Source

添加花材

shish 2 năm trước cách đây
mục cha
commit
217469caef

+ 21 - 3
app-ghs/controllers/OrderItemController.php

@@ -26,13 +26,16 @@ class OrderItemController extends BaseController
         if (empty($order)) {
             util::fail('没有订单');
         }
+        if ($order->status != 2) {
+            util::fail('待发货才能添加');
+        }
         if ($order->book == 0) {
             util::fail('不是预订单');
         }
         if (floatval($order->actPrice) != 0) {
             util::fail('订单金额不是0');
         }
-
+        OrderItemClass::bookDelItem($order, $smallId);
         util::complete('删除成功');
     }
 
@@ -47,14 +50,29 @@ class OrderItemController extends BaseController
         if (empty($order)) {
             util::fail('没有订单');
         }
+        if ($order->status != 2) {
+            util::fail('待发货才能添加');
+        }
         if ($order->book == 0) {
             util::fail('不是预订单');
         }
         if (floatval($order->actPrice) != 0) {
             util::fail('订单金额不是0');
         }
-        print_r($arr);
-        die;
+        if (empty($arr)) {
+            util::fail('请选花材');
+        }
+        $new = [];
+        foreach ($arr as $val) {
+            $id = $val['id'] ?? 0;
+            $num = $val['bigCount'] ?? 0;
+            $name = $val['name'] ?? '';
+            if ($num <= 0) {
+                util::fail($name . ' 数量要大于0');
+            }
+            $new[$id] = ['num' => $num, 'productId' => $id];
+        }
+        OrderItemClass::bookAddItem($order, $new);
         util::complete('添加成功');
     }
 

+ 123 - 0
biz-ghs/order/classes/OrderItemClass.php

@@ -5,8 +5,11 @@ namespace bizGhs\order\classes;
 use biz\product\classes\XjClass;
 use biz\stat\classes\StatBookClass;
 use bizGhs\custom\classes\CustomClass;
+use bizGhs\ghs\classes\GhsClass;
 use bizGhs\product\classes\ProductClass;
 use bizGhs\stock\classes\StockRecordClass;
+use bizHd\purchase\classes\PurchaseClass;
+use bizHd\purchase\classes\PurchaseItemClass;
 use common\components\dict;
 use common\components\imgUtil;
 use common\components\orderSn;
@@ -19,6 +22,126 @@ class OrderItemClass extends BaseClass
 
     public static $baseFile = '\bizGhs\order\models\OrderItem';
 
+    //预订单删除花材项 ssh 20240123
+    public static function bookDelItem($order, $smallId)
+    {
+
+    }
+
+    //预订单添加花材项 ssh 20240123
+    public static function bookAddItem($order, $itemList)
+    {
+        $orderSn = $order->orderSn ?? '';
+        $addIds = array_column($itemList, 'productId');
+        $existList = self::getAllByCondition(['orderSn' => $orderSn], null, '*');
+        foreach ($existList as $ex) {
+            $productId = $ex['productId'] ?? 0;
+            $name = $ex['name'] ?? '';
+            if (in_array($productId, $addIds)) {
+                util::fail($name . ' 已经存在');
+            }
+        }
+        $addInfo = ProductClass::getByIds($addIds, null, 'id');
+        if (empty($addInfo)) {
+            util::fail('没有花材');
+        }
+        $productList = [];
+        foreach ($itemList as $item) {
+            $num = $item['num'] ?? 0;
+            $productId = $item['productId'] ?? 0;
+            $info = $addInfo[$productId] ?? [];
+            $current = [];
+            $current['name'] = $info['name'] ?? '';
+            $current['cover'] = $info['cover'] ?? '';
+            $current['orderSn'] = $orderSn;
+            $ptItemId = $info['itemId'] ?? 0;
+            $current['itemId'] = $ptItemId;
+            $current['productId'] = $productId;
+            $classId = $info['classId'] ?? 0
+            $current['classId'] = $classId;
+            $current['variety'] = $info['variety'] ?? 0;
+            $current['shopId'] = $info['shopId'] ?? 0;
+            $current['mainId'] = $info['mainId'] ?? 0;
+
+            $current['smallUnit'] = $info['smallUnit'] ?? 0;
+            $current['bigUnit'] = $info['bigUnit'] ?? 0;
+            $current['price'] = 0;
+
+            $current['unitWeight'] = $info['weight'] ?? 0;
+            $current['cost'] = $info['cost'] ?? 0;
+            $current['num'] = $num;
+            $current['bigNum'] = $num;
+            $current['preNum'] = $num;
+            $current['preBigNum'] = $num;
+            $current['ratio'] = $info['ratio'] ?? 20;
+            $current['variety'] = $info['variety'] ?? 0;
+
+            $current['xhNum'] = $num;
+            $current['xhUnitName'] = $info['bigUnit'] ?? '';
+            $current['xhUnitType'] = 0;
+            $current['xhPreNum'] = $num;
+            $current['xhPreUnitName'] = $info['bigUnit'] ?? '';
+            $current['xhPreUnitType'] = 0;
+            self::add($current);
+
+            $productList[] = [
+                'productId' => $productId,
+                'bigNum' => $num,
+                'smallNum' => 0,
+                'classId' => $classId,
+                'itemId' => $ptItemId,
+                'userPrice' => 0,
+            ];
+        }
+        $shopId = $order->shopId ?? 0;
+        $sjId = $order->sjId ?? 0;
+        $mainId = $order->mainId ?? 0;
+        $ghsId = $order->ghsId ?? 0;
+        $ghs = GhsClass::getById($ghsId, true);
+        if (empty($ghs)) {
+            util::fail('供货商无效');
+        }
+        $productList = ProductClass::toggleProductList($productList, $shopId, $sjId, $mainId, $ghs);
+        $cgId = $order->purchaseId ?? 0;
+        $cg = PurchaseClass::getById($cgId, true);
+        if (empty($cg)) {
+            util::fail('没有采购信息');
+        }
+        $cgProductIds = array_column($productList, 'productId');
+        $cgProductInfoList = ProductClass::getByIds($cgProductIds, null, 'id');
+        $cgOrderSn = $cg->orderSn ?? '';
+
+        foreach ($productList as $key => $val) {
+            $productId = $val['productId'] ?? 0;
+            $num = $val['num'] ?? 0;
+            $ghsProductId = $val['ghsProductId'] ?? 0;
+            $thisInfo = $cgProductInfoList[$productId] ?? [];
+            $newItem = [];
+            $newItem['name'] = $thisInfo['name'] ?? '';
+            $newItem['cover'] = $thisInfo['cover'] ?? '';
+            $newItem['orderSn'] = $cgOrderSn;
+            $newItem['productId'] = $productId;
+            $newItem['itemId'] = $thisInfo['itemId'] ?? 0;
+            $newItem['mainId'] = $cg->mainId ?? 0;
+            $newItem['ghsId'] = $ghsId;
+            $newItem['itemNum'] = $num;
+            $newItem['preItemNum'] = $num;
+            $newItem['ghsProductId'] = $ghsProductId;
+            $newItem['ratio'] = $thisInfo['ratio'] ?? 0
+            $newItem['price'] = 0;
+            $newItem['variety'] = $thisInfo['variety'] ?? 0
+            $newItem['unitWeight'] = $thisInfo['weight'] ?? 0
+            $newItem['xhNum'] = $num;
+            $newItem['xhUnitName'] = $thisInfo['bigUnit'] ?? '';
+            $newItem['xhUnitType'] = 0;
+            $newItem['xhPreNum'] = $num;
+            $newItem['xhPreUnitName'] = $thisInfo['bigUnit'] ?? '';
+            $newItem['xhPreUnitType'] = 0;
+            PurchaseItemClass::add($newItem);
+        }
+
+    }
+
     public static function giveItem($order, $orderItem, $product, $num, $data)
     {
         $productId = $product->id ?? 0;