Base.php 16 KB

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