Przeglądaj źródła

工单完成新款提交

shish 4 lat temu
rodzic
commit
cbcc9d41b5

+ 2 - 2
app-ghs/controllers/WastageController.php

@@ -83,7 +83,7 @@ class WastageController extends BaseController
     public function actionList()
     {
         $where = [];
-        $where['shopId'] = $this->shopId;
+        $where['mainId'] = $this->mainId;
         $list = StockWastageOrderClass::getOrderList($where);
         util::success($list);
     }
@@ -91,7 +91,7 @@ class WastageController extends BaseController
     public function actionDetail()
     {
         $orderSn = Yii::$app->request->get('orderSn', '');
-        $orderData = StockWastageOrderClass::getOrderDetail($orderSn, $this->shopId);
+        $orderData = StockWastageOrderClass::getOrderDetail($orderSn, $this->mainId);
         util::success($orderData);
     }
 

+ 2 - 8
app-hd/controllers/WorkController.php

@@ -50,6 +50,8 @@ class WorkController extends BaseController
         $post['shopId'] = $this->shopId ?? 0;
         $orderSn = orderSn::getWorkSn();
         $post['workSn'] = $orderSn;
+        $post['staffId'] = $this->shopAdminId;
+        $post['staffName'] = $this->shopAdmin->name;
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
@@ -128,7 +130,6 @@ class WorkController extends BaseController
     {
         $post = Yii::$app->request->post();
         $workId = $post['id'] ?? 0;
-        $wastage = $post['wastage'] ?? '';
         $connection = Yii::$app->db;//事务处理
         $transaction = $connection->beginTransaction();
         try {
@@ -144,13 +145,6 @@ class WorkController extends BaseController
             if ($work->stockLock == 0) {
                 WorkClass::lock($work);
             }
-            //报损扣除库存
-            if (!empty($wastage)) {
-                $wastage = json_decode($wastage, true);
-                if (!empty($wastage)) {
-                    WorkItemClass::waste($work, $wastage);
-                }
-            }
             WorkClass::finish($work);
             $transaction->commit();
             util::complete();

+ 31 - 1
app-hd/controllers/WorkItemController.php

@@ -14,6 +14,37 @@ class WorkItemController extends BaseController
 
     public $guestAccess = [];
 
+    //修改报损数量 ssh 20220425
+    public function actionModifyWastage()
+    {
+        $post = Yii::$app->request->post();
+        $id = $post['id'] ?? 0;
+        $item = WorkItemClass::getById($id, true);
+        WorkItemClass::valid($item, $this->mainId);
+        $workSn = $item->workSn ?? '';
+        $work = WorkClass::getByCondition(['workSn' => $workSn], true);
+        if (empty($work)) {
+            util::fail('没有找到');
+        }
+        if ($work->stockLock == 1) {
+            util::fail('已锁定,不能再报损');
+        }
+        if ($work->status == WorkClass::STATUS_COMPLETE) {
+            util::fail('已完成,不能再报损');
+        }
+        if ($work->status == WorkClass::STATUS_CANCEL) {
+            util::fail('已取消,不能再报损');
+        }
+        $wastNum = $post['num'] ?? 0;
+        $wastUnitType = $post['unitType'] ?? 0;
+        $wastUnitName = $post['unitName'] ?? '';
+        $item->wastNum = $wastNum;
+        $item->wastUnitType = $wastUnitType;
+        $item->wastUnitName = $wastUnitName;
+        $item->save();
+        util::complete();
+    }
+
     //修改用材信息
     public function actionModifyItem()
     {
@@ -39,7 +70,6 @@ class WorkItemController extends BaseController
             util::fail('工单已取消');
         }
 
-
         $connection = Yii::$app->db;//事务处理
         $transaction = $connection->beginTransaction();
         try {

+ 2 - 0
biz-ghs/order/classes/StockWastageOrderClass.php

@@ -21,6 +21,8 @@ class StockWastageOrderClass extends BaseClass
     public static $baseFile = '\bizGhs\order\models\StockWastageOrder';
     const STATUS_COMPLETE = 1; //已完成
 
+    const WASTAGE_TYPE_COMMON = 0;
+    const WASTAGE_TYPE_WORK = 1;
 
     // 订单列表
     public static function getOrderList($where)

+ 1 - 1
biz-hd/order/classes/OrderGoodsClass.php

@@ -286,7 +286,7 @@ class OrderGoodsClass extends BaseClass
         }
     }
 
-    //制作单取消
+    //单取消
     //退回花材损耗,退回花材消耗,退回成品库存
     public static function cancelMakeGoods($orderSn)
     {

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

@@ -50,6 +50,8 @@ class WorkClass extends BaseClass
         $work->status = self::STATUS_COMPLETE;
         $work->save();
 
+        WorkItemClass::wastage($work);
+
         $num = $work->num ?? 0;
         $mainId = $work->mainId ?? 0;
         $workSn = $work->workSn ?? '';

+ 56 - 17
biz-hd/work/classes/WorkItemClass.php

@@ -2,10 +2,13 @@
 
 namespace bizHd\work\classes;
 
+use biz\stock\classes\StockClass;
+use bizGhs\order\classes\StockWastageOrderClass;
 use bizGhs\product\classes\ProductClass;
 use common\components\arrayUtil;
 use common\components\dict;
 use common\components\imgUtil;
+use common\components\orderSn;
 use common\components\util;
 use Yii;
 use bizHd\base\classes\BaseClass;
@@ -15,31 +18,67 @@ class WorkItemClass extends BaseClass
 
     public static $baseFile = '\bizHd\work\models\WorkItem';
 
-    public static function waste($work, $wastage)
+    public static function valid($item, $mainId)
     {
-        //[{"productId":"12253","num":1,"unitType":0}]
-        $wast = arrayUtil::arraySort($wastage, 'productId');
+        if (empty($item)) {
+            util::fail('没有找到数据');
+        }
+        if (isset($item->mainId) == false || $item->mainId != $mainId) {
+            util::fail('没有权限');
+        }
+    }
 
+    //报损处理 ssh 20220425
+    public static function wastage($work)
+    {
         $workSn = $work->workSn ?? '';
+        $mainId = $work->mainId ?? 0;
+        $sjId = $work->sjId ?? 0;
+        $shopId = $work->shopId ?? 0;
+        $staffId = $work->staffId ?? 0;
+        $staffName = $work->staffName ?? '';
         $itemList = self::getAllByCondition(['workSn' => $workSn], null, '*', null, true);
+        $product = [];
         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 相应库存扣除
-
+                $wastNum = $item->wastNum ?? 0;
+                $wastUnitType = $item->wastUnitType ?? 0;
+                $mainId = $item->mainId ?? 0;
+                if ($wastNum > 0) {
+                    $ptItemId = $item->ptItemId ?? 0;
+                    $productId = $item->itemId ?? 0;
+                    $bigNum = $wastUnitType == 0 ? $wastNum : 0;
+                    $smallNum = $wastUnitType == 0 ? 0 : $wastNum;
+                    $product[] = [
+                        'productId' => $productId,
+                        'bigNum' => $bigNum,
+                        'smallNum' => $smallNum,
+                        'classId' => -1,
+                        'itemId' => $ptItemId,
+                    ];
+                }
             }
         }
+
+        if (empty($product)) {
+            return true;
+        }
+        $data = [];
+        $data['product'] = $product;
+        $data['status'] = StockWastageOrderClass::STATUS_COMPLETE;
+        $orderSn = orderSn::getGhsStockWastageSn();
+        $data['orderSn'] = $orderSn;
+        $data['sjId'] = $sjId;
+        $data['shopId'] = $shopId;
+        $data['shopAdminId'] = $staffId;
+        $data['shopAdminName'] = $staffName;
+        $data['bigNum'] = 0;
+        $data['smallNum'] = 0;
+        $data['remark'] = '工单报损';
+        $data['mainId'] = $mainId;
+        $data['type'] = StockWastageOrderClass::WASTAGE_TYPE_WORK;
+        $data['targetId'] = $work->id ?? 0;
+        StockWastageOrderClass::addOrder($data);
     }
 
     //取消锁定,释放库存 ssh 20220320

+ 6 - 0
sql.txt

@@ -907,4 +907,10 @@ CREATE TABLE IF NOT EXISTS `xhWastageGoods` (
   `updateTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最后修改时间'
 ) COMMENT='损耗成品详情';
 
+ALTER TABLE xhWastage ADD `type` TINYINT NOT NULL DEFAULT 0 COMMENT '报损类型 0普通报损 1工单报损' AFTER `orderSn`;
+ALTER TABLE xhWastage ADD `targetId` INT NOT NULL DEFAULT 0 COMMENT '报损发起id,如工单id' AFTER `type`;
+
+ALTER TABLE xhWork ADD `flowerNum` TINYINT NOT NULL DEFAULT 0 COMMENT '主花支数' AFTER `smallNum`;
+ALTER TABLE xhWork MODIFY `smallNum` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '小单位数量';
+
 ---ssh 20220424