Talent.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  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. switch ($type) {
  70. case 1:
  71. $this->mixSave($info, $request, TalentState::SCND_SAVE);
  72. exit();
  73. break;
  74. case 2:
  75. $this->icSave($info, $request, TalentState::SCND_SAVE);
  76. exit();
  77. break;
  78. }
  79. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL])) {
  80. $res = ["msg" => "审核失败,不能再保存"];
  81. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  82. exit;
  83. }
  84. $res = ["msg" => "已提交审核,请耐心等待"];
  85. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  86. exit;
  87. }
  88. $checkState = $info["checkState"] ?: 0;
  89. $info["enterprise"] = $ep;
  90. $info["talent_type_list"] = DictApi::findChildDictByCode("talent_type");
  91. return view($tpl, ["year" => date("Y"), "checkState" => $checkState, "row" => $info]);
  92. }
  93. /**
  94. * 旧第二步
  95. * @param \think\Request $request
  96. * @return type
  97. */
  98. public function second(\think\Request $request) {
  99. $params = $request->param();
  100. $id = $params["id"];
  101. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  102. $info["real_state"] = TalentLogApi::getLastLog($id, 1)["state"];
  103. if ($request->isPost()) {
  104. if (!$info || $info["enterprise_id"] != $this->user["uid"]) {
  105. $res = ["msg" => "没有对应的人才认定申报信息"];
  106. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  107. exit;
  108. }
  109. $checkState = $info["checkState"];
  110. if ($checkState == TalentState::SCND_SAVE || $checkState == TalentState::BASE_REVERIFY_PASS) {
  111. $this->save($info, $request, TalentState::SCND_SAVE);
  112. exit();
  113. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL])) {
  114. $res = ["msg" => "审核失败,不能再保存"];
  115. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  116. exit;
  117. }
  118. $res = ["msg" => "已提交审核,请耐心等待"];
  119. echo sprintf("<script>parent.TalentInfoInfoDlg.infoCallback(%s);</script>", json_encode($res));
  120. exit;
  121. }
  122. $enterprise_info = \app\common\model\Enterprise::find($this->user["uid"]);
  123. $info["enterprise"] = $enterprise_info;
  124. $batch = \app\common\api\BatchApi::getValidBatch(1, $enterprise_info["type"]);
  125. return view("second", ["year" => $info["apply_year"] ?: $batch["batch"], "row" => $info]);
  126. }
  127. public function view(\think\Request $request) {
  128. switch ($this->user["type"]) {
  129. case 1:
  130. $tpl = "view"; //晋江人才
  131. break;
  132. case 2:
  133. $tpl = "ic_view"; //集成电路
  134. break;
  135. }
  136. $id = $request->param("id");
  137. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  138. return view($tpl, ["row" => $info]);
  139. }
  140. /**
  141. * 提交表单(旧第二步)
  142. */
  143. public function submit() {
  144. $params = $this->request->param();
  145. $id = $params["id"];
  146. if (!$info = TalentApi::chkIsOwner($id, $this->user["uid"])) {
  147. $res = ["msg" => "没有对应的人才认定申报信息"];
  148. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  149. exit;
  150. }
  151. $checkState = $info["checkState"];
  152. if ($checkState == TalentState::SCND_SAVE || $checkState == TalentState::BASE_REVERIFY_PASS) {
  153. $field_dict = \app\common\api\DictApi::getTalentFields(2);
  154. $no_empty = ["talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "bank", "bank_number", "bank_branch_name",
  155. "bank_account", "study_abroad", "phone", "email", "import_way", "cur_entry_time", "cur_entry_time", "position", "source"];
  156. $where = [];
  157. $where[] = ["rel", "=", "study_abroad"];
  158. $where[] = ["step", "=", 2];
  159. $where[] = ["project", "=", 1];
  160. $where[] = ["active", "=", 1];
  161. $where[] = ["delete", "=", 0];
  162. $where[] = ["type", "=", $this->user["type"]];
  163. $where[] = ["isConditionFile", "<>", 1];
  164. $abroad_files = Db::table("new_common_filetype")->where($where)->select()->toArray(); //留学的附件
  165. $abroad_file_ids = null;
  166. if ($abroad_files)
  167. $abroad_file_ids = array_column($abroad_files, "id");
  168. if ($params["study_abroad"] == 1) {
  169. $no_empty[] = "abroad_school";
  170. $no_empty[] = "abroad_major";
  171. }
  172. if (in_array($params["source"], [1, 3])) {
  173. $no_empty[] = "source_batch";
  174. $no_empty[] = "fujian_highcert_pubtime";
  175. $no_empty[] = "fujian_highcert_exptime";
  176. if ($params["source"] == 3) {
  177. $no_empty[] = "source_city";
  178. }
  179. }
  180. if (in_array($params["source"], [2, 4])) {
  181. $no_empty[] = "source_batch";
  182. $no_empty[] = "quanzhou_highcert_pubtime";
  183. $no_empty[] = "quanzhou_highcert_exptime";
  184. if ($params["source"] == 4) {
  185. $no_empty[] = "source_county";
  186. }
  187. }
  188. $condition_info = Db::table("new_talent_condition")->findOrEmpty($params["talent_condition"]);
  189. if ($condition_info["isSalary"] == 1) {
  190. $no_empty[] = "annual_salary";
  191. }
  192. $no_empty = array_filter($no_empty);
  193. $return = [];
  194. foreach ($no_empty as $key) {
  195. if (!$params[$key]) {
  196. $return[] = sprintf("请填写“%s”", $field_dict[$key]);
  197. }
  198. }
  199. if (count($return) > 0) {
  200. $res = ["msg" => implode("<br>", $return)];
  201. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  202. exit;
  203. }
  204. if ($condition_info["bindFileTypes"] && $info["source"] == 5) {
  205. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  206. $whr[] = ["must", "=", 1];
  207. }
  208. $where = [];
  209. $where[] = ["step", "=", 2];
  210. $where[] = ["project", "=", 1];
  211. $where[] = ["type", "=", $this->user["type"]];
  212. $where[] = ["must", "=", 1];
  213. $where[] = ["active", "=", 1];
  214. $where[] = ["delete", "=", 0];
  215. $where[] = ["isConditionFile", "<>", 1];
  216. if ($whr) {
  217. $filetypes = Db::table("new_common_filetype")->whereOr([$where, $whr])->select()->toArray();
  218. } else {
  219. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  220. }
  221. $ft_ids = array_column($filetypes, "id");
  222. if ($params["study_abroad"] == 1) {
  223. //选中留学,如果存在留学附件变成必传
  224. $ft_ids = array_unique(array_merge($ft_ids, (array) $abroad_file_ids));
  225. } else {
  226. //没选中,留学附件就算设成必传也不用验证
  227. $ft_ids = array_diff($ft_ids, (array) $abroad_file_ids);
  228. }
  229. $whr = [];
  230. $whr[] = ["typeId", "in", $ft_ids];
  231. $whr[] = ["mainId", "=", $id];
  232. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  233. $upload_type_counts = count($distinct_filetypes);
  234. if ($upload_type_counts != count($ft_ids)) {
  235. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
  236. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  237. exit;
  238. }
  239. $this->save($info, $this->request, TalentState::SCND_SUBMIT);
  240. } else if (in_array($checkState, [TalentState::BASE_VERIFY_FAIL, TalentState::BASE_REVERIFY_FAIL, TalentState::FST_VERIFY_FAIL, TalentState::REVERIFY_FAIL])) {
  241. $res = ["msg" => "审核失败,不能再提交审核"];
  242. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  243. exit;
  244. }
  245. $res = ["msg" => "已提交审核,请耐心等待"];
  246. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  247. exit;
  248. }
  249. /**
  250. * 提交表单(新:混合基础信息人才申报信息)
  251. */
  252. public function submitToCheck() {
  253. $params = $this->request->param();
  254. $id = $params["id"];
  255. if (!$info = TalentApi::chkIsOwner($id, $this->user["uid"])) {
  256. $res = ["msg" => "没有对应的人才认定申报信息"];
  257. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  258. exit;
  259. }
  260. $checkState = $info["checkState"];
  261. if ($checkState == TalentState::SCND_SAVE) {
  262. $field_dict = \app\common\api\DictApi::getTalentFields(4);
  263. $no_empty = ["name", "nation", "card_type", "card_number", "sex", "birthday", "politics", "nationality", "province", "city", "county", "talent_type", "experience", "education",
  264. "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "bank", "bank_number", "bank_branch_name",
  265. "bank_account", "study_abroad", "phone", "email", "import_way", "cur_entry_time", "cur_entry_time", "position", "source"];
  266. $where = [];
  267. $where[] = ["rel", "=", "study_abroad"];
  268. $where[] = ["step", "=", 2];
  269. $where[] = ["project", "=", 1];
  270. $where[] = ["active", "=", 1];
  271. $where[] = ["delete", "=", 0];
  272. $where[] = ["type", "=", $this->user["type"]];
  273. $where[] = ["isConditionFile", "<>", 1];
  274. $abroad_files = Db::table("new_common_filetype")->where($where)->select()->toArray(); //留学的附件
  275. $abroad_file_ids = null;
  276. if ($abroad_files)
  277. $abroad_file_ids = array_column($abroad_files, "id");
  278. if (in_array($param["talent_type"], [1, 2])) {
  279. $no_empty[] = "tax_insurance_month";
  280. $no_empty[] = "labor_contract_rangetime";
  281. }
  282. if ($param["talent_type"] == 3) {
  283. $no_empty[] = "pre_import_type";
  284. }
  285. if ($params["study_abroad"] == 1) {
  286. $no_empty[] = "abroad_school";
  287. $no_empty[] = "abroad_major";
  288. }
  289. if (in_array($params["source"], [1, 3])) {
  290. $no_empty[] = "source_batch";
  291. $no_empty[] = "fujian_highcert_pubtime";
  292. $no_empty[] = "fujian_highcert_exptime";
  293. if ($params["source"] == 3) {
  294. $no_empty[] = "source_city";
  295. }
  296. }
  297. if (in_array($params["source"], [2, 4])) {
  298. $no_empty[] = "source_batch";
  299. $no_empty[] = "quanzhou_highcert_pubtime";
  300. $no_empty[] = "quanzhou_highcert_exptime";
  301. if ($params["source"] == 4) {
  302. $no_empty[] = "source_county";
  303. }
  304. }
  305. $condition_info = Db::table("new_talent_condition")->findOrEmpty($params["talent_condition"]);
  306. if ($condition_info["isSalary"] == 1) {
  307. $no_empty[] = "annual_salary";
  308. }
  309. $no_empty = array_filter($no_empty);
  310. $return = [];
  311. foreach ($no_empty as $key) {
  312. if (!$params[$key]) {
  313. $return[] = sprintf("请填写“%s”", $field_dict[$key]);
  314. }
  315. }
  316. if (count($return) > 0) {
  317. $res = ["msg" => implode("<br>", $return)];
  318. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  319. exit;
  320. }
  321. if ($condition_info["bindFileTypes"] && $info["source"] == 5) {
  322. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  323. $whr[] = ["must", "=", 1];
  324. }
  325. $where = [];
  326. $where[] = ["project", "=", 1];
  327. $where[] = ["type", "=", $this->user["type"]];
  328. $where[] = ["must", "=", 1];
  329. $where[] = ["active", "=", 1];
  330. $where[] = ["delete", "=", 0];
  331. $where[] = ["isConditionFile", "<>", 1];
  332. if ($whr) {
  333. $filetypes = Db::table("new_common_filetype")->whereOr([$where, $whr])->select()->toArray();
  334. } else {
  335. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  336. }
  337. $ft_ids = array_column($filetypes, "id");
  338. if ($params["study_abroad"] == 1) {
  339. //选中留学,如果存在留学附件变成必传
  340. $ft_ids = array_unique(array_merge($ft_ids, (array) $abroad_file_ids));
  341. } else {
  342. //没选中,留学附件就算设成必传也不用验证
  343. $ft_ids = array_diff($ft_ids, (array) $abroad_file_ids);
  344. }
  345. $whr = [];
  346. $whr[] = ["typeId", "in", $ft_ids];
  347. $whr[] = ["mainId", "=", $id];
  348. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  349. $upload_type_counts = count($distinct_filetypes);
  350. if ($upload_type_counts != count($ft_ids)) {
  351. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
  352. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  353. exit;
  354. }
  355. $this->save($info, $this->request, TalentState::SCND_SUBMIT);
  356. } 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])) {
  357. $res = ["msg" => "审核失败,不能再提交审核"];
  358. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  359. exit;
  360. }
  361. $res = ["msg" => "已提交审核,请耐心等待"];
  362. echo sprintf("<script>parent.TalentInfoInfoDlg.submitCallback(%s);</script>", json_encode($res));
  363. exit;
  364. }
  365. /**
  366. * 保存表单(旧第二步)
  367. * @param type $info talent_info
  368. * @param type $param request->param();
  369. */
  370. private function save($info, \think\Request $request, $checkState) {
  371. try {
  372. $batch = \app\common\api\BatchApi::getValidBatch(1, $this->user["type"]);
  373. if (!$batch) {
  374. throw new ValidateException("不在人才认定申报申请时间内");
  375. }
  376. $param = $request->param();
  377. validate(TalentInfo::class)->check($param);
  378. $data["apply_year"] = $batch["batch"];
  379. $all_valid_keys = ["applay_year", "import_way", "cur_entry_time", "position",
  380. "source", "source_batch", "fujian_highcert_pubtime", "fujian_highcert_exptime", "quanzhou_highcert_pubtime", "quanzhou_highcert_exptime", "source_city", "source_county",
  381. "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "professional", "bank", "bank_number", "bank_branch_name", "bank_account",
  382. "study_abroad", "abroad_school", "abroad_major", "phone", "email", "annual_salary", "pro_qua"];
  383. foreach ($all_valid_keys as $key) {
  384. $data[$key] = trim($param[$key]);
  385. }
  386. if ($data["study_abroad"] == 1) {
  387. $data["abroad_school"] = $param["abroad_school"];
  388. $data["abroad_major"] = $param["abroad_major"];
  389. } else {
  390. $data["abroad_school"] = null;
  391. $data["abroad_major"] = null;
  392. }
  393. switch ($data["source"]) {
  394. case 1:
  395. $data["source_batch"] = $param["source_batch"];
  396. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  397. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  398. $data["source_city"] = null;
  399. break;
  400. case 2:
  401. $data["source_batch"] = $param["source_batch"];
  402. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  403. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  404. $data["source_county"] = null;
  405. break;
  406. case 3:
  407. $data["source_batch"] = $param["source_batch"];
  408. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  409. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  410. $data["source_city"] = $param["source_city"];
  411. break;
  412. case 4:
  413. $data["source_batch"] = $param["source_batch"];
  414. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  415. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  416. $data["source_county"] = $param["source_county"];
  417. break;
  418. }
  419. $condition_info = Db::table("new_talent_condition")->findOrEmpty($param["talent_condition"]);
  420. if ($condition_info["isSalary"] == 1) {
  421. $data["annual_salary"] = $param["annual_salary"];
  422. } else {
  423. $data["annual_salary"] = null;
  424. }
  425. if ($info["real_state"] == TalentState::FST_VERIFY_REJECT) {
  426. //真实状态8是驳回,需要判断什么字段可以提交
  427. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  428. $tmp_data = $data;
  429. $data = [];
  430. foreach ($modify_fields as $field) {
  431. $data[$field] = $tmp_data[$field];
  432. }
  433. }
  434. $data["checkState"] = $checkState;
  435. $data["id"] = $info["id"];
  436. $success_msg = "提交成功";
  437. $error_msg = "提交失败";
  438. if ($checkState == TalentState::SCND_SAVE) {
  439. $last_log = TalentLogApi::getLastLog($data["id"], 1);
  440. if ($last_log["new_state"] != TalentState::SCND_SAVE) {
  441. TalentLogApi::write(1, $data["id"], $checkState, "保存认定材料未提交", 1);
  442. }
  443. TalentModel::update($data);
  444. } else if ($checkState == TalentState::SCND_SUBMIT) {
  445. $success_msg = "提交成功";
  446. $error_msg = "提交失败";
  447. $data["new_submit_time"] = date("Y-m-d H:i:s");
  448. TalentModel::update($data);
  449. TalentLogApi::write(1, $info["id"], $checkState, "确认提交审核", 1);
  450. } else {
  451. throw new ValidateException($error_msg);
  452. }
  453. $res = ["code" => 200, "msg" => $success_msg, "obj" => ["id" => $info["id"], "checkState" => $checkState]];
  454. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  455. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  456. exit();
  457. } catch (ValidateException $e) {
  458. $res = ["msg" => $e->getMessage()];
  459. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  460. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  461. exit();
  462. }
  463. }
  464. /**
  465. * 保存表单(新:混合基础信息人才申报信息)
  466. * @param type $info talent_info
  467. * @param type $param request->param();
  468. */
  469. private function mixSave($info, \think\Request $request, $checkState) {
  470. try {
  471. $batch = \app\common\api\BatchApi::getValidBatch(1, $this->user["type"]);
  472. if (!$batch) {
  473. throw new ValidateException("不在人才认定申报申请时间内");
  474. }
  475. $param = $request->param();
  476. validate(TalentInfo::class)->check($param);
  477. $id = $param["id"];
  478. if ($id) {
  479. if (!$info || $info["id"] != $id || $info["enterprise_id"] != $this->user["uid"]) {
  480. throw new ValidateException("没有对应的人才认定申报信息");
  481. }
  482. }
  483. $files = $param["uploadFiles"];
  484. $data["headimgurl"] = $info["headimgurl"];
  485. if ($request->file()) {
  486. $headimg = $request->file("photo");
  487. $upload = new \app\common\api\UploadApi();
  488. $result = $upload->uploadOne($headimg, "image", "talent/photo");
  489. $file = imagecreatefromstring(file_get_contents("storage/" . $result->filepath));
  490. $width = imagesx($file);
  491. $height = imagesy($file);
  492. //免冠二寸照长宽413:579
  493. if ($width * 579 != $height * 413) {
  494. @unlink("storage/" . $result->filepath); //像素不符合,删除上传文件
  495. throw new ValidateException("近期免冠半身彩照(二寸)不符合二寸像素标准。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
  496. }
  497. if ($info && $info["headimgurl"]) {
  498. //如果新照片符合像素要求,则删除旧照片
  499. $old_head_url = "storage/" . $info["headimgurl"];
  500. if (file_exists($old_head_url))
  501. @unlink($old_head_url);
  502. }
  503. $data["headimgurl"] = $result->filepath;
  504. }
  505. if (!$data["headimgurl"] && $checkState == TalentState::SCND_SUBMIT)
  506. throw new ValidateException("请上传头像。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
  507. $where = [];
  508. $where[] = ["project", "=", 1];
  509. $where[] = ["type", "=", $this->user["type"]];
  510. $where[] = ["must", "=", 1];
  511. $where[] = ["active", "=", 1];
  512. $where[] = ["delete", "=", 0];
  513. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  514. $age = 0;
  515. if ($param["birthday"]) {
  516. $birthday = $param["birthday"];
  517. $birthdayYear = substr($birthday, 0, 4);
  518. $currentYear = date("Y");
  519. $age = $currentYear - $birthdayYear;
  520. }
  521. $ft_ids = [];
  522. $deletes = [];
  523. foreach ($filetypes as $ft) {
  524. if ($ft["option"]) {
  525. if ($ft["rel"] == "birthday") {
  526. if ($age < $ft["option"]) {
  527. $deletes[] = $ft["id"];
  528. continue;
  529. }
  530. } else {
  531. $selectVal = $param[$ft["rel"]];
  532. $conditions = array_filter(explode(",", $ft["option"]));
  533. if (!in_array($selectVal, $conditions)) {
  534. $deletes[] = $ft["id"];
  535. continue;
  536. }
  537. }
  538. }
  539. $ft_ids[] = $ft["id"];
  540. }
  541. $data["apply_year"] = $batch["batch"];
  542. $all_valid_keys = ["talent_type", "name", "card_type", "card_number", "sex", "birthday", "nationality", "province", "city", "county", "nation", "politics", "experience", "education",
  543. "import_way", "cur_entry_time", "position",
  544. "source", "source_batch", "fujian_highcert_pubtime", "fujian_highcert_exptime", "quanzhou_highcert_pubtime", "quanzhou_highcert_exptime", "source_city", "source_county",
  545. "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "professional", "bank", "bank_number", "bank_branch_name", "bank_account",
  546. "study_abroad", "abroad_school", "abroad_major", "phone", "email", "annual_salary", "pro_qua"];
  547. foreach ($all_valid_keys as $key) {
  548. $data[$key] = trim($param[$key]);
  549. }
  550. if (in_array($data["talent_type"], [1, 2])) {
  551. $data["tax_insurance_month"] = $param["tax_insurance_month"];
  552. $data["labor_contract_rangetime"] = $param["labor_contract_rangetime"];
  553. $data["salary_pay_way"] = $param["salary_pay_way"];
  554. $data["salary_pay_month"] = $param["salary_pay_month"];
  555. $data["fst_work_time"] = $param["fst_work_time"];
  556. $data['pre_import_type'] = null;
  557. } else {
  558. $data["tax_insurance_month"] = null;
  559. $data["labor_contract_rangetime"] = null;
  560. $data["salary_pay_way"] = null;
  561. $data["salary_pay_month"] = null;
  562. $data["fst_work_time"] = null;
  563. $data['pre_import_type'] = $param["pre_import_type"];
  564. }
  565. if ($data["study_abroad"] == 1) {
  566. $data["abroad_school"] = $param["abroad_school"];
  567. $data["abroad_major"] = $param["abroad_major"];
  568. } else {
  569. $data["abroad_school"] = null;
  570. $data["abroad_major"] = null;
  571. }
  572. switch ($data["source"]) {
  573. case 1:
  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"] = null;
  578. break;
  579. case 2:
  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"] = null;
  584. break;
  585. case 3:
  586. $data["source_batch"] = $param["source_batch"];
  587. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  588. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  589. $data["source_city"] = $param["source_city"];
  590. break;
  591. case 4:
  592. $data["source_batch"] = $param["source_batch"];
  593. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  594. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  595. $data["source_county"] = $param["source_county"];
  596. break;
  597. }
  598. $condition_info = Db::table("new_talent_condition")->findOrEmpty($param["talent_condition"]);
  599. if ($condition_info["isSalary"] == 1) {
  600. $data["annual_salary"] = $param["annual_salary"];
  601. } else {
  602. $data["annual_salary"] = null;
  603. }
  604. if ($info["real_state"] == TalentState::FST_VERIFY_REJECT) {
  605. //真实状态11是驳回,需要判断什么字段可以提交
  606. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  607. $tmp_data = $data;
  608. $data = [];
  609. foreach ($modify_fields as $field) {
  610. $data[$field] = $tmp_data[$field];
  611. }
  612. }
  613. $data["checkState"] = $checkState;
  614. $data["id"] = $id;
  615. $success_msg = "提交成功";
  616. $error_msg = "提交失败";
  617. if ($checkState == TalentState::SCND_SAVE) {
  618. $success_msg = "保存成功";
  619. if ($data["id"]) {
  620. //编辑
  621. TalentModel::update($data);
  622. $last_log = TalentLogApi::getLastLog($data["id"], 1);
  623. if ($last_log["new_state"] != TalentState::SCND_SAVE) {
  624. TalentLogApi::write(1, $data["id"], $checkState, "保存未提交", 1);
  625. } else {
  626. TalentLogApi::setActive($last_log["id"], 1); //更新修改时间
  627. }
  628. } else {
  629. //新增
  630. $data["enterprise_id"] = $this->user["uid"];
  631. $id = TalentModel::insertGetId($data);
  632. TalentLogApi::write(1, $id, $checkState, "保存未提交", 1);
  633. $whr = [];
  634. $whr[] = ["fileId", "in", $files];
  635. $upd_checklog["mainId"] = $id;
  636. Db::table("new_talent_checklog")->where($whr)->save($upd_checklog);
  637. }
  638. } else if ($checkState == TalentState::SCND_SUBMIT) {
  639. $data["new_submit_time"] = date("Y-m-d H:i:s");
  640. TalentModel::update($data);
  641. TalentLogApi::write(1, $data["id"], $checkState, "确认提交审核", 1);
  642. } else {
  643. throw new ValidateException($error_msg);
  644. }
  645. if ($id) {
  646. if ($deletes) {
  647. //删除多余的附件,一般是选择人才类型留下来的
  648. $whr = [];
  649. $whr[] = ["typeId", "in", $deletes];
  650. $whr[] = ["id", "in", $files];
  651. $_wait_del_files = Db::table("new_talent_file")->where($whr)->select()->toArray();
  652. $_logfileIds[] = [];
  653. foreach ($_wait_del_files as $_del_file) {
  654. $_logfileIds[] = $_del_file["id"];
  655. @unlink("storage/" . $_del_file["url"]);
  656. }
  657. Db::table("new_talent_file")->where($whr)->delete();
  658. if ($_logfileIds) {
  659. $whr = [];
  660. $whr[] = ["fileId", "in", $_logfileIds];
  661. $_upd_checklog["description"] = "删除附件";
  662. $_upd_checklog["updateUser"] = sprintf("%s(%s)", $this->user["account"], $this->user["companyName"] ?: $this->user["rolename"]);
  663. $_upd_checklog["updateTime"] = date("Y-m-d H:i:s");
  664. Db::table("new_talent_checklog")->where($whr)->save($_upd_checklog);
  665. }
  666. }
  667. $whr = [];
  668. $whr[] = ["id", "in", $files];
  669. Db::table("new_talent_file")->where($whr)->save(["mainId" => $id]);
  670. $res = ["code" => 200, "msg" => $success_msg, "obj" => ["id" => $id, "checkState" => $checkState]];
  671. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  672. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  673. exit();
  674. } else {
  675. throw new ValidateException($error_msg);
  676. }
  677. } catch (ValidateException $e) {
  678. $res = ["msg" => $e->getMessage()];
  679. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  680. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  681. exit();
  682. }
  683. }
  684. private function icSave($info, \think\Request $request, $checkState) {
  685. try {
  686. $batch = \app\common\api\BatchApi::getValidBatch(1, $this->user["type"]);
  687. if (!$batch) {
  688. throw new ValidateException("不在人才认定申报申请时间内");
  689. }
  690. $param = $request->param();
  691. validate(TalentInfo::class)->check($param);
  692. $id = $param["id"];
  693. if ($id) {
  694. if (!$info || $info["id"] != $id || $info["enterprise_id"] != $this->user["uid"]) {
  695. throw new ValidateException("没有对应的人才认定申报信息");
  696. }
  697. }
  698. $files = $param["uploadFiles"];
  699. $data["headimgurl"] = $info["headimgurl"];
  700. if ($request->file()) {
  701. $headimg = $request->file("photo");
  702. $upload = new \app\common\api\UploadApi();
  703. $result = $upload->uploadOne($headimg, "image", "talent/photo");
  704. $file = imagecreatefromstring(file_get_contents("storage/" . $result->filepath));
  705. $width = imagesx($file);
  706. $height = imagesy($file);
  707. //免冠二寸照长宽413:579
  708. if ($width * 579 != $height * 413) {
  709. @unlink("storage/" . $result->filepath); //像素不符合,删除上传文件
  710. throw new ValidateException("近期免冠半身彩照(二寸)不符合二寸像素标准。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
  711. }
  712. if ($info && $info["headimgurl"]) {
  713. //如果新照片符合像素要求,则删除旧照片
  714. $old_head_url = "storage/" . $info["headimgurl"];
  715. if (file_exists($old_head_url))
  716. @unlink($old_head_url);
  717. }
  718. $data["headimgurl"] = $result->filepath;
  719. }
  720. if (!$data["headimgurl"] && $checkState == TalentState::SCND_SUBMIT)
  721. throw new ValidateException("请上传头像。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
  722. $where = [];
  723. $where[] = ["project", "=", 1];
  724. $where[] = ["type", "=", $this->user["type"]];
  725. $where[] = ["must", "=", 1];
  726. $where[] = ["active", "=", 1];
  727. $where[] = ["delete", "=", 0];
  728. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  729. $age = 0;
  730. if ($param["birthday"]) {
  731. $birthday = $param["birthday"];
  732. $birthdayYear = substr($birthday, 0, 4);
  733. $currentYear = date("Y");
  734. $age = $currentYear - $birthdayYear;
  735. }
  736. $ft_ids = [];
  737. $deletes = [];
  738. foreach ($filetypes as $ft) {
  739. if ($ft["option"]) {
  740. if ($ft["rel"] == "birthday") {
  741. if ($age < $ft["option"]) {
  742. $deletes[] = $ft["id"];
  743. continue;
  744. }
  745. } else {
  746. $selectVal = $param[$ft["rel"]];
  747. $conditions = array_filter(explode(",", $ft["option"]));
  748. if (!in_array($selectVal, $conditions)) {
  749. $deletes[] = $ft["id"];
  750. continue;
  751. }
  752. }
  753. }
  754. $ft_ids[] = $ft["id"];
  755. }
  756. $data["apply_year"] = $batch["batch"];
  757. $all_valid_keys = ["talent_type", "name", "card_type", "card_number", "sex", "birthday", "nationality", "province", "city", "county", "nation", "politics", "experience", "education",
  758. "import_way", "cur_entry_time", "position",
  759. "source", "source_batch", "fujian_highcert_pubtime", "fujian_highcert_exptime", "quanzhou_highcert_pubtime", "quanzhou_highcert_exptime", "source_city", "source_county",
  760. "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "professional", "bank", "bank_number", "bank_branch_name", "bank_account",
  761. "study_abroad", "abroad_school", "abroad_major", "phone", "email", "annual_salary", "pro_qua"];
  762. foreach ($all_valid_keys as $key) {
  763. $data[$key] = trim($param[$key]);
  764. }
  765. if (in_array($data["talent_type"], [1, 2])) {
  766. $data["tax_insurance_month"] = $param["tax_insurance_month"];
  767. $data["labor_contract_rangetime"] = $param["labor_contract_rangetime"];
  768. $data["fst_work_time"] = $param["fst_work_time"];
  769. $data['pre_import_type'] = null;
  770. } else {
  771. $data["tax_insurance_month"] = null;
  772. $data["labor_contract_rangetime"] = null;
  773. $data["fst_work_time"] = null;
  774. $data['pre_import_type'] = $param["pre_import_type"];
  775. }
  776. if ($data["study_abroad"] == 1) {
  777. $data["abroad_school"] = $param["abroad_school"];
  778. $data["abroad_major"] = $param["abroad_major"];
  779. } else {
  780. $data["abroad_school"] = null;
  781. $data["abroad_major"] = null;
  782. }
  783. switch ($data["source"]) {
  784. case 1:
  785. $data["source_batch"] = $param["source_batch"];
  786. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  787. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  788. $data["source_city"] = null;
  789. break;
  790. case 2:
  791. $data["source_batch"] = $param["source_batch"];
  792. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  793. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  794. $data["source_county"] = null;
  795. break;
  796. case 3:
  797. $data["source_batch"] = $param["source_batch"];
  798. $data["fujian_highcert_pubtime"] = $param["fujian_highcert_pubtime"];
  799. $data["fujian_highcert_exptime"] = $param["fujian_highcert_exptime"];
  800. $data["source_city"] = $param["source_city"];
  801. break;
  802. case 4:
  803. $data["source_batch"] = $param["source_batch"];
  804. $data["quanzhou_highcert_pubtime"] = $param["quanzhou_highcert_pubtime"];
  805. $data["quanzhou_highcert_exptime"] = $param["quanzhou_highcert_exptime"];
  806. $data["source_county"] = $param["source_county"];
  807. break;
  808. }
  809. $condition_info = Db::table("new_talent_condition")->findOrEmpty($param["talent_condition"]);
  810. if ($condition_info["isSalary"] == 1) {
  811. $data["annual_salary"] = $param["annual_salary"];
  812. } else {
  813. $data["annual_salary"] = null;
  814. }
  815. if ($info["real_state"] == TalentState::FST_VERIFY_REJECT) {
  816. //真实状态11是驳回,需要判断什么字段可以提交
  817. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  818. $tmp_data = $data;
  819. $data = [];
  820. foreach ($modify_fields as $field) {
  821. $data[$field] = $tmp_data[$field];
  822. }
  823. }
  824. $data["checkState"] = $checkState;
  825. $data["id"] = $id;
  826. $success_msg = "提交成功";
  827. $error_msg = "提交失败";
  828. if ($checkState == TalentState::SCND_SAVE) {
  829. $success_msg = "保存成功";
  830. if ($data["id"]) {
  831. //编辑
  832. TalentModel::update($data);
  833. $last_log = TalentLogApi::getLastLog($data["id"], 1);
  834. if ($last_log["new_state"] != TalentState::SCND_SAVE) {
  835. TalentLogApi::write(1, $data["id"], $checkState, "保存未提交", 1);
  836. } else {
  837. TalentLogApi::setActive($last_log["id"], 1); //更新修改时间
  838. }
  839. } else {
  840. //新增
  841. $data["enterprise_id"] = $this->user["uid"];
  842. $id = TalentModel::insertGetId($data);
  843. TalentLogApi::write(1, $id, $checkState, "保存未提交", 1);
  844. $whr = [];
  845. $whr[] = ["fileId", "in", $files];
  846. $upd_checklog["mainId"] = $id;
  847. Db::table("new_talent_checklog")->where($whr)->save($upd_checklog);
  848. }
  849. } else if ($checkState == TalentState::SCND_SUBMIT) {
  850. $data["new_submit_time"] = date("Y-m-d H:i:s");
  851. TalentModel::update($data);
  852. TalentLogApi::write(1, $data["id"], $checkState, "确认提交审核", 1);
  853. } else {
  854. throw new ValidateException($error_msg);
  855. }
  856. if ($id) {
  857. if ($deletes) {
  858. //删除多余的附件,一般是选择人才类型留下来的
  859. $whr = [];
  860. $whr[] = ["typeId", "in", $deletes];
  861. $whr[] = ["id", "in", $files];
  862. $_wait_del_files = Db::table("new_talent_file")->where($whr)->select()->toArray();
  863. $_logfileIds[] = [];
  864. foreach ($_wait_del_files as $_del_file) {
  865. $_logfileIds[] = $_del_file["id"];
  866. @unlink("storage/" . $_del_file["url"]);
  867. }
  868. Db::table("new_talent_file")->where($whr)->delete();
  869. if ($_logfileIds) {
  870. $whr = [];
  871. $whr[] = ["fileId", "in", $_logfileIds];
  872. $_upd_checklog["description"] = "删除附件";
  873. $_upd_checklog["updateUser"] = sprintf("%s(%s)", $this->user["account"], $this->user["companyName"] ?: $this->user["rolename"]);
  874. $_upd_checklog["updateTime"] = date("Y-m-d H:i:s");
  875. Db::table("new_talent_checklog")->where($whr)->save($_upd_checklog);
  876. }
  877. }
  878. $whr = [];
  879. $whr[] = ["id", "in", $files];
  880. Db::table("new_talent_file")->where($whr)->save(["mainId" => $id]);
  881. $res = ["code" => 200, "msg" => $success_msg, "obj" => ["id" => $id, "checkState" => $checkState]];
  882. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  883. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  884. exit();
  885. } else {
  886. throw new ValidateException($error_msg);
  887. }
  888. } catch (ValidateException $e) {
  889. $res = ["msg" => $e->getMessage()];
  890. $callback = $checkState == TalentState::SCND_SAVE ? "infoCallback" : "submitCallback";
  891. echo sprintf("<script>parent.TalentInfoInfoDlg.{$callback}(%s);</script>", json_encode($res));
  892. exit();
  893. }
  894. }
  895. public function delete() {
  896. $id = $this->request->param("talentInfoId");
  897. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  898. if (!$info) {
  899. return json(["msg" => "操作失败"]);
  900. }
  901. $checkState = $info["checkState"];
  902. if (in_array($checkState, [0, 1])) {
  903. $log = TalentLogApi::getLastLog($id, 1);
  904. if ($log["state"] > 1) {
  905. //有提交审核记录
  906. return json(["msg" => "该申报已提交审核,无法删除"]);
  907. }
  908. }
  909. $data["id"] = $id;
  910. $data["delete"] = 1;
  911. TalentModel::update($data);
  912. return json(["msg" => "删除成功"]);
  913. }
  914. public function mixDelete() {
  915. $id = $this->request->param("talentInfoId");
  916. $info = Talent::chkIsOwner($id, $this->user["uid"]);
  917. if (!$info) {
  918. return json(["msg" => "操作失败"]);
  919. }
  920. $checkState = $info["checkState"];
  921. if (in_array($checkState, [0, TalentState::SCND_SAVE])) {
  922. $log = TalentLogApi::getLastLog($id, 1);
  923. if ($log["state"] > 1) {
  924. //有提交审核记录
  925. return json(["msg" => "该申报已提交审核,无法删除"]);
  926. }
  927. }
  928. $data["id"] = $id;
  929. $data["delete"] = 1;
  930. TalentModel::update($data);
  931. return json(["msg" => "删除成功"]);
  932. }
  933. }