|
|
@@ -19,6 +19,7 @@ use bizGhs\item\classes\CostChangeClass;
|
|
|
use bizGhs\order\classes\OrderClass;
|
|
|
use bizGhs\order\traits\OrderTrait;
|
|
|
use bizGhs\product\classes\ProductClass;
|
|
|
+use bizGhs\stock\classes\OnStockRecordClass;
|
|
|
use bizGhs\stock\classes\StockRecordClass;
|
|
|
use bizGhs\stock\services\StockRecordService;
|
|
|
use bizHd\cg\classes\CgRefundClass;
|
|
|
@@ -112,6 +113,41 @@ class PurchaseClass extends BaseClass
|
|
|
$cg->status = 3;
|
|
|
$cg->fhTime = date("Y-m-d H:i:s");
|
|
|
$cg->save();
|
|
|
+
|
|
|
+ $orderSn = $cg->orderSn ?? '';
|
|
|
+ $itemList = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true);
|
|
|
+ if (!empty($itemList)) {
|
|
|
+ $sjId = $cg->sjId ?? 0;
|
|
|
+ $shopId = $cg->shopId ?? 0;
|
|
|
+ $mainId = $cg->mainId ?? 0;
|
|
|
+ $ghsName = $cg->ghsName ?? '';
|
|
|
+ foreach ($itemList as $key => $val) {
|
|
|
+ $productId = $val->productId ?? 0;
|
|
|
+ $itemId = $val->itemId ?? 0;
|
|
|
+ $num = $val->xhNum ?? 0;
|
|
|
+ $product = ProductClass::getLockById($productId);
|
|
|
+ if (empty($product)) {
|
|
|
+ util::fail('没有找到花材呢');
|
|
|
+ }
|
|
|
+ //增加路上库存
|
|
|
+ $onRecord = [];
|
|
|
+ $onRecord['sjId'] = $sjId;
|
|
|
+ $onRecord['shopId'] = $shopId;
|
|
|
+ $onRecord['mainId'] = $mainId;
|
|
|
+ $onRecord['orderSn'] = $orderSn;
|
|
|
+ $onRecord['productId'] = $productId;
|
|
|
+ $onRecord['itemId'] = $itemId;
|
|
|
+ $onRecord['relateName'] = $ghsName;
|
|
|
+ $onRecord['itemNum'] = $num;
|
|
|
+ $oldOnStock = $product->onStock ?? 0;
|
|
|
+ $onRecord['oldStock'] = $oldOnStock;
|
|
|
+ $newOnStock = bcadd($oldOnStock, $num);
|
|
|
+ $onRecord['newStock'] = $newOnStock;
|
|
|
+ $onRecord['ptStyle'] = 1;
|
|
|
+ OnStockRecordClass::addPurchaseOrderRecord($onRecord);
|
|
|
+ ProductClass::addOnStockByItemNum($productId, $num);
|
|
|
+ }
|
|
|
+ }
|
|
|
return $cg;
|
|
|
}
|
|
|
|
|
|
@@ -143,6 +179,10 @@ class PurchaseClass extends BaseClass
|
|
|
$order->save();
|
|
|
//加库存 lqh 2021-05-10
|
|
|
$orderSn = $cg->orderSn;
|
|
|
+ $sjId = $cg->sjId ?? 0;
|
|
|
+ $shopId = $cg->shopId ?? 0;
|
|
|
+ $mainId = $cg->mainId ?? 0;
|
|
|
+ $ghsName = $cg->ghsName ?? '';
|
|
|
$purchaseItem = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, "*");
|
|
|
foreach ($purchaseItem as $v) {
|
|
|
//小单位库存不考虑入库 ssh 202310
|
|
|
@@ -164,33 +204,53 @@ class PurchaseClass extends BaseClass
|
|
|
$recordData['relateName'] = $cg->ghsName ?? '';
|
|
|
StockRecordClass::addPurchaseOrderRecord($recordData);
|
|
|
|
|
|
- $unitPrice = $v['xhUnitPrice'] ?? 0;
|
|
|
$product = ProductClass::getLockById($productId);
|
|
|
- if (!empty($product)) {
|
|
|
- $product->cost = $unitPrice;
|
|
|
- $product->save();
|
|
|
- $ptItemId = $product->itemId ?? 0;
|
|
|
- $mainId = $product->mainId ?? 0;
|
|
|
- $staffId = $cg->shopAdminId ?? 0;
|
|
|
- $staffName = $cg->shopAdminName ?? '';
|
|
|
- //成本变动记录
|
|
|
- $changeData = [
|
|
|
- 'ptStyle' => 2,
|
|
|
- 'sjId' => 0,
|
|
|
- 'mainId' => $mainId,
|
|
|
- 'itemId' => $productId,
|
|
|
- 'ptItemId' => $ptItemId,
|
|
|
- 'cost' => $unitPrice,
|
|
|
- 'staffId' => $staffId,
|
|
|
- 'staffName' => $staffName,
|
|
|
- 'name' => $product->name ?? '',
|
|
|
- 'cover' => $product->cover ?? '',
|
|
|
- 'targetId' => $cg->id ?? 0,
|
|
|
- 'event' => '采购',
|
|
|
- ];
|
|
|
- CostChangeClass::addData($changeData);
|
|
|
+ if (empty($product)) {
|
|
|
+ util::fail('没有找到花材哈');
|
|
|
}
|
|
|
|
|
|
+ //减少路上库存
|
|
|
+ $onRecord = [];
|
|
|
+ $onRecord['sjId'] = $sjId;
|
|
|
+ $onRecord['shopId'] = $shopId;
|
|
|
+ $onRecord['mainId'] = $mainId;
|
|
|
+ $onRecord['orderSn'] = $orderSn;
|
|
|
+ $onRecord['productId'] = $productId;
|
|
|
+ $onRecord['itemId'] = $v['itemId'] ?? 0;
|
|
|
+ $onRecord['relateName'] = $ghsName;
|
|
|
+ $onRecord['itemNum'] = $itemNum;
|
|
|
+ $oldOnStock = $product->onStock ?? 0;
|
|
|
+ $onRecord['oldStock'] = $oldOnStock;
|
|
|
+ $onRecord['newStock'] = bcsub($oldOnStock, $itemNum);
|
|
|
+ $onRecord['ptStyle'] = 1;
|
|
|
+ OnStockRecordClass::addInStockOrderRecord($onRecord);
|
|
|
+ ProductClass::decreaseOnStockByItemNum($productId, $itemNum);
|
|
|
+
|
|
|
+ $unitPrice = $v['xhUnitPrice'] ?? 0;
|
|
|
+ $product->cost = $unitPrice;
|
|
|
+ $product->save();
|
|
|
+ $ptItemId = $product->itemId ?? 0;
|
|
|
+ $mainId = $product->mainId ?? 0;
|
|
|
+ $staffId = $cg->shopAdminId ?? 0;
|
|
|
+ $staffName = $cg->shopAdminName ?? '';
|
|
|
+ //成本变动记录
|
|
|
+ $changeData = [
|
|
|
+ 'ptStyle' => 2,
|
|
|
+ 'sjId' => 0,
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'itemId' => $productId,
|
|
|
+ 'ptItemId' => $ptItemId,
|
|
|
+ 'cost' => $unitPrice,
|
|
|
+ 'staffId' => $staffId,
|
|
|
+ 'staffName' => $staffName,
|
|
|
+ 'name' => $product->name ?? '',
|
|
|
+ 'cover' => $product->cover ?? '',
|
|
|
+ 'targetId' => $cg->id ?? 0,
|
|
|
+ 'event' => '采购',
|
|
|
+ ];
|
|
|
+ CostChangeClass::addData($changeData);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
$cg->status = 4;
|