Auth.php 28 KB

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