Talent.php 13 KB

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