88 lines
3.8 KiB
PHP
88 lines
3.8 KiB
PHP
<?php
|
|
namespace app\jobs\store\platformCommission\refundOrderHandle;
|
|
|
|
|
|
use app\common\model\store\platformCommission\Legumes;
|
|
use app\common\model\store\platformCommission\LegumesLog;
|
|
use app\common\model\store\platformCommission\Record;
|
|
use app\jobs\store\platformCommission\ComputeIntegralJob;
|
|
use crmeb\interfaces\JobInterface;
|
|
use think\facade\Log;
|
|
use think\facade\Queue;
|
|
|
|
/**
|
|
* Common: 订单退款成功 - 豆豆和积分处理
|
|
* Author: wu-hui
|
|
* Time: 2024/01/03 10:09
|
|
* Class HandleLegumesJob
|
|
* @package app\jobs\store\platformCommission\refundOrderHandle
|
|
*/
|
|
class HandleLegumesJob implements JobInterface{
|
|
public function fire($job,$data){
|
|
try{
|
|
Log::info("订单退款成功 - 豆豆和积分 - 开始处理: ".var_export($data,1));
|
|
// 获取当前抽成信息
|
|
$platformCommissionRecord = Record::where('order_product_id',$data['order_product_id'])->find();
|
|
// 判断:当前抽成豆豆信息是否已经结算,未结算-无操作处理(结算时处理退款内容);已结算-处理退款相关内容
|
|
$maxEndTime = Legumes::max('end_time');
|
|
$createTime = strtotime($platformCommissionRecord->create_time);
|
|
if($createTime < $maxEndTime){
|
|
// 已结算 - 处理退款相关内容
|
|
$legumesId = (int)Legumes::where('start_time','<',$createTime)->where('end_time','>',$createTime)->value('id');
|
|
if($legumesId > 0){
|
|
// 获取需要修改的信息列表
|
|
$correlationList = LegumesLog::field('id,uid,order_money,refund_order_money,get_legumes,refund_get_legumes,get_integral')
|
|
->where('legumes_id',$legumesId)
|
|
->select()
|
|
->toArray();
|
|
// 循环处理
|
|
$updateData = [];
|
|
foreach($correlationList as $correlationInfo){
|
|
// 计算 退款金额
|
|
$reduceOrderMoney = (float)sprintf("%.2f",$correlationInfo['order_money'] * $data['refund_rate'] / 100);
|
|
$refundOrderMoney = bcadd($correlationInfo['refund_order_money'],$reduceOrderMoney,2);
|
|
if($refundOrderMoney > $correlationInfo['order_money']) $refundOrderMoney = $correlationInfo['order_money'];
|
|
// 计算 退款豆豆
|
|
$reduceGetLegumes = (float)sprintf("%.2f",$correlationInfo['get_legumes'] * $data['refund_rate'] / 100);
|
|
$refundGetLegumes = bcadd($correlationInfo['refund_get_legumes'],$reduceGetLegumes,3);
|
|
if($refundGetLegumes > $correlationInfo['get_legumes']) $refundGetLegumes = $correlationInfo['get_legumes'];
|
|
// 记录修改信息
|
|
$updateData[] = [
|
|
'id' => $correlationInfo['id'],
|
|
'refund_order_money' => $refundOrderMoney,
|
|
'refund_get_legumes' => $refundGetLegumes
|
|
];
|
|
}
|
|
|
|
if(count($updateData) > 0) {
|
|
LegumesLog::batchUpdate(array_values($updateData));
|
|
Queue::push(ComputeIntegralJob::class,[
|
|
'ids' => array_column($correlationList,'id')
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch(\Exception $e){
|
|
$data['error_msg'] = $e->getMessage();
|
|
Log::info('订单退款成功 - 豆豆和积分 - 失败: '.var_export($data,1));
|
|
}
|
|
$job->delete();
|
|
}
|
|
|
|
public function failed($data){
|
|
Log::info('订单退款成功 - 豆豆和积分 - 失败(failed): '.var_export($data,1));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|