添加:退款申请计算退还的豆豆抵扣积分

添加:平台抽成信息显示当前订单商品信息
This commit is contained in:
wuhui_zzw 2024-01-02 15:20:59 +08:00
parent a5b1657c67
commit 5088c3b5b3
6 changed files with 69 additions and 11 deletions

View File

@ -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');
}
}

View File

@ -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;

View File

@ -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');

View File

@ -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('订单不支持退款退货');

View File

@ -62,6 +62,11 @@ return [
// 订单完成 - 平台抽成相关冻结内容解冻
'app\listener\platformCommission\OrderTakeEvent'
],
// 订单退款事件
'refund.agree' => [
// 订单退款 - 平台抽成相关处理
'app\listener\platformCommission\OrderAgreeRefundEvent'
],
],
'subscribe' => [],
];

View File

@ -0,0 +1,34 @@
<?php
namespace app\listener\platformCommission;
use app\common\model\store\platformCommission\LegumesLog;
use think\facade\Log;
/**
* Common: 订单退款申请成功(同意退款)
* Author: wu-hui
* Time: 2024/01/02 13:33
* Class OrderAgreeRefundEvent
* @package app\listener\platformCommission
*/
class OrderAgreeRefundEvent{
public $groupOrder;
public function handle($data){
try{
$refund = $data['refund'];
Log::info('订单进入退款成功 - 平台抽成相关处理 - 开始:'.var_export(['id' => $data['id']],1));
}catch(\Exception $e){
Log::info('订单进入退款成功 - 平台抽成相关处理 - 错误:'.$e->getMessage());
}
}
}