|
|
@@ -449,4 +449,104 @@ class ShareCommissionRecordingTest extends TestCase
|
|
|
$this->assertSame(0, $counts['linked_real_invitee_deposit_logs_all']);
|
|
|
$this->assertSame(0, $counts['with_promoter_wallet_deposit_logs_all']);
|
|
|
}
|
|
|
+
|
|
|
+ private function summaryHistory(): void
|
|
|
+ {
|
|
|
+ DB::table('users')->insert(['id' => 99, 'member_id' => '1003', 'account' => 'other', 'first_name' => '其他推广人', 'user_code' => 'OTHER']);
|
|
|
+ foreach ([
|
|
|
+ ['2020-01-01', 7, 'commission', '100.0000', '2.5000', '2.5000', 1],
|
|
|
+ ['2020-01-01', 7, 'fee_waiver', '40.0000', '2.5000', '1.0000', 1],
|
|
|
+ ['2026-10-01', 7, 'commission', '200.0000', '2.5000', '5.0000', 1],
|
|
|
+ ['2026-10-02', 7, 'commission', '1000.0000', '10.0000', '100.0000', 0],
|
|
|
+ ['2026-10-05', 99, 'commission', '1000.0000', '10.0000', '100.0000', 1],
|
|
|
+ ] as $i => [$day, $promoter, $type, $base, $rate, $amount, $status]) {
|
|
|
+ ShareCommissionRecord::create([
|
|
|
+ 'stat_date' => $day, 'promoter_user_id' => $promoter, 'type' => $type,
|
|
|
+ 'category' => 'recharge', 'base_amount' => $base, 'rate' => $rate, 'amount' => $amount,
|
|
|
+ 'source_type' => 'summary_test', 'source_id' => (string)$i, 'status' => $status,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function summaryResponse(array $params): array
|
|
|
+ {
|
|
|
+ $request = Request::create('/admin/shareEarning/summary', '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())->summary(new ShareEarningReportService());
|
|
|
+ });
|
|
|
+ })->getData(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function clearedSummaryDates(): array
|
|
|
+ {
|
|
|
+ return [
|
|
|
+ 'omitted' => [[]],
|
|
|
+ 'null' => [['start_date' => null, 'end_date' => null]],
|
|
|
+ 'empty strings from date picker' => [['start_date' => '', 'end_date' => '']],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /** @dataProvider clearedSummaryDates */
|
|
|
+ public function test_summary_without_dates_includes_all_history_and_keeps_pagination_and_global_totals(array $dates): void
|
|
|
+ {
|
|
|
+ $this->summaryHistory();
|
|
|
+ $before = DB::table('share_commission_records')->orderBy('id')->get()->toJson();
|
|
|
+ $result = $this->summaryResponse($dates + ['account' => '', 'page' => 1, 'limit' => 1]);
|
|
|
+ $this->assertSame(0, $result['code']);
|
|
|
+ $this->assertSame(3, $result['data']['total']);
|
|
|
+ $this->assertCount(1, $result['data']['data']);
|
|
|
+ $this->assertSame('2026-10-05', $result['data']['data'][0]['date']);
|
|
|
+ $this->assertSame('107.5000', $result['data']['summary']['total_commission']);
|
|
|
+ $this->assertSame('2.5000', $result['data']['summary']['highest_fee_waiver_rate']);
|
|
|
+ $last = $this->summaryResponse($dates + ['page' => 3, 'limit' => 1]);
|
|
|
+ $this->assertSame('2020-01-01', $last['data']['data'][0]['date']);
|
|
|
+ $this->assertSame('40.0000', $last['data']['data'][0]['sales_amount']);
|
|
|
+ $this->assertSame($before, DB::table('share_commission_records')->orderBy('id')->get()->toJson());
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function selectedSummaryDates(): array
|
|
|
+ {
|
|
|
+ return [
|
|
|
+ ['2020-01-01', '2020-01-01', '2.5000', '2.5000'],
|
|
|
+ ['2026-10-01', '2026-10-02', '5.0000', '0.0000'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ /** @dataProvider selectedSummaryDates */
|
|
|
+ public function test_summary_explicit_dates_apply_to_list_count_and_totals(string $start, string $end, string $commission, string $feeRate): void
|
|
|
+ {
|
|
|
+ $this->summaryHistory();
|
|
|
+ $result = $this->summaryResponse(['start_date' => $start, 'end_date' => $end, 'page' => 1, 'limit' => 10]);
|
|
|
+ $this->assertSame(0, $result['code']);
|
|
|
+ $this->assertSame(1, $result['data']['total']);
|
|
|
+ $this->assertCount(1, $result['data']['data']);
|
|
|
+ $this->assertSame($start, $result['data']['data'][0]['date']);
|
|
|
+ $this->assertSame($commission, $result['data']['summary']['total_commission']);
|
|
|
+ $this->assertSame($feeRate, $result['data']['summary']['highest_fee_waiver_rate']);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_summary_default_all_history_still_applies_account_and_status_filters(): void
|
|
|
+ {
|
|
|
+ $this->summaryHistory();
|
|
|
+ $result = $this->summaryResponse(['account' => 'prom', 'page' => 1, 'limit' => 10]);
|
|
|
+ $this->assertSame(0, $result['code']);
|
|
|
+ $this->assertSame(2, $result['data']['total']);
|
|
|
+ $this->assertSame('7.5000', $result['data']['summary']['total_commission']);
|
|
|
+ $this->assertSame('2.5000', $result['data']['summary']['highest_fee_waiver_rate']);
|
|
|
+ $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
|
|
|
+ {
|
|
|
+ $this->summaryHistory();
|
|
|
+ $invalid = $this->summaryResponse(['start_date' => '2020-01-01', 'end_date' => '2026-10-01']);
|
|
|
+ $this->assertSame(-3, $invalid['code']);
|
|
|
+ $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']);
|
|
|
+ }
|
|
|
}
|