SeminarSignUpController.php 19KB

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