Auth.php 37 KB

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