SeminarSignUpController.php 17KB

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