|
|
@@ -550,6 +550,7 @@ class ShareCommissionRecordingTest extends TestCase
|
|
|
{
|
|
|
DB::connection()->getSchemaBuilder()->create('share_settings', function (Blueprint $t) {
|
|
|
$t->id(); $t->decimal('valid_member_min_deposit', 20, 2);
|
|
|
+ $t->decimal('tier_one_rate', 8, 4)->default(4);
|
|
|
});
|
|
|
DB::table('share_settings')->insert(['valid_member_min_deposit' => 20]);
|
|
|
DB::connection()->getSchemaBuilder()->create('user_login', function (Blueprint $t) {
|
|
|
@@ -659,4 +660,112 @@ class ShareCommissionRecordingTest extends TestCase
|
|
|
$this->assertSame(-3, $invalid['code']);
|
|
|
$this->assertStringContainsString('366', $invalid['msg']);
|
|
|
}
|
|
|
+
|
|
|
+ private function promotersResponse(array $params): array
|
|
|
+ {
|
|
|
+ $request = Request::create('/admin/shareEarning/members/promoters', '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())->promoterDetails(new ShareEarningReportService());
|
|
|
+ });
|
|
|
+ })->getData(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_promoter_details_preserves_historical_codes_when_no_current_promoter_matches(): void
|
|
|
+ {
|
|
|
+ $this->memberHistory();
|
|
|
+ DB::table('users')->whereIn('id', [42, 43])->update(['created_at' => '2026-05-08 12:00:00']);
|
|
|
+ DB::table('users')->where('id', 7)->update(['user_code' => 'CHANGED']);
|
|
|
+ $before = DB::table('users')->orderBy('id')->get()->toJson();
|
|
|
+ $days = $this->membersResponse(['start_date' => '2026-05-08', 'end_date' => '2026-05-08']);
|
|
|
+ $result = $this->promotersResponse(['date' => '2026-05-08', 'page' => 1, 'limit' => 10, 'member_id' => '', 'account' => '']);
|
|
|
+ $this->assertSame(0, $result['code']);
|
|
|
+ $this->assertSame($days['data']['data'][0]['promoter_count'], $result['data']['total']);
|
|
|
+ $this->assertCount(2, $result['data']['data']);
|
|
|
+ $rows = array_column($result['data']['data'], null, 'promoter_code');
|
|
|
+ $this->assertSame('100.0000', $rows['PROMO']['deposit_total']);
|
|
|
+ $this->assertSame('30.0000', $rows['OTHER']['deposit_total']);
|
|
|
+ foreach ($rows as $row) {
|
|
|
+ $this->assertSame('2026-05-08', $row['date']);
|
|
|
+ $this->assertSame('missing', $row['promoter_status']);
|
|
|
+ $this->assertSame('', $row['member_id']);
|
|
|
+ $this->assertSame('', $row['account']);
|
|
|
+ $this->assertSame('', $row['nickname']);
|
|
|
+ $this->assertSame(1, $row['registered_count']);
|
|
|
+ $this->assertSame('0.0000', $row['commission']);
|
|
|
+ }
|
|
|
+ $this->assertSame($before, DB::table('users')->orderBy('id')->get()->toJson());
|
|
|
+ $this->assertSame(0, ShareCommissionRecord::count());
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_promoter_details_keeps_matched_identity_commission_and_missing_code_in_same_report(): void
|
|
|
+ {
|
|
|
+ $this->memberHistory();
|
|
|
+ foreach ([['2020-01-01', 1, '2.5000'], ['2020-01-01', 0, '100.0000'], ['2021-06-15', 1, '50.0000']] as $i => [$day, $status, $amount]) {
|
|
|
+ ShareCommissionRecord::create([
|
|
|
+ 'stat_date' => $day, 'promoter_user_id' => 7, 'type' => 'commission', 'category' => 'recharge',
|
|
|
+ 'base_amount' => '100.0000', 'rate' => '2.5000', 'amount' => $amount,
|
|
|
+ 'source_type' => 'promoter_test', 'source_id' => (string)$i, 'status' => $status,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ $result = $this->promotersResponse(['date' => '2020-01-01']);
|
|
|
+ $this->assertSame(0, $result['code']);
|
|
|
+ $this->assertSame(2, $result['data']['total']);
|
|
|
+ $rows = array_column($result['data']['data'], null, 'promoter_code');
|
|
|
+ $this->assertSame('matched', $rows['PROMO']['promoter_status']);
|
|
|
+ $this->assertSame('1001', $rows['PROMO']['member_id']);
|
|
|
+ $this->assertSame('promoter', $rows['PROMO']['account']);
|
|
|
+ $this->assertSame('推广人', $rows['PROMO']['nickname']);
|
|
|
+ $this->assertSame('100.0000', $rows['PROMO']['deposit_total']);
|
|
|
+ $this->assertSame(1, $rows['PROMO']['registered_count']);
|
|
|
+ $this->assertSame('2.5000', $rows['PROMO']['commission']);
|
|
|
+ $this->assertSame('4.0000', $rows['PROMO']['current_fee_rate']);
|
|
|
+ $this->assertSame('missing', $rows['OTHER']['promoter_status']);
|
|
|
+ $this->assertSame('30.0000', $rows['OTHER']['deposit_total']);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_promoter_details_pagination_filters_and_empty_dates_still_apply(): void
|
|
|
+ {
|
|
|
+ $this->memberHistory();
|
|
|
+ $first = $this->promotersResponse(['date' => '2020-01-01', 'page' => 1, 'limit' => 1]);
|
|
|
+ $this->assertSame(0, $first['code']);
|
|
|
+ $this->assertSame(2, $first['data']['total']);
|
|
|
+ $this->assertCount(1, $first['data']['data']);
|
|
|
+ $this->assertSame('PROMO', $first['data']['data'][0]['promoter_code']);
|
|
|
+ $last = $this->promotersResponse(['date' => '2020-01-01', 'page' => 2, 'limit' => 1]);
|
|
|
+ $this->assertSame(2, $last['data']['total']);
|
|
|
+ $this->assertSame('OTHER', $last['data']['data'][0]['promoter_code']);
|
|
|
+ foreach ([['member_id' => '1001'], ['account' => 'prom']] as $filter) {
|
|
|
+ $result = $this->promotersResponse($filter + ['date' => '2020-01-01']);
|
|
|
+ $this->assertSame(0, $result['code']);
|
|
|
+ $this->assertSame(1, $result['data']['total']);
|
|
|
+ $this->assertSame('PROMO', $result['data']['data'][0]['promoter_code']);
|
|
|
+ }
|
|
|
+ foreach ([['date' => '2019-01-01'], ['date' => '2020-01-01', 'page' => 3, 'limit' => 1],
|
|
|
+ ['date' => '2020-01-01', 'member_id' => '1002'], ['date' => '2020-01-01', 'account' => 'OTHER']] as $params) {
|
|
|
+ $result = $this->promotersResponse($params);
|
|
|
+ $this->assertSame(0, $result['code']);
|
|
|
+ $this->assertSame([], $result['data']['data']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_promoter_details_does_not_assign_an_ambiguous_code_to_one_of_several_users(): void
|
|
|
+ {
|
|
|
+ $this->memberHistory();
|
|
|
+ DB::table('users')->insert([
|
|
|
+ 'id' => 99, 'member_id' => '1009', 'account' => 'duplicate',
|
|
|
+ 'first_name' => '重复邀请码', 'user_code' => 'PROMO',
|
|
|
+ ]);
|
|
|
+ $result = $this->promotersResponse(['date' => '2020-01-01']);
|
|
|
+ $this->assertSame(0, $result['code']);
|
|
|
+ $this->assertSame(2, $result['data']['total']);
|
|
|
+ $rows = array_column($result['data']['data'], null, 'promoter_code');
|
|
|
+ $this->assertSame('ambiguous', $rows['PROMO']['promoter_status']);
|
|
|
+ $this->assertSame('', $rows['PROMO']['member_id']);
|
|
|
+ $this->assertSame('', $rows['PROMO']['account']);
|
|
|
+ $this->assertSame('100.0000', $rows['PROMO']['deposit_total']);
|
|
|
+ $this->assertSame(1, $rows['PROMO']['registered_count']);
|
|
|
+ $this->assertSame('0.0000', $rows['PROMO']['commission']);
|
|
|
+ }
|
|
|
}
|