Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

63 rindas
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. // チェック処理
  26. $this->checkEmailForCreate();
  27. $this->checkCustomerCode();
  28. $user->save();
  29. }
  30. private function checkEmailForCreate()
  31. {
  32. if (User::whereEmail($this->user)
  33. ->exists()
  34. ) {
  35. ParamException::throw(User::COL_NAME_EMAIL, trans('validation.unique'));
  36. }
  37. }
  38. private function checkCustomerCode()
  39. {
  40. $customer = MstCustomer::whereCustomerId($this->user->customer_code)
  41. ->first();
  42. if ($customer === null) {
  43. ParamException::throw(User::COL_NAME_CUSTOMER_CODE, trans('validation.exists'));
  44. return;
  45. }
  46. $this->user->customer_id = $customer->id;
  47. }
  48. }