| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <?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 App\Module\GameItems\AdminControllers\Tools\RefreshCheckTool;
- use App\Module\GameItems\AdminControllers\Tools\SyncChetsJsonTool;
- use App\Module\GameItems\AdminControllers\Tools\SyncItemsJsonTool;
- use Carbon\Carbon;
- 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;
- use UCore\Helper\Datetime;
- /**
- * 游戏配置表管理控制器
- *
- * 用于显示和管理游戏中的各种配置表
- */
- #[Resource('game-jsonconfigs', names: 'dcat.admin.game-jsonconfigs')]
- 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',
- SyncItemsJsonTool::make(),
- $this->getItemConfigInfo()
- ));
- // 宝箱配置表卡片
- $row->column(6, $this->createConfigCard(
- '宝箱配置表',
- 'chest.json',
- 'gameitems:generate-chest-json',
- SyncChetsJsonTool::make(),
- $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-jsonconfigs/refresh-pets',
- $this->getPetConfigInfo()
- ));
- // 农场房屋配置表卡片
- $row->column(6, $this->createConfigCard(
- '农场房屋配置表',
- 'farm_house.json',
- 'farm:generate-house-json',
- 'game-jsonconfigs/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, $refresh, $info)
- {
- $headers = [ '属性', '值' ];
- $rows = [];
- foreach ($info as $key => $value) {
- $rows[] = [ $key, $value ];
- }
- $card = new Card($title, Table::make($headers, $rows));
- $card->tool($refresh);
- $card->footer("<code>文件: {$filename}</code><br><code>命令: php artisan {$command}</code>");
- return $card;
- }
- /**
- * 获取物品配置表信息
- *
- * @return array
- */
- protected function getItemConfigInfo()
- {
- $data = ItemJsonConfig::getData();
- $info = [
- '生成时间' => Datetime::ts2string($data['generated_ts']),
- '物品数量' => isset($data['items']) ? count($data['items']) : 0,
- ];
- return $info;
- }
- /**
- * 获取宝箱配置表信息
- *
- * @return array
- */
- protected function getChestConfigInfo()
- {
- $data = ChestJsonConfig::getData();
- $info = [
- '生成时间' => Datetime::ts2string($data['generated_ts']),
- '宝箱数量' => isset($data['chest']) ? count($data['chest']) : 0,
- ];
- 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 = [
- '生成时间' => Datetime::ts2string($data['generated_ts']),
- '宠物数量' => 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 = [
- '生成时间' => Datetime::ts2string($data['generated_ts']),
- '房屋配置数量' => isset($data['house_configs']) ? count($data['house_configs']) : 0,
- ];
- return $info;
- }
- }
|