dongasai 6 сар өмнө
parent
commit
aa0ddeab7c

+ 1 - 0
.augment-guidelines

@@ -17,6 +17,7 @@
 2. 使用MCP执行SQL操作
 3. 使用 `php artisan debug:reproduce-error` 命令进行请求(sys_request_logs表)回放
 4. 编写代码时添加中文注释
+5. 不能使用tinker
 
 ### 任务完成后
 1. 检查git状态并提交代码:使用中文CommitMessage

+ 14 - 2
app/Module/Farm/Commands/ScheduleCropStageUpdatesCommand.php

@@ -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;