UsersInfo.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Admin\Actions\Users;
  3. use App\Models\User;
  4. use Dcat\Admin\Contracts\LazyRenderable;
  5. use Dcat\Admin\Traits\LazyWidget;
  6. use Dcat\Admin\Widgets\Form;
  7. use PHPUnit\Util\Exception;
  8. class UsersInfo extends Form implements LazyRenderable
  9. {
  10. use LazyWidget;
  11. public function __construct($data = [], $key = null)
  12. {
  13. parent::__construct($data, $key);
  14. }
  15. public function handle(array $input)
  16. {
  17. $user = User::query()->find($input['id']);
  18. if(!$user){
  19. return $this->response()->error('请刷新后重试');
  20. }
  21. if($input['mobile']!=$user->mobile && User::query()->where('mobile',$input['mobile'])->first()){
  22. return $this->response()->error('该手机号码已被使用');
  23. }else{
  24. $user->mobile = $input['mobile'];
  25. }
  26. if($input['password']!=''){
  27. $user->password = $input['password'];
  28. }
  29. $user->sex = $input['sex'];
  30. $user->save();
  31. return $this->response()->success('保存成功')->refresh();
  32. }
  33. public function form()
  34. {
  35. $user = User::query()->find($this->payload['id']);
  36. $this->hidden('id')->value($this->payload['id']);
  37. $this->text('mobile', '手机号')->value($user->mobile)->help('手机号,不修改则不变');
  38. $this->password('password', '密码')
  39. ->minLength(6)
  40. ->maxLength(20)
  41. ->customFormat(function ($v) {
  42. if ($v == $this->password) {
  43. return;
  44. }
  45. return $v;
  46. })
  47. ->help('请输入6-20个字符,不填写则不修改');
  48. $this->radio('sex','性别')->options([1=>"男",2=>"女"])->checked([$user->sex]);
  49. }
  50. }