SeminarSignUpController.php 19KB

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