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.
120 lines
3.3 KiB
120 lines
3.3 KiB
<?php
|
|
|
|
namespace App\AdminAgent\Controllers;
|
|
|
|
use App\AdminAgent\Repositories\User;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
class UserController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
Admin::translation('user');
|
|
return Grid::make(new User(), function (Grid $grid) {
|
|
$grid->disableRowSelector();
|
|
$grid->disableCreateButton();
|
|
$grid->disableBatchDelete();
|
|
$grid->disableDeleteButton();
|
|
|
|
//如果是核销人员页面,多加where条件判断
|
|
if (strpos(Route::current()->uri, 'verifier')) {
|
|
$grid->model()->where('is_verify', 1);
|
|
}
|
|
|
|
$grid->model()->where('agent_id', Admin::user()->id);
|
|
|
|
$grid->column('id')->sortable();
|
|
$grid->column('avatar')->image(60, 60);
|
|
$grid->column('mobile');
|
|
$grid->column('nickname');
|
|
$grid->column('status')->switch();
|
|
$grid->column('is_verify')->switch();
|
|
$grid->column('created_at');
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->panel();
|
|
|
|
$filter->equal('id')->width(2);
|
|
$filter->equal('mobile')->width(2);
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new User(), function (Show $show) {
|
|
$show->disableDeleteButton();
|
|
|
|
//不允许查看非自己的数据
|
|
if ($show->model()->agent_id != Admin::user()->id) {
|
|
Admin::exit('数据不存在');
|
|
}
|
|
|
|
$show->field('id');
|
|
$show->field('avatar')->image(80, 80);
|
|
$show->field('mobile');
|
|
$show->field('nickname');
|
|
$show->field('status')->bool();
|
|
$show->field('created_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new User(), function (Form $form) {
|
|
$form->disableDeleteButton();
|
|
|
|
//不允许查看非自己的数据
|
|
if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
|
|
return $form->response()->error('数据不存在');
|
|
}
|
|
|
|
$form->display('id');
|
|
$form->display('nickname');
|
|
$form->text('mobile');
|
|
$form->switch('status');
|
|
$form->switch('is_verify');
|
|
})->saving(function (Form $form) {
|
|
//不允许修改非自己的数据
|
|
if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
|
|
return $form->response()->error('数据不存在');
|
|
}
|
|
|
|
//处理特殊字段
|
|
$form->agent_id = Admin::user()->id;
|
|
if (isset($form->status)) { //为防止行内编辑出错,此处需要加判断
|
|
$form->status = $form->status ? 1 : 0;
|
|
}
|
|
if (isset($form->is_verify)) { //为防止行内编辑出错,此处需要加判断
|
|
$form->is_verify = $form->is_verify ? 1 : 0;
|
|
}
|
|
|
|
//不允许编辑的字段
|
|
$form->ignore(['id', 'agent_id', 'nickname', 'deleted_at']);
|
|
})->deleting(function (Form $form) {
|
|
return $form->response()->error('操作禁止');
|
|
});
|
|
}
|
|
}
|