Auth.php 23 KB

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