shish 4 år sedan
förälder
incheckning
c8e0bdd742
2 ändrade filer med 60 tillägg och 61 borttagningar
  1. 33 24
      app-ghs/controllers/StockOutController.php
  2. 27 37
      biz-ghs/order/classes/StockOutOrderClass.php

+ 33 - 24
app-ghs/controllers/StockOutController.php

@@ -55,32 +55,41 @@ class StockOutController extends BaseController
             util::fail('花材格式不正确');
         }
 
-        //入库门店有效性判断
-        if ($this->shopId == $inShopId) {
-            util::fail('不能出库给当前门店');
-        }
-        $inShop = ShopClass::getById($inShopId);
-        if (empty($inShop)) {
-            util::fail('没有找到门店');
-        }
-        ShopClass::valid($inShop, $this->sjId);
-        $post['inMainId'] = $inShop->mainId ?? 0;
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
 
-        ProductClass::valid($ghsItemInfo, $this->mainId);
-        //判断花材里的信息
-        foreach ($ghsItemInfo as $v) {
-            $bigNum = $v['bigNum'] ?? 0;
-            $smallNum = $v['smallNum'] ?? 0;
-            if ($bigNum <= 0 && $smallNum <= 0) {
-                util::fail('花材数量不能为0');
+        try {
+
+            //入库门店有效性判断
+            if ($this->shopId == $inShopId) {
+                util::fail('不能出库给当前门店');
             }
-        }
-        $post['itemInfo'] = $ghsItemInfo;
-        $order = StockOutOrderClass::addOrder($post);
-        if ($order) {
-            util::success($order);
-        } else {
-            util::fail();
+            $inShop = ShopClass::getById($inShopId);
+            if (empty($inShop)) {
+                util::fail('没有找到门店');
+            }
+            ShopClass::valid($inShop, $this->sjId);
+            $post['inMainId'] = $inShop->mainId ?? 0;
+
+            ProductClass::valid($ghsItemInfo, $this->mainId);
+            //判断花材里的信息
+            foreach ($ghsItemInfo as $v) {
+                $bigNum = $v['bigNum'] ?? 0;
+                $smallNum = $v['smallNum'] ?? 0;
+                if ($bigNum <= 0 && $smallNum <= 0) {
+                    util::fail('花材数量不能为0');
+                }
+            }
+            $post['itemInfo'] = $ghsItemInfo;
+            $order = StockOutOrderClass::addOrder($post);
+            if ($order) {
+                $transaction->commit();
+                util::success($order);
+            }
+            util::fail('出库失败');
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            util::fail('出库失败');
         }
     }
 

+ 27 - 37
biz-ghs/order/classes/StockOutOrderClass.php

@@ -47,48 +47,38 @@ class StockOutOrderClass extends BaseClass
         $outShopId = $data['outShopId'] ?? 0;
         $outMainId = $data['outMainId'] ?? 0;
 
-        $connection = Yii::$app->db;
-        $transaction = $connection->beginTransaction();
-
-        try {
-            $order = self::add($data);
-            //先减库存,若取消出库则加回来
-            foreach ($ghsItemInfo as $k => $v) {
-                $stockInfo = ProductClass::decreaseStock($v['productId'], $v['bigNum'], $v['smallNum'], true);
-                $ghsItemInfo[$k]['oldStock'] = $stockInfo['oldStock'];
-                $ghsItemInfo[$k]['newStock'] = $stockInfo['newStock'];
-            }
 
-            //写入详情表
-            $batchData = self::groupOrderItem($ghsItemInfo, $orderSn);
-            foreach ($batchData as $outKey => $outVal) {
-                $batchData[$outKey]['mainId'] = $outMainId;
-                $batchData[$outKey]['shopId'] = $outShopId;
-            }
-            StockOutOrderItemClass::batchAddOrderItem($batchData);
+        $order = self::add($data);
+        //先减库存,若取消出库则加回来
+        foreach ($ghsItemInfo as $k => $v) {
+            $stockInfo = ProductClass::decreaseStock($v['productId'], $v['bigNum'], $v['smallNum'], true);
+            $ghsItemInfo[$k]['oldStock'] = $stockInfo['oldStock'];
+            $ghsItemInfo[$k]['newStock'] = $stockInfo['newStock'];
+        }
 
-            $orderData = self::getOrderDetail($orderSn, $data['outShopId']);
-            $orderData['shopId'] = $outShopId;
-            $orderData['mainId'] = $outMainId;
-            $itemInfo = $orderData['itemInfo'] ?? [];
-            if (empty($itemInfo)) {
-                $transaction->rollBack();
-                util::fail("订单异常");
-            }
-            //写流水
-            StockRecordClass::addRecordByOrder($orderData, StockRecordClass::STOCK_RECORD_TYPE_OUT_STOCK);
+        //写入详情表
+        $batchData = self::groupOrderItem($ghsItemInfo, $orderSn);
+        foreach ($batchData as $outKey => $outVal) {
+            $batchData[$outKey]['mainId'] = $outMainId;
+            $batchData[$outKey]['shopId'] = $outShopId;
+        }
+        StockOutOrderItemClass::batchAddOrderItem($batchData);
 
-            $transaction->commit();
-            if ($action === self::ACTION_CONFIRM) {
-                //直接出库=》待入库
-                self::confirmOrder($orderSn, $data['outShopId'], $data['adminId']);
-            }
-            return $order;
-        } catch (\Exception $exception) {
+        $orderData = self::getOrderDetail($orderSn, $data['outShopId']);
+        $orderData['shopId'] = $outShopId;
+        $orderData['mainId'] = $outMainId;
+        $itemInfo = $orderData['itemInfo'] ?? [];
+        if (empty($itemInfo)) {
             $transaction->rollBack();
-            util::fail('保存失败' . $exception->getMessage());
+            util::fail("订单异常");
         }
-
+        //写流水
+        StockRecordClass::addRecordByOrder($orderData, StockRecordClass::STOCK_RECORD_TYPE_OUT_STOCK);
+        if ($action === self::ACTION_CONFIRM) {
+            //直接出库=》待入库
+            self::confirmOrder($orderSn, $data['outShopId'], $data['adminId']);
+        }
+        return $order;
     }