Talent.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 add() {
  24. $request = $this->request;
  25. $param = $request->param();
  26. $id = isset($param["id"]) ? $param["id"] : 0;
  27. $info = self::chkIsOwner($id, $this->user["uid"]);
  28. if ($info && in_array($info["checkState"], [TalentState::BASE_VERIFY_PASS, TalentState::SCND_SAVE])) {
  29. return $this->second($request);
  30. exit();
  31. }
  32. if ($request->isPost()) {
  33. if ($id) {
  34. $data["id"] = $id;
  35. if (!$info) {
  36. $res = ["msg" => "没有对应的人才认定申报信息"];
  37. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  38. exit;
  39. }
  40. if ($info["checkState"] == TalentState::REVERIFY_FAIL) {
  41. $res = ["msg" => "审核失败,不能再修改"];
  42. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  43. exit;
  44. }
  45. if (!in_array($info["checkState"], [TalentState::FST_SAVE, TalentState::BASE_VERIFY_PASS, TalentState::SCND_SAVE])) {
  46. $res = ["msg" => "审核中,不能修改"];
  47. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  48. exit;
  49. }
  50. }
  51. $data["enterprise_id"] = $this->user["uid"];
  52. $data["talent_type"] = $param["talent_type"];
  53. $data["tax_insurance_month"] = $param["tax_insurance_month"];
  54. $data["labor_contract_rangetime"] = $param["labor_contract_rangetime"];
  55. $data["name"] = $param["name"];
  56. $data["card_type"] = $param["card_type"];
  57. $data["card_number"] = $param["card_number"];
  58. $data["sex"] = $param["sex"];
  59. $data["birthday"] = $param["birthday"];
  60. $data["nationality"] = $param["nationality"];
  61. $data["province"] = $param["province"];
  62. $data["city"] = $param["city"];
  63. $data["county"] = $param["county"];
  64. $data["nation"] = $param["nation"];
  65. $data["politics"] = $param["politics"];
  66. if ($request->file()) {
  67. $headimg = $request->file("photo");
  68. if ($info) {
  69. $old_head_url = "storage/" . $info["headimgurl"];
  70. if (file_exists($old_head_url))
  71. unlink($old_head_url);
  72. }
  73. $upload = new \app\common\api\UploadApi();
  74. $result = $upload->uploadOne($headimg, "image", "talent/photo");
  75. $data["headimgurl"] = $result->filepath;
  76. }
  77. if ($id > 0) {
  78. TalentModel::update($data);
  79. } else {
  80. $data["checkState"] = TalentState::FST_SAVE;
  81. $id = TalentModel::insertGetId($data);
  82. TalentLogApi::write(1, $id, TalentState::FST_SAVE, "添加人才认定申报", 1);
  83. }
  84. if ($id) {
  85. $res = ["code" => 200, "msg" => "保存成功", "obj" => ["id" => $id, "checkState" => TalentState::FST_SAVE]];
  86. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  87. } else {
  88. $res = ["msg" => "保存失败"];
  89. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  90. }
  91. exit();
  92. }
  93. $checkState = $info["checkState"] ?: 0;
  94. $enterprise_info = \app\common\model\Enterprise::find($this->user["uid"]);
  95. $info["enterprise"] = $enterprise_info;
  96. $info["talent_type_list"] = \app\common\api\DictApi::findChildDictByCode("talent_type");
  97. return view("first", ["year" => date("Y"), "checkState" => $checkState, "row" => $info]);
  98. }
  99. private function second(\think\Request $request) {
  100. $params = $request->param();
  101. $id = $params["id"];
  102. if ($request->isPost()) {
  103. $batch = \app\common\api\BatchApi::getValidBatch(1, $this->user["type"]);
  104. if (!$batch) {
  105. $res = ["msg" => "不在人才认定申报申请时间内"];
  106. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  107. exit;
  108. }
  109. $field_dict = \app\common\api\DictApi::getTalentFields(2);
  110. //可以用匹配键的方式,可以少很多代码。。先这样吧。
  111. $all_valid_keys = ["applay_year", "fst_work_time", "import_way", "cur_entry_time", "position",
  112. "source", "source_batch", "fujian_highcert_pubtime", "fujian_highcert_exptime", "quanzhou_highcert_pubtime", "quanzhou_highcert_exptime", "source_city", "source_county",
  113. "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "professional", "bank", "bank_number", "bank_branch_name", "bank_account",
  114. "study_abroad", "abroad_school", "abroad_major", "phone", "email"];
  115. foreach ($all_valid_keys as $key) {
  116. $data[$key] = trim($params[$key]);
  117. if (strpos($key, "time") !== false && strtotime($params[$key]) === false) {
  118. unset($data[$key]); //时间格式的验证不通过就清掉,下面判断是否为空如果赫然在列就不能通过
  119. }
  120. }
  121. $no_empty = ["talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "professional", "bank", "bank_number", "bank_branch_name",
  122. "bank_account", "study_abroad", "phone", "email", "import_way", "fst_work_time", "cur_entry_time", "cur_entry_time", "position", "source"];
  123. if ($data["study_abroad"] == 1) {
  124. $no_empty[] = "abroad_school";
  125. $no_empty[] = "abroad_major";
  126. }
  127. if (in_array($data["source"], [1, 3])) {
  128. $no_empty[] = "source_batch";
  129. $no_empty[] = "fujian_highcert_pubtime";
  130. $no_empty[] = "fujian_highcert_exptime";
  131. if ($data["source"] == 3) {
  132. $no_empty[] = "source_city";
  133. }
  134. }
  135. if (in_array($data["source"], [2, 4])) {
  136. $no_empty[] = "source_batch";
  137. $no_empty[] = "quanzhou_highcert_pubtime";
  138. $no_empty[] = "quanzhou_highcert_exptime";
  139. if ($data["source"] == 4) {
  140. $no_empty[] = "source_county";
  141. }
  142. }
  143. $no_empty = array_filter($no_empty);
  144. $return = [];
  145. foreach ($no_empty as $key) {
  146. if (!$data[$key]) {
  147. $return[] = sprintf("请填写“%s”", $field_dict[$key]);
  148. }
  149. }
  150. if (count($return) > 0) {
  151. $res = ["msg" => implode("<br>", $return)];
  152. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  153. exit;
  154. }
  155. if (!preg_match("/^(13|14|15|17|18|19)[\d]{9}$/", $data["phone"])) {
  156. $res = ["msg" => "手机号码格式错误"];
  157. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  158. exit;
  159. }
  160. if (!filter_var($data["email"], FILTER_VALIDATE_EMAIL)) {
  161. $res = ["msg" => "电子邮箱格式错误"];
  162. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  163. exit;
  164. }
  165. if (!in_array($data["talent_arrange"], [1, 2, 3, 4, 5, 6, 7])) {
  166. $res = ["msg" => "人才层次只能在预设范围内选择"];
  167. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  168. exit;
  169. }
  170. if (!in_array($data["source"], [1, 2, 3, 4, 5])) {
  171. $res = ["msg" => "来源只能在预设范围内选择"];
  172. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  173. exit;
  174. }
  175. $where = [];
  176. $where[] = ["step", "=", 2];
  177. $where[] = ["project", "=", 1];
  178. $where[] = ["type", "=", $this->user["type"]];
  179. $where[] = ["must", "=", 1];
  180. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  181. $ft_ids = array_column($filetypes, "id");
  182. $whr = [];
  183. $whr[] = ["typeId", "in", $ft_ids];
  184. $whr[] = ["mainId", "=", $id];
  185. $upload_type_counts = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->count();
  186. if ($upload_type_counts != count($ft_ids)) {
  187. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
  188. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  189. exit;
  190. }
  191. $data["apply_year"] = $batch["batch"];
  192. $data["id"] = $id;
  193. $data["checkState"] = TalentState::SCND_SAVE;
  194. if (TalentModel::update($data)) {
  195. $res = ["code" => 200, "msg" => "保存成功", "obj" => ["id" => $id, "checkState" => TalentState::SCND_SAVE]];
  196. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  197. } else {
  198. $res = ["code" => 500, "msg" => "保存失败"];
  199. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  200. }
  201. }
  202. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  203. $enterprise_info = \app\common\model\Enterprise::find($this->user["uid"]);
  204. $info["enterprise"] = $enterprise_info;
  205. $batch = \app\common\api\BatchApi::getValidBatch(1, $enterprise_info["type"]);
  206. return view("second", ["year" => $batch["batch"], "row" => $info]);
  207. }
  208. public function view() {
  209. $id = $this->request->param("id");
  210. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  211. return view("", ["row" => $info]);
  212. }
  213. // 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  214. public function submit() {
  215. $id = $this->request->param("id");
  216. if (!$info = self::chkIsOwner($id, $this->user["uid"]))
  217. return json(["msg" => "没有对应的人才认定申报信息"]);
  218. $checkState = $info["checkState"];
  219. if ($checkState == TalentState::BASE_VERIFY_PASS || $checkState == 0) {
  220. return json(["msg" => '请先保存资料并上传相应附件后再点击提交审核']);
  221. } else if ($checkState == TalentState::FST_SAVE) {
  222. $filed_dict = \app\common\api\DictApi::getTalentFields(1);
  223. //初次提交材料
  224. $change_state = TalentState::FST_SUBMIT; //等待审核
  225. if (!$info["headimgurl"])
  226. return json(["msg" => "请上传头像"]);
  227. $no_empty = ["talent_type", "name", "card_type", "card_number", "sex", "birthday", "nationality", "province", "city", "nation", "politics"];
  228. if (in_array($info["talent_type"], [1, 2]))
  229. $no_empty[] = "tax_insurance_month";
  230. if ($info["talent_type"] == 3)
  231. $no_empty[] = "labor_contract_rangetime";
  232. $return = [];
  233. foreach ($no_empty as $key) {
  234. if (!$info[$key]) {
  235. $return[] = sprintf("请填写“%s”", $filed_dict[$key]);
  236. }
  237. }
  238. if (count($return) > 0)
  239. return json(["msg" => implode("<br>", $return)]);
  240. $where = [];
  241. $where[] = ["step", "=", 1];
  242. $where[] = ["project", "=", 1];
  243. $where[] = ["type", "=", $this->user["type"]];
  244. $where[] = ["must", "=", 1];
  245. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  246. $ft_ids = array_column($filetypes, "id");
  247. $whr = [];
  248. $whr[] = ["typeId", "in", $ft_ids];
  249. $whr[] = ["mainId", "=", $info["id"]];
  250. $upload_type_counts = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->count();
  251. if ($upload_type_counts != count($ft_ids))
  252. return json(["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"]);
  253. $data["id"] = $id;
  254. $data["checkState"] = $change_state;
  255. $data["active"] = 1;
  256. TalentModel::update($data);
  257. TalentLogApi::write(1, $id, $change_state, "提交基础判定材料待审核", 1);
  258. return json(["code" => 200, "msg" => "提交成功"]);
  259. } else if ($checkState == TalentState::SCND_SAVE) {
  260. $change_state = TalentState::SCND_SUBMIT; //等待初审
  261. $data["id"] = $id;
  262. $data["checkState"] = $change_state;
  263. $data["active"] = 1;
  264. TalentModel::update($data);
  265. TalentLogApi::write(1, $id, $change_state, "确认提交审核", 1);
  266. return json(["code" => 200, "msg" => "提交成功"]);
  267. } else if ($checkState == TalentState::REVERIFY_FAIL) {
  268. return ["msg" => "审核失败,不能再提交审核"];
  269. }
  270. return json(["msg" => "已提交审核,请耐心等待"]);
  271. }
  272. public function delete() {
  273. $id = $this->request->param("talentInfoId");
  274. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  275. if (!$info) {
  276. return json(["msg" => "操作失败"]);
  277. }
  278. $checkState = $info["checkState"];
  279. if (in_array($checkState, [0, 1])) {
  280. $log = TalentLogApi::getLastLog($id, 1);
  281. if ($log["state"] > 1) {
  282. //有提交审核记录
  283. return json(["msg" => "操作失败"]);
  284. }
  285. }
  286. $data["id"] = $id;
  287. $data["delete"] = 1;
  288. TalentModel::update($data);
  289. return json(["msg" => "删除成功"]);
  290. }
  291. static private function chkIsOwner($id, $uid) {
  292. $where[] = ["id", "=", $id];
  293. $where[] = ["enterprise_id", "=", $uid];
  294. $info = TalentModel::where($where)->findOrEmpty()->toArray();
  295. return $info;
  296. }
  297. }