This commit is contained in:
lewis 2025-01-13 16:55:26 +08:00
commit 283868bb81

View File

@ -897,16 +897,25 @@ class BeforehandOrderLogic extends BaseLogic
$pay_price = 0;
$total_profit = 0;
foreach ($data as $k => &$v) {
$find = StoreProduct::where('id', $v['product_id'])->field('top_cate_id,store_name,unit,after_sales')->withTrashed()->find();
$find = StoreProduct::where('id', $v['product_id'])->field('top_cate_id,store_name,unit,after_sales,cost')->withTrashed()->find();
$v['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
$v['store_name'] = $find['store_name'];
$v['mark'] = $find['after_sales'];
$v['purchase'] = StoreProductGroupPrice::where('product_id', $v['product_id'])->where('group_id', $user_ship)->value('price');
if ($v['purchase']) {
$v['pay_price'] = bcmul($v['purchase'], $v['nums'], 2);
if ($v['vip_price'] > 0) {
$v['pay_price'] = bcmul($v['vip_price'], $v['nums'], 2);
$price =$v['vip_price'];
} else {
$v['pay_price'] = 0;
$price = StoreProductGroupPrice::where('product_id', $v['product_id'])->where('group_id', $user_ship)->value('price');
if ($price > 0) {
$v['pay_price'] = bcmul($price, $v['nums'], 2);
} else {
$price = $find['cost'];
$v['pay_price'] = bcmul($price, $v['nums'], 2);
}
WarehouseProduct::where('id', $v['id'])->update(['vip_price' => $price]);
}
$v['purchase'] = $price;
$v['profit'] = bcsub($v['total_price'], $v['pay_price'], 2);
$total_profit = bcadd($total_profit, $v['profit'], 2);
$pay_price = bcadd($pay_price, $v['pay_price'], 2);