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(' 刷新配置');
$card->footer("文件: {$filename}命令: php artisan {$command}");
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('命令输出', "
{$output}"))
->body("");
} catch (\Exception $e) {
admin_error('刷新失败', '物品配置表刷新失败: ' . $e->getMessage());
return $content
->title($this->title)
->description('刷新物品配置表')
->body(Card::make('错误信息', "{$e->getMessage()}"))
->body("");
}
}
/**
* 刷新宝箱配置表
*
* @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('命令输出', "{$output}"))
->body("");
} catch (\Exception $e) {
admin_error('刷新失败', '宝箱配置表刷新失败: ' . $e->getMessage());
return $content
->title($this->title)
->description('刷新宝箱配置表')
->body(Card::make('错误信息', "{$e->getMessage()}"))
->body("");
}
}
/**
* 刷新宠物配置表
*
* @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('命令输出', "{$output}"))
->body("");
} catch (\Exception $e) {
admin_error('刷新失败', '宠物配置表刷新失败: ' . $e->getMessage());
return $content
->title($this->title)
->description('刷新宠物配置表')
->body(Card::make('错误信息', "{$e->getMessage()}"))
->body("");
}
}
/**
* 刷新农场房屋配置表
*
* @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('命令输出', "{$output}"))
->body("");
} catch (\Exception $e) {
admin_error('刷新失败', '农场房屋配置表刷新失败: ' . $e->getMessage());
return $content
->title($this->title)
->description('刷新农场房屋配置表')
->body(Card::make('错误信息', "{$e->getMessage()}"))
->body("");
}
}
}