From 5088c3b5b3d745c879f481447204ecf8ae3abdd8 Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Tue, 2 Jan 2024 15:20:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E9=80=80=E6=AC=BE?= =?UTF-8?q?=E7=94=B3=E8=AF=B7=E8=AE=A1=E7=AE=97=E9=80=80=E8=BF=98=E7=9A=84?= =?UTF-8?q?=E8=B1=86=E8=B1=86=E6=8A=B5=E6=89=A3=E7=A7=AF=E5=88=86=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=B9=B3=E5=8F=B0=E6=8A=BD=E6=88=90?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=98=BE=E7=A4=BA=E5=BD=93=E5=89=8D=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E5=95=86=E5=93=81=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/store/platformCommission/Record.php | 10 ++++++ .../order/StoreRefundOrderRepository.php | 15 ++++---- .../platformCommission/RecordRepository.php | 10 +++++- .../api/store/order/StoreRefundOrder.php | 6 ++-- app/event.php | 5 +++ .../OrderAgreeRefundEvent.php | 34 +++++++++++++++++++ 6 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 app/listener/platformCommission/OrderAgreeRefundEvent.php diff --git a/app/common/model/store/platformCommission/Record.php b/app/common/model/store/platformCommission/Record.php index c34deb9..344f7cc 100644 --- a/app/common/model/store/platformCommission/Record.php +++ b/app/common/model/store/platformCommission/Record.php @@ -6,6 +6,7 @@ namespace app\common\model\store\platformCommission; use app\common\model\BaseModel; use app\common\model\store\order\StoreOrder; +use app\common\model\store\order\StoreOrderProduct; use app\common\model\system\merchant\Merchant; use app\common\model\user\User; use think\model\concern\SoftDelete; @@ -53,5 +54,14 @@ class Record extends BaseModel public function storeOrder(){ return $this->hasOne(StoreOrder::class,'order_id','order_id'); } + /** + * Common: 关联订单商品表 + * Author: wu-hui + * Time: 2024/01/02 15:06 + * @return \think\model\relation\HasOne + */ + public function storeOrderProduct(){ + return $this->hasOne(StoreOrderProduct::class,'order_product_id','order_product_id'); + } } diff --git a/app/common/repositories/store/order/StoreRefundOrderRepository.php b/app/common/repositories/store/order/StoreRefundOrderRepository.php index d497d0c..7066b99 100644 --- a/app/common/repositories/store/order/StoreRefundOrderRepository.php +++ b/app/common/repositories/store/order/StoreRefundOrderRepository.php @@ -632,11 +632,9 @@ class StoreRefundOrderRepository extends BaseRepository $orderId = $order->order_id; //TODO 订单状态生成佣金 $product = app()->make(StoreOrderProductRepository::class)->userRefundProducts([$productId], $uid, $orderId,$refund_switch); - if (empty($product->toArray())) - throw new ValidateException('请选择正确的退款商品'); + if (empty($product->toArray())) throw new ValidateException('请选择正确的退款商品'); $product = $product[0]; - if ($product['refund_num'] < $num) - throw new ValidateException('可退款商品不足' . floatval($num) . '件'); + if ($product['refund_num'] < $num) throw new ValidateException('可退款商品不足' . floatval($num) . '件'); $productRefundPrice = app()->make(StoreRefundProductRepository::class)->userRefundPrice([$productId])[$productId] ?? []; //计算可退运费 @@ -652,8 +650,7 @@ class StoreRefundOrderRepository extends BaseRepository } } $totalRefundPrice = bcadd($refundPrice, $postagePrice, 2); - if ($totalRefundPrice < $data['refund_price']) - throw new ValidateException('最高可退款' . floatval($totalRefundPrice) . '元'); + if ($totalRefundPrice < $data['refund_price']) throw new ValidateException('最高可退款' . floatval($totalRefundPrice) . '元'); $data['refund_postage'] = 0; @@ -676,15 +673,20 @@ class StoreRefundOrderRepository extends BaseRepository $data['platform_refund_price'] = $platform_refund_price; $integral = 0; + $legumesIntegral = 0;// 需要退还的豆豆积分 if ($product['integral'] > 0) { if ($product['refund_num'] == $num) { $integral = bcsub($product['integral_total'], $productRefundPrice['refund_integral'] ?? 0, 0); + $legumesIntegral = bcsub($product['use_legumes_integral'], $productRefundPrice['refund_legumes_integral'] ?? 0, 2); } else { $integral = bcmul($product['integral'], $num, 0); + $singleLegumesIntegral = (float)sprintf("%.2f",$product['use_legumes_integral'] / $product['product_num']); + $legumesIntegral = bcmul($singleLegumesIntegral, $num, 2); } } $data['integral'] = $integral; + $data['refund_legumes_integral'] = $legumesIntegral; $total_extension_one = 0; $total_extension_two = 0; @@ -710,6 +712,7 @@ class StoreRefundOrderRepository extends BaseRepository 'platform_refund_price' => $data['platform_refund_price'], 'refund_price' => $data['refund_price'], 'refund_integral' => $data['integral'], + 'refund_legumes_integral' => $data['refund_legumes_integral'], 'refund_postage' => $data['refund_postage'], ]); $product->refund_num -= $num; diff --git a/app/common/repositories/store/platformCommission/RecordRepository.php b/app/common/repositories/store/platformCommission/RecordRepository.php index d998afd..b93c89f 100644 --- a/app/common/repositories/store/platformCommission/RecordRepository.php +++ b/app/common/repositories/store/platformCommission/RecordRepository.php @@ -93,7 +93,15 @@ class RecordRepository extends BaseRepository{ }, 'storeOrder' => function($query){ $query->field('order_id,order_sn'); - } + }, + 'storeOrderProduct' => function($query){ + $query->field('order_product_id,product_id') + ->with([ + 'product' => function($product){ + $product->field('product_id,store_name,image')->bind(['store_name','image']); + } + ]); + }, ]) ->order('create_time DESC') ->order('id DESC'); diff --git a/app/controller/api/store/order/StoreRefundOrder.php b/app/controller/api/store/order/StoreRefundOrder.php index c89e5bf..9912833 100644 --- a/app/controller/api/store/order/StoreRefundOrder.php +++ b/app/controller/api/store/order/StoreRefundOrder.php @@ -114,13 +114,11 @@ class StoreRefundOrder extends BaseController $type = $data['type']; $num = $data['num']; unset($data['num'], $data['ids'], $data['type']); - if ($type == 1 && count($ids) > 1) - return app('json')->fail('请选择正确的退款商品'); + if ($type == 1 && count($ids) > 1) return app('json')->fail('请选择正确的退款商品'); $uid = $this->request->uid(); $order = $orderRepository->userOrder($id, $uid); if (!$order) return app('json')->fail('订单状态错误'); - if (!$order->refund_status) - return app('json')->fail('订单已过退款/退货期限'); + if (!$order->refund_status) return app('json')->fail('订单已过退款/退货期限'); if ($order->status < 0) return app('json')->fail('订单已退款'); if ($order->status == 10) return app('json')->fail('订单不支持退款'); if($order->is_virtual && $data['refund_type'] == 2) return app('json')->fail('订单不支持退款退货'); diff --git a/app/event.php b/app/event.php index bf11ede..8f702f3 100644 --- a/app/event.php +++ b/app/event.php @@ -62,6 +62,11 @@ return [ // 订单完成 - 平台抽成相关冻结内容解冻 'app\listener\platformCommission\OrderTakeEvent' ], + // 订单退款事件 + 'refund.agree' => [ + // 订单退款 - 平台抽成相关处理 + 'app\listener\platformCommission\OrderAgreeRefundEvent' + ], ], 'subscribe' => [], ]; diff --git a/app/listener/platformCommission/OrderAgreeRefundEvent.php b/app/listener/platformCommission/OrderAgreeRefundEvent.php new file mode 100644 index 0000000..007ee5d --- /dev/null +++ b/app/listener/platformCommission/OrderAgreeRefundEvent.php @@ -0,0 +1,34 @@ + $data['id']],1)); + + + + + }catch(\Exception $e){ + Log::info('订单进入退款成功 - 平台抽成相关处理 - 错误:'.$e->getMessage()); + } + } + + + +} \ No newline at end of file