|
|
@@ -165,7 +165,7 @@ class ActivityCatalogTest extends TestCase
|
|
|
|
|
|
public function test_legacy_activity_dates_are_paired_nullable_and_permanent_rows_do_not_expire(): void
|
|
|
{
|
|
|
- foreach ([1, 2, 3, 4, 5, 6] as $type) {
|
|
|
+ foreach ([1, 2, 3, 4, 5] as $type) {
|
|
|
foreach ([[null, null], ['', '']] as [$start, $end]) {
|
|
|
$result = $this->save(['type' => $type, 'start_time' => $start, 'end_time' => $end]);
|
|
|
$this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
|
@@ -181,8 +181,8 @@ class ActivityCatalogTest extends TestCase
|
|
|
}
|
|
|
}
|
|
|
$this->assertSame(0, ActivityRewardService::expire());
|
|
|
- $this->assertSame(12, $this->listing(['status' => 1])['total']);
|
|
|
- $this->assertCount(12, \App\Support\ActivityPeriod::active(ActivityReward::query(), time())->get());
|
|
|
+ $this->assertSame(10, $this->listing(['status' => 1])['total']);
|
|
|
+ $this->assertCount(10, \App\Support\ActivityPeriod::active(ActivityReward::query(), time())->get());
|
|
|
$this->request('');
|
|
|
$this->assertCount(2, (new \App\Http\Controllers\api\ActivityReward())->index()->getData(true)['data']);
|
|
|
}
|
|
|
@@ -365,7 +365,6 @@ class ActivityCatalogTest extends TestCase
|
|
|
['value' => 3, 'label' => '即充即送'],
|
|
|
['value' => 4, 'label' => '老用户召集令'],
|
|
|
['value' => 5, 'label' => 'USDT使用教学'],
|
|
|
- ['value' => 6, 'label' => '余额宝'],
|
|
|
], $body['data']['activity_types']);
|
|
|
$this->assertNotContains(1, array_column($body['data']['activity_types'], 'value'));
|
|
|
$router = new Router(new Dispatcher($this->app), $this->app);
|
|
|
@@ -692,7 +691,7 @@ class ActivityCatalogTest extends TestCase
|
|
|
$this->assertNull(ActivityReward::findOrFail($legacy)->toArray()['type_name']);
|
|
|
$this->request('options');
|
|
|
$options = (new AdminActivityReward())->options()->getData(true)['data']['activity_types'];
|
|
|
- $this->assertSame([2, 3, 4, 5, 6], array_column($options, 'value'));
|
|
|
+ $this->assertSame([2, 3, 4, 5], array_column($options, 'value'));
|
|
|
}
|
|
|
|
|
|
public function test_lottery_merge_migration_preserves_activities_and_their_business_settings(): void
|
|
|
@@ -743,4 +742,81 @@ class ActivityCatalogTest extends TestCase
|
|
|
$this->assertSame($before, (array) DB::table('activity_rewards')->find($id));
|
|
|
$this->assertSame(2, DB::table('activity_rewards')->count());
|
|
|
}
|
|
|
+
|
|
|
+ private function yuebaoForm(array $overrides = []): array
|
|
|
+ {
|
|
|
+ return $overrides + [
|
|
|
+ 'title' => '余额宝', 'sub_title' => '余额宝', 'status' => 1, 'lang' => 'zh',
|
|
|
+ 'start_time' => '2026-04-01 00:00:00', 'end_time' => '2027-12-31 00:00:00',
|
|
|
+ 'detail_image' => '/app.png', 'pc_image' => '/pc.png', 'content' => '<p>说明</p>',
|
|
|
+ 'daily_interest_rate' => '0.246', 'number_of_consecutive_days_of_deposit' => 7,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function yuebao(string $action, array $params = [], string $method = 'GET'): array
|
|
|
+ {
|
|
|
+ $this->app->instance('request', Request::create('/admin/yuebao/config', $method, $params));
|
|
|
+ $controller = new \App\Http\Controllers\admin\YueBao();
|
|
|
+ return ($method === 'GET' ? $controller->config() : $controller->saveConfig())->getData(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_yuebao_is_hidden_from_activity_management(): void
|
|
|
+ {
|
|
|
+ $yuebao = $this->rawActivity(['type' => 6, 'title' => '余额宝']);
|
|
|
+ $this->rawActivity(['type' => 3]);
|
|
|
+ $this->assertNotContains($yuebao, array_column($this->listing()['data'], 'id'));
|
|
|
+ $this->assertSame(0, $this->listing(['type' => '6'])['total']);
|
|
|
+ $this->assertSame(HttpStatus::CUSTOM_ERROR, $this->save(['type' => 6])['code']);
|
|
|
+ $this->assertSame(HttpStatus::CUSTOM_ERROR, $this->save(['id' => $yuebao, 'type' => 3])['code']);
|
|
|
+ $this->assertSame(6, (int)DB::table('activity_rewards')->where('id', $yuebao)->value('type'));
|
|
|
+ $this->request('delete', ['id' => $yuebao], 'POST');
|
|
|
+ $this->assertSame(HttpStatus::CUSTOM_ERROR, (new AdminActivityReward())->destroy()->getData(true)['code']);
|
|
|
+ $this->assertTrue(DB::table('activity_rewards')->where('id', $yuebao)->exists());
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_yuebao_config_creates_then_updates_single_row(): void
|
|
|
+ {
|
|
|
+ $this->assertNull($this->yuebao('config')['data']);
|
|
|
+ $result = $this->yuebao('config', $this->yuebaoForm(['type' => 2, 'sort' => 50, 'game_category' => 'hot',
|
|
|
+ 'register_platforms' => ['H5'], 'publish_platforms' => ['APP']]), 'POST');
|
|
|
+ $this->assertSame(HttpStatus::OK, $result['code'], $result['msg'] ?? '');
|
|
|
+ $this->assertSame(1, DB::table('activity_rewards')->where('type', 6)->count());
|
|
|
+ $row = ActivityReward::where('type', 6)->firstOrFail();
|
|
|
+ $this->assertSame(0, $row->sort);
|
|
|
+ $this->assertNull($row->getRawOriginal('game_category'));
|
|
|
+ $this->assertSame(['daily_interest_rate' => '0.246', 'number_of_consecutive_days_of_deposit' => 7], json_decode($row->getRawOriginal('params'), true));
|
|
|
+
|
|
|
+ $data = $this->yuebao('config')['data'];
|
|
|
+ $this->assertSame('0.246', $data['daily_interest_rate']);
|
|
|
+ $this->assertSame(7, $data['number_of_consecutive_days_of_deposit']);
|
|
|
+ $this->assertSame(['APP'], $data['publish_platforms']);
|
|
|
+ $this->assertSame(['H5'], $data['register_platforms']);
|
|
|
+ foreach (['type', 'sort', 'game_category', 'click_type', 'link', 'params'] as $hidden) {
|
|
|
+ $this->assertArrayNotHasKey($hidden, $data);
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::table('activity_rewards')->where('id', $row->id)->update(['params' => json_encode(['daily_interest_rate' => 1, 'extra' => 'keep'])]);
|
|
|
+ $result = $this->yuebao('config', $this->yuebaoForm(['daily_interest_rate' => '0.5', 'number_of_consecutive_days_of_deposit' => 3, 'status' => 0]), 'POST');
|
|
|
+ $this->assertSame(HttpStatus::OK, $result['code'], $result['msg'] ?? '');
|
|
|
+ $this->assertSame(1, DB::table('activity_rewards')->where('type', 6)->count());
|
|
|
+ $fresh = $row->fresh();
|
|
|
+ $this->assertSame(0, (int)$fresh->status);
|
|
|
+ $this->assertSame(['daily_interest_rate' => '0.5', 'extra' => 'keep', 'number_of_consecutive_days_of_deposit' => 3], json_decode($fresh->getRawOriginal('params'), true));
|
|
|
+
|
|
|
+ foreach ([['daily_interest_rate' => ''], ['daily_interest_rate' => -1], ['number_of_consecutive_days_of_deposit' => 0], ['title' => ''], ['end_time' => null]] as $invalid) {
|
|
|
+ $this->assertSame(HttpStatus::CUSTOM_ERROR, $this->yuebao('config', $this->yuebaoForm($invalid), 'POST')['code']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function test_yuebao_config_edits_highest_priority_legacy_row_in_budget_mode(): void
|
|
|
+ {
|
|
|
+ $old = $this->rawActivity(['type' => 6, 'sort' => 0]);
|
|
|
+ $main = $this->rawActivity(['type' => 6, 'sort' => 5, 'budget' => '100.00']);
|
|
|
+ $this->assertSame($main, $this->yuebao('config')['data']['id']);
|
|
|
+ $result = $this->yuebao('config', $this->yuebaoForm(['budget' => '200']), 'POST');
|
|
|
+ $this->assertSame(HttpStatus::OK, $result['code'], $result['msg'] ?? '');
|
|
|
+ $this->assertSame('200.00', ActivityReward::findOrFail($main)->budget);
|
|
|
+ $this->assertSame(5, ActivityReward::findOrFail($main)->sort);
|
|
|
+ $this->assertSame('活动分类测试', ActivityReward::findOrFail($old)->title);
|
|
|
+ }
|
|
|
}
|