Auth.php 41 KB

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