Base.php 17 KB

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