Auth.php 32 KB

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