From 5c8dc13c60fbe4f46b4d9a3694286bf949650e6c Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Fri, 29 Dec 2023 11:50:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E5=85=A8=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E7=94=A8=E6=88=B7=E8=B1=86=E8=B1=86=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E7=A7=AF=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platformCommission/LegumesRepository.php | 2 +- .../platformCommission/ComputeIntegralJob.php | 74 +++++++++++++++++++ .../platformCommission/SparateLegumesJob.php | 6 +- 3 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 app/jobs/store/platformCommission/ComputeIntegralJob.php diff --git a/app/common/repositories/store/platformCommission/LegumesRepository.php b/app/common/repositories/store/platformCommission/LegumesRepository.php index bb42020..3554b78 100644 --- a/app/common/repositories/store/platformCommission/LegumesRepository.php +++ b/app/common/repositories/store/platformCommission/LegumesRepository.php @@ -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,[ diff --git a/app/jobs/store/platformCommission/ComputeIntegralJob.php b/app/jobs/store/platformCommission/ComputeIntegralJob.php new file mode 100644 index 0000000..8413388 --- /dev/null +++ b/app/jobs/store/platformCommission/ComputeIntegralJob.php @@ -0,0 +1,74 @@ +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)); + } + + + + + + + + + + + +} diff --git a/app/jobs/store/platformCommission/SparateLegumesJob.php b/app/jobs/store/platformCommission/SparateLegumesJob.php index a0f5fde..b7ff160 100644 --- a/app/jobs/store/platformCommission/SparateLegumesJob.php +++ b/app/jobs/store/platformCommission/SparateLegumesJob.php @@ -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();