Talent.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. <?php
  2. namespace app\enterprise\controller;
  3. use app\enterprise\common\EnterpriseController;
  4. use app\enterprise\api\TalentApi;
  5. use app\enterprise\model\Talent as TalentModel;
  6. use think\facade\Db;
  7. use app\common\api\EnterpriseApi;
  8. use app\common\api\DictApi;
  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 Talent
  16. *
  17. * @author sgq
  18. */
  19. class Talent extends EnterpriseController {
  20. public function index() {
  21. $isMix = $this->request->param("isMix");
  22. $tpl = "";
  23. if ($isMix == 1) {
  24. $tpl = "newIndex";
  25. }
  26. return view($tpl);
  27. }
  28. public function list() {
  29. $step = 2;
  30. $res = TalentApi::getList($this->request, $step);
  31. return json($res);
  32. }
  33. /**
  34. * 新人才申报企业端统一申报入口,混合基础信息及人才信息
  35. */
  36. public function apply(\think\Request $request) {
  37. $type = $this->user["type"];
  38. $tpl = "";
  39. switch ($type) {
  40. case 1:
  41. $tpl = "apply"; //晋江人才
  42. break;
  43. case 2:
  44. $tpl = "ic_apply"; //集成电路
  45. break;
  46. }
  47. $param = $request->param();
  48. $id = isset($param["id"]) ? $param["id"] : 0;
  49. $info = TalentApi::chkIsOwner($id, $this->user["uid"]);
  50. $ep = EnterpriseApi::getOne($this->user["uid"]);
  51. if (!chkEnterpriseFull($ep))
  52. return;
  53. $tagList = DictApi::selectByParentCode('enterprise_tag');
  54. $streetList = DictApi::selectByParentCode('street');
  55. $industryFieldNew = DictApi::selectByParentCode('industry_field');
  56. $ep->enterpristTagName = $tagList[$ep->enterpriseTag];
  57. $ep->streetName = $streetList[$ep->street];
  58. $ep->industryFieldNewName = $industryFieldNew[$ep->industryFieldNew];
  59. if ($info) {
  60. $info["real_state"] = TalentLogApi::getLastLog($id, $type)["state"];
  61. }
  62. if ($info && in_array($info["checkState"], [TalentState::FST_VERIFY_PASS, TalentState::DEPT_VERIFY_PASS, TalentState::REVERIFY_PASS, TalentState::REVERIFY_FAIL])) {
  63. return $this->view($request);
  64. exit();
  65. }
  66. if ($request->isPost()) {
  67. $checkState = $info["checkState"] ?: 0;
  68. if ($checkState == TalentState::SCND_SAVE || $checkState == 0) {
  69. $this->mixSave($info, $request, TalentState::SCND_SAVE);
  70. exit();
  71. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL])) {
  72. $res = ["msg" => "审核失败,不能再保存"];
  73. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  74. exit;
  75. }
  76. $res = ["msg" => "已提交审核,请耐心等待"];
  77. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  78. exit;
  79. }
  80. $checkState = $info["checkState"] ?: 0;
  81. $info["enterprise"] = $ep;
  82. $info["talent_type_list"] = DictApi::findChildDictByCode("talent_type");
  83. return view($tpl, ["year" => date("Y"), "checkState" => $checkState, "row" => $info]);
  84. }
  85. /**
  86. * 旧第二步
  87. * @param \think\Request $request
  88. * @return type
  89. */
  90. public function second(\think\Request $request) {
  91. $params = $request->param();
  92. $id = $params["id"];
  93. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  94. $info["real_state"] = TalentLogApi::getLastLog($id, 1)["state"];
  95. if ($request->isPost()) {
  96. if (!$info || $info["enterprise_id"] != $this->user["uid"]) {
  97. $res = ["msg" => "没有对应的人才认定申报信息"];
  98. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  99. exit;
  100. }
  101. $checkState = $info["checkState"];
  102. if ($checkState == TalentState::SCND_SAVE || $checkState == TalentState::BASE_REVERIFY_PASS) {
  103. $this->save($info, $request, TalentState::SCND_SAVE);
  104. exit();
  105. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL])) {
  106. $res = ["msg" => "审核失败,不能再保存"];
  107. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  108. exit;
  109. }
  110. $res = ["msg" => "已提交审核,请耐心等待"];
  111. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  112. exit;
  113. }
  114. $enterprise_info = \app\common\model\Enterprise::find($this->user["uid"]);
  115. $info["enterprise"] = $enterprise_info;
  116. $batch = \app\common\api\BatchApi::getValidBatch(1, $enterprise_info["type"]);
  117. return view("second", ["year" => $info["apply_year"] ?: $batch["batch"], "row" => $info]);
  118. }
  119. public function view(\think\Request $request) {
  120. switch ($this->user["type"]) {
  121. case 1:
  122. $tpl = "view"; //晋江人才
  123. break;
  124. case 2:
  125. $tpl = "ic_view"; //集成电路
  126. break;
  127. }
  128. $id = $request->param("id");
  129. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  130. return view($tpl, ["row" => $info]);
  131. }
  132. /**
  133. * 提交表单(旧第二步)
  134. */
  135. public function submit() {
  136. $params = $this->request->param();
  137. $id = $params["id"];
  138. if (!$info = TalentApi::chkIsOwner($id, $this->user["uid"])) {
  139. $res = ["msg" => "没有对应的人才认定申报信息"];
  140. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  141. exit;
  142. }
  143. $checkState = $info["checkState"];
  144. if ($checkState == TalentState::SCND_SAVE || $checkState == TalentState::BASE_REVERIFY_PASS) {
  145. $field_dict = \app\common\api\DictApi::getTalentFields(2);
  146. $no_empty = ["talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "bank", "bank_number", "bank_branch_name",
  147. "bank_account", "study_abroad", "phone", "email", "import_way", "cur_entry_time", "cur_entry_time", "position", "source"];
  148. $where = [];
  149. $where[] = ["rel", "=", "study_abroad"];
  150. $where[] = ["step", "=", 2];
  151. $where[] = ["project", "=", 1];
  152. $where[] = ["active", "=", 1];
  153. $where[] = ["delete", "=", 0];
  154. $where[] = ["type", "=", $this->user["type"]];
  155. $where[] = ["isConditionFile", "<>", 1];
  156. $abroad_files = Db::table("new_common_filetype")->where($where)->select()->toArray(); //留学的附件
  157. $abroad_file_ids = null;
  158. if ($abroad_files)
  159. $abroad_file_ids = array_column($abroad_files, "id");
  160. if ($params["study_abroad"] == 1) {
  161. $no_empty[] = "abroad_school";
  162. $no_empty[] = "abroad_major";
  163. }
  164. if (in_array($params["source"], [1, 3])) {
  165. $no_empty[] = "source_batch";
  166. $no_empty[] = "fujian_highcert_pubtime";
  167. $no_empty[] = "fujian_highcert_exptime";
  168. if ($params["source"] == 3) {
  169. $no_empty[] = "source_city";
  170. }
  171. }
  172. if (in_array($params["source"], [2, 4])) {
  173. $no_empty[] = "source_batch";
  174. $no_empty[] = "quanzhou_highcert_pubtime";
  175. $no_empty[] = "quanzhou_highcert_exptime";
  176. if ($params["source"] == 4) {
  177. $no_empty[] = "source_county";
  178. }
  179. }
  180. $condition_info = Db::table("new_talent_condition")->findOrEmpty($params["talent_condition"]);
  181. if ($condition_info["isSalary"] == 1) {
  182. $no_empty[] = "annual_salary";
  183. }
  184. $no_empty = array_filter($no_empty);
  185. $return = [];
  186. foreach ($no_empty as $key) {
  187. if (!$params[$key]) {
  188. $return[] = sprintf("请填写“%s”", $field_dict[$key]);
  189. }
  190. }
  191. if (count($return) > 0) {
  192. $res = ["msg" => implode("<br>", $return)];
  193. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  194. exit;
  195. }
  196. if ($condition_info["bindFileTypes"] && $info["source"] == 5) {
  197. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  198. $whr[] = ["must", "=", 1];
  199. }
  200. $where = [];
  201. $where[] = ["step", "=", 2];
  202. $where[] = ["project", "=", 1];
  203. $where[] = ["type", "=", $this->user["type"]];
  204. $where[] = ["must", "=", 1];
  205. $where[] = ["active", "=", 1];
  206. $where[] = ["delete", "=", 0];
  207. $where[] = ["isConditionFile", "<>", 1];
  208. if ($whr) {
  209. $filetypes = Db::table("new_common_filetype")->whereOr([$where, $whr])->select()->toArray();
  210. } else {
  211. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  212. }
  213. $ft_ids = array_column($filetypes, "id");
  214. if ($params["study_abroad"] == 1) {
  215. //选中留学,如果存在留学附件变成必传
  216. $ft_ids = array_unique(array_merge($ft_ids, (array) $abroad_file_ids));
  217. } else {
  218. //没选中,留学附件就算设成必传也不用验证
  219. $ft_ids = array_diff($ft_ids, (array) $abroad_file_ids);
  220. }
  221. $whr = [];
  222. $whr[] = ["typeId", "in", $ft_ids];
  223. $whr[] = ["mainId", "=", $id];
  224. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  225. $upload_type_counts = count($distinct_filetypes);
  226. if ($upload_type_counts != count($ft_ids)) {
  227. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
  228. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  229. exit;
  230. }
  231. $this->save($info, $this->request, TalentState::SCND_SUBMIT);
  232. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL])) {
  233. $res = ["msg" => "审核失败,不能再提交审核"];
  234. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  235. exit;
  236. }
  237. $res = ["msg" => "已提交审核,请耐心等待"];
  238. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  239. exit;
  240. }
  241. /**
  242. * 提交表单(新:混合基础信息人才申报信息)
  243. */
  244. public function submitToCheck() {
  245. $params = $this->request->param();
  246. $id = $params["id"];
  247. if (!$info = TalentApi::chkIsOwner($id, $this->user["uid"])) {
  248. $res = ["msg" => "没有对应的人才认定申报信息"];
  249. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  250. exit;
  251. }
  252. $checkState = $info["checkState"];
  253. if ($checkState == TalentState::SCND_SAVE) {
  254. $field_dict = \app\common\api\DictApi::getTalentFields(4);
  255. $no_empty = ["name", "nation", "card_type", "card_number", "sex", "birthday", "politics", "nationality", "province", "city", "county", "talent_type", "experience", "education",
  256. "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "bank", "bank_number", "bank_branch_name",
  257. "bank_account", "study_abroad", "phone", "email", "import_way", "cur_entry_time", "cur_entry_time", "position", "source"];
  258. $where = [];
  259. $where[] = ["rel", "=", "study_abroad"];
  260. $where[] = ["step", "=", 2];
  261. $where[] = ["project", "=", 1];
  262. $where[] = ["active", "=", 1];
  263. $where[] = ["delete", "=", 0];
  264. $where[] = ["type", "=", $this->user["type"]];
  265. $where[] = ["isConditionFile", "<>", 1];
  266. $abroad_files = Db::table("new_common_filetype")->where($where)->select()->toArray(); //留学的附件
  267. $abroad_file_ids = null;
  268. if ($abroad_files)
  269. $abroad_file_ids = array_column($abroad_files, "id");
  270. if (in_array($param["talent_type"], [1, 2])) {
  271. $no_empty[] = "tax_insurance_month";
  272. $no_empty[] = "labor_contract_rangetime";
  273. }
  274. if ($param["talent_type"] == 3) {
  275. $no_empty[] = "pre_import_type";
  276. }
  277. if ($params["study_abroad"] == 1) {
  278. $no_empty[] = "abroad_school";
  279. $no_empty[] = "abroad_major";
  280. }
  281. if (in_array($params["source"], [1, 3])) {
  282. $no_empty[] = "source_batch";
  283. $no_empty[] = "fujian_highcert_pubtime";
  284. $no_empty[] = "fujian_highcert_exptime";
  285. if ($params["source"] == 3) {
  286. $no_empty[] = "source_city";
  287. }
  288. }
  289. if (in_array($params["source"], [2, 4])) {
  290. $no_empty[] = "source_batch";
  291. $no_empty[] = "quanzhou_highcert_pubtime";
  292. $no_empty[] = "quanzhou_highcert_exptime";
  293. if ($params["source"] == 4) {
  294. $no_empty[] = "source_county";
  295. }
  296. }
  297. $condition_info = Db::table("new_talent_condition")->findOrEmpty($params["talent_condition"]);
  298. if ($condition_info["isSalary"] == 1) {
  299. $no_empty[] = "annual_salary";
  300. }
  301. $no_empty = array_filter($no_empty);
  302. $return = [];
  303. foreach ($no_empty as $key) {
  304. if (!$params[$key]) {
  305. $return[] = sprintf("请填写“%s”", $field_dict[$key]);
  306. }
  307. }
  308. if (count($return) > 0) {
  309. $res = ["msg" => implode("<br>", $return)];
  310. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  311. exit;
  312. }
  313. if ($condition_info["bindFileTypes"] && $info["source"] == 5) {
  314. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  315. $whr[] = ["must", "=", 1];
  316. }
  317. $where = [];
  318. $where[] = ["project", "=", 1];
  319. $where[] = ["type", "=", $this->user["type"]];
  320. $where[] = ["must", "=", 1];
  321. $where[] = ["active", "=", 1];
  322. $where[] = ["delete", "=", 0];
  323. $where[] = ["isConditionFile", "<>", 1];
  324. if ($whr) {
  325. $filetypes = Db::table("new_common_filetype")->whereOr([$where, $whr])->select()->toArray();
  326. } else {
  327. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  328. }
  329. $ft_ids = array_column($filetypes, "id");
  330. if ($params["study_abroad"] == 1) {
  331. //选中留学,如果存在留学附件变成必传
  332. $ft_ids = array_unique(array_merge($ft_ids, (array) $abroad_file_ids));
  333. } else {
  334. //没选中,留学附件就算设成必传也不用验证
  335. $ft_ids = array_diff($ft_ids, (array) $abroad_file_ids);
  336. }
  337. $whr = [];
  338. $whr[] = ["typeId", "in", $ft_ids];
  339. $whr[] = ["mainId", "=", $id];
  340. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  341. $upload_type_counts = count($distinct_filetypes);
  342. if ($upload_type_counts != count($ft_ids)) {
  343. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
  344. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  345. exit;
  346. }
  347. $this->save($info, $this->request, TalentState::SCND_SUBMIT);
  348. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL, TalentState::ZX_FAIL, TalentState::ANNOUNCED_REVERIFY_FAIL, TalentState::PUBLISH_FAIL])) {
  349. $res = ["msg" => "审核失败,不能再提交审核"];
  350. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  351. exit;
  352. }
  353. $res = ["msg" => "已提交审核,请耐心等待"];
  354. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  355. exit;
  356. }
  357. /**
  358. * 保存表单(旧第二步)
  359. * @param type $info talent_info
  360. * @param type $param request->param();
  361. */
  362. private function save($info, \think\Request $request, $checkState) {
  363. try {
  364. $batch = \app\common\api\BatchApi::getValidBatch(1, $this->user["type"]);
  365. if (!$batch) {
  366. throw new ValidateException("不在人才认定申报申请时间内");
  367. }
  368. $param = $request->param();
  369. validate(TalentInfo::class)->check($param);
  370. $data["apply_year"] = $batch["batch"];
  371. $all_valid_keys = ["applay_year", "import_way", "cur_entry_time", "position",
  372. "source", "source_batch", "fujian_highcert_pubtime", "fujian_highcert_exptime", "quanzhou_highcert_pubtime", "quanzhou_highcert_exptime", "source_city", "source_county",
  373. "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "professional", "bank", "bank_number", "bank_branch_name", "bank_account",
  374. "study_abroad", "abroad_school", "abroad_major", "phone", "email", "annual_salary", "pro_qua"];
  375. foreach ($all_valid_keys as $key) {
  376. $data[$key] = trim($param[$key]);
  377. }
  378. if ($data["study_abroad"] == 1) {
  379. $data["abroad_school"] = $param["abroad_school"];
  380. $data["abroad_major"] = $param["abroad_major"];
  381. } else {
  382. $data["abroad_school"] = null;
  383. $data["abroad_major"] = null;
  384. }
  385. switch ($data["source"]) {
  386. case 1:
  387. $data["source_batch"] = $param["source_batch"];
  388. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  389. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  390. $data["source_city"] = null;
  391. break;
  392. case 2:
  393. $data["source_batch"] = $param["source_batch"];
  394. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  395. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  396. $data["source_county"] = null;
  397. break;
  398. case 3:
  399. $data["source_batch"] = $param["source_batch"];
  400. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  401. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  402. $data["source_city"] = $param["source_city"];
  403. break;
  404. case 4:
  405. $data["source_batch"] = $param["source_batch"];
  406. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  407. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  408. $data["source_county"] = $param["source_county"];
  409. break;
  410. }
  411. $condition_info = Db::table("new_talent_condition")->findOrEmpty($param["talent_condition"]);
  412. if ($condition_info["isSalary"] == 1) {
  413. $data["annual_salary"] = $param["annual_salary"];
  414. } else {
  415. $data["annual_salary"] = null;
  416. }
  417. if ($info["real_state"] == TalentState::FST_VERIFY_REJECT) {
  418. //真实状态8是驳回,需要判断什么字段可以提交
  419. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  420. $tmp_data = $data;
  421. $data = [];
  422. foreach ($modify_fields as $field) {
  423. $data[$field] = $tmp_data[$field];
  424. }
  425. }
  426. $data["checkState"] = $checkState;
  427. $data["id"] = $info["id"];
  428. $success_msg = "提交成功";
  429. $error_msg = "提交失败";
  430. if ($checkState == TalentState::SCND_SAVE) {
  431. $last_log = TalentLogApi::getLastLog($data["id"], 1);
  432. if ($last_log["new_state"] != TalentState::SCND_SAVE) {
  433. TalentLogApi::write(1, $data["id"], $checkState, "保存认定材料未提交", 1);
  434. }
  435. TalentModel::update($data);
  436. } else if ($checkState == TalentState::SCND_SUBMIT) {
  437. $success_msg = "提交成功";
  438. $error_msg = "提交失败";
  439. $data["new_submit_time"] = date("Y-m-d H:i:s");
  440. TalentModel::update($data);
  441. TalentLogApi::write(1, $info["id"], $checkState, "确认提交审核", 1);
  442. } else {
  443. throw new ValidateException($error_msg);
  444. }
  445. $res = ["code" => 200, "msg" => $success_msg, "obj" => ["id" => $info["id"], "checkState" => $checkState]];
  446. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  447. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  448. exit();
  449. } catch (ValidateException $e) {
  450. $res = ["msg" => $e->getMessage()];
  451. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  452. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  453. exit();
  454. }
  455. }
  456. /**
  457. * 保存表单(新:混合基础信息人才申报信息)
  458. * @param type $info talent_info
  459. * @param type $param request->param();
  460. */
  461. private function mixSave($info, \think\Request $request, $checkState) {
  462. try {
  463. $batch = \app\common\api\BatchApi::getValidBatch(1, $this->user["type"]);
  464. if (!$batch) {
  465. throw new ValidateException("不在人才认定申报申请时间内");
  466. }
  467. $param = $request->param();
  468. validate(TalentInfo::class)->check($param);
  469. $id = $param["id"];
  470. if ($id) {
  471. if (!$info || $info["id"] != $id || $info["enterprise_id"] != $this->user["uid"]) {
  472. throw new ValidateException("没有对应的人才认定申报信息");
  473. }
  474. }
  475. $files = $param["uploadFiles"];
  476. $data["headimgurl"] = $info["headimgurl"];
  477. if ($request->file()) {
  478. $headimg = $request->file("photo");
  479. $upload = new \app\common\api\UploadApi();
  480. $result = $upload->uploadOne($headimg, "image", "talent/photo");
  481. $file = imagecreatefromstring(file_get_contents("storage/" . $result->filepath));
  482. $width = imagesx($file);
  483. $height = imagesy($file);
  484. //免冠二寸照长宽413:579
  485. if ($width * 579 != $height * 413) {
  486. @unlink("storage/" . $result->filepath); //像素不符合,删除上传文件
  487. throw new ValidateException("近期免冠半身彩照(二寸)不符合二寸像素标准。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
  488. }
  489. if ($info && $info["headimgurl"]) {
  490. //如果新照片符合像素要求,则删除旧照片
  491. $old_head_url = "storage/" . $info["headimgurl"];
  492. if (file_exists($old_head_url))
  493. @unlink($old_head_url);
  494. }
  495. $data["headimgurl"] = $result->filepath;
  496. }
  497. if (!$data["headimgurl"] && $checkState == TalentState::SCND_SUBMIT)
  498. throw new ValidateException("请上传头像。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
  499. $where = [];
  500. $where[] = ["project", "=", 1];
  501. $where[] = ["type", "=", $this->user["type"]];
  502. $where[] = ["must", "=", 1];
  503. $where[] = ["active", "=", 1];
  504. $where[] = ["delete", "=", 0];
  505. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  506. $age = 0;
  507. if ($param["birthday"]) {
  508. $birthday = $param["birthday"];
  509. $birthdayYear = substr($birthday, 0, 4);
  510. $currentYear = date("Y");
  511. $age = $currentYear - $birthdayYear;
  512. }
  513. $ft_ids = [];
  514. $deletes = [];
  515. foreach ($filetypes as $ft) {
  516. if ($ft["option"]) {
  517. if ($ft["rel"] == "birthday") {
  518. if ($age < $ft["option"]) {
  519. $deletes[] = $ft["id"];
  520. continue;
  521. }
  522. } else {
  523. $selectVal = $param[$ft["rel"]];
  524. $conditions = array_filter(explode(",", $ft["option"]));
  525. if (!in_array($selectVal, $conditions)) {
  526. $deletes[] = $ft["id"];
  527. continue;
  528. }
  529. }
  530. }
  531. $ft_ids[] = $ft["id"];
  532. }
  533. $data["apply_year"] = $batch["batch"];
  534. $all_valid_keys = ["talent_type", "name", "card_type", "card_number", "sex", "birthday", "nationality", "province", "city", "county", "nation", "politics", "experience", "education",
  535. "import_way", "cur_entry_time", "position",
  536. "source", "source_batch", "fujian_highcert_pubtime", "fujian_highcert_exptime", "quanzhou_highcert_pubtime", "quanzhou_highcert_exptime", "source_city", "source_county",
  537. "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "professional", "bank", "bank_number", "bank_branch_name", "bank_account",
  538. "study_abroad", "abroad_school", "abroad_major", "phone", "email", "annual_salary", "pro_qua"];
  539. foreach ($all_valid_keys as $key) {
  540. $data[$key] = trim($param[$key]);
  541. }
  542. if (in_array($data["talent_type"], [1, 2])) {
  543. $data["tax_insurance_month"] = $param["tax_insurance_month"];
  544. $data["labor_contract_rangetime"] = $param["labor_contract_rangetime"];
  545. $data["fst_work_time"] = $param["fst_work_time"];
  546. $data['pre_import_type'] = null;
  547. } else {
  548. $data["tax_insurance_month"] = null;
  549. $data["labor_contract_rangetime"] = null;
  550. $data["fst_work_time"] = null;
  551. $data['pre_import_type'] = $param["pre_import_type"];
  552. }
  553. if ($data["study_abroad"] == 1) {
  554. $data["abroad_school"] = $param["abroad_school"];
  555. $data["abroad_major"] = $param["abroad_major"];
  556. } else {
  557. $data["abroad_school"] = null;
  558. $data["abroad_major"] = null;
  559. }
  560. switch ($data["source"]) {
  561. case 1:
  562. $data["source_batch"] = $param["source_batch"];
  563. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  564. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  565. $data["source_city"] = null;
  566. break;
  567. case 2:
  568. $data["source_batch"] = $param["source_batch"];
  569. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  570. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  571. $data["source_county"] = null;
  572. break;
  573. case 3:
  574. $data["source_batch"] = $param["source_batch"];
  575. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  576. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  577. $data["source_city"] = $param["source_city"];
  578. break;
  579. case 4:
  580. $data["source_batch"] = $param["source_batch"];
  581. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  582. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  583. $data["source_county"] = $param["source_county"];
  584. break;
  585. }
  586. $condition_info = Db::table("new_talent_condition")->findOrEmpty($param["talent_condition"]);
  587. if ($condition_info["isSalary"] == 1) {
  588. $data["annual_salary"] = $param["annual_salary"];
  589. } else {
  590. $data["annual_salary"] = null;
  591. }
  592. if ($info["real_state"] == TalentState::FST_VERIFY_REJECT) {
  593. //真实状态11是驳回,需要判断什么字段可以提交
  594. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  595. $tmp_data = $data;
  596. $data = [];
  597. foreach ($modify_fields as $field) {
  598. $data[$field] = $tmp_data[$field];
  599. }
  600. }
  601. $data["checkState"] = $checkState;
  602. $data["id"] = $id;
  603. $success_msg = "提交成功";
  604. $error_msg = "提交失败";
  605. if ($checkState == TalentState::SCND_SAVE) {
  606. $success_msg = "保存成功";
  607. if ($data["id"]) {
  608. //编辑
  609. TalentModel::update($data);
  610. $last_log = TalentLogApi::getLastLog($data["id"], 1);
  611. if ($last_log["new_state"] != TalentState::SCND_SAVE) {
  612. TalentLogApi::write(1, $data["id"], $checkState, "保存未提交", 1);
  613. } else {
  614. TalentLogApi::setActive($last_log["id"], 1); //更新修改时间
  615. }
  616. } else {
  617. //新增
  618. $data["enterprise_id"] = $this->user["uid"];
  619. $id = TalentModel::insertGetId($data);
  620. TalentLogApi::write(1, $id, $checkState, "保存未提交", 1);
  621. $whr = [];
  622. $whr[] = ["fileId", "in", $files];
  623. $upd_checklog["mainId"] = $id;
  624. Db::table("new_talent_checklog")->where($whr)->save($upd_checklog);
  625. }
  626. } else if ($checkState == TalentState::SCND_SUBMIT) {
  627. $data["new_submit_time"] = date("Y-m-d H:i:s");
  628. TalentModel::update($data);
  629. TalentLogApi::write(1, $data["id"], $checkState, "确认提交审核", 1);
  630. } else {
  631. throw new ValidateException($error_msg);
  632. }
  633. if ($id) {
  634. if ($deletes) {
  635. //删除多余的附件,一般是选择人才类型留下来的
  636. $whr = [];
  637. $whr[] = ["typeId", "in", $deletes];
  638. $whr[] = ["id", "in", $files];
  639. $_wait_del_files = Db::table("new_talent_file")->where($whr)->select()->toArray();
  640. $_logfileIds[] = [];
  641. foreach ($_wait_del_files as $_del_file) {
  642. $_logfileIds[] = $_del_file["id"];
  643. @unlink("storage/" . $_del_file["url"]);
  644. }
  645. Db::table("new_talent_file")->where($whr)->delete();
  646. if ($_logfileIds) {
  647. $whr = [];
  648. $whr[] = ["fileId", "in", $_logfileIds];
  649. $_upd_checklog["description"] = "删除附件";
  650. $_upd_checklog["updateUser"] = sprintf("%s(%s)", $this->user["account"], $this->user["companyName"] ?: $this->user["rolename"]);
  651. $_upd_checklog["updateTime"] = date("Y-m-d H:i:s");
  652. Db::table("new_talent_checklog")->where($whr)->save($_upd_checklog);
  653. }
  654. }
  655. $whr = [];
  656. $whr[] = ["id", "in", $files];
  657. Db::table("new_talent_file")->where($whr)->save(["mainId" => $id]);
  658. $res = ["code" => 200, "msg" => $success_msg, "obj" => ["id" => $id, "checkState" => $checkState]];
  659. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  660. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  661. exit();
  662. } else {
  663. throw new ValidateException($error_msg);
  664. }
  665. } catch (ValidateException $e) {
  666. $res = ["msg" => $e->getMessage()];
  667. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  668. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  669. exit();
  670. }
  671. }
  672. public function delete() {
  673. $id = $this->request->param("talentInfoId");
  674. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  675. if (!$info) {
  676. return json(["msg" => "操作失败"]);
  677. }
  678. $checkState = $info["checkState"];
  679. if (in_array($checkState, [0, 1])) {
  680. $log = TalentLogApi::getLastLog($id, 1);
  681. if ($log["state"] > 1) {
  682. //有提交审核记录
  683. return json(["msg" => "该申报已提交审核,无法删除"]);
  684. }
  685. }
  686. $data["id"] = $id;
  687. $data["delete"] = 1;
  688. TalentModel::update($data);
  689. return json(["msg" => "删除成功"]);
  690. }
  691. public function mixDelete() {
  692. $id = $this->request->param("talentInfoId");
  693. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  694. if (!$info) {
  695. return json(["msg" => "操作失败"]);
  696. }
  697. $checkState = $info["checkState"];
  698. if (in_array($checkState, [0, TalentState::SCND_SAVE])) {
  699. $log = TalentLogApi::getLastLog($id, 1);
  700. if ($log["state"] > 1) {
  701. //有提交审核记录
  702. return json(["msg" => "该申报已提交审核,无法删除"]);
  703. }
  704. }
  705. $data["id"] = $id;
  706. $data["delete"] = 1;
  707. TalentModel::update($data);
  708. return json(["msg" => "删除成功"]);
  709. }
  710. }