Base.php 16 KB

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