|
@@ -7,6 +7,7 @@ use App\Http\Controllers\admin\ActivityReward as AdminActivityReward;
|
|
|
use App\Models\ActivityReward;
|
|
use App\Models\ActivityReward;
|
|
|
use App\Services\ActivityRewardService;
|
|
use App\Services\ActivityRewardService;
|
|
|
use App\Services\Sharing\ShareDefaults;
|
|
use App\Services\Sharing\ShareDefaults;
|
|
|
|
|
+use App\Support\ActivityCatalog;
|
|
|
use Illuminate\Config\Repository;
|
|
use Illuminate\Config\Repository;
|
|
|
use Illuminate\Database\Capsule\Manager;
|
|
use Illuminate\Database\Capsule\Manager;
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
@@ -125,10 +126,20 @@ class ActivityCatalogTest extends TestCase
|
|
|
$this->request('options');
|
|
$this->request('options');
|
|
|
$body = (new AdminActivityReward())->options()->getData(true);
|
|
$body = (new AdminActivityReward())->options()->getData(true);
|
|
|
$this->assertSame(HttpStatus::OK, $body['code'], $body['msg']);
|
|
$this->assertSame(HttpStatus::OK, $body['code'], $body['msg']);
|
|
|
|
|
+ $financialCategories = ['third:1' => '真人', 'third:2' => '电子', 'third:3' => '彩票',
|
|
|
|
|
+ 'third:4' => '体育', 'third:5' => '电竞', 'third:6' => '捕鱼', 'third:7' => '棋牌',
|
|
|
|
|
+ 'self:sport' => 'F1体育', 'self:lottery' => 'F1彩票'];
|
|
|
|
|
+ $this->assertSame($financialCategories, ShareDefaults::categories());
|
|
|
|
|
+ $this->assertCount(9, ShareDefaults::categories());
|
|
|
|
|
+ $this->assertArrayNotHasKey('other', ShareDefaults::categories());
|
|
|
|
|
+ $this->assertSame($financialCategories + ['other' => '其他'], ActivityCatalog::gameTypes());
|
|
|
$expectedGames = [];
|
|
$expectedGames = [];
|
|
|
- foreach (ShareDefaults::categories() as $value => $label) $expectedGames[] = compact('value', 'label');
|
|
|
|
|
- $this->assertCount(9, $expectedGames);
|
|
|
|
|
|
|
+ foreach ($financialCategories + ['other' => '其他'] as $value => $label) $expectedGames[] = compact('value', 'label');
|
|
|
|
|
+ $this->assertCount(10, $expectedGames);
|
|
|
$this->assertSame($expectedGames, $body['data']['game_types']);
|
|
$this->assertSame($expectedGames, $body['data']['game_types']);
|
|
|
|
|
+ $this->assertNotContains('', array_column($body['data']['game_types'], 'value'));
|
|
|
|
|
+ $this->assertNotContains('wallet', array_column($body['data']['game_types'], 'value'));
|
|
|
|
|
+ $this->assertNotContains('all', array_column($body['data']['game_types'], 'value'));
|
|
|
$this->assertSame([
|
|
$this->assertSame([
|
|
|
['value' => 2, 'label' => '普通活动'],
|
|
['value' => 2, 'label' => '普通活动'],
|
|
|
['value' => 3, 'label' => '即充即送'],
|
|
['value' => 3, 'label' => '即充即送'],
|
|
@@ -163,7 +174,7 @@ class ActivityCatalogTest extends TestCase
|
|
|
$this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
$this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
|
$row = ActivityReward::findOrFail($id)->toArray();
|
|
$row = ActivityReward::findOrFail($id)->toArray();
|
|
|
$this->assertSame('third:1', $row['game_category']);
|
|
$this->assertSame('third:1', $row['game_category']);
|
|
|
- $this->assertSame('第三方真人', $row['game_category_name']);
|
|
|
|
|
|
|
+ $this->assertSame('真人', $row['game_category_name']);
|
|
|
$this->assertSame('即充即送', $row['type_name']);
|
|
$this->assertSame('即充即送', $row['type_name']);
|
|
|
$this->assertSame(37, $row['sort']);
|
|
$this->assertSame(37, $row['sort']);
|
|
|
$this->assertSame(['PC'], $row['publish_platforms']);
|
|
$this->assertSame(['PC'], $row['publish_platforms']);
|
|
@@ -183,7 +194,7 @@ class ActivityCatalogTest extends TestCase
|
|
|
public function test_every_game_category_is_saved_and_named_for_normal_and_type_two_activities(): void
|
|
public function test_every_game_category_is_saved_and_named_for_normal_and_type_two_activities(): void
|
|
|
{
|
|
{
|
|
|
foreach ([2 => '普通活动', 3 => '即充即送'] as $type => $typeName) {
|
|
foreach ([2 => '普通活动', 3 => '即充即送'] as $type => $typeName) {
|
|
|
- foreach (ShareDefaults::categories() as $category => $label) {
|
|
|
|
|
|
|
+ foreach (ActivityCatalog::gameTypes() as $category => $label) {
|
|
|
$result = $this->save(['type' => $type, 'game_category' => $category]);
|
|
$result = $this->save(['type' => $type, 'game_category' => $category]);
|
|
|
$this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
$this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
|
$row = ActivityReward::query()->latest('id')->firstOrFail()->toArray();
|
|
$row = ActivityReward::query()->latest('id')->firstOrFail()->toArray();
|
|
@@ -193,14 +204,44 @@ class ActivityCatalogTest extends TestCase
|
|
|
$this->assertSame($label, $row['game_category_name']);
|
|
$this->assertSame($label, $row['game_category_name']);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- $this->assertSame(18, $this->listing()['total']);
|
|
|
|
|
|
|
+ $this->assertSame(20, $this->listing()['total']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_other_category_is_preserved_on_omitted_edit_and_can_be_cleared_for_type_two_and_three(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ foreach ([2, 3] as $type) {
|
|
|
|
|
+ $result = $this->save(['type' => $type, 'game_category' => 'other']);
|
|
|
|
|
+ $this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
|
|
|
+ $id = DB::table('activity_rewards')->latest('id')->value('id');
|
|
|
|
|
+ $this->assertSame('other', DB::table('activity_rewards')->where('id', $id)->value('game_category'));
|
|
|
|
|
+ $result = $this->save(['id' => $id, 'type' => $type, 'title' => '编辑其他分类活动']);
|
|
|
|
|
+ $this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
|
|
|
+ $page = $this->listing(['game_category' => 'other', 'type' => (string) $type]);
|
|
|
|
|
+ $this->assertSame(1, $page['total']);
|
|
|
|
|
+ $this->assertSame($id, $page['data'][0]['id']);
|
|
|
|
|
+ $this->assertSame('other', $page['data'][0]['game_category']);
|
|
|
|
|
+ $this->assertSame('其他', $page['data'][0]['game_category_name']);
|
|
|
|
|
+ $this->assertSame('其他', ActivityReward::findOrFail($id)->toArray()['game_category_name']);
|
|
|
|
|
+ foreach ([null, ''] as $clear) {
|
|
|
|
|
+ $this->assertSame(HttpStatus::OK, $this->save(['id' => $id, 'type' => $type, 'game_category' => 'other'])['code']);
|
|
|
|
|
+ $result = $this->save(['id' => $id, 'type' => $type, 'game_category' => $clear]);
|
|
|
|
|
+ $this->assertSame(HttpStatus::OK, $result['code'], $result['msg']);
|
|
|
|
|
+ $this->assertNull(DB::table('activity_rewards')->where('id', $id)->value('game_category'));
|
|
|
|
|
+ $row = collect($this->listing()['data'])->keyBy('id')->get($id);
|
|
|
|
|
+ $this->assertNull($row['game_category']);
|
|
|
|
|
+ $this->assertNull($row['game_category_name']);
|
|
|
|
|
+ $this->assertSame(0, $this->listing(['game_category' => 'other', 'type' => (string) $type])['total']);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->assertSame(2, DB::table('activity_rewards')->count());
|
|
|
|
|
+ $this->assertSame(0, DB::table('activity_reward_recipients')->count());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function test_invalid_categories_are_rejected_by_controller_and_service_even_for_type_two(): void
|
|
public function test_invalid_categories_are_rejected_by_controller_and_service_even_for_type_two(): void
|
|
|
{
|
|
{
|
|
|
$id = $this->rawActivity(['game_category' => 'third:1']);
|
|
$id = $this->rawActivity(['game_category' => 'third:1']);
|
|
|
$before = DB::table('activity_rewards')->get()->toJson();
|
|
$before = DB::table('activity_rewards')->get()->toJson();
|
|
|
- foreach (['unknown', 'third:8', '1', 1, ['third:1']] as $category) {
|
|
|
|
|
|
|
+ foreach (['unknown', 'third:8', 'wallet', 'all', '其他', '1', 1, ['third:1']] as $category) {
|
|
|
foreach ([2, 3] as $type) {
|
|
foreach ([2, 3] as $type) {
|
|
|
$result = $this->save(['id' => $id, 'type' => $type, 'title' => '不应保存', 'game_category' => $category]);
|
|
$result = $this->save(['id' => $id, 'type' => $type, 'title' => '不应保存', 'game_category' => $category]);
|
|
|
$this->assertSame(HttpStatus::CUSTOM_ERROR, $result['code']);
|
|
$this->assertSame(HttpStatus::CUSTOM_ERROR, $result['code']);
|
|
@@ -238,7 +279,7 @@ class ActivityCatalogTest extends TestCase
|
|
|
$this->assertSame(array_slice($matching, ($page - 1) * 2, 2), array_column($result['data'], 'id'));
|
|
$this->assertSame(array_slice($matching, ($page - 1) * 2, 2), array_column($result['data'], 'id'));
|
|
|
foreach ($result['data'] as $row) {
|
|
foreach ($result['data'] as $row) {
|
|
|
$this->assertSame('third:1', $row['game_category']);
|
|
$this->assertSame('third:1', $row['game_category']);
|
|
|
- $this->assertSame('第三方真人', $row['game_category_name']);
|
|
|
|
|
|
|
+ $this->assertSame('真人', $row['game_category_name']);
|
|
|
$this->assertSame('即充即送', $row['type_name']);
|
|
$this->assertSame('即充即送', $row['type_name']);
|
|
|
}
|
|
}
|
|
|
$seen = array_merge($seen, array_column($result['data'], 'id'));
|
|
$seen = array_merge($seen, array_column($result['data'], 'id'));
|
|
@@ -257,6 +298,43 @@ class ActivityCatalogTest extends TestCase
|
|
|
$this->assertSame($before, DB::table('activity_rewards')->orderBy('id')->get()->toJson());
|
|
$this->assertSame($before, DB::table('activity_rewards')->orderBy('id')->get()->toJson());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public function test_other_category_filter_combines_with_existing_filters_before_count_and_pagination(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $base = ['title' => '目标其他活动', 'type' => 3, 'status' => 0, 'lang' => 'zh', 'game_category' => 'other', 'publish_platforms' => ['H5']];
|
|
|
|
|
+ $matching = [];
|
|
|
|
|
+ for ($i = 1; $i <= 5; $i++) $matching[] = $this->rawActivity(['sort' => $i] + $base);
|
|
|
|
|
+ foreach ([['game_category' => 'third:1'], ['game_category' => null], ['publish_platforms' => ['PC']],
|
|
|
|
|
+ ['status' => 1], ['lang' => 'en'], ['title' => '不同标题'], ['type' => 4]] as $extra) {
|
|
|
|
|
+ $this->rawActivity($extra + ['sort' => 100] + $base);
|
|
|
|
|
+ }
|
|
|
|
|
+ $before = DB::table('activity_rewards')->orderBy('id')->get()->toJson();
|
|
|
|
|
+ $matching = array_reverse($matching);
|
|
|
|
|
+ $filters = ['title' => '目标', 'type' => '3', 'status' => '0', 'lang' => 'zh', 'platform' => 'h5', 'game_category' => 'other', 'limit' => 2];
|
|
|
|
|
+ $seen = [];
|
|
|
|
|
+ foreach ([1, 2, 3, 4] as $page) {
|
|
|
|
|
+ $result = $this->listing($filters + ['page' => $page]);
|
|
|
|
|
+ $this->assertSame(5, $result['total']);
|
|
|
|
|
+ $this->assertSame(array_slice($matching, ($page - 1) * 2, 2), array_column($result['data'], 'id'));
|
|
|
|
|
+ foreach ($result['data'] as $row) {
|
|
|
|
|
+ $this->assertSame('other', $row['game_category']);
|
|
|
|
|
+ $this->assertSame('其他', $row['game_category_name']);
|
|
|
|
|
+ }
|
|
|
|
|
+ $seen = array_merge($seen, array_column($result['data'], 'id'));
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->assertSame($matching, $seen);
|
|
|
|
|
+ $all = $this->listing();
|
|
|
|
|
+ $this->assertSame(12, $all['total']);
|
|
|
|
|
+ foreach ([null, ''] as $category) {
|
|
|
|
|
+ $page = $this->listing(['game_category' => $category]);
|
|
|
|
|
+ $this->assertSame($all['total'], $page['total']);
|
|
|
|
|
+ $this->assertSame(array_column($all['data'], 'id'), array_column($page['data'], 'id'));
|
|
|
|
|
+ }
|
|
|
|
|
+ $defaultRows = array_filter($all['data'], fn ($row) => $row['game_category'] === null);
|
|
|
|
|
+ $this->assertCount(1, $defaultRows);
|
|
|
|
|
+ $this->assertNull(array_values($defaultRows)[0]['game_category_name']);
|
|
|
|
|
+ $this->assertSame($before, DB::table('activity_rewards')->orderBy('id')->get()->toJson());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function test_legacy_type_one_remains_readable_and_editable_without_becoming_an_option(): void
|
|
public function test_legacy_type_one_remains_readable_and_editable_without_becoming_an_option(): void
|
|
|
{
|
|
{
|
|
|
$result = $this->save(['type' => 1]);
|
|
$result = $this->save(['type' => 1]);
|
|
@@ -269,7 +347,7 @@ class ActivityCatalogTest extends TestCase
|
|
|
$this->assertSame(1, (int) $row['type']);
|
|
$this->assertSame(1, (int) $row['type']);
|
|
|
$this->assertNull($row['type_name']);
|
|
$this->assertNull($row['type_name']);
|
|
|
$this->assertSame('self:lottery', $row['game_category']);
|
|
$this->assertSame('self:lottery', $row['game_category']);
|
|
|
- $this->assertSame('自有彩票', $row['game_category_name']);
|
|
|
|
|
|
|
+ $this->assertSame('F1彩票', $row['game_category_name']);
|
|
|
$this->assertSame('12.34', $row['budget_used']);
|
|
$this->assertSame('12.34', $row['budget_used']);
|
|
|
$this->assertSame(2, $row['rewarded_count']);
|
|
$this->assertSame(2, $row['rewarded_count']);
|
|
|
$legacy = $this->rawActivity(['type' => 99, 'game_category' => null]);
|
|
$legacy = $this->rawActivity(['type' => 99, 'game_category' => null]);
|