|
|
@@ -52,14 +52,15 @@ class PurchaseOrderClass extends BaseClass
|
|
|
$data['status'] = self::PURCHASE_ORDER_STATUS_COMPLETE;
|
|
|
$orderSn = orderSn::getGhsPurchaseSn();
|
|
|
$data['orderSn'] = $orderSn;
|
|
|
- $ghsItemInfo = $data['itemInfo']; // [{itemId:0,bigNum:0,smallNum:0,productId:1.0,itemPrice:1,weight:1}] //增加重量kg
|
|
|
+ //数据结构 [{itemId:0,bigNum:0,smallNum:0,productId:1.0,itemPrice:1,weight:1}]
|
|
|
+ $ghsItemInfo = $data['itemInfo'];
|
|
|
$ghsItemInfo = self::mergeItemInfo($ghsItemInfo);
|
|
|
//计算出总共多少扎,多少支
|
|
|
$bigNum = 0; //总共多少扎
|
|
|
$smallNum = 0; //总共多少支
|
|
|
$totalItemPrice = 0;
|
|
|
//花材中总重量
|
|
|
- $totalItemWeight = 0;
|
|
|
+ $totalWeight = 0;
|
|
|
$ghsItemInfoMap = [];
|
|
|
if (!empty($ghsItemInfo)) {
|
|
|
foreach ($ghsItemInfo as $v) {
|
|
|
@@ -72,17 +73,13 @@ class PurchaseOrderClass extends BaseClass
|
|
|
} else {
|
|
|
$weight = $v['weight'] ?? 0;
|
|
|
}
|
|
|
- $totalItemWeight = bcadd($totalItemWeight, $weight, 2);
|
|
|
+ $totalWeight = bcadd($totalWeight, $weight, 2);
|
|
|
}
|
|
|
}
|
|
|
$data['bigNum'] = $bigNum;
|
|
|
$data['smallNum'] = $smallNum;
|
|
|
$data['price'] = $totalItemPrice;
|
|
|
- $data['totalWeight'] = $totalItemWeight;
|
|
|
-
|
|
|
- //包装重量 shish 20210614
|
|
|
- //$data['packWeight'] = isset($data['packWeight']) && is_numeric($data['packWeight']) ? $data['packWeight'] : 0;
|
|
|
- //$totalItemWeight = bcadd($totalItemWeight, $data['packWeight'], 2);
|
|
|
+ $data['totalWeight'] = $totalWeight;
|
|
|
|
|
|
//计算订单总价
|
|
|
$data['packingCharge'] = empty($data['packingCharge']) ? 0 : $data['packingCharge'];
|
|
|
@@ -146,6 +143,9 @@ class PurchaseOrderClass extends BaseClass
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
|
|
|
try {
|
|
|
+ //总运费/总公斤数,计算每公斤的运费
|
|
|
+ $avgKgWeight = bcdiv($totalFreight, $totalWeight, 2);
|
|
|
+ $data['avgKgWeight'] = $avgKgWeight;
|
|
|
|
|
|
$data['cgStyle'] = dict::getDict('cgStyle', 'ghs');
|
|
|
$order = self::add($data);
|
|
|
@@ -163,13 +163,6 @@ class PurchaseOrderClass extends BaseClass
|
|
|
$totalItemNum = bcadd($totalItemNum, $v['itemNum'], 2);
|
|
|
}
|
|
|
|
|
|
- //平均计算出每扎得运费:总运费/总扎数
|
|
|
- //$avgFreight = bcdiv($totalFreight, $totalItemNum, 2);
|
|
|
-
|
|
|
- //计算每公斤的运费 总运费/总重量
|
|
|
- $avgKgWeight = bcdiv($totalFreight, $totalItemWeight, 2);
|
|
|
- $data['avgKgWeight'] = $avgKgWeight;
|
|
|
-
|
|
|
//现在暂时点击确定,完成 加库存
|
|
|
foreach ($batchData as $v) {
|
|
|
$itemId = $v['itemId'];
|
|
|
@@ -186,32 +179,24 @@ class PurchaseOrderClass extends BaseClass
|
|
|
StockRecordService::addPurchaseOrderRecord($record);
|
|
|
//加库存
|
|
|
ProductClass::addStockByItemNum($productId, $v['itemNum']);
|
|
|
- //
|
|
|
- //每扎的采购价
|
|
|
- //总的采购价/扎数
|
|
|
- $avgItemCost = 0;
|
|
|
+
|
|
|
+ //单位采购价=总的采购价/扎数
|
|
|
+ $unitCgPrice = 0;
|
|
|
if ($v['itemNum'] > 0) {
|
|
|
- $avgItemCost = bcdiv($v['itemPrice'], $v['itemNum'], 2);
|
|
|
+ $unitCgPrice = bcdiv($v['itemPrice'], $v['itemNum'], 2);
|
|
|
}
|
|
|
- // 每扎采购价+每扎运费 = 每扎成本价
|
|
|
- //$avgCost = bcadd($avgItemCost, $avgFreight, 2);
|
|
|
//2021-06-11 修改每扎运费计算
|
|
|
$itemInfoTmp = json_decode($v['itemInfo'], true);
|
|
|
//花材的重量
|
|
|
$productWeight = $itemInfoTmp['itemWeight'] ?? 0;
|
|
|
- $productFreight = bcmul($avgKgWeight, $productWeight, 2);
|
|
|
- $avgCost = bcadd($avgItemCost, $productFreight, 2);
|
|
|
- //修改 ghsItem 中的成本价
|
|
|
- // ItemClass::changeCost($itemId,$sjId,$avgCost);
|
|
|
-
|
|
|
- //2021.4.6修改product 成本价
|
|
|
+ $unitFreight = bcmul($avgKgWeight, $productWeight, 2);
|
|
|
+ $unitCost = bcadd($unitCgPrice, $unitFreight, 2);
|
|
|
//2021.6.21 成本价改为四舍五入取整数
|
|
|
- $avgCost = round($avgCost);
|
|
|
+ $unitCost = round($unitCost);
|
|
|
|
|
|
- //ProductClass::changeCost($productId, $avgCost);
|
|
|
//采购之后全部变成自动调价
|
|
|
$product = ProductClass::getLockById($productId);
|
|
|
- $product->cost = $avgCost;
|
|
|
+ $product->cost = $unitCost;
|
|
|
$product->priceLabel = ProductClass::PRICE_LABEL_AUTO;
|
|
|
$product->save();
|
|
|
|