Integral.php 18 KB

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