Talent.php 14 KB

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