Auth.php 21 KB

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