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