From ff30059ddb5f35984feed58bfbc919017f6df163 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 20 Nov 2024 16:30:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(order):=20=E4=BC=98=E5=8C=96=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E9=80=80=E6=AC=BE=E5=92=8C=E4=BB=B7=E6=A0=BC=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改预订单生成逻辑,增加用户等级和成本价判断 - 优化采购价和售价比较,确保合理的价格计算 - 修复微信支付退款金额计算错误 - 优化退库单和供应商退货单的数据处理 --- .../beforehand_order/BeforehandOrderLogic.php | 37 +++++++++++-------- .../logic/store_order/StoreOrderLogic.php | 9 ++++- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index 05cccca76..55f85fbb7 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -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); diff --git a/app/admin/logic/store_order/StoreOrderLogic.php b/app/admin/logic/store_order/StoreOrderLogic.php index ad1a1ba4b..9eae12c4b 100644 --- a/app/admin/logic/store_order/StoreOrderLogic.php +++ b/app/admin/logic/store_order/StoreOrderLogic.php @@ -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 '退款成功';