SeminarSignUpController.php 11KB

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