shish 2 лет назад
Родитель
Сommit
6aadd354fe

+ 6 - 1
app-ghs/controllers/PurchaseOrderController.php

@@ -312,7 +312,12 @@ class PurchaseOrderController extends BaseController
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
-            PurchaseOrderClass::cancel($cg);
+            $shop = $this->shop;
+            $staff = $this->shopAdmin;
+            $staffId = $staff->id??0;
+            $staffName = $staff->name??'';
+            $params = ['staffId'=>$staffId,'staffName'=>$staffName,'staff'=>$staff];
+            PurchaseOrderClass::cancel($cg,$shop,$params);
             $transaction->commit();
             util::complete();
         } catch (\Exception $e) {

+ 37 - 11
biz-ghs/book/classes/BookCustomClass.php

@@ -220,6 +220,13 @@ class BookCustomClass extends BaseClass
             $customName = $bill->customName ?? '';
             $customNamePy = $bill->customNamePy ?? '';
             $event = $customName . '减少预订' . $name . $num . $bigUnit . ',其中路上减少' . $delRoadNum . $bigUnit;
+        } elseif ($currentChangeType == 'cgCancel') {
+            $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel');
+            $customId = $bookCustomRes->customId ?? 0;
+            $customName = $bookCustomRes->customName ?? '';
+            $customNamePy = $bookCustomRes->customNamePy ?? '';
+            $orderSn = $bill->orderSn ?? '';
+            $event = "采购单 {$orderSn} 取消,{$name} 路上减少" . $delRoadNum . $bigUnit;
         } else {
             $event = '';
             $customId = 0;
@@ -227,7 +234,6 @@ class BookCustomClass extends BaseClass
             $customNamePy = '';
             util::fail('此变动方式没有找到');
         }
