SeminarSignUpController.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. public function getData()
  96. {
  97. $list = $this->seminarSignUpSv->getData();
  98. $data = [
  99. 'list' => $list
  100. ];
  101. return $this->apiResponse($data);
  102. }
  103. /**
  104. * 參數加解密模組: 加密部分,建議使用環境變數中的 secret key 作加解密種子
  105. */
  106. public function safeEncrypt(string $message, string $skey): string
  107. {
  108. $strArr = str_split(base64_encode($message));
  109. $strCount = count($strArr);
  110. foreach (str_split($skey) as $key => $value)
  111. $key < $strCount && $strArr[$key].=$value;
  112. return str_replace(array('=', ' ', '/'), array('O0O0O', 'o000o', 'oo00o'), join('', $strArr));
  113. }
  114. /**
  115. * 參數加解密模組: 解密部分,建議使用環境變數中的 secret key 作加解密種子
  116. */
  117. public function safeDecrypt(string $encrypted, string $skey): string
  118. {
  119. $strArr = str_split(str_replace(array('O0O0O', 'o000o', 'oo00o'), array('=', ' ', '/'), $encrypted), 2);
  120. $strCount = count($strArr);
  121. foreach (str_split($skey) as $key => $value)
  122. $key <= $strCount && isset($strArr[$key]) && $strArr[$key][1] === $value && $strArr[$key] = $strArr[$key][0];
  123. return base64_decode(join('', $strArr));
  124. }
  125. public function mailToUser_TW(
  126. string $firstName='',
  127. string $lastName='',
  128. string $companyName='',
  129. string $companyEmail='',
  130. string $backupEmail='',
  131. string $phoneNumber='',
  132. string $country='',
  133. string $registeredSession='',
  134. string $lunchOptions='',
  135. string $typeOfIndustry='',
  136. string $typeOfJob='',
  137. string $jobTitle='',
  138. string $trackOfInterest=''
  139. )
  140. {
  141. $data = array(
  142. 'firstName' => $firstName,
  143. 'lastName' => $lastName,
  144. 'companyName' => $companyName,
  145. 'companyEmail' => $companyEmail,
  146. 'backupEmail' => $backupEmail,
  147. 'phoneNumber' => $phoneNumber,
  148. 'country' => $country,
  149. 'registeredSession' => $registeredSession,
  150. 'lunchOptions' => $lunchOptions,
  151. 'typeOfIndustry' => $typeOfIndustry,
  152. 'typeOfJob' => $typeOfJob,
  153. 'jobTitle' => $jobTitle,
  154. 'trackOfInterest' => $trackOfInterest,
  155. );
  156. if (strlen($backupEmail)>0) {
  157. \Mail::send(['text'=>'mailTW'], $data, function($message) use ($firstName, $companyEmail, $backupEmail) {
  158. $message->to($companyEmail, $firstName)->subject('報名成功-Arm Tech Symposia 2022');
  159. $message->cc($backupEmail, $firstName)->subject('報名成功-Arm Tech Symposia 2022');
  160. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  161. });
  162. } else {
  163. \Mail::send(['text'=>'mailTW'], $data, function($message) use ($companyEmail, $firstName) {
  164. $message->to($companyEmail, $firstName)->subject('報名成功-Arm Tech Symposia 2022');
  165. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  166. });
  167. }
  168. }
  169. public function mailToUser_JP(
  170. string $firstName='',
  171. string $lastName='',
  172. string $companyName='',
  173. string $companyEmail='',
  174. string $backupEmail='',
  175. string $phoneNumber='',
  176. string $country='',
  177. // string $registeredSession='',
  178. // string $lunchOptions='',
  179. string $typeOfIndustry='',
  180. string $typeOfJob='',
  181. string $jobTitle='',
  182. string $trackOfInterest=''
  183. )
  184. {
  185. $data = array(
  186. 'firstName' => $firstName,
  187. 'lastName' => $lastName,
  188. 'companyName' => $companyName,
  189. 'companyEmail' => $companyEmail,
  190. 'backupEmail' => $backupEmail,
  191. 'phoneNumber' => $phoneNumber,
  192. 'country' => $country,
  193. // 'registeredSession' => $registeredSession,
  194. // 'lunchOptions' => $lunchOptions,
  195. 'typeOfIndustry' => $typeOfIndustry,
  196. 'typeOfJob' => $typeOfJob,
  197. 'jobTitle' => $jobTitle,
  198. 'trackOfInterest' => $trackOfInterest,
  199. );
  200. if ($backupEmail) {
  201. \Mail::send(['text'=>'mailJP'], $data, function($message) use ($companyEmail, $firstName, $backupEmail) {
  202. $message->to($companyEmail, $firstName)->subject('Arm Tech Symposia 仮登録完了のお知らせ');
  203. $message->cc($backupEmail, $firstName)->subject('Arm Tech Symposia 仮登録完了のお知らせ');
  204. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  205. });
  206. } else {
  207. \Mail::send(['text'=>'mailJP'], $data, function($message) use ($companyEmail, $firstName) {
  208. $message->to($companyEmail, $firstName)->subject('Arm Tech Symposia 仮登録完了のお知らせ');
  209. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  210. });
  211. }
  212. }
  213. public function mailToUser_KR(
  214. string $firstName='',
  215. string $lastName='',
  216. string $companyName='',
  217. string $companyEmail='',
  218. string $backupEmail='',
  219. string $phoneNumber='',
  220. string $country='',
  221. // string $registeredSession='',
  222. // string $lunchOptions='',
  223. string $typeOfIndustry='',
  224. string $typeOfJob='',
  225. string $jobTitle='',
  226. string $trackOfInterest=''
  227. )
  228. {
  229. $data = array(
  230. 'firstName' => $firstName,
  231. 'lastName' => $lastName,
  232. 'companyName' => $companyName,
  233. 'companyEmail' => $companyEmail,
  234. 'backupEmail' => $backupEmail,
  235. 'phoneNumber' => $phoneNumber,
  236. 'country' => $country,
  237. // 'registeredSession' => $registeredSession,
  238. // 'lunchOptions' => $lunchOptions,
  239. 'typeOfIndustry' => $typeOfIndustry,
  240. 'typeOfJob' => $typeOfJob,
  241. 'jobTitle' => $jobTitle,
  242. 'trackOfInterest' => $trackOfInterest,
  243. );
  244. if ($backupEmail) {
  245. \Mail::send(['text'=>'mailKR'], $data, function($message) use ($companyEmail, $firstName, $backupEmail) {
  246. $message->to($companyEmail, $firstName)->subject('등록 확인 메일');
  247. $message->cc($backupEmail, $firstName)->subject('등록 확인 메일');
  248. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  249. });
  250. } else {
  251. \Mail::send(['text'=>'mailKR'], $data, function($message) use ($companyEmail, $firstName) {
  252. $message->to($companyEmail, $firstName)->subject('등록 확인 메일');
  253. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  254. });
  255. }
  256. }
  257. public function mailToUser_EN(string $firstName='', string $companyEmail='', string $backupEmail='')
  258. {
  259. $data = array('name'=>$firstName);
  260. if ($backupEmail) {
  261. \Mail::send(['text'=>'mailEN'], $data, function($message) use ($companyEmail, $firstName, $backupEmail) {
  262. $message->to($companyEmail, $firstName)->subject('Registration is complete');
  263. $message->cc($backupEmail, $firstName)->subject('Registration is complete');
  264. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  265. });
  266. } else {
  267. \Mail::send(['text'=>'mailEN'], $data, function($message) use ($companyEmail, $firstName) {
  268. $message->to($companyEmail, $firstName)->subject('Registration is complete');
  269. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  270. });
  271. }
  272. }
  273. }