shish 2 жил өмнө
parent
commit
0d26bfa16c

+ 49 - 1
app-ghs/controllers/ItemController.php

@@ -38,9 +38,17 @@ class ItemController extends BaseController
         if (empty($staff) || $staff->mainId != $this->mainId) {
             util::fail('不是你的员工');
         }
+        $staffName = $staff->name ?? '';
         $item->cgStaffId = $staffId;
-        $item->cgStaffName = $staff->name ?? '';
+        $item->cgStaffName = $staffName;
         $item->save();
+
+        $shop = $this->shop;
+        $bookSn = $shop->bookSn??0;
+        if(!empty($bookSn)){
+            BookItemClass::updateByCondition(['bookSn'=>$bookSn,'itemId'=>$id],['cgStaffId'=>$staffId,'cgStaffName'=>$staffName]);
+        }
+
         util::complete('修改成功');
     }
 
@@ -151,6 +159,32 @@ class ItemController extends BaseController
         }
         $level = $custom->level ?? 1;
         $field = '*';
+
+        //只查我负责的花材
+        $globalCgMyCharge = $get['globalCgMyCharge']??0;
+        $needCgList = [];
+        $shop = $this->shop;
+        $bookSn = $shop->bookSn??0;
+        $staff = $this->shopAdmin;
+        $staffId = $staff->id??0;
+        if(!empty($bookSn)){
+            $biList = BookItemClass::getAllByCondition(['bookSn'=>$bookSn,'cgStaffId'=>$staffId],null,'*',null,true);
+            if(!empty($biList)){
+                $myIds = [];
+                foreach($biList as $biInfo){
+                    $biProductId = $biInfo->itemId??0;
+                    if($biInfo->needCgNum > 0){
+                        $myIds[] = $biProductId;
+                        $needCgList[$biProductId] = $biInfo->needCgNum;
+                    }
+                }
+                if(!empty($myIds)){
+                    $where['id']=['in',$myIds];
+                }
+            }
+        }
+
+
         $result = ProductClass::getList($field, $where, ['inTurn' => SORT_DESC, 'actualSold' => SORT_DESC]);
         $list = $result['list'] ?? [];
         if ($requestType == 'hasStockList') {
@@ -191,6 +225,20 @@ class ItemController extends BaseController
         } else {
             util::fail('没有数据');
         }
+
+        if(!empty($needCgList)) {
+            //采购人采自己花材需要知道要采多少
+            if(!empty($list)){
+                foreach($list as $key => $val){
+                    $productId = $val['id']??0;
+                    if(isset($needCgList[$productId])){
+                        $needCgNum = $needCgList[$productId];
+                        $list[$key]['needCgNum'] = $needCgNum;
+                    }
+                }
+            }
+        }
+
         $result['list'] = $list;
         util::success($result);
     }

+ 36 - 2
app-ghs/controllers/PurchaseOrderController.php

@@ -5,6 +5,7 @@ namespace ghs\controllers;
 use biz\ghs\classes\GhsClass;
 use biz\sj\classes\SjClass;
 use biz\wx\classes\WxMessageClass;
+use bizGhs\book\classes\BookItemClass;
 use bizGhs\order\classes\PurchaseOrderClass;
 use bizGhs\order\classes\PurchaseOrderItemClass;
 use bizGhs\product\classes\ProductClass;
@@ -459,11 +460,35 @@ class PurchaseOrderController extends BaseController
             $post['ghsName'] = $ghsInfo['name'] ?? '';
             $post['ghsAvatar'] = $ghsInfo['shortAvatar'] ?? '';
 
+            $shop = $this->shop;
+            $bookSn = $shop->bookSn ?? 0;
+
+            //只查我负责的花材
+            $globalCgMyCharge = $post['globalCgMyCharge']??0;
+            $needCgList = [];
+            if($globalCgMyCharge == 1){
+                $staffId = $staff->id??0;
+                if(!empty($bookSn)){
+                    $bList = BookItemClass::getAllByCondition(['bookSn'=>$bookSn,'cgStaffId'=>$staffId],null,'*',null,true);
+                    if(!empty($bList)){
+                        $myIds = [];
+                        foreach($bList as $bInfo){
+                            $biProductId = $bInfo->itemId??0;
+                            if($bInfo->needCgNum > 0){
+                                $myIds[] = $biProductId;
+                                $needCgList[$biProductId] = $bInfo->needCgNum;
+                            }
+                        }
+                    }
+                }
+            }
+
             //判断花材里的信息
             foreach ($ghsItemInfo as $v) {
                 $bigNum = $v['bigNum'] ?? 0;
                 $productId = $v['productId'] ?? 0;
                 $smallNum = $v['smallNum'] ?? 0;
+                $name = $v['name']??'';
                 if (!isset($v['itemPrice'])) {
                     util::fail('采购价格不能为空');
                 }
@@ -473,13 +498,22 @@ class PurchaseOrderController extends BaseController
                 if ($bigNum <= 0 && $smallNum <= 0) {
                     util::fail('花材数量不能为0');
                 }
+
+                if($globalCgMyCharge == 1){
+                    if(isset($needCgList[$productId]) == false){
+                        util::fail($name.' 不需要采购');
+                    }
+                    $needNum = $needCgList[$productId];
+                    if($bigNum>$needNum){
+                        util::fail($name.' 只要采'.$needNum.'份');
+                    }
+                }
+
             }
             $post['itemInfo'] = $ghsItemInfo;
             //0稍后入库 1直接入库
             $inType = $post['inType'] ?? PurchaseOrderClass::IN_TYPE_NOW;
 
-            $shop = $this->shop;
-            $bookSn = $shop->bookSn ?? 0;
             if ($inType == 1 && !empty($bookSn)) {
                 util::fail('开启预订不能直接入库');
             }