Sfoglia il codice sorgente

修复农场灾害清理时的土地状态问题

- 移除clearDisaster方法中强制修正土地状态为灾害的逻辑
- 修改清理完所有灾害后的土地状态更新逻辑,根据作物生长阶段设置正确的土地状态
- 确保作物成熟时即使有灾害也能保持可收获状态
- 清理灾害后如果作物已成熟,土地状态应为可收获而不是种植中
AI Assistant 6 mesi fa
parent
commit
605848b672
1 ha cambiato i file con 23 aggiunte e 18 eliminazioni
  1. 23 18
      app/Module/Farm/Logics/CropLogic.php

+ 23 - 18
app/Module/Farm/Logics/CropLogic.php

@@ -619,22 +619,17 @@ class CropLogic
                 throw new \Exception('指定类型的灾害不存在');
             }
 
-            // 检查土地状态(移到灾害检查之后,因为作物数据更准确)
-            if ($land->status !== LAND_STATUS::DISASTER->value) {
-                // 如果土地状态不是灾害状态,但作物确实有活跃灾害,修正土地状态
-                Log::warning('土地状态与作物灾害数据不一致,自动修正', [
-                    'user_id' => $userId,
-                    'land_id' => $landId,
-                    'land_status' => $land->status,
-                    'expected_status' => LAND_STATUS::DISASTER->value,
-                    'active_disasters' => array_filter($disasters, function($disaster) {
-                        return ($disaster['status'] ?? '') === 'active';
-                    })
-                ]);
-
-                $land->status = LAND_STATUS::DISASTER->value;
-                $land->save();
-            }
+            // 记录土地状态信息(仅用于日志,不修改土地状态)
+            Log::info('清理灾害时的土地状态', [
+                'user_id' => $userId,
+                'land_id' => $landId,
+                'land_status' => $land->status,
+                'crop_growth_stage' => $crop->growth_stage,
+                'disaster_type' => $disasterType,
+                'active_disasters_count' => count(array_filter($disasters, function($disaster) {
+                    return ($disaster['status'] ?? '') === 'active';
+                }))
+            ]);
 
             // 更新灾害状态
             $disasters[$disasterIndex]['status']     = 'cleared';
@@ -651,10 +646,20 @@ class CropLogic
                 }
             }
 
-            // 如果没有其他活跃灾害,更新土地状态
+            // 如果没有其他活跃灾害,根据作物生长阶段更新土地状态
             $oldLandStatus = $land->status;
             if (!$hasActiveDisaster) {
-                $land->status = LAND_STATUS::PLANTING->value;
+                // 根据作物当前生长阶段设置土地状态
+                if ($crop->growth_stage === GROWTH_STAGE::MATURE->value) {
+                    // 作物已成熟,土地状态为可收获
+                    $land->status = LAND_STATUS::HARVESTABLE->value;
+                } elseif ($crop->growth_stage === GROWTH_STAGE::WITHERED->value) {
+                    // 作物已枯萎,土地状态为枯萎
+                    $land->status = LAND_STATUS::WITHERED->value;
+                } else {
+                    // 其他阶段,土地状态为种植中
+                    $land->status = LAND_STATUS::PLANTING->value;
+                }
                 $land->updateHasCrop();
             }