SeminarSignUpController.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. $overOrNot = $this->seminarSignUpSv->overLimitOrNot($trackNo); // true: 可報名 / false: 已額滿
  48. $duplicatedOrNot = $this->seminarSignUpSv->duplicatedOrNot($trackNo, $companyEmail, $phoneNumber); // true: 可報名 / false: 已重複
  49. if ($overOrNot&&$duplicatedOrNot) {
  50. $this->seminarSignUpSv->insertData(
  51. $firstName,
  52. $lastName,
  53. $companyName,
  54. $companyEmail,
  55. $backupEmail,
  56. $phoneNumber,
  57. $country,
  58. $trackNo,
  59. $registeredSession,
  60. $lunchOptions,
  61. $typeOfIndustry,
  62. $typeOfJob,
  63. $jobTitle,
  64. $trackOfInterest,
  65. $areaOfInterest,
  66. $howToKnowAboutTheEvent,
  67. $consentAcceptEmail,
  68. $consentPrivacyPolicy,
  69. );
  70. $res = '報名成功';
  71. if ($lang=='TP'||$lang=='HS') {
  72. $this->mailToUser_TW($firstName_orig, $lastName_orig, $companyName_orig, $companyEmail_orig, $backupEmail_orig,
  73. $phoneNumber_orig, $country, $registeredSession, $lunchOptions, $typeOfIndustry, $typeOfJob, $jobTitle, $trackOfInterest);
  74. } elseif ($lang=='JP') {
  75. $this->mailToUser_JP($firstName_orig, $lastName_orig, $companyName_orig, $companyEmail_orig, $backupEmail_orig,
  76. $phoneNumber_orig, $country, /*$registeredSession, $lunchOptions, */$typeOfIndustry, $typeOfJob, $jobTitle, $trackOfInterest);
  77. } elseif ($lang=='KR') {
  78. $this->mailToUser_KR($firstName_orig, $lastName_orig, $companyName_orig, $companyEmail_orig, $backupEmail_orig,
  79. $phoneNumber_orig, $country, /*$registeredSession, $lunchOptions, */$typeOfIndustry, $typeOfJob, $jobTitle, $trackOfInterest);
  80. } else {
  81. $this->mailToUser_EN($firstName_orig, $companyEmail_orig, $backupEmail_orig);
  82. }
  83. } elseif (!$overOrNot) {
  84. $res = '已達報名上限';
  85. } elseif (!$duplicatedOrNot) {
  86. $res = '已重複報名';
  87. }
  88. $data = [
  89. 'res' => $res,
  90. ];
  91. return $this->apiResponse($data);
  92. }
  93. public function getData()
  94. {
  95. $list = $this->seminarSignUpSv->getData();
  96. $data = [
  97. 'list' => $list
  98. ];
  99. return $this->apiResponse($data);
  100. }
  101. /**
  102. * 參數加解密模組: 加密部分,建議使用環境變數中的 secret key 作加解密種子
  103. */
  104. public function safeEncrypt(string $message, string $skey): string
  105. {
  106. $strArr = str_split(base64_encode($message));
  107. $strCount = count($strArr);
  108. foreach (str_split($skey) as $key => $value)
  109. $key < $strCount && $strArr[$key].=$value;
  110. return str_replace(array('=', ' ', '/'), array('O0O0O', 'o000o', 'oo00o'), join('', $strArr));
  111. }
  112. /**
  113. * 參數加解密模組: 解密部分,建議使用環境變數中的 secret key 作加解密種子
  114. */
  115. public function safeDecrypt(string $encrypted, string $skey): string
  116. {
  117. $strArr = str_split(str_replace(array('O0O0O', 'o000o', 'oo00o'), array('=', ' ', '/'), $encrypted), 2);
  118. $strCount = count($strArr);
  119. foreach (str_split($skey) as $key => $value)
  120. $key <= $strCount && isset($strArr[$key]) && $strArr[$key][1] === $value && $strArr[$key] = $strArr[$key][0];
  121. return base64_decode(join('', $strArr));
  122. }
  123. public function mailToUser_TW(
  124. string $firstName='',
  125. string $lastName='',
  126. string $companyName='',
  127. string $companyEmail='',
  128. string $backupEmail='',
  129. string $phoneNumber='',
  130. string $country='',
  131. string $registeredSession='',
  132. string $lunchOptions='',
  133. string $typeOfIndustry='',
  134. string $typeOfJob='',
  135. string $jobTitle='',
  136. string $trackOfInterest=''
  137. )
  138. {
  139. $data = array(
  140. 'firstName' => $firstName,
  141. 'lastName' => $lastName,
  142. 'companyName' => $companyName,
  143. 'companyEmail' => $companyEmail,
  144. 'backupEmail' => $backupEmail,
  145. 'phoneNumber' => $phoneNumber,
  146. 'country' => $country,
  147. 'registeredSession' => $registeredSession,
  148. 'lunchOptions' => $lunchOptions,
  149. 'typeOfIndustry' => $typeOfIndustry,
  150. 'typeOfJob' => $typeOfJob,
  151. 'jobTitle' => $jobTitle,
  152. 'trackOfInterest' => $trackOfInterest,
  153. );
  154. if (strlen($backupEmail)>0) {
  155. \Mail::send(['text'=>'mailTW'], $data, function($message) use ($firstName, $companyEmail, $backupEmail) {
  156. $message->to($companyEmail, $firstName)->subject('報名成功');
  157. $message->cc($backupEmail, $firstName)->subject('報名成功');
  158. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  159. });
  160. } else {
  161. \Mail::send(['text'=>'mailTW'], $data, function($message) use ($companyEmail, $firstName) {
  162. $message->to($companyEmail, $firstName)->subject('報名成功');
  163. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  164. });
  165. }
  166. }
  167. public function mailToUser_JP(
  168. string $firstName='',
  169. string $lastName='',
  170. string $companyName='',
  171. string $companyEmail='',
  172. string $backupEmail='',
  173. string $phoneNumber='',
  174. string $country='',
  175. // string $registeredSession='',
  176. // string $lunchOptions='',
  177. string $typeOfIndustry='',
  178. string $typeOfJob='',
  179. string $jobTitle='',
  180. string $trackOfInterest=''
  181. )
  182. {
  183. $data = array(
  184. 'firstName' => $firstName,
  185. 'lastName' => $lastName,
  186. 'companyName' => $companyName,
  187. 'companyEmail' => $companyEmail,
  188. 'backupEmail' => $backupEmail,
  189. 'phoneNumber' => $phoneNumber,
  190. 'country' => $country,
  191. 'registeredSession' => $registeredSession,
  192. 'lunchOptions' => $lunchOptions,
  193. 'typeOfIndustry' => $typeOfIndustry,
  194. 'typeOfJob' => $typeOfJob,
  195. 'jobTitle' => $jobTitle,
  196. 'trackOfInterest' => $trackOfInterest,
  197. );
  198. if ($backupEmail) {
  199. \Mail::send(['text'=>'mailJP'], $data, function($message) use ($companyEmail, $firstName, $backupEmail) {
  200. $message->to($companyEmail, $firstName)->subject('Arm Tech Symposia 仮登録完了のお知らせ');
  201. $message->cc($backupEmail, $firstName)->subject('Arm Tech Symposia 仮登録完了のお知らせ');
  202. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  203. });
  204. } else {
  205. \Mail::send(['text'=>'mailJP'], $data, function($message) use ($companyEmail, $firstName) {
  206. $message->to($companyEmail, $firstName)->subject('Arm Tech Symposia 仮登録完了のお知らせ');
  207. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  208. });
  209. }
  210. }
  211. public function mailToUser_KR(
  212. string $firstName='',
  213. string $lastName='',
  214. string $companyName='',
  215. string $companyEmail='',
  216. string $backupEmail='',
  217. string $phoneNumber='',
  218. string $country='',
  219. // string $registeredSession='',
  220. // string $lunchOptions='',
  221. string $typeOfIndustry='',
  222. string $typeOfJob='',
  223. string $jobTitle='',
  224. string $trackOfInterest=''
  225. )
  226. {
  227. $data = array(
  228. 'firstName' => $firstName,
  229. 'lastName' => $lastName,
  230. 'companyName' => $companyName,
  231. 'companyEmail' => $companyEmail,
  232. 'backupEmail' => $backupEmail,
  233. 'phoneNumber' => $phoneNumber,
  234. 'country' => $country,
  235. // 'registeredSession' => $registeredSession,
  236. // 'lunchOptions' => $lunchOptions,
  237. 'typeOfIndustry' => $typeOfIndustry,
  238. 'typeOfJob' => $typeOfJob,
  239. 'jobTitle' => $jobTitle,
  240. 'trackOfInterest' => $trackOfInterest,
  241. );
  242. if ($backupEmail) {
  243. \Mail::send(['text'=>'mailKR'], $data, function($message) use ($companyEmail, $firstName, $backupEmail) {
  244. $message->to($companyEmail, $firstName)->subject('등록 확인 메일');
  245. $message->cc($backupEmail, $firstName)->subject('등록 확인 메일');
  246. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  247. });
  248. } else {
  249. \Mail::send(['text'=>'mailKR'], $data, function($message) use ($companyEmail, $firstName) {
  250. $message->to($companyEmail, $firstName)->subject('등록 확인 메일');
  251. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  252. });
  253. }
  254. }
  255. public function mailToUser_EN(string $firstName='', string $companyEmail='', string $backupEmail='')
  256. {
  257. $data = array('name'=>$firstName);
  258. if ($backupEmail) {
  259. \Mail::send(['text'=>'mailEN'], $data, function($message) use ($companyEmail, $firstName, $backupEmail) {
  260. $message->to($companyEmail, $firstName)->subject('Registration is complete');
  261. $message->cc($backupEmail, $firstName)->subject('Registration is complete');
  262. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  263. });
  264. } else {
  265. \Mail::send(['text'=>'mailEN'], $data, function($message) use ($companyEmail, $firstName) {
  266. $message->to($companyEmail, $firstName)->subject('Registration is complete');
  267. $message->from(env('MAIL_USERNAME'),env('MAIL_FROM_NAME'));
  268. });
  269. }
  270. }
  271. }