Base.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  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. $where[] = ["active", "=", 1];
  160. $where[] = ["delete", "=", 0];
  161. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  162. $ft_ids = [];
  163. $deletes = [];
  164. foreach ($filetypes as $ft) {
  165. if ($ft["option"]) {
  166. $selectVal = $param[$ft["rel"]];
  167. $conditions = array_filter(explode(",", $ft["option"]));
  168. if (!in_array($selectVal, $conditions)) {
  169. $deletes[] = $ft["id"];
  170. continue;
  171. }
  172. }
  173. $ft_ids[] = $ft["id"];
  174. }
  175. //$ft_ids = array_column($filetypes, "id");
  176. $whr = [];
  177. $upload_type_counts = 0;
  178. if ($files) {
  179. $whr[] = ["typeId", "in", $ft_ids];
  180. $whr[] = ["id", "in", $files];
  181. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  182. $upload_type_counts = count($distinct_filetypes);
  183. }
  184. if ($upload_type_counts != count($ft_ids)) {
  185. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
  186. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  187. exit;
  188. }
  189. $data["enterprise_id"] = $this->user["uid"];
  190. $data["talent_type"] = $param["talent_type"];
  191. $data["tax_insurance_month"] = $param["tax_insurance_month"];
  192. $data["labor_contract_rangetime"] = $param["labor_contract_rangetime"];
  193. $data['pre_import_type'] = $param["pre_import_type"];
  194. $data["name"] = $param["name"];
  195. $data["card_type"] = $param["card_type"];
  196. $data["card_number"] = $param["card_number"];
  197. $data["sex"] = $param["sex"];
  198. $data["birthday"] = $param["birthday"];
  199. $data["nationality"] = $param["nationality"];
  200. $data["province"] = $param["province"];
  201. $data["city"] = $param["city"];
  202. $data["county"] = $param["county"];
  203. $data["nation"] = $param["nation"];
  204. $data["politics"] = $param["politics"];
  205. $data["fst_work_time"] = $param["fst_work_time"];
  206. $data["experience"] = $param["experience"];
  207. $data["education"] = $param["education"];
  208. if ($info["real_state"] == 4) {
  209. //真实状态4是驳回,需要判断什么字段可以提交
  210. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  211. $tmp_data = $data;
  212. $data = [];
  213. if ($tmp_data["id"]) {
  214. $data["id"] = $tmp_data["id"];
  215. }
  216. foreach ($modify_fields as $field) {
  217. $data[$field] = $tmp_data[$field];
  218. }
  219. }
  220. if ($id > 0) {
  221. TalentModel::update($data);
  222. } else {
  223. $data["checkState"] = TalentState::FST_SAVE;
  224. $id = TalentModel::insertGetId($data);
  225. TalentLogApi::write(1, $id, TalentState::FST_SAVE, "添加人才认定申报", 1);
  226. $whr = [];
  227. $whr[] = ["fileId", "in", $files];
  228. $upd_checklog["mainId"] = $id;
  229. Db::table("new_talent_checklog")->where($whr)->save($upd_checklog);
  230. }
  231. if ($id) {
  232. if ($deletes) {
  233. //删除多余的附件,一般是选择人才类型留下来的
  234. $whr = [];
  235. $whr[] = ["typeId", "in", $deletes];
  236. $whr[] = ["id", "in", $files];
  237. $_wait_del_files = Db::table("new_talent_file")->where($whr)->select()->toArray();
  238. $_logfileIds[] = [];
  239. foreach ($_wait_del_files as $_del_file) {
  240. $_logfileIds[] = $_del_file["id"];
  241. @unlink("storage/" . $_del_file["url"]);
  242. }
  243. Db::table("new_talent_file")->where($whr)->delete();
  244. if ($_logfileIds) {
  245. $whr = [];
  246. $whr[] = ["fileId", "in", $_logfileIds];
  247. $_upd_checklog["description"] = "人才申报过程1中取消且已经彻底删除的附件";
  248. $_upd_checklog["updateUser"] = sprintf("%s(%s)", $this->user["account"], $this->user["companyName"] ?: $this->user["rolename"]);
  249. $_upd_checklog["updateTime"] = date("Y-m-d H:i:s");
  250. Db::table("new_talent_checklog")->where($whr)->save($_upd_checklog);
  251. }
  252. }
  253. $whr = [];
  254. $whr[] = ["id", "in", $files];
  255. Db::table("new_talent_file")->where($whr)->save(["mainId" => $id]);
  256. $res = ["code" => 200, "msg" => "保存成功", "obj" => ["id" => $id, "checkState" => TalentState::FST_SAVE]];
  257. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  258. } else {
  259. $res = ["msg" => "保存失败"];
  260. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  261. }
  262. exit();
  263. }
  264. $checkState = $info["checkState"] ?: 0;
  265. $info["enterprise"] = $ep;
  266. $info["talent_type_list"] = \app\common\api\DictApi::findChildDictByCode("talent_type");
  267. return view("first", ["year" => date("Y"), "checkState" => $checkState, "row" => $info]);
  268. }
  269. public function view(\think\Request $request) {
  270. $id = $request->param("id");
  271. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  272. return view("view", ["row" => $info]);
  273. }
  274. // 1保存未提交 2已提交未审核 3已审核 4驳回 5保存补充材料未提交 6提交补充材料进入初审 7初审通过 8初审驳回 9部门审核通过 10部门审核驳回 11复核通过 12复核驳回 13复核失败
  275. public function submit() {
  276. $id = $this->request->param("id");
  277. if (!$info = self::chkIsOwner($id, $this->user["uid"]))
  278. return json(["msg" => "没有对应的人才认定申报信息"]);
  279. $checkState = $info["checkState"];
  280. if ($checkState == TalentState::BASE_VERIFY_PASS || $checkState == 0) {
  281. return json(["msg" => '请先保存资料并上传相应附件后再点击提交审核']);
  282. } else if ($checkState == TalentState::FST_SAVE) {
  283. //初次提交材料
  284. $where = [];
  285. $where[] = ["step", "=", 1];
  286. $where[] = ["project", "=", 1];
  287. $where[] = ["type", "=", $this->user["type"]];
  288. $where[] = ["must", "=", 1];
  289. $where[] = ["active", "=", 1];
  290. $where[] = ["delete", "=", 0];
  291. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  292. $ft_ids = [];
  293. foreach ($filetypes as $ft) {
  294. if ($ft["option"]) {
  295. $selectVal = $info[$ft["rel"]];
  296. $conditions = array_filter(explode(",", $ft["option"]));
  297. if (!in_array($selectVal, $conditions)) {
  298. $deletes[] = $ft["id"];
  299. continue;
  300. }
  301. }
  302. $ft_ids[] = $ft["id"];
  303. }
  304. //$ft_ids = array_column($filetypes, "id");
  305. $whr = [];
  306. $upload_type_counts = 0;
  307. if ($ft_ids) {
  308. $whr[] = ["typeId", "in", $ft_ids];
  309. $whr[] = ["mainId", "=", $id];
  310. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  311. $upload_type_counts = count($distinct_filetypes);
  312. }
  313. if ($upload_type_counts != count($ft_ids)) {
  314. return json(["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"]);
  315. }
  316. $change_state = TalentState::FST_SUBMIT; //等待审核
  317. $data["id"] = $id;
  318. $data["checkState"] = $change_state;
  319. $data["first_submit_time"] = date("Y-m-d H:i:s");
  320. $data["active"] = 1;
  321. TalentModel::update($data);
  322. TalentLogApi::write(1, $id, $change_state, "提交基础判定材料待审核", 1);
  323. return json(["code" => 200, "msg" => "提交成功"]);
  324. } else if ($checkState == TalentState::REVERIFY_FAIL) {
  325. return ["msg" => "审核失败,不能再提交审核"];
  326. }
  327. return json(["msg" => "已提交审核,请耐心等待"]);
  328. }
  329. public function delete() {
  330. $id = $this->request->param("talentInfoId");
  331. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  332. if (!$info) {
  333. return json(["msg" => "操作失败"]);
  334. }
  335. $checkState = $info["checkState"];
  336. if (in_array($checkState, [0, 1])) {
  337. $log = TalentLogApi::getLastLog($id, 1);
  338. if ($log["state"] > 1) {
  339. //有提交审核记录
  340. return json(["msg" => "操作失败"]);
  341. }
  342. }
  343. $data["id"] = $id;
  344. $data["delete"] = 1;
  345. TalentModel::update($data);
  346. return json(["msg" => "删除成功"]);
  347. }
  348. static private function chkIsOwner($id, $uid) {
  349. $where[] = ["id", "=", $id];
  350. $where[] = ["enterprise_id", "=", $uid];
  351. $info = TalentModel::where($where)->findOrEmpty()->toArray();
  352. return $info;
  353. }
  354. }