Talent.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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\EnterpriseApi;
  8. use app\common\api\DictApi;
  9. use app\common\api\TalentLogApi;
  10. use app\common\api\TalentState;
  11. use think\exception\ValidateException;
  12. use app\enterprise\validate\TalentInfo;
  13. // 0正在填写 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  14. /**
  15. * Description of Talent
  16. *
  17. * @author sgq
  18. */
  19. class Talent extends EnterpriseController {
  20. public function index() {
  21. return view();
  22. }
  23. public function list() {
  24. $step = 2;
  25. $res = TalentApi::getList($this->request, $step);
  26. return json($res);
  27. }
  28. /**
  29. * 人才申报企业端统一申报入口
  30. */
  31. public function apply(\think\Request $request) {
  32. $type = $this->user["type"];
  33. $tpl = "";
  34. switch ($type) {
  35. case 1:
  36. $tpl = "apply"; //晋江人才
  37. break;
  38. case 2:
  39. $tpl = "ic_apply"; //集成电路
  40. break;
  41. }
  42. $param = $request->param();
  43. $id = isset($param["id"]) ? $param["id"] : 0;
  44. $info = TalentApi::chkIsOwner($id, $this->user["uid"]);
  45. $ep = EnterpriseApi::getOne($this->user["uid"]);
  46. if (!chkEnterpriseFull($ep))
  47. return;
  48. $tagList = DictApi::selectByParentCode('enterprise_tag');
  49. $streetList = DictApi::selectByParentCode('street');
  50. $industryFieldNew = DictApi::selectByParentCode('industry_field');
  51. $ep->enterpristTagName = $tagList[$ep->enterpriseTag];
  52. $ep->streetName = $streetList[$ep->street];
  53. $ep->industryFieldNewName = $industryFieldNew[$ep->industryFieldNew];
  54. if ($info) {
  55. $info["real_state"] = TalentLogApi::getLastLog($id, $type)["state"];
  56. }
  57. if ($info && in_array($info["checkState"], [TalentState::FST_VERIFY_PASS, TalentState::DEPT_VERIFY_PASS, TalentState::REVERIFY_PASS, TalentState::REVERIFY_FAIL])) {
  58. return $this->view($request);
  59. exit();
  60. }
  61. if ($request->isPost()) {
  62. $checkState = $info["checkState"] ?: 0;
  63. if ($checkState == TalentState::FST_SAVE || $checkState == 0) {
  64. $this->save($info, $request, TalentState::FST_SAVE);
  65. exit();
  66. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL])) {
  67. $res = ["msg" => "审核失败,不能再保存"];
  68. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  69. exit;
  70. }
  71. $res = ["msg" => "已提交审核,请耐心等待"];
  72. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  73. exit;
  74. }
  75. $checkState = $info["checkState"] ?: 0;
  76. $info["enterprise"] = $ep;
  77. $info["talent_type_list"] = DictApi::findChildDictByCode("talent_type");
  78. return view($tpl, ["year" => date("Y"), "checkState" => $checkState, "row" => $info]);
  79. }
  80. public function second(\think\Request $request) {
  81. $params = $request->param();
  82. $id = $params["id"];
  83. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  84. $info["real_state"] = TalentLogApi::getLastLog($id, 1)["state"];
  85. if ($request->isPost()) {
  86. if (!$info || $info["enterprise_id"] != $this->user["uid"]) {
  87. $res = ["msg" => "没有对应的人才认定申报信息"];
  88. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  89. exit;
  90. }
  91. $checkState = $info["checkState"];
  92. if ($checkState == TalentState::SCND_SAVE || $checkState == TalentState::BASE_REVERIFY_PASS) {
  93. $this->save($info, $request, TalentState::SCND_SAVE);
  94. exit();
  95. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL])) {
  96. $res = ["msg" => "审核失败,不能再保存"];
  97. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  98. exit;
  99. }
  100. $res = ["msg" => "已提交审核,请耐心等待"];
  101. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  102. exit;
  103. }
  104. $enterprise_info = \app\common\model\Enterprise::find($this->user["uid"]);
  105. $info["enterprise"] = $enterprise_info;
  106. $batch = \app\common\api\BatchApi::getValidBatch(1, $enterprise_info["type"]);
  107. return view("second", ["year" => $info["apply_year"] ?: $batch["batch"], "row" => $info]);
  108. }
  109. public function view(\think\Request $request) {
  110. switch ($this->user["type"]) {
  111. case 1:
  112. $tpl = "view"; //晋江人才
  113. break;
  114. case 2:
  115. $tpl = "ic_view"; //集成电路
  116. break;
  117. }
  118. $id = $request->param("id");
  119. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  120. return view($tpl, ["row" => $info]);
  121. }
  122. // 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  123. public function submit() {
  124. $params = $this->request->param();
  125. $id = $params["id"];
  126. if (!$info = TalentApi::chkIsOwner($id, $this->user["uid"])) {
  127. $res = ["msg" => "没有对应的人才认定申报信息"];
  128. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  129. exit;
  130. }
  131. $checkState = $info["checkState"];
  132. if ($checkState == TalentState::SCND_SAVE || $checkState == TalentState::BASE_REVERIFY_PASS) {
  133. $field_dict = \app\common\api\DictApi::getTalentFields(2);
  134. $no_empty = ["talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "bank", "bank_number", "bank_branch_name",
  135. "bank_account", "study_abroad", "phone", "email", "import_way", "cur_entry_time", "cur_entry_time", "position", "source"];
  136. $where = [];
  137. $where[] = ["rel", "=", "study_abroad"];
  138. $where[] = ["step", "=", 2];
  139. $where[] = ["project", "=", 1];
  140. $where[] = ["active", "=", 1];
  141. $where[] = ["delete", "=", 0];
  142. $where[] = ["type", "=", $this->user["type"]];
  143. $where[] = ["isConditionFile", "<>", 1];
  144. $abroad_files = Db::table("new_common_filetype")->where($where)->select()->toArray(); //留学的附件
  145. $abroad_file_ids = null;
  146. if ($abroad_files)
  147. $abroad_file_ids = array_column($abroad_files, "id");
  148. if ($params["study_abroad"] == 1) {
  149. $no_empty[] = "abroad_school";
  150. $no_empty[] = "abroad_major";
  151. }
  152. if (in_array($params["source"], [1, 3])) {
  153. $no_empty[] = "source_batch";
  154. $no_empty[] = "fujian_highcert_pubtime";
  155. $no_empty[] = "fujian_highcert_exptime";
  156. if ($params["source"] == 3) {
  157. $no_empty[] = "source_city";
  158. }
  159. }
  160. if (in_array($params["source"], [2, 4])) {
  161. $no_empty[] = "source_batch";
  162. $no_empty[] = "quanzhou_highcert_pubtime";
  163. $no_empty[] = "quanzhou_highcert_exptime";
  164. if ($params["source"] == 4) {
  165. $no_empty[] = "source_county";
  166. }
  167. }
  168. $condition_info = Db::table("new_talent_condition")->findOrEmpty($params["talent_condition"]);
  169. if ($condition_info["isSalary"] == 1) {
  170. $no_empty[] = "annual_salary";
  171. }
  172. $no_empty = array_filter($no_empty);
  173. $return = [];
  174. foreach ($no_empty as $key) {
  175. if (!$params[$key]) {
  176. $return[] = sprintf("请填写“%s”", $field_dict[$key]);
  177. }
  178. }
  179. if (count($return) > 0) {
  180. $res = ["msg" => implode("<br>", $return)];
  181. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  182. exit;
  183. }
  184. if ($condition_info["bindFileTypes"] && $info["source"] == 5) {
  185. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  186. $whr[] = ["must", "=", 1];
  187. }
  188. $where = [];
  189. $where[] = ["step", "=", 2];
  190. $where[] = ["project", "=", 1];
  191. $where[] = ["type", "=", $this->user["type"]];
  192. $where[] = ["must", "=", 1];
  193. $where[] = ["active", "=", 1];
  194. $where[] = ["delete", "=", 0];
  195. $where[] = ["isConditionFile", "<>", 1];
  196. if ($whr) {
  197. $filetypes = Db::table("new_common_filetype")->whereOr([$where, $whr])->select()->toArray();
  198. } else {
  199. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  200. }
  201. $ft_ids = array_column($filetypes, "id");
  202. if ($params["study_abroad"] == 1) {
  203. //选中留学,如果存在留学附件变成必传
  204. $ft_ids = array_unique(array_merge($ft_ids, (array) $abroad_file_ids));
  205. } else {
  206. //没选中,留学附件就算设成必传也不用验证
  207. $ft_ids = array_diff($ft_ids, (array) $abroad_file_ids);
  208. }
  209. $whr = [];
  210. $whr[] = ["typeId", "in", $ft_ids];
  211. $whr[] = ["mainId", "=", $id];
  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. $this->save($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])) {
  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(1, $this->user["type"]);
  237. if (!$batch) {
  238. throw new ValidateException("不在人才认定申报申请时间内");
  239. }
  240. $param = $request->param();
  241. validate(TalentInfo::class)->check($param);
  242. $data["apply_year"] = $batch["batch"];
  243. $all_valid_keys = ["applay_year", "import_way", "cur_entry_time", "position",
  244. "source", "source_batch", "fujian_highcert_pubtime", "fujian_highcert_exptime", "quanzhou_highcert_pubtime", "quanzhou_highcert_exptime", "source_city", "source_county",
  245. "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "professional", "bank", "bank_number", "bank_branch_name", "bank_account",
  246. "study_abroad", "abroad_school", "abroad_major", "phone", "email", "annual_salary", "pro_qua"];
  247. foreach ($all_valid_keys as $key) {
  248. $data[$key] = trim($param[$key]);
  249. }
  250. if ($data["study_abroad"] == 1) {
  251. $data["abroad_school"] = $param["abroad_school"];
  252. $data["abroad_major"] = $param["abroad_major"];
  253. } else {
  254. $data["abroad_school"] = null;
  255. $data["abroad_major"] = null;
  256. }
  257. switch ($data["source"]) {
  258. case 1:
  259. $data["source_batch"] = $param["source_batch"];
  260. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  261. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  262. $data["source_city"] = null;
  263. break;
  264. case 2:
  265. $data["source_batch"] = $param["source_batch"];
  266. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  267. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  268. $data["source_county"] = null;
  269. break;
  270. case 3:
  271. $data["source_batch"] = $param["source_batch"];
  272. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  273. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  274. $data["source_city"] = $param["source_city"];
  275. break;
  276. case 4:
  277. $data["source_batch"] = $param["source_batch"];
  278. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  279. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  280. $data["source_county"] = $param["source_county"];
  281. break;
  282. }
  283. $condition_info = Db::table("new_talent_condition")->findOrEmpty($param["talent_condition"]);
  284. if ($condition_info["isSalary"] == 1) {
  285. $data["annual_salary"] = $param["annual_salary"];
  286. } else {
  287. $data["annual_salary"] = null;
  288. }
  289. if ($info["real_state"] == TalentState::FST_VERIFY_REJECT) {
  290. //真实状态8是驳回,需要判断什么字段可以提交
  291. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  292. $tmp_data = $data;
  293. $data = [];
  294. foreach ($modify_fields as $field) {
  295. $data[$field] = $tmp_data[$field];
  296. }
  297. }
  298. $data["checkState"] = $checkState;
  299. $data["id"] = $info["id"];
  300. $success_msg = "提交成功";
  301. $error_msg = "提交失败";
  302. if ($checkState == TalentState::SCND_SAVE) {
  303. $last_log = TalentLogApi::getLastLog($data["id"], 1);
  304. if ($last_log["new_state"] != TalentState::SCND_SAVE) {
  305. TalentLogApi::write(1, $data["id"], $checkState, "保存认定材料未提交", 1);
  306. }
  307. TalentModel::update($data);
  308. } else if ($checkState == TalentState::SCND_SUBMIT) {
  309. $success_msg = "提交成功";
  310. $error_msg = "提交失败";
  311. $data["new_submit_time"] = date("Y-m-d H:i:s");
  312. TalentModel::update($data);
  313. TalentLogApi::write(1, $info["id"], $checkState, "确认提交审核", 1);
  314. } else {
  315. throw new ValidateException($error_msg);
  316. }
  317. $res = ["code" => 200, "msg" => $success_msg, "obj" => ["id" => $info["id"], "checkState" => $checkState]];
  318. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  319. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  320. exit();
  321. } catch (ValidateException $e) {
  322. $res = ["msg" => $e->getMessage()];
  323. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  324. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  325. exit();
  326. }
  327. }
  328. public function delete() {
  329. $id = $this->request->param("talentInfoId");
  330. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  331. if (!$info) {
  332. return json(["msg" => "操作失败"]);
  333. }
  334. $checkState = $info["checkState"];
  335. if (in_array($checkState, [0, 1])) {
  336. $log = TalentLogApi::getLastLog($id, 1);
  337. if ($log["state"] > 1) {
  338. //有提交审核记录
  339. return json(["msg" => "操作失败"]);
  340. }
  341. }
  342. $data["id"] = $id;
  343. $data["delete"] = 1;
  344. TalentModel::update($data);
  345. return json(["msg" => "删除成功"]);
  346. }
  347. }