Base.php 16 KB

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