添加:全平台用户豆豆转换积分

This commit is contained in:
wuhui_zzw 2023-12-29 11:50:32 +08:00
parent bb411c89dd
commit 5c8dc13c60
3 changed files with 79 additions and 3 deletions

View File

@ -52,7 +52,7 @@ class LegumesRepository extends BaseRepository{
]);
// 修改豆豆实时价格
$cid = app()->make(ConfigClassifyRepository::class)->keyById('platform_commission');
$set['legumes_price'] = $legumesNum;
$set['legumes_price'] = $tomorrowLegumesPrice;
app()->make(ConfigValueRepository::class)->save($cid, $set, 0);
// 触发事件 开始给每个消费用户分豆豆
Queue::push(SparateLegumesJob::class,[

View File

@ -0,0 +1,74 @@
<?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));
}
}

View File

@ -4,11 +4,11 @@ namespace app\jobs\store\platformCommission;
use app\common\model\store\order\StoreOrder;
use app\common\model\store\platformCommission\LegumesLog;
use app\common\repositories\store\platformCommission\LegumesLogRepository;
use app\common\repositories\store\platformCommission\LegumesRepository;
use crmeb\interfaces\JobInterface;
use think\facade\Log;
use think\facade\Queue;
/**
* Common: 给本周期内消费者分豆豆
@ -52,10 +52,12 @@ class SparateLegumesJob implements JobInterface{
}
// 添加数据
if(count($insertData) > 0) app()->make(LegumesLogRepository::class)->insertAll($insertData);
// 修改豆豆周期分配状态
app()->make(LegumesRepository::class)->update($data['legumes_id'],[
'status' => 1
]);
// 触发全平台豆豆转积分操作
Queue::push(ComputeIntegralJob::class);
}
catch(\Exception $e){
$data['error_msg'] = $e->getMessage();