Base.php 18 KB

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