TestFundLogCollectorCommand.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Module\Game\Commands;
  3. use App\Module\Fund\Models\FundLogModel;
  4. use App\Module\Game\Logics\UserLogCollectors\FundLogCollector;
  5. use UCore\Command\Command;
  6. /**
  7. * 测试资金日志收集器优化命令
  8. *
  9. * 用于测试FundLogCollector的优化效果
  10. */
  11. class TestFundLogCollectorCommand extends Command
  12. {
  13. /**
  14. * 命令名称和参数
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'game:test-fund-log-collector {fund_log_id : 要测试的fund_log记录ID}';
  19. /**
  20. * 命令描述
  21. *
  22. * @var string
  23. */
  24. protected $description = '测试资金日志收集器的优化效果,查看指定fund_log记录会生成什么样的用户日志消息';
  25. /**
  26. * 执行命令
  27. */
  28. public function handleRun()
  29. {
  30. $fundLogId = (int)$this->argument('fund_log_id');
  31. $this->info("🔍 测试资金日志收集器优化效果");
  32. $this->line("📝 测试记录ID: {$fundLogId}");
  33. $this->line("");
  34. try {
  35. // 获取fund_log记录
  36. $fundLog = FundLogModel::find($fundLogId);
  37. if (!$fundLog) {
  38. $this->error("❌ 未找到ID为 {$fundLogId} 的fund_log记录");
  39. return 1;
  40. }
  41. $this->line("📊 原始记录信息:");
  42. $this->line(" 用户ID: {$fundLog->user_id}");
  43. $this->line(" 资金类型: " . (is_object($fundLog->fund_id) ? $fundLog->fund_id->value : $fundLog->fund_id));
  44. $this->line(" 金额: {$fundLog->amount}");
  45. $this->line(" 操作类型: " . (is_object($fundLog->operate_type) ? $fundLog->operate_type->value : $fundLog->operate_type));
  46. $this->line(" 操作ID: {$fundLog->operate_id}");
  47. $this->line(" 备注: {$fundLog->remark}");
  48. $this->line(" 创建时间: " . date('Y-m-d H:i:s', $fundLog->create_time));
  49. $this->line("");
  50. // 创建收集器实例
  51. $collector = new FundLogCollector();
  52. // 测试转换方法
  53. $userLogData = $collector->convertToUserLogPublic($fundLog);
  54. if ($userLogData) {
  55. $this->info("✅ 转换成功!");
  56. $this->line("📝 生成的用户日志信息:");
  57. $this->line(" 用户ID: {$userLogData['user_id']}");
  58. $this->line(" 消息: {$userLogData['message']}");
  59. $this->line(" 来源类型: {$userLogData['source_type']}");
  60. $this->line(" 来源ID: {$userLogData['source_id']}");
  61. $this->line(" 来源表: {$userLogData['source_table']}");
  62. $this->line(" 原始时间: {$userLogData['original_time']}");
  63. } else {
  64. $this->warning("⚠️ 记录被跳过(可能不符合收集条件)");
  65. }
  66. $this->line("");
  67. $this->info("🎉 测试完成!");
  68. return 0;
  69. } catch (\Exception $e) {
  70. $this->error("❌ 测试失败: {$e->getMessage()}");
  71. $this->line("🚨 错误详情: " . $e->getTraceAsString());
  72. return 1;
  73. }
  74. }
  75. }