shish 4 年 前
コミット
428f71e51b

+ 3 - 5
app-hd/controllers/WorkController.php

@@ -132,15 +132,13 @@ class WorkController extends BaseController
             }
             //花材未锁定,需要锁定并扣库存
             if ($work->hasLock == 0) {
-                WorkItemClass::lock($work);
-                $work->hasLock = 1;
-                $work->save();
+                WorkClass::lock($work);
             }
-            //有报损,库存也需要扣除
+            //报损扣除库存
             if (!empty($wastage)) {
                 $wastage = json_decode($wastage, true);
                 if (!empty($wastage)) {
-
+                    WorkItemClass::waste($work, $wastage);
                 }
             }
             WorkClass::finish($work);

+ 8 - 0
biz-hd/work/classes/WorkClass.php

@@ -17,6 +17,14 @@ class WorkClass extends BaseClass
     const STATUS_COMPLETE = 1;
     const STATUS_CANCEL = 2;
 
+    //锁定工单 ssh 20220320
+    public static function lock($work)
+    {
+        $work->hasLock = 1;
+        $work->save();
+        WorkItemClass::lock($work);
+    }
+
     public static function cancel($work)
     {
         if ($work->status == self::STATUS_COMPLETE) {

+ 34 - 3
biz-hd/work/classes/WorkItemClass.php

@@ -3,6 +3,7 @@
 namespace bizHd\work\classes;
 
 use bizGhs\product\classes\ProductClass;
+use common\components\arrayUtil;
 use common\components\dict;
 use common\components\imgUtil;
 use common\components\util;
@@ -14,6 +15,33 @@ class WorkItemClass extends BaseClass
 
     public static $baseFile = '\bizHd\work\models\WorkItem';
 
+    public static function waste($work, $wastage)
+    {
+        //[{"productId":"12253","num":1,"unitType":0}]
+        $wast = arrayUtil::arraySort($wastage, 'productId');
+
+        $workSn = $work->workSn ?? '';
+        $itemList = self::getAllByCondition(['workSn' => $workSn], null, '*', null, true);
+        if (!empty($itemList)) {
+            foreach ($itemList as $key => $item) {
+                $itemId = $item->itemId ?? 0;
+                $wastNum = $wast[$itemId]['num'];
+                $wastUnitType = $wast[$itemId]['unitType'];
+                $bigName = $item->bigName ?? '';
+                $smallName = $item->smallName ?? '';
+                $wastUnitName = $wastUnitType == dict::getDict('unitType', 'big') ? $bigName : $smallName;
+
+                $item->wastNum = $wastNum;
+                $item->wastUnitType = $wastUnitType;
+                $item->wastUnitName = $wastUnitName;
+                $item->save();
+
+                //todo 相应库存扣除
+
+            }
+        }
+    }
+
     //取消锁定,释放库存 ssh 20220320
     public static function cancelLock($work)
     {
@@ -93,10 +121,13 @@ class WorkItemClass extends BaseClass
     //锁定用材 ssh 20220320
     public static function lock($work)
     {
-        if ($work->hasLock == 1) {
-            return false;
+        $workSn = $work->workSn ?? '';
+        $list = self::getAllByCondition(['workSn' => $workSn], null, '*', null, true);
+        if (!empty($list)) {
+            foreach ($list as $key => $item) {
+                //todo 库存处理
+            }
         }
-        //todo 库存需要扣除
     }
 
     //获取工单的所有花材信息 ssh 20220320