|
|
@@ -39,12 +39,11 @@ class UpdateCropGrowthCommand extends Command
|
|
|
try {
|
|
|
// 获取需要更新生长阶段的作物
|
|
|
/**
|
|
|
- * @var FarmCrop[] $crops
|
|
|
- *
|
|
|
+ * @var \Illuminate\Database\Eloquent\Collection $crops
|
|
|
*/
|
|
|
$crops = FarmCrop::whereNotNull('stage_end_time')
|
|
|
->where('stage_end_time', '<=', now())
|
|
|
- ->where('growth_stage', '<', GROWTH_STAGE::WITHERED)
|
|
|
+ ->where('growth_stage', '<', GROWTH_STAGE::WITHERED->value)
|
|
|
->get();
|
|
|
|
|
|
$this->info("找到 {$crops->count()} 个需要更新的作物");
|
|
|
@@ -63,6 +62,7 @@ class UpdateCropGrowthCommand extends Command
|
|
|
|
|
|
// 更新作物信息
|
|
|
$crop->growth_stage = $newStage;
|
|
|
+ $crop->stage_start_time = now(); // 设置新阶段的开始时间
|
|
|
$crop->stage_end_time = $stageEndTime;
|
|
|
$crop->fertilized = false; // 重置施肥状态
|
|
|
$crop->save();
|
|
|
@@ -106,16 +106,19 @@ class UpdateCropGrowthCommand extends Command
|
|
|
$currentStage = $crop->growth_stage;
|
|
|
|
|
|
// 如果当前是成熟期,且超过一定时间,则进入枯萎期
|
|
|
- if ($currentStage === GROWTH_STAGE::MATURE) {
|
|
|
+ if ($currentStage === GROWTH_STAGE::MATURE->value) {
|
|
|
// 成熟期持续时间,默认为24小时
|
|
|
$matureDuration = 24 * 60 * 60;
|
|
|
|
|
|
// 如果成熟期已经超过指定时间,则进入枯萎期
|
|
|
- if ($crop->stage_end_time && now()->diffInSeconds($crop->stage_end_time->subSeconds($matureDuration)) > $matureDuration) {
|
|
|
- return GROWTH_STAGE::WITHERED;
|
|
|
+ if ($crop->stage_end_time && $crop->stage_end_time instanceof \Carbon\Carbon) {
|
|
|
+ $endTimeMinusDuration = $crop->stage_end_time->copy()->subSeconds($matureDuration);
|
|
|
+ if (now()->diffInSeconds($endTimeMinusDuration) > $matureDuration) {
|
|
|
+ return GROWTH_STAGE::WITHERED->value;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- return GROWTH_STAGE::MATURE;
|
|
|
+ return GROWTH_STAGE::MATURE->value;
|
|
|
}
|
|
|
|
|
|
// 正常阶段递增
|