SeminarSignUpController.php 17KB

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