Ver Fonte

refactor(app): 优化错误重现命令和验证逻辑

- 在 ReproduceErrorCommand 中添加请求数据的打印输出,便于调试
-优化 Response 结果的输出格式,使用 dump 函数更直观展示数据结构
- 修正 ValidationBase 中用户 ID 的获取方法,提高数据准确性
- 简化 PetExistsValidator 中的查询逻辑,提升代码可读性
notfff há 7 meses atrás
pai
commit
b10bbcaec0

+ 9 - 7
app/Console/Commands/ReproduceErrorCommand.php

@@ -94,6 +94,8 @@ class ReproduceErrorCommand extends Command
             $this->error("请求记录中缺少 protobuf_json 数据");
             return 1;
         }
+        $this->info("请求数据");
+        dump(json_decode($requestLog->protobuf_json,true));
 
         // 解析 headers 获取 token
         $token = $this->extractToken($requestLog->headers);
@@ -121,15 +123,15 @@ class ReproduceErrorCommand extends Command
         }
 
         // 输出结果
-        $this->info("请求完成,响应结果:");
-        $this->line("状态码: " . $response['status_code']);
-        $this->line("响应头:");
-        foreach ($response['headers'] as $name => $values) {
-            $this->line("  {$name}: " . implode(', ', $values));
-        }
+//        $this->info("请求完成,响应结果:");
+//        $this->line("状态码: " . $response['status_code']);
+//        $this->line("响应头:");
+//        foreach ($response['headers'] as $name => $values) {
+//            $this->line("  {$name}: " . implode(', ', $values));
+//        }
         $this->line("响应内容:");
-        $this->line($response['body']);
 
+        dump(json_decode($response['body'],true));
         return 0;
     }
 

+ 1 - 1
app/Module/AppGame/Validations/ValidationBase.php

@@ -24,7 +24,7 @@ abstract class ValidationBase extends ValidationCore
     {
         $data            = json_decode($message->serializeToJsonString(), true);
         Logger::debug('makeByProrobufUser',$data);
-        $data['user_id'] = SessionApp::getSessionId();
+        $data['user_id'] = SessionApp::getUserId();
 
         return new static($data, [], [], $scene);
     }

+ 1 - 3
app/Module/Pet/Validators/PetExistsValidator.php

@@ -29,9 +29,7 @@ class PetExistsValidator extends Validator
         try {
             // 获取宠物信息
             $pet = PetUser::where('id', $petId)
-                ->when($userId > 0, function($query) use ($userId) {
-                    return $query->where('user_id', $userId);
-                })
+                ->where('user_id',$userId)
                 ->first();
 
             if (!$pet) {