|
@@ -55,7 +55,7 @@ class PromotionActivitiesTest extends TestCase
|
|
|
'reporting_activity' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,user_id INTEGER,session_hash TEXT,observed_at TEXT',
|
|
'reporting_activity' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,user_id INTEGER,session_hash TEXT,observed_at TEXT',
|
|
|
'menus' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,parent_id INTEGER,title TEXT,icon TEXT,uri TEXT,permission_name TEXT,sort INTEGER,status INTEGER,type INTEGER,created_at TEXT,updated_at TEXT',
|
|
'menus' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,parent_id INTEGER,title TEXT,icon TEXT,uri TEXT,permission_name TEXT,sort INTEGER,status INTEGER,type INTEGER,created_at TEXT,updated_at TEXT',
|
|
|
] as $table => $columns) DB::statement('CREATE TABLE bot_' . $table . ' (' . $columns . ')');
|
|
] as $table => $columns) DB::statement('CREATE TABLE bot_' . $table . ' (' . $columns . ')');
|
|
|
- foreach (['2026_10_13_120000_add_activity_eligibility_fields.php', '2026_10_14_120000_add_activity_reward_quotas.php', '2026_10_25_120000_add_game_category_to_activity_rewards.php', '2026_10_26_160000_create_promotion_activities.php'] as $migration) (require dirname(__DIR__, 2) . '/database/migrations/' . $migration)->up();
|
|
|
|
|
|
|
+ foreach (['2026_10_13_120000_add_activity_eligibility_fields.php', '2026_10_14_120000_add_activity_reward_quotas.php', '2026_10_25_120000_add_game_category_to_activity_rewards.php', '2026_10_26_160000_create_promotion_activities.php', '2026_10_27_130000_initialize_fixed_promotion_activities.php'] as $migration) (require dirname(__DIR__, 2) . '/database/migrations/' . $migration)->up();
|
|
|
$this->member(1); $this->member(2, 1);
|
|
$this->member(1); $this->member(2, 1);
|
|
|
DB::table('share_policies')->insert(['id' => 1, 'effective_date' => '2026-10-01', 'valid_member_min_deposit' => '200', 'valid_member_min_effective_bet' => '300']);
|
|
DB::table('share_policies')->insert(['id' => 1, 'effective_date' => '2026-10-01', 'valid_member_min_deposit' => '200', 'valid_member_min_effective_bet' => '300']);
|
|
|
$this->service = new PromotionService();
|
|
$this->service = new PromotionService();
|
|
@@ -70,9 +70,10 @@ class PromotionActivitiesTest extends TestCase
|
|
|
}
|
|
}
|
|
|
private function activity(int $type = 9, array $params = [], int $status = 1): int
|
|
private function activity(int $type = 9, array $params = [], int $status = 1): int
|
|
|
{
|
|
{
|
|
|
- (new PromotionAdminService())->save(['title' => '测试活动', 'sub_title' => '规则', 'type' => $type, 'status' => $status,
|
|
|
|
|
- 'start_time' => '2026-10-01 00:00:00', 'end_time' => '2026-12-31 23:59:59', 'lang' => 'zh', 'params' => $params]);
|
|
|
|
|
- return (int)DB::table('promotion_activities')->max('id');
|
|
|
|
|
|
|
+ $input = ['title' => '测试活动', 'sub_title' => '规则', 'type' => $type, 'status' => $status,
|
|
|
|
|
+ 'start_time' => '2026-10-01 00:00:00', 'end_time' => '2026-12-31 23:59:59', 'lang' => 'zh', 'params' => $params];
|
|
|
|
|
+ if (in_array($type, [7, 9], true)) $input['id'] = (int) DB::table('promotion_activities')->where('type', $type)->value('id');
|
|
|
|
|
+ return (int) (new PromotionAdminService())->save($input)['id'];
|
|
|
}
|
|
}
|
|
|
private function deposit(int $id, string $amount, ?string $time = null, string $type = '充值'): BalanceLog
|
|
private function deposit(int $id, string $amount, ?string $time = null, string $type = '充值'): BalanceLog
|
|
|
{
|
|
{
|
|
@@ -269,6 +270,61 @@ class PromotionActivitiesTest extends TestCase
|
|
|
$this->assertTrue(DB::connection()->getSchemaBuilder()->hasTable('promotion_activities'));
|
|
$this->assertTrue(DB::connection()->getSchemaBuilder()->hasTable('promotion_activities'));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function test_fixed_activities_are_initialized_disabled_without_publishing_or_creating_menus(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->assertSame(2, DB::table('promotion_activities')->count());
|
|
|
|
|
+ foreach ([7, 9] as $type) {
|
|
|
|
|
+ $row = DB::table('promotion_activities')->where('type', $type)->first();
|
|
|
|
|
+ $this->assertNotNull($row); $this->assertSame(0, (int) $row->status);
|
|
|
|
|
+ $this->assertNull(DB::table('promotion_campaigns')->where('activity_id', $row->id)->value('first_published_at'));
|
|
|
|
|
+ }
|
|
|
|
|
+ $options = (new PromotionAdminService())->options();
|
|
|
|
|
+ $this->assertSame([7, 8, 9], array_column($options['types'], 'value'));
|
|
|
|
|
+ $this->assertSame([8], array_column($options['create_types'], 'value'));
|
|
|
|
|
+ $this->assertSame(0, DB::table('menus')->count());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_fixed_types_cannot_be_created_even_when_no_configuration_exists(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $admin = new PromotionAdminService();
|
|
|
|
|
+ foreach ([7, 9] as $type) {
|
|
|
|
|
+ $input = ['title' => '不能新建', 'type' => $type, 'status' => 0,
|
|
|
|
|
+ 'start_time' => '2026-10-01 00:00:00', 'end_time' => '2026-12-31 23:59:59'];
|
|
|
|
|
+ $this->invalid(fn () => $admin->save($input), '不支持新增');
|
|
|
|
|
+ $this->assertSame(1, DB::table('promotion_activities')->where('type', $type)->count());
|
|
|
|
|
+ $id = DB::table('promotion_activities')->where('type', $type)->value('id');
|
|
|
|
|
+ DB::table('promotion_campaigns')->where('activity_id', $id)->delete();
|
|
|
|
|
+ DB::table('promotion_activities')->where('id', $id)->delete();
|
|
|
|
|
+ $this->invalid(fn () => $admin->save($input), '不支持新增');
|
|
|
|
|
+ $this->assertSame(0, DB::table('promotion_activities')->where('type', $type)->count());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_first_deposit_still_allows_multiple_new_configurations_and_type_change_is_rejected(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $first = $this->activity(8); $second = $this->activity(8);
|
|
|
|
|
+ $this->assertNotSame($first, $second);
|
|
|
|
|
+ $this->assertSame(2, DB::table('promotion_activities')->where('type', 8)->count());
|
|
|
|
|
+ $this->invalid(fn () => (new PromotionAdminService())->save(['id' => $first, 'title' => '不能换类型', 'type' => 9, 'status' => 0,
|
|
|
|
|
+ 'start_time' => '2026-10-01 00:00:00', 'end_time' => '2026-12-31 23:59:59']), '不能变更活动类型');
|
|
|
|
|
+ $this->assertSame(8, (int) DB::table('promotion_activities')->where('id', $first)->value('type'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_fixed_initialization_and_relisting_do_not_replace_existing_activity_or_reset_its_history(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $id = $this->activity(9, ['completion_probability' => 0]);
|
|
|
|
|
+ DB::table('promotion_activities')->where('id', $id)->update(['rewarded_count' => 3, 'budget_used' => '1998']);
|
|
|
|
|
+ $before = (array) DB::table('promotion_activities')->where('id', $id)->first();
|
|
|
|
|
+ $published = DB::table('promotion_campaigns')->where('activity_id', $id)->value('first_published_at');
|
|
|
|
|
+ $migration = require dirname(__DIR__, 2) . '/database/migrations/2026_10_27_130000_initialize_fixed_promotion_activities.php';
|
|
|
|
|
+ $this->travel('2026-10-27 12:00:00'); $migration->up(); $migration->down();
|
|
|
|
|
+ $this->assertSame($before, (array) DB::table('promotion_activities')->where('id', $id)->first());
|
|
|
|
|
+ $this->assertSame(2, DB::table('promotion_activities')->count());
|
|
|
|
|
+ $admin = new PromotionAdminService(); $admin->status($id, 0); $admin->status($id, 1);
|
|
|
|
|
+ $this->assertSame($published, DB::table('promotion_campaigns')->where('activity_id', $id)->value('first_published_at'));
|
|
|
|
|
+ $this->assertSame(3, (int) DB::table('promotion_activities')->where('id', $id)->value('rewarded_count'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function test_admin_partial_rule_edit_preserves_other_settings_and_zero_probability(): void
|
|
public function test_admin_partial_rule_edit_preserves_other_settings_and_zero_probability(): void
|
|
|
{
|
|
{
|
|
|
$id = $this->activity(9, ['turnover_ratio' => 3, 'deposit_amount' => 5000]);
|
|
$id = $this->activity(9, ['turnover_ratio' => 3, 'deposit_amount' => 5000]);
|