|
|
@@ -3,6 +3,7 @@
|
|
|
namespace App\Module\GameItems\AdminControllers;
|
|
|
|
|
|
use App\Module\GameItems\Models\ItemInstance;
|
|
|
+use App\Module\GameItems\Models\Item as ItemItem;
|
|
|
use Dcat\Admin\Form;
|
|
|
use Dcat\Admin\Grid;
|
|
|
use Dcat\Admin\Show;
|
|
|
@@ -27,40 +28,38 @@ class InstanceController extends AdminController
|
|
|
*/
|
|
|
protected function grid()
|
|
|
{
|
|
|
- $grid = new Grid(new ItemInstance());
|
|
|
-
|
|
|
- $grid->column('id', 'ID')->sortable();
|
|
|
- $grid->column('item.name', '基础物品');
|
|
|
- $grid->column('name', '实例名称');
|
|
|
- $grid->column('tradable', '可交易')->switch();
|
|
|
- $grid->column('is_bound', '已绑定')->switch();
|
|
|
- $grid->column('bound_to', '绑定用户ID');
|
|
|
- $grid->column('bind_exp_time', '绑定过期时间');
|
|
|
- $grid->column('expire_at', '过期时间');
|
|
|
- $grid->column('created_at', '创建时间');
|
|
|
- $grid->column('updated_at', '更新时间');
|
|
|
-
|
|
|
- // 筛选
|
|
|
- $grid->filter(function ($filter) {
|
|
|
- $filter->equal('id', 'ID');
|
|
|
- $filter->equal('item_id', '基础物品')->select(
|
|
|
- ItemItem::where('is_unique', 1)->pluck('name', 'id')
|
|
|
- );
|
|
|
- $filter->like('name', '实例名称');
|
|
|
- $filter->equal('tradable', '可交易')->radio([
|
|
|
- 1 => '是',
|
|
|
- 0 => '否',
|
|
|
- ]);
|
|
|
- $filter->equal('is_bound', '已绑定')->radio([
|
|
|
- 1 => '是',
|
|
|
- 0 => '否',
|
|
|
- ]);
|
|
|
- $filter->equal('bound_to', '绑定用户ID');
|
|
|
- $filter->between('bind_exp_time', '绑定过期时间')->datetime();
|
|
|
- $filter->between('expire_at', '过期时间')->datetime();
|
|
|
+ return Grid::make(new ItemInstance(), function (Grid $grid) {
|
|
|
+ $grid->column('id', 'ID')->sortable();
|
|
|
+ $grid->column('item.name', '基础物品');
|
|
|
+ $grid->column('name', '实例名称');
|
|
|
+ $grid->column('tradable', '可交易')->switch();
|
|
|
+ $grid->column('is_bound', '已绑定')->switch();
|
|
|
+ $grid->column('bound_to', '绑定用户ID');
|
|
|
+ $grid->column('bind_exp_time', '绑定过期时间');
|
|
|
+ $grid->column('expire_at', '过期时间');
|
|
|
+ $grid->column('created_at', '创建时间');
|
|
|
+ $grid->column('updated_at', '更新时间');
|
|
|
+
|
|
|
+ // 筛选
|
|
|
+ $grid->filter(function ($filter) {
|
|
|
+ $filter->equal('id', 'ID');
|
|
|
+ $filter->equal('item_id', '基础物品')->select(
|
|
|
+ ItemItem::where('is_unique', 1)->pluck('name', 'id')
|
|
|
+ );
|
|
|
+ $filter->like('name', '实例名称');
|
|
|
+ $filter->equal('tradable', '可交易')->radio([
|
|
|
+ 1 => '是',
|
|
|
+ 0 => '否',
|
|
|
+ ]);
|
|
|
+ $filter->equal('is_bound', '已绑定')->radio([
|
|
|
+ 1 => '是',
|
|
|
+ 0 => '否',
|
|
|
+ ]);
|
|
|
+ $filter->equal('bound_to', '绑定用户ID');
|
|
|
+ $filter->between('bind_exp_time', '绑定过期时间')->datetime();
|
|
|
+ $filter->between('expire_at', '过期时间')->datetime();
|
|
|
+ });
|
|
|
});
|
|
|
-
|
|
|
- return $grid;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -86,95 +85,93 @@ class InstanceController extends AdminController
|
|
|
*/
|
|
|
protected function detail($id)
|
|
|
{
|
|
|
- $show = new Show(ItemInstance::findOrFail($id));
|
|
|
+ return Show::make(ItemInstance::findOrFail($id), function (Show $show) {
|
|
|
+ $show->field('id', 'ID');
|
|
|
+ $show->field('item.name', '基础物品');
|
|
|
+ $show->field('name', '实例名称');
|
|
|
+
|
|
|
+ // 显示显示属性
|
|
|
+ $show->field('display_attributes', '显示属性')->as(function ($attributes) {
|
|
|
+ if (empty($attributes)) {
|
|
|
+ return '无';
|
|
|
+ }
|
|
|
|
|
|
- $show->field('id', 'ID');
|
|
|
- $show->field('item.name', '基础物品');
|
|
|
- $show->field('name', '实例名称');
|
|
|
+ if (is_string($attributes)) {
|
|
|
+ $attributes = json_decode($attributes, true);
|
|
|
+ }
|
|
|
|
|
|
- // 显示显示属性
|
|
|
- $show->field('display_attributes', '显示属性')->as(function ($attributes) {
|
|
|
- if (empty($attributes)) {
|
|
|
- return '无';
|
|
|
- }
|
|
|
+ if (is_array($attributes)) {
|
|
|
+ $html = '<table class="table table-bordered">';
|
|
|
+ $html .= '<thead><tr><th>属性名</th><th>属性值</th></tr></thead>';
|
|
|
+ $html .= '<tbody>';
|
|
|
|
|
|
- if (is_string($attributes)) {
|
|
|
- $attributes = json_decode($attributes, true);
|
|
|
- }
|
|
|
+ foreach ($attributes as $key => $value) {
|
|
|
+ $html .= '<tr>';
|
|
|
+ $html .= '<td>' . $key . '</td>';
|
|
|
+ $html .= '<td>' . $value . '</td>';
|
|
|
+ $html .= '</tr>';
|
|
|
+ }
|
|
|
|
|
|
- if (is_array($attributes)) {
|
|
|
- $html = '<table class="table table-bordered">';
|
|
|
- $html .= '<thead><tr><th>属性名</th><th>属性值</th></tr></thead>';
|
|
|
- $html .= '<tbody>';
|
|
|
+ $html .= '</tbody></table>';
|
|
|
|
|
|
- foreach ($attributes as $key => $value) {
|
|
|
- $html .= '<tr>';
|
|
|
- $html .= '<td>' . $key . '</td>';
|
|
|
- $html .= '<td>' . $value . '</td>';
|
|
|
- $html .= '</tr>';
|
|
|
+ return $html;
|
|
|
}
|
|
|
|
|
|
- $html .= '</tbody></table>';
|
|
|
+ return $attributes;
|
|
|
+ })->unescape();
|
|
|
|
|
|
- return $html;
|
|
|
- }
|
|
|
+ // 显示数值属性
|
|
|
+ $show->field('numeric_attributes', '数值属性')->as(function ($attributes) {
|
|
|
+ if (empty($attributes)) {
|
|
|
+ return '无';
|
|
|
+ }
|
|
|
|
|
|
- return $attributes;
|
|
|
- })->unescape();
|
|
|
+ if (is_string($attributes)) {
|
|
|
+ $attributes = json_decode($attributes, true);
|
|
|
+ }
|
|
|
|
|
|
- // 显示数值属性
|
|
|
- $show->field('numeric_attributes', '数值属性')->as(function ($attributes) {
|
|
|
- if (empty($attributes)) {
|
|
|
- return '无';
|
|
|
- }
|
|
|
+ if (is_array($attributes)) {
|
|
|
+ $html = '<table class="table table-bordered">';
|
|
|
+ $html .= '<thead><tr><th>属性名</th><th>属性值</th></tr></thead>';
|
|
|
+ $html .= '<tbody>';
|
|
|
|
|
|
- if (is_string($attributes)) {
|
|
|
- $attributes = json_decode($attributes, true);
|
|
|
- }
|
|
|
+ foreach ($attributes as $key => $value) {
|
|
|
+ $html .= '<tr>';
|
|
|
+ $html .= '<td>' . $key . '</td>';
|
|
|
+ $html .= '<td>' . $value . '</td>';
|
|
|
+ $html .= '</tr>';
|
|
|
+ }
|
|
|
|
|
|
- if (is_array($attributes)) {
|
|
|
- $html = '<table class="table table-bordered">';
|
|
|
- $html .= '<thead><tr><th>属性名</th><th>属性值</th></tr></thead>';
|
|
|
- $html .= '<tbody>';
|
|
|
+ $html .= '</tbody></table>';
|
|
|
|
|
|
- foreach ($attributes as $key => $value) {
|
|
|
- $html .= '<tr>';
|
|
|
- $html .= '<td>' . $key . '</td>';
|
|
|
- $html .= '<td>' . $value . '</td>';
|
|
|
- $html .= '</tr>';
|
|
|
+ return $html;
|
|
|
}
|
|
|
|
|
|
- $html .= '</tbody></table>';
|
|
|
-
|
|
|
- return $html;
|
|
|
- }
|
|
|
-
|
|
|
- return $attributes;
|
|
|
- })->unescape();
|
|
|
-
|
|
|
- $show->field('tradable', '可交易')->as(function ($value) {
|
|
|
- return $value ? '是' : '否';
|
|
|
- });
|
|
|
- $show->field('is_bound', '已绑定')->as(function ($value) {
|
|
|
- return $value ? '是' : '否';
|
|
|
- });
|
|
|
- $show->field('bound_to', '绑定用户ID');
|
|
|
- $show->field('bind_exp_time', '绑定过期时间');
|
|
|
- $show->field('expire_at', '过期时间');
|
|
|
- $show->field('created_at', '创建时间');
|
|
|
- $show->field('updated_at', '更新时间');
|
|
|
+ return $attributes;
|
|
|
+ })->unescape();
|
|
|
|
|
|
- // 显示拥有该物品实例的用户
|
|
|
- $show->users('拥有用户', function ($users) {
|
|
|
- $users->resource('/admin/game-items-user-items');
|
|
|
- $users->id('ID');
|
|
|
- $users->user_id('用户ID');
|
|
|
- $users->quantity('数量');
|
|
|
- $users->expire_at('过期时间');
|
|
|
- $users->created_at('获得时间');
|
|
|
+ $show->field('tradable', '可交易')->as(function ($value) {
|
|
|
+ return $value ? '是' : '否';
|
|
|
+ });
|
|
|
+ $show->field('is_bound', '已绑定')->as(function ($value) {
|
|
|
+ return $value ? '是' : '否';
|
|
|
+ });
|
|
|
+ $show->field('bound_to', '绑定用户ID');
|
|
|
+ $show->field('bind_exp_time', '绑定过期时间');
|
|
|
+ $show->field('expire_at', '过期时间');
|
|
|
+ $show->field('created_at', '创建时间');
|
|
|
+ $show->field('updated_at', '更新时间');
|
|
|
+
|
|
|
+ // 显示拥有该物品实例的用户
|
|
|
+ $show->users('拥有用户', function ($users) {
|
|
|
+ $users->resource('/admin/game-items-user-items');
|
|
|
+ $users->id('ID');
|
|
|
+ $users->user_id('用户ID');
|
|
|
+ $users->quantity('数量');
|
|
|
+ $users->expire_at('过期时间');
|
|
|
+ $users->created_at('获得时间');
|
|
|
+ });
|
|
|
});
|
|
|
-
|
|
|
- return $show;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -213,53 +210,51 @@ class InstanceController extends AdminController
|
|
|
*/
|
|
|
protected function form()
|
|
|
{
|
|
|
- $form = new Form(new ItemInstance());
|
|
|
-
|
|
|
- $form->select('item_id', '基础物品')
|
|
|
- ->options(ItemItem::where('is_unique', 1)->pluck('name', 'id'))
|
|
|
- ->required();
|
|
|
- $form->text('name', '实例名称')
|
|
|
- ->help('留空则使用基础物品名称');
|
|
|
-
|
|
|
- // 显示属性
|
|
|
- $form->keyValue('display_attributes', '显示属性')
|
|
|
- ->help('用于显示的属性,如:攻击力、防御力等');
|
|
|
-
|
|
|
- // 数值属性
|
|
|
- $form->keyValue('numeric_attributes', '数值属性')
|
|
|
- ->help('用于计算的属性,如:攻击加成、防御加成等');
|
|
|
-
|
|
|
- $form->switch('tradable', '可交易')
|
|
|
- ->default(true);
|
|
|
- $form->switch('is_bound', '已绑定')
|
|
|
- ->default(false)
|
|
|
- ->when(true, function (Form $form) {
|
|
|
- $form->text('bound_to', '绑定用户ID')
|
|
|
- ->required()
|
|
|
- ->help('物品绑定的用户ID');
|
|
|
- $form->datetime('bind_exp_time', '绑定过期时间')
|
|
|
- ->help('绑定过期时间,为空表示永久绑定');
|
|
|
- });
|
|
|
- $form->datetime('expire_at', '过期时间')
|
|
|
- ->help('物品过期时间,为空表示永不过期');
|
|
|
-
|
|
|
- // 保存前回调
|
|
|
- $form->saving(function (Form $form) {
|
|
|
- // 如果名称为空,使用基础物品名称
|
|
|
- if (empty($form->name)) {
|
|
|
- $item = ItemItem::find($form->item_id);
|
|
|
- if ($item) {
|
|
|
- $form->name = $item->name;
|
|
|
+ return Form::make(new ItemInstance(), function (Form $form) {
|
|
|
+ $form->select('item_id', '基础物品')
|
|
|
+ ->options(ItemItem::where('is_unique', 1)->pluck('name', 'id'))
|
|
|
+ ->required();
|
|
|
+ $form->text('name', '实例名称')
|
|
|
+ ->help('留空则使用基础物品名称');
|
|
|
+
|
|
|
+ // 显示属性
|
|
|
+ $form->keyValue('display_attributes', '显示属性')
|
|
|
+ ->help('用于显示的属性,如:攻击力、防御力等');
|
|
|
+
|
|
|
+ // 数值属性
|
|
|
+ $form->keyValue('numeric_attributes', '数值属性')
|
|
|
+ ->help('用于计算的属性,如:攻击加成、防御加成等');
|
|
|
+
|
|
|
+ $form->switch('tradable', '可交易')
|
|
|
+ ->default(true);
|
|
|
+ $form->switch('is_bound', '已绑定')
|
|
|
+ ->default(false)
|
|
|
+ ->when(true, function (Form $form) {
|
|
|
+ $form->text('bound_to', '绑定用户ID')
|
|
|
+ ->required()
|
|
|
+ ->help('物品绑定的用户ID');
|
|
|
+ $form->datetime('bind_exp_time', '绑定过期时间')
|
|
|
+ ->help('绑定过期时间,为空表示永久绑定');
|
|
|
+ });
|
|
|
+ $form->datetime('expire_at', '过期时间')
|
|
|
+ ->help('物品过期时间,为空表示永不过期');
|
|
|
+
|
|
|
+ // 保存前回调
|
|
|
+ $form->saving(function (Form $form) {
|
|
|
+ // 如果名称为空,使用基础物品名称
|
|
|
+ if (empty($form->name)) {
|
|
|
+ $item = ItemItem::find($form->item_id);
|
|
|
+ if ($item) {
|
|
|
+ $form->name = $item->name;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // 如果未绑定,清空绑定相关字段
|
|
|
- if (!$form->is_bound) {
|
|
|
- $form->bound_to = null;
|
|
|
- $form->bind_exp_time = null;
|
|
|
- }
|
|
|
+ // 如果未绑定,清空绑定相关字段
|
|
|
+ if (!$form->is_bound) {
|
|
|
+ $form->bound_to = null;
|
|
|
+ $form->bind_exp_time = null;
|
|
|
+ }
|
|
|
+ });
|
|
|
});
|
|
|
-
|
|
|
- return $form;
|
|
|
}
|
|
|
}
|