UserCheck.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\admin\Actions\Notice;
  3. use App\Models\User;
  4. use Dcat\Admin\Contracts\LazyRenderable;
  5. use Dcat\Admin\Traits\LazyWidget;
  6. use Dcat\Admin\Widgets\Form;
  7. class UserCheck extends Form implements LazyRenderable
  8. {
  9. use LazyWidget;
  10. public function __construct($data = [], $key = null)
  11. {
  12. parent::__construct($data, $key);
  13. }
  14. public function handle(array $input)
  15. {
  16. $user = User::query()->find($input['id']);
  17. if(!$user){
  18. return $this->response()->error('请刷新后重试');
  19. }
  20. if($input['mobile']!=$user->mobile && User::query()->where('mobile',$input['mobile'])->first()){
  21. return $this->response()->error('该手机号码已被使用');
  22. }else{
  23. $user->mobile = $input['mobile'];
  24. }
  25. if($input['password']!=''){
  26. $user->password = $input['password'];
  27. }
  28. $user->save();
  29. return $this->response()->success('保存成功')->refresh();
  30. }
  31. public function form()
  32. {
  33. $this->hidden('id')->value($this->payload['id']);
  34. $this->radio('type')->options([0=>'全部用户',1=>'男性用户',2=>"女性用户"])->default(0);
  35. }
  36. }