Auth.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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. $ep->modify_fields = null; //注释注册驳回:如果要开启驳回,注释或者删掉这句话及上面那段 $data = [...];
  327. if ($ep->modify_fields) {
  328. $modify_fields = explode(",", $ep->modify_fields);
  329. foreach ($modify_fields as $field) {
  330. $data[$field] = \StrUtil::getRequestDecodeParam($this->request, $field);
  331. }
  332. }
  333. $modify_files = ["imgurl", "bankImg", "domainImg", "typeImg", "beian"]; //注释注册驳回:如果要开启驳回,用explode(",", $ep->modify_files)替换["imgurl", "bankImg", "domainImg", "typeImg", "beian"]这句代码;
  334. $files = $this->request->file();
  335. if ($files) {
  336. $uploadapi = new UploadApi();
  337. if (array_key_exists('imgurl', $files) && in_array('imgurl', $modify_files)) {
  338. $upload_result = $uploadapi->uploadOne($this->request->file('imgurl'), 'system');
  339. if ($upload_result->code == 500) {
  340. return \StrUtil::back($upload_result, "Register.epCallBack");
  341. }
  342. $data["imgurl"] = $upload_result->filepath;
  343. }
  344. //检验附件 开户许可证
  345. if (array_key_exists('bankImg', $files) && in_array('bankImg', $modify_files)) {
  346. $upload_result1 = $uploadapi->uploadOne($this->request->file('bankImg'), 'system');
  347. if ($upload_result1->code == 500) {
  348. return \StrUtil::back($upload_result1, "Register.epCallBack");
  349. }
  350. $data["bankImg"] = $upload_result1->filepath;
  351. }
  352. //检验附件 行业领域佐证材料
  353. if (array_key_exists('domainImg', $files) && in_array('domainImg', $modify_files)) {
  354. $upload_result2 = $uploadapi->uploadOne($this->request->file('domainImg'), 'system');
  355. if ($upload_result2->code == 500) {
  356. return \StrUtil::back($upload_result2, "Register.epCallBack");
  357. }
  358. $data["domainImg"] = $upload_result2->filepath;
  359. }
  360. //检验附件 行业领域佐证材料
  361. if (array_key_exists('typeImg', $files) && in_array('typeImg', $modify_files)) {
  362. $upload_result4 = $uploadapi->uploadOne($this->request->file('typeImg'), 'system');
  363. if ($upload_result4->code == 500) {
  364. return \StrUtil::back($upload_result4, "Register.epCallBack");
  365. }
  366. $data["typeImg"] = $upload_result4->filepath;
  367. }
  368. //检验附件 人才联络员备案表
  369. if (array_key_exists('beian', $files) && in_array('beian', $modify_files)) {
  370. $upload_result3 = $uploadapi->uploadOne($this->request->file('beian'), 'system');
  371. if ($upload_result3->code == 500) {
  372. return \StrUtil::back($upload_result3, "Register.epCallBack");
  373. }
  374. $data["beian"] = $upload_result3->filepath;
  375. }
  376. }
  377. try {
  378. if ($data['name'] && stripos($data['name'], "(")) {
  379. $data['name'] = str_replace('(', '(', $data['name']);
  380. }
  381. if ($data['name'] && stripos($data['name'], ")")) {
  382. $data['name'] = str_replace(')', ')', $data['name']);
  383. }
  384. $data['id'] = $ep->id;
  385. if ($ep->special == 0) {
  386. if ($data["type"] == 1) {
  387. if ($data["agencyType"] == 1) {
  388. validate(\app\common\validate\Enterprise::class)->batch(true)->scene('change')->check($data);
  389. if (!$data["domainImg"] && !$ep->domainImg) {
  390. $response_object->code = 500;
  391. $response_object->msg = "行业领域佐证材料不能为空";
  392. return \StrUtil::back($response_object, "Register.epCallBack");
  393. }
  394. } else {
  395. validate(\app\common\validate\Enterprise::class)->batch(true)->scene('change2')->check($data);
  396. }
  397. $checkTypes = ["guishang", "gaoxinjishu", "zhuanjingtexin"];
  398. if (in_array($data["enterpriseType"], $checkTypes) && (!$data["typeImg"] && !$ep->typeImg)) {
  399. $response_object->code = 500;
  400. $response_object->msg = '规上、高新技术、专精特新企业需要上传佐证材料';
  401. return \StrUtil::back($response_object, "Register.epCallBack");
  402. }
  403. } else {
  404. validate(\app\common\validate\Enterprise::class)->batch(true)->scene('jc_change')->check($data);
  405. }
  406. if (!$data["imgurl"] && !$ep->imgurl) {
  407. $response_object->code = 500;
  408. $response_object->msg = '营业执照不能为空';
  409. return \StrUtil::back($response_object, "Register.epCallBack");
  410. }
  411. if (!$data["bankImg"] && !$ep->bankImg) {
  412. $response_object->code = 500;
  413. $response_object->msg = '开户许可证/基本存款账户信息不能为空';
  414. return \StrUtil::back($response_object, "Register.epCallBack");
  415. }
  416. if (!$data["beian"] && !$ep->beian) {
  417. $response_object->code = 500;
  418. $response_object->msg = '人才联络员备案表不能为空';
  419. return \StrUtil::back($response_object, "Register.epCallBack");
  420. }
  421. } else {
  422. validate(\app\common\validate\Enterprise::class)->batch(true)->scene('sy_change')->check($data);
  423. if (!$data["imgurl"] && !$ep->imgurl) {
  424. $response_object->code = 500;
  425. $response_object->msg = '法人代表证或批文不能为空';
  426. return \StrUtil::back($response_object, "Register.epCallBack");
  427. }
  428. }
  429. //unset($data["agentPhone"]);
  430. $data['checkState'] = 4;
  431. $data["updateTime"] = date("Y-m-d H:i:s");
  432. $ep->update($data);
  433. TalentChecklog::create([
  434. 'id' => getStringId(),
  435. 'mainId' => $data['id'],
  436. 'type' => 10,
  437. 'typeField' => null,
  438. 'active' => 1,
  439. 'state' => 4,
  440. 'step' => 100,
  441. 'stateChange' => '用户提交',
  442. 'description' => '用户信息修改成功',
  443. 'createTime' => date("Y-m-d H:i:s", time()),
  444. 'createUser' => '用户'
  445. ]);
  446. $response_object->code = 200;
  447. $response_object->msg = '修改成功';
  448. return \StrUtil::back($response_object, "Register.epCallBack");
  449. } catch (ValidateException $e) {
  450. $error = $e->getError();
  451. $response_object->code = 500;
  452. $response_object->msg = array_pop($error);
  453. return \StrUtil::back($response_object, "Register.epCallBack");
  454. }
  455. }
  456. if ($ep->imgurl) {
  457. $pathinfo = pathinfo($ep->imgurl);
  458. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  459. $ep->imgurl_is_img = 1;
  460. }
  461. }
  462. if ($ep->domainImg) {
  463. $pathinfo = pathinfo($ep->domainImg);
  464. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  465. $ep->domainImg_is_img = 1;
  466. }
  467. }
  468. if ($ep->typeImg) {
  469. $pathinfo = pathinfo($ep->typeImg);
  470. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  471. $ep->typeImg_is_img = 1;
  472. }
  473. }
  474. if ($ep->beian) {
  475. $pathinfo = pathinfo($ep->beian);
  476. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  477. $ep->beian_is_img = 1;
  478. }
  479. }
  480. if ($ep->bankImg) {
  481. $pathinfo = pathinfo($ep->bankImg);
  482. if (in_array($pathinfo["extension"], ["jpg", "jpeg", "png", "gif"])) {
  483. $ep->bankImg_is_img = 1;
  484. }
  485. }
  486. $msg = session('temp')['msg'];
  487. return view("", ['msg' => $msg, 'ep' => $ep]);
  488. }
  489. public function findBackPassword() {
  490. $type = intval($this->request['type']);
  491. if (\StrUtil::isEmpOrNull($type)) {
  492. return json(['msg' => '请选择账号类型', 'code' => 500]);
  493. }
  494. $username = \StrUtil::getRequestDecodeParam($this->request, 'username');
  495. if (\StrUtil::isEmpOrNull($username)) {
  496. return json(['msg' => '请填写账号', 'code' => 500]);
  497. }
  498. $password = \StrUtil::getRequestDecodeParam($this->request, 'password');
  499. if (\StrUtil::isEmpOrNull($password)) {
  500. return json(['msg' => '请填写新密码', 'code' => 500]);
  501. }
  502. $rePassword = \StrUtil::getRequestDecodeParam($this->request, 'rePassword');
  503. if (\StrUtil::isEmpOrNull($rePassword)) {
  504. return json(['msg' => '请填写重复新密码', 'code' => 500]);
  505. }
  506. if ($password != $rePassword) {
  507. return json(['msg' => '两次密码填写不一致', 'code' => 500]);
  508. }
  509. if (!preg_match("/^(?=.*\d)(?=.*[A-Za-z]).{8,}$/", $password)) {
  510. return json(['msg' => '密码必须包含字母、数字、特殊字符且长度超过8位', 'code' => 500]);
  511. }
  512. $phone = \StrUtil::getRequestDecodeParam($this->request, 'phone');
  513. if (\StrUtil::isEmpOrNull($phone)) {
  514. return json(['msg' => '请填写手机号', 'code' => 500]);
  515. }
  516. $verificationCode = \StrUtil::getRequestDecodeParam($this->request, 'verificationCode');
  517. if (\StrUtil::isEmpOrNull($verificationCode)) {
  518. return json(['msg' => '请填写验证码', 'code' => 500]);
  519. }
  520. //检验验证码
  521. $codeResult = MessageRecord::where('smsType', 1)->where('phone', $phone)->order('createTime', 'desc')->find();
  522. if (!$codeResult || (time() - strtotime($codeResult['sendingDate']) > 300)) {
  523. return json(['msg' => '请先发送验证码', 'code' => 500]);
  524. }
  525. if ($codeResult['params'] != $verificationCode) {
  526. return json(['msg' => '验证码不正确', 'code' => 500]);
  527. }
  528. $password = hash('md5', $password);
  529. if ($type == 1) {
  530. $count = \app\common\model\Enterprise::where('username', $username)->where('agentPhone', $phone)->count();
  531. if ($count == 0) {
  532. return json(['msg' => '未找到相关账号,请仔细核对账号及手机号信息!', 'code' => 500]);
  533. }
  534. if ($count > 1) {
  535. return json(['msg' => '找到多个账户,请联系相关单位处理!', 'code' => 500]);
  536. }
  537. $ep = \app\common\model\Enterprise::where('username', $username)->where('agentPhone', $phone)->find();
  538. $ep->password = $password;
  539. $ep->save();
  540. } else {
  541. //个人账户找回密码TODO
  542. }
  543. return json(['msg' => '找回密码成功!', 'code' => 200]);
  544. }
  545. public function verificationCode() {
  546. $phone = $this->request["phone"];
  547. $type = $this->request["type"];
  548. //校验手机号码是否为空
  549. if (\StrUtil::isEmpOrNull($phone)) {
  550. return json(["msg" => "请填写手机号码!"], 500);
  551. }
  552. if (\StrUtil::isEmpOrNull($type)) {
  553. return json(["msg" => "请填写手机号码!"], 500);
  554. }
  555. //校验手机号码格式是否正确
  556. if (\StrUtil::isMoblePhone($phone)) {
  557. return json(["msg" => "请填写正确的手机号码!"], 500);
  558. }
  559. $record = Cache::get("verify_{$type}_{$phone}");
  560. if ($record) {
  561. $time = time();
  562. if ($time - $record <= 60) {
  563. return json(["msg" => "一分钟内请勿频繁发送短信!"], 500);
  564. }
  565. }
  566. $code = '';
  567. for ($i = 1; $i <= 6; $i++) {
  568. $code .= rand(0, 9);
  569. }
  570. //$code = 999999;
  571. $template = "【晋江市人才服务平台】尊敬的用户,您的短信验证码为{$code},5分钟内有效。若非本人操作请忽略。";
  572. $smsapi = new ChuanglanSmsApi();
  573. $result = $smsapi->sendSMS($phone, $template);
  574. $result = json_decode($result, true);
  575. $id = getStringId();
  576. $record_data = [
  577. 'id' => $id,
  578. 'bizId' => $id,
  579. 'type' => 2,
  580. 'smsType' => 1,
  581. 'phone' => $phone,
  582. 'params' => $code,
  583. 'templateCode' => $template,
  584. 'state' => $result['code'] == 0 ? 2 : 3,
  585. 'sendingDate' => date("Y-m-d H:i:s", time()),
  586. 'createTime' => date("Y-m-d H:i:s", time()),
  587. 'msg' => $result['errorMsg']
  588. ];
  589. MessageRecord::create($record_data);
  590. if ($result['code'] == 0) {
  591. Cache::set("verify_{$type}_{$phone}", time());
  592. return json(["msg" => '验证码发送成功'], 200);
  593. } else {
  594. return json(["msg" => '验证码发送失败'], 500);
  595. }
  596. }
  597. }