|
|
@@ -368,13 +368,14 @@ class CropLogic
|
|
|
if ($crop->stage_end_time) {
|
|
|
$currentTime = now();
|
|
|
$endTime = $crop->stage_end_time;
|
|
|
-// dd($endTime);
|
|
|
$remainingTime = $currentTime->diffInSeconds($endTime, false);
|
|
|
|
|
|
if ($remainingTime > 0) {
|
|
|
// 确保减少的时间不超过剩余时间
|
|
|
$reducedTime = min($crop_growth_time, $remainingTime);
|
|
|
- $crop->stage_end_time = $endTime->subSeconds($reducedTime);
|
|
|
+ // 使用copy()方法创建副本,避免修改原始对象
|
|
|
+ $newEndTime = $endTime->copy()->subSeconds($reducedTime);
|
|
|
+ $crop->stage_end_time = $newEndTime;
|
|
|
|
|
|
Log::info('化肥减少生长时间', [
|
|
|
'crop_id' => $crop->id,
|
|
|
@@ -383,6 +384,13 @@ class CropLogic
|
|
|
'new_end_time' => $crop->stage_end_time->toDateTimeString(),
|
|
|
'stage_start_time' => $crop->stage_start_time->toDateTimeString()
|
|
|
]);
|
|
|
+ } else {
|
|
|
+ Log::warning('作物已经到达或超过结束时间,无法减少生长时间', [
|
|
|
+ 'crop_id' => $crop->id,
|
|
|
+ 'current_time' => $currentTime->toDateTimeString(),
|
|
|
+ 'stage_end_time' => $endTime->toDateTimeString(),
|
|
|
+ 'remaining_time' => $remainingTime
|
|
|
+ ]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -684,7 +692,8 @@ class CropLogic
|
|
|
$currentStage = $crop->growth_stage;
|
|
|
|
|
|
// 如果当前是成熟期,且超过一定时间,则进入枯萎期
|
|
|
- if ($currentStage === GROWTH_STAGE::MATURE->value) {
|
|
|
+ $currentStageValue = is_object($currentStage) ? $currentStage->value : $currentStage;
|
|
|
+ if ($currentStageValue === GROWTH_STAGE::MATURE->value) {
|
|
|
// 成熟期持续时间,默认为24小时
|
|
|
$matureDuration = 24 * 60 * 60;
|
|
|
|
|
|
@@ -709,7 +718,8 @@ class CropLogic
|
|
|
];
|
|
|
|
|
|
// 确保返回整数值
|
|
|
- return $stageMap[$currentStage->value()] ?? GROWTH_STAGE::WITHERED->value;
|
|
|
+ $currentStageValue = is_object($currentStage) ? $currentStage->value : $currentStage;
|
|
|
+ return $stageMap[$currentStageValue] ?? GROWTH_STAGE::WITHERED->value;
|
|
|
}
|
|
|
|
|
|
/**
|