Talent.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?php
  2. namespace app\enterprise\controller;
  3. use app\enterprise\common\EnterpriseController;
  4. use app\enterprise\api\TalentApi;
  5. use app\enterprise\model\Talent as TalentModel;
  6. use think\facade\Db;
  7. use app\common\api\TalentLogApi;
  8. use app\common\api\TalentState;
  9. use think\exception\ValidateException;
  10. use app\enterprise\validate\TalentInfo;
  11. // 0正在填写 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  12. /**
  13. * Description of Talent
  14. *
  15. * @author sgq
  16. */
  17. class Talent extends EnterpriseController {
  18. public function index() {
  19. return view();
  20. }
  21. public function list() {
  22. $step = 2;
  23. $res = TalentApi::getList($this->request, $step);
  24. return json($res);
  25. }
  26. public function second(\think\Request $request) {
  27. $params = $request->param();
  28. $id = $params["id"];
  29. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  30. $info["real_state"] = TalentLogApi::getLastLog($id, 1)["state"];
  31. if ($request->isPost()) {
  32. if (!$info || $info["enterprise_id"] != $this->user["uid"]) {
  33. $res = ["msg" => "没有对应的人才认定申报信息"];
  34. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  35. exit;
  36. }
  37. $checkState = $info["checkState"];
  38. if ($checkState == TalentState::SCND_SAVE || $checkState == TalentState::BASE_REVERIFY_PASS) {
  39. $this->save($info, $request, TalentState::SCND_SAVE);
  40. exit();
  41. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL])) {
  42. $res = ["msg" => "审核失败,不能再保存"];
  43. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  44. exit;
  45. }
  46. $res = ["msg" => "已提交审核,请耐心等待"];
  47. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  48. exit;
  49. }
  50. $enterprise_info = \app\common\model\Enterprise::find($this->user["uid"]);
  51. $info["enterprise"] = $enterprise_info;
  52. $batch = \app\common\api\BatchApi::getValidBatch(1, $enterprise_info["type"]);
  53. return view("second", ["year" => $info["apply_year"] ?: $batch["batch"], "row" => $info]);
  54. }
  55. public function view(\think\Request $request) {
  56. $id = $request->param("id");
  57. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  58. return view("view", ["row" => $info]);
  59. }
  60. // 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  61. public function submit() {
  62. $params = $this->request->param();
  63. $id = $params["id"];
  64. if (!$info = TalentApi::chkIsOwner($id, $this->user["uid"])) {
  65. $res = ["msg" => "没有对应的人才认定申报信息"];
  66. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  67. exit;
  68. }
  69. $checkState = $info["checkState"];
  70. if ($checkState == TalentState::SCND_SAVE || $checkState == TalentState::BASE_REVERIFY_PASS) {
  71. $field_dict = \app\common\api\DictApi::getTalentFields(2);
  72. $no_empty = ["talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "bank", "bank_number", "bank_branch_name",
  73. "bank_account", "study_abroad", "phone", "email", "import_way", "cur_entry_time", "cur_entry_time", "position", "source"];
  74. $where = [];
  75. $where[] = ["rel", "=", "study_abroad"];
  76. $where[] = ["step", "=", 2];
  77. $where[] = ["project", "=", 1];
  78. $where[] = ["active", "=", 1];
  79. $where[] = ["delete", "=", 0];
  80. $where[] = ["type", "=", $this->user["type"]];
  81. $where[] = ["isConditionFile", "<>", 1];
  82. $abroad_files = Db::table("new_common_filetype")->where($where)->select()->toArray(); //留学的附件
  83. $abroad_file_ids = null;
  84. if ($abroad_files)
  85. $abroad_file_ids = array_column($abroad_files, "id");
  86. if ($params["study_abroad"] == 1) {
  87. $no_empty[] = "abroad_school";
  88. $no_empty[] = "abroad_major";
  89. }
  90. if (in_array($params["source"], [1, 3])) {
  91. $no_empty[] = "source_batch";
  92. $no_empty[] = "fujian_highcert_pubtime";
  93. $no_empty[] = "fujian_highcert_exptime";
  94. if ($params["source"] == 3) {
  95. $no_empty[] = "source_city";
  96. }
  97. }
  98. if (in_array($params["source"], [2, 4])) {
  99. $no_empty[] = "source_batch";
  100. $no_empty[] = "quanzhou_highcert_pubtime";
  101. $no_empty[] = "quanzhou_highcert_exptime";
  102. if ($params["source"] == 4) {
  103. $no_empty[] = "source_county";
  104. }
  105. }
  106. $condition_info = Db::table("new_talent_condition")->findOrEmpty($params["talent_condition"]);
  107. if ($condition_info["isSalary"] == 1) {
  108. $no_empty[] = "annual_salary";
  109. }
  110. $no_empty = array_filter($no_empty);
  111. $return = [];
  112. foreach ($no_empty as $key) {
  113. if (!$params[$key]) {
  114. $return[] = sprintf("请填写“%s”", $field_dict[$key]);
  115. }
  116. }
  117. if (count($return) > 0) {
  118. $res = ["msg" => implode("<br>", $return)];
  119. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  120. exit;
  121. }
  122. if ($condition_info["bindFileTypes"] && $info["source"] == 5) {
  123. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  124. $whr[] = ["must", "=", 1];
  125. }
  126. $where = [];
  127. $where[] = ["step", "=", 2];
  128. $where[] = ["project", "=", 1];
  129. $where[] = ["type", "=", $this->user["type"]];
  130. $where[] = ["must", "=", 1];
  131. $where[] = ["active", "=", 1];
  132. $where[] = ["delete", "=", 0];
  133. $where[] = ["isConditionFile", "<>", 1];
  134. if ($whr) {
  135. $filetypes = Db::table("new_common_filetype")->whereOr([$where, $whr])->select()->toArray();
  136. } else {
  137. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  138. }
  139. $ft_ids = array_column($filetypes, "id");
  140. if ($params["study_abroad"] == 1) {
  141. //选中留学,如果存在留学附件变成必传
  142. $ft_ids = array_unique(array_merge($ft_ids, (array) $abroad_file_ids));
  143. } else {
  144. //没选中,留学附件就算设成必传也不用验证
  145. $ft_ids = array_diff($ft_ids, (array) $abroad_file_ids);
  146. }
  147. $whr = [];
  148. $whr[] = ["typeId", "in", $ft_ids];
  149. $whr[] = ["mainId", "=", $id];
  150. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  151. $upload_type_counts = count($distinct_filetypes);
  152. if ($upload_type_counts != count($ft_ids)) {
  153. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
  154. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  155. exit;
  156. }
  157. $this->save($info, $this->request, TalentState::SCND_SUBMIT);
  158. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL])) {
  159. $res = ["msg" => "审核失败,不能再提交审核"];
  160. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  161. exit;
  162. }
  163. $res = ["msg" => "已提交审核,请耐心等待"];
  164. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  165. exit;
  166. }
  167. /**
  168. * 保存表单
  169. * @param type $info talent_info
  170. * @param type $param request->param();
  171. */
  172. private function save($info, \think\Request $request, $checkState) {
  173. try {
  174. $batch = \app\common\api\BatchApi::getValidBatch(1, $this->user["type"]);
  175. if (!$batch) {
  176. throw new ValidateException("不在人才认定申报申请时间内");
  177. }
  178. $param = $request->param();
  179. validate(TalentInfo::class)->check($param);
  180. $data["apply_year"] = $batch["batch"];
  181. $all_valid_keys = ["applay_year", "import_way", "cur_entry_time", "position",
  182. "source", "source_batch", "fujian_highcert_pubtime", "fujian_highcert_exptime", "quanzhou_highcert_pubtime", "quanzhou_highcert_exptime", "source_city", "source_county",
  183. "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "professional", "bank", "bank_number", "bank_branch_name", "bank_account",
  184. "study_abroad", "abroad_school", "abroad_major", "phone", "email", "annual_salary", "pro_qua"];
  185. foreach ($all_valid_keys as $key) {
  186. $data[$key] = trim($param[$key]);
  187. }
  188. if ($data["study_abroad"] == 1) {
  189. $data["abroad_school"] = $param["abroad_school"];
  190. $data["abroad_major"] = $param["abroad_major"];
  191. } else {
  192. $data["abroad_school"] = null;
  193. $data["abroad_major"] = null;
  194. }
  195. switch ($data["source"]) {
  196. case 1:
  197. $data["source_batch"] = $param["source_batch"];
  198. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  199. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  200. $data["source_city"] = null;
  201. break;
  202. case 2:
  203. $data["source_batch"] = $param["source_batch"];
  204. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  205. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  206. $data["source_county"] = null;
  207. break;
  208. case 3:
  209. $data["source_batch"] = $param["source_batch"];
  210. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  211. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  212. $data["source_city"] = $param["source_city"];
  213. break;
  214. case 4:
  215. $data["source_batch"] = $param["source_batch"];
  216. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  217. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  218. $data["source_county"] = $param["source_county"];
  219. break;
  220. }
  221. $condition_info = Db::table("new_talent_condition")->findOrEmpty($param["talent_condition"]);
  222. if ($condition_info["isSalary"] == 1) {
  223. $data["annual_salary"] = $param["annual_salary"];
  224. } else {
  225. $data["annual_salary"] = null;
  226. }
  227. if ($info["real_state"] == TalentState::FST_VERIFY_REJECT) {
  228. //真实状态8是驳回,需要判断什么字段可以提交
  229. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  230. $tmp_data = $data;
  231. $data = [];
  232. foreach ($modify_fields as $field) {
  233. $data[$field] = $tmp_data[$field];
  234. }
  235. }
  236. $data["checkState"] = $checkState;
  237. $data["id"] = $info["id"];
  238. $success_msg = "提交成功";
  239. $error_msg = "提交失败";
  240. if ($checkState == TalentState::SCND_SAVE) {
  241. $last_log = TalentLogApi::getLastLog($data["id"], 1);
  242. if ($last_log["new_state"] != TalentState::SCND_SAVE) {
  243. TalentLogApi::write(1, $data["id"], $checkState, "保存认定材料未提交", 1);
  244. }
  245. TalentModel::update($data);
  246. } else if ($checkState == TalentState::SCND_SUBMIT) {
  247. $success_msg = "提交成功";
  248. $error_msg = "提交失败";
  249. $data["new_submit_time"] = date("Y-m-d H:i:s");
  250. TalentModel::update($data);
  251. TalentLogApi::write(1, $info["id"], $checkState, "确认提交审核", 1);
  252. } else {
  253. throw new ValidateException($error_msg);
  254. }
  255. $res = ["code" => 200, "msg" => $success_msg, "obj" => ["id" => $info["id"], "checkState" => $checkState]];
  256. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  257. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  258. exit();
  259. } catch (ValidateException $e) {
  260. $res = ["msg" => $e->getMessage()];
  261. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  262. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  263. exit();
  264. }
  265. }
  266. public function delete() {
  267. $id = $this->request->param("talentInfoId");
  268. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  269. if (!$info) {
  270. return json(["msg" => "操作失败"]);
  271. }
  272. $checkState = $info["checkState"];
  273. if (in_array($checkState, [0, 1])) {
  274. $log = TalentLogApi::getLastLog($id, 1);
  275. if ($log["state"] > 1) {
  276. //有提交审核记录
  277. return json(["msg" => "操作失败"]);
  278. }
  279. }
  280. $data["id"] = $id;
  281. $data["delete"] = 1;
  282. TalentModel::update($data);
  283. return json(["msg" => "删除成功"]);
  284. }
  285. }