|
|
@@ -5,6 +5,9 @@ namespace App\Module\GameItems\AdminControllers;
|
|
|
use App\Module\Game\DCache\ItemJsonConfig;
|
|
|
use App\Module\GameItems\Enums\ITEM_TYPE;
|
|
|
use App\Module\GameItems\Models\ItemCategory;
|
|
|
+use App\Module\GameItems\Models\ItemChestOpenCost;
|
|
|
+use App\Module\GameItems\Repositorys\ItemChestContentRepository;
|
|
|
+use App\Module\GameItems\Repositorys\ItemChestOpenCostRepository;
|
|
|
use App\Module\GameItems\Repositorys\ItemRepository;
|
|
|
use Dcat\Admin\Form;
|
|
|
use Dcat\Admin\Grid;
|
|
|
@@ -28,18 +31,19 @@ use App\Module\GameItems\AdminControllers\Actions\DuplicateRowAction;
|
|
|
#[Resource('game-items', names: 'dcat.admin.game-items')]
|
|
|
class ItemController extends AdminController
|
|
|
{
|
|
|
+
|
|
|
/**
|
|
|
* 生成物品JSON数据
|
|
|
*/
|
|
|
#[Get('game-items/generate-json')]
|
|
|
public function generateJson()
|
|
|
{
|
|
|
- $success = ItemJsonConfig::getData([],true);
|
|
|
+ $success = ItemJsonConfig::getData([], true);
|
|
|
|
|
|
return response()->json([
|
|
|
- 'status' => $success ? 'success' : 'error',
|
|
|
- 'message' => $success ? 'JSON生成成功' : 'JSON生成失败'
|
|
|
- ]);
|
|
|
+ 'status' => $success ? 'success' : 'error',
|
|
|
+ 'message' => $success ? 'JSON生成成功' : 'JSON生成失败'
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -57,7 +61,7 @@ class ItemController extends AdminController
|
|
|
*/
|
|
|
protected function grid()
|
|
|
{
|
|
|
- return Grid::make(new ItemRepository(['category']), function (Grid $grid) {
|
|
|
+ return Grid::make(new ItemRepository([ 'category' ]), function (Grid $grid) {
|
|
|
$status = \App\Module\GameItems\AdminControllers\Tools\RefreshCheckTool::checkSyncStatus();
|
|
|
|
|
|
if ($status['is_synced']) {
|
|
|
@@ -67,9 +71,9 @@ class ItemController extends AdminController
|
|
|
}
|
|
|
|
|
|
$grid->tools([
|
|
|
- new \App\Module\GameItems\AdminControllers\Tools\RefreshCheckTool($status['should_display']),
|
|
|
- new \App\Module\GameItems\AdminControllers\Tools\SyncItemsJsonTool($status['should_display'])
|
|
|
- ]);
|
|
|
+ new \App\Module\GameItems\AdminControllers\Tools\RefreshCheckTool($status['should_display']),
|
|
|
+ new \App\Module\GameItems\AdminControllers\Tools\SyncItemsJsonTool($status['should_display'])
|
|
|
+ ]);
|
|
|
|
|
|
$helper = new GridHelper($grid, $this);
|
|
|
$grid->column('id', 'ID')->sortable();
|
|
|
@@ -98,33 +102,34 @@ class ItemController extends AdminController
|
|
|
// 筛选
|
|
|
$grid->filter(function ($filter) {
|
|
|
$helper = new FilterHelper($filter, $this);
|
|
|
- $helper->equal('id','ID');
|
|
|
+ $helper->equal('id', 'ID');
|
|
|
|
|
|
$filter->like('name', '名称');
|
|
|
$filter->equal('category_id', '分类')->select(
|
|
|
ItemCategory::pluck('name', 'id')
|
|
|
);
|
|
|
- $helper->equalRadioModelCats('type','类型');
|
|
|
+ $helper->equalRadioModelCats('type', '类型');
|
|
|
|
|
|
$filter->equal('is_unique', '单独属性')->radio([
|
|
|
+ 1 => '是',
|
|
|
+ 0 => '否',
|
|
|
+ ]);
|
|
|
+ $filter->equal('tradable', '可交易')->radio([
|
|
|
+ 1 => '是',
|
|
|
+ 0 => '否',
|
|
|
+ ]);
|
|
|
+ $filter->equal('dismantlable', '可分解')->radio([
|
|
|
1 => '是',
|
|
|
0 => '否',
|
|
|
]);
|
|
|
- $filter->equal('tradable', '可交易')->radio([
|
|
|
- 1 => '是',
|
|
|
- 0 => '否',
|
|
|
- ]);
|
|
|
- $filter->equal('dismantlable', '可分解')->radio([
|
|
|
- 1 => '是',
|
|
|
- 0 => '否',
|
|
|
- ]);
|
|
|
});
|
|
|
|
|
|
return $grid;
|
|
|
});
|
|
|
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 详情页
|
|
|
*
|
|
|
@@ -135,7 +140,7 @@ class ItemController extends AdminController
|
|
|
{
|
|
|
return Show::make($id, new ItemRepository(), function (Show $show) {
|
|
|
$helper = new ShowHelper($show, $this);
|
|
|
- $helper->field('id','ID');
|
|
|
+ $helper->field('id', 'ID');
|
|
|
$show->field('name', '名称');
|
|
|
$show->field('description', '描述');
|
|
|
$show->field('category.name', '分类');
|
|
|
@@ -157,23 +162,54 @@ class ItemController extends AdminController
|
|
|
$show->field('global_expire_at', '全局过期时间');
|
|
|
$show->field('created_at', '创建时间');
|
|
|
$show->field('updated_at', '更新时间');
|
|
|
-
|
|
|
+ $show->divider();
|
|
|
// 如果是宝箱类型,显示宝箱内容
|
|
|
- if ($show->getModel()->type == ITEM_TYPE::CHEST) {
|
|
|
- $show->chestContents('宝箱内容', function ($chestContents) {
|
|
|
- $chestContents->resource('/admin/game-items-chest-contents');
|
|
|
- $chestContents->id('ID');
|
|
|
- $chestContents->item()->name('物品名称');
|
|
|
- $chestContents->group()->name('物品组名称');
|
|
|
- $chestContents->min_quantity('最小数量');
|
|
|
- $chestContents->max_quantity('最大数量');
|
|
|
- $chestContents->weight('权重');
|
|
|
- $chestContents->allow_duplicate('允许重复')->bool();
|
|
|
- $chestContents->pity_count('保底次数');
|
|
|
- $chestContents->pity_weight_factor('保底权重因子');
|
|
|
+
|
|
|
+ $show->relation('chest_contents', '宝箱内容',
|
|
|
+ function (\App\Module\GameItems\Models\Item $item) {
|
|
|
+// dd($item);
|
|
|
+ $grid = new Grid(new ItemChestContentRepository([ 'chest', 'item', 'group' ]));
|
|
|
+
|
|
|
+ $grid->model()->where('chest_id', $item->id);
|
|
|
+
|
|
|
+ // 设置路由
|
|
|
+ $grid->setResource('game-items-chest-contents');
|
|
|
+
|
|
|
+ $grid->id();
|
|
|
+ $grid->column('chest.name', '宝箱名称');
|
|
|
+ $grid->column('item.name', '物品名称');
|
|
|
+ $grid->column('group.name', '物品组名称');
|
|
|
+ $grid->column('min_quantity', '最小数量');
|
|
|
+ $grid->column('max_quantity', '最大数量');
|
|
|
+ $grid->column('weight', '权重');
|
|
|
+
|
|
|
+ $grid->disableActions();
|
|
|
+
|
|
|
+ return $grid;
|
|
|
+
|
|
|
});
|
|
|
- }
|
|
|
|
|
|
+ $show->relation('chest_costs', '宝箱消耗',
|
|
|
+ function (\App\Module\GameItems\Models\Item $item) {
|
|
|
+// dd($item);
|
|
|
+ $grid = new Grid(new ItemChestOpenCostRepository(['cost_item']));
|
|
|
+
|
|
|
+ $grid->model()->where('chest_id', $item->id);
|
|
|
+
|
|
|
+ // 设置路由
|
|
|
+ $grid->setResource('game-items-chest-costs');
|
|
|
+
|
|
|
+ $grid->id();
|
|
|
+ $grid->column('cost_item.name', '物品名称');
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $grid->disableActions();
|
|
|
+
|
|
|
+ return $grid;
|
|
|
+
|
|
|
+ });
|
|
|
return $show;
|
|
|
});
|
|
|
|
|
|
@@ -188,14 +224,14 @@ class ItemController extends AdminController
|
|
|
protected function form()
|
|
|
{
|
|
|
return Form::make(new ItemRepository(), function (Form $form) {
|
|
|
- $helper = new \App\Module\GameItems\AdminControllers\Helper\FormHelper($form,$this);
|
|
|
+ $helper = new \App\Module\GameItems\AdminControllers\Helper\FormHelper($form, $this);
|
|
|
$helper->text('name')->required();
|
|
|
|
|
|
$form->textarea('description', '描述');
|
|
|
$form->select('category_id', '分类')
|
|
|
->options(ItemCategory::pluck('name', 'id'))
|
|
|
->required();
|
|
|
- $helper->selectOptionCast('type','类型');
|
|
|
+ $helper->selectOptionCast('type', '类型');
|
|
|
|
|
|
$form->switch('is_unique', '单独属性')
|
|
|
->default(false);
|