Talent.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. // 0正在填写 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  10. /**
  11. * Description of Talent
  12. *
  13. * @author sgq
  14. */
  15. class Talent extends EnterpriseController {
  16. public function index() {
  17. return view();
  18. }
  19. public function list() {
  20. $res = TalentApi::getList($this->request);
  21. return json($res);
  22. }
  23. public function second(\think\Request $request) {
  24. $params = $request->param();
  25. $id = $params["id"];
  26. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  27. if (!$info || $info["enterprise_id"] != $this->user["uid"]) {
  28. $res = ["msg" => "错误的访问方式"];
  29. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  30. exit;
  31. }
  32. $info["real_state"] = TalentLogApi::getLastLog($id, 1)["state"];
  33. if ($request->isPost()) {
  34. $batch = \app\common\api\BatchApi::getValidBatch(1, $this->user["type"]);
  35. if (!$batch) {
  36. $res = ["msg" => "不在人才认定申报申请时间内"];
  37. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  38. exit;
  39. }
  40. $field_dict = \app\common\api\DictApi::getTalentFields(2);
  41. //可以用匹配键的方式,可以少很多代码。。先这样吧。
  42. $all_valid_keys = ["applay_year", "import_way", "cur_entry_time", "position",
  43. "source", "source_batch", "fujian_highcert_pubtime", "fujian_highcert_exptime", "quanzhou_highcert_pubtime", "quanzhou_highcert_exptime", "source_city", "source_county",
  44. "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "professional", "bank", "bank_number", "bank_branch_name", "bank_account",
  45. "study_abroad", "abroad_school", "abroad_major", "phone", "email", "annual_salary"];
  46. foreach ($all_valid_keys as $key) {
  47. $data[$key] = trim($params[$key]);
  48. if (strpos($key, "time") !== false && strtotime($params[$key]) === false) {
  49. unset($data[$key]); //时间格式的验证不通过就清掉,下面判断是否为空如果赫然在列就不能通过
  50. }
  51. }
  52. $no_empty = ["talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "bank", "bank_number", "bank_branch_name",
  53. "bank_account", "study_abroad", "phone", "email", "import_way", "cur_entry_time", "cur_entry_time", "position", "source"];
  54. $where = [];
  55. $where[] = ["rel", "=", "study_abroad"];
  56. $where[] = ["step", "=", 2];
  57. $where[] = ["project", "=", 1];
  58. $where[] = ["active", "=", 1];
  59. $where[] = ["delete", "=", 0];
  60. $where[] = ["type", "=", $this->user["type"]];
  61. $where[] = ["isConditionFile", "<>", 1];
  62. $abroad_files = Db::table("new_common_filetype")->where($where)->select()->toArray(); //留学的附件
  63. $abroad_file_ids = null;
  64. if ($abroad_files)
  65. $abroad_file_ids = array_column($abroad_files, "id");
  66. if ($data["study_abroad"] == 1) {
  67. $no_empty[] = "abroad_school";
  68. $no_empty[] = "abroad_major";
  69. }
  70. if (in_array($data["source"], [1, 3])) {
  71. $no_empty[] = "source_batch";
  72. $no_empty[] = "fujian_highcert_pubtime";
  73. $no_empty[] = "fujian_highcert_exptime";
  74. if ($data["source"] == 3) {
  75. $no_empty[] = "source_city";
  76. }
  77. }
  78. if (in_array($data["source"], [2, 4])) {
  79. $no_empty[] = "source_batch";
  80. $no_empty[] = "quanzhou_highcert_pubtime";
  81. $no_empty[] = "quanzhou_highcert_exptime";
  82. if ($data["source"] == 4) {
  83. $no_empty[] = "source_county";
  84. }
  85. }
  86. $condition_info = Db::table("new_talent_condition")->findOrEmpty($params["talent_condition"]);
  87. if ($condition_info["isSalary"] == 1) {
  88. $no_empty[] = "annual_salary";
  89. }
  90. $no_empty = array_filter($no_empty);
  91. $return = [];
  92. foreach ($no_empty as $key) {
  93. if (!$data[$key]) {
  94. $return[] = sprintf("请填写“%s”", $field_dict[$key]);
  95. }
  96. }
  97. if (count($return) > 0) {
  98. $res = ["msg" => implode("<br>", $return)];
  99. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  100. exit;
  101. }
  102. if (!preg_match("/^(13|14|15|17|18|19)[\d]{9}$/", $data["phone"])) {
  103. $res = ["msg" => "手机号码格式错误"];
  104. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  105. exit;
  106. }
  107. if (!filter_var($data["email"], FILTER_VALIDATE_EMAIL)) {
  108. $res = ["msg" => "电子邮箱格式错误"];
  109. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  110. exit;
  111. }
  112. if (!in_array($data["talent_arrange"], [1, 2, 3, 4, 5, 6, 7])) {
  113. $res = ["msg" => "人才层次只能在预设范围内选择"];
  114. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  115. exit;
  116. }
  117. if (!in_array($data["source"], [1, 2, 3, 4, 5])) {
  118. $res = ["msg" => "来源只能在预设范围内选择"];
  119. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  120. exit;
  121. }
  122. if ($condition_info["bindFileTypes"]) {
  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")->where([$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 ($data["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.infoCallback(%s);</script>", json_encode($res));
  155. exit;
  156. }
  157. if ($info["real_state"] == 8) {
  158. //真实状态8是驳回,需要判断什么字段可以提交
  159. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  160. $tmp_data = $data;
  161. $data = [];
  162. foreach ($modify_fields as $field) {
  163. $data[$field] = $tmp_data[$field];
  164. }
  165. }
  166. $data["apply_year"] = $batch["batch"];
  167. $data["id"] = $id;
  168. $data["checkState"] = TalentState::SCND_SAVE;
  169. if (TalentModel::update($data)) {
  170. $res = ["code" => 200, "msg" => "保存成功", "obj" => ["id" => $id, "checkState" => TalentState::SCND_SAVE]];
  171. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  172. } else {
  173. $res = ["code" => 500, "msg" => "保存失败"];
  174. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  175. }
  176. exit();
  177. }
  178. $enterprise_info = \app\common\model\Enterprise::find($this->user["uid"]);
  179. $info["enterprise"] = $enterprise_info;
  180. $batch = \app\common\api\BatchApi::getValidBatch(1, $enterprise_info["type"]);
  181. return view("second", ["year" => $info["apply_year"] ?: $batch["batch"], "row" => $info]);
  182. }
  183. public function view(\think\Request $request) {
  184. $id = $request->param("id");
  185. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  186. return view("view", ["row" => $info]);
  187. }
  188. // 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  189. public function submit() {
  190. $id = $this->request->param("id");
  191. if (!$info = self::chkIsOwner($id, $this->user["uid"]))
  192. return json(["msg" => "没有对应的人才认定申报信息"]);
  193. $checkState = $info["checkState"];
  194. if ($checkState == TalentState::BASE_VERIFY_PASS || $checkState == 0) {
  195. return json(["msg" => '请先保存资料并上传相应附件后再点击提交审核']);
  196. } else if ($checkState == TalentState::SCND_SAVE) {
  197. $condition_info = Db::table("new_talent_condition")->findOrEmpty($info["talent_condition"]);
  198. if ($condition_info["bindFileTypes"]) {
  199. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  200. $whr[] = ["must", "=", 1];
  201. }
  202. $where = [];
  203. $where[] = ["rel", "=", "study_abroad"];
  204. $where[] = ["step", "=", 2];
  205. $where[] = ["project", "=", 1];
  206. $where[] = ["active", "=", 1];
  207. $where[] = ["delete", "=", 0];
  208. $where[] = ["type", "=", $this->user["type"]];
  209. $where[] = ["isConditionFile", "<>", 1];
  210. $abroad_files = Db::table("new_common_filetype")->where($where)->select()->toArray(); //留学的附件
  211. $abroad_file_ids = null;
  212. if ($abroad_files)
  213. $abroad_file_ids = array_column($abroad_files, "id");
  214. $where = [];
  215. $where[] = ["step", "=", 2];
  216. $where[] = ["project", "=", 1];
  217. $where[] = ["type", "=", $this->user["type"]];
  218. $where[] = ["must", "=", 1];
  219. $where[] = ["active", "=", 1];
  220. $where[] = ["delete", "=", 0];
  221. $where[] = ["isConditionFile", "<>", 1];
  222. if ($whr) {
  223. $filetypes = Db::table("new_common_filetype")->where([$where, $whr])->select()->toArray();
  224. } else {
  225. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  226. }
  227. $ft_ids = array_column($filetypes, "id");
  228. if ($info["study_abroad"] == 1) {
  229. //选中留学,如果存在留学附件变成必传
  230. $ft_ids = array_unique(array_merge($ft_ids, (array) $abroad_file_ids));
  231. } else {
  232. //没选中,留学附件就算设成必传也不用验证
  233. $ft_ids = array_diff($ft_ids, (array) $abroad_file_ids);
  234. }
  235. $whr = [];
  236. $whr[] = ["typeId", "in", $ft_ids];
  237. $whr[] = ["mainId", "=", $id];
  238. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  239. $upload_type_counts = count($distinct_filetypes);
  240. if ($upload_type_counts != count($ft_ids)) {
  241. return json(["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"]);
  242. }
  243. $change_state = TalentState::SCND_SUBMIT; //等待初审
  244. $data["id"] = $id;
  245. $data["checkState"] = $change_state;
  246. $data["active"] = 1;
  247. $data["new_submit_time"] = date("Y-m-d H:i:s");
  248. TalentModel::update($data);
  249. TalentLogApi::write(1, $id, $change_state, "确认提交审核", 1);
  250. return json(["code" => 200, "msg" => "提交成功"]);
  251. } else if ($checkState == TalentState::REVERIFY_FAIL) {
  252. return ["msg" => "审核失败,不能再提交审核"];
  253. }
  254. return json(["msg" => "已提交审核,请耐心等待"]);
  255. }
  256. public function delete() {
  257. $id = $this->request->param("talentInfoId");
  258. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  259. if (!$info) {
  260. return json(["msg" => "操作失败"]);
  261. }
  262. $checkState = $info["checkState"];
  263. if (in_array($checkState, [0, 1])) {
  264. $log = TalentLogApi::getLastLog($id, 1);
  265. if ($log["state"] > 1) {
  266. //有提交审核记录
  267. return json(["msg" => "操作失败"]);
  268. }
  269. }
  270. $data["id"] = $id;
  271. $data["delete"] = 1;
  272. TalentModel::update($data);
  273. return json(["msg" => "删除成功"]);
  274. }
  275. static public function chkIsOwner($id, $uid) {
  276. $where[] = ["id", "=", $id];
  277. $where[] = ["enterprise_id", "=", $uid];
  278. $info = TalentModel::where($where)->findOrEmpty()->toArray();
  279. return $info;
  280. }
  281. }