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 1/3] =?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 '退款成功';
From 74f5de71d67bacb5ca1e58b523283d82373383ec Mon Sep 17 00:00:00 2001
From: mkm <727897186@qq.com>
Date: Wed, 20 Nov 2024 16:52:54 +0800
Subject: [PATCH 2/3] =?UTF-8?q?refactor(admin):=20=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E5=89=8D=E7=BD=AE=E8=AE=A2=E5=8D=95=E5=A4=84=E7=90=86=E9=80=BB?=
=?UTF-8?q?=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 移除了不必要的采购价处理逻辑
- 删除了未使用的用户信息查询
- 简化了订单 ID 和验证码的生成过程
---
.../beforehand_order/BeforehandOrderLogic.php | 14 --------------
1 file changed, 14 deletions(-)
diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php
index 55f85fbb7..1a2c03045 100644
--- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php
+++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php
@@ -180,17 +180,6 @@ class BeforehandOrderLogic extends BaseLogic
$product = StoreProduct::where('id', $v['product_id'])->find();
$find = StoreProductLogic::ordinary($product, $params['store_id'], 0, $product);
}
- if (in_array($order['order_type'], [2, 3])) {
- if (isset($v['purchase']) && $v['purchase'] > 0) {
- $purchase = $v['purchase'];
- } else {
- $purchase = StoreProduct::where('id', $v['product_id'])->withTrashed()->value('purchase');
- $find['purchase'] = $purchase;
- // $purchase = $v['price'];
- }
- $find->save(['price' => $v['price'], 'vip_price' => $v['price'], 'cost' => $v['price'], 'purchase' => $purchase]);
- }
-
$cart_select[$k]['price'] = $v['price'];
//判断如果采购价小于售价,则采购价等于售价
@@ -228,13 +217,10 @@ class BeforehandOrderLogic extends BaseLogic
$cart_select[$k]['name'] = $find['store_name'];
$cart_select[$k]['store_id'] = $params['store_id'] ?? 0;
-
$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();
-
$order_id = getNewOrderId('PF');
$code = rand(1, 10) . '-' . substr($order_id, -5);
From 85997befc800fabcf91fba660994bbbe84dd2f6b Mon Sep 17 00:00:00 2001
From: mkm <727897186@qq.com>
Date: Wed, 20 Nov 2024 16:59:09 +0800
Subject: [PATCH 3/3] =?UTF-8?q?feat(purchase):=20=E6=9B=B4=E6=96=B0?=
=?UTF-8?q?=E9=87=87=E8=B4=AD=E4=BF=A1=E6=81=AF=E4=B8=AD=E9=87=87=E8=B4=AD?=
=?UTF-8?q?=E4=BA=BA=E5=90=8D=E7=A7=B0=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 将采购人名称获取方式从 User 模型改为 DeliveryService 模型
- 在企业微信通知中添加采购总价信息
- 优化企业微信通知中的采购金额显示,区分单价和总价
---
.../purchase_product_offer/PurchaseProductOfferLogic.php | 2 +-
.../purchase_product_offer/PurchaseProductOfferListsTwo.php | 2 +-
app/common/service/workWechat/ProductOffer.php | 4 +++-
3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php
index 2bab83798..42e18dcb8 100644
--- a/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php
+++ b/app/admin/logic/purchase_product_offer/PurchaseProductOfferLogic.php
@@ -173,7 +173,7 @@ class PurchaseProductOfferLogic extends BaseLogic
Db::commit();
$offer['store_name']=$product['store_name'];
$offer['unit_name']=$unit_name;
- $offer['buyer_name']=User::where('id',$offer['buyer_id'])->value('real_name');
+ $offer['buyer_name']=DeliveryService::where('uid',$offer['buyer_id'])->value('nickname');
if($offer['pay_type']==1){
$offer['pay_type_name']='赊账';
}elseif($offer['pay_type']==2){
diff --git a/app/api/lists/purchase_product_offer/PurchaseProductOfferListsTwo.php b/app/api/lists/purchase_product_offer/PurchaseProductOfferListsTwo.php
index 803664e31..3e9810f51 100644
--- a/app/api/lists/purchase_product_offer/PurchaseProductOfferListsTwo.php
+++ b/app/api/lists/purchase_product_offer/PurchaseProductOfferListsTwo.php
@@ -56,7 +56,7 @@ class PurchaseProductOfferListsTwo extends BaseApiDataLists implements ListsSear
$item->store_name=$find->store_name;
$item->unit_name=StoreProductUnit::where('id',$item->unit)->value('name');
$item->category_name=StoreCategory::where('id',$find->top_cate_id)->value('name');
- $item->buyer_name=User::where('id',$item['buyer_id'])->value('real_name');
+ $item->buyer_name=DeliveryService::where('uid',$item->buyer_id)->value('nickname');
})
->toArray();
diff --git a/app/common/service/workWechat/ProductOffer.php b/app/common/service/workWechat/ProductOffer.php
index 06305f969..cf2b8706e 100644
--- a/app/common/service/workWechat/ProductOffer.php
+++ b/app/common/service/workWechat/ProductOffer.php
@@ -17,6 +17,7 @@ class ProductOffer
$num = $data['buyer_nums'];
$unit_name = $data['unit_name'];
$price = $data['price'];
+ $total_price = $data['total_price'];
$create_time = $data['create_time'];
$buyer_name = $data['buyer_name'];
$pay_type = $data['pay_type_name'];
@@ -26,7 +27,8 @@ class ProductOffer
>商品名称:$store_name
>数量/单位:$num/$unit_name
>采购人:$buyer_name
- >采购金额:$price
+ >采购单价:$price
+ >采购总价:$total_price
>采购时间:$create_time
>支付方式:$pay_type
[下载今日采购表格]($urls)"]];