UsersInfo.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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(trans('user.help.refresh_error'));
  21. }
  22. if($input['mobile']!=$user->mobile && User::query()->where('mobile',$input['mobile'])->first()){
  23. return $this->response()->error(trans('user.help.mobile_used'));
  24. }else{
  25. $user->mobile = $input['mobile'];
  26. }
  27. if($input['email']!=$user->email && User::query()->where('email',$input['email'])->first()){
  28. return $this->response()->error(trans('user.help.email_used'));
  29. }else{
  30. $user->mobile = $input['mobile'];
  31. }
  32. if($input['password']!=''){
  33. $user->password = $input['password'];
  34. }
  35. $user->sex = $input['sex'];
  36. $user->save();
  37. return $this->response()->success('success')->refresh();
  38. }
  39. public function form()
  40. {
  41. $user = User::query()->find($this->payload['id']);
  42. $this->hidden('id')->value($this->payload['id']);
  43. $this->text('mobile')->default($user->mobile??'')->help(trans('user.help.mobile_help'));
  44. $this->text('email')->default($user->email??'')->help(trans('user.help.eamil_help'));
  45. $this->text('password')
  46. ->minLength(6)
  47. ->maxLength(20)
  48. ->customFormat(function ($v) {
  49. if ($v == $this->password) {
  50. return;
  51. }
  52. return $v;
  53. })
  54. ->help(trans('user.help.password_help'));
  55. $this->radio('sex',trans('user.fields.sex'))->options([1=>trans('user.fields.man'),2=>trans('user.fields.woman')])->value($user->sex);
  56. }
  57. }