SeminarSignUpController.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Api\ApiController;
  4. use App\Http\Services\Api\SeminarSignUpService;
  5. use App\Http\Requests\Api\SeminarSignUp\StoreRequest;
  6. use Log;
  7. class SeminarSignUpController extends ApiController
  8. {
  9. private $seminarSignUpSv;
  10. public function __construct()
  11. {
  12. $this->seminarSignUpSv = new SeminarSignUpService();
  13. }
  14. // save data to db
  15. public function insertData(StoreRequest $request)
  16. {
  17. $trackNo = $request->input('trackNo', '');
  18. $lang = substr($trackNo, 0, 2);
  19. $firstName_orig = $request->input('firstName', '');
  20. $firstName = $this->safeEncrypt($firstName_orig, 'arm');
  21. $lastName_orig = $request->input('lastName', '');
  22. $lastName = $this->safeEncrypt($lastName_orig, 'arm');
  23. $companyName_orig = $request->input('companyName', '');
  24. $companyName = $this->safeEncrypt($companyName_orig, 'arm');
  25. $companyEmail_orig = $request->input('companyEmail', '');
  26. $companyEmail = $this->safeEncrypt($companyEmail_orig, 'arm');
  27. $backupEmail = $request->input('backupEmail', '');
  28. if (!is_null($backupEmail)) {
  29. $backupEmail_orig = $request->input('backupEmail', '');
  30. $backupEmail = $this->safeEncrypt($backupEmail_orig, 'arm');
  31. } else {
  32. $backupEmail_orig = '';
  33. }
  34. $phoneNumber_orig = $request->input('phoneNumber', '');
  35. $phoneNumber = $this->safeEncrypt($phoneNumber_orig, 'arm');
  36. $country = $request->input('country', '');
  37. $registeredSession = $request->input('registeredSession', '');
  38. $lunchOptions = $request->input('lunchOptions', '');
  39. $typeOfIndustry = $request->input('typeOfIndustry', '');
  40. $typeOfJob = $request->input('typeOfJob', '');
  41. $jobTitle = $request->input('jobTitle', '');
  42. $trackOfInterest = $request->input('trackOfInterest', '');
  43. $areaOfInterest = $request->input('areaOfInterest', '');
  44. $howToKnowAboutTheEvent = $request->input('howToKnowAboutTheEvent', '');
  45. $consentAcceptEmail = $request->input('consentAcceptEmail', '');
  46. $consentPrivacyPolicy = $request->input('consentPrivacyPolicy', '');
  47. $media = $request->input('media', '');
  48. $utm_source = $request->input('utm_source', '');
  49. $utm_medium = $request->input('utm_medium', '');
  50. $utm_content = $request->input('utm_content', '');
  51. $utm_term = $request->input('utm_term', '');
  52. $utm_campaign = $request->input('utm_campaign', '');
  53. $overOrNot = $this->seminarSignUpSv->overLimitOrNot($trackNo); // true: 可報名 / false: 已額滿
  54. $duplicatedOrNot = $this->seminarSignUpSv->duplicatedOrNot($trackNo, $companyEmail, $phoneNumber); // true: 可報名 / false: 已重複
  55. if ($overOrNot&&$duplicatedOrNot) {
  56. $this->seminarSignUpSv->insertData(
  57. $firstName,
  58. $lastName,
  59. $companyName,
  60. $companyEmail,
  61. $backupEmail,
  62. $phoneNumber,
  63. $country,
  64. $trackNo,
  65. $registeredSession,
  66. $lunchOptions,
  67. $typeOfIndustry,
  68. $typeOfJob,
  69. $jobTitle,
  70. $trackOfInterest,
  71. $areaOfInterest,
  72. $howToKnowAboutTheEvent,
  73. $consentAcceptEmail,
  74. $consentPrivacyPolicy,
  75. $media,
  76. $utm_source,
  77. $utm_medium,
  78. $utm_content,
  79. $utm_term,
  80. $utm_campaign,
  81. );
  82. $res = '報名成功';
  83. if ($lang=='TP'||$lang=='HS') {
  84. $this->mailToUser_TW($firstName_orig, $lastName_orig, $companyName_orig, $companyEmail_orig, $backupEmail_orig,
  85. $phoneNumber_orig, $country, $registeredSession, $lunchOptions, $typeOfIndustry, $typeOfJob, $jobTitle, $trackOfInterest);
  86. } elseif ($lang=='JP') {
  87. $this->mailToUser_JP($firstName_orig, $lastName_orig, $companyName_orig, $companyEmail_orig, $backupEmail_orig,
  88. $phoneNumber_orig, $country, /*$registeredSession, $lunchOptions, */$typeOfIndustry, $typeOfJob, $jobTitle, $trackOfInterest);
  89. } elseif ($lang=='KR') {
  90. $this->mailToUser_KR($firstName_orig, $lastName_orig, $companyName_orig, $companyEmail_orig, $backupEmail_orig,
  91. $phoneNumber_orig, $country, /*$registeredSession, $lunchOptions, */$typeOfIndustry, $typeOfJob, $jobTitle, $trackOfInterest);
  92. } else {
  93. $this->mailToUser_EN($firstName_orig, $companyEmail_orig, $backupEmail_orig);
  94. }
  95. } elseif (!$overOrNot) {
  96. $res = '已達報名上限';
  97. } elseif (!$duplicatedOrNot) {
  98. $res = '已重複報名';
  99. }
  100. $data = [
  101. 'res' => $res,
  102. ];
  103. return $this->apiResponse($data);
  104. }
  105. // list
  106. public function getReMailData()
  107. {
  108. $list = $this->seminarSignUpSv->getReMailData();
  109. $returnData = array();
  110. for ($i = 0; $i < count($list); $i++) {
  111. try{
  112. // \Log::info($this->safeDecrypt($list[$i]["firstName"], 'arm'));
  113. // $data[] = array(
  114. //一般資料
  115. $id = $list[$i]["id"];
  116. $firstName_orig = $this->safeDecrypt($list[$i]["firstName"], 'arm');
  117. $lastName_orig = $this->safeDecrypt($list[$i]["lastName"], 'arm');
  118. $companyName_orig = $this->safeDecrypt($list[$i]["companyName"], 'arm');
  119. $companyEmail_orig = $this->safeDecrypt($list[$i]["companyEmail"], 'arm');
  120. if (!is_null($list[$i]["backupEmail"])) {
  121. $backupEmail_orig = $this->safeDecrypt($list[$i]["backupEmail"], 'arm');
  122. } else {
  123. $backupEmail_orig = '';
  124. }
  125. $phoneNumber_orig = $this->safeDecrypt($list[$i]["phoneNumber"], 'arm');
  126. $country = $list[$i]["country"];
  127. $trackNo = $list[$i]["trackNo"];
  128. $lang = substr($trackNo, 0, 2);
  129. $registeredSession = $list[$i]["registeredSession"];
  130. $lunchOptions = $list[$i]["lunchOptions"];
  131. $typeOfIndustry = $list[$i]["typeOfIndustry"];
  132. $typeOfJob = $list[$i]["typeOfJob"];
  133. $jobTitle = $list[$i]["jobTitle"];
  134. $trackOfInterest = $list[$i]["trackOfInterest"];
  135. // if ($lang=='TP'||$lang=='HS') {
  136. // $this->mailToUser_TW($firstName_orig, $lastName_orig, $companyName_orig, $companyEmail_orig, $backupEmail_orig,
  137. // $phoneNumber_orig, $country, $registeredSession, $lunchOptions, $typeOfIndustry, $typeOfJob, $jobTitle, $trackOfInterest);
  138. // } elseif ($lang=='JP') {
  139. // $this->mailToUser_JP($firstName_orig, $lastName_orig, $companyName_orig, $companyEmail_orig, $backupEmail_orig,
  140. // $phoneNumber_orig, $country, /*$registeredSession, $lunchOptions, */$typeOfIndustry, $typeOfJob, $jobTitle, $trackOfInterest);
  141. // } elseif ($lang=='KR') {
  142. // $this->mailToUser_KR($firstName_orig, $lastName_orig, $companyName_orig, $companyEmail_orig, $backupEmail_orig,
  143. // $phoneNumber_orig, $country, /*$registeredSession, $lunchOptions, */$typeOfIndustry, $typeOfJob, $jobTitle, $trackOfInterest);
  144. // } else {
  145. // $this->mailToUser_EN($firstName_orig, $companyEmail_orig, $backupEmail_orig);
  146. // }
  147. // );
  148. $res = [
  149. 'id' => $id,
  150. 'value' => $id.' / '.$firstName_orig.' / '.$lastName_orig.' / '.$companyName_orig.' / '.$companyEmail_orig.' / '.
  151. $backupEmail_orig.' / '.$phoneNumber_orig.' / '.$country.' / '.$trackNo.' / '.$lang.' / '.$registeredSession.' / '.
  152. $lunchOptions.' / '.$typeOfIndustry.' / '.$typeOfJob.' / '.$jobTitle.' / '.$trackOfInterest,
  153. 'message' => 'succ',
  154. ];
  155. \Log::info($id.': '.print_r($res, true));
  156. $returnData[] = $res;
  157. } catch (\Throwable $exception) {
  158. $message = [
  159. 'msg' => $exception->getMessage(),
  160. 'line' => $exception->getLine(),
  161. 'file' => $exception->getFile()
  162. ];
  163. // 返回
  164. $res = [
  165. 'id' => $id,
  166. 'value' => $id.' / '.$firstName_orig.' / '.$lastName_orig.' / '.$companyName_orig.' / '.$companyEmail_orig.' / '.
  167. $backupEmail_orig.' / '.$phoneNumber_orig.' / '.$country.' / '.$trackNo.' / '.$lang.' / '.$registeredSession.' / '.
  168. $lunchOptions.' / '.$typeOfIndustry.' / '.$typeOfJob.' / '.$jobTitle.' / '.$trackOfInterest,
  169. 'message' => $message,
  170. ];
  171. $returnData[] = $res;
  172. $log = json_encode($res, JSON_UNESCAPED_UNICODE);
  173. \Log::info(print_r($log, true));
  174. }
  175. }
  176. return $returnData;
  177. }
  178. // list
  179. public function restoreUTMData()
  180. {
  181. $list = $this->seminarSignUpSv->getUTMData();
  182. $returnData = array();
  183. for ($i = 0; $i < count($list); $i++) {
  184. //一般資料
  185. $id = $list[$i]["id"];
  186. $media = $list[$i]["media"];
  187. $tmp = substr($media, 1);
  188. $tmpArr = explode('&',$tmp);
  189. return $tmpArr;
  190. $res = [
  191. 'id' => $id,
  192. 'value' => $id.' / '.$firstName_orig.' / '.$lastName_orig.' / '.$companyName_orig.' / '.$companyEmail_orig.' / '.
  193. $backupEmail_orig.' / '.$phoneNumber_orig.' / '.$country.' / '.$trackNo.' / '.$lang.' / '.$registeredSession.' / '.
  194. $lunchOptions.' / '.$typeOfIndustry.' / '.$typeOfJob.' / '.$jobTitle.' / '.$trackOfInterest,
  195. 'message' => 'succ',
  196. ];
  197. \Log::info($id.': '.print_r($res, true));
  198. $returnData[] = $res;
  199. // } catch (\Throwable $exception) {
  200. // $message = [
  201. // 'msg' => $exception->getMessage(),
  202. // 'line' => $exception->getLine(),
  203. // 'file' => $exception->getFile()
  204. // ];
  205. // // 返回
  206. // $res = [
  207. // 'id' => $id,
  208. // 'value' => $id.' / '.$firstName_orig.' / '.$lastName_orig.' / '.$companyName_orig.' / '.$companyEmail_orig.' / '.
  209. // $backupEmail_orig.' / '.$phoneNumber_orig.' / '.$country.' / '.$trackNo.' / '.$lang.' / '.$registeredSession.' / '.
  210. // $lunchOptions.' / '.$typeOfIndustry.' / '.$typeOfJob.' / '.$jobTitle.' / '.$trackOfInterest,
  211. // 'message' => $message,
  212. // ];
  213. // $returnData[] = $res;
  214. // $log = json_encode($res, JSON_UNESCAPED_UNICODE);
  215. // \Log::info(print_r($log, true));
  216. // }
  217. }
  218. return $returnData;
  219. }
  220. public function getData()
  221. {
  222. $list = $this->seminarSignUpSv->getData();
  223. $data = [
  224. 'list' => $list
  225. ];
  226. return $this->apiResponse($data);
  227. }
  228. /**
  229. * 參數加解密模組: 加密部分,建議使用環境變數中的 secret key 作加解密種子
  230. */
  231. public function safeEncrypt(string $message, string $skey): string
  232. {
  233. $strArr = str_split(base64_encode($message));
  234. $strCount = count($strArr);
  235. foreach (str_split($skey) as $key => $value)
  236. $key < $strCount && $strArr[$key].=$value;
  237. return str_replace(array('=', ' ', '/'), array('O0O0O', 'o000o', 'oo00o'), join('', $strArr));
  238. }
  239. /**
  240. * 參數加解密模組: 解密部分,建議使用環境變數中的 secret key 作加解密種子
  241. */
  242. public function safeDecrypt(string $encrypted, string $skey): string
  243. {
  244. $strArr = str_split(str_replace(array('O0O0O', 'o000o', 'oo00o'), array('=', ' ', '/'), $encrypted), 2);
  245. $strCount = count($strArr);
  246. foreach (str_split($skey) as $key => $value)
  247. $key <= $strCount && isset($strArr[$key]) && $strArr[$key][1] === $value && $strArr[$key] = $strArr[$key][0];
  248. return base64_decode(join('', $strArr));
  249. }
  250. public function mailToUser_TW(
  251. string $firstName='',
  252. string $lastName='',
  253. string $companyName='',
  254. string $companyEmail='',
  255. string $backupEmail='',
  256. string $phoneNumber='',
  257. string $country='',
  258. string $registeredSession='',
  259. string $lunchOptions='',
  260. string $typeOfIndustry='',
  261. string $typeOfJob='',
  262. string $jobTitle='',
  263. string $trackOfInterest=''
  264. )
  265. {
  266. $data = array(
  267. 'firstName' => $firstName,
  268. 'lastName' => $lastName,
  269. 'companyName' => $companyName,
  270. 'companyEmail' => $companyEmail,
  271. 'backupEmail' => $backupEmail,
  272. 'phoneNumber' => $phoneNumber,
  273. 'country' => $country,
  274. 'registeredSession' => $registeredSession,
  275. 'lunchOptions' => $lunchOptions,
  276. 'typeOfIndustry' => $typeOfIndustry,
  277. 'typeOfJob' => $typeOfJob,
  278. 'jobTitle' => $jobTitle,
  279. 'trackOfInterest' => $trackOfInterest,
  280. );
  281. if (strlen($backupEmail)>0) {
  282. \Mail::send(['text'=>'mailTW'], $data, function($message) use ($firstName, $companyEmail, $backupEmail) {
  283. $message->to($companyEmail, $firstName)->subject('報名成功-Arm Tech Symposia 2022');
  284. $message->cc($backupEmail, $firstName)->subject('報名成功-Arm Tech Symposia 2022');
  285. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  286. });
  287. } else {
  288. \Mail::send(['text'=>'mailTW'], $data, function($message) use ($companyEmail, $firstName) {
  289. $message->to($companyEmail, $firstName)->subject('報名成功-Arm Tech Symposia 2022');
  290. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  291. });
  292. }
  293. }
  294. public function mailToUser_JP(
  295. string $firstName='',
  296. string $lastName='',
  297. string $companyName='',
  298. string $companyEmail='',
  299. string $backupEmail='',
  300. string $phoneNumber='',
  301. string $country='',
  302. // string $registeredSession='',
  303. // string $lunchOptions='',
  304. string $typeOfIndustry='',
  305. string $typeOfJob='',
  306. string $jobTitle='',
  307. string $trackOfInterest=''
  308. )
  309. {
  310. $data = array(
  311. 'firstName' => $firstName,
  312. 'lastName' => $lastName,
  313. 'companyName' => $companyName,
  314. 'companyEmail' => $companyEmail,
  315. 'backupEmail' => $backupEmail,
  316. 'phoneNumber' => $phoneNumber,
  317. 'country' => $country,
  318. // 'registeredSession' => $registeredSession,
  319. // 'lunchOptions' => $lunchOptions,
  320. 'typeOfIndustry' => $typeOfIndustry,
  321. 'typeOfJob' => $typeOfJob,
  322. 'jobTitle' => $jobTitle,
  323. 'trackOfInterest' => $trackOfInterest,
  324. );
  325. if ($backupEmail) {
  326. \Mail::send(['text'=>'mailJP'], $data, function($message) use ($companyEmail, $firstName, $backupEmail) {
  327. $message->to($companyEmail, $firstName)->subject('Arm Tech Symposia 仮登録完了のお知らせ');
  328. $message->cc($backupEmail, $firstName)->subject('Arm Tech Symposia 仮登録完了のお知らせ');
  329. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  330. });
  331. } else {
  332. \Mail::send(['text'=>'mailJP'], $data, function($message) use ($companyEmail, $firstName) {
  333. $message->to($companyEmail, $firstName)->subject('Arm Tech Symposia 仮登録完了のお知らせ');
  334. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  335. });
  336. }
  337. }
  338. public function mailToUser_KR(
  339. string $firstName='',
  340. string $lastName='',
  341. string $companyName='',
  342. string $companyEmail='',
  343. string $backupEmail='',
  344. string $phoneNumber='',
  345. string $country='',
  346. // string $registeredSession='',
  347. // string $lunchOptions='',
  348. string $typeOfIndustry='',
  349. string $typeOfJob='',
  350. string $jobTitle='',
  351. string $trackOfInterest=''
  352. )
  353. {
  354. $data = array(
  355. 'firstName' => $firstName,
  356. 'lastName' => $lastName,
  357. 'companyName' => $companyName,
  358. 'companyEmail' => $companyEmail,
  359. 'backupEmail' => $backupEmail,
  360. 'phoneNumber' => $phoneNumber,
  361. 'country' => $country,
  362. // 'registeredSession' => $registeredSession,
  363. // 'lunchOptions' => $lunchOptions,
  364. 'typeOfIndustry' => $typeOfIndustry,
  365. 'typeOfJob' => $typeOfJob,
  366. 'jobTitle' => $jobTitle,
  367. 'trackOfInterest' => $trackOfInterest,
  368. );
  369. if ($backupEmail) {
  370. \Mail::send(['text'=>'mailKR'], $data, function($message) use ($companyEmail, $firstName, $backupEmail) {
  371. $message->to($companyEmail, $firstName)->subject('등록 확인 메일');
  372. $message->cc($backupEmail, $firstName)->subject('등록 확인 메일');
  373. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  374. });
  375. } else {
  376. \Mail::send(['text'=>'mailKR'], $data, function($message) use ($companyEmail, $firstName) {
  377. $message->to($companyEmail, $firstName)->subject('등록 확인 메일');
  378. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  379. });
  380. }
  381. }
  382. public function mailToUser_EN(string $firstName='', string $companyEmail='', string $backupEmail='')
  383. {
  384. $data = array('name'=>$firstName);
  385. if ($backupEmail) {
  386. \Mail::send(['text'=>'mailEN'], $data, function($message) use ($companyEmail, $firstName, $backupEmail) {
  387. $message->to($companyEmail, $firstName)->subject('Registration is complete');
  388. $message->cc($backupEmail, $firstName)->subject('Registration is complete');
  389. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  390. });
  391. } else {
  392. \Mail::send(['text'=>'mailEN'], $data, function($message) use ($companyEmail, $firstName) {
  393. $message->to($companyEmail, $firstName)->subject('Registration is complete');
  394. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  395. });
  396. }
  397. }
  398. }