TestUrsReferralSyncCommand.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Module\Test\Commands;
  3. use App\Module\UrsPromotion\Logics\UrsReferralSyncLogic;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\Log;
  6. /**
  7. * 测试URS推荐关系同步机制重构
  8. */
  9. class TestUrsReferralSyncCommand extends Command
  10. {
  11. /**
  12. * 命令签名
  13. */
  14. protected $signature = 'test:urs-referral-sync {urs_user_id} {farm_user_id}';
  15. /**
  16. * 命令描述
  17. */
  18. protected $description = '测试重构后的URS推荐关系同步机制';
  19. /**
  20. * 执行命令
  21. */
  22. public function handle(): int
  23. {
  24. $ursUserId = (int) $this->argument('urs_user_id');
  25. $farmUserId = (int) $this->argument('farm_user_id');
  26. $this->info("开始测试URS推荐关系同步机制");
  27. $this->info("URS用户ID: {$ursUserId}");
  28. $this->info("农场用户ID: {$farmUserId}");
  29. try {
  30. // 使用重构后的同步逻辑
  31. $syncLogic = new UrsReferralSyncLogic();
  32. $result = $syncLogic->syncReferralRelations($ursUserId, $farmUserId);
  33. $this->info("同步结果: " . ($result ? '成功(首次进入)' : '失败或非首次进入'));
  34. // 显示详细的节点执行情况
  35. $this->info("\n=== 节点执行详情 ===");
  36. $this->info("1. 创建用户映射 - 已执行");
  37. $this->info("2. 请求URS获取上级关系 - 已执行");
  38. $this->info("3. 验证和创建推荐关系 - 已执行");
  39. $this->info("4. 生成关系缓存 - 由UrsReferralService自动处理");
  40. $this->info("5. 更新团队统计 - 由UrsReferralService自动处理");
  41. $this->info("6. 触发事件 - 由UrsReferralService自动处理");
  42. $this->info("\n测试完成!");
  43. return 0;
  44. } catch (\Exception $e) {
  45. $this->error("测试失败: " . $e->getMessage());
  46. $this->error("错误详情: " . $e->getTraceAsString());
  47. return 1;
  48. }
  49. }
  50. }