| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- <?php
- namespace App\Module\Game\AdminControllers;
- use App\Module\Game\DCache\ChestJsonConfig;
- use App\Module\Game\DCache\FarmHouseJsonConfig;
- use App\Module\Game\DCache\FarmLandJsonConfig;
- use App\Module\Game\DCache\FundCurrencyJsonConfig;
- 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
- {
- /**
- * 刷新货币配置表
- *
- * @return \Illuminate\Http\JsonResponse
- */
- #[Get('game-jsonconfigs/refresh-currencies')]
- public function refreshCurrencies()
- {
- try {
- // 调用命令生成JSON
- $process = new \Symfony\Component\Process\Process(['php', 'artisan', 'fund:generate-currency-json']);
- $process->setWorkingDirectory(base_path());
- $process->run();
- if (!$process->isSuccessful()) {
- return response()->json([
- 'status' => 'error',
- 'message' => '刷新失败: ' . $process->getErrorOutput()
- ]);
- }
- // 强制刷新缓存
- FundCurrencyJsonConfig::getData([], true);
- return response()->json([
- 'status' => 'success',
- 'message' => '刷新成功'
- ]);
- } catch (\Exception $e) {
- return response()->json([
- 'status' => 'error',
- 'message' => '刷新失败: ' . $e->getMessage()
- ]);
- }
- }
- /**
- * 刷新土地配置表
- *
- * @return \Illuminate\Http\JsonResponse
- */
- #[Get('game-jsonconfigs/refresh-farm-land')]
- public function refreshFarmLand()
- {
- try {
- // 调用命令生成JSON
- $process = new \Symfony\Component\Process\Process(['php', 'artisan', 'farm:generate-land-json']);
- $process->setWorkingDirectory(base_path());
- $process->run();
- if (!$process->isSuccessful()) {
- return response()->json([
- 'status' => 'error',
- 'message' => '刷新失败: ' . $process->getErrorOutput()
- ]);
- }
- // 强制刷新缓存
- FarmLandJsonConfig::getData([], true);
- return response()->json([
- 'status' => 'success',
- 'message' => '刷新成功'
- ]);
- } catch (\Exception $e) {
- return response()->json([
- 'status' => 'error',
- 'message' => '刷新失败: ' . $e->getMessage()
- ]);
- }
- }
- /**
- * 页面标题
- *
- * @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()
- ));
- })
- ->body(function (Row $row) {
- // 土地配置表卡片
- $row->column(6, $this->createConfigCard(
- '土地配置表',
- 'farm_land.json',
- 'farm:generate-land-json',
- 'game-jsonconfigs/refresh-farm-land',
- $this->getFarmLandConfigInfo()
- ));
- // 货币配置表卡片
- $row->column(6, $this->createConfigCard(
- '货币配置表',
- 'currencies.json',
- 'fund:generate-currency-json',
- 'game-jsonconfigs/refresh-currencies',
- $this->getFundCurrencyConfigInfo()
- ));
- });
- }
- /**
- * 创建配置表信息卡片
- *
- * @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;
- }
- /**
- * 获取土地配置表信息
- *
- * @return array
- */
- protected function getFarmLandConfigInfo()
- {
- $data = FarmLandJsonConfig::getData();
- $info = [
- '生成时间' => Datetime::ts2string($data['generated_ts']),
- '土地类型数量' => isset($data['land_types']) ? count($data['land_types']) : 0,
- '升级路径数量' => isset($data['upgrade_paths']) ? count($data['upgrade_paths']) : 0,
- ];
- return $info;
- }
- /**
- * 获取货币配置表信息
- *
- * @return array
- */
- protected function getFundCurrencyConfigInfo()
- {
- $data = FundCurrencyJsonConfig::getData();
- $info = [
- '生成时间' => Datetime::ts2string($data['generated_ts']),
- '货币数量' => isset($data['currencies']) ? count($data['currencies']) : 0,
- ];
- return $info;
- }
- }
|