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.

64 satır
1.4KB

  1. <?php
  2. namespace App\Logics\LoginUser;
  3. use App\Codes\UserRole;
  4. use App\Exceptions\ParamException;
  5. use App\Models\Htpms\MstCustomer;
  6. use App\Models\HtpmsCustomer\Mst\Shop;
  7. use App\Models\User;
  8. class LoginUserLogic
  9. {
  10. private User|null $user = null;
  11. public function createCustomerUser(User $user)
  12. {
  13. $this->user = $user;
  14. $user->role = UserRole::CUSTOMER;
  15. // チェック処理
  16. $this->checkEmailForCreate();
  17. $this->checkCustomerCode();
  18. $user->save();
  19. }
  20. public function createShopUser(Shop $shop, User $user)
  21. {
  22. $this->user = $user;
  23. $user->role = UserRole::SHOP;
  24. $user->shop_id = $shop->id;
  25. $user->shop_name = $shop->name;
  26. // チェック処理
  27. $this->checkEmailForCreate();
  28. $this->checkCustomerCode();
  29. $user->save();
  30. }
  31. private function checkEmailForCreate()
  32. {
  33. if (User::whereEmail($this->user->email)
  34. ->exists()
  35. ) {
  36. ParamException::throw(User::COL_NAME_EMAIL, trans('validation.unique'));
  37. }
  38. }
  39. private function checkCustomerCode()
  40. {
  41. $customer = MstCustomer::whereCustomerId($this->user->customer_code)
  42. ->first();
  43. if ($customer === null) {
  44. ParamException::throw(User::COL_NAME_CUSTOMER_CODE, trans('validation.exists'));
  45. return;
  46. }
  47. $this->user->customer_id = $customer->id;
  48. }
  49. }