zhanglinxin 1 year ago
parent
commit
799285dad7
1 changed files with 53 additions and 15 deletions
  1. 53 15
      application/common/service/ApproveService.php

+ 53 - 15
application/common/service/ApproveService.php

@@ -13,6 +13,8 @@ use app\common\model\ApproveInfoLog;
 use app\common\model\ApproveMaintain;
 use app\common\model\ApproveStockGoods;
 use app\common\model\ApproveUseGoods;
+use app\common\model\GoodsStock;
+use app\common\model\GoodsStockLog;
 use app\common\model\User;
 use think\Db;
 use think\Exception;
@@ -473,28 +475,35 @@ class ApproveService
         if ($status == CommonConstant::STATUS_3) {
             if ($info->module == CommonConstant::MODULE_3) {
                 // 入库商品列表 TODO
-                $stock_goods = $info->stock_goods;
-                p($stock_goods->toArray());
-                if (!$stock_goods->toArray()) {
+                $goods = $info->stock_goods;
+                if (!$goods->toArray()) {
                     except('入库商品不存在');
                 }
             }
-            if ($info->module == CommonConstant::MODULE_4) {
-                // 领用商品列表 TODO
-                $use_goods = $info->use_goods;
-                if (!$use_goods->toArray()) {
-                    except('领用商品不存在');
-                }
-            }
             if ($info->module == CommonConstant::MODULE_8) {
                 // 维修
                 $is_maintain = CommonService::isMaintain($user);
                 if ($is_maintain && !$maintain_user_id) {
                     except('请选择维修人员');
                 }
+                // 维修人员ID
+                if ($maintain_user_id > 0) {
+                    $info->maintain_user_id = $maintain_user_id;
+                }
             }
         }
-//        p($approve);exit;
+        if ($status == CommonConstant::STATUS_4) {
+            if ($info->module == CommonConstant::MODULE_4) {
+                // 领用商品列表 TODO
+                $goods = $info->use_goods;
+                if (!$goods->toArray()) {
+                    except('领用商品不存在');
+                }
+            }
+        }
+
+        p($goods->toArray());
+        exit;
 
         Db::startTrans();
         try {
@@ -506,16 +515,45 @@ class ApproveService
                 } else {
                     // 审批通过
                     $info->status = $status;
+                    if ($info->module == CommonConstant::MODULE_3) {
+                        // 入库商品列表
+                        $goodsStockSave = [];
+                        $goodsStockLog = [];
+                        foreach ($goods as $key => $val) {
+                            foreach ($val['goods_stock_text'] as $k => $v) {
+                                $goodsStockSave[] = [
+                                    'id' => $v['id'],
+                                    'stock' => ['inc', $v['stock']],
+                                ];
+                                $goodsStockLog[] = [
+                                    'info_id' => $val['info_id'],
+                                    'goods_id' => $v['goods_id'],
+                                    'stock_id' => $v['id'],
+                                    'name' => $v['name'],
+                                    'price' => $v['price'],
+                                    'stock' => $v['stock'],
+                                ];
+                            }
+                        }
+                        if ($goodsStockSave) {
+                            // 批量更新商品库存
+                            (new GoodsStock)->saveAll($goodsStockSave);
+                        }
+                        if ($goodsStockLog) {
+                            // 批量添加商品入库记录
+                            GoodsStockLog::insertAll($goodsStockLog);
+                        }
+                    }
+                    if ($info->module == CommonConstant::MODULE_4) {
+                        // 领用商品列表
+
+                    }
                 }
             }
             if ($status == CommonConstant::STATUS_4) {
                 // 审批驳回
                 $info->status = $status;
             }
-            if ($maintain_user_id > 0) {
-                // 维修人员ID
-                $info->maintain_user_id = $maintain_user_id;
-            }
             $info->cur_num = $info['cur_num'] + 1;
             $info->save();