Auth.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. $data['id'] = getStringId();
  63. $data['password'] = hash('md5',$data['password']);
  64. $data['source'] = $source;
  65. $data['imgurl'] = $upload_result->filepath;
  66. $data['createTime'] = date("Y-m-d H:i:s",time());
  67. $data['updateTime'] = date("Y-m-d H:i:s",time());
  68. $data['active'] = 1;
  69. $data['checkState'] = 1;
  70. \app\common\model\Enterprise::create($data);
  71. TalentChecklog::create([
  72. 'id' => getStringId(),
  73. 'mainId' => $data['id'],
  74. 'type' => 10,
  75. 'typeField' => null,
  76. 'active' => 1,
  77. 'state' => 1,
  78. 'step' => 100,
  79. 'stateChange' => '用户提交',
  80. 'description' => '用户注册',
  81. 'createTime' => date("Y-m-d H:i:s",time()),
  82. 'createUser' => '用户'
  83. ]);
  84. $response_object->code = 200;
  85. $response_object->msg = '注册成功';
  86. return \StrUtil::back($response_object,"Register.epCallBack");
  87. } catch (ValidateException $e){
  88. $error = $e->getError();
  89. $response_object->code = 500;
  90. $response_object->msg = array_pop($error);
  91. return \StrUtil::back($response_object,"Register.epCallBack");
  92. }
  93. }
  94. return view("", ["msg" => $msg]);
  95. }
  96. public function enterpriseRegister()
  97. {
  98. }
  99. public function verificationCode()
  100. {
  101. $phone = $this->request["phone"];
  102. $type = $this->request["type"];
  103. //校验手机号码是否为空
  104. if(\StrUtil::isEmpOrNull($phone)) {
  105. return json(["msg" => "请填写手机号码!"],500);
  106. }
  107. if (\StrUtil::isEmpOrNull($type)) {
  108. return json(["msg" => "请填写手机号码!"],500);
  109. }
  110. //校验手机号码格式是否正确
  111. if(\StrUtil::isMoblePhone($phone)) {
  112. return json(["msg" => "请填写正确的手机号码!"],500);
  113. }
  114. $record = Cache::get("verify_{$type}_{$phone}");
  115. if($record){
  116. $time = time();
  117. if($time - $record <= 60){
  118. return json(["msg" => "一分钟内请勿频繁发送短信!"],500);
  119. }
  120. }
  121. $code = '';
  122. for ($i = 1;$i <= 6;$i++){
  123. $code .= rand(0,9);
  124. }
  125. $template = "【晋江市人才服务平台】尊敬的用户,您的短信验证码为{$code},5分钟内有效。若非本人操作请忽略。";
  126. $smsapi = new ChuanglanSmsApi();
  127. $result = $smsapi->sendSMS($phone,$template);
  128. $result = json_decode($result,true);
  129. $id = getStringId();
  130. $record_data = [
  131. 'id' => $id,
  132. 'bizId' => $id,
  133. 'type' => 2,
  134. 'smsType' => 1,
  135. 'phone' => $phone,
  136. 'params' => $code,
  137. 'templateCode' => $template,
  138. 'state' => $result['code'] == 0 ? 2 : 3,
  139. 'sendingDate' => date("Y-m-d H:i:s",time()),
  140. 'createTime' => date("Y-m-d H:i:s",time()),
  141. 'msg' => $result['errorMsg']
  142. ];
  143. MessageRecord::create($record_data);
  144. if($result['code'] == 0){
  145. Cache::set("verify_{$type}_{$phone}",time());
  146. return json(["msg" => '验证码发送成功'],200);
  147. }else{
  148. return json(["msg" => '验证码发送失败'],500);
  149. }
  150. }
  151. }