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