Auth.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. namespace app\common\controller;
  3. use app\BaseController;
  4. use app\common\api\ChuanglanSmsApi;
  5. use app\common\model\MessageRecord;
  6. use app\common\model\TalentChecklog;
  7. use think\facade\Cache;
  8. use app\common\validate\Enterprise;
  9. use think\exception\ValidateException;
  10. use think\facade\Request;
  11. use app\common\api\UploadApi;
  12. class Auth extends BaseController
  13. {
  14. public function register(){
  15. $msg = "";
  16. if($this->request->isPost()){
  17. $source = intval($this->request['source']);
  18. $response_object = new \StdClass();
  19. $data = [
  20. 'username' => \StrUtil::getRequestDecodeParam($this->request,'username'),
  21. 'password' => \StrUtil::getRequestDecodeParam($this->request,'password'),
  22. 're_password' => \StrUtil::getRequestDecodeParam($this->request,'re_password'),
  23. 'name' => \StrUtil::getRequestDecodeParam($this->request,'name'),
  24. 'idCard' => \StrUtil::getRequestDecodeParam($this->request,'idCard'),
  25. 'agentName' => \StrUtil::getRequestDecodeParam($this->request,'agentName'),
  26. 'agentPhone' => \StrUtil::getRequestDecodeParam($this->request,'agentPhone'),
  27. 'verificationCode' => \StrUtil::getRequestDecodeParam($this->request,'verificationCode'),
  28. 'legal' => \StrUtil::getRequestDecodeParam($this->request,'legal'),
  29. 'street' => \StrUtil::getRequestDecodeParam($this->request,'street'),
  30. 'address' => \StrUtil::getRequestDecodeParam($this->request,'address'),
  31. 'type' => intval($this->request['type']),
  32. 'enterpriseTag' => \StrUtil::getRequestDecodeParam($this->request,'enterpriseTag'),
  33. 'enterpriseType' => \StrUtil::getRequestDecodeParam($this->request,'enterpriseType'),
  34. 'agentEmail' => \StrUtil::getRequestDecodeParam($this->request,'agentEmail'),
  35. 'ephone' => \StrUtil::getRequestDecodeParam($this->request,'ephone'),
  36. 'industryFieldNew' => \StrUtil::getRequestDecodeParam($this->request,'industryFieldNew'),
  37. 'industryFieldOld' => \StrUtil::getRequestDecodeParam($this->request,'industryFieldOld'),
  38. 'bankCard' => \StrUtil::getRequestDecodeParam($this->request,'bankCard'),
  39. 'bank' => \StrUtil::getRequestDecodeParam($this->request,'bank'),
  40. 'bankNetwork' => \StrUtil::getRequestDecodeParam($this->request,'bankNetwork')
  41. ];
  42. try {
  43. $result = validate(Enterprise::class)->batch(true)->scene('add')->check($data);
  44. //检验验证码
  45. $codeResult = MessageRecord::where('smsType',1)->where('phone',$data['agentPhone'])->find();
  46. if(!$codeResult){
  47. $response_object->code = 500;
  48. $response_object->msg = '请先发送验证码';
  49. return \StrUtil::back($response_object,"Register.epCallBack");
  50. }
  51. if(time() - strtotime($codeResult['createTime']) > 300){
  52. $response_object->code = 500;
  53. $response_object->msg = '验证码过期,请重新发送';
  54. return \StrUtil::back($response_object,"Register.epCallBack");
  55. }
  56. //检验附件 营业执照
  57. $uploadapi = new UploadApi();
  58. $upload_result = $uploadapi->uploadOne($this->request->file('imgurl'),'image');
  59. if($upload_result->code == 500){
  60. return \StrUtil::back($upload_result,"Register.epCallBack");
  61. }
  62. //检验附件 开户许可证
  63. $upload_result1 = $uploadapi->uploadOne($this->request->file('bankImg'),'image');
  64. if($upload_result->code == 500){
  65. return \StrUtil::back($upload_result1,"Register.epCallBack");
  66. }
  67. //检验附件 行业领域佐证材料
  68. if($this->request->file('domainImg')){
  69. $upload_result2 = $uploadapi->uploadOne($this->request->file('domainImg'),'image');
  70. if($upload_result2->code == 500){
  71. return \StrUtil::back($upload_result2,"Register.epCallBack");
  72. }
  73. $domainImg = $upload_result2->filepath;
  74. }else{
  75. $domainImg = '';
  76. }
  77. //检验附件 人才联络员备案表
  78. $upload_result3 = $uploadapi->uploadOne($this->request->file('beian'),'system');
  79. if($upload_result->code == 500){
  80. return \StrUtil::back($upload_result3,"Register.epCallBack");
  81. }
  82. $data['id'] = getStringId();
  83. $data['password'] = hash('md5',$data['password']);
  84. $data['source'] = $source;
  85. $data['imgurl'] = $upload_result->filepath;
  86. $data['bankImg'] = $upload_result1->filepath;
  87. $data['domainImg'] = $domainImg;
  88. $data['beian'] = $upload_result3->filepath;
  89. $data['createTime'] = date("Y-m-d H:i:s",time());
  90. $data['updateTime'] = date("Y-m-d H:i:s",time());
  91. $data['active'] = 1;
  92. $data['checkState'] = 1;
  93. \app\common\model\Enterprise::create($data);
  94. TalentChecklog::create([
  95. 'id' => getStringId(),
  96. 'mainId' => $data['id'],
  97. 'type' => 10,
  98. 'typeField' => null,
  99. 'active' => 1,
  100. 'state' => 1,
  101. 'step' => 100,
  102. 'stateChange' => '用户提交',
  103. 'description' => '用户注册',
  104. 'createTime' => date("Y-m-d H:i:s",time()),
  105. 'createUser' => '用户'
  106. ]);
  107. $response_object->code = 200;
  108. $response_object->msg = '注册成功';
  109. return \StrUtil::back($response_object,"Register.epCallBack");
  110. } catch (ValidateException $e){
  111. $error = $e->getError();
  112. $response_object->code = 500;
  113. $response_object->msg = array_pop($error);
  114. return \StrUtil::back($response_object,"Register.epCallBack");
  115. }
  116. }
  117. return view("", ["msg" => $msg]);
  118. }
  119. public function enterpriseRegister()
  120. {
  121. }
  122. public function verificationCode()
  123. {
  124. $phone = $this->request["phone"];
  125. $type = $this->request["type"];
  126. //校验手机号码是否为空
  127. if(\StrUtil::isEmpOrNull($phone)) {
  128. return json(["msg" => "请填写手机号码!"],500);
  129. }
  130. if (\StrUtil::isEmpOrNull($type)) {
  131. return json(["msg" => "请填写手机号码!"],500);
  132. }
  133. //校验手机号码格式是否正确
  134. if(\StrUtil::isMoblePhone($phone)) {
  135. return json(["msg" => "请填写正确的手机号码!"],500);
  136. }
  137. $record = Cache::get("verify_{$type}_{$phone}");
  138. if($record){
  139. $time = time();
  140. if($time - $record <= 60){
  141. return json(["msg" => "一分钟内请勿频繁发送短信!"],500);
  142. }
  143. }
  144. $code = '';
  145. for ($i = 1;$i <= 6;$i++){
  146. $code .= rand(0,9);
  147. }
  148. $code = 999999;
  149. $template = "【晋江市人才服务平台】尊敬的用户,您的短信验证码为{$code},5分钟内有效。若非本人操作请忽略。";
  150. $smsapi = new ChuanglanSmsApi();
  151. //$result = $smsapi->sendSMS($phone,$template);
  152. //测试
  153. $result = [
  154. 'code' => 0,
  155. 'errorMsg' => ''
  156. ];
  157. //$result = json_decode($result,true);
  158. $id = getStringId();
  159. $record_data = [
  160. 'id' => $id,
  161. 'bizId' => $id,
  162. 'type' => 2,
  163. 'smsType' => 1,
  164. 'phone' => $phone,
  165. 'params' => $code,
  166. 'templateCode' => $template,
  167. 'state' => $result['code'] == 0 ? 2 : 3,
  168. 'sendingDate' => date("Y-m-d H:i:s",time()),
  169. 'createTime' => date("Y-m-d H:i:s",time()),
  170. 'msg' => $result['errorMsg']
  171. ];
  172. MessageRecord::create($record_data);
  173. if($result['code'] == 0){
  174. Cache::set("verify_{$type}_{$phone}",time());
  175. return json(["msg" => '验证码发送成功'],200);
  176. }else{
  177. return json(["msg" => '验证码发送失败'],500);
  178. }
  179. }
  180. }