Base.php 17 KB

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