SeminarSignUpController.php 21KB

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