122 lines
4.0 KiB
PHP
122 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Repositories\Banner;
|
|
use Carbon\Carbon;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
|
|
class BannerController extends AdminController
|
|
{
|
|
|
|
protected $title = 'Banner管理';
|
|
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new Banner(), function (Grid $grid) {
|
|
$grid->column('id')->sortable();
|
|
$grid->column('banner_res')->image(100, 100);
|
|
$grid->column('banner_desc');
|
|
$grid->column('banner_address')->display(function($banner_address){
|
|
$address_options = [
|
|
'banner_index'=>"首页广告位",
|
|
'banner_goods'=>"商品广告位",
|
|
'register_gift'=>"注册活动广告位",
|
|
'vote_activity'=>"投票活动广告位",
|
|
];
|
|
return $address_options[$banner_address];
|
|
})->label();
|
|
$grid->column('jump_link', '跳转链接');
|
|
$grid->column('is_show')->switch();
|
|
$grid->column('sort')->editable();
|
|
$grid->column('created_at');
|
|
$grid->column('updated_at')->sortable();
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
// $filter->equal('id');
|
|
$filter->equal('banner_address')->select([
|
|
'banner_index'=>"首页广告位",
|
|
'banner_goods'=>"商品广告位",
|
|
'register_gift'=>"注册活动广告位",
|
|
'vote_activity'=>"投票活动广告位",
|
|
]);
|
|
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new Banner(), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('banner_res')->image(100, 100);
|
|
$show->field('banner_desc');
|
|
$show->field('banner_address')->as(function($banner_address){
|
|
$address_options = [
|
|
'banner_index'=>"首页广告位",
|
|
'banner_goods'=>"商品广告位",
|
|
'register_gift'=>"注册活动广告位",
|
|
'vote_activity'=>"投票活动广告位",
|
|
];
|
|
return $address_options[$banner_address];
|
|
})->label();
|
|
$show->field('jump_link', '跳转链接');
|
|
$show->field('is_show')->as(function($is_show){
|
|
$options = [
|
|
'0'=>"否",
|
|
'1'=>"是",
|
|
];
|
|
return $options[$is_show];
|
|
})->label();
|
|
$show->field('sort');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new Banner(), function (Form $form) {
|
|
$form->display('id');
|
|
$form->image('banner_res')
|
|
->accept('jpg,png,gif,jpeg', 'image/*')
|
|
->move('milk-tea/banners/'.Carbon::now()->toDateString())
|
|
->saveFullUrl()->removable(false)
|
|
->required()->help('建议图片尺寸:首页[750*580];商品列表[750*400]');
|
|
$form->text('banner_desc');
|
|
$form->select('banner_address', '广告位')->options([
|
|
'banner_index'=>"首页广告位",
|
|
'banner_goods'=>"商品广告位",
|
|
'register_gift'=>"注册活动广告位",
|
|
'vote_activity'=>"投票活动广告位",
|
|
])->default('banner_index');
|
|
$form->text('jump_link', '跳转链接');
|
|
$form->switch('is_show');
|
|
$form->number('sort')->default(0);
|
|
|
|
$form->display('created_at');
|
|
$form->display('updated_at');
|
|
});
|
|
}
|
|
}
|