shish hai 1 ano
pai
achega
5aa1d33d55
Modificáronse 2 ficheiros con 78 adicións e 16 borrados
  1. 25 16
      app-ghs/controllers/ItemController.php
  2. 53 0
      biz-ghs/item/classes/ItemClass.php

+ 25 - 16
app-ghs/controllers/ItemController.php

@@ -24,6 +24,9 @@ class ItemController extends BaseController
     //挪到处理区 ssh 20250418
     public function actionMoveToLosing()
     {
+        //避免重复提交
+        util::checkRepeatCommit($this->adminId, 4);
+
         $get = Yii::$app->request->get();
         $id = $get['id'] ?? '';
         $num = $get['num'] ?? 0;
@@ -37,23 +40,29 @@ class ItemController extends BaseController
         if ($num <= 0) {
             util::fail('请输入数量');
         }
-        $stock = $item->stock ?? 0;
-        $stock = floatval($stock);
-        if ($num > $stock) {
-            util::fail('剩' . $stock . '可以挪动');
-        }
-        $shopId = $this->shopId;
-        $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
-        $getItemId = $ext->losingItem ?? 0;
-        if (empty($getItemId)) {
-            util::fail('没有设置处理区花材');
-        }
-        $getItem = ItemClass::getById($getItemId, true);
-        if (empty($getItem)) {
-            util::fail('没有设置处理区花材哈');
+        $remark = '挪到处理区';
+        $staff = $this->shopAdmin;
+        $staffName = $staff->name ?? '';
+        $staffId = $staff->id;
+        $adminId = $this->adminId;
+        $params = [
+            'staffId' => $staffId,
+            'staffName' => $staffName,
+            'adminId' => $adminId,
+            'remark' => $remark,
+        ];
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $shop = $this->shop;
+            ItemClass::moveLose($item, $num, $shop, $params);
+            $transaction->commit();
+            util::complete('挪动成功');
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::info("挪动失败原因:" . $e->getMessage());
+            util::fail('挪动失败');
         }
-
-        util::complete('挪动成功');
     }
 
     //设为处理区用的花材 ssh 20250418

+ 53 - 0
biz-ghs/item/classes/ItemClass.php

@@ -5,6 +5,7 @@ namespace bizGhs\item\classes;
 use biz\item\classes\PtItemCatClass;
 use biz\item\classes\PtItemCatRelateClass;
 use biz\item\classes\PtItemClass;
+use biz\shop\classes\ShopExtClass;
 use bizGhs\base\classes\BaseClass;
 use bizGhs\book\classes\BookItemClass;
 use bizGhs\order\classes\CheckOrderClass;
@@ -18,6 +19,58 @@ class ItemClass extends BaseClass
 
     public static $baseFile = '\bizGhs\item\models\Item';
 
+    public static function moveLose($outItem, $num, $shop, $params)
+    {
+        $sjId = $shop->sjId;
+        $mainId = $shop->mainId;
+        $adminId = $params['adminId'] ?? 0;
+        $staffName = $params['staffName'] ?? '';
+        $remark = $params['remark'] ?? '';
+        $shopId = $shop->id;
+        $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
+        $getItemId = $ext->losingItem ?? 0;
+        if (empty($getItemId)) {
+            util::fail('没有设置处理区花材');
+        }
+        $getItem = ItemClass::getById($getItemId, true);
+        if (empty($getItem)) {
+            util::fail('没有设置处理区花材哈');
+        }
+
+        //出口
+        $outStock = bcsub($outItem->stock, $num, 2);
+        if ($outStock < 0) {
+            util::fail('剩余' . $outItem->stock . '可挪动');
+        }
+        $outRatio = $outItem->ratio ?? 0;
+        $formNum = ProductClass::formatStock($outStock, $outRatio);
+        $ghsItemInfo = [['productId' => $outItem->id, 'bigNum' => $formNum['bigNum'], 'smallNum' => $formNum['smallNum']]];
+        $pdData = [];
+        $pdData['itemInfo'] = $ghsItemInfo;
+        $pdData['sjId'] = $sjId;
+        $pdData['shopId'] = $shopId;
+        $pdData['adminId'] = $adminId;
+        $pdData['mainId'] = $mainId;
+        $pdData['staffName'] = $staffName;
+        $pdData['remark'] = $remark;
+        CheckOrderClass::opOrder($pdData, false, false);
+
+        //进口
+        $inRatio = $getItem->ratio ?? 0;
+        $inStock = bcadd($getItem->stock, $num, 2);
+        $format = ProductClass::formatStock($inStock, $inRatio);
+        $ghsItemInfo = [['productId' => $getItem->id, 'bigNum' => $format['bigNum'], 'smallNum' => $format['smallNum']]];
+        $pdData = [];
+        $pdData['itemInfo'] = $ghsItemInfo;
+        $pdData['sjId'] = $sjId;
+        $pdData['shopId'] = $shopId;
+        $pdData['adminId'] = $adminId;
+        $pdData['mainId'] = $mainId;
+        $pdData['staffName'] = $staffName;
+        $pdData['remark'] = $remark;
+        CheckOrderClass::opOrder($pdData, false, false);
+    }
+
     //增加和减少半扎 ssh 20250417
     public static function modifyHalf($shop, $product, $params, $add)
     {