Integral.php 23 KB

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