Integral.php 23 KB

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