|
|
@@ -306,17 +306,23 @@ class CropLogic
|
|
|
// 更新作物信息
|
|
|
$crop->fertilized = true;
|
|
|
|
|
|
- //todo 正确的: 根据 crop_growth_time 参数,x秒,来减少当前阶段时间
|
|
|
-
|
|
|
- // 缩短当前阶段时间(假设化肥效果是缩短30%的时间) todo 废弃
|
|
|
+ // 根据 crop_growth_time 参数减少当前阶段时间
|
|
|
if ($crop->stage_end_time) {
|
|
|
$currentTime = now();
|
|
|
$endTime = $crop->stage_end_time;
|
|
|
$remainingTime = $currentTime->diffInSeconds($endTime, false);
|
|
|
|
|
|
if ($remainingTime > 0) {
|
|
|
- $reducedTime = (int)($remainingTime * 0.3);
|
|
|
+ // 确保减少的时间不超过剩余时间
|
|
|
+ $reducedTime = min($crop_growth_time, $remainingTime);
|
|
|
$crop->stage_end_time = $endTime->subSeconds($reducedTime);
|
|
|
+
|
|
|
+ Log::info('化肥减少生长时间', [
|
|
|
+ 'crop_id' => $crop->id,
|
|
|
+ 'reduced_time' => $reducedTime,
|
|
|
+ 'original_end_time' => $endTime->toDateTimeString(),
|
|
|
+ 'new_end_time' => $crop->stage_end_time->toDateTimeString()
|
|
|
+ ]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -586,16 +592,16 @@ class CropLogic
|
|
|
$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 && now()->diffInSeconds($crop->stage_end_time->copy()->subSeconds($matureDuration)) > $matureDuration) {
|
|
|
+ return GROWTH_STAGE::WITHERED->value;
|
|
|
}
|
|
|
|
|
|
- return GROWTH_STAGE::MATURE;
|
|
|
+ return GROWTH_STAGE::MATURE->value;
|
|
|
}
|
|
|
|
|
|
// 正常阶段递增
|
|
|
@@ -620,20 +626,20 @@ class CropLogic
|
|
|
$now = now();
|
|
|
|
|
|
switch ($stage) {
|
|
|
- case GROWTH_STAGE::SEED:
|
|
|
+ case GROWTH_STAGE::SEED->value:
|
|
|
return $now->addSeconds($seed->seed_time);
|
|
|
|
|
|
- case GROWTH_STAGE::SPROUT:
|
|
|
+ case GROWTH_STAGE::SPROUT->value:
|
|
|
return $now->addSeconds($seed->sprout_time);
|
|
|
|
|
|
- case GROWTH_STAGE::GROWTH:
|
|
|
+ case GROWTH_STAGE::GROWTH->value:
|
|
|
return $now->addSeconds($seed->growth_time);
|
|
|
|
|
|
- case GROWTH_STAGE::MATURE:
|
|
|
+ case GROWTH_STAGE::MATURE->value:
|
|
|
// 成熟期持续24小时后进入枯萎期
|
|
|
return $now->addHours(24);
|
|
|
|
|
|
- case GROWTH_STAGE::WITHERED:
|
|
|
+ case GROWTH_STAGE::WITHERED->value:
|
|
|
// 枯萎期没有结束时间
|
|
|
return null;
|
|
|
|