Base.php 16 KB

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