SeminarSignUpController.php 17KB

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