| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace App\Admin\Controllers;
- use App\Modes\User;
- use App\Http\Controllers\Controller;
- use Encore\Admin\Controllers\HasResourceActions;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Show;
- class UserController extends Controller
- {
- use HasResourceActions;
- /**
- * Index interface.
- *
- * @param Content $content
- * @return Content
- */
- public function index(Content $content)
- {
- return $content
- ->header('用户列表')
- ->description(' ')
- ->body($this->grid());
- }
- /**
- * Show interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function show($id, Content $content)
- {
- return $content
- ->header('用户详情')
- ->description(' ')
- ->body($this->detail($id));
- }
- /**
- * Edit interface.
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function edit($id, Content $content)
- {
- return $content
- ->header('用户编辑')
- ->description(' ')
- ->body($this->form()->edit($id));
- }
- /**
- * Create interface.
- *
- * @param Content $content
- * @return Content
- */
- public function create(Content $content)
- {
- return $content
- ->header('用户新增')
- ->description(' ')
- ->body($this->form());
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new User);
- $grid->id('Id');
- $grid->mobile('手机号码');
- $grid->nick_name('昵称');
- $grid->avatar('头像');
- $grid->real_name('真实姓名');
- $grid->id_card('身份证号码');
- $grid->balance('余额');
- $grid->coin('点币');
- $grid->province('省');
- $grid->city('市');
- $grid->district('区');
- $grid->invitor('邀请人');
- $grid->invite_code('邀请码');
- $grid->level('等级');
- $grid->status('状态');
- $grid->created_at('注册时间');
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(User::findOrFail($id));
- $show->id('Id');
- $show->mobile('手机号码');
- $show->nick_name('昵称');
- $show->avatar('头像');
- $show->password('密码');
- $show->real_name('真实姓名');
- $show->id_card('身份证号码');
- $show->balance('余额');
- $show->coin('点币');
- $show->province('省');
- $show->city('市');
- $show->district('区');
- $show->invitor('邀请人');
- $show->invite_code('邀请码');
- $show->level('等级');
- $show->status('状态');
- $show->created_at('注册时间');
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new Form(new User);
- $form->number('mobile', '手机号码');
- $form->text('nick_name', '昵称');
- $form->image('avatar', '头像');
- $form->password('password', '密码');
- $form->text('real_name', '真实姓名');
- $form->text('id_card', '身份证号码');
- $form->decimal('balance', '余额')->default(0.0000);
- $form->decimal('coin', '点币')->default(0.0000);
- $form->number('province', '省');
- $form->number('city', '市');
- $form->number('district', '区');
- $form->number('invitor', '邀请人');
- $form->text('invite_code', '邀请码');
- $form->switch('level', '等级')->default(1);
- $form->switch('status', '状态')->default(1);
- // 修改密码
- $form->saving(function (Form $form) {
- if ($form->password && $form->model()->password !== $form->password) {
- $form->password = User::encodePassword($form->password);
- }
- $form->avata = '/upload/' . $form->avatar;
- });
- return $form;
- }
- }
|