You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.3 KiB
93 lines
2.3 KiB
<?php
|
|
|
|
namespace App\AdminAgent\Controllers;
|
|
|
|
use App\AdminAgent\Repositories\WaterfallAd;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
|
|
class WaterfallAdController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new WaterfallAd(), function (Grid $grid) {
|
|
$grid->disableFilterButton();
|
|
|
|
$grid->model()->where('agent_id', Admin::user()->id);
|
|
|
|
$grid->column('id')->sortable();
|
|
$grid->column('picture');
|
|
$grid->column('agent_product_id');
|
|
$grid->column('created_at');
|
|
$grid->column('updated_at')->sortable();
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->panel();
|
|
|
|
$filter->equal('id');
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new WaterfallAd(), function (Show $show) {
|
|
//不允许查看非自己的数据
|
|
if ($show->model()->agent_id != Admin::user()->id) {
|
|
Admin::exit('数据不存在');
|
|
}
|
|
|
|
$show->field('id');
|
|
$show->field('picture');
|
|
$show->field('agent_product_id');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new WaterfallAd(), function (Form $form) {
|
|
//不允许查看非自己的数据
|
|
if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
|
|
return $form->response()->error('数据不存在');
|
|
}
|
|
|
|
$form->display('id');
|
|
$form->text('picture');
|
|
$form->text('agent_product_id');
|
|
})->saving(function (Form $form) {
|
|
//不允许修改非自己的数据
|
|
if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
|
|
return $form->response()->error('数据不存在');
|
|
}
|
|
|
|
|
|
})->deleting(function (Form $form) {
|
|
//不允许删除非自己的数据
|
|
if ($form->model()[0]['agent_id'] != Admin::user()->id) {
|
|
return $form->response()->error('数据不存在');
|
|
}
|
|
});
|
|
}
|
|
}
|