| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- <?php
- namespace App\Module\Game\AdminControllers;
- use App\Module\Game\DCache\ChestJsonConfig;
- use App\Module\Game\DCache\FarmHouseJsonConfig;
- use App\Module\Game\DCache\ItemJsonConfig;
- use App\Module\Game\DCache\PetJsonConfig;
- use Dcat\Admin\Layout\Content;
- use Dcat\Admin\Layout\Row;
- use Dcat\Admin\Widgets\Card;
- use Dcat\Admin\Widgets\Table;
- use Dcat\Admin\Http\Controllers\AdminController;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Artisan;
- use Spatie\RouteAttributes\Attributes\Resource;
- use Spatie\RouteAttributes\Attributes\Get;
- use Spatie\RouteAttributes\Attributes\Post;
- /**
- * 游戏配置表管理控制器
- *
- * 用于显示和管理游戏中的各种配置表
- */
- class GameConfigController extends AdminController
- {
- /**
- * 页面标题
- *
- * @var string
- */
- protected $title = '游戏配置表管理';
- /**
- * 页面描述
- *
- * @var string
- */
- protected $description = '查看和刷新游戏中的各种配置表';
- /**
- * 配置表首页
- *
- * @param Content $content
- * @return Content
- */
- public function index(Content $content)
- {
- return $content
- ->title($this->title)
- ->description($this->description)
- ->body(function (Row $row) {
- // 物品配置表卡片
- $row->column(6, $this->createConfigCard(
- '物品配置表',
- 'items.json',
- 'gameitems:generate-json',
- 'game/configs/refresh-items',
- $this->getItemConfigInfo()
- ));
- // 宝箱配置表卡片
- $row->column(6, $this->createConfigCard(
- '宝箱配置表',
- 'chest.json',
- 'gameitems:generate-chest-json',
- 'game/configs/refresh-chests',
- $this->getChestConfigInfo()
- ));
- })
- ->body(function (Row $row) {
- // 宠物配置表卡片
- $row->column(6, $this->createConfigCard(
- '宠物配置表',
- 'pet_config.json, pet_level_config.json, pet_skill_config.json',
- 'pet:generate-json',
- 'game/configs/refresh-pets',
- $this->getPetConfigInfo()
- ));
- // 农场房屋配置表卡片
- $row->column(6, $this->createConfigCard(
- '农场房屋配置表',
- 'farm_house.json',
- 'farm:generate-house-json',
- 'game/configs/refresh-farm-house',
- $this->getFarmHouseConfigInfo()
- ));
- });
- }
- /**
- * 创建配置表信息卡片
- *
- * @param string $title 卡片标题
- * @param string $filename 文件名
- * @param string $command 生成命令
- * @param string $refreshUrl 刷新URL
- * @param array $info 配置信息
- * @return Card
- */
- protected function createConfigCard($title, $filename, $command, $refreshUrl, $info)
- {
- $headers = ['属性', '值'];
- $rows = [];
- foreach ($info as $key => $value) {
- $rows[] = [$key, $value];
- }
- $card = new Card($title, Table::make($headers, $rows));
- $card->tool('<a href="' . admin_url($refreshUrl) . '" class="btn btn-primary btn-sm"><i class="fa fa-refresh"></i> 刷新配置</a>');
- $card->footer("<code>文件: {$filename}</code><br><code>命令: php artisan {$command}</code>");
- return $card;
- }
- /**
- * 获取物品配置表信息
- *
- * @return array
- */
- protected function getItemConfigInfo()
- {
- $data = ItemJsonConfig::getData();
- $info = [
- '生成时间' => $data['generated_at'] ?? '未知',
- '物品数量' => isset($data['items']) ? count($data['items']) : 0,
- '文件路径' => public_path('json/items.json'),
- ];
- return $info;
- }
- /**
- * 获取宝箱配置表信息
- *
- * @return array
- */
- protected function getChestConfigInfo()
- {
- $data = ChestJsonConfig::getData();
- $info = [
- '生成时间' => $data['generated_at'] ?? '未知',
- '宝箱数量' => isset($data['chest']) ? count($data['chest']) : 0,
- '文件路径' => public_path('json/chest.json'),
- ];
- return $info;
- }
- /**
- * 获取宠物配置表信息
- *
- * @return array
- */
- protected function getPetConfigInfo()
- {
- $data = PetJsonConfig::getData();
- $petConfig = $data['pet_config'] ?? [];
- $petLevelConfig = $data['pet_level_config'] ?? [];
- $petSkillConfig = $data['pet_skill_config'] ?? [];
- $info = [
- '生成时间' => $petConfig['generated_at'] ?? '未知',
- '宠物数量' => isset($petConfig['pets']) ? count($petConfig['pets']) : 0,
- '等级配置数量' => isset($petLevelConfig['pet_levels']) ? count($petLevelConfig['pet_levels']) : 0,
- '技能配置数量' => isset($petSkillConfig['pet_skills']) ? count($petSkillConfig['pet_skills']) : 0,
- ];
- return $info;
- }
- /**
- * 获取农场房屋配置表信息
- *
- * @return array
- */
- protected function getFarmHouseConfigInfo()
- {
- $data = FarmHouseJsonConfig::getData();
- $info = [
- '生成时间' => $data['generated_at'] ?? '未知',
- '房屋配置数量' => isset($data['house_configs']) ? count($data['house_configs']) : 0,
- '文件路径' => public_path('json/farm_house.json'),
- ];
- return $info;
- }
- /**
- * 刷新物品配置表
- *
- * @param Content $content
- * @return Content
- */
- #[Get('game/configs/refresh-items')]
- public function refreshItems(Content $content)
- {
- try {
- Artisan::call('gameitems:generate-json');
- $output = Artisan::output();
- // 强制刷新缓存
- ItemJsonConfig::getData([], true);
- admin_success('刷新成功', '物品配置表已成功刷新');
- return $content
- ->title($this->title)
- ->description('刷新物品配置表')
- ->body(Card::make('命令输出', "<pre>{$output}</pre>"))
- ->body("<script>setTimeout(function(){ window.location.href = '" . admin_url('game/configs') . "'; }, 2000);</script>");
- } catch (\Exception $e) {
- admin_error('刷新失败', '物品配置表刷新失败: ' . $e->getMessage());
- return $content
- ->title($this->title)
- ->description('刷新物品配置表')
- ->body(Card::make('错误信息', "<pre>{$e->getMessage()}</pre>"))
- ->body("<script>setTimeout(function(){ window.location.href = '" . admin_url('game/configs') . "'; }, 3000);</script>");
- }
- }
- /**
- * 刷新宝箱配置表
- *
- * @param Content $content
- * @return Content
- */
- #[Get('game/configs/refresh-chests')]
- public function refreshChests(Content $content)
- {
- try {
- Artisan::call('gameitems:generate-chest-json');
- $output = Artisan::output();
- // 强制刷新缓存
- ChestJsonConfig::getData([], true);
- admin_success('刷新成功', '宝箱配置表已成功刷新');
- return $content
- ->title($this->title)
- ->description('刷新宝箱配置表')
- ->body(Card::make('命令输出', "<pre>{$output}</pre>"))
- ->body("<script>setTimeout(function(){ window.location.href = '" . admin_url('game/configs') . "'; }, 2000);</script>");
- } catch (\Exception $e) {
- admin_error('刷新失败', '宝箱配置表刷新失败: ' . $e->getMessage());
- return $content
- ->title($this->title)
- ->description('刷新宝箱配置表')
- ->body(Card::make('错误信息', "<pre>{$e->getMessage()}</pre>"))
- ->body("<script>setTimeout(function(){ window.location.href = '" . admin_url('game/configs') . "'; }, 3000);</script>");
- }
- }
- /**
- * 刷新宠物配置表
- *
- * @param Content $content
- * @return Content
- */
- #[Get('game/configs/refresh-pets')]
- public function refreshPets(Content $content)
- {
- try {
- Artisan::call('pet:generate-json');
- $output = Artisan::output();
- // 强制刷新缓存
- PetJsonConfig::getData([], true);
- admin_success('刷新成功', '宠物配置表已成功刷新');
- return $content
- ->title($this->title)
- ->description('刷新宠物配置表')
- ->body(Card::make('命令输出', "<pre>{$output}</pre>"))
- ->body("<script>setTimeout(function(){ window.location.href = '" . admin_url('game/configs') . "'; }, 2000);</script>");
- } catch (\Exception $e) {
- admin_error('刷新失败', '宠物配置表刷新失败: ' . $e->getMessage());
- return $content
- ->title($this->title)
- ->description('刷新宠物配置表')
- ->body(Card::make('错误信息', "<pre>{$e->getMessage()}</pre>"))
- ->body("<script>setTimeout(function(){ window.location.href = '" . admin_url('game/configs') . "'; }, 3000);</script>");
- }
- }
- /**
- * 刷新农场房屋配置表
- *
- * @param Content $content
- * @return Content
- */
- #[Get('game/configs/refresh-farm-house')]
- public function refreshFarmHouse(Content $content)
- {
- try {
- Artisan::call('farm:generate-house-json');
- $output = Artisan::output();
- // 强制刷新缓存
- FarmHouseJsonConfig::getData([], true);
- admin_success('刷新成功', '农场房屋配置表已成功刷新');
- return $content
- ->title($this->title)
- ->description('刷新农场房屋配置表')
- ->body(Card::make('命令输出', "<pre>{$output}</pre>"))
- ->body("<script>setTimeout(function(){ window.location.href = '" . admin_url('game/configs') . "'; }, 2000);</script>");
- } catch (\Exception $e) {
- admin_error('刷新失败', '农场房屋配置表刷新失败: ' . $e->getMessage());
- return $content
- ->title($this->title)
- ->description('刷新农场房屋配置表')
- ->body(Card::make('错误信息', "<pre>{$e->getMessage()}</pre>"))
- ->body("<script>setTimeout(function(){ window.location.href = '" . admin_url('game/configs') . "'; }, 3000);</script>");
- }
- }
- }
|