Auth.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. public function register() {
  15. $msg = "";
  16. if ($this->request->isPost()) {
  17. $source = 3; //intval($this->request['source']);
  18. $response_object = new \StdClass();
  19. $special = \StrUtil::getRequestDecodeParam($this->request, 'special');
  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. if (stripos($data['name'], "(")) {
  45. $data['name'] = str_replace('(', '(', $data['name']);
  46. }
  47. if (stripos($data['name'], ")")) {
  48. $data['name'] = str_replace(')', ')', $data['name']);
  49. }
  50. $files = $this->request->file();
  51. if ($special == 'qiye') {
  52. if ($data['type'] == 1) {
  53. validate(Enterprise::class)->batch(true)->scene('add')->check($data);
  54. if (!array_key_exists('domainImg', $files) || $files['domainImg'] == '') {
  55. $response_object->code = 500;
  56. $response_object->msg = '行业领域佐证材料不能为空';
  57. return \StrUtil::back($response_object, "Register.epCallBack");
  58. }
  59. $checkTypes = ["guishang", "gaoxinjishu", "zhuanjingtexin"];
  60. if (in_array($data["enterpriseType"], $checkTypes) && (!array_key_exists('typeImg', $files) || $files['typeImg'] == '')) {
  61. $response_object->code = 500;
  62. $response_object->msg = '规上、高新技术、专精特新企业需要上传佐证材料';
  63. return \StrUtil::back($response_object, "Register.epCallBack");
  64. }
  65. } else {
  66. validate(Enterprise::class)->batch(true)->scene('jc_add')->check($data); //集成电路
  67. }
  68. if (!array_key_exists('imgurl', $files) || $files['imgurl'] == '') {
  69. $response_object->code = 500;
  70. $response_object->msg = '营业执照不能为空';
  71. return \StrUtil::back($response_object, "Register.epCallBack");
  72. }
  73. if (!array_key_exists('bankImg', $files) || $files['bankImg'] == '') {
  74. $response_object->code = 500;
  75. $response_object->msg = '开户许可证不能为空';
  76. return \StrUtil::back($response_object, "Register.epCallBack");
  77. }
  78. if (!array_key_exists('beian', $files) || $files['beian'] == '') {
  79. $response_object->code = 500;
  80. $response_object->msg = '人才联络员备案表不能为空';
  81. return \StrUtil::back($response_object, "Register.epCallBack");
  82. }
  83. $data['special'] = 0;
  84. } else {
  85. $data['type'] = 1;
  86. validate(Enterprise::class)->batch(true)->scene('sy_add')->check($data); //事业单位
  87. if (!array_key_exists('imgurl', $files) || $files['imgurl'] == '') {
  88. $response_object->code = 500;
  89. $response_object->msg = '法人代表证或批文不能为空';
  90. return \StrUtil::back($response_object, "Register.epCallBack");
  91. }
  92. $data['special'] = 1;
  93. }
  94. //检验验证码
  95. $codeResult = MessageRecord::where('smsType', 1)->where('phone', $data['agentPhone'])->order('createTime', 'desc')->find();
  96. if (!$codeResult) {
  97. $response_object->code = 500;
  98. $response_object->msg = '请先发送验证码';
  99. return \StrUtil::back($response_object, "Register.epCallBack");
  100. }
  101. if (time() - strtotime($codeResult['createTime']) > 300) {
  102. $response_object->code = 500;
  103. $response_object->msg = '验证码过期,请重新发送';
  104. return \StrUtil::back($response_object, "Register.epCallBack");
  105. }
  106. $uploadapi = new UploadApi();
  107. //检验附件 营业执照
  108. if (array_key_exists('imgurl', $files)) {
  109. $upload_result = $uploadapi->uploadOne($this->request->file('imgurl'), 'system');
  110. if ($upload_result->code == 500) {
  111. return \StrUtil::back($upload_result, "Register.epCallBack");
  112. }
  113. $imgurl = $upload_result->filepath;
  114. } else {
  115. $imgurl = '';
  116. }
  117. //检验附件 开户许可证
  118. if (array_key_exists('bankImg', $files)) {
  119. $upload_result1 = $uploadapi->uploadOne($this->request->file('bankImg'), 'system');
  120. if ($upload_result1->code == 500) {
  121. return \StrUtil::back($upload_result1, "Register.epCallBack");
  122. }
  123. $bankImg = $upload_result1->filepath;
  124. } else {
  125. $bankImg = '';
  126. }
  127. //检验附件 行业领域佐证材料
  128. if (array_key_exists('domainImg', $files)) {
  129. $upload_result2 = $uploadapi->uploadOne($this->request->file('domainImg'), 'system');
  130. if ($upload_result2->code == 500) {
  131. return \StrUtil::back($upload_result2, "Register.epCallBack");
  132. }
  133. $domainImg = $upload_result2->filepath;
  134. } else {
  135. $domainImg = '';
  136. }
  137. //检验附件 行业领域佐证材料
  138. if (array_key_exists('typeImg', $files)) {
  139. $upload_result4 = $uploadapi->uploadOne($this->request->file('typeImg'), 'system');
  140. if ($upload_result4->code == 500) {
  141. return \StrUtil::back($upload_result4, "Register.epCallBack");
  142. }
  143. $typeImg = $upload_result4->filepath;
  144. } else {
  145. $typeImg = '';
  146. }
  147. //检验附件 人才联络员备案表
  148. if (array_key_exists('beian', $files)) {
  149. $upload_result3 = $uploadapi->uploadOne($this->request->file('beian'), 'system');
  150. if ($upload_result3->code == 500) {
  151. return \StrUtil::back($upload_result3, "Register.epCallBack");
  152. }
  153. $beian = $upload_result3->filepath;
  154. } else {
  155. $beian = '';
  156. }
  157. $data['id'] = getStringId();
  158. $data['password'] = hash('md5', $data['password']);
  159. $data['source'] = $source;
  160. $data['imgurl'] = $imgurl;
  161. $data['bankImg'] = $bankImg;
  162. $data['domainImg'] = $domainImg;
  163. $data["typeImg"] = $typeImg;
  164. $data['beian'] = $beian;
  165. $data['createTime'] = date("Y-m-d H:i:s", time());
  166. $data['updateTime'] = date("Y-m-d H:i:s", time());
  167. $data['active'] = 1;
  168. $data['checkState'] = 1;
  169. \app\common\model\Enterprise::create($data);
  170. TalentChecklog::create([
  171. 'id' => getStringId(),
  172. 'mainId' => $data['id'],
  173. 'type' => 10,
  174. 'typeField' => null,
  175. 'active' => 1,
  176. 'state' => 1,
  177. 'step' => 100,
  178. 'stateChange' => '用户提交',
  179. 'description' => '用户注册',
  180. 'createTime' => date("Y-m-d H:i:s", time()),
  181. 'createUser' => '用户'
  182. ]);
  183. $response_object->code = 200;
  184. $response_object->msg = '注册成功';
  185. return \StrUtil::back($response_object, "Register.epCallBack");
  186. } catch (ValidateException $e) {
  187. $error = $e->getError();
  188. $response_object->code = 500;
  189. $response_object->msg = array_pop($error);
  190. return \StrUtil::back($response_object, "Register.epCallBack");
  191. }
  192. }
  193. return view("", ["msg" => $msg]);
  194. }
  195. public function enterprise_edit() {
  196. $temp = session('temp');
  197. if (empty($temp)) {
  198. return redirect("/");
  199. }
  200. $ep = EnterpriseApi::getOne(session('temp')['uid']);
  201. if ($this->request->isPost()) {
  202. $response_object = new \StdClass();
  203. $data = [
  204. 'name' => \StrUtil::getRequestDecodeParam($this->request, 'name'), //单位名称
  205. 'idCard' => \StrUtil::getRequestDecodeParam($this->request, 'idCard'), //统一社会信用代码
  206. 'agentName' => \StrUtil::getRequestDecodeParam($this->request, 'agentName'), //人才联络员
  207. 'legal' => \StrUtil::getRequestDecodeParam($this->request, 'legal'), //法人
  208. 'street' => \StrUtil::getRequestDecodeParam($this->request, 'street'), //镇街
  209. 'address' => \StrUtil::getRequestDecodeParam($this->request, 'address'), //地址
  210. 'type' => intval($this->request['type']),
  211. 'enterpriseTag' => \StrUtil::getRequestDecodeParam($this->request, 'enterpriseTag'), //单位标签
  212. 'enterpriseType' => \StrUtil::getRequestDecodeParam($this->request, 'enterpriseType'), //单位类型
  213. 'agentPhone' => \StrUtil::getRequestDecodeParam($this->request, 'agentPhone'), //手机
  214. 'agentEmail' => \StrUtil::getRequestDecodeParam($this->request, 'agentEmail'), //邮箱
  215. 'ephone' => \StrUtil::getRequestDecodeParam($this->request, 'ephone'), //单位电话
  216. 'industryFieldNew' => \StrUtil::getRequestDecodeParam($this->request, 'industryFieldNew'), //产业领域
  217. 'industryFieldOld' => \StrUtil::getRequestDecodeParam($this->request, 'industryFieldOld'), //行业领域
  218. 'bankCard' => \StrUtil::getRequestDecodeParam($this->request, 'bankCard'), //银行
  219. 'bank' => \StrUtil::getRequestDecodeParam($this->request, 'bank'), //开户行
  220. 'bankNetwork' => \StrUtil::getRequestDecodeParam($this->request, 'bankNetwork')//网点
  221. ];
  222. $files = $this->request->file();
  223. if ($files) {
  224. $uploadapi = new UploadApi();
  225. if (array_key_exists('imgurl', $files)) {
  226. $upload_result = $uploadapi->uploadOne($this->request->file('imgurl'), 'system');
  227. if ($upload_result->code == 500) {
  228. return \StrUtil::back($upload_result, "Register.epCallBack");
  229. }
  230. $data["imgurl"] = $upload_result->filepath;
  231. }
  232. //检验附件 开户许可证
  233. if (array_key_exists('bankImg', $files)) {
  234. $upload_result1 = $uploadapi->uploadOne($this->request->file('bankImg'), 'system');
  235. if ($upload_result1->code == 500) {
  236. return \StrUtil::back($upload_result1, "Register.epCallBack");
  237. }
  238. $data["bankImg"] = $upload_result1->filepath;
  239. }
  240. //检验附件 行业领域佐证材料
  241. if (array_key_exists('domainImg', $files)) {
  242. $upload_result2 = $uploadapi->uploadOne($this->request->file('domainImg'), 'system');
  243. if ($upload_result2->code == 500) {
  244. return \StrUtil::back($upload_result2, "Register.epCallBack");
  245. }
  246. $data["domainImg"] = $upload_result2->filepath;
  247. }
  248. //检验附件 行业领域佐证材料
  249. if (array_key_exists('typeImg', $files)) {
  250. $upload_result4 = $uploadapi->uploadOne($this->request->file('typeImg'), 'system');
  251. if ($upload_result4->code == 500) {
  252. return \StrUtil::back($upload_result4, "Register.epCallBack");
  253. }
  254. $data["typeImg"] = $upload_result4->filepath;
  255. }
  256. //检验附件 人才联络员备案表
  257. if (array_key_exists('beian', $files)) {
  258. $upload_result3 = $uploadapi->uploadOne($this->request->file('beian'), 'system');
  259. if ($upload_result3->code == 500) {
  260. return \StrUtil::back($upload_result3, "Register.epCallBack");
  261. }
  262. $data["beian"] = $upload_result3->filepath;
  263. }
  264. }
  265. try {
  266. if (stripos($data['name'], "(")) {
  267. $data['name'] = str_replace('(', '(', $data['name']);
  268. }
  269. if (stripos($data['name'], ")")) {
  270. $data['name'] = str_replace(')', ')', $data['name']);
  271. }
  272. $data['id'] = $ep->id;
  273. if ($ep->special == 0) {
  274. if ($ep->type == 1) {
  275. validate(\app\common\validate\Enterprise::class)->batch(true)->scene('change')->check($data);
  276. } else {
  277. validate(\app\common\validate\Enterprise::class)->batch(true)->scene('jc_change')->check($data);
  278. }
  279. } else {
  280. validate(\app\common\validate\Enterprise::class)->batch(true)->scene('sy_change')->check($data);
  281. }
  282. unset($data["agentPhone"]);
  283. $data['checkState'] = 1;
  284. $ep->update($data);
  285. $response_object->code = 200;
  286. $response_object->msg = '修改成功';
  287. return \StrUtil::back($response_object, "Register.epCallBack");
  288. } catch (ValidateException $e) {
  289. $error = $e->getError();
  290. $response_object->code = 500;
  291. $response_object->msg = array_pop($error);
  292. return \StrUtil::back($response_object, "Register.epCallBack");
  293. }
  294. }
  295. if ($ep->imgurl) {
  296. $pathinfo = pathinfo($ep->imgurl);
  297. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  298. $ep->imgurl_is_img = 1;
  299. }
  300. }
  301. if ($ep->domainImg) {
  302. $pathinfo = pathinfo($ep->domainImg);
  303. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  304. $ep->domainImg_is_img = 1;
  305. }
  306. }
  307. if ($ep->typeImg) {
  308. $pathinfo = pathinfo($ep->typeImg);
  309. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  310. $ep->typeImg_is_img = 1;
  311. }
  312. }
  313. if ($ep->beian) {
  314. $pathinfo = pathinfo($ep->beian);
  315. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  316. $ep->beian_is_img = 1;
  317. }
  318. }
  319. if ($ep->bankImg) {
  320. $pathinfo = pathinfo($ep->bankImg);
  321. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  322. $ep->bankImg_is_img = 1;
  323. }
  324. }
  325. $msg = session('temp')['msg'];
  326. return view("", ['msg' => $msg, 'ep' => $ep]);
  327. }
  328. public function findBackPassword() {
  329. $type = intval($this->request['type']);
  330. if (\StrUtil::isEmpOrNull($type)) {
  331. return json(['msg' => '请选择账号类型', 'code' => 500]);
  332. }
  333. $username = \StrUtil::getRequestDecodeParam($this->request, 'username');
  334. if (\StrUtil::isEmpOrNull($username)) {
  335. return json(['msg' => '请填写账号', 'code' => 500]);
  336. }
  337. $password = \StrUtil::getRequestDecodeParam($this->request, 'password');
  338. if (\StrUtil::isEmpOrNull($password)) {
  339. return json(['msg' => '请填写新密码', 'code' => 500]);
  340. }
  341. $rePassword = \StrUtil::getRequestDecodeParam($this->request, 'rePassword');
  342. if (\StrUtil::isEmpOrNull($rePassword)) {
  343. return json(['msg' => '请填写重复新密码', 'code' => 500]);
  344. }
  345. if ($password != $rePassword) {
  346. return json(['msg' => '两次密码填写不一致', 'code' => 500]);
  347. }
  348. if (!preg_match("/^(?=.*\d)(?=.*[A-Za-z]).{8,}$/", $password)) {
  349. return json(['msg' => '密码必须包含字母、数字、特殊字符且长度超过8位', 'code' => 500]);
  350. }
  351. $phone = \StrUtil::getRequestDecodeParam($this->request, 'phone');
  352. if (\StrUtil::isEmpOrNull($phone)) {
  353. return json(['msg' => '请填写手机号', 'code' => 500]);
  354. }
  355. $verificationCode = \StrUtil::getRequestDecodeParam($this->request, 'verificationCode');
  356. if (\StrUtil::isEmpOrNull($verificationCode)) {
  357. return json(['msg' => '请填写验证码', 'code' => 500]);
  358. }
  359. //检验验证码
  360. $codeResult = MessageRecord::where('smsType', 1)->where('phone', $phone)->order('createTime', 'desc')->find();
  361. if (!$codeResult || (time() - strtotime($codeResult['sendingDate']) > 300)) {
  362. return json(['msg' => '请先发送验证码', 'code' => 500]);
  363. }
  364. if ($codeResult['params'] != $verificationCode) {
  365. return json(['msg' => '验证码不正确', 'code' => 500]);
  366. }
  367. $password = hash('md5', $password);
  368. if ($type == 1) {
  369. $count = \app\common\model\Enterprise::where('username', $username)->where('agentPhone', $phone)->count();
  370. if ($count == 0) {
  371. return json(['msg' => '未找到相关账号,请仔细核对账号及手机号信息!', 'code' => 500]);
  372. }
  373. if ($count > 1) {
  374. return json(['msg' => '找到多个账户,请联系相关单位处理!', 'code' => 500]);
  375. }
  376. $ep = \app\common\model\Enterprise::where('username', $username)->where('agentPhone', $phone)->find();
  377. $ep->password = $password;
  378. $ep->save();
  379. } else {
  380. //个人账户找回密码TODO
  381. }
  382. return json(['msg' => '找回密码成功!', 'code' => 200]);
  383. }
  384. public function verificationCode() {
  385. $phone = $this->request["phone"];
  386. $type = $this->request["type"];
  387. //校验手机号码是否为空
  388. if (\StrUtil::isEmpOrNull($phone)) {
  389. return json(["msg" => "请填写手机号码!"], 500);
  390. }
  391. if (\StrUtil::isEmpOrNull($type)) {
  392. return json(["msg" => "请填写手机号码!"], 500);
  393. }
  394. //校验手机号码格式是否正确
  395. if (\StrUtil::isMoblePhone($phone)) {
  396. return json(["msg" => "请填写正确的手机号码!"], 500);
  397. }
  398. $record = Cache::get("verify_{$type}_{$phone}");
  399. if ($record) {
  400. $time = time();
  401. if ($time - $record <= 60) {
  402. return json(["msg" => "一分钟内请勿频繁发送短信!"], 500);
  403. }
  404. }
  405. $code = '';
  406. for ($i = 1; $i <= 6; $i++) {
  407. $code .= rand(0, 9);
  408. }
  409. //$code = 999999;
  410. $template = "【晋江市人才服务平台】尊敬的用户,您的短信验证码为{$code},5分钟内有效。若非本人操作请忽略。";
  411. $smsapi = new ChuanglanSmsApi();
  412. $result = $smsapi->sendSMS($phone, $template);
  413. $result = json_decode($result, true);
  414. $id = getStringId();
  415. $record_data = [
  416. 'id' => $id,
  417. 'bizId' => $id,
  418. 'type' => 2,
  419. 'smsType' => 1,
  420. 'phone' => $phone,
  421. 'params' => $code,
  422. 'templateCode' => $template,
  423. 'state' => $result['code'] == 0 ? 2 : 3,
  424. 'sendingDate' => date("Y-m-d H:i:s", time()),
  425. 'createTime' => date("Y-m-d H:i:s", time()),
  426. 'msg' => $result['errorMsg']
  427. ];
  428. MessageRecord::create($record_data);
  429. if ($result['code'] == 0) {
  430. Cache::set("verify_{$type}_{$phone}", time());
  431. return json(["msg" => '验证码发送成功'], 200);
  432. } else {
  433. return json(["msg" => '验证码发送失败'], 500);
  434. }
  435. }
  436. }