ContactUsController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace Themes\kbgolf\pro\app\Http\Controllers;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\CallApiService;
  5. use App\Services\MessageSendService;
  6. use Themes\Pro\point2u\app\Services\MsqMarketApiService;
  7. use Unirest\Request;
  8. class ContactUsController extends Controller
  9. {
  10. private $callApiService;
  11. public function __construct(CallApiService $callApiService, MessageSendService $messageSendService)
  12. {
  13. $this->callApiService = $callApiService;
  14. $this->messageSendService = $messageSendService;
  15. }
  16. public function getSetup()
  17. {
  18. return $this->callApiService->callApi([
  19. 'url' => 'setup-get',
  20. 'data' => [
  21. 'SetupCode' => 'contact-us',
  22. 'BrandCode' => 'main',
  23. 'LangType' => getLocale()
  24. ]
  25. ]);
  26. }
  27. public function index()
  28. {
  29. return view('views.contact-us');
  30. }
  31. public function store()
  32. {
  33. $rules = [
  34. 'captcha' => 'required|captcha',
  35. 'Pc2' => 'required|regex:/^010(?:-?\d{4}){2}$/',
  36. ];
  37. $validator = validator()->make(request()->all(), $rules);
  38. if ($validator->fails()) {
  39. notify()->error('보안 체크 숫자 입력이 틀렸습니다. 다시 올바르게 입력해서 문의하기 해주세요', 'Error', 'bottomRight');
  40. return redirect()->to('/contactus-custom')->withInput();
  41. }
  42. $request = array_merge([
  43. 'Id' => 0,
  44. 'PostTypeId' => 7,
  45. 'Status' => '2',
  46. 'MemberId' => session('member')['MemberId'] ?? 0,
  47. ], request()->all());
  48. $response = $this->callApiService->callApi([
  49. 'url' => 'post-act',
  50. 'data' => [
  51. 'Page' => [
  52. $request
  53. ]
  54. ],
  55. ]);
  56. if ($this->callApiService->verifyApiError($response)) {
  57. notify()->error($response['body'], 'Error', 'bottomRight');
  58. return redirect()->route('index')->withInput();
  59. }
  60. $redirectTo = redirect()->to('/');
  61. $contactUs = $this->getSetup();
  62. $contactUs['Fields'] = [
  63. [
  64. 'Name' => 'Pc1',
  65. 'Caption' => '신청자 이름'
  66. ],
  67. [
  68. 'Name' => 'Pc2',
  69. 'Caption' => '연락처'
  70. ],
  71. [
  72. 'Name' => 'Pc3',
  73. 'Caption' => '거래 구분'
  74. ],
  75. [
  76. 'Name' => 'Pc4',
  77. 'Caption' => '회원권 구분'
  78. ],
  79. [
  80. 'Name' => 'Pc5',
  81. 'Caption' => '회원권명'
  82. ],
  83. [
  84. 'Name' => 'Pc6',
  85. 'Caption' => '희망 가격'
  86. ],
  87. [
  88. 'Name' => 'Pt1',
  89. 'Caption' => '요청 사항'
  90. ],
  91. ];
  92. $msg = '[kbgolf] 고객지원 요청내용입니다.\n';
  93. foreach($contactUs['Fields'] ?? [] as $fields) {
  94. $msg .= $fields['Caption'] . ': ' . $request[$fields['Name']] . '\n';
  95. }
  96. if ($contactUs['OkMobile']) {
  97. $toMobiles = preg_replace('/\s+/', '', explode(',', $contactUs['ToMobile']));
  98. foreach($toMobiles ?? [] as $toMobile) {
  99. $this->messageSendService->send($msg, $msg, $toMobile);
  100. }
  101. }
  102. $toMails = preg_replace('/\s+/', '', explode(',', $contactUs['ToMail']));
  103. foreach($toMails ?? [] as $toMail) {
  104. \Mail::send('views.emails.contact-us', ['request' => $request, 'contactUs' => $contactUs],
  105. function ($message) use ($toMail) {
  106. $message->to($toMail);
  107. $message->subject('[kbgolf] 고객지원 요청내용입니다.');
  108. }
  109. );
  110. }
  111. notify()->success('성공적으로 문의하였습니다', 'Success', 'bottomRight');
  112. return $redirectTo;
  113. }
  114. }