Integral.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. <?php
  2. namespace app\enterprise\controller;
  3. use app\enterprise\common\EnterpriseController;
  4. use think\facade\Db;
  5. use app\common\api\EnterpriseApi;
  6. use app\enterprise\validate\TalentInfo;
  7. use app\common\api\IntegralState;
  8. use app\common\api\IntegralRecordApi;
  9. use app\common\api\TalentLogApi;
  10. use app\common\api\Project;
  11. /**
  12. * Description of 积分申报
  13. *
  14. * @author sgq
  15. */
  16. class Integral extends EnterpriseController {
  17. public function index() {
  18. return view();
  19. }
  20. public function list() {
  21. $res = IntegralRecordApi::getList($this->request, $step);
  22. return json($res);
  23. }
  24. /**
  25. * 积分申报入口
  26. */
  27. public function apply(\think\Request $request) {
  28. $type = $this->user["type"];
  29. $param = $request->param();
  30. $id = isset($param["id"]) ? $param["id"] : 0;
  31. $info = IntegralRecordApi::getOne($id);
  32. $ep = EnterpriseApi::getOne($this->user["uid"]);
  33. if ($info) {
  34. $info["real_state"] = TalentLogApi::getLastLog($id, Project::INTEGRAL)["state"];
  35. }
  36. if ($info && in_array($info["checkState"], [IntegralState::VERIFY_PASS, IntegralState::REVERIFY_PASS, IntegralState::REVERIFY_FAIL])) {
  37. return $this->view($request);
  38. exit();
  39. }
  40. if ($request->isPost()) {
  41. $checkState = $info["checkState"] ?: 0;
  42. if ($checkState == IntegralState::SAVE || $checkState == 0) {
  43. $this->save($info, $request, IntegralState::SAVE);
  44. } else if (in_array($checkState, [IntegralState::VERIFY_FAIL, IntegralState::REVERIFY_FAIL])) {
  45. $res = ["msg" => "审核失败,不能再保存"];
  46. echo sprintf("<script>parent.IntegralInfoDlg.infoCallback(%s);</script>", json_encode($res));
  47. exit;
  48. }
  49. $res = ["msg" => "已提交审核,请耐心等待"];
  50. echo sprintf("<script>parent.IntegralInfoDlg.infoCallback(%s);</script>", json_encode($res));
  51. exit;
  52. }
  53. $checkState = $info["checkState"] ?: 0;
  54. $info["enterprise"] = $ep;
  55. return view("", ["year" => date("Y"), "checkState" => $checkState, "row" => $info]);
  56. }
  57. public function view(\think\Request $request) {
  58. switch ($this->user["type"]) {
  59. case 1:
  60. $tpl = "view"; //晋江人才
  61. break;
  62. case 2:
  63. $tpl = "ic_view"; //集成电路
  64. break;
  65. }
  66. $id = $request->param("id");
  67. $info = \app\common\api\VerifyApi::getTalentInfoById($id);
  68. return view($tpl, ["row" => $info]);
  69. }
  70. /**
  71. * 提交表单(新:混合基础信息人才申报信息)晋江人才
  72. */
  73. private function submitToCheck() {
  74. $params = $this->request->param();
  75. $id = $params["id"];
  76. $info = TalentApi::chkIsOwner($id, $this->user["uid"]);
  77. if ($info) {
  78. $info["real_state"] = TalentLogApi::getLastLog($id, 1)["state"];
  79. }
  80. $checkState = $info["checkState"];
  81. if ($checkState == TalentState::SCND_SAVE || !$id) {
  82. $field_dict = \app\common\api\DictApi::getTalentFields(4);
  83. $no_empty = ["name", "nation", "card_type", "card_number", "sex", "birthday", "politics", "nationality", "province", "city", "county", "talent_type", "experience", "education",
  84. "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "bank", "bank_number", "bank_branch_name",
  85. "bank_account", "study_abroad", "phone", "email", "import_way", "cur_entry_time", "cur_entry_time", "position", "source"];
  86. $where = [];
  87. $where[] = ["rel", "=", "study_abroad"];
  88. $where[] = ["project", "=", 1];
  89. $where[] = ["active", "=", 1];
  90. $where[] = ["delete", "=", 0];
  91. $where[] = ["type", "=", $this->user["type"]];
  92. $where[] = ["isConditionFile", "<>", 1];
  93. $abroad_files = Db::table("new_common_filetype")->where($where)->select()->toArray(); //留学的附件
  94. $abroad_file_ids = null;
  95. if ($abroad_files)
  96. $abroad_file_ids = array_column($abroad_files, "id");
  97. if (in_array($params["talent_type"], [1, 2])) {
  98. $no_empty[] = "tax_insurance_month";
  99. $no_empty[] = "labor_contract_rangetime";
  100. }
  101. if ($params["talent_type"] == 3) {
  102. $no_empty[] = "pre_import_type";
  103. }
  104. if ($params["study_abroad"] == 1) {
  105. $no_empty[] = "abroad_school";
  106. $no_empty[] = "abroad_major";
  107. }
  108. if (in_array($params["source"], [1, 3])) {
  109. $no_empty[] = "source_batch";
  110. $no_empty[] = "fujian_highcert_pubtime";
  111. $no_empty[] = "fujian_highcert_exptime";
  112. if ($params["source"] == 3) {
  113. $no_empty[] = "source_city";
  114. }
  115. }
  116. if (in_array($params["source"], [2, 4])) {
  117. $no_empty[] = "source_batch";
  118. $no_empty[] = "quanzhou_highcert_pubtime";
  119. $no_empty[] = "quanzhou_highcert_exptime";
  120. if ($params["source"] == 4) {
  121. $no_empty[] = "source_county";
  122. }
  123. }
  124. $condition_info = Db::table("new_talent_condition")->findOrEmpty($params["talent_condition"]);
  125. if ($condition_info["isSalary"] == 1) {
  126. $no_empty[] = "annual_salary";
  127. }
  128. $no_empty = array_filter($no_empty);
  129. $return = [];
  130. foreach ($no_empty as $key) {
  131. if (!$params[$key]) {
  132. $return[] = sprintf("请填写“%s”", $field_dict[$key]);
  133. }
  134. }
  135. if (count($return) > 0) {
  136. $res = ["msg" => implode("<br>", $return)];
  137. echo sprintf("<script>parent.IntegralInfoDlg.submitCallback(%s);</script>", json_encode($res));
  138. exit;
  139. }
  140. if ($condition_info["bindFileTypes"] && $info["source"] == 5) {
  141. $whr[] = ["id", "in", $condition_info["bindFileTypes"]];
  142. $whr[] = ["must", "=", 1];
  143. }
  144. $where = [];
  145. $where[] = ["project", "=", 1];
  146. $where[] = ["type", "=", $this->user["type"]];
  147. $where[] = ["must", "=", 1];
  148. $where[] = ["active", "=", 1];
  149. $where[] = ["delete", "=", 0];
  150. $where[] = ["isConditionFile", "<>", 1];
  151. if ($whr) {
  152. $filetypes = Db::table("new_common_filetype")->whereOr([$where, $whr])->select()->toArray();
  153. } else {
  154. $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
  155. }
  156. $age = 0;
  157. if ($params["birthday"]) {
  158. $birthday = $params["birthday"];
  159. $birthdayYear = substr($birthday, 0, 4);
  160. $currentYear = date("Y");
  161. $age = $currentYear - $birthdayYear;
  162. }
  163. $ft_ids = [];
  164. $deletes = [];
  165. foreach ($filetypes as $ft) {
  166. if ($ft["option"]) {
  167. if ($ft["rel"] == "birthday") {
  168. if ($age < $ft["option"]) {
  169. $deletes[] = $ft["id"];
  170. continue;
  171. }
  172. } else {
  173. $selectVal = $params[$ft["rel"]];
  174. $conditions = array_filter(explode(",", $ft["option"]));
  175. if (!in_array($selectVal, $conditions)) {
  176. $deletes[] = $ft["id"];
  177. continue;
  178. }
  179. }
  180. }
  181. $ft_ids[] = $ft["id"];
  182. }
  183. if ($params["study_abroad"] == 1) {
  184. //选中留学,如果存在留学附件变成必传
  185. $ft_ids = array_unique(array_merge($ft_ids, (array) $abroad_file_ids));
  186. } else {
  187. //没选中,留学附件就算设成必传也不用验证
  188. $ft_ids = array_diff($ft_ids, (array) $abroad_file_ids);
  189. }
  190. $whr = [];
  191. if ($id) {
  192. $whr[] = ["mainId", "=", $id];
  193. } else {
  194. if ($params["uploadFiles"])
  195. $whr[] = ["id", "in", $params["uploadFiles"]];
  196. }
  197. $whr[] = ["typeId", "in", $ft_ids];
  198. $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select();
  199. $upload_type_counts = count($distinct_filetypes);
  200. if ($upload_type_counts != count($ft_ids)) {
  201. $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"];
  202. echo sprintf("<script>parent.IntegralInfoDlg.submitCallback(%s);</script>", json_encode($res));
  203. exit;
  204. }
  205. return $this->mixSave($info, $this->request, TalentState::SCND_SUBMIT);
  206. } 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])) {
  207. $res = ["msg" => "审核失败,不能再提交审核"];
  208. echo sprintf("<script>parent.IntegralInfoDlg.submitCallback(%s);</script>", json_encode($res));
  209. exit;
  210. }
  211. $res = ["msg" => "已提交审核,请耐心等待"];
  212. echo sprintf("<script>parent.IntegralInfoDlg.submitCallback(%s);</script>", json_encode($res));
  213. exit;
  214. }
  215. /**
  216. * 保存申报表单
  217. * @param type $info talent_info
  218. * @param type $param request->param();
  219. */
  220. private function save($info, \think\Request $request, $checkState) {
  221. try {
  222. $batch = \app\common\api\BatchApi::getValidBatch(Project::INTEGRAL, $this->user["type"]);
  223. if (!$batch) {
  224. throw new ValidateException("不在人才认定申报申请时间内");
  225. }
  226. $param = $request->param();
  227. validate(IntegralValidator::class)->check($param);
  228. $id = $param["id"];
  229. $files = $param["uploadFiles"];
  230. if ($id) {
  231. if (!$info || $info["id"] != $id || $info["enterprise_id"] != $this->user["uid"]) {
  232. throw new ValidateException("没有对应的积分申报信息");
  233. }
  234. }
  235. $all_valid_keys = ["name", "card_type", "card_number", "phone", "email"];
  236. foreach ($all_valid_keys as $key) {
  237. $data[$key] = trim($param[$key]);
  238. }
  239. $updateDetailList = [];
  240. $insertDetailList = [];
  241. $data["batch_id"] = $batch["id"];
  242. $detail_ids = $param["detail_id"];
  243. $projectTypes = $param["projectType"];
  244. $projectIds = $param["projectId"];
  245. $item_ids = $param["item_id"];
  246. $amounts = $param["amount"];
  247. if ($info["real_state"] == IntegralState::VERIFY_REJECT) {
  248. //真实状态是驳回,需要判断什么字段可以提交
  249. $modify_fields = array_filter(explode(",", $info["modify_fields"]));
  250. $tmp_data = $data;
  251. $data = [];
  252. foreach ($modify_fields as $field) {
  253. $data[$field] = $tmp_data[$field];
  254. }
  255. $tmp_item_ids = [];
  256. if ($info["modify_files"]) {
  257. $detailCounts = count($detail_ids);
  258. for ($i = 0; $i < $detailCounts; $i++) {
  259. if (!in_array($item_ids[$i], $tmp_item_ids)) {
  260. $tmp_item_ids[] = $item_ids[$i];
  261. }
  262. if ($detail_ids[$i]) {
  263. $updateDetailList[] = [
  264. "id" => $detail_ids[$i],
  265. "record_id" => "",
  266. "item_id" => "",
  267. "amount" => "",
  268. "unit" => "",
  269. "file_id"
  270. ];
  271. } else {
  272. $insertDetailList[] = [
  273. "id" => getStringId(),
  274. "record_id" => "",
  275. "item_id" => "",
  276. "amount" => "",
  277. "unit" => "",
  278. "file_id"
  279. ];
  280. }
  281. }
  282. }
  283. }
  284. $data["checkState"] = $checkState;
  285. $data["id"] = $id;
  286. $success_msg = "提交成功";
  287. $error_msg = "提交失败";
  288. if ($checkState == IntegralState::SAVE) {
  289. $success_msg = "保存成功";
  290. if ($data["id"]) {
  291. //编辑
  292. TalentModel::update($data);
  293. $last_log = TalentLogApi::getLastLog($data["id"], Project::INTEGRAL);
  294. if ($last_log["new_state"] != IntegralState::SAVE) {
  295. TalentLogApi::write(1, $data["id"], $checkState, "保存未提交", 1);
  296. } else {
  297. TalentLogApi::setActive($last_log["id"], 1); //更新修改时间
  298. }
  299. } else {
  300. //新增
  301. $data["enterprise_id"] = $this->user["uid"];
  302. $data["id"] = getStringId();
  303. \app\common\model\IntegralRecord::insert($data);
  304. TalentLogApi::write(Project::INTEGRAL, $data["id"], $checkState, "保存未提交", 1);
  305. $whr = [];
  306. $whr[] = ["fileId", "in", $files];
  307. $upd_checklog["mainId"] = $data["id"];
  308. Db::table("new_talent_checklog")->where($whr)->save($upd_checklog);
  309. }
  310. } else if ($checkState == IntegralState::SUBMIT) {
  311. if (!$info["first_submit_time"]) {
  312. $data["first_submit_time"] = date("Y-m-d H:i:s");
  313. } else {
  314. $data["new_submit_time"] = date("Y-m-d H:i:s");
  315. }
  316. if ($data["id"]) {
  317. \app\common\model\IntegralRecord::update($data);
  318. } else {
  319. //新增
  320. $data["enterprise_id"] = $this->user["uid"];
  321. $data["id"] = getStringId();
  322. \app\common\model\IntegralRecord::insert($data);
  323. $whr = [];
  324. $whr[] = ["fileId", "in", $files];
  325. $upd_checklog["mainId"] = $data["id"];
  326. Db::table("new_talent_checklog")->where($whr)->save($upd_checklog);
  327. }
  328. TalentLogApi::write(Project::INTEGRAL, $id, $checkState, "确认提交审核", 1);
  329. } else {
  330. throw new ValidateException($error_msg);
  331. }
  332. if ($data["id"]) {
  333. //删除多余的附件,一般是选择人才类型留下来的
  334. $whr = [];
  335. $whr[] = ["mainId", "=", $data["id"]];
  336. $whr[] = ["type", "=", Project::INTEGRAL];
  337. $whr[] = ["id", "not in", $files];
  338. $_wait_del_files = Db::table("new_talent_file")->where($whr)->select()->toArray();
  339. $_logfileIds[] = [];
  340. foreach ($_wait_del_files as $_del_file) {
  341. $_logfileIds[] = $_del_file["id"];
  342. @unlink("storage/" . $_del_file ["url"]);
  343. }
  344. Db::table("new_talent_file")->where($whr)->delete();
  345. if ($_logfileIds) {
  346. $whr = [];
  347. $whr[] = ["fileId", "in", $_logfileIds];
  348. $_upd_checklog["description"] = "删除附件";
  349. $_upd_checklog["updateUser"] = sprintf("%s(%s)", $this->user["account"], $this->user["companyName"] ?: $this->user["rolename"]);
  350. $_upd_checklog["updateTime"] = date("Y-m-d H:i:s");
  351. Db::table("new_talent_checklog")->where($whr)->save($_upd_checklog);
  352. }
  353. $whr = [];
  354. $whr[] = ["id", "in", $files];
  355. Db::table("new_talent_file")->where($whr)->save(["mainId" => $id]);
  356. $res = ["code" => 200, "msg" => $success_msg, "obj" => ["id" => $id, "checkState" => $checkState]];
  357. $callback = $checkState == IntegralState::SAVE ? "infoCallback" : "submitCallback";
  358. echo sprintf("<script>parent.IntegralInfoDlg.{$callback}(%s);</script>", json_encode($res));
  359. exit();
  360. } else {
  361. throw new ValidateException($error_msg);
  362. }
  363. } catch (ValidateException $e) {
  364. $res = ["msg" => $e->getMessage()];
  365. $callback = $checkState == IntegralState::SAVE ? "infoCallback" : "submitCallback";
  366. echo sprintf("<script>parent.IntegralInfoDlg.{$callback}(%s);</script>", json_encode($res));
  367. exit();
  368. }
  369. }
  370. public function delete() {
  371. $id = $this->request->param("id");
  372. $info = IntegralRecordApi::chkIsOwner($id, $this->user["uid"]);
  373. if (!$info) {
  374. return json(["msg" => "操作失败"]);
  375. }
  376. $checkState = $info["checkState"];
  377. if (in_array($checkState, [0, 1])) {
  378. $log = TalentLogApi::getLastLog($id, Project::INTEGRAL);
  379. if ($log["state"] > 1) {
  380. //有提交审核记录
  381. return json(["msg" => "该申报已提交审核,无法删除"]);
  382. }
  383. }
  384. $data["id"] = $id;
  385. $data["delete"] = 1;
  386. \app\common\model\IntegralRecord::update($data);
  387. return json(["msg" => "删除成功"]);
  388. }
  389. }