Просмотр исходного кода

refactor(AppGame): 优化施肥功能和物品链接

- 在 FertilizerHandler 中添加物品信息获取逻辑
- 修改 CropService 中的 useFertilizer 方法,增加作物生长时间参数
- 更新 CropLogic 中的 useFertilizer 方法,准备根据实际生长时间减少阶段时间
- 修复 UserItemController 中物品ID链接地址
notfff 7 месяцев назад
Родитель
Сommit
62fdb66b1d

+ 3 - 1
app/Module/AppGame/Handler/Land/FertilizerHandler.php

@@ -5,6 +5,7 @@ namespace App\Module\AppGame\Handler\Land;
 use App\Module\AppGame\Handler\BaseHandler;
 use App\Module\Farm\Services\CropService;
 use App\Module\Farm\Services\LandService;
+use App\Module\GameItems\Logics\Item;
 use App\Module\GameItems\Services\ItemService;
 use Google\Protobuf\Internal\Message;
 use Illuminate\Support\Facades\Log;
@@ -56,9 +57,10 @@ class FertilizerHandler extends BaseHandler
         if ($hasItem->error) {
             throw new LogicException("您没有该肥料物品");
         }
+        $item = ItemService::getItemInfo($itemId);
 
         // 调用施肥服务
-        $result = CropService::useFertilizer($userId, $landId);
+        $result = CropService::useFertilizer($userId, $landId,$crop_growth_time);
         if (!$result) {
             throw new LogicException("施肥失败,请检查土地状态或作物生长阶段");
         }

+ 4 - 2
app/Module/Farm/Logics/CropLogic.php

@@ -266,7 +266,7 @@ class CropLogic
      * @param int $landId
      * @return bool
      */
-    public function useFertilizer(int $userId, int $landId): bool
+    public function useFertilizer(int $userId, int $landId,int $crop_growth_time): bool
     {
         try {
             // 获取土地信息
@@ -306,7 +306,9 @@ class CropLogic
             // 更新作物信息
             $crop->fertilized = true;
 
-            // 缩短当前阶段时间(假设化肥效果是缩短30%的时间)
+            //todo 正确的: 根据  crop_growth_time 参数,x秒,来减少当前阶段时间
+
+            // 缩短当前阶段时间(假设化肥效果是缩短30%的时间) todo 废弃
             if ($crop->stage_end_time) {
                 $currentTime = now();
                 $endTime = $crop->stage_end_time;

+ 15 - 15
app/Module/Farm/Services/CropService.php

@@ -29,11 +29,11 @@ class CropService
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
-            
+
             return null;
         }
     }
-    
+
     /**
      * 获取土地上的作物信息
      *
@@ -51,11 +51,11 @@ class CropService
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
-            
+
             return null;
         }
     }
-    
+
     /**
      * 种植作物
      *
@@ -77,11 +77,11 @@ class CropService
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
-            
+
             return null;
         }
     }
-    
+
     /**
      * 收获作物
      *
@@ -101,11 +101,11 @@ class CropService
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
-            
+
             return null;
         }
     }
-    
+
     /**
      * 使用化肥
      *
@@ -113,11 +113,11 @@ class CropService
      * @param int $landId
      * @return bool
      */
-    public static function useFertilizer(int $userId, int $landId): bool
+    public static function useFertilizer(int $userId, int $landId,int $crop_growth_time): bool
     {
         try {
             $cropLogic = new CropLogic();
-            return $cropLogic->useFertilizer($userId, $landId);
+            return $cropLogic->useFertilizer($userId, $landId,$crop_growth_time);
         } catch (\Exception $e) {
             Log::error('使用化肥失败', [
                 'user_id' => $userId,
@@ -125,11 +125,11 @@ class CropService
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
-            
+
             return false;
         }
     }
-    
+
     /**
      * 清理灾害
      *
@@ -151,11 +151,11 @@ class CropService
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
-            
+
             return false;
         }
     }
-    
+
     /**
      * 铲除作物
      *
@@ -175,7 +175,7 @@ class CropService
                 'error' => $e->getMessage(),
                 'trace' => $e->getTraceAsString()
             ]);
-            
+
             return false;
         }
     }

+ 1 - 1
app/Module/GameItems/AdminControllers/UserItemController.php

@@ -54,7 +54,7 @@ class UserItemController extends AdminController
 
             // 添加物品ID列,并链接到物品列表
             $grid->column('item_id', '物品ID')->display(function ($itemId) {
-                $url = admin_url('game-items/' . $itemId);
+                $url = admin_url('game-items/?id=' . $itemId);
                 return "<a href='{$url}' target='_blank'>{$itemId}</a>";
             });