UsersInfo.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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->save();
  30. return $this->response()->success('保存成功')->refresh();
  31. }
  32. public function form()
  33. {
  34. $user = User::query()->find($this->payload['id']);
  35. $this->hidden('id')->value($this->payload['id']);
  36. $this->text('mobile', '手机号')->value($user->mobile)->help('手机号,不修改则不变');
  37. $this->password('password', '密码')
  38. ->minLength(6)
  39. ->maxLength(20)
  40. ->customFormat(function ($v) {
  41. if ($v == $this->password) {
  42. return;
  43. }
  44. return $v;
  45. })
  46. ->help('请输入6-20个字符,不填写则不修改');
  47. }
  48. }