UserController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Modes\User;
  4. use App\Http\Controllers\Controller;
  5. use Encore\Admin\Controllers\HasResourceActions;
  6. use Encore\Admin\Form;
  7. use Encore\Admin\Grid;
  8. use Encore\Admin\Layout\Content;
  9. use Encore\Admin\Show;
  10. class UserController extends Controller
  11. {
  12. use HasResourceActions;
  13. /**
  14. * Index interface.
  15. *
  16. * @param Content $content
  17. * @return Content
  18. */
  19. public function index(Content $content)
  20. {
  21. return $content
  22. ->header('用户列表')
  23. ->description(' ')
  24. ->body($this->grid());
  25. }
  26. /**
  27. * Show interface.
  28. *
  29. * @param mixed $id
  30. * @param Content $content
  31. * @return Content
  32. */
  33. public function show($id, Content $content)
  34. {
  35. return $content
  36. ->header('用户详情')
  37. ->description(' ')
  38. ->body($this->detail($id));
  39. }
  40. /**
  41. * Edit interface.
  42. *
  43. * @param mixed $id
  44. * @param Content $content
  45. * @return Content
  46. */
  47. public function edit($id, Content $content)
  48. {
  49. return $content
  50. ->header('用户编辑')
  51. ->description(' ')
  52. ->body($this->form()->edit($id));
  53. }
  54. /**
  55. * Create interface.
  56. *
  57. * @param Content $content
  58. * @return Content
  59. */
  60. public function create(Content $content)
  61. {
  62. return $content
  63. ->header('用户新增')
  64. ->description(' ')
  65. ->body($this->form());
  66. }
  67. /**
  68. * Make a grid builder.
  69. *
  70. * @return Grid
  71. */
  72. protected function grid()
  73. {
  74. $grid = new Grid(new User);
  75. $grid->id('Id');
  76. $grid->mobile('手机号码');
  77. $grid->nick_name('昵称');
  78. $grid->avatar('头像');
  79. $grid->real_name('真实姓名');
  80. $grid->id_card('身份证号码');
  81. $grid->balance('余额');
  82. $grid->coin('点币');
  83. $grid->province('省');
  84. $grid->city('市');
  85. $grid->district('区');
  86. $grid->invitor('邀请人');
  87. $grid->invite_code('邀请码');
  88. $grid->level('等级');
  89. $grid->status('状态');
  90. $grid->created_at('注册时间');
  91. return $grid;
  92. }
  93. /**
  94. * Make a show builder.
  95. *
  96. * @param mixed $id
  97. * @return Show
  98. */
  99. protected function detail($id)
  100. {
  101. $show = new Show(User::findOrFail($id));
  102. $show->id('Id');
  103. $show->mobile('手机号码');
  104. $show->nick_name('昵称');
  105. $show->avatar('头像');
  106. $show->password('密码');
  107. $show->real_name('真实姓名');
  108. $show->id_card('身份证号码');
  109. $show->balance('余额');
  110. $show->coin('点币');
  111. $show->province('省');
  112. $show->city('市');
  113. $show->district('区');
  114. $show->invitor('邀请人');
  115. $show->invite_code('邀请码');
  116. $show->level('等级');
  117. $show->status('状态');
  118. $show->created_at('注册时间');
  119. return $show;
  120. }
  121. /**
  122. * Make a form builder.
  123. *
  124. * @return Form
  125. */
  126. protected function form()
  127. {
  128. $form = new Form(new User);
  129. $form->number('mobile', '手机号码');
  130. $form->text('nick_name', '昵称');
  131. $form->image('avatar', '头像');
  132. $form->password('password', '密码');
  133. $form->text('real_name', '真实姓名');
  134. $form->text('id_card', '身份证号码');
  135. $form->decimal('balance', '余额')->default(0.0000);
  136. $form->decimal('coin', '点币')->default(0.0000);
  137. $form->number('province', '省');
  138. $form->number('city', '市');
  139. $form->number('district', '区');
  140. $form->number('invitor', '邀请人');
  141. $form->text('invite_code', '邀请码');
  142. $form->switch('level', '等级')->default(1);
  143. $form->switch('status', '状态')->default(1);
  144. // 修改密码
  145. $form->saving(function (Form $form) {
  146. if ($form->password && $form->model()->password !== $form->password) {
  147. $form->password = User::encodePassword($form->password);
  148. }
  149. $form->avata = '/upload/' . $form->avatar;
  150. });
  151. return $form;
  152. }
  153. }