| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace App\Module\UrsPromotion\Commands;
- use Illuminate\Console\Command;
- use App\Module\UrsPromotion\Services\UrsProfitService;
- use App\Module\UrsPromotion\Services\UrsTalentService;
- use App\Module\UrsPromotion\Enums\UrsProfitType;
- /**
- * URS收益分成测试命令
- *
- * 用于测试URS推广系统的收益分成功能
- */
- class TestUrsProfitCommand extends Command
- {
- /**
- * 命令签名
- */
- protected $signature = 'urs:test-profit {user_id} {amount} {type=planting_reward}';
- /**
- * 命令描述
- */
- protected $description = '测试URS收益分成功能';
- /**
- * 执行命令
- */
- public function handle()
- {
- $userId = (int)$this->argument('user_id');
- $amount = $this->argument('amount');
- $type = $this->argument('type');
-
- $this->info("开始测试URS收益分成功能");
- $this->info("用户ID: {$userId}");
- $this->info("收益金额: {$amount}");
- $this->info("收益类型: {$type}");
- $this->line('');
-
- // 显示用户的推荐关系树
- $this->info("=== 用户推荐关系树 ===");
- $tree = UrsTalentService::getUserReferralTree($userId);
- $this->displayReferralTree($tree);
- $this->line('');
-
- // 执行收益分成
- $this->info("=== 执行收益分成 ===");
-
- if ($type === 'promotion_reward') {
- $profits = UrsProfitService::distributePromotionReward(
- $userId,
- 'test_command',
- time(),
- $amount
- );
- } else {
- $profits = UrsProfitService::distributePlantingReward(
- $userId,
- 'test_command',
- time(),
- $amount
- );
- }
-
- if (empty($profits)) {
- $this->warn("没有产生任何收益分成");
- } else {
- $this->info("成功分成给 " . count($profits) . " 个用户:");
- foreach ($profits as $profit) {
- $rate = round($profit->profit_rate * 100, 2);
- $levelName = $profit->getRelationLevelName();
- $this->line("- 用户{$profit->user_id}: {$profit->profit_amount} ({$rate}%, {$levelName})");
- }
- }
-
- $this->line('');
- $this->info("测试完成!");
- }
-
- /**
- * 显示推荐关系树
- */
- private function displayReferralTree(array $tree): void
- {
- $this->line("用户 {$tree['user_id']} 的团队结构:");
-
- if (!empty($tree['direct'])) {
- $this->line(" 直推用户 (" . count($tree['direct']) . "人):");
- foreach ($tree['direct'] as $user) {
- $this->line(" - 用户{$user['user_id']}");
- }
- }
-
- if (!empty($tree['indirect'])) {
- $this->line(" 间推用户 (" . count($tree['indirect']) . "人):");
- foreach ($tree['indirect'] as $user) {
- $this->line(" - 用户{$user['user_id']} (通过用户{$user['referrer_id']})");
- }
- }
-
- if (!empty($tree['third'])) {
- $this->line(" 三推用户 (" . count($tree['third']) . "人):");
- foreach ($tree['third'] as $user) {
- $this->line(" - 用户{$user['user_id']} (通过用户{$user['referrer_id']})");
- }
- }
-
- if (empty($tree['direct']) && empty($tree['indirect']) && empty($tree['third'])) {
- $this->line(" 无团队成员");
- }
- }
- }
|