UserAuthForm.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Admin\Actions\Users;
  3. use App\Models\User;
  4. use App\Models\UserVipLogModel;
  5. use App\Models\VipModel;
  6. use Dcat\Admin\Contracts\LazyRenderable;
  7. use Dcat\Admin\Traits\LazyWidget;
  8. use Dcat\Admin\Widgets\Form;
  9. use Illuminate\Support\Facades\DB;
  10. use PHPUnit\Util\Exception;
  11. class UserAuthForm extends Form implements LazyRenderable
  12. {
  13. use LazyWidget;
  14. public function __construct($data = [], $key = null)
  15. {
  16. parent::__construct($data, $key);
  17. }
  18. public function handle(array $input)
  19. {
  20. DB::beginTransaction();
  21. try {
  22. $user = User::query()->find($input['id']);
  23. if(!$user){
  24. throw new Exception("请刷新后重试");
  25. }
  26. $user->is_auth = $input['is_auth'];
  27. $user->save();
  28. DB::commit();
  29. }catch (\Exception $exception){
  30. DB::rollBack();
  31. return $this->response()->error($exception->getMessage());
  32. }
  33. return $this->response()->success('保存成功')->refresh();
  34. }
  35. public function form()
  36. {
  37. $this->hidden('id')->value($this->payload['id']);
  38. $this->select('is_auth', '认证等级')->options([0=>'未认证',1=>'真人认证',2=>"女神认证"]);
  39. }
  40. }