Browse Source

零售采购库存是否入库
1. xhShopExt 新建字段 cgIn( 0-不入库(default), 1-入库)
- 在 xhCg 采购单上用 cgIn 记录历史值,同时也方便取值(省得要查询 xhShopExt)
2. xhGhs(xhGhsCustom)表中 live=0,则要入库存(最高优先级,不管 cgIn 等于多少)

shizhongqi 10 months ago
parent
commit
c454911ff9

+ 16 - 12
app-hd/controllers/ProductController.php

@@ -423,20 +423,24 @@ class ProductController extends BaseController
                     }
                     //确认收货并入库
                     if ($cg->status == PurchaseClass::STATUS_SENDING) {
-                        // 构建“冲销”函数的参数 -- 变动前的花材存库数据
-                        $purchaseItems = PurchaseItemClass::getAllByCondition(['orderSn' => $cg->orderSn], null, "productId");
-                        $productIds = ArrayHelper::getColumn($purchaseItems, 'productId'); //$productIds 是本次入库涉及的花材ID数组
-                        $oldStocks = [];
-                        foreach ($productIds as $productId) {
-                            $product = ProductClass::getById($productId, true);
-                            $oldStocks[$productId] = $product;
+                        if ($cg->cgIn == 0) { // cgIn: 0-不入库(即得执行冲销), 1-入库
+                            // 构建“冲销”函数的参数 -- 变动前的花材存库数据
+                            $purchaseItems = PurchaseItemClass::getAllByCondition(['orderSn' => $cg->orderSn], null, "productId");
+                            $productIds = ArrayHelper::getColumn($purchaseItems, 'productId'); //$productIds 是本次入库涉及的花材ID数组
+                            $oldStocks = [];
+                            foreach ($productIds as $productId) {
+                                $product = ProductClass::getById($productId, true);
+                                $oldStocks[$productId] = $product;
+                            }
                         }
                         PurchaseClass::takeToPutIn($cg);
-                        // “冲销”本次入库的数量
-                        PurchaseClass::rollbackProductStock($oldStocks, $shop, $adminId, $this->mainId, $this->shopAdmin->name);
-                        if ($doType == 1) {
-                            $transaction->commit();
-                            util::complete('入库成功');
+                        if ($cg->cgIn == 0) {
+                            // “冲销”本次入库的数量
+                            PurchaseClass::rollbackProductStock($oldStocks, $shop, $adminId, $this->mainId, $this->shopAdmin->name);
+                            if ($doType == 1) {
+                                $transaction->commit();
+                                util::complete('入库成功');
+                            }
                         }
                     } else {
                         util::fail('订单不是待入库状态');

+ 8 - 0
app-hd/controllers/PurchaseController.php

@@ -250,6 +250,14 @@ class PurchaseController extends BaseController
             util::fail('不能跟自己的店买花');
         }
 
+        // 判断零售采购库存是否入库
+        if ($ghsInfo['live'] == 0) { //  live=0,则要入库存(最高优先级,不管 cgIn 等于多少)
+            $post['cgIn'] = 1;
+        } else {
+            $shopExt = ShopExtClass::getByCondition(['shopId'=>$this->shopId], false, flase, 'cgIn');
+            $post['cgIn'] = $shopExt['cgIn'];
+        }
+
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {

+ 18 - 14
biz-ghs/order/classes/OrderClass.php

@@ -444,24 +444,28 @@ class OrderClass extends BaseClass
             $staffName = $params['staffName'] ?? '';
             $element = ['staffId' => $staffId, 'staffName' => $staffName];
             self::orderSend($order, $element, true);
-            $cg = PurchaseClass::getById($cgId, true);
+            //$cg = PurchaseClass::getById($cgId, true);
         }
-        // 构建“冲销”函数的参数 -- 变动前的花材存库数据
-        $purchaseItems = PurchaseItemClass::getAllByCondition(['orderSn' => $cg->orderSn], null, "productId");
-        $productIds = ArrayHelper::getColumn($purchaseItems, 'productId'); //$productIds 是本次入库涉及的花材ID数组
-        $oldStocks = [];
-        foreach ($productIds as $productId) {
-            $product = ProductClass::getById($productId, true);
-            $oldStocks[$productId] = $product;
+        if ($cg->cgIn == 0) { // cgIn: 0-不入库(即得执行冲销), 1-入库
+            // 构建“冲销”函数的参数 -- 变动前的花材存库数据
+            $purchaseItems = PurchaseItemClass::getAllByCondition(['orderSn' => $cg->orderSn], null, "productId");
+            $productIds = ArrayHelper::getColumn($purchaseItems, 'productId'); //$productIds 是本次入库涉及的花材ID数组
+            $oldStocks = [];
+            foreach ($productIds as $productId) {
+                $product = ProductClass::getById($productId, true);
+                $oldStocks[$productId] = $product;
+            }
         }
         PurchaseClass::takeToPutIn($cg);
-        $shop = ShopClass::getLockById($shopId);
-        if (empty($shop)) {
-            util::fail('没有找到门店14');
+        if ($cg->cgIn == 0) {
+            $shop = ShopClass::getLockById($shopId);
+            if (empty($shop)) {
+                util::fail('没有找到门店14');
+            }
+            $adminId = $shop->adminId;
+            $mainId = $shop->mainId;
+            PurchaseClass::rollbackProductStock($oldStocks, $shop, $adminId, $mainId, '系统');
         }
-        $adminId = $shop->adminId;
-        $mainId = $shop->mainId;
-        PurchaseClass::rollbackProductStock($oldStocks, $shop, $adminId, $mainId, '系统');
     }
 
     //订单发货主方法 ssh 20231119

+ 5 - 1
biz-hd/cg/classes/CgRefundClass.php

@@ -127,7 +127,7 @@ class CgRefundClass extends BaseClass
         }
 
         // 处理退货退款前,把库存先补回。(本次哪些花材要退多少,就补回多少)
-        if ($refundType == CgRefundClass::REFUND_TYPE_MONEY_GOOD) {
+        if ($refundType == CgRefundClass::REFUND_TYPE_MONEY_GOOD && $cg->cgIn != 1) {
             $field = 'id, cgItemId, itemNum, xhNum';
             $refundItemList = CgRefundItemClass::getAllByCondition(['orderSn' => $refundSn], null, $field, null, true);
             if (empty($refundItemList)) {
@@ -159,6 +159,10 @@ class CgRefundClass extends BaseClass
             $adminId = $cgShop->adminId;
             // 补回本次退货的花材数量
             PurchaseClass::increaseProductStock($itemDatas, $cgShop, $adminId, $cg->mainId, '系统');
+        }else{
+            if ($refundType == CgRefundClass::REFUND_TYPE_MONEY_GOOD && $cg->cgIn == 1) {
+                Yii::info('采购单-'.$cg->orderSn. ' 是正常入库单,不对库存回补');
+            }
         }
 
         if ($refundType == CgRefundClass::REFUND_TYPE_MONEY_GOOD) {

+ 17 - 13
biz-hd/purchase/classes/PurchaseClass.php

@@ -179,22 +179,26 @@ class PurchaseClass extends BaseClass
             $cg = self::orderSend($cg, [], true);
         }
 
-        // 构建“冲销”函数的参数 -- 变动前的花材存库数据
-        $purchaseItems = PurchaseItemClass::getAllByCondition(['orderSn' => $cg->orderSn], null, "productId");
-        $productIds = ArrayHelper::getColumn($purchaseItems, 'productId'); //$productIds 是本次入库涉及的花材ID数组
-        $oldStocks = [];
-        foreach ($productIds as $productId) {
-            $product = ProductClass::getById($productId, true);
-            $oldStocks[$productId] = $product;
+        if ($cg->cgIn == 0) { // cgIn: 0-不入库(即得执行冲销), 1-入库
+            // 构建“冲销”函数的参数 -- 变动前的花材存库数据
+            $purchaseItems = PurchaseItemClass::getAllByCondition(['orderSn' => $cg->orderSn], null, "productId");
+            $productIds = ArrayHelper::getColumn($purchaseItems, 'productId'); //$productIds 是本次入库涉及的花材ID数组
+            $oldStocks = [];
+            foreach ($productIds as $productId) {
+                $product = ProductClass::getById($productId, true);
+                $oldStocks[$productId] = $product;
+            }
         }
         self::takeToPutIn($cg);
-        $shop = ShopClass::getLockById($cg->shopId);
-        if (empty($shop)) {
-            util::fail('没有找到门店14');
+        if ($cg->cgIn == 0) {
+            $shop = ShopClass::getLockById($cg->shopId);
+            if (empty($shop)) {
+                util::fail('没有找到门店14');
+            }
+            $adminId = $shop->adminId;
+            $mainId = $shop->mainId;
+            PurchaseClass::rollbackProductStock($oldStocks, $shop, $adminId, $mainId, '系统');
         }
-        $adminId = $shop->adminId;
-        $mainId = $shop->mainId;
-        PurchaseClass::rollbackProductStock($oldStocks, $shop, $adminId, $mainId, '系统');
     }
 
     //确认收货并入库 ssh 20231119