152 lines
3.5 KiB
PHP
152 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Models\Goods;
|
|
use Encore\Admin\Controllers\HasResourceActions;
|
|
use Encore\Admin\Form;
|
|
use Encore\Admin\Grid;
|
|
use Encore\Admin\Layout\Content;
|
|
use Encore\Admin\Show;
|
|
|
|
class GoodsController extends Controller
|
|
{
|
|
use HasResourceActions;
|
|
|
|
/**
|
|
* Index interface.
|
|
*
|
|
* @param Content $content
|
|
* @return Content
|
|
*/
|
|
public function index(Content $content)
|
|
{
|
|
|
|
return $content
|
|
->header('产品包管理')
|
|
->description('description')
|
|
->body($this->grid());
|
|
}
|
|
|
|
/**
|
|
* Show interface.
|
|
*
|
|
* @param mixed $id
|
|
* @param Content $content
|
|
* @return Content
|
|
*/
|
|
public function show($id, Content $content)
|
|
{
|
|
return $content
|
|
->header('Detail')
|
|
->description('description')
|
|
->body($this->detail($id));
|
|
}
|
|
|
|
/**
|
|
* Edit interface.
|
|
*
|
|
* @param mixed $id
|
|
* @param Content $content
|
|
* @return Content
|
|
*/
|
|
public function edit($id, Content $content)
|
|
{
|
|
return $content
|
|
->header('编辑产品包')
|
|
->body($this->form()->edit($id));
|
|
}
|
|
|
|
/**
|
|
* Create interface.
|
|
*
|
|
* @param Content $content
|
|
* @return Content
|
|
*/
|
|
public function create(Content $content)
|
|
{
|
|
return $content
|
|
->header('新增产品包')
|
|
->body($this->form());
|
|
}
|
|
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
$grid = new Grid(new Goods);
|
|
$grid->model()->orderBy('id', 'desc');
|
|
|
|
$grid->actions(function ($actions) {
|
|
});
|
|
|
|
$grid->filter(function ($filter) {
|
|
$filter->disableIdFilter();
|
|
$filter->like('name', '产品包名称');
|
|
$filter->equal('status', '产品包状态')->select([
|
|
1 => '正常',
|
|
0 => '禁用',
|
|
]);
|
|
});
|
|
|
|
$grid->id('ID');
|
|
$grid->cover('封面')->image('', 60, 60);
|
|
$grid->name('产品包名称');
|
|
$grid->description('试读');
|
|
$grid->price('价格');
|
|
$grid->column('类型')->display(function () {
|
|
return $this->type_text;
|
|
});
|
|
$grid->status('状态')->switch();
|
|
$grid->created_at('创建时间');
|
|
return $grid;
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
$show = new Show(Goods::findOrFail($id));
|
|
|
|
$show->id('编号');
|
|
$show->name('产品包名称');
|
|
$show->price('价格');
|
|
$show->created_at('创建时间');
|
|
|
|
return $show;
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
$form = new Form(new Goods);
|
|
|
|
$form->text('name', '产品包名称')->rules('required');
|
|
$form->textarea('description', '试读')->rules('required|max:255', [
|
|
'required' => '试读不能为空',
|
|
'max' => '试读不能超过255字',
|
|
]);
|
|
$form->text('price', '价格')->rules('required');
|
|
$form->image('cover', '封面');
|
|
$form->select('type', '类型')->options([
|
|
'1' => '普通产品',
|
|
'2' => '升级产品',
|
|
])->rules('required');
|
|
$form->editor('content', '详情')->rules('required', ['required' => '详情不能为空']);
|
|
$form->switch('status', '状态')->default(1);
|
|
return $form;
|
|
}
|
|
|
|
}
|