|
|
@@ -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;
|
|
|
}
|
|
|
|