|
@@ -39,7 +39,10 @@ class Egame extends Controller
|
|
|
'plat_type' => ['nullable', 'string', 'max:32'],
|
|
'plat_type' => ['nullable', 'string', 'max:32'],
|
|
|
'game_type' => ['nullable', 'integer', 'min:0', 'max:255'],
|
|
'game_type' => ['nullable', 'integer', 'min:0', 'max:255'],
|
|
|
'game_code' => ['nullable', 'string', 'max:128'],
|
|
'game_code' => ['nullable', 'string', 'max:128'],
|
|
|
|
|
+ 'name' => ['nullable', 'string', 'max:128'],
|
|
|
'keyword' => ['nullable', 'string', 'max:128'],
|
|
'keyword' => ['nullable', 'string', 'max:128'],
|
|
|
|
|
+ 'ingress' => ['nullable', Rule::in(EgameItem::ingressValues())],
|
|
|
|
|
+ 'network' => ['nullable', Rule::in(EgameItem::networkValues())],
|
|
|
'status' => ['nullable', 'integer', Rule::in([
|
|
'status' => ['nullable', 'integer', Rule::in([
|
|
|
EgameItem::STATUS_DISABLED,
|
|
EgameItem::STATUS_DISABLED,
|
|
|
EgameItem::STATUS_ENABLED,
|
|
EgameItem::STATUS_ENABLED,
|
|
@@ -49,13 +52,18 @@ class Egame extends Controller
|
|
|
]);
|
|
]);
|
|
|
|
|
|
|
|
$query = EgameItem::query();
|
|
$query = EgameItem::query();
|
|
|
- foreach (['item_type', 'plat_type', 'game_type', 'game_code', 'status'] as $field) {
|
|
|
|
|
|
|
+ foreach (['item_type', 'plat_type', 'game_type', 'game_code', 'status', 'ingress', 'network'] as $field) {
|
|
|
$value = request()->input($field);
|
|
$value = request()->input($field);
|
|
|
if ($value !== null && $value !== '') {
|
|
if ($value !== null && $value !== '') {
|
|
|
$query->where($field, $value);
|
|
$query->where($field, $value);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $name = trim((string) request()->input('name', ''));
|
|
|
|
|
+ if ($name !== '') {
|
|
|
|
|
+ $query->where('name', 'like', "%{$name}%");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$platformScope = (string) request()->input('platform_scope', '');
|
|
$platformScope = (string) request()->input('platform_scope', '');
|
|
|
if ($platformScope !== '') {
|
|
if ($platformScope !== '') {
|
|
|
$itemType = (string) request()->input('item_type', '');
|
|
$itemType = (string) request()->input('item_type', '');
|
|
@@ -83,11 +91,12 @@ class Egame extends Controller
|
|
|
$page = (int) request()->input('page', 1);
|
|
$page = (int) request()->input('page', 1);
|
|
|
$total = (clone $query)->count();
|
|
$total = (clone $query)->count();
|
|
|
$states = $this->catalogStates();
|
|
$states = $this->catalogStates();
|
|
|
|
|
+ $gameCountsByPlat = $this->gameCountsByPlat();
|
|
|
$list = $query->orderByDesc('sort')
|
|
$list = $query->orderByDesc('sort')
|
|
|
->orderByDesc('id')
|
|
->orderByDesc('id')
|
|
|
->forPage($page, $limit)
|
|
->forPage($page, $limit)
|
|
|
->get()
|
|
->get()
|
|
|
- ->map(fn (EgameItem $item) => $this->decorateItem($item, $states))
|
|
|
|
|
|
|
+ ->map(fn (EgameItem $item) => $this->decorateItem($item, $states, $gameCountsByPlat))
|
|
|
->values();
|
|
->values();
|
|
|
} catch (ValidationException $e) {
|
|
} catch (ValidationException $e) {
|
|
|
return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
|
|
return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
|
|
@@ -121,11 +130,7 @@ class Egame extends Controller
|
|
|
'plat_type',
|
|
'plat_type',
|
|
|
'game_type'
|
|
'game_type'
|
|
|
);
|
|
);
|
|
|
- $platformGameCounts = $this->groupedCounts(
|
|
|
|
|
- EgameItem::query()->where('item_type', EgameItem::TYPE_GAME),
|
|
|
|
|
- 'plat_type',
|
|
|
|
|
- 'id'
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ $platformGameCounts = $this->gameCountsByPlat();
|
|
|
|
|
|
|
|
$categories = EgameItem::query()
|
|
$categories = EgameItem::query()
|
|
|
->where('item_type', EgameItem::TYPE_CATEGORY)
|
|
->where('item_type', EgameItem::TYPE_CATEGORY)
|
|
@@ -149,7 +154,7 @@ class Egame extends Controller
|
|
|
->orderBy('plat_type')
|
|
->orderBy('plat_type')
|
|
|
->get()
|
|
->get()
|
|
|
->map(function (EgameItem $item) use ($states, $platformCategoryCounts, $platformGameCounts) {
|
|
->map(function (EgameItem $item) use ($states, $platformCategoryCounts, $platformGameCounts) {
|
|
|
- $this->decorateItem($item, $states);
|
|
|
|
|
|
|
+ $this->decorateItem($item, $states, $platformGameCounts);
|
|
|
$key = strtolower((string) $item->plat_type);
|
|
$key = strtolower((string) $item->plat_type);
|
|
|
$item->setAttribute('category_count', $platformCategoryCounts[$key] ?? 0);
|
|
$item->setAttribute('category_count', $platformCategoryCounts[$key] ?? 0);
|
|
|
$item->setAttribute('game_count', $platformGameCounts[$key] ?? 0);
|
|
$item->setAttribute('game_count', $platformGameCounts[$key] ?? 0);
|
|
@@ -163,15 +168,9 @@ class Egame extends Controller
|
|
|
return $this->success([
|
|
return $this->success([
|
|
|
'categories' => $categories,
|
|
'categories' => $categories,
|
|
|
'platforms' => $platforms,
|
|
'platforms' => $platforms,
|
|
|
- 'statuses' => [
|
|
|
|
|
- ['value' => EgameItem::STATUS_ENABLED, 'label' => '开启'],
|
|
|
|
|
- ['value' => EgameItem::STATUS_DISABLED, 'label' => '关闭'],
|
|
|
|
|
- ],
|
|
|
|
|
- 'ingress' => [
|
|
|
|
|
- ['value' => '1', 'label' => '仅电脑'],
|
|
|
|
|
- ['value' => '2', 'label' => '仅手机'],
|
|
|
|
|
- ['value' => '3', 'label' => '通用'],
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ 'statuses' => EgameItem::optionList(EgameItem::STATUS_LABELS),
|
|
|
|
|
+ 'ingress' => EgameItem::optionList(EgameItem::INGRESS_LABELS),
|
|
|
|
|
+ 'networks' => EgameItem::optionList(EgameItem::NETWORK_LABELS),
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -193,9 +192,13 @@ class Egame extends Controller
|
|
|
'game_type' => ['nullable', 'integer', 'min:0', 'max:255'],
|
|
'game_type' => ['nullable', 'integer', 'min:0', 'max:255'],
|
|
|
'game_code' => ['nullable', 'string', 'max:128'],
|
|
'game_code' => ['nullable', 'string', 'max:128'],
|
|
|
'name' => ['nullable', 'string', 'max:128'],
|
|
'name' => ['nullable', 'string', 'max:128'],
|
|
|
- 'ingress' => ['nullable', Rule::in(['1', '2', '3'])],
|
|
|
|
|
|
|
+ 'description' => ['nullable', 'string', 'max:255'],
|
|
|
|
|
+ 'ingress' => ['nullable', Rule::in(EgameItem::ingressValues())],
|
|
|
|
|
+ 'network' => ['nullable', Rule::in(array_merge([''], EgameItem::networkValues()))],
|
|
|
'lobby_enabled' => ['nullable', 'boolean'],
|
|
'lobby_enabled' => ['nullable', 'boolean'],
|
|
|
'logo' => ['nullable', 'string', 'max:500'],
|
|
'logo' => ['nullable', 'string', 'max:500'],
|
|
|
|
|
+ 'logo_pc' => ['nullable', 'string', 'max:500'],
|
|
|
|
|
+ 'logo_h5' => ['nullable', 'string', 'max:500'],
|
|
|
'logo_langs' => ['nullable', 'array'],
|
|
'logo_langs' => ['nullable', 'array'],
|
|
|
'status' => ['nullable', 'integer', Rule::in([
|
|
'status' => ['nullable', 'integer', Rule::in([
|
|
|
EgameItem::STATUS_DISABLED,
|
|
EgameItem::STATUS_DISABLED,
|
|
@@ -235,7 +238,7 @@ class Egame extends Controller
|
|
|
return $this->error((int) $e->getCode(), $e->getMessage());
|
|
return $this->error((int) $e->getCode(), $e->getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return $this->success($this->decorateItem($item, $this->catalogStates()));
|
|
|
|
|
|
|
+ return $this->success($this->decorateItem($item, $this->catalogStates(), $this->gameCountsByPlat()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function setStatus(): JsonResponse
|
|
public function setStatus(): JsonResponse
|
|
@@ -262,7 +265,7 @@ class Egame extends Controller
|
|
|
return $this->error((int) $e->getCode(), $e->getMessage());
|
|
return $this->error((int) $e->getCode(), $e->getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return $this->success($this->decorateItem($item, $this->catalogStates()));
|
|
|
|
|
|
|
+ return $this->success($this->decorateItem($item, $this->catalogStates(), $this->gameCountsByPlat()));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function delete(): JsonResponse
|
|
public function delete(): JsonResponse
|
|
@@ -397,19 +400,25 @@ class Egame extends Controller
|
|
|
$input = request()->all();
|
|
$input = request()->all();
|
|
|
$data = $isNew ? [
|
|
$data = $isNew ? [
|
|
|
'name' => '',
|
|
'name' => '',
|
|
|
- 'ingress' => '3',
|
|
|
|
|
|
|
+ 'description' => '',
|
|
|
|
|
+ 'ingress' => EgameItem::INGRESS_BOTH,
|
|
|
|
|
+ 'network' => '',
|
|
|
'lobby_enabled' => 0,
|
|
'lobby_enabled' => 0,
|
|
|
'logo' => '',
|
|
'logo' => '',
|
|
|
|
|
+ 'logo_h5' => '',
|
|
|
'logo_langs' => null,
|
|
'logo_langs' => null,
|
|
|
'status' => EgameItem::STATUS_ENABLED,
|
|
'status' => EgameItem::STATUS_ENABLED,
|
|
|
'sort' => 0,
|
|
'sort' => 0,
|
|
|
] : [];
|
|
] : [];
|
|
|
|
|
|
|
|
- foreach (['name', 'ingress', 'logo'] as $field) {
|
|
|
|
|
|
|
+ foreach (['name', 'description', 'ingress', 'network', 'logo', 'logo_h5'] as $field) {
|
|
|
if (array_key_exists($field, $input)) {
|
|
if (array_key_exists($field, $input)) {
|
|
|
$data[$field] = trim((string) $input[$field]);
|
|
$data[$field] = trim((string) $input[$field]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ if (array_key_exists('logo_pc', $input) && !array_key_exists('logo', $data)) {
|
|
|
|
|
+ $data['logo'] = trim((string) $input['logo_pc']);
|
|
|
|
|
+ }
|
|
|
if (array_key_exists('logo_langs', $input)) {
|
|
if (array_key_exists('logo_langs', $input)) {
|
|
|
$data['logo_langs'] = $item->item_type === EgameItem::TYPE_GAME
|
|
$data['logo_langs'] = $item->item_type === EgameItem::TYPE_GAME
|
|
|
? $input['logo_langs']
|
|
? $input['logo_langs']
|
|
@@ -427,8 +436,11 @@ class Egame extends Controller
|
|
|
: 0;
|
|
: 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if ($item->item_type !== EgameItem::TYPE_GAME && array_key_exists('ingress', $data)) {
|
|
|
|
|
- $data['ingress'] = '3';
|
|
|
|
|
|
|
+ if ($item->isCategory() && array_key_exists('ingress', $data)) {
|
|
|
|
|
+ $data['ingress'] = EgameItem::INGRESS_BOTH;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($item->isCategory() && array_key_exists('network', $data)) {
|
|
|
|
|
+ $data['network'] = '';
|
|
|
}
|
|
}
|
|
|
if ($item->item_type !== EgameItem::TYPE_GAME && array_key_exists('logo_langs', $data)) {
|
|
if ($item->item_type !== EgameItem::TYPE_GAME && array_key_exists('logo_langs', $data)) {
|
|
|
$data['logo_langs'] = null;
|
|
$data['logo_langs'] = null;
|
|
@@ -471,7 +483,7 @@ class Egame extends Controller
|
|
|
return $states;
|
|
return $states;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private function decorateItem(EgameItem $item, array $states): EgameItem
|
|
|
|
|
|
|
+ private function decorateItem(EgameItem $item, array $states, array $gameCountsByPlat = []): EgameItem
|
|
|
{
|
|
{
|
|
|
$platType = strtolower((string) $item->plat_type);
|
|
$platType = strtolower((string) $item->plat_type);
|
|
|
$gameType = (string) $item->game_type;
|
|
$gameType = (string) $item->game_type;
|
|
@@ -526,10 +538,40 @@ class Egame extends Controller
|
|
|
}
|
|
}
|
|
|
$item->setAttribute('effective_status', $disabledBy === null ? 1 : 0);
|
|
$item->setAttribute('effective_status', $disabledBy === null ? 1 : 0);
|
|
|
$item->setAttribute('disabled_by', $disabledBy);
|
|
$item->setAttribute('disabled_by', $disabledBy);
|
|
|
|
|
+ $item->setAttribute('description', (string) ($item->description ?? ''));
|
|
|
|
|
+ $item->setAttribute('logo_pc', (string) ($item->logo ?? ''));
|
|
|
|
|
+ $item->setAttribute('logo_h5', (string) ($item->logo_h5 ?? ''));
|
|
|
|
|
+ $item->setAttribute('network', (string) ($item->network ?? ''));
|
|
|
|
|
+ $item->setAttribute('network_name', EgameItem::networkName($item->network ?? ''));
|
|
|
|
|
+ $item->setAttribute('ingress_name', EgameItem::ingressName($item->ingress ?? ''));
|
|
|
|
|
+ $item->setAttribute('status_name', EgameItem::STATUS_LABELS[(int) $item->status] ?? '');
|
|
|
|
|
+
|
|
|
|
|
+ $gameCount = $gameCountsByPlat[$platType] ?? 0;
|
|
|
|
|
+ $item->setAttribute(
|
|
|
|
|
+ 'has_game_manage',
|
|
|
|
|
+ $item->item_type === EgameItem::TYPE_PLATFORM && $gameCount > 0
|
|
|
|
|
+ );
|
|
|
|
|
+ if ($item->item_type === EgameItem::TYPE_PLATFORM && !$item->hasAttribute('game_count')) {
|
|
|
|
|
+ $item->setAttribute('game_count', $gameCount);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return $item;
|
|
return $item;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private function gameCountsByPlat(): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $counts = [];
|
|
|
|
|
+ foreach ($this->groupedCounts(
|
|
|
|
|
+ EgameItem::query()->where('item_type', EgameItem::TYPE_GAME),
|
|
|
|
|
+ 'plat_type',
|
|
|
|
|
+ 'id'
|
|
|
|
|
+ ) as $platType => $count) {
|
|
|
|
|
+ $counts[strtolower((string) $platType)] = (int) $count;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $counts;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private function enabled(?EgameItem $item): bool
|
|
private function enabled(?EgameItem $item): bool
|
|
|
{
|
|
{
|
|
|
return $item !== null && $item->status === EgameItem::STATUS_ENABLED;
|
|
return $item !== null && $item->status === EgameItem::STATUS_ENABLED;
|