Prechádzať zdrojové kódy

拆散单支的用法

shish 8 mesiacov pred
rodič
commit
d329cc1fb3

+ 47 - 0
app-ghs/controllers/ProductController.php

@@ -15,6 +15,7 @@ use bizGhs\cp\classes\CpItemClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\item\classes\ItemClass;
 use bizGhs\item\classes\ItemClassClass;
+use bizGhs\item\classes\UnitChangeClass;
 use bizGhs\merchant\classes\ShopClass;
 use bizGhs\notify\classes\NotifyClass;
 use bizGhs\order\classes\PurchaseOrderClass;
@@ -1317,6 +1318,18 @@ class ProductController extends BaseController
         $respond['hasRightChange'] = $hasRightRespond['hasRightChange'];
         $respond['hasRightChangeReason'] = $hasRightRespond['reason'];
 
+        //查出拆散的子花材
+        $part = UnitChangeClass::getByCondition(['big' => $id], true);
+        $partAcceptItem = 0;
+        $partAcceptItemName = '';
+        if (!empty($part)) {
+            $partAcceptItem = $part->small;
+            $small = ProductClass::getByCondition(['id' => $partAcceptItem], true, false, 'id,name');
+            $partAcceptItemName = $small->name ?? '';;
+        }
+        $respond['partAcceptItem'] = $partAcceptItem;
+        $respond['partAcceptItemName'] = $partAcceptItemName;
+
         $respond['cpInfo'] = $cpInfo;
         util::success($respond);
     }
@@ -1684,4 +1697,38 @@ class ProductController extends BaseController
         util::complete('修改成功');
     }
 
+    //修改拆散接收的花材 ssh 20251124
+    public function actionModifyPartAcceptItem()
+    {
+        $get = Yii::$app->request->get();
+        $smallId = $get['small'] ?? 0;
+        $bigId = $get['big'] ?? 0;
+        $small = ProductClass::getById($smallId, true);
+        if (empty($small)) {
+            util::fail('子花材没找到');
+        }
+        $smallName = $small->name ?? '';
+        if ($small->mainId != $this->mainId) {
+            util::fail($smallName . '不是你的花材');
+        }
+        if ($small->ratio != 1) {
+            util::fail($smallName . '不是1支装的');
+        }
+        $big = ProductClass::getById($bigId, true);
+        if (empty($big)) {
+            util::fail('没有找到花材');
+        }
+        if ($big->mainId != $this->mainId) {
+            util::fail('不是你的花材呢');
+        }
+        $change = UnitChangeClass::getByCondition(['big' => $bigId], true);
+        if (empty($change)) {
+            UnitChangeClass::add(['big' => $bigId, 'small' => $smallId], true);
+        } else {
+            $change->small = $smallId;
+            $change->save();
+        }
+        util::complete('修改成功');
+    }
+
 }

+ 48 - 1
app-hd/controllers/ProductController.php

@@ -10,6 +10,7 @@ use bizGhs\item\classes\ItemClassClass;
 use bizGhs\product\classes\ProductClass;
 use bizGhs\product\services\ProductService;
 use bizHd\admin\classes\ShopAdminClass;
+use bizHd\item\classes\UnitChangeClass;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\purchase\classes\PurchaseItemClass;
 use bizHd\pictext\classes\PicTextGhsItemClass;
@@ -778,6 +779,18 @@ class ProductController extends BaseController
             $respond['images'] = $respond['shortCover'];
         }
 
+        //查出拆散的子花材
+        $part = UnitChangeClass::getByCondition(['big' => $id], true);
+        $partAcceptItem = 0;
+        $partAcceptItemName = '';
+        if (!empty($part)) {
+            $partAcceptItem = $part->small;
+            $small = ProductClass::getByCondition(['id' => $partAcceptItem], true, false, 'id,name');
+            $partAcceptItemName = $small->name ?? '';;
+        }
+        $respond['partAcceptItem'] = $partAcceptItem;
+        $respond['partAcceptItemName'] = $partAcceptItemName;
+
         util::success($respond);
     }
 
@@ -944,4 +957,38 @@ class ProductController extends BaseController
         util::complete('修改成功');
     }
 
-}
+    //修改拆散接收的花材 ssh 20251124
+    public function actionModifyPartAcceptItem()
+    {
+        $get = Yii::$app->request->get();
+        $smallId = $get['small'] ?? 0;
+        $bigId = $get['big'] ?? 0;
+        $small = ProductClass::getById($smallId, true);
+        if (empty($small)) {
+            util::fail('子花材没找到');
+        }
+        $smallName = $small->name ?? '';
+        if ($small->mainId != $this->mainId) {
+            util::fail($smallName . '不是你的花材');
+        }
+        if ($small->ratio != 1) {
+            util::fail($smallName . '不是1支装的');
+        }
+        $big = ProductClass::getById($bigId, true);
+        if (empty($big)) {
+            util::fail('没有找到花材');
+        }
+        if ($big->mainId != $this->mainId) {
+            util::fail('不是你的花材呢');
+        }
+        $change = UnitChangeClass::getByCondition(['big' => $bigId], true);
+        if (empty($change)) {
+            UnitChangeClass::add(['big' => $bigId, 'small' => $smallId], true);
+        } else {
+            $change->small = $smallId;
+            $change->save();
+        }
+        util::complete('修改成功');
+    }
+
+}

