Base.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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, [TalentState::FST_SAVE, TalentState::FST_SUBMIT]);
  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) {
  29. $info["real_state"] = TalentLogApi::getLastLog($id, 1)["state"];
  30. }
  31. if ($info && in_array($info["checkState"], [TalentState::BASE_VERIFY_PASS, TalentState::SCND_SAVE])) {
  32. $res = ["msg" => "错误的访问方式"];
  33. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  34. exit;
  35. }
  36. if ($info && in_array($info["checkState"], [TalentState::FST_VERIFY_PASS, TalentState::DEPT_VERIFY_PASS, TalentState::REVERIFY_PASS, TalentState::REVERIFY_FAIL])) {
  37. return $this->view($request);
  38. exit();
  39. }
  40. if ($request->isPost()) {
  41. if ($id) {
  42. $data["id"] = $id;
  43. if (!$info) {
  44. $res = ["msg" => "没有对应的人才认定申报信息"];
  45. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  46. exit;
  47. }
  48. if ($info["checkState"] == TalentState::REVERIFY_FAIL) {
  49. $res = ["msg" => "审核失败,不能再修改"];
  50. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  51. exit;
  52. }
  53. if (!in_array($info["checkState"], [TalentState::FST_SAVE, TalentState::BASE_VERIFY_PASS, TalentState::SCND_SAVE])) {
  54. $res = ["msg" => "审核中,不能修改"];
  55. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  56. exit;
  57. }
  58. }
  59. $files = $param["uploadFiles"];
  60. $filed_dict = \app\common\api\DictApi::getTalentFields(1);
  61. $data["headimgurl"] = $info["headimgurl"];
  62. if ($request->file()) {
  63. $headimg = $request->file("photo");
  64. if ($info && $info["headimgurl"]) {
  65. $old_head_url = "storage/" . $info["headimgurl"];
  66. if (file_exists($old_head_url))
  67. unlink($old_head_url);
  68. }
  69. $upload = new \app\common\api\UploadApi();
  70. $result = $upload->uploadOne($headimg, "image", "talent/photo");
  71. $data["headimgurl"] = $result->filepath;
  72. }
  73. if (!$data["headimgurl"]) {
  74. $res = ["msg" => "请上传头像"];
  75. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  76. exit;
  77. }
  78. $no_empty = ["talent_type", "name", "card_type", "card_number", "sex", "birthday", "nationality", "province", "city", "nation", "politics"];
  79. if (in_array($param["talent_type"], [1, 2])) {
  80. list($date1, $date2) = explode(" - ", $param["tax_insurance_month"]);
  81. if (strtotime($date1) > strtotime($date2)) {
  82. $res = ["msg" => $filed_dict["tax_insurance_month"] . "起始时间不能大于结束时间"];
  83. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  84. exit;
  85. }
  86. /* $start = date_create($date1);
  87. $end = date_create($date2);
  88. $diff = date_diff($end, $start);
  89. $m = $diff->m ?: 0;
  90. $y = $diff->y ?: 0;
  91. $months = $y * 12 + $m;
  92. if ($months < 6) {
  93. $res = ["msg" => $filed_dict["tax_insurance_month"] . "应大于或等于6个月"];
  94. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  95. exit;
  96. } */
  97. $no_empty[] = "tax_insurance_month";
  98. $no_empty[] = "labor_contract_rangetime";
  99. }
  100. if ($param["talent_type"] == 3) {
  101. list($date1, $date2) = explode(" - ", $param["labor_contract_rangetime"]);
  102. if (strtotime($date1) > strtotime($date2)) {
  103. $res = ["msg" => $filed_dict["labor_contract_rangetime"] . "起始时间不能大于结束时间"];
  104. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  105. exit;
  106. }
  107. /* $start = date_create($date1);
  108. $end = date_create($date2);
  109. $diff = date_diff($end, $start);
  110. $m = $diff->m ?: 0;
  111. $y = $diff->y ?: 0;
  112. $months = $y * 12 + $m;
  113. if ($months < 6) {
  114. $res = ["msg" => $filed_dict["labor_contract_rangetime"] . "应大于或等于6个月"];
  115. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  116. exit;
  117. } */
  118. $no_empty[] = "pre_import_type";
  119. }
  120. $return = [];
  121. foreach ($no_empty as $key) {
  122. if (!$param[$key]) {
  123. $return[] = sprintf("请填写“%s”", $filed_dict[$key]);
  124. }
  125. }
  126. if (count($return) > 0) {
  127. $res = ["msg" => implode("<br>", $return)];
  128. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  129. exit;
  130. }
  131. $where = [];
  132. $where[] = ["step", "=", 1];
  133. $where[] = ["project", "=", 1];
  134. $where[] = ["type", "=", $this->user["type"]];
  135. $where[] = ["must", "=", 1];
  136. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  137. $ft_ids = [];
  138. $deletes = [];
  139. foreach ($filetypes as $ft) {
  140. if ($ft["option"]) {
  141. $selectVal = $param[$ft["rel"]];
  142. $conditions = array_filter(explode(",", $ft["option"]));
  143. if (!in_array($selectVal, $conditions)) {
  144. $deletes[] = $ft["id"];
  145. continue;
  146. }
  147. }
  148. $ft_ids[] = $ft["id"];
  149. }
  150. //$ft_ids = array_column($filetypes, "id");
  151. $whr = [];
  152. $upload_type_counts = 0;
  153. if ($files) {
  154. $whr[] = ["typeId", "in", $ft_ids];
  155. $whr[] = ["id", "in", $files];
  156. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  157. $upload_type_counts = count($distinct_filetypes);
  158. }
  159. if ($upload_type_counts != count($ft_ids)) {
  160. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
  161. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  162. exit;
  163. }
  164. $data["enterprise_id"] = $this->user["uid"];
  165. $data["talent_type"] = $param["talent_type"];
  166. $data["tax_insurance_month"] = $param["tax_insurance_month"];
  167. $data["labor_contract_rangetime"] = $param["labor_contract_rangetime"];
  168. $data['pre_import_type'] = $param["pre_import_type"];
  169. $data["name"] = $param["name"];
  170. $data["card_type"] = $param["card_type"];
  171. $data["card_number"] = $param["card_number"];
  172. $data["sex"] = $param["sex"];
  173. $data["birthday"] = $param["birthday"];
  174. $data["nationality"] = $param["nationality"];
  175. $data["province"] = $param["province"];
  176. $data["city"] = $param["city"];
  177. $data["county"] = $param["county"];
  178. $data["nation"] = $param["nation"];
  179. $data["politics"] = $param["politics"];
  180. if ($info["real_state"] == 4) {
  181. //真实状态4是驳回,需要判断什么字段可以提交
  182. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  183. $tmp_data = $data;
  184. $data = [];
  185. if ($tmp_data["id"]) {
  186. $data["id"] = $tmp_data["id"];
  187. }
  188. foreach ($modify_fields as $field) {
  189. $data[$field] = $tmp_data[$field];
  190. }
  191. }
  192. if ($id > 0) {
  193. TalentModel::update($data);
  194. } else {
  195. $data["checkState"] = TalentState::FST_SAVE;
  196. $id = TalentModel::insertGetId($data);
  197. TalentLogApi::write(1, $id, TalentState::FST_SAVE, "添加人才认定申报", 1);
  198. $whr = [];
  199. $whr[] = ["fileId", "in", $files];
  200. $upd_checklog["mainId"] = $id;
  201. Db::table("new_talent_checklog")->where($whr)->save($upd_checklog);
  202. }
  203. if ($id) {
  204. if ($deletes) {
  205. //删除多余的附件,一般是选择人才类型留下来的
  206. $whr = [];
  207. $whr[] = ["typeId", "in", $deletes];
  208. $whr[] = ["id", "in", $files];
  209. $_wait_del_files = Db::table("new_talent_file")->where($whr)->select()->toArray();
  210. $_logfileIds[] = [];
  211. foreach ($_wait_del_files as $_del_file) {
  212. $_logfileIds[] = $_del_file["id"];
  213. @unlink("storage/" . $_del_file["url"]);
  214. }
  215. Db::table("new_talent_file")->where($whr)->delete();
  216. if ($_logfileIds) {
  217. $whr = [];
  218. $whr[] = ["fileId", "in", $_logfileIds];
  219. $_upd_checklog["description"] = "人才申报过程1中取消且已经彻底删除的附件";
  220. $_upd_checklog["updateUser"] = sprintf("%s(%s)", $this->user["account"], $this->user["companyName"] ?: $this->user["rolename"]);
  221. $_upd_checklog["updateTime"] = date("Y-m-d H:i:s");
  222. Db::table("new_talent_checklog")->where($whr)->save($_upd_checklog);
  223. }
  224. }
  225. $whr = [];
  226. $whr[] = ["id", "in", $files];
  227. Db::table("new_talent_file")->where($whr)->save(["mainId" => $id]);
  228. $res = ["code" => 200, "msg" => "保存成功", "obj" => ["id" => $id, "checkState" => TalentState::FST_SAVE]];
  229. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  230. } else {
  231. $res = ["msg" => "保存失败"];
  232. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  233. }
  234. exit();
  235. }
  236. $checkState = $info["checkState"] ?: 0;
  237. $enterprise_info = \app\common\model\Enterprise::find($this->user["uid"]);
  238. $info["enterprise"] = $enterprise_info;
  239. $info["talent_type_list"] = \app\common\api\DictApi::findChildDictByCode("talent_type");
  240. return view("first", ["year" => date("Y"), "checkState" => $checkState, "row" => $info]);
  241. }
  242. public function view(\think\Request $request) {
  243. $id = $request->param("id");
  244. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  245. return view("view", ["row" => $info]);
  246. }
  247. // 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  248. public function submit() {
  249. $id = $this->request->param("id");
  250. if (!$info = self::chkIsOwner($id, $this->user["uid"]))
  251. return json(["msg" => "没有对应的人才认定申报信息"]);
  252. $checkState = $info["checkState"];
  253. if ($checkState == TalentState::BASE_VERIFY_PASS || $checkState == 0) {
  254. return json(["msg" => '请先保存资料并上传相应附件后再点击提交审核']);
  255. } else if ($checkState == TalentState::FST_SAVE) {
  256. //初次提交材料
  257. $where = [];
  258. $where[] = ["step", "=", 1];
  259. $where[] = ["project", "=", 1];
  260. $where[] = ["type", "=", $this->user["type"]];
  261. $where[] = ["must", "=", 1];
  262. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  263. $ft_ids = [];
  264. foreach ($filetypes as $ft) {
  265. if ($ft["option"]) {
  266. $selectVal = $info[$ft["rel"]];
  267. $conditions = array_filter(explode(",", $ft["option"]));
  268. if (!in_array($selectVal, $conditions)) {
  269. $deletes[] = $ft["id"];
  270. continue;
  271. }
  272. }
  273. $ft_ids[] = $ft["id"];
  274. }
  275. //$ft_ids = array_column($filetypes, "id");
  276. $whr = [];
  277. $upload_type_counts = 0;
  278. if ($ft_ids) {
  279. $whr[] = ["typeId", "in", $ft_ids];
  280. $whr[] = ["mainId", "=", $id];
  281. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  282. $upload_type_counts = count($distinct_filetypes);
  283. }
  284. if ($upload_type_counts != count($ft_ids)) {
  285. return json(["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"]);
  286. }
  287. $change_state = TalentState::FST_SUBMIT; //等待审核
  288. $data["id"] = $id;
  289. $data["checkState"] = $change_state;
  290. $data["first_submit_time"] = date("Y-m-d H:i:s");
  291. $data["active"] = 1;
  292. TalentModel::update($data);
  293. TalentLogApi::write(1, $id, $change_state, "提交基础判定材料待审核", 1);
  294. return json(["code" => 200, "msg" => "提交成功"]);
  295. } else if ($checkState == TalentState::REVERIFY_FAIL) {
  296. return ["msg" => "审核失败,不能再提交审核"];
  297. }
  298. return json(["msg" => "已提交审核,请耐心等待"]);
  299. }
  300. public function delete() {
  301. $id = $this->request->param("talentInfoId");
  302. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  303. if (!$info) {
  304. return json(["msg" => "操作失败"]);
  305. }
  306. $checkState = $info["checkState"];
  307. if (in_array($checkState, [0, 1])) {
  308. $log = TalentLogApi::getLastLog($id, 1);
  309. if ($log["state"] > 1) {
  310. //有提交审核记录
  311. return json(["msg" => "操作失败"]);
  312. }
  313. }
  314. $data["id"] = $id;
  315. $data["delete"] = 1;
  316. TalentModel::update($data);
  317. return json(["msg" => "删除成功"]);
  318. }
  319. static private function chkIsOwner($id, $uid) {
  320. $where[] = ["id", "=", $id];
  321. $where[] = ["enterprise_id", "=", $uid];
  322. $info = TalentModel::where($where)->findOrEmpty()->toArray();
  323. return $info;
  324. }
  325. }