Talent.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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", "fst_work_time", "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"];
  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", "fst_work_time", "cur_entry_time", "cur_entry_time", "position", "source"];
  54. if ($data["study_abroad"] == 1) {
  55. $no_empty[] = "abroad_school";
  56. $no_empty[] = "abroad_major";
  57. }
  58. if (in_array($data["source"], [1, 3])) {
  59. $no_empty[] = "source_batch";
  60. $no_empty[] = "fujian_highcert_pubtime";
  61. $no_empty[] = "fujian_highcert_exptime";
  62. if ($data["source"] == 3) {
  63. $no_empty[] = "source_city";
  64. }
  65. }
  66. if (in_array($data["source"], [2, 4])) {
  67. $no_empty[] = "source_batch";
  68. $no_empty[] = "quanzhou_highcert_pubtime";
  69. $no_empty[] = "quanzhou_highcert_exptime";
  70. if ($data["source"] == 4) {
  71. $no_empty[] = "source_county";
  72. }
  73. }
  74. $no_empty = array_filter($no_empty);
  75. $return = [];
  76. foreach ($no_empty as $key) {
  77. if (!$data[$key]) {
  78. $return[] = sprintf("请填写“%s”", $field_dict[$key]);
  79. }
  80. }
  81. if (count($return) > 0) {
  82. $res = ["msg" => implode("<br>", $return)];
  83. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  84. exit;
  85. }
  86. if (!preg_match("/^(13|14|15|17|18|19)[\d]{9}$/", $data["phone"])) {
  87. $res = ["msg" => "手机号码格式错误"];
  88. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  89. exit;
  90. }
  91. if (!filter_var($data["email"], FILTER_VALIDATE_EMAIL)) {
  92. $res = ["msg" => "电子邮箱格式错误"];
  93. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  94. exit;
  95. }
  96. if (!in_array($data["talent_arrange"], [1, 2, 3, 4, 5, 6, 7])) {
  97. $res = ["msg" => "人才层次只能在预设范围内选择"];
  98. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  99. exit;
  100. }
  101. if (!in_array($data["source"], [1, 2, 3, 4, 5])) {
  102. $res = ["msg" => "来源只能在预设范围内选择"];
  103. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  104. exit;
  105. }
  106. $condition_info = Db::table("new_talent_condition")->findOrEmpty($params["talent_condition"]);
  107. if ($condition_info["bindFileTypes"]) {
  108. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  109. $whr[] = ["must", "=", 1];
  110. }
  111. $where = [];
  112. $where[] = ["step", "=", 2];
  113. $where[] = ["project", "=", 1];
  114. $where[] = ["type", "=", $this->user["type"]];
  115. $where[] = ["must", "=", 1];
  116. if ($whr) {
  117. $filetypes = Db::table("new_common_filetype")->whereOr([$where, $whr])->select()->toArray();
  118. } else {
  119. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  120. }
  121. $ft_ids = array_column($filetypes, "id");
  122. $whr = [];
  123. $whr[] = ["typeId", "in", $ft_ids];
  124. $whr[] = ["mainId", "=", $id];
  125. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  126. $upload_type_counts = count($distinct_filetypes);
  127. if ($upload_type_counts != count($ft_ids)) {
  128. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
  129. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  130. exit;
  131. }
  132. if ($info["real_state"] == 8) {
  133. //真实状态8是驳回,需要判断什么字段可以提交
  134. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  135. $tmp_data = $data;
  136. $data = [];
  137. foreach ($modify_fields as $field) {
  138. $data[$field] = $tmp_data[$field];
  139. }
  140. }
  141. $data["apply_year"] = $batch["batch"];
  142. $data["id"] = $id;
  143. $data["checkState"] = TalentState::SCND_SAVE;
  144. if (TalentModel::update($data)) {
  145. $res = ["code" => 200, "msg" => "保存成功", "obj" => ["id" => $id, "checkState" => TalentState::SCND_SAVE]];
  146. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  147. } else {
  148. $res = ["code" => 500, "msg" => "保存失败"];
  149. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  150. }
  151. exit();
  152. }
  153. $enterprise_info = \app\common\model\Enterprise::find($this->user["uid"]);
  154. $info["enterprise"] = $enterprise_info;
  155. $batch = \app\common\api\BatchApi::getValidBatch(1, $enterprise_info["type"]);
  156. return view("second", ["year" => $info["apply_year"] ?: $batch["batch"], "row" => $info]);
  157. }
  158. public function view(\think\Request $request) {
  159. $id = $request->param("id");
  160. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  161. return view("view", ["row" => $info]);
  162. }
  163. // 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  164. public function submit() {
  165. $id = $this->request->param("id");
  166. if (!$info = self::chkIsOwner($id, $this->user["uid"]))
  167. return json(["msg" => "没有对应的人才认定申报信息"]);
  168. $checkState = $info["checkState"];
  169. if ($checkState == TalentState::BASE_VERIFY_PASS || $checkState == 0) {
  170. return json(["msg" => '请先保存资料并上传相应附件后再点击提交审核']);
  171. } else if ($checkState == TalentState::SCND_SAVE) {
  172. $condition_info = Db::table("new_talent_condition")->findOrEmpty($info["talent_condition"]);
  173. if ($condition_info["bindFileTypes"]) {
  174. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  175. $whr[] = ["must", "=", 1];
  176. }
  177. $where = [];
  178. $where[] = ["step", "=", 2];
  179. $where[] = ["project", "=", 1];
  180. $where[] = ["type", "=", $this->user["type"]];
  181. $where[] = ["must", "=", 1];
  182. if ($whr) {
  183. $filetypes = Db::table("new_common_filetype")->whereOr([$where, $whr])->select()->toArray();
  184. } else {
  185. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  186. }
  187. $ft_ids = array_column($filetypes, "id");
  188. $whr = [];
  189. $whr[] = ["typeId", "in", $ft_ids];
  190. $whr[] = ["mainId", "=", $id];
  191. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  192. $upload_type_counts = count($distinct_filetypes);
  193. if ($upload_type_counts != count($ft_ids)) {
  194. return json(["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"]);
  195. }
  196. $change_state = TalentState::SCND_SUBMIT; //等待初审
  197. $data["id"] = $id;
  198. $data["checkState"] = $change_state;
  199. $data["active"] = 1;
  200. $data["new_submit_time"] = date("Y-m-d H:i:s");
  201. TalentModel::update($data);
  202. TalentLogApi::write(1, $id, $change_state, "确认提交审核", 1);
  203. return json(["code" => 200, "msg" => "提交成功"]);
  204. } else if ($checkState == TalentState::REVERIFY_FAIL) {
  205. return ["msg" => "审核失败,不能再提交审核"];
  206. }
  207. return json(["msg" => "已提交审核,请耐心等待"]);
  208. }
  209. public function delete() {
  210. $id = $this->request->param("talentInfoId");
  211. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  212. if (!$info) {
  213. return json(["msg" => "操作失败"]);
  214. }
  215. $checkState = $info["checkState"];
  216. if (in_array($checkState, [0, 1])) {
  217. $log = TalentLogApi::getLastLog($id, 1);
  218. if ($log["state"] > 1) {
  219. //有提交审核记录
  220. return json(["msg" => "操作失败"]);
  221. }
  222. }
  223. $data["id"] = $id;
  224. $data["delete"] = 1;
  225. TalentModel::update($data);
  226. return json(["msg" => "删除成功"]);
  227. }
  228. static public function chkIsOwner($id, $uid) {
  229. $where[] = ["id", "=", $id];
  230. $where[] = ["enterprise_id", "=", $uid];
  231. $info = TalentModel::where($where)->findOrEmpty()->toArray();
  232. return $info;
  233. }
  234. }