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();