|
|
@@ -1,219 +0,0 @@
|
|
|
-<?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\Models\UrsUserReferral;
|
|
|
-use App\Module\UrsPromotion\Models\UrsUserTalent;
|
|
|
-use App\Module\UrsPromotion\Models\UrsProfit;
|
|
|
-use App\Module\UrsPromotion\Models\UrsTalentConfig;
|
|
|
-use Illuminate\Support\Facades\DB;
|
|
|
-
|
|
|
-/**
|
|
|
- * URS推广模块集成测试命令
|
|
|
- *
|
|
|
- * 用于全面测试URS推广系统的各项功能
|
|
|
- */
|
|
|
-class UrsPromotionIntegrationTestCommand extends Command
|
|
|
-{
|
|
|
- /**
|
|
|
- * 命令签名
|
|
|
- */
|
|
|
- protected $signature = 'urs:integration-test {--reset : 重置测试数据}';
|
|
|
-
|
|
|
- /**
|
|
|
- * 命令描述
|
|
|
- */
|
|
|
- protected $description = 'URS推广模块集成测试';
|
|
|
-
|
|
|
- /**
|
|
|
- * 执行命令
|
|
|
- */
|
|
|
- public function handle()
|
|
|
- {
|
|
|
- $this->info('开始URS推广模块集成测试...');
|
|
|
- $this->line('');
|
|
|
-
|
|
|
- // 检查是否重置数据
|
|
|
- if ($this->option('reset')) {
|
|
|
- $this->resetTestData();
|
|
|
- }
|
|
|
-
|
|
|
- // 1. 测试达人等级配置
|
|
|
- $this->testTalentConfigs();
|
|
|
-
|
|
|
- // 2. 测试推荐关系
|
|
|
- $this->testReferralRelations();
|
|
|
-
|
|
|
- // 3. 测试达人等级计算
|
|
|
- $this->testTalentLevelCalculation();
|
|
|
-
|
|
|
- // 4. 测试收益分成
|
|
|
- $this->testProfitDistribution();
|
|
|
-
|
|
|
- // 5. 测试统计功能
|
|
|
- $this->testStatistics();
|
|
|
-
|
|
|
- $this->line('');
|
|
|
- $this->info('URS推广模块集成测试完成!');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 重置测试数据
|
|
|
- */
|
|
|
- private function resetTestData(): void
|
|
|
- {
|
|
|
- $this->warn('重置测试数据...');
|
|
|
-
|
|
|
- // 清空测试数据(保留配置)
|
|
|
- UrsProfit::where('source_type', 'like', 'test_%')->delete();
|
|
|
- UrsUserTalent::whereIn('user_id', [2001, 2002, 2003, 2004, 2005])->delete();
|
|
|
- UrsUserReferral::whereIn('user_id', [2001, 2002, 2003, 2004, 2005])->delete();
|
|
|
-
|
|
|
- $this->info('测试数据重置完成');
|
|
|
- $this->line('');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 测试达人等级配置
|
|
|
- */
|
|
|
- private function testTalentConfigs(): void
|
|
|
- {
|
|
|
- $this->info('=== 测试达人等级配置 ===');
|
|
|
-
|
|
|
- $configs = UrsTalentService::getAllTalentConfigs();
|
|
|
- $this->line('达人等级配置数量: ' . count($configs));
|
|
|
-
|
|
|
- foreach ($configs as $config) {
|
|
|
- $this->line("等级{$config['level']}: {$config['name']} (直推{$config['direct_count_required']}人, 团队{$config['promotion_count_required']}人)");
|
|
|
- }
|
|
|
-
|
|
|
- $this->line('');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 测试推荐关系
|
|
|
- */
|
|
|
- private function testReferralRelations(): void
|
|
|
- {
|
|
|
- $this->info('=== 测试推荐关系 ===');
|
|
|
-
|
|
|
- // 创建测试推荐关系: 2001 -> 2002 -> 2003 -> 2004
|
|
|
- $referrals = [
|
|
|
- ['urs_user_id' => 2002, 'urs_referrer_id' => 2001],
|
|
|
- ['urs_user_id' => 2003, 'urs_referrer_id' => 2002],
|
|
|
- ['urs_user_id' => 2004, 'urs_referrer_id' => 2003],
|
|
|
- ['urs_user_id' => 2005, 'urs_referrer_id' => 2001], // 2001的另一个直推
|
|
|
- ];
|
|
|
-
|
|
|
- foreach ($referrals as $referral) {
|
|
|
- UrsUserReferral::updateOrCreate(
|
|
|
- ['urs_user_id' => $referral['urs_user_id']],
|
|
|
- array_merge($referral, [
|
|
|
- 'referral_time' => now(),
|
|
|
- 'status' => UrsUserReferral::STATUS_VALID,
|
|
|
- ])
|
|
|
- );
|
|
|
- $this->line("创建推荐关系: URS用户{$referral['urs_user_id']} <- URS用户{$referral['urs_referrer_id']}");
|
|
|
- }
|
|
|
-
|
|
|
- $this->line('');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 测试达人等级计算
|
|
|
- */
|
|
|
- private function testTalentLevelCalculation(): void
|
|
|
- {
|
|
|
- $this->info('=== 测试达人等级计算 ===');
|
|
|
-
|
|
|
- // 更新用户2001的达人等级
|
|
|
- $talent = UrsTalentService::updateUserTalent(2001);
|
|
|
- if ($talent) {
|
|
|
- $this->line("用户2001达人等级: {$talent->getTalentLevelName()}");
|
|
|
- $this->line("直推: {$talent->direct_count}, 间推: {$talent->indirect_count}, 三推: {$talent->third_count}, 总计: {$talent->promotion_count}");
|
|
|
- }
|
|
|
-
|
|
|
- // 显示推荐关系树
|
|
|
- $tree = UrsTalentService::getUserReferralTree(2001);
|
|
|
- $this->line('推荐关系树:');
|
|
|
- $this->line(" 直推: " . count($tree['direct']) . "人");
|
|
|
- $this->line(" 间推: " . count($tree['indirect']) . "人");
|
|
|
- $this->line(" 三推: " . count($tree['third']) . "人");
|
|
|
-
|
|
|
- $this->line('');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 测试收益分成
|
|
|
- */
|
|
|
- private function testProfitDistribution(): void
|
|
|
- {
|
|
|
- $this->info('=== 测试收益分成 ===');
|
|
|
-
|
|
|
- // 测试推广收益分成
|
|
|
- $this->line('测试推广收益分成 (用户2005进入农场, 奖励500金币):');
|
|
|
- $profits = UrsProfitService::distributePromotionReward(2005, 'test_farm_enter', 12345, '500');
|
|
|
- $this->displayProfits($profits);
|
|
|
-
|
|
|
- // 测试种植收益分成
|
|
|
- $this->line('测试种植收益分成 (用户2004收获作物, 奖励1000金币):');
|
|
|
- $profits = UrsProfitService::distributePlantingReward(2004, 'test_farm_harvest', 67890, '1000');
|
|
|
- $this->displayProfits($profits);
|
|
|
-
|
|
|
- $this->line('');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 测试统计功能
|
|
|
- */
|
|
|
- private function testStatistics(): void
|
|
|
- {
|
|
|
- $this->info('=== 测试统计功能 ===');
|
|
|
-
|
|
|
- // 获取用户2001的收益统计
|
|
|
- $stats = UrsProfitService::getUserProfitStats(2001);
|
|
|
- $this->line("用户2001总收益: {$stats['total_amount']} (共{$stats['total_count']}笔)");
|
|
|
-
|
|
|
- if (!empty($stats['by_type'])) {
|
|
|
- foreach ($stats['by_type'] as $type => $data) {
|
|
|
- $typeName = $type === 'promotion_reward' ? '推广收益' : '种植收益';
|
|
|
- $this->line(" {$typeName}: {$data['amount']} (共{$data['count']}笔)");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!empty($stats['by_level'])) {
|
|
|
- foreach ($stats['by_level'] as $level => $data) {
|
|
|
- $levelName = match($level) {
|
|
|
- 1 => '直推',
|
|
|
- 2 => '间推',
|
|
|
- 3 => '三推',
|
|
|
- default => "层级{$level}",
|
|
|
- };
|
|
|
- $this->line(" {$levelName}: {$data['amount']} (共{$data['count']}笔)");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $this->line('');
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 显示收益分成结果
|
|
|
- */
|
|
|
- private function displayProfits(array $profits): void
|
|
|
- {
|
|
|
- if (empty($profits)) {
|
|
|
- $this->line(' 无收益分成');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- foreach ($profits as $profit) {
|
|
|
- $rate = round($profit->profit_rate * 100, 2);
|
|
|
- $levelName = $profit->getRelationLevelName();
|
|
|
- $typeName = $profit->getProfitTypeName();
|
|
|
- $this->line(" 用户{$profit->user_id}: {$profit->profit_amount} ({$rate}%, {$levelName}, {$typeName})");
|
|
|
- }
|
|
|
- }
|
|
|
-}
|