ContactUsCustomController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace Themes\kbgolf\pro\app\Http\Controllers\Page;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\CallApiService;
  5. use App\Services\MessageSendService;
  6. use Illuminate\Pagination\LengthAwarePaginator;
  7. use Illuminate\Http\Request;
  8. use DateTime;
  9. class ContactUsCustomController extends Controller
  10. {
  11. private $callApiService;
  12. public function __construct(CallApiService $callApiService, MessageSendService $messageSendService)
  13. {
  14. $this->callApiService = $callApiService;
  15. $this->messageSendService = $messageSendService;
  16. }
  17. public function getSetup()
  18. {
  19. return $this->callApiService->callApi([
  20. 'url' => 'setup-get',
  21. 'data' => [
  22. 'SetupCode' => 'contact-us',
  23. 'BrandCode' => 'main',
  24. 'LangType' => getLocale()
  25. ]
  26. ]);
  27. }
  28. public function index($id=null)
  29. {
  30. [$oauth2InfoList, $develLoginInfo] = setupSsoClientOrLoginInfo('member');
  31. $query = "post_type_id = 58";
  32. $limit = (int)request('limit', 12);
  33. $page = (int)request('page', 1);
  34. if($id != null){
  35. $query .= " and mx.id = '$id'";
  36. }
  37. // dd($query);
  38. // api 호출 request
  39. $contactUsCustomList = $this->callApiService->callApi([
  40. 'url' => 'post-page',
  41. 'data' => [
  42. 'PageVars' => [
  43. 'Query' => $query,
  44. 'Desc' => 'created_on',
  45. 'Limit' => $limit,
  46. 'Offset' => ($page - 1) * $limit
  47. ]
  48. ]
  49. ]);
  50. // date 포맷 변경
  51. if (isset($contactUsCustomList['Page']) && !empty($contactUsCustomList['Page'])) {
  52. foreach ($contactUsCustomList['Page'] as &$contactUsCustom) {
  53. if (isset($contactUsCustom['OfficialDate'])) {
  54. $OfficialDate = DateTime::createFromFormat('Ymd', $contactUsCustom['OfficialDate']);
  55. $date = $OfficialDate->format('Y.m.d');
  56. $contactUsCustom['date'] = $date;
  57. }
  58. if(isset($contactUsCustom['Pc1'])){
  59. $Pc1Length = mb_strlen($contactUsCustom['Pc1'], 'UTF-8');
  60. if($Pc1Length > 2){
  61. $contactUsCustom['maskedName'] = mb_substr($contactUsCustom['Pc1'], 0, $Pc1Length - 2, 'UTF-8') . 'OO';
  62. }else{
  63. $contactUsCustom['maskedName'] = mb_substr($contactUsCustom['Pc1'], 0, $Pc1Length - 1, 'UTF-8') . 'O';
  64. }
  65. }
  66. }
  67. }
  68. // dd($contactUsCustomList);
  69. if ($this->callApiService->verifyApiError($contactUsCustomList)) {
  70. notify()->error($contactUsCustomList['body'], 'Error', 'bottomRight');
  71. return redirect()->back();
  72. }
  73. // pagenation
  74. $totalcnt = $contactUsCustomList['PageVars']['QueryCnt'];
  75. $contactUsCustomItems['Page'] = new LengthAwarePaginator(
  76. $contactUsCustomList['Page'],
  77. $totalcnt,
  78. $limit,
  79. $page,
  80. ['path' => request()->url()]
  81. );
  82. return view('views.page.contactus-custom-list', compact('contactUsCustomList', 'contactUsCustomItems', 'oauth2InfoList'));
  83. }
  84. public function store()
  85. {
  86. $rules = [
  87. 'captcha' => 'required|captcha',
  88. 'Pc2' => 'required|regex:/^010(?:-?\d{4}){2}$/',
  89. ];
  90. $validator = validator()->make(request()->all(), $rules);
  91. if ($validator->fails()) {
  92. notify()->error('보안 체크 숫자 입력이 틀렸습니다. 다시 올바르게 입력해서 문의하기 해주세요', 'Error', 'bottomRight');
  93. return redirect()->to('/contactus-custom')->withInput();
  94. }
  95. $request = array_merge([
  96. 'Id' => 0,
  97. 'PostTypeId' => 58,
  98. 'Status' => '2',
  99. 'MemberId' => session('member')['MemberId'] ?? 0,
  100. ], request()->all());
  101. $response = $this->callApiService->callApi([
  102. 'url' => 'post-act',
  103. 'data' => [
  104. 'Page' => [
  105. $request
  106. ]
  107. ],
  108. ]);
  109. if ($this->callApiService->verifyApiError($response)) {
  110. notify()->error($response['body'], 'Error', 'bottomRight');
  111. return redirect()->route('index')->withInput();
  112. }
  113. $redirectTo = redirect()->to('/');
  114. $contactUs = $this->getSetup();
  115. $contactUs['Fields'] = [
  116. [
  117. 'Name' => 'Pc1',
  118. 'Caption' => '신청자 이름'
  119. ],
  120. [
  121. 'Name' => 'Pc2',
  122. 'Caption' => '연락처'
  123. ],
  124. [
  125. 'Name' => 'Pc3',
  126. 'Caption' => '거래 구분'
  127. ],
  128. [
  129. 'Name' => 'Pc4',
  130. 'Caption' => '회원권 구분'
  131. ],
  132. [
  133. 'Name' => 'Pc5',
  134. 'Caption' => '회원권명'
  135. ],
  136. [
  137. 'Name' => 'Pc6',
  138. 'Caption' => '희망 가격'
  139. ],
  140. [
  141. 'Name' => 'Pt1',
  142. 'Caption' => '요청 사항'
  143. ],
  144. [
  145. 'Name' => 'Pc7',
  146. 'Caption' => '상태'
  147. ],
  148. ];
  149. $msg = '[kbgolf] 고객지원 요청내용입니다.\n';
  150. foreach($contactUs['Fields'] ?? [] as $fields) {
  151. $msg .= $fields['Caption'] . ': ' . $request[$fields['Name']] . '\n';
  152. }
  153. if ($contactUs['OkMobile']) {
  154. $toMobiles = preg_replace('/\s+/', '', explode(',', $contactUs['ToMobile']));
  155. foreach($toMobiles ?? [] as $toMobile) {
  156. $this->messageSendService->send($msg, $msg, $toMobile);
  157. }
  158. }
  159. $toMails = preg_replace('/\s+/', '', explode(',', $contactUs['ToMail']));
  160. foreach($toMails ?? [] as $toMail) {
  161. \Mail::send('views.emails.contact-us', ['request' => $request, 'contactUs' => $contactUs],
  162. function ($message) use ($toMail) {
  163. $message->to($toMail);
  164. $message->subject('[kbgolf] 고객지원 요청내용입니다.');
  165. }
  166. );
  167. }
  168. notify()->success('성공적으로 문의하였습니다', 'Success', 'bottomRight');
  169. return $redirectTo;
  170. }
  171. }