normalizedNetwork((string) $this->argument('network')); if ($network === null) { $this->error('network 只允许 mainland、hk、kr、jp、none'); return self::FAILURE; } $platType = strtolower(trim((string) $this->option('plat-type'))); $gameTypeOption = $this->option('game-type'); $gameType = $gameTypeOption === null || $gameTypeOption === '' ? null : (int) $gameTypeOption; $onlyEmpty = !$this->option('force'); $dryRun = (bool) $this->option('dry-run'); if ($platType === '') { $this->error('必须指定 --plat-type'); return self::FAILURE; } if ($gameType !== null && ($gameType < 1 || $gameType > 7)) { $this->error('--game-type 必须是 1~7'); return self::FAILURE; } $platformQuery = EgameItem::query() ->where('item_type', EgameItem::TYPE_PLATFORM) ->where('plat_type', $platType) ->where('game_type', '>', 0); if ($gameType !== null) { $platformQuery->where('game_type', $gameType); } if ($onlyEmpty) { $platformQuery->where(function ($query) { $query->whereNull('network')->orWhere('network', ''); }); } $gameQuery = EgameItem::query() ->where('item_type', EgameItem::TYPE_GAME) ->where('plat_type', $platType); if ($gameType !== null) { $gameQuery->where('game_type', $gameType); } if ($onlyEmpty) { $gameQuery->where(function ($query) { $query->whereNull('network')->orWhere('network', ''); }); } $platformCount = (clone $platformQuery)->count(); $gameCount = (clone $gameQuery)->count(); $label = $network === '' ? '不限制' : EgameItem::networkName($network); $this->line(sprintf( 'plat_type=%s game_type=%s network=%s(%s) only-empty=%s', $platType, $gameType === null ? '全部' : (string) $gameType, $network === '' ? 'none' : $network, $label, $onlyEmpty ? 'yes' : 'no' )); $this->line(sprintf('将更新平台行 %d 条、游戏 %d 条', $platformCount, $gameCount)); if ($dryRun) { $this->info('dry-run,未写库'); return self::SUCCESS; } $now = now(); $platformUpdated = $platformQuery->update(['network' => $network, 'updated_at' => $now]); $gameUpdated = $gameQuery->update(['network' => $network, 'updated_at' => $now]); $this->info(sprintf('已更新平台行 %d、游戏 %d', $platformUpdated, $gameUpdated)); return self::SUCCESS; } private function normalizedNetwork(string $value): ?string { $value = strtolower(trim($value)); if (in_array($value, ['none', 'unrestricted', 'clear', '-'], true)) { return ''; } if (in_array($value, EgameItem::networkValues(), true)) { return $value; } return null; } }