Auth.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. $special = \StrUtil::getRequestDecodeParam($this->request,'special');
  21. $data = [
  22. 'username' => \StrUtil::getRequestDecodeParam($this->request,'username'),
  23. 'password' => \StrUtil::getRequestDecodeParam($this->request,'password'),
  24. 're_password' => \StrUtil::getRequestDecodeParam($this->request,'re_password'),
  25. 'name' => \StrUtil::getRequestDecodeParam($this->request,'name'),
  26. 'idCard' => \StrUtil::getRequestDecodeParam($this->request,'idCard'),
  27. 'agentName' => \StrUtil::getRequestDecodeParam($this->request,'agentName'),
  28. 'agentPhone' => \StrUtil::getRequestDecodeParam($this->request,'agentPhone'),
  29. 'verificationCode' => \StrUtil::getRequestDecodeParam($this->request,'verificationCode'),
  30. 'legal' => \StrUtil::getRequestDecodeParam($this->request,'legal'),
  31. 'street' => \StrUtil::getRequestDecodeParam($this->request,'street'),
  32. 'address' => \StrUtil::getRequestDecodeParam($this->request,'address'),
  33. 'type' => intval($this->request['type']),
  34. 'enterpriseTag' => \StrUtil::getRequestDecodeParam($this->request,'enterpriseTag'),
  35. 'enterpriseType' => \StrUtil::getRequestDecodeParam($this->request,'enterpriseType'),
  36. 'agentEmail' => \StrUtil::getRequestDecodeParam($this->request,'agentEmail'),
  37. 'ephone' => \StrUtil::getRequestDecodeParam($this->request,'ephone'),
  38. 'industryFieldNew' => \StrUtil::getRequestDecodeParam($this->request,'industryFieldNew'),
  39. 'industryFieldOld' => \StrUtil::getRequestDecodeParam($this->request,'industryFieldOld'),
  40. 'bankCard' => \StrUtil::getRequestDecodeParam($this->request,'bankCard'),
  41. 'bank' => \StrUtil::getRequestDecodeParam($this->request,'bank'),
  42. 'bankNetwork' => \StrUtil::getRequestDecodeParam($this->request,'bankNetwork')
  43. ];
  44. try {
  45. if($special == 'qiye'){
  46. validate(Enterprise::class)->batch(true)->scene('add')->check($data);
  47. $data['special'] = 0;
  48. }else{
  49. validate(Enterprise::class)->batch(true)->scene('sy_add')->check($data);
  50. $data['special'] = 1;
  51. }
  52. //检验验证码
  53. $codeResult = MessageRecord::where('smsType',1)->where('phone',$data['agentPhone'])->order('createTime','desc')->find();
  54. if(!$codeResult){
  55. $response_object->code = 500;
  56. $response_object->msg = '请先发送验证码';
  57. return \StrUtil::back($response_object,"Register.epCallBack");
  58. }
  59. if(time() - strtotime($codeResult['createTime']) > 300){
  60. $response_object->code = 500;
  61. $response_object->msg = '验证码过期,请重新发送';
  62. return \StrUtil::back($response_object,"Register.epCallBack");
  63. }
  64. $uploadapi = new UploadApi();
  65. $files = $this->request->file();
  66. //检验附件 营业执照
  67. if(array_key_exists('imgurl',$files)){
  68. $upload_result = $uploadapi->uploadOne($this->request->file('imgurl'),'image');
  69. if($upload_result->code == 500){
  70. return \StrUtil::back($upload_result,"Register.epCallBack");
  71. }
  72. $imgurl = $upload_result->filepath;
  73. }else{
  74. $imgurl = '';
  75. }
  76. //检验附件 开户许可证
  77. if(array_key_exists('bankImg',$files)){
  78. $upload_result1 = $uploadapi->uploadOne($this->request->file('bankImg'),'image');
  79. if($upload_result->code == 500){
  80. return \StrUtil::back($upload_result1,"Register.epCallBack");
  81. }
  82. $bankImg = $upload_result1->filepath;
  83. }else{
  84. $bankImg = '';
  85. }
  86. //检验附件 行业领域佐证材料
  87. if(array_key_exists('domainImg',$files)){
  88. $upload_result2 = $uploadapi->uploadOne($this->request->file('domainImg'),'image');
  89. if($upload_result2->code == 500){
  90. return \StrUtil::back($upload_result2,"Register.epCallBack");
  91. }
  92. $domainImg = $upload_result2->filepath;
  93. }else{
  94. $domainImg = '';
  95. }
  96. //检验附件 人才联络员备案表
  97. if(array_key_exists('beian',$files)){
  98. $upload_result3 = $uploadapi->uploadOne($this->request->file('beian'),'system');
  99. if($upload_result->code == 500){
  100. return \StrUtil::back($upload_result3,"Register.epCallBack");
  101. }
  102. $beian = $upload_result3->filepath;
  103. }else{
  104. $beian = '';
  105. }
  106. $data['id'] = getStringId();
  107. $data['password'] = hash('md5',$data['password']);
  108. $data['source'] = $source;
  109. $data['imgurl'] = $imgurl;
  110. $data['bankImg'] = $bankImg;
  111. $data['domainImg'] = $domainImg;
  112. $data['beian'] = $beian;
  113. $data['createTime'] = date("Y-m-d H:i:s",time());
  114. $data['updateTime'] = date("Y-m-d H:i:s",time());
  115. $data['active'] = 1;
  116. $data['checkState'] = 1;
  117. \app\common\model\Enterprise::create($data);
  118. TalentChecklog::create([
  119. 'id' => getStringId(),
  120. 'mainId' => $data['id'],
  121. 'type' => 10,
  122. 'typeField' => null,
  123. 'active' => 1,
  124. 'state' => 1,
  125. 'step' => 100,
  126. 'stateChange' => '用户提交',
  127. 'description' => '用户注册',
  128. 'createTime' => date("Y-m-d H:i:s",time()),
  129. 'createUser' => '用户'
  130. ]);
  131. $response_object->code = 200;
  132. $response_object->msg = '注册成功';
  133. return \StrUtil::back($response_object,"Register.epCallBack");
  134. } catch (ValidateException $e){
  135. $error = $e->getError();
  136. $response_object->code = 500;
  137. $response_object->msg = array_pop($error);
  138. return \StrUtil::back($response_object,"Register.epCallBack");
  139. }
  140. }
  141. return view("", ["msg" => $msg]);
  142. }
  143. public function enterprise_edit()
  144. {
  145. $temp = session('temp');
  146. if(empty($temp)){
  147. return redirect("/");
  148. }
  149. $ep = EnterpriseApi::getOne(session('temp')['uid']);
  150. if($this->request->isPost()){
  151. $response_object = new \StdClass();
  152. $data = [
  153. 'name' => \StrUtil::getRequestDecodeParam($this->request,'name'),//单位名称
  154. 'idCard' => \StrUtil::getRequestDecodeParam($this->request,'idCard'),//统一社会信用代码
  155. 'agentName' => \StrUtil::getRequestDecodeParam($this->request,'agentName'),//人才联络员
  156. 'legal' => \StrUtil::getRequestDecodeParam($this->request,'legal'),//法人
  157. 'street' => \StrUtil::getRequestDecodeParam($this->request,'street'),//镇街
  158. 'address' => \StrUtil::getRequestDecodeParam($this->request,'address'),//地址
  159. 'type' => intval($this->request['type']),
  160. 'enterpriseTag' => \StrUtil::getRequestDecodeParam($this->request,'enterpriseTag'),//单位标签
  161. 'enterpriseType' => \StrUtil::getRequestDecodeParam($this->request,'enterpriseType'),//单位类型
  162. 'agentEmail' => \StrUtil::getRequestDecodeParam($this->request,'agentEmail'),//邮箱
  163. 'ephone' => \StrUtil::getRequestDecodeParam($this->request,'ephone'),//单位电话
  164. 'industryFieldNew' => \StrUtil::getRequestDecodeParam($this->request,'industryFieldNew'),//产业领域
  165. 'industryFieldOld' => \StrUtil::getRequestDecodeParam($this->request,'industryFieldOld'),//行业领域
  166. 'bankCard' => \StrUtil::getRequestDecodeParam($this->request,'bankCard'),//银行
  167. 'bank' => \StrUtil::getRequestDecodeParam($this->request,'bank'),//开户行
  168. 'bankNetwork' => \StrUtil::getRequestDecodeParam($this->request,'bankNetwork')//网点
  169. ];
  170. try {
  171. $data['id'] = $ep->id;
  172. validate(\app\common\validate\Enterprise::class)->batch(true)->scene('check_common')->check($data);
  173. $data['checkState'] = 1;
  174. $ep->update($data);
  175. $response_object->code = 200;
  176. $response_object->msg = '修改成功';
  177. return \StrUtil::back($response_object,"Register.epCallBack");
  178. }catch (ValidateException $e){
  179. $error = $e->getError();
  180. $response_object->code = 500;
  181. $response_object->msg = array_pop($error);
  182. return \StrUtil::back($response_object,"Register.epCallBack");
  183. }
  184. }
  185. $msg = session('temp')['msg'];
  186. return view("",['msg' => $msg, 'ep' => $ep]);
  187. }
  188. public function verificationCode()
  189. {
  190. $phone = $this->request["phone"];
  191. $type = $this->request["type"];
  192. //校验手机号码是否为空
  193. if(\StrUtil::isEmpOrNull($phone)) {
  194. return json(["msg" => "请填写手机号码!"],500);
  195. }
  196. if (\StrUtil::isEmpOrNull($type)) {
  197. return json(["msg" => "请填写手机号码!"],500);
  198. }
  199. //校验手机号码格式是否正确
  200. if(\StrUtil::isMoblePhone($phone)) {
  201. return json(["msg" => "请填写正确的手机号码!"],500);
  202. }
  203. $record = Cache::get("verify_{$type}_{$phone}");
  204. if($record){
  205. $time = time();
  206. if($time - $record <= 60){
  207. return json(["msg" => "一分钟内请勿频繁发送短信!"],500);
  208. }
  209. }
  210. $code = '';
  211. for ($i = 1;$i <= 6;$i++){
  212. $code .= rand(0,9);
  213. }
  214. $code = 999999;
  215. $template = "【晋江市人才服务平台】尊敬的用户,您的短信验证码为{$code},5分钟内有效。若非本人操作请忽略。";
  216. $smsapi = new ChuanglanSmsApi();
  217. //$result = $smsapi->sendSMS($phone,$template);
  218. //测试
  219. $result = [
  220. 'code' => 0,
  221. 'errorMsg' => ''
  222. ];
  223. //$result = json_decode($result,true);
  224. $id = getStringId();
  225. $record_data = [
  226. 'id' => $id,
  227. 'bizId' => $id,
  228. 'type' => 2,
  229. 'smsType' => 1,
  230. 'phone' => $phone,
  231. 'params' => $code,
  232. 'templateCode' => $template,
  233. 'state' => $result['code'] == 0 ? 2 : 3,
  234. 'sendingDate' => date("Y-m-d H:i:s",time()),
  235. 'createTime' => date("Y-m-d H:i:s",time()),
  236. 'msg' => $result['errorMsg']
  237. ];
  238. MessageRecord::create($record_data);
  239. if($result['code'] == 0){
  240. Cache::set("verify_{$type}_{$phone}",time());
  241. return json(["msg" => '验证码发送成功'],200);
  242. }else{
  243. return json(["msg" => '验证码发送失败'],500);
  244. }
  245. }
  246. }