Base.php 18 KB

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