|
@@ -479,7 +479,7 @@ class ShareCommissionRecordingTest extends TestCase
|
|
|
})->getData(true);
|
|
})->getData(true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static function clearedSummaryDates(): array
|
|
|
|
|
|
|
+ public static function clearedReportDates(): array
|
|
|
{
|
|
{
|
|
|
return [
|
|
return [
|
|
|
'omitted' => [[]],
|
|
'omitted' => [[]],
|
|
@@ -488,7 +488,7 @@ class ShareCommissionRecordingTest extends TestCase
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** @dataProvider clearedSummaryDates */
|
|
|
|
|
|
|
+ /** @dataProvider clearedReportDates */
|
|
|
public function test_summary_without_dates_includes_all_history_and_keeps_pagination_and_global_totals(array $dates): void
|
|
public function test_summary_without_dates_includes_all_history_and_keeps_pagination_and_global_totals(array $dates): void
|
|
|
{
|
|
{
|
|
|
$this->summaryHistory();
|
|
$this->summaryHistory();
|
|
@@ -538,15 +538,125 @@ class ShareCommissionRecordingTest extends TestCase
|
|
|
$this->assertSame(['promoter', 'promoter'], array_column($result['data']['data'], 'promoter_account'));
|
|
$this->assertSame(['promoter', 'promoter'], array_column($result['data']['data'], 'promoter_account'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public function test_summary_explicit_range_limits_and_other_report_defaults_remain_unchanged(): void
|
|
|
|
|
|
|
+ public function test_summary_explicit_range_limit_remains_enforced(): void
|
|
|
{
|
|
{
|
|
|
$this->summaryHistory();
|
|
$this->summaryHistory();
|
|
|
$invalid = $this->summaryResponse(['start_date' => '2020-01-01', 'end_date' => '2026-10-01']);
|
|
$invalid = $this->summaryResponse(['start_date' => '2020-01-01', 'end_date' => '2026-10-01']);
|
|
|
$this->assertSame(-3, $invalid['code']);
|
|
$this->assertSame(-3, $invalid['code']);
|
|
|
$this->assertStringContainsString('366', $invalid['msg']);
|
|
$this->assertStringContainsString('366', $invalid['msg']);
|
|
|
- DB::table('users')->update(['created_at' => '2020-01-01 00:00:00']);
|
|
|
|
|
- $other = (new ShareEarningReportService())->memberDays([]);
|
|
|
|
|
- $this->assertSame(0, $other['total']);
|
|
|
|
|
- $this->assertSame([], $other['data']);
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function memberHistory(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ DB::connection()->getSchemaBuilder()->create('share_settings', function (Blueprint $t) {
|
|
|
|
|
+ $t->id(); $t->decimal('valid_member_min_deposit', 20, 2);
|
|
|
|
|
+ });
|
|
|
|
|
+ DB::table('share_settings')->insert(['valid_member_min_deposit' => 20]);
|
|
|
|
|
+ DB::connection()->getSchemaBuilder()->create('user_login', function (Blueprint $t) {
|
|
|
|
|
+ $t->id(); $t->string('user_id'); $t->integer('status'); $t->string('platform');
|
|
|
|
|
+ });
|
|
|
|
|
+ DB::table('users')->where('id', 42)->update(['created_at' => '2020-01-01 00:00:00']);
|
|
|
|
|
+ foreach ([
|
|
|
|
|
+ [43, '1003', 'OTHER', '2020-01-01 23:59:59'],
|
|
|
|
|
+ [44, '1004', 'PROMO', '2021-06-15 12:00:00'],
|
|
|
|
|
+ [45, '1005', 'PROMO', date('Y-m-d') . ' 12:00:00'],
|
|
|
|
|
+ [46, '1006', null, '2019-01-01 12:00:00'],
|
|
|
|
|
+ [47, '1007', '', '2018-01-01 12:00:00'],
|
|
|
|
|
+ ] as [$id, $memberId, $code, $createdAt]) {
|
|
|
|
|
+ DB::table('users')->insert([
|
|
|
|
|
+ 'id' => $id, 'member_id' => $memberId, 'account' => 'member' . $memberId,
|
|
|
|
|
+ 'first_name' => '会员', 'user_code' => 'CODE' . $memberId,
|
|
|
|
|
+ 'agent_user_code' => $code, 'created_at' => $createdAt,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ foreach ([
|
|
|
|
|
+ ['1002', '充值', 100], ['1002', '提现', -10],
|
|
|
|
|
+ ['1002', '投注', -20], ['1002', '优惠活动', 5], ['1003', '三方充值', 30],
|
|
|
|
|
+ ] as [$memberId, $type, $amount]) {
|
|
|
|
|
+ DB::table('balance_logs')->insert([
|
|
|
|
|
+ 'member_id' => $memberId, 'change_type' => $type, 'amount' => $amount,
|
|
|
|
|
+ 'before_balance' => 100, 'after_balance' => 100 + $amount,
|
|
|
|
|
+ 'created_at' => date('Y-m-d H:i:s'),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ DB::table('user_login')->insert([
|
|
|
|
|
+ ['user_id' => '1002', 'status' => 0, 'platform' => 'Android'],
|
|
|
|
|
+ ['user_id' => '1002', 'status' => 1, 'platform' => 'H5'],
|
|
|
|
|
+ ['user_id' => '1002', 'status' => 1, 'platform' => 'Android'],
|
|
|
|
|
+ ['user_id' => '1003', 'status' => 1, 'platform' => 'Android'],
|
|
|
|
|
+ ['user_id' => '1004', 'status' => 1, 'platform' => 'iOS'],
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function membersResponse(array $params): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $request = Request::create('/admin/shareEarning/members', 'GET', $params);
|
|
|
|
|
+ return (new \App\Http\Middleware\TrimStrings())->handle($request, function ($request) {
|
|
|
|
|
+ return (new \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull())->handle($request, function ($request) {
|
|
|
|
|
+ $this->app->instance('request', $request);
|
|
|
|
|
+ return (new ShareEarning())->memberList(new ShareEarningReportService());
|
|
|
|
|
+ });
|
|
|
|
|
+ })->getData(true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** @dataProvider clearedReportDates */
|
|
|
|
|
+ public function test_members_without_dates_includes_historical_registration_days_without_backfill(array $dates): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->memberHistory();
|
|
|
|
|
+ $users = DB::table('users')->orderBy('id')->get()->toJson();
|
|
|
|
|
+ $logs = DB::table('balance_logs')->orderBy('id')->get()->toJson();
|
|
|
|
|
+ $result = $this->membersResponse($dates + ['page' => 1, 'limit' => 1]);
|
|
|
|
|
+ $this->assertSame(0, $result['code']);
|
|
|
|
|
+ $this->assertSame(3, $result['data']['total']);
|
|
|
|
|
+ $this->assertCount(1, $result['data']['data']);
|
|
|
|
|
+ $this->assertSame(date('Y-m-d'), $result['data']['data'][0]['date']);
|
|
|
|
|
+ $last = $this->membersResponse($dates + ['page' => 3, 'limit' => 1]);
|
|
|
|
|
+ $this->assertSame(3, $last['data']['total']);
|
|
|
|
|
+ $row = $last['data']['data'][0];
|
|
|
|
|
+ $this->assertSame('2020-01-01', $row['date']);
|
|
|
|
|
+ $this->assertSame(2, $row['registered_members']);
|
|
|
|
|
+ $this->assertSame(2, $row['promoter_count']);
|
|
|
|
|
+ $this->assertSame(1, $row['h5_registered']);
|
|
|
|
|
+ $this->assertSame(1, $row['android_registered']);
|
|
|
|
|
+ $this->assertSame(0, $row['ios_registered']);
|
|
|
|
|
+ $this->assertSame('130.0000', $row['deposit_total']);
|
|
|
|
|
+ $this->assertSame('20.0000', $row['consume_total']);
|
|
|
|
|
+ $this->assertSame('115.0000', $row['company_profit']);
|
|
|
|
|
+ $this->assertSame($users, DB::table('users')->orderBy('id')->get()->toJson());
|
|
|
|
|
+ $this->assertSame($logs, DB::table('balance_logs')->orderBy('id')->get()->toJson());
|
|
|
|
|
+ $this->assertSame(0, ShareCommissionRecord::count());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_members_explicit_dates_filter_registration_days_but_keep_lifetime_money_metrics(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->memberHistory();
|
|
|
|
|
+ $result = $this->membersResponse(['start_date' => '2020-01-01', 'end_date' => '2020-01-01']);
|
|
|
|
|
+ $this->assertSame(0, $result['code']);
|
|
|
|
|
+ $this->assertSame(1, $result['data']['total']);
|
|
|
|
|
+ $this->assertCount(1, $result['data']['data']);
|
|
|
|
|
+ $row = $result['data']['data'][0];
|
|
|
|
|
+ $this->assertSame('2020-01-01', $row['date']);
|
|
|
|
|
+ $this->assertSame(2, $row['registered_members']);
|
|
|
|
|
+ $this->assertSame('130.0000', $row['deposit_total']);
|
|
|
|
|
+ $other = $this->membersResponse(['start_date' => '2021-06-15', 'end_date' => '2021-06-15']);
|
|
|
|
|
+ $this->assertSame(0, $other['code']);
|
|
|
|
|
+ $this->assertSame(1, $other['data']['total']);
|
|
|
|
|
+ $this->assertSame(1, $other['data']['data'][0]['ios_registered']);
|
|
|
|
|
+ $this->assertSame('0.0000', $other['data']['data'][0]['deposit_total']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_members_empty_days_and_explicit_range_limit(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->memberHistory();
|
|
|
|
|
+ $empty = $this->membersResponse(['start_date' => '2019-01-01', 'end_date' => '2019-01-01']);
|
|
|
|
|
+ $this->assertSame(0, $empty['code']);
|
|
|
|
|
+ $this->assertSame(0, $empty['data']['total']);
|
|
|
|
|
+ $this->assertSame([], $empty['data']['data']);
|
|
|
|
|
+ $pastLastPage = $this->membersResponse(['page' => 4, 'limit' => 1]);
|
|
|
|
|
+ $this->assertSame(3, $pastLastPage['data']['total']);
|
|
|
|
|
+ $this->assertSame([], $pastLastPage['data']['data']);
|
|
|
|
|
+ $invalid = $this->membersResponse(['start_date' => '2020-01-01', 'end_date' => '2026-10-01']);
|
|
|
|
|
+ $this->assertSame(-3, $invalid['code']);
|
|
|
|
|
+ $this->assertStringContainsString('366', $invalid['msg']);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|