SeminarSignUpController.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. return $tmp;
  189. $res = [
  190. 'id' => $id,
  191. 'value' => $id.' / '.$firstName_orig.' / '.$lastName_orig.' / '.$companyName_orig.' / '.$companyEmail_orig.' / '.
  192. $backupEmail_orig.' / '.$phoneNumber_orig.' / '.$country.' / '.$trackNo.' / '.$lang.' / '.$registeredSession.' / '.
  193. $lunchOptions.' / '.$typeOfIndustry.' / '.$typeOfJob.' / '.$jobTitle.' / '.$trackOfInterest,
  194. 'message' => 'succ',
  195. ];
  196. \Log::info($id.': '.print_r($res, true));
  197. $returnData[] = $res;
  198. // } catch (\Throwable $exception) {
  199. // $message = [
  200. // 'msg' => $exception->getMessage(),
  201. // 'line' => $exception->getLine(),
  202. // 'file' => $exception->getFile()
  203. // ];
  204. // // 返回
  205. // $res = [
  206. // 'id' => $id,
  207. // 'value' => $id.' / '.$firstName_orig.' / '.$lastName_orig.' / '.$companyName_orig.' / '.$companyEmail_orig.' / '.
  208. // $backupEmail_orig.' / '.$phoneNumber_orig.' / '.$country.' / '.$trackNo.' / '.$lang.' / '.$registeredSession.' / '.
  209. // $lunchOptions.' / '.$typeOfIndustry.' / '.$typeOfJob.' / '.$jobTitle.' / '.$trackOfInterest,
  210. // 'message' => $message,
  211. // ];
  212. // $returnData[] = $res;
  213. // $log = json_encode($res, JSON_UNESCAPED_UNICODE);
  214. // \Log::info(print_r($log, true));
  215. // }
  216. }
  217. return $returnData;
  218. }
  219. public function getData()
  220. {
  221. $list = $this->seminarSignUpSv->getData();
  222. $data = [
  223. 'list' => $list
  224. ];
  225. return $this->apiResponse($data);
  226. }
  227. /**
  228. * 參數加解密模組: 加密部分,建議使用環境變數中的 secret key 作加解密種子
  229. */
  230. public function safeEncrypt(string $message, string $skey): string
  231. {
  232. $strArr = str_split(base64_encode($message));
  233. $strCount = count($strArr);
  234. foreach (str_split($skey) as $key => $value)
  235. $key < $strCount && $strArr[$key].=$value;
  236. return str_replace(array('=', ' ', '/'), array('O0O0O', 'o000o', 'oo00o'), join('', $strArr));
  237. }
  238. /**
  239. * 參數加解密模組: 解密部分,建議使用環境變數中的 secret key 作加解密種子
  240. */
  241. public function safeDecrypt(string $encrypted, string $skey): string
  242. {
  243. $strArr = str_split(str_replace(array('O0O0O', 'o000o', 'oo00o'), array('=', ' ', '/'), $encrypted), 2);
  244. $strCount = count($strArr);
  245. foreach (str_split($skey) as $key => $value)
  246. $key <= $strCount && isset($strArr[$key]) && $strArr[$key][1] === $value && $strArr[$key] = $strArr[$key][0];
  247. return base64_decode(join('', $strArr));
  248. }
  249. public function mailToUser_TW(
  250. string $firstName='',
  251. string $lastName='',
  252. string $companyName='',
  253. string $companyEmail='',
  254. string $backupEmail='',
  255. string $phoneNumber='',
  256. string $country='',
  257. string $registeredSession='',
  258. string $lunchOptions='',
  259. string $typeOfIndustry='',
  260. string $typeOfJob='',
  261. string $jobTitle='',
  262. string $trackOfInterest=''
  263. )
  264. {
  265. $data = array(
  266. 'firstName' => $firstName,
  267. 'lastName' => $lastName,
  268. 'companyName' => $companyName,
  269. 'companyEmail' => $companyEmail,
  270. 'backupEmail' => $backupEmail,
  271. 'phoneNumber' => $phoneNumber,
  272. 'country' => $country,
  273. 'registeredSession' => $registeredSession,
  274. 'lunchOptions' => $lunchOptions,
  275. 'typeOfIndustry' => $typeOfIndustry,
  276. 'typeOfJob' => $typeOfJob,
  277. 'jobTitle' => $jobTitle,
  278. 'trackOfInterest' => $trackOfInterest,
  279. );
  280. if (strlen($backupEmail)>0) {
  281. \Mail::send(['text'=>'mailTW'], $data, function($message) use ($firstName, $companyEmail, $backupEmail) {
  282. $message->to($companyEmail, $firstName)->subject('報名成功-Arm Tech Symposia 2022');
  283. $message->cc($backupEmail, $firstName)->subject('報名成功-Arm Tech Symposia 2022');
  284. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  285. });
  286. } else {
  287. \Mail::send(['text'=>'mailTW'], $data, function($message) use ($companyEmail, $firstName) {
  288. $message->to($companyEmail, $firstName)->subject('報名成功-Arm Tech Symposia 2022');
  289. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  290. });
  291. }
  292. }
  293. public function mailToUser_JP(
  294. string $firstName='',
  295. string $lastName='',
  296. string $companyName='',
  297. string $companyEmail='',
  298. string $backupEmail='',
  299. string $phoneNumber='',
  300. string $country='',
  301. // string $registeredSession='',
  302. // string $lunchOptions='',
  303. string $typeOfIndustry='',
  304. string $typeOfJob='',
  305. string $jobTitle='',
  306. string $trackOfInterest=''
  307. )
  308. {
  309. $data = array(
  310. 'firstName' => $firstName,
  311. 'lastName' => $lastName,
  312. 'companyName' => $companyName,
  313. 'companyEmail' => $companyEmail,
  314. 'backupEmail' => $backupEmail,
  315. 'phoneNumber' => $phoneNumber,
  316. 'country' => $country,
  317. // 'registeredSession' => $registeredSession,
  318. // 'lunchOptions' => $lunchOptions,
  319. 'typeOfIndustry' => $typeOfIndustry,
  320. 'typeOfJob' => $typeOfJob,
  321. 'jobTitle' => $jobTitle,
  322. 'trackOfInterest' => $trackOfInterest,
  323. );
  324. if ($backupEmail) {
  325. \Mail::send(['text'=>'mailJP'], $data, function($message) use ($companyEmail, $firstName, $backupEmail) {
  326. $message->to($companyEmail, $firstName)->subject('Arm Tech Symposia 仮登録完了のお知らせ');
  327. $message->cc($backupEmail, $firstName)->subject('Arm Tech Symposia 仮登録完了のお知らせ');
  328. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  329. });
  330. } else {
  331. \Mail::send(['text'=>'mailJP'], $data, function($message) use ($companyEmail, $firstName) {
  332. $message->to($companyEmail, $firstName)->subject('Arm Tech Symposia 仮登録完了のお知らせ');
  333. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  334. });
  335. }
  336. }
  337. public function mailToUser_KR(
  338. string $firstName='',
  339. string $lastName='',
  340. string $companyName='',
  341. string $companyEmail='',
  342. string $backupEmail='',
  343. string $phoneNumber='',
  344. string $country='',
  345. // string $registeredSession='',
  346. // string $lunchOptions='',
  347. string $typeOfIndustry='',
  348. string $typeOfJob='',
  349. string $jobTitle='',
  350. string $trackOfInterest=''
  351. )
  352. {
  353. $data = array(
  354. 'firstName' => $firstName,
  355. 'lastName' => $lastName,
  356. 'companyName' => $companyName,
  357. 'companyEmail' => $companyEmail,
  358. 'backupEmail' => $backupEmail,
  359. 'phoneNumber' => $phoneNumber,
  360. 'country' => $country,
  361. // 'registeredSession' => $registeredSession,
  362. // 'lunchOptions' => $lunchOptions,
  363. 'typeOfIndustry' => $typeOfIndustry,
  364. 'typeOfJob' => $typeOfJob,
  365. 'jobTitle' => $jobTitle,
  366. 'trackOfInterest' => $trackOfInterest,
  367. );
  368. if ($backupEmail) {
  369. \Mail::send(['text'=>'mailKR'], $data, function($message) use ($companyEmail, $firstName, $backupEmail) {
  370. $message->to($companyEmail, $firstName)->subject('등록 확인 메일');
  371. $message->cc($backupEmail, $firstName)->subject('등록 확인 메일');
  372. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  373. });
  374. } else {
  375. \Mail::send(['text'=>'mailKR'], $data, function($message) use ($companyEmail, $firstName) {
  376. $message->to($companyEmail, $firstName)->subject('등록 확인 메일');
  377. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  378. });
  379. }
  380. }
  381. public function mailToUser_EN(string $firstName='', string $companyEmail='', string $backupEmail='')
  382. {
  383. $data = array('name'=>$firstName);
  384. if ($backupEmail) {
  385. \Mail::send(['text'=>'mailEN'], $data, function($message) use ($companyEmail, $firstName, $backupEmail) {
  386. $message->to($companyEmail, $firstName)->subject('Registration is complete');
  387. $message->cc($backupEmail, $firstName)->subject('Registration is complete');
  388. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  389. });
  390. } else {
  391. \Mail::send(['text'=>'mailEN'], $data, function($message) use ($companyEmail, $firstName) {
  392. $message->to($companyEmail, $firstName)->subject('Registration is complete');
  393. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  394. });
  395. }
  396. }
  397. }