Pārlūkot izejas kodu

自动收获修复

Your Name 5 mēneši atpakaļ
vecāks
revīzija
44d934df08
2 mainītis faili ar 25 papildinājumiem un 12 dzēšanām
  1. 4 4
      UCore/Helper/Logger.php
  2. 21 8
      app/Module/Pet/Logic/PetAutoSkillLogic.php

+ 4 - 4
UCore/Helper/Logger.php

@@ -21,7 +21,7 @@ class Logger
      */
     static public function debug($msg, $data = [])
     {
-        Log::debug($msg . ' ' . json_encode($data));
+        Log::debug($msg . ' ' .json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
     }
 
     /**
@@ -33,7 +33,7 @@ class Logger
      */
     static public function error($msg, $data = [])
     {
-        Log::error($msg . ' ' . json_encode($data));
+        Log::error($msg . ' ' . json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
         DB::table('system_logs')->insert([
                                              'level1'  => 'error',
                                              'message' => $msg,
@@ -45,7 +45,7 @@ class Logger
 
     static public function warning($msg, $data = [])
     {
-        Log::warning($msg . ' ' . json_encode($data));
+        Log::warning($msg . ' ' . json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
     }
 
     /**
@@ -79,7 +79,7 @@ class Logger
 
     static public function info($msg, $data = [])
     {
-        Log::info($msg . ' ' . json_encode($data));
+        Log::info($msg . ' ' . json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
     }
 
 

+ 21 - 8
app/Module/Pet/Logic/PetAutoSkillLogic.php

@@ -10,6 +10,7 @@ use App\Module\GameItems\Services\ItemService;
 
 use Illuminate\Support\Facades\Log;
 use UCore\Dto\Res;
+use UCore\Helper\Logger;
 
 /**
  * 宠物自动技能处理逻辑
@@ -45,7 +46,7 @@ class PetAutoSkillLogic
         $harvestableLands = LandService::getHarvestableLands($userId);
 
         $harvestCount = 0;
-        $autoClearedCount = 0;
+
         $harvestResults = [];
 
         if (!$harvestableLands->isEmpty()) {
@@ -81,7 +82,7 @@ class PetAutoSkillLogic
         // 记录统计信息
         $this->recordSkillStatistics($activeSkill, 'auto_harvest', [
             'harvest_count' => $harvestCount,
-            'auto_cleared_count' => $autoClearedCount,
+
             'total_lands_checked' => $harvestableLands->count(),
             'harvest_results' => $harvestResults
         ]);
@@ -91,8 +92,6 @@ class PetAutoSkillLogic
             'pet_id' => $pet->id,
             'user_id' => $userId,
             'harvest_count' => $harvestCount,
-            'auto_cleared_count' => $autoClearedCount,
-
             'total_lands' => $harvestableLands->count()
         ]);
     }
@@ -834,13 +833,15 @@ class PetAutoSkillLogic
             ->first();
 
         if (!$land) {
+            Logger::warning('自动清理枯萎作物失败', [
+                'user_id' => $userId,
+                'land_id' => $landId,
+                'error' => '土地不存在'
+            ]);
             return false;
         }
 
-        // 检查土地状态是否为枯萎状态
-        if ($land->status !== \App\Module\Farm\Enums\LAND_STATUS::WITHERED->value) {
-            return false;
-        }
+    
 
         // 获取土地上的作物
         $crop = \App\Module\Farm\Models\FarmCrop::where('land_id', $landId)->first();
@@ -854,6 +855,11 @@ class PetAutoSkillLogic
         // 检查作物是否为枯萎状态
         $cropStageValue = is_object($crop->growth_stage) ? $crop->growth_stage->value : $crop->growth_stage;
         if ($cropStageValue !== \App\Module\Farm\Enums\GROWTH_STAGE::WITHERED->value) {
+            Logger::warning('自动清理枯萎作物失败', [
+                'user_id' => $userId,
+                'land_id' => $landId,
+                'error' => '作物不是枯萎状态'
+            ]);
             return false;
         }
 
@@ -868,6 +874,13 @@ class PetAutoSkillLogic
             ]);
             return true;
         }
+        else {
+            Logger::warning('自动清理枯萎作物失败', [
+                'user_id' => $userId,
+                'land_id' => $landId,
+                'error' => '铲除作物失败'
+            ]);
+        }
 
         return false;
     }