diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 2590ec6a3..79b78a775 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -897,16 +897,24 @@ 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'] = $v['vip_price'];//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); } 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);