75 lines
2.2 KiB
PHP
75 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace app\jobs\store\platformCommission;
|
|
|
|
|
|
|
|
use app\common\model\store\platformCommission\LegumesLog;
|
|
use app\common\repositories\store\platformCommission\RecordRepository;
|
|
use crmeb\interfaces\JobInterface;
|
|
use think\facade\Log;
|
|
use think\facade\Queue;
|
|
|
|
/**
|
|
* Common: 全平台豆豆计算
|
|
* Author: wu-hui
|
|
* Time: 2023/12/29 11:13
|
|
* Class ComputeIntegralJob
|
|
* @package app\jobs\store\platformCommission
|
|
*/
|
|
class ComputeIntegralJob implements JobInterface{
|
|
|
|
public function fire($job,$data){
|
|
try{
|
|
Log::info("全平台豆豆计算 - 开始处理: ".var_export($data,1));
|
|
$page = $data['page'] ?? 0;
|
|
$limit = 1000;
|
|
$set = app()->make(RecordRepository::class)->getBaseConfig();
|
|
// 获取当前页数据 有效记录、已获取积分低于订单金额
|
|
$model = LegumesLog::field('id,order_money,get_legumes,get_integral')
|
|
->whereIn('status',[0,1])
|
|
->where('get_integral < order_money');
|
|
$count = $model->count();
|
|
$list = $model->page($page,$limit)->select()->toArray();
|
|
if(count($list) <= 0) throw new \Exception('无处理数据!');
|
|
// 循环处理
|
|
$updateData = [];
|
|
foreach($list as $item){
|
|
$getIntegral = (float)sprintf("%.2f",$item['get_legumes'] * $set['legumes_price']);
|
|
$updateData[] = [
|
|
'id' => $item['id'],
|
|
'get_integral' => $getIntegral >= $item['order_money'] ? $item['order_money'] : $getIntegral
|
|
];
|
|
}
|
|
LegumesLog::batchUpdate(array_values($updateData));
|
|
// 判断:是否存在下一页
|
|
$currentLimit = $page * $limit;
|
|
if($currentLimit < $count){
|
|
Queue::push(ComputeIntegralJob::class,[
|
|
'page' => $page + 1
|
|
]);
|
|
}
|
|
}
|
|
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));
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|