Talent.php 11 KB

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