ContactUsCustomController.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. $query = "post_type_id = 58";
  31. $limit = (int)request('limit', 12);
  32. $page = (int)request('page', 1);
  33. if($id != null){
  34. $query .= " and mx.id = '$id'";
  35. }
  36. // dd($query);
  37. // api 호출 request
  38. $contactUsCustomList = $this->callApiService->callApi([
  39. 'url' => 'post-page',
  40. 'data' => [
  41. 'PageVars' => [
  42. 'Query' => $query,
  43. 'Desc' => 'created_on',
  44. 'Limit' => $limit,
  45. 'Offset' => ($page - 1) * $limit
  46. ]
  47. ]
  48. ]);
  49. // date 포맷 변경
  50. if (isset($contactUsCustomList['Page']) && !empty($contactUsCustomList['Page'])) {
  51. foreach ($contactUsCustomList['Page'] as &$contactUsCustom) {
  52. if (isset($contactUsCustom['OfficialDate'])) {
  53. $OfficialDate = DateTime::createFromFormat('Ymd', $contactUsCustom['OfficialDate']);
  54. $date = $OfficialDate->format('Y.m.d');
  55. $contactUsCustom['date'] = $date;
  56. }
  57. if(isset($contactUsCustom['Pc1'])){
  58. $Pc1Length = mb_strlen($contactUsCustom['Pc1'], 'UTF-8');
  59. if($Pc1Length > 2){
  60. $contactUsCustom['maskedName'] = mb_substr($contactUsCustom['Pc1'], 0, $Pc1Length - 2, 'UTF-8') . 'OO';
  61. }else{
  62. $contactUsCustom['maskedName'] = mb_substr($contactUsCustom['Pc1'], 0, $Pc1Length - 1, 'UTF-8') . 'O';
  63. }
  64. }
  65. }
  66. }
  67. // dd($contactUsCustomList);
  68. if ($this->callApiService->verifyApiError($contactUsCustomList)) {
  69. notify()->error($contactUsCustomList['body'], 'Error', 'bottomRight');
  70. return redirect()->back();
  71. }
  72. // pagenation
  73. $totalcnt = $contactUsCustomList['PageVars']['QueryCnt'];
  74. $contactUsCustomItems['Page'] = new LengthAwarePaginator(
  75. $contactUsCustomList['Page'],
  76. $totalcnt,
  77. $limit,
  78. $page,
  79. ['path' => request()->url()]
  80. );
  81. return view('views.page.contactus-custom-list', compact('contactUsCustomList', 'contactUsCustomItems'));
  82. }
  83. public function show($siseType = null, $postTitle = null)
  84. {
  85. if (is_null($postTitle) && !is_null($siseType)) {
  86. $postTitle = $siseType;
  87. $siseType = null;
  88. }
  89. $limit = (int)request('limit', 10);
  90. $page = (int)request('page', 1);
  91. $policyPage = $this->callApiService->callApi([
  92. 'url' => 'simple-join-page',
  93. 'data' => [
  94. 'QueryVars' => [
  95. 'QueryName' => 'post-member-user',
  96. 'SimpleFilter' => "post_type_id = 12 and mx.status = '0'"
  97. ],
  98. 'PageVars' => [
  99. 'Desc' => 'Id',
  100. 'Limit' => $limit,
  101. 'Offset' => ($page - 1) * $limit
  102. ]
  103. ]
  104. ]);
  105. $policy = $policyPage['Page'][0];
  106. if (empty($policy)) {
  107. notify()->error(__('개인정보 보호정책이 존재하지 않습니다'), 'Error', 'bottomRight');
  108. return redirect()->back();
  109. }
  110. if (empty($policy['PostSlug'])) {
  111. $key = $policy['Id'];
  112. } else {
  113. $key = $policy['PostSlug'];
  114. }
  115. return view('views.page.contactus-custom', [
  116. 'siseType' => $siseType,
  117. 'postTitle' => $postTitle,
  118. ], compact('policy', 'policy'));
  119. }
  120. public function store()
  121. {
  122. $rules = [
  123. 'captcha' => 'required|captcha',
  124. 'Pc2' => 'required|regex:/^010(?:-?\d{4}){2}$/',
  125. ];
  126. $validator = validator()->make(request()->all(), $rules);
  127. if ($validator->fails()) {
  128. notify()->error('보안 체크 숫자 입력이 틀렸습니다. 다시 올바르게 입력해서 문의하기 해주세요', 'Error', 'bottomRight');
  129. return redirect()->to('/contactus-custom')->withInput();
  130. }
  131. $request = array_merge([
  132. 'Id' => 0,
  133. 'PostTypeId' => 58,
  134. 'Status' => '2',
  135. 'MemberId' => session('member')['MemberId'] ?? 0,
  136. ], request()->all());
  137. $response = $this->callApiService->callApi([
  138. 'url' => 'post-act',
  139. 'data' => [
  140. 'Page' => [
  141. $request
  142. ]
  143. ],
  144. ]);
  145. if ($this->callApiService->verifyApiError($response)) {
  146. notify()->error($response['body'], 'Error', 'bottomRight');
  147. return redirect()->route('index')->withInput();
  148. }
  149. $redirectTo = redirect()->to('/');
  150. $contactUs = $this->getSetup();
  151. $contactUs['Fields'] = [
  152. [
  153. 'Name' => 'Pc1',
  154. 'Caption' => '신청자 이름'
  155. ],
  156. [
  157. 'Name' => 'Pc2',
  158. 'Caption' => '연락처'
  159. ],
  160. [
  161. 'Name' => 'Pc3',
  162. 'Caption' => '거래 구분'
  163. ],
  164. [
  165. 'Name' => 'Pc4',
  166. 'Caption' => '회원권 구분'
  167. ],
  168. [
  169. 'Name' => 'Pc5',
  170. 'Caption' => '회원권명'
  171. ],
  172. [
  173. 'Name' => 'Pc6',
  174. 'Caption' => '희망 가격'
  175. ],
  176. [
  177. 'Name' => 'Pt1',
  178. 'Caption' => '요청 사항'
  179. ],
  180. [
  181. 'Name' => 'Pc7',
  182. 'Caption' => '상태'
  183. ],
  184. ];
  185. $msg = '[kbgolf] 고객지원 요청내용입니다.\n';
  186. foreach($contactUs['Fields'] ?? [] as $fields) {
  187. $msg .= $fields['Caption'] . ': ' . $request[$fields['Name']] . '\n';
  188. }
  189. if ($contactUs['OkMobile']) {
  190. $toMobiles = preg_replace('/\s+/', '', explode(',', $contactUs['ToMobile']));
  191. foreach($toMobiles ?? [] as $toMobile) {
  192. $this->messageSendService->send($msg, $msg, $toMobile);
  193. }
  194. }
  195. $toMails = preg_replace('/\s+/', '', explode(',', $contactUs['ToMail']));
  196. foreach($toMails ?? [] as $toMail) {
  197. \Mail::send('views.emails.contact-us', ['request' => $request, 'contactUs' => $contactUs],
  198. function ($message) use ($toMail) {
  199. $message->to($toMail);
  200. $message->subject('[kbgolf] 고객지원 요청내용입니다.');
  201. }
  202. );
  203. }
  204. notify()->success('성공적으로 문의하였습니다', 'Success', 'bottomRight');
  205. return $redirectTo;
  206. }
  207. }