You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1009B

  1. <?php
  2. namespace App\Http\Controllers\Web\Auth;
  3. use App\Codes\UserRole;
  4. use App\Http\Controllers\Web\WebController;
  5. use App\Models\User;
  6. use Illuminate\Http\JsonResponse;
  7. use Illuminate\Http\Request;
  8. class SwitchCustomerController extends WebController
  9. {
  10. public function name(): string
  11. {
  12. return "成り代わり(顧客)";
  13. }
  14. public function description(): string
  15. {
  16. return "成り代わりを行う";
  17. }
  18. public function __construct(protected SwitchParam $param)
  19. {
  20. parent::__construct();
  21. }
  22. protected function run(Request $request): JsonResponse
  23. {
  24. $param = $this->param;
  25. $user = User::findOrFail($param->userId);
  26. if ($user->role !== UserRole::CUSTOMER) throw new LogicException();
  27. $this->sessionUser->switch($user);
  28. $res = [
  29. 'user_id' => $user->id,
  30. 'name' => $user->name,
  31. 'role' => $user->role,
  32. ];
  33. return $this->successResponse($res);
  34. }
  35. }