Integral.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <?php
  2. namespace app\enterprise\controller;
  3. use app\enterprise\common\EnterpriseController;
  4. use think\facade\Db;
  5. use app\common\api\EnterpriseApi;
  6. use app\enterprise\validate\TalentInfo;
  7. /**
  8. * Description of 积分申报
  9. *
  10. * @author sgq
  11. */
  12. class Integral extends EnterpriseController {
  13. public function index() {
  14. return view();
  15. }
  16. public function list() {
  17. $res = IntegralLogApi::getList($this->request, $step);
  18. return json($res);
  19. }
  20. /**
  21. * 积分申报入口
  22. */
  23. public function apply(\think\Request $request) {
  24. $type = $this->user["type"];
  25. $tpl = "";
  26. switch ($type) {
  27. case 1:
  28. $tpl = "apply"; //晋江人才
  29. break;
  30. case 2:
  31. $tpl = "ic_apply"; //集成电路
  32. break;
  33. }
  34. $param = $request->param();
  35. $id = isset($param["id"]) ? $param["id"] : 0;
  36. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  37. $ep = EnterpriseApi::getOne($this->user["uid"]);
  38. if (!chkEnterpriseFull($ep))
  39. return;
  40. $tagList = DictApi::selectByParentCode('enterprise_tag');
  41. $streetList = DictApi::selectByParentCode('street');
  42. $industryFieldNew = DictApi::selectByParentCode('industry_field');
  43. $ep->enterpristTagName = $tagList[$ep->enterpriseTag];
  44. $ep->streetName = $streetList[$ep->street];
  45. $ep->industryFieldNewName = $industryFieldNew[$ep->industryFieldNew];
  46. if ($info) {
  47. $info["real_state"] = TalentLogApi::getLastLog($id, 1)["state"];
  48. }
  49. if ($info && in_array($info["checkState"], [TalentState::FST_VERIFY_PASS, TalentState::DEPT_VERIFY_PASS, TalentState::REVERIFY_PASS, TalentState::REVERIFY_FAIL])) {
  50. return $this->view($request);
  51. exit();
  52. }
  53. if ($request->isPost()) {
  54. $checkState = $info["checkState"] ?: 0;
  55. if ($checkState == TalentState::SCND_SAVE || $checkState == 0) {
  56. switch ($type) {
  57. case 1:
  58. $this->mixSave($info, $request, TalentState::SCND_SAVE);
  59. exit();
  60. break;
  61. case 2:
  62. $this->icSave($info, $request, TalentState::SCND_SAVE);
  63. exit();
  64. break;
  65. }
  66. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL])) {
  67. $res = ["msg" => "审核失败,不能再保存"];
  68. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  69. exit;
  70. }
  71. $res = ["msg" => "已提交审核,请耐心等待"];
  72. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  73. exit;
  74. }
  75. $checkState = $info["checkState"] ?: 0;
  76. $info["enterprise"] = $ep;
  77. $info["talent_type_list"] = DictApi::findChildDictByCode("talent_type");
  78. return view($tpl, ["year" => date("Y"), "checkState" => $checkState, "row" => $info]);
  79. }
  80. public function view(\think\Request $request) {
  81. switch ($this->user["type"]) {
  82. case 1:
  83. $tpl = "view"; //晋江人才
  84. break;
  85. case 2:
  86. $tpl = "ic_view"; //集成电路
  87. break;
  88. }
  89. $id = $request->param("id");
  90. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  91. return view($tpl, ["row" => $info]);
  92. }
  93. /**
  94. * 提交表单(新:混合基础信息人才申报信息)晋江人才
  95. */
  96. private function submitToCheck() {
  97. $params = $this->request->param();
  98. $id = $params["id"];
  99. $info = TalentApi::chkIsOwner($id, $this->user["uid"]);
  100. if ($info) {
  101. $info["real_state"] = TalentLogApi::getLastLog($id, 1)["state"];
  102. }
  103. $checkState = $info["checkState"];
  104. if ($checkState == TalentState::SCND_SAVE || !$id) {
  105. $field_dict = \app\common\api\DictApi::getTalentFields(4);
  106. $no_empty = ["name", "nation", "card_type", "card_number", "sex", "birthday", "politics", "nationality", "province", "city", "county", "talent_type", "experience", "education",
  107. "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "bank", "bank_number", "bank_branch_name",
  108. "bank_account", "study_abroad", "phone", "email", "import_way", "cur_entry_time", "cur_entry_time", "position", "source"];
  109. $where = [];
  110. $where[] = ["rel", "=", "study_abroad"];
  111. $where[] = ["project", "=", 1];
  112. $where[] = ["active", "=", 1];
  113. $where[] = ["delete", "=", 0];
  114. $where[] = ["type", "=", $this->user["type"]];
  115. $where[] = ["isConditionFile", "<>", 1];
  116. $abroad_files = Db::table("new_common_filetype")->where($where)->select()->toArray(); //留学的附件
  117. $abroad_file_ids = null;
  118. if ($abroad_files)
  119. $abroad_file_ids = array_column($abroad_files, "id");
  120. if (in_array($params["talent_type"], [1, 2])) {
  121. $no_empty[] = "tax_insurance_month";
  122. $no_empty[] = "labor_contract_rangetime";
  123. }
  124. if ($params["talent_type"] == 3) {
  125. $no_empty[] = "pre_import_type";
  126. }
  127. if ($params["study_abroad"] == 1) {
  128. $no_empty[] = "abroad_school";
  129. $no_empty[] = "abroad_major";
  130. }
  131. if (in_array($params["source"], [1, 3])) {
  132. $no_empty[] = "source_batch";
  133. $no_empty[] = "fujian_highcert_pubtime";
  134. $no_empty[] = "fujian_highcert_exptime";
  135. if ($params["source"] == 3) {
  136. $no_empty[] = "source_city";
  137. }
  138. }
  139. if (in_array($params["source"], [2, 4])) {
  140. $no_empty[] = "source_batch";
  141. $no_empty[] = "quanzhou_highcert_pubtime";
  142. $no_empty[] = "quanzhou_highcert_exptime";
  143. if ($params["source"] == 4) {
  144. $no_empty[] = "source_county";
  145. }
  146. }
  147. $condition_info = Db::table("new_talent_condition")->findOrEmpty($params["talent_condition"]);
  148. if ($condition_info["isSalary"] == 1) {
  149. $no_empty[] = "annual_salary";
  150. }
  151. $no_empty = array_filter($no_empty);
  152. $return = [];
  153. foreach ($no_empty as $key) {
  154. if (!$params[$key]) {
  155. $return[] = sprintf("请填写“%s”", $field_dict[$key]);
  156. }
  157. }
  158. if (count($return) > 0) {
  159. $res = ["msg" => implode("<br>", $return)];
  160. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  161. exit;
  162. }
  163. if ($condition_info["bindFileTypes"] && $info["source"] == 5) {
  164. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  165. $whr[] = ["must", "=", 1];
  166. }
  167. $where = [];
  168. $where[] = ["project", "=", 1];
  169. $where[] = ["type", "=", $this->user["type"]];
  170. $where[] = ["must", "=", 1];
  171. $where[] = ["active", "=", 1];
  172. $where[] = ["delete", "=", 0];
  173. $where[] = ["isConditionFile", "<>", 1];
  174. if ($whr) {
  175. $filetypes = Db::table("new_common_filetype")->whereOr([$where, $whr])->select()->toArray();
  176. } else {
  177. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  178. }
  179. $age = 0;
  180. if ($params["birthday"]) {
  181. $birthday = $params["birthday"];
  182. $birthdayYear = substr($birthday, 0, 4);
  183. $currentYear = date("Y");
  184. $age = $currentYear - $birthdayYear;
  185. }
  186. $ft_ids = [];
  187. $deletes = [];
  188. foreach ($filetypes as $ft) {
  189. if ($ft["option"]) {
  190. if ($ft["rel"] == "birthday") {
  191. if ($age < $ft["option"]) {
  192. $deletes[] = $ft["id"];
  193. continue;
  194. }
  195. } else {
  196. $selectVal = $params[$ft["rel"]];
  197. $conditions = array_filter(explode(",", $ft["option"]));
  198. if (!in_array($selectVal, $conditions)) {
  199. $deletes[] = $ft["id"];
  200. continue;
  201. }
  202. }
  203. }
  204. $ft_ids[] = $ft["id"];
  205. }
  206. if ($params["study_abroad"] == 1) {
  207. //选中留学,如果存在留学附件变成必传
  208. $ft_ids = array_unique(array_merge($ft_ids, (array) $abroad_file_ids));
  209. } else {
  210. //没选中,留学附件就算设成必传也不用验证
  211. $ft_ids = array_diff($ft_ids, (array) $abroad_file_ids);
  212. }
  213. $whr = [];
  214. if ($id) {
  215. $whr[] = ["mainId", "=", $id];
  216. } else {
  217. if ($params["uploadFiles"])
  218. $whr[] = ["id", "in", $params["uploadFiles"]];
  219. }
  220. $whr[] = ["typeId", "in", $ft_ids];
  221. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  222. $upload_type_counts = count($distinct_filetypes);
  223. if ($upload_type_counts != count($ft_ids)) {
  224. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
  225. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  226. exit;
  227. }
  228. return $this->mixSave($info, $this->request, TalentState::SCND_SUBMIT);
  229. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL, TalentState::ZX_FAIL, TalentState::ANNOUNCED_REVERIFY_FAIL, TalentState::PUBLISH_FAIL])) {
  230. $res = ["msg" => "审核失败,不能再提交审核"];
  231. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  232. exit;
  233. }
  234. $res = ["msg" => "已提交审核,请耐心等待"];
  235. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  236. exit;
  237. }
  238. /**
  239. * 保存申报表单
  240. * @param type $info talent_info
  241. * @param type $param request->param();
  242. */
  243. private function save($info, \think\Request $request, $checkState) {
  244. try {
  245. $batch = \app\common\api\BatchApi::getValidBatch(20, $this->user["type"]);
  246. if (!$batch) {
  247. throw new ValidateException("不在人才认定申报申请时间内");
  248. }
  249. $param = $request->param();
  250. validate(TalentInfo::class)->check($param);
  251. $id = $param["id"];
  252. if ($id) {
  253. if (!$info || $info["id"] != $id || $info["enterprise_id"] != $this->user["uid"]) {
  254. throw new ValidateException("没有对应的人才认定申报信息");
  255. }
  256. }
  257. $files = $param["uploadFiles"];
  258. $data["headimgurl"] = $info["headimgurl"];
  259. if ($request->file()) {
  260. $headimg = $request->file("photo");
  261. $upload = new \app\common\api\UploadApi();
  262. $result = $upload->uploadOne($headimg, "image", "talent/photo");
  263. $file = imagecreatefromstring(file_get_contents("storage/" . $result->filepath));
  264. $width = imagesx($file);
  265. $height = imagesy($file);
  266. //免冠二寸照长宽413:579
  267. if ($width * 579 != $height * 413) {
  268. @unlink("storage/" . $result->filepath); //像素不符合,删除上传文件
  269. throw new ValidateException("近期免冠半身彩照(二寸)不符合二寸像素标准。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
  270. }
  271. if ($info && $info["headimgurl"]) {
  272. //如果新照片符合像素要求,则删除旧照片
  273. $old_head_url = "storage/" . $info["headimgurl"];
  274. if (file_exists($old_head_url))
  275. @unlink($old_head_url);
  276. }
  277. $data["headimgurl"] = $result->filepath;
  278. }
  279. if (!$data["headimgurl"] && $checkState == TalentState::SCND_SUBMIT)
  280. throw new ValidateException("请上传头像。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
  281. $where = [];
  282. $where[] = ["project", "=", 1];
  283. $where[] = ["type", "=", $this->user["type"]];
  284. $where[] = ["must", "=", 1];
  285. $where[] = ["active", "=", 1];
  286. $where[] = ["delete", "=", 0];
  287. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  288. $age = 0;
  289. if ($param["birthday"]) {
  290. $birthday = $param["birthday"];
  291. $birthdayYear = substr($birthday, 0, 4);
  292. $currentYear = date("Y");
  293. $age = $currentYear - $birthdayYear;
  294. }
  295. $ft_ids = [];
  296. $deletes = [];
  297. foreach ($filetypes as $ft) {
  298. if ($ft["option"]) {
  299. if ($ft["rel"] == "birthday") {
  300. if ($age < $ft["option"]) {
  301. $deletes[] = $ft["id"];
  302. continue;
  303. }
  304. } else {
  305. $selectVal = $param[$ft["rel"]];
  306. $conditions = array_filter(explode(",", $ft["option"]));
  307. if (!in_array($selectVal, $conditions)) {
  308. $deletes[] = $ft["id"];
  309. continue;
  310. }
  311. }
  312. }
  313. $ft_ids[] = $ft["id"];
  314. }
  315. $data["apply_year"] = $batch["batch"];
  316. $all_valid_keys = ["talent_type", "name", "card_type", "card_number", "sex", "birthday", "nationality", "province", "city", "county", "nation", "politics", "experience", "education",
  317. "import_way", "cur_entry_time", "position",
  318. "source", "source_batch", "fujian_highcert_pubtime", "fujian_highcert_exptime", "quanzhou_highcert_pubtime", "quanzhou_highcert_exptime", "source_city", "source_county",
  319. "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "professional", "bank", "bank_number", "bank_branch_name", "bank_account",
  320. "study_abroad", "abroad_school", "abroad_major", "phone", "email", "annual_salary", "pro_qua"];
  321. foreach ($all_valid_keys as $key) {
  322. $data[$key] = trim($param[$key]);
  323. }
  324. if (in_array($data["talent_type"], [1, 2])) {
  325. $data["tax_insurance_month"] = $param["tax_insurance_month"];
  326. $data["labor_contract_rangetime"] = $param["labor_contract_rangetime"];
  327. $data["salary_pay_way"] = $param["salary_pay_way"];
  328. $data["salary_pay_month"] = $param["salary_pay_month"];
  329. $data["fst_work_time"] = $param["fst_work_time"];
  330. $data['pre_import_type'] = null;
  331. } else {
  332. $data["tax_insurance_month"] = null;
  333. $data["labor_contract_rangetime"] = null;
  334. $data["salary_pay_way"] = null;
  335. $data["salary_pay_month"] = null;
  336. $data["fst_work_time"] = null;
  337. $data['pre_import_type'] = $param["pre_import_type"];
  338. }
  339. if ($data["study_abroad"] == 1) {
  340. $data["abroad_school"] = $param["abroad_school"];
  341. $data["abroad_major"] = $param["abroad_major"];
  342. } else {
  343. $data["abroad_school"] = null;
  344. $data["abroad_major"] = null;
  345. }
  346. switch ($data["source"]) {
  347. case 1:
  348. $data["source_batch"] = $param["source_batch"];
  349. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  350. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  351. $data["source_city"] = null;
  352. break;
  353. case 2:
  354. $data["source_batch"] = $param["source_batch"];
  355. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  356. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  357. $data["source_county"] = null;
  358. break;
  359. case 3:
  360. $data["source_batch"] = $param["source_batch"];
  361. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  362. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  363. $data["source_city"] = $param["source_city"];
  364. break;
  365. case 4:
  366. $data["source_batch"] = $param["source_batch"];
  367. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  368. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  369. $data["source_county"] = $param["source_county"];
  370. break;
  371. }
  372. $condition_info = Db::table("new_talent_condition")->findOrEmpty($param["talent_condition"]);
  373. if ($condition_info["isSalary"] == 1) {
  374. $data["annual_salary"] = $param["annual_salary"];
  375. } else {
  376. $data["annual_salary"] = null;
  377. }
  378. if ($info["real_state"] == TalentState::FST_VERIFY_REJECT) {
  379. //真实状态11是驳回,需要判断什么字段可以提交
  380. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  381. $tmp_data = $data;
  382. $data = [];
  383. foreach ($modify_fields as $field) {
  384. $data[$field] = $tmp_data[$field];
  385. }
  386. }
  387. $data["checkState"] = $checkState;
  388. $data["id"] = $id;
  389. $success_msg = "提交成功";
  390. $error_msg = "提交失败";
  391. if ($checkState == TalentState::SCND_SAVE) {
  392. $success_msg = "保存成功";
  393. if ($data["id"]) {
  394. //编辑
  395. TalentModel::update($data);
  396. $last_log = TalentLogApi::getLastLog($data["id"], 1);
  397. if ($last_log["new_state"] != TalentState::SCND_SAVE) {
  398. TalentLogApi::write(1, $data["id"], $checkState, "保存未提交", 1);
  399. } else {
  400. TalentLogApi::setActive($last_log["id"], 1); //更新修改时间
  401. }
  402. } else {
  403. //新增
  404. $data["enterprise_id"] = $this->user["uid"];
  405. $id = TalentModel::insertGetId($data);
  406. TalentLogApi::write(1, $id, $checkState, "保存未提交", 1);
  407. $whr = [];
  408. $whr[] = ["fileId", "in", $files];
  409. $upd_checklog["mainId"] = $id;
  410. Db::table("new_talent_checklog")->where($whr)->save($upd_checklog);
  411. }
  412. } else if ($checkState == TalentState::SCND_SUBMIT) {
  413. if (!$info["first_submit_time"]) {
  414. $data["first_submit_time"] = date("Y-m-d H:i:s");
  415. } else {
  416. $data["new_submit_time"] = date("Y-m-d H:i:s");
  417. }
  418. if ($data["id"]) {
  419. TalentModel::update($data);
  420. } else {
  421. //新增
  422. $data["enterprise_id"] = $this->user["uid"];
  423. $id = TalentModel::insertGetId($data);
  424. $whr = [];
  425. $whr[] = ["fileId", "in", $files];
  426. $upd_checklog["mainId"] = $id;
  427. Db::table("new_talent_checklog")->where($whr)->save($upd_checklog);
  428. }
  429. TalentLogApi::write(1, $id, $checkState, "确认提交审核", 1);
  430. } else {
  431. throw new ValidateException($error_msg);
  432. }
  433. if ($id) {
  434. if ($deletes) {
  435. //删除多余的附件,一般是选择人才类型留下来的
  436. $whr = [];
  437. $whr[] = ["typeId", "in", $deletes];
  438. $whr[] = ["id", "in", $files];
  439. $_wait_del_files = Db::table("new_talent_file")->where($whr)->select()->toArray();
  440. $_logfileIds[] = [];
  441. foreach ($_wait_del_files as $_del_file) {
  442. $_logfileIds[] = $_del_file["id"];
  443. @unlink("storage/" . $_del_file["url"]);
  444. }
  445. Db::table("new_talent_file")->where($whr)->delete();
  446. if ($_logfileIds) {
  447. $whr = [];
  448. $whr[] = ["fileId", "in", $_logfileIds];
  449. $_upd_checklog["description"] = "删除附件";
  450. $_upd_checklog["updateUser"] = sprintf("%s(%s)", $this->user["account"], $this->user["companyName"] ?: $this->user["rolename"]);
  451. $_upd_checklog["updateTime"] = date("Y-m-d H:i:s");
  452. Db::table("new_talent_checklog")->where($whr)->save($_upd_checklog);
  453. }
  454. }
  455. $whr = [];
  456. $whr[] = ["id", "in", $files];
  457. Db::table("new_talent_file")->where($whr)->save(["mainId" => $id]);
  458. $res = ["code" => 200, "msg" => $success_msg, "obj" => ["id" => $id, "checkState" => $checkState]];
  459. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  460. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  461. exit();
  462. } else {
  463. throw new ValidateException($error_msg);
  464. }
  465. } catch (ValidateException $e) {
  466. $res = ["msg" => $e->getMessage()];
  467. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  468. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  469. exit();
  470. }
  471. }
  472. public function delete() {
  473. $id = $this->request->param("talentInfoId");
  474. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  475. if (!$info) {
  476. return json(["msg" => "操作失败"]);
  477. }
  478. $checkState = $info["checkState"];
  479. if (in_array($checkState, [0, 1])) {
  480. $log = TalentLogApi::getLastLog($id, 1);
  481. if ($log["state"] > 1) {
  482. //有提交审核记录
  483. return json(["msg" => "该申报已提交审核,无法删除"]);
  484. }
  485. }
  486. $data["id"] = $id;
  487. $data["delete"] = 1;
  488. TalentModel::update($data);
  489. return json(["msg" => "删除成功"]);
  490. }
  491. }