|
|
@@ -4,7 +4,10 @@ namespace Tests\Integration;
|
|
|
|
|
|
use App\Http\Controllers\agent\ProfileController;
|
|
|
use App\Models\Agent\Agent;
|
|
|
+use App\Models\Agent\AgentSetting;
|
|
|
+use App\Services\Agent\AgentPeriodReportService;
|
|
|
use App\Services\Agent\AgentReportService;
|
|
|
+use App\Services\PaymentOrderService;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
@@ -82,4 +85,81 @@ class AgentDashboardTest extends TestCase
|
|
|
$rows = array_column((new AgentReportService())->reportRows(null, ['start_date' => '2026-09-07'])['list'], null, 'id');
|
|
|
$this->assertSame(0, $rows[$equity->id]['member_count'], 'admin agent report still counts only the equity agent\'s own members');
|
|
|
}
|
|
|
+
|
|
|
+ public function test_charts_group_registrations_and_deduplicate_successful_daily_deposits_across_channels(): void
|
|
|
+ {
|
|
|
+ $agent = $this->agent();
|
|
|
+ $other = $this->agent();
|
|
|
+ foreach ([['a', $agent, '2026-08-31'], ['b', $agent, '2026-09-02'], ['c', $other, '2026-09-02']] as [$id, $owner, $day]) {
|
|
|
+ DB::table('users')->insert(['member_id' => $id, 'username' => $id, 'agent_id' => $owner->id, 'created_at' => $day . ' 00:00:00']);
|
|
|
+ }
|
|
|
+ DB::table('recharges')->insert(['member_id' => 'a', 'status' => 1, 'amount' => 100,
|
|
|
+ 'exchange_rate' => '7.1250', 'created_at' => '2026-09-02 10:00:00']);
|
|
|
+ DB::table('recharges')->insert(['member_id' => 'a', 'status' => 1, 'amount' => 20, 'created_at' => '2026-09-03 00:00:00']);
|
|
|
+ foreach ([
|
|
|
+ ['a', PaymentOrderService::TYPE_PAY, PaymentOrderService::STATUS_SUCCESS, 30],
|
|
|
+ ['b', PaymentOrderService::TYPE_SELF_PAY, PaymentOrderService::STATUS_SUCCESS, 40],
|
|
|
+ ['c', PaymentOrderService::TYPE_PAY, PaymentOrderService::STATUS_SUCCESS, 1000],
|
|
|
+ ['a', PaymentOrderService::TYPE_PAYOUT, PaymentOrderService::STATUS_SUCCESS, 1000],
|
|
|
+ ['a', PaymentOrderService::TYPE_PAY, PaymentOrderService::STATUS_STAY, 1000],
|
|
|
+ ] as [$member, $type, $status, $amount]) {
|
|
|
+ DB::table('payment_orders')->insert(['member_id' => $member, 'type' => $type, 'status' => $status,
|
|
|
+ 'amount' => $amount, 'created_at' => '2026-09-02 23:59:59']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $range = ['start_date' => '2026-08-31', 'end_date' => '2026-09-07'];
|
|
|
+ $days = $this->charts($agent, $range);
|
|
|
+ $this->assertSame('own', $days['scope']);
|
|
|
+ $this->assertNull($days['equity']);
|
|
|
+ $this->assertSame([1, 0, 1, 0, 0, 0, 0, 0], array_column($days['registrations'], 'new_members'));
|
|
|
+ $this->assertSame([0, 0, 2, 1, 0, 0, 0, 0], array_column($days['daily_deposits'], 'deposit_members'));
|
|
|
+ $this->assertSame(['0.0000', '0.0000', '782.5000', '20.0000', '0.0000', '0.0000', '0.0000', '0.0000'], array_column($days['daily_deposits'], 'deposit_amount'));
|
|
|
+
|
|
|
+ $weeks = $this->charts($agent, $range + ['period' => 'week']);
|
|
|
+ $this->assertSame(['2026-W36', '2026-W37'], array_column($weeks['registrations'], 'period_key'));
|
|
|
+ $this->assertSame([2, 0], array_column($weeks['registrations'], 'new_members'));
|
|
|
+ $this->assertSame($days['daily_deposits'], $weeks['daily_deposits']);
|
|
|
+ $months = $this->charts($agent, $range + ['period' => 'month']);
|
|
|
+ $this->assertSame(['2026-08', '2026-09'], array_column($months['registrations'], 'period_key'));
|
|
|
+ $this->assertSame([1, 1], array_column($months['registrations'], 'new_members'));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_shareholder_chart_shows_current_formal_holdings_and_real_platform_members(): void
|
|
|
+ {
|
|
|
+ Schema::table('users', function (Blueprint $table) {
|
|
|
+ $table->integer('from')->default(1);
|
|
|
+ $table->integer('user_type')->default(0);
|
|
|
+ });
|
|
|
+ $holder = $this->agent(Agent::TYPE_EQUITY);
|
|
|
+ $other = $this->agent(Agent::TYPE_EQUITY);
|
|
|
+ $test = $this->agents->create(['username' => 'test-holder', 'password' => 'secret1', 'type' => Agent::TYPE_EQUITY, 'is_test' => 1]);
|
|
|
+ foreach ([[$holder, '12.3456'], [$other, '7.6544'], [$test, '9.5000']] as [$shareholder, $percent]) {
|
|
|
+ Agent::query()->whereKey($shareholder->id)->update(['equity_percent' => $percent]);
|
|
|
+ }
|
|
|
+ AgentSetting::current()->update(['company_equity_percent' => '60.5000']);
|
|
|
+ foreach ([['real', null, 1, 0], ['test', $test->id, 1, 0], ['guest', null, 2, 1], ['simulated', null, 1, 2]] as [$id, $agentId, $from, $type]) {
|
|
|
+ DB::table('users')->insert(['member_id' => $id, 'username' => $id, 'agent_id' => $agentId,
|
|
|
+ 'from' => $from, 'user_type' => $type, 'created_at' => now()]);
|
|
|
+ DB::table('recharges')->insert(['member_id' => $id, 'status' => 1, 'amount' => 100, 'created_at' => now()]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $charts = $this->charts($holder, ['start_date' => '2026-09-07']);
|
|
|
+ $this->assertSame('platform', $charts['scope']);
|
|
|
+ $this->assertSame([1], array_column($charts['registrations'], 'new_members'));
|
|
|
+ $this->assertSame([1], array_column($charts['daily_deposits'], 'deposit_members'));
|
|
|
+ $this->assertSame(['100.0000'], array_column($charts['daily_deposits'], 'deposit_amount'));
|
|
|
+ $this->assertSame([
|
|
|
+ 'own_percent' => '12.3456', 'other_percent' => '7.6544', 'company_percent' => '60.5000', 'remaining_percent' => '19.5000',
|
|
|
+ ], $charts['equity']);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function charts(Agent $agent, array $params): array
|
|
|
+ {
|
|
|
+ $request = Request::create('/agent/dashboard/charts', 'GET', $params);
|
|
|
+ $request->attributes->set('agent', $agent);
|
|
|
+ $this->app->instance('request', $request);
|
|
|
+ $response = (new ProfileController())->dashboardCharts($request, new AgentPeriodReportService(), new AgentReportService())->getData(true);
|
|
|
+ $this->assertSame(0, $response['code'], (string) $response['msg']);
|
|
|
+ return $response['data'];
|
|
|
+ }
|
|
|
}
|