-
         $changeData = [
             'mainId' => $mainId,
             'bookSn' => $bookSn,
@@ -276,9 +282,9 @@ class BookCustomClass extends BaseClass
         $currentChangeType = $params['currentChangeType']??'delBook';
         if($currentChangeType == 'addCg'){
             $currentCapitalType = dict::getDict('capitalType', 'ghsPurchase');
-            $customId = 0;
-            $customName = '';
-            $customNamePy = '';
+            $customId = $bookCustomRes->customId??0;
+            $customName = $bookCustomRes->name??'';
+            $customNamePy = $bookCustomRes->py??'';
             $orderSn = $bill->orderSn??'';
             $event = $staffName."增加待入库单 {$orderSn} 减少待采 {$name} ". $delNeedCgNum . $bigUnit;
         }elseif($currentChangeType == 'delBook'){
@@ -372,7 +378,7 @@ class BookCustomClass extends BaseClass
         return $bookCustomRes;
     }
 
-    public static function addNeedCgNum($bookCustomRes, $addNeedCgNum, $num, $order, $shop, $product, $params)
+    public static function addNeedCgNum($bookCustomRes, $addNeedCgNum, $num, $bill, $shop, $product, $params)
     {
         $bookCustomRes->needCgNum = bcadd($bookCustomRes->needCgNum, $addNeedCgNum);
         $bookCustomRes->save();
@@ -388,14 +394,34 @@ class BookCustomClass extends BaseClass
         $py = $product->py ?? '';
         $bigUnit = $product->bigUnit ?? '扎';
         $bookSn = $shop->bookSn ?? '';
-        $mainId = $order->mainId ?? 0;
-        $customId = $order->customId ?? 0;
-        $customName = $order->customName ?? '';
-        $customNamePy = $order->customNamePy ?? '';
-        $currentCapitalType = dict::getDict('capitalType', 'addBook');
+        $mainId = $shop->mainId ?? 0;
         $staffName = $params['staffName'] ?? '';
         $staffId = $params['staffId'] ?? 0;
-        $event = $customName . '预订 ' . $name . $num . $bigUnit . ',增加待采' . $addNeedCgNum . $bigUnit;
+
+
+        $currentChangeType = $params['currentChangeType']??'addBook';
+        if($currentChangeType == 'cgCancel'){
+            $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel');
+            $customId = $bookCustomRes->customId??0;
+            $customName = $bookCustomRes->name??'';
+            $customNamePy = $bookCustomRes->py??'';
+            $orderSn = $bill->orderSn??'';
+            $event = "采购单 {$orderSn} 取消,{$name} 增加待采" . $addNeedCgNum . $bigUnit;
+        }elseif($currentChangeType == 'addBook'){
+            $currentCapitalType = dict::getDict('capitalType', 'addBook');
+            $customId = $bill->customId ?? 0;
+            $customName = $bill->customName ?? '';
+            $customNamePy = $bill->customNamePy ?? '';
+            $event = $customName . '预订 ' . $name . $num . $bigUnit . ',增加待采' . $addNeedCgNum . $bigUnit;
+        }else{
+            $currentCapitalType = dict::getDict('capitalType', 'addBook');
+            $customId = 0;
+            $customName = '';
+            $customNamePy = '';
+            $event = '';
+            util::fail('无效动作哈...');
+        }
+
         $changeData = [
             'mainId' => $mainId,
             'bookSn' => $bookSn,

+ 33 - 8
biz-ghs/book/classes/BookItemClass.php

@@ -578,7 +578,6 @@ class BookItemClass extends BaseClass
         $ioRes = $params['ioRes'] ?? null;
         $relatedId = $ioRes->id ?? 0;
 
-        //预订减少变动记录
         $itemId = $product->id ?? 0;
         $ptItemId = $product->itemId ?? 0;
         $name = $product->name ?? '';
@@ -607,6 +606,13 @@ class BookItemClass extends BaseClass
             $customName = $bill->customName ?? '';
             $customNamePy = $bill->customNamePy ?? '';
             $event = $customName . '减少预订' . $name . $num . $bigUnit . ',其中减少路上' . $delRoadNum . $bigUnit;
+        } elseif ($currentChangeType == 'cgCancel') {
+            $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel');
+            $customId = 0;
+            $customName = '';
+            $customNamePy = '';
+            $orderSn = $bill->orderSn ?? '';
+            $event = "采购单 {$orderSn} 取消,{$name} 路上减少" . $delRoadNum . $bigUnit;
         } else {
             $event = '';
             $customId = 0;
@@ -707,7 +713,7 @@ class BookItemClass extends BaseClass
         return $bookItemRes;
     }
 
-    public static function addNeedCgNum($bookItemRes, $addNeedCgNum, $totalBookNum, $order, $shop, $product, $params)
+    public static function addNeedCgNum($bookItemRes, $addNeedCgNum, $totalBookNum, $bill, $shop, $product, $params)
     {
         $bookItemRes->needCgNum = bcadd($bookItemRes->needCgNum, $addNeedCgNum);
         $bookItemRes->save();
@@ -723,14 +729,33 @@ class BookItemClass extends BaseClass
         $py = $product->py ?? '';
         $bigUnit = $product->bigUnit ?? '扎';
         $bookSn = $shop->bookSn ?? '';
-        $mainId = $order->mainId ?? 0;
-        $customId = $order->customId ?? 0;
-        $customName = $order->customName ?? '';
-        $customNamePy = $order->customNamePy ?? '';
-        $currentCapitalType = dict::getDict('capitalType', 'addBook');
+        $mainId = $shop->mainId ?? 0;
         $staffName = $params['staffName'] ?? '';
         $staffId = $params['staffId'] ?? 0;
-        $event = $customName . '预订 ' . $name . $totalBookNum . $bigUnit . ',增加待采' . $addNeedCgNum . $bigUnit;
+
+        $currentChangeType = $params['currentChangeType']??'addBook';
+        if($currentChangeType == 'cgCancel'){
+            $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel');
+            $customId = $bookCustomRes->customId??0;
+            $customName = $bookCustomRes->name??'';
+            $customNamePy = $bookCustomRes->py??'';
+            $orderSn = $bill->orderSn??'';
+            $event = "采购单 {$orderSn} 取消,{$name} 增加待采" . $addNeedCgNum . $bigUnit;
+        }elseif($currentChangeType == 'addBook'){
+            $currentCapitalType = dict::getDict('capitalType', 'addBook');
+            $customId = $bill->customId ?? 0;
+            $customName = $bill->customName ?? '';
+            $customNamePy = $bill->customNamePy ?? '';
+            $event = $customName . '预订 ' . $name . $totalBookNum . $bigUnit . ',增加待采' . $addNeedCgNum . $bigUnit;
+        }else{
+            $currentCapitalType = dict::getDict('capitalType', 'addBook');
+            $customId = 0;
+            $customName = '';
+            $customNamePy = '';
+            $event = '';
+            util::fail('无效动作哈...');
+        }
+
         $changeData = [
             'mainId' => $mainId,
             'bookSn' => $bookSn,

+ 30 - 7
biz-ghs/book/classes/BookItemCustomClass.php

@@ -212,6 +212,13 @@ class BookItemCustomClass extends BaseClass
             $customNamePy = $bookItemCustomRes->customNamePy ?? '';
             $orderSn = $bill->orderSn ?? '';
             $event = "采购单 {$orderSn} 入库上架,{$name} 路上减少" . $delRoadNum . $bigUnit;
+        }elseif($currentChangeType == 'cgCancel'){
+            $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel');
+            $customId = $bookItemCustomRes->customId ?? 0;
+            $customName = $bookItemCustomRes->customName ?? '';
+            $customNamePy = $bookItemCustomRes->customNamePy ?? '';
+            $orderSn = $bill->orderSn ?? '';
+            $event = "采购单 {$orderSn} 取消,{$name} 路上减少" . $delRoadNum . $bigUnit;
         } elseif ($currentChangeType == 'delBook') {
             //减少预订
             $currentCapitalType = dict::getDict('capitalType', 'delBook');
@@ -315,7 +322,7 @@ class BookItemCustomClass extends BaseClass
     }
 
     //预订增加待采数量 ssh 20240712
-    public static function addNeedCgNum($bookItemCustomRes, $addNeedCgNum, $totalBookNum, $order, $shop, $product, $params)
+    public static function addNeedCgNum($bookItemCustomRes, $addNeedCgNum, $totalBookNum, $bill, $shop, $product, $params)
     {
         $bookItemCustomRes->needCgNum = bcadd($bookItemCustomRes->needCgNum, $addNeedCgNum);
         $bookItemCustomRes->save();
@@ -331,14 +338,30 @@ class BookItemCustomClass extends BaseClass
         $py = $product->py ?? '';
         $bigUnit = $product->bigUnit ?? '扎';
         $bookSn = $shop->bookSn ?? '';
-        $mainId = $order->mainId ?? 0;
-        $customId = $order->customId ?? 0;
-        $customName = $order->customName ?? '';
-        $customNamePy = $order->customNamePy ?? '';
-        $currentCapitalType = dict::getDict('capitalType', 'addBook');
+        $mainId = $shop->mainId ?? 0;
         $staffName = $params['staffName'] ?? '';
         $staffId = $params['staffId'] ?? 0;
-        $event = $customName . '预订 ' . $name . $totalBookNum . $bigUnit . ',增加待采' . $addNeedCgNum . $bigUnit;
+        $currentChangeType = $params['currentChangeType']??'delBook';
+        if($currentChangeType == 'cgCancel'){
+            $currentCapitalType = dict::getDict('capitalType', 'ghsCgCancel');
+            $customId = $bookItemCustomRes->customId ?? 0;
+            $customName = $bookItemCustomRes->customName ?? '';
+            $customNamePy = $bookItemCustomRes->customNamePy ?? '';
+            $orderSn = $bill->orderSn ?? '';
+            $event = "采购单 {$orderSn} 取消,{$name} 增加待采" . $addNeedCgNum . $bigUnit;
+        }elseif($currentChangeType == 'delBook'){
+            $currentCapitalType = dict::getDict('capitalType', 'addBook');
+            $customId = $bill->customId ?? 0;
+            $customName = $bill->customName ?? '';
+            $customNamePy = $bill->customNamePy ?? '';
+            $event = $customName . '预订 ' . $name . $totalBookNum . $bigUnit . ',增加待采' . $addNeedCgNum . $bigUnit;
+        }else{
+            $customId = 0;
+            $customName = '';
+            $customNamePy = '';
+            $currentCapitalType = dict::getDict('capitalType', 'addBook');
+            util::fail('没有');
+        }
         $changeData = [
             'mainId' => $mainId,
             'bookSn' => $bookSn,

+ 20 - 7
biz-ghs/cg/classes/CgOrderItemClass.php

@@ -17,7 +17,7 @@ class CgOrderItemClass extends BaseClass
 
     public static $baseFile = '\bizGhs\cg\models\CgOrderItem';
 
-    public static function cancelAssign($cg)
+    public static function cancelAssign($cg,$shop,$params)
     {
         $orderSn = $cg->orderSn ?? '';
         $bookSn = $cg->bookSn ?? '';
@@ -25,8 +25,17 @@ class CgOrderItemClass extends BaseClass
         if (empty($cgItemList)) {
             return true;
         }
+        $ids = [];
+        foreach($cgItemList as $cgItem){
+            $ids[] = $cgItem->productId ?? 0;
+        }
+        $productInfo = ProductClass::getAllByCondition(['id'=>['in',$ids]],null,'*','id',true);
         foreach ($cgItemList as $cgItem) {
             $productId = $cgItem->productId ?? 0;
+            $product = $productInfo[$productId]??null;
+            if(empty($product)){
+                util::fail('售后找不到花材');
+            }
             $cgItemName = $cgItem->name ?? '';
             $parentId = $cgItem->id ?? 0;
             $sendList = CgOrderItemSendClass::getAllByCondition(['parentId' => $parentId], null, '*', null, true);
@@ -54,9 +63,12 @@ class CgOrderItemClass extends BaseClass
                         if ($num > $roadNum) {
                             util::fail("路上库存不足扣减 bookItemCustom {$cgItemName}");
                         }
-                        $bookItemCustomRes->roadNum = bcsub($roadNum, $num);
+
                         $bookItemCustomRes->needCgNum = bcadd($bookItemCustomRes->needCgNum, $num);
-                        $bookItemCustomRes->save();
+
+                        $params['currentChangeType'] = 'cgCancel';
+                        $bookItemCustomRes = BookItemCustomClass::delRoadNum($bookItemCustomRes, $num, 0, $cg, $shop, $product, $params);
+                        $bookItemCustomRes = BookItemCustomClass::addNeedCgNum($bookItemCustomRes,$num, 0, $cg, $shop, $product, $params);
 
                         $customId = $bookItemCustomRes->customId ?? 0;
                         $bookCustomRes = BookCustomClass::getByCondition(['bookSn' => $bookSn, 'customId' => $customId], true);
@@ -67,10 +79,12 @@ class CgOrderItemClass extends BaseClass
                         if ($num > $roadNum2) {
                             util::fail("路上库存不足扣减 bookCustom {$cgItemName}");
                         }
-                        $bookCustomRes->roadNum = bcsub($roadNum2, $num);
                         $bookCustomRes->needCgNum = bcadd($bookCustomRes->needCgNum, $num);
                         $bookCustomRes->save();
 
+                        $bookCustomRes = BookCustomClass::delRoadNum($bookCustomRes,$num, 0, $cg, $shop, $product, $params);
+                        $bookCustomRes = BookCustomClass::addNeedCgNum($bookCustomRes,$num, 0, $cg, $shop, $product, $params);
+
                         $bookItemRes = BookItemClass::getByCondition(['bookSn' => $bookSn, 'itemId' => $productId], true);
                         if (empty($bookItemRes)) {
                             util::fail('预订花材缺失');
@@ -79,9 +93,8 @@ class CgOrderItemClass extends BaseClass
                         if ($num > $roadNum3) {
                             util::fail("路上库存不足扣减 bookItem {$cgItemName}");
                         }
-                        $bookItemRes->roadNum = bcsub($roadNum3, $num);
-                        $bookItemRes->needCgNum = bcadd($bookItemRes->needCgNum, $num);
-                        $bookItemRes->save();
+                        $bookItemRes = BookItemClass::delRoadNum($bookItemRes,$num,0, $cg, $shop, $product, $params);
+                        $bookItemRes = BookItemClass::addNeedCgNum($bookItemRes,$num,0, $cg, $shop, $product, $params);
                     }
                 }
             }

+ 2 - 2
biz-ghs/order/classes/PurchaseOrderClass.php

@@ -230,7 +230,7 @@ class PurchaseOrderClass extends BaseClass
     }
 
     //取消采购入库 ssh 20231218
-    public static function cancel($cg)
+    public static function cancel($cg,$shop,$params)
     {
         $cg->status = self::PURCHASE_ORDER_STATUS_CANCEL;
         $cg->save();
@@ -280,7 +280,7 @@ class PurchaseOrderClass extends BaseClass
                 $key = 'ghs_cg_order_scan_seat_' . $cg->id;
                 $noLock = util::lock($key);
                 if ($noLock) {
-                    CgOrderItemClass::cancelAssign($cg);
+                    CgOrderItemClass::cancelAssign($cg,$shop,$params);
                     util::unlock($key);
                 } else {
                     util::fail('正在分配货位,请1秒后再取消');

+ 4 - 0
common/components/dict.php

@@ -353,7 +353,10 @@ class dict
             'addBook' => ['id' => 67, 'name' => 'addBook'],
             //减少预订
             'delBook' => ['id' => 68, 'name' => 'delBook'],
+            //供货商采购单售后
             'ghsCgRefund' => ['id' => 69, 'name' => 'ghsCgRefund'],
+            //供货商的采购单取消
+            'ghsCgCancel' => ['id' => 70, 'name' => 'ghsCgCancel'],
         ],
         "capitalTypeList" => [//流水类型的对应链接,后台收支明细查看时跳转的链接
             0 => ['link' => '/capital/order-detail', 'name' => '网店', 'orderLink' => '/order/detail', 'id' => 0,],
@@ -396,6 +399,7 @@ class dict
             67 => ['link' => '', 'name' => '新增预订', 'id' => 67,],
             68 => ['link' => '', 'name' => '减少预订', 'id' => 68,],
             69 => ['link' => '', 'name' => '采购售后', 'id' => 69,],
+            70 => ['link' => '', 'name' => '取消采购', 'id' => 70,],
         ],
 
         //用户来源