UsersInfo.php 1.8 KB

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