|
|
@@ -44,12 +44,24 @@ class ScheduleCropStageUpdatesCommand extends Command
|
|
|
$startTime = now();
|
|
|
$endTime = now()->addSeconds(60);
|
|
|
|
|
|
- $crops = FarmCrop::whereNotNull('stage_end_time')
|
|
|
+ // 先查找未来60秒内需要状态变更的作物
|
|
|
+ $futureCrops = FarmCrop::whereNotNull('stage_end_time')
|
|
|
->whereBetween('stage_end_time', [$startTime, $endTime])
|
|
|
->where('growth_stage', '<', GROWTH_STAGE::WITHERED->value)
|
|
|
->get();
|
|
|
|
|
|
- $this->info("找到 {$crops->count()} 个需要在未来60秒内状态变更的作物");
|
|
|
+ // 再查找已经超过结束时间但尚未更新的作物(最多处理50个,避免一次处理太多)
|
|
|
+ $pastCrops = FarmCrop::whereNotNull('stage_end_time')
|
|
|
+ ->where('stage_end_time', '<', $startTime)
|
|
|
+ ->where('growth_stage', '<', GROWTH_STAGE::WITHERED->value)
|
|
|
+ ->limit(50)
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ // 合并两个集合
|
|
|
+ $crops = $futureCrops->merge($pastCrops);
|
|
|
+
|
|
|
+ $this->info("找到 {$futureCrops->count()} 个需要在未来60秒内状态变更的作物");
|
|
|
+ $this->info("找到 {$pastCrops->count()} 个已超过结束时间但尚未更新的作物");
|
|
|
|
|
|
$scheduledCount = 0;
|
|
|
|