| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace App\Module\Game\Commands;
- use App\Module\Fund\Models\FundLogModel;
- use App\Module\Game\Logics\UserLogCollectors\FundLogCollector;
- use UCore\Command\Command;
- /**
- * 测试资金日志收集器优化命令
- *
- * 用于测试FundLogCollector的优化效果
- */
- class TestFundLogCollectorCommand extends Command
- {
- /**
- * 命令名称和参数
- *
- * @var string
- */
- protected $signature = 'game:test-fund-log-collector {fund_log_id : 要测试的fund_log记录ID}';
- /**
- * 命令描述
- *
- * @var string
- */
- protected $description = '测试资金日志收集器的优化效果,查看指定fund_log记录会生成什么样的用户日志消息';
- /**
- * 执行命令
- */
- public function handleRun()
- {
- $fundLogId = (int)$this->argument('fund_log_id');
- $this->info("🔍 测试资金日志收集器优化效果");
- $this->line("📝 测试记录ID: {$fundLogId}");
- $this->line("");
- try {
- // 获取fund_log记录
- $fundLog = FundLogModel::find($fundLogId);
- if (!$fundLog) {
- $this->error("❌ 未找到ID为 {$fundLogId} 的fund_log记录");
- return 1;
- }
- $this->line("📊 原始记录信息:");
- $this->line(" 用户ID: {$fundLog->user_id}");
- $this->line(" 资金类型: " . (is_object($fundLog->fund_id) ? $fundLog->fund_id->value : $fundLog->fund_id));
- $this->line(" 金额: {$fundLog->amount}");
- $this->line(" 操作类型: " . (is_object($fundLog->operate_type) ? $fundLog->operate_type->value : $fundLog->operate_type));
- $this->line(" 操作ID: {$fundLog->operate_id}");
- $this->line(" 备注: {$fundLog->remark}");
- $this->line(" 创建时间: " . date('Y-m-d H:i:s', $fundLog->create_time));
- $this->line("");
- // 创建收集器实例
- $collector = new FundLogCollector();
- // 测试转换方法
- $userLogData = $collector->convertToUserLogPublic($fundLog);
- if ($userLogData) {
- $this->info("✅ 转换成功!");
- $this->line("📝 生成的用户日志信息:");
- $this->line(" 用户ID: {$userLogData['user_id']}");
- $this->line(" 消息: {$userLogData['message']}");
- $this->line(" 来源类型: {$userLogData['source_type']}");
- $this->line(" 来源ID: {$userLogData['source_id']}");
- $this->line(" 来源表: {$userLogData['source_table']}");
- $this->line(" 原始时间: {$userLogData['original_time']}");
- } else {
- $this->warning("⚠️ 记录被跳过(可能不符合收集条件)");
- }
- $this->line("");
- $this->info("🎉 测试完成!");
- return 0;
- } catch (\Exception $e) {
- $this->error("❌ 测试失败: {$e->getMessage()}");
- $this->line("🚨 错误详情: " . $e->getTraceAsString());
- return 1;
- }
- }
- }
|