SeminarSignUpController.php 20KB

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