+ 22 - 0
biz-ghs/item/classes/UnitChangeClass.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace bizGhs\item\classes;
+
+use biz\item\classes\PtItemCatClass;
+use biz\item\classes\PtItemCatRelateClass;
+use biz\item\classes\PtItemClass;
+use biz\shop\classes\ShopExtClass;
+use bizGhs\base\classes\BaseClass;
+use bizGhs\book\classes\BookItemClass;
+use bizGhs\order\classes\CheckOrderClass;
+use bizGhs\product\classes\ProductClass;
+use common\components\imgUtil;
+use common\components\util;
+use common\services\xhItemService;
+
+class UnitChangeClass extends BaseClass
+{
+
+    public static $baseFile = '\bizGhs\item\models\UnitChange';
+
+}

+ 11 - 0
biz-ghs/item/models/UnitChange.php

@@ -0,0 +1,11 @@
+<?php
+namespace bizGhs\item\models;
+use bizGhs\base\models\Base;
+
+class UnitChange extends Base
+{
+    public static function tableName()
+    {
+        return 'xhUnitChange';
+    }
+}

+ 11 - 0
biz-ghs/item/services/UnitChangeService.php

@@ -0,0 +1,11 @@
+<?php
+namespace bizGhs\item\services;
+
+use bizGhs\base\services\BaseService;
+
+class UnitChangeService extends BaseService
+{
+
+    public static $baseFile = '\bizGhs\item\classes\UnitChangeClass';
+
+}

+ 46 - 0
biz-ghs/part/classes/PartClass.php

@@ -3,6 +3,7 @@
 namespace bizGhs\part\classes;
 
 use bizGhs\base\classes\BaseClass;
+use bizGhs\item\classes\UnitChangeClass;
 use bizGhs\product\classes\ProductClass;
 use bizGhs\shop\classes\MainClass;
 use bizGhs\stock\classes\StockRecordClass;
@@ -113,6 +114,51 @@ class PartClass extends BaseClass
         $order->cost = $totalCost;
         $order->save();
         \bizHd\part\classes\StatPartClass::replace($main, $totalCost, $totalNum);
+
+        //拆散后子花材的库存需要增加,多处要同步修改,关键词part_to_sub_item
+        $ids = array_column($productInfoList, 'productId');
+        $bigInfoList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,ratio', 'id');
+        $map = UnitChangeClass::getAllByCondition(['big' => ['in', $ids]], null, '*', 'big');
+        if (!empty($map)) {
+            foreach ($productInfoList as $key => $value) {
+                $num = $value['bigNum'] ?? 0;
+                $productId = $value['productId'] ?? 0;
+                $mapInfo = $map[$productId] ?? [];
+                $bigInfo = $bigInfoList[$productId] ?? [];
+                if (!empty($mapInfo) && !empty($bigInfo)) {
+                    $bigRatio = $bigInfo['ratio'] ?? 0;
+                    $bigName = $bigInfo['name'] ?? '';
+                    $totalNum = bcmul($num, $bigRatio);
+                    $smallId = $mapInfo['small'] ?? 0;
+                    $stockInfo = ProductClass::addStock($smallId, $totalNum, 0);
+
+                    $smallInfo = ProductClass::getById($smallId, true);
+                    $sjId = $smallInfo->sjId ?? 0;
+                    $shopId = $smallInfo->shopId ?? 0;
+                    $ptItemId = $smallInfo->itemId ?? 0;
+                    $mainId = $smallInfo->mainId ?? 0;
+
+                    $oldStock = $stockInfo['oldStock'] ?? 0;
+                    $newStock = $stockInfo['newStock'] ?? 0;
+                    //库存变动记录
+                    $recordData = [];
+                    $recordData['relateName'] = $data['shopAdminName'] ?? '';
+                    $recordData['itemNum'] = $totalNum;
+                    $recordData['sjId'] = $sjId;
+                    $recordData['shopId'] = $shopId;
+                    $recordData['mainId'] = $mainId;
+                    $recordData['orderSn'] = $orderSn;
+                    $recordData['itemId'] = $ptItemId;
+                    $recordData['oldStock'] = $oldStock; //当时库存
+                    $recordData['productId'] = $smallId;
+                    $recordData['newStock'] = $newStock;// 最新库存
+                    $recordData['io'] = 1;
+                    $recordData['remark'] = "拆散{$num}扎 " . $bigName;
+                    StockRecordClass::partItemAddRecord($recordData);
+                }
+            }
+        }
+
         return $order;
     }
 

+ 7 - 1
biz-ghs/stock/classes/StockRecordClass.php

