fix(order): 优化订单退款和价格计算逻辑
- 修改预订单生成逻辑,增加用户等级和成本价判断 - 优化采购价和售价比较,确保合理的价格计算 - 修复微信支付退款金额计算错误 - 优化退库单和供应商退货单的数据处理
This commit is contained in:
parent
afc39e852a
commit
ff30059ddb
@ -166,12 +166,13 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
Db::startTrans();
|
||||
try {
|
||||
$cart_info = BeforehandOrderCartInfo::where('bhoid', $params['id'])->select()->toArray();
|
||||
|
||||
$user = User::where('id', $params['user_id'])->find();
|
||||
$cart_select = [];
|
||||
$total_price = 0;
|
||||
$pay_price = 0;
|
||||
$cost_price = 0;
|
||||
foreach ($cart_info as $k => $v) {
|
||||
$total_prices=$v['total_price'];
|
||||
$v['uid'] = $params['user_id'];
|
||||
$v['store_id'] = $params['store_id'];
|
||||
$find = StoreBranchProduct::where('store_id', $params['store_id'])->where('product_id', $v['product_id'])->find();
|
||||
@ -190,15 +191,25 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
$find->save(['price' => $v['price'], 'vip_price' => $v['price'], 'cost' => $v['price'], 'purchase' => $purchase]);
|
||||
}
|
||||
|
||||
|
||||
$cart_select[$k]['price'] = $v['price'];
|
||||
//判断如果采购价小于售价,则采购价等于售价
|
||||
if ($v['price']<$find['purchase'] && $find['purchase']!=0) {
|
||||
$cart_select[$k]['price'] = $find['purchase'];
|
||||
}
|
||||
if ($user['user_ship'] == 4 && $find['cost']!=0) {
|
||||
$cart_select[$k]['price'] = $find['cost'];
|
||||
$total_prices=bcmul($find['cost'], $v['cart_num'], 2);
|
||||
}
|
||||
$cart_select[$k]['cost'] = $find['cost'];
|
||||
$cart_select[$k]['purchase'] = $find['purchase'];
|
||||
$cart_select[$k]['vip'] = 0;
|
||||
$cart_select[$k]['unit_name'] = StoreProductUnit::where(['id' => $find['unit']])->value('name') ?? ''; //单位名称
|
||||
|
||||
//利润
|
||||
$cart_select[$k]['total_purchase'] = bcmul($v['cart_num'], $find['purchase'], 2) ?? 0; //成本
|
||||
$cart_select[$k]['pay_price'] = $v['total_price']; //订单支付金额
|
||||
$cart_select[$k]['total_price'] = $v['total_price']; //订单支付金额
|
||||
$cart_select[$k]['pay_price'] = $total_prices; //订单支付金额
|
||||
$cart_select[$k]['total_price'] = $total_prices; //订单支付金额
|
||||
$cart_select[$k]['store_price'] = 0; //商户价
|
||||
$cart_select[$k]['vip_price'] = 0; //vip售价
|
||||
$cart_select[$k]['product_id'] = $v['product_id'];
|
||||
@ -215,15 +226,11 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
$cart_select[$k]['cart_info'] = json_encode($cartInfo);
|
||||
//理论上每笔都是拆分了
|
||||
$cart_select[$k]['name'] = $find['store_name'];
|
||||
if ($find['purchase'] < $v['price']) {
|
||||
$cart_select[$k]['purchase'] = $find['purchase'];
|
||||
} else {
|
||||
$cart_select[$k]['purchase'] = $v['price'];
|
||||
}
|
||||
|
||||
$cart_select[$k]['store_id'] = $params['store_id'] ?? 0;
|
||||
|
||||
$total_price = bcadd($total_price, $v['total_price'], 2);
|
||||
$pay_price = bcadd($pay_price, $v['total_price'], 2);
|
||||
$total_price = bcadd($total_price, $total_prices, 2);
|
||||
$pay_price = bcadd($pay_price, $total_prices, 2);
|
||||
$cost_price = bcadd($pay_price, $cart_select[$k]['total_purchase'], 2);
|
||||
}
|
||||
$user = User::where('id', $params['user_id'])->find();
|
||||
@ -393,7 +400,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
'purchase' => $arr['purchase'],
|
||||
'oid' => $res['id'],
|
||||
'code' => $res['code'],
|
||||
'unit' => $arr['unit']??0,
|
||||
'unit' => $arr['unit'] ?? 0,
|
||||
];
|
||||
WarehouseProductLogic::setOutbound($data);
|
||||
}
|
||||
@ -646,7 +653,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
$order_info = new StockReturn();
|
||||
$order = BeforehandOrder::where('id', $params['id'])->find();
|
||||
|
||||
$data = WarehouseProductReturn::where('bhoid', $order['id'])->where('return_type',1)->select()->each(function ($item) {
|
||||
$data = WarehouseProductReturn::where('bhoid', $order['id'])->where('return_type', 1)->select()->each(function ($item) {
|
||||
$find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,unit')->withTrashed()->find();
|
||||
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||
$item['store_name'] = $find['store_name'];
|
||||
@ -656,7 +663,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
throw new BusinessException('退库商品为空,不能导出退库单');
|
||||
}
|
||||
$order['system_store_name'] = SystemStore::where('id', $order['store_id'])->value('name');
|
||||
$order['total_price'] = WarehouseProductReturn::where('bhoid', $order['id'])->where('return_type',1)->sum('total_price');
|
||||
$order['total_price'] = WarehouseProductReturn::where('bhoid', $order['id'])->where('return_type', 1)->sum('total_price');
|
||||
$other_data = $order['other_data'];
|
||||
unset($order['other_data']);
|
||||
$file_path = $order_info->export($data, $order, $other_data);
|
||||
@ -671,7 +678,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
$order_info = new ReturnSupplier();
|
||||
$order = BeforehandOrder::where('id', $params['id'])->find();
|
||||
|
||||
$data = WarehouseProductReturn::where('bhoid', $order['id'])->where('return_type',2)->select()->each(function ($item) {
|
||||
$data = WarehouseProductReturn::where('bhoid', $order['id'])->where('return_type', 2)->select()->each(function ($item) {
|
||||
$find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,unit')->withTrashed()->find();
|
||||
$item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||
$item['store_name'] = $find['store_name'];
|
||||
@ -681,7 +688,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
throw new BusinessException('退库商品为空,不能导出退库单');
|
||||
}
|
||||
$order['system_store_name'] = SystemStore::where('id', $order['store_id'])->value('name');
|
||||
$order['total_price'] = WarehouseProductReturn::where('bhoid', $order['id'])->where('return_type',2)->sum('total_price');
|
||||
$order['total_price'] = WarehouseProductReturn::where('bhoid', $order['id'])->where('return_type', 2)->sum('total_price');
|
||||
$other_data = $order['other_data'];
|
||||
unset($order['other_data']);
|
||||
$file_path = $order_info->export($data, $order, $other_data);
|
||||
|
@ -155,9 +155,14 @@ class StoreOrderLogic extends BaseLogic
|
||||
} else {
|
||||
//微信支付
|
||||
if (in_array($detail['pay_type'], [PayEnum::WECHAT_PAY_MINI, PayEnum::WECHAT_PAY_BARCODE])) {
|
||||
$money = (int)bcmul($detail['pay_price'], 100);
|
||||
if(!empty($params['refund_price']) && $params['refund_price']>0){
|
||||
$money = (int)bcmul($params['refund_price'], 100);
|
||||
}else{
|
||||
$money = (int)bcmul($detail['pay_price'], 100);
|
||||
}
|
||||
$pay_price = (int)bcmul($detail['pay_price'], 100);
|
||||
$refund = (new \app\common\logic\store_order\StoreOrderLogic())
|
||||
->refund($params['order_id'], $money, $money);
|
||||
->refund($params['order_id'], $money, $pay_price);
|
||||
if ($refund) {
|
||||
StoreOrderCartInfo::where('oid', $detail['id'])->update(['is_pay' => -1]);
|
||||
return '退款成功';
|
||||
|
Loading…
x
Reference in New Issue
Block a user