Auth.php 8.8 KB

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