@@ -32,7 +32,7 @@ class StockRecordClass extends BaseClass
     const STOCK_RECORD_TYPE_GOODS_WASTAGE_CANCEL = 15;//取消制作已报损
     const STOCK_RECORD_TYPE_HD_REFUND = 16;//花店退货退款
     const STOCK_RECORD_TYPE_GHS_REFUND = 17;//供货商申请退货退款
-    const STOCK_RECORD_TYPE_PART = 18;//供货商申请退货退款
+    const STOCK_RECORD_TYPE_PART = 18;//拆散
     const STOCK_RECORD_TYPE_GIVE = 19;//赠送
     const STOCK_RECORD_TYPE_ACCEPT = 20;//接收赠送
 
@@ -170,6 +170,12 @@ class StockRecordClass extends BaseClass
         self::add($refundRecord);
     }
 
+    public static function partItemAddRecord($refundRecord)
+    {
+        $refundRecord['recordType'] = self::STOCK_RECORD_TYPE_PART;
+        self::add($refundRecord);
+    }
+
     //采购订单流水记录
     public static function addPurchaseOrderRecord($data)
     {

+ 12 - 0
biz-hd/item/classes/UnitChangeClass.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace bizHd\item\classes;
+
+use bizHd\base\classes\BaseClass;
+
+class UnitChangeClass extends BaseClass
+{
+
+    public static $baseFile = '\bizHd\item\models\UnitChange';
+
+}

+ 12 - 0
biz-hd/item/models/UnitChange.php

@@ -0,0 +1,12 @@
+<?php
+namespace bizHd\item\models;
+use bizHd\base\models\Base;
+class UnitChange extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhUnitChange';
+    }
+
+}

+ 47 - 1
biz-hd/part/classes/PartClass.php

@@ -3,6 +3,7 @@
 namespace bizHd\part\classes;
 
 use bizHd\base\classes\BaseClass;
+use bizHd\item\classes\UnitChangeClass;
 use bizHd\shop\classes\MainClass;
 use common\components\dict;
 use common\components\orderSn;
@@ -98,7 +99,7 @@ class PartClass extends BaseClass
         StockRecordClass::addRecordByOrder($stockData, StockRecordClass::STOCK_RECORD_TYPE_PART);
         $main = MainClass::getLockById($mainId);
         if (empty($main)) {
-            util::fail('没有main信息29');
+            util::fail('没有main信息');
         }
         $totalCost = 0;
         $totalNum = 0;
@@ -111,6 +112,51 @@ class PartClass extends BaseClass
         $order->cost = $totalCost;
         $order->save();
         StatPartClass::replace($main, $totalCost, $totalNum);
+
+        //拆散后子花材的库存需要增加,多处要同步修改,关键词part_to_sub_item
+        $ids = array_column($productInfoList, 'productId');
+        $bigInfoList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, 'id,name,ratio', 'id');
+        $map = UnitChangeClass::getAllByCondition(['big' => ['in', $ids]], null, '*', 'big');
+        if (!empty($map)) {
+            foreach ($productInfoList as $key => $value) {
+                $num = $value['bigNum'] ?? 0;
+                $productId = $value['productId'] ?? 0;
+                $mapInfo = $map[$productId] ?? [];
+                $bigInfo = $bigInfoList[$productId] ?? [];
+                if (!empty($mapInfo) && !empty($bigInfo)) {
+                    $bigRatio = $bigInfo['ratio'] ?? 0;
+                    $bigName = $bigInfo['name'] ?? '';
+                    $totalNum = bcmul($num, $bigRatio);
+                    $smallId = $mapInfo['small'] ?? 0;
+                    $stockInfo = ProductClass::addStock($smallId, $totalNum, 0);
+
+                    $smallInfo = ProductClass::getById($smallId, true);
+                    $sjId = $smallInfo->sjId ?? 0;
+                    $shopId = $smallInfo->shopId ?? 0;
+                    $ptItemId = $smallInfo->itemId ?? 0;
+                    $mainId = $smallInfo->mainId ?? 0;
+
+                    $oldStock = $stockInfo['oldStock'] ?? 0;
+                    $newStock = $stockInfo['newStock'] ?? 0;
+                    //库存变动记录
+                    $recordData = [];
+                    $recordData['relateName'] = $data['shopAdminName'] ?? '';
+                    $recordData['itemNum'] = $totalNum;
+                    $recordData['sjId'] = $sjId;
+                    $recordData['shopId'] = $shopId;
+                    $recordData['mainId'] = $mainId;
+                    $recordData['orderSn'] = $orderSn;
+                    $recordData['itemId'] = $ptItemId;
+                    $recordData['oldStock'] = $oldStock; //当时库存
+                    $recordData['productId'] = $smallId;
+                    $recordData['newStock'] = $newStock;// 最新库存
+                    $recordData['io'] = 1;
+                    $recordData['remark'] = "拆散{$num}扎 " . $bigName;
+                    StockRecordClass::partItemAddRecord($recordData);
+                }
+            }
+        }
+
         return $order;
     }