request, $step); return json($res); } /** * 积分申报入口 */ public function apply(\think\Request $request) { $type = $this->user["type"]; $param = $request->param(); $id = isset($param["id"]) ? $param["id"] : 0; $info = IntegralRecordApi::getOne($id); $ep = EnterpriseApi::getOne($this->user["uid"]); if ($info) { $info["real_state"] = TalentLogApi::getLastLog($id, Project::INTEGRAL)["state"]; } if ($info && in_array($info["checkState"], [IntegralState::VERIFY_PASS, IntegralState::REVERIFY_PASS, IntegralState::REVERIFY_FAIL])) { return $this->view($request); exit(); } if ($request->isPost()) { $checkState = $info["checkState"] ?: 0; if ($checkState == IntegralState::SAVE || $checkState == 0) { $this->save($info, $request, IntegralState::SAVE); } else if (in_array($checkState, [IntegralState::VERIFY_FAIL, IntegralState::REVERIFY_FAIL])) { $res = ["msg" => "审核失败,不能再保存"]; echo sprintf("", json_encode($res)); exit; } $res = ["msg" => "已提交审核,请耐心等待"]; echo sprintf("", json_encode($res)); exit; } $checkState = $info["checkState"] ?: 0; $info["enterprise"] = $ep; return view("", ["year" => date("Y"), "checkState" => $checkState, "row" => $info]); } public function view(\think\Request $request) { switch ($this->user["type"]) { case 1: $tpl = "view"; //晋江人才 break; case 2: $tpl = "ic_view"; //集成电路 break; } $id = $request->param("id"); $info = \app\common\api\VerifyApi::getTalentInfoById($id); return view($tpl, ["row" => $info]); } /** * 提交表单(新:混合基础信息人才申报信息)晋江人才 */ private function submitToCheck() { $params = $this->request->param(); $id = $params["id"]; $info = TalentApi::chkIsOwner($id, $this->user["uid"]); if ($info) { $info["real_state"] = TalentLogApi::getLastLog($id, 1)["state"]; } $checkState = $info["checkState"]; if ($checkState == TalentState::SCND_SAVE || !$id) { $field_dict = \app\common\api\DictApi::getTalentFields(4); $no_empty = ["name", "nation", "card_type", "card_number", "sex", "birthday", "politics", "nationality", "province", "city", "county", "talent_type", "experience", "education", "talent_arrange", "talent_condition", "highest_degree", "graduate_school", "major", "bank", "bank_number", "bank_branch_name", "bank_account", "study_abroad", "phone", "email", "import_way", "cur_entry_time", "cur_entry_time", "position", "source"]; $where = []; $where[] = ["rel", "=", "study_abroad"]; $where[] = ["project", "=", 1]; $where[] = ["active", "=", 1]; $where[] = ["delete", "=", 0]; $where[] = ["type", "=", $this->user["type"]]; $where[] = ["isConditionFile", "<>", 1]; $abroad_files = Db::table("new_common_filetype")->where($where)->select()->toArray(); //留学的附件 $abroad_file_ids = null; if ($abroad_files) $abroad_file_ids = array_column($abroad_files, "id"); if (in_array($params["talent_type"], [1, 2])) { $no_empty[] = "tax_insurance_month"; $no_empty[] = "labor_contract_rangetime"; } if ($params["talent_type"] == 3) { $no_empty[] = "pre_import_type"; } if ($params["study_abroad"] == 1) { $no_empty[] = "abroad_school"; $no_empty[] = "abroad_major"; } if (in_array($params["source"], [1, 3])) { $no_empty[] = "source_batch"; $no_empty[] = "fujian_highcert_pubtime"; $no_empty[] = "fujian_highcert_exptime"; if ($params["source"] == 3) { $no_empty[] = "source_city"; } } if (in_array($params["source"], [2, 4])) { $no_empty[] = "source_batch"; $no_empty[] = "quanzhou_highcert_pubtime"; $no_empty[] = "quanzhou_highcert_exptime"; if ($params["source"] == 4) { $no_empty[] = "source_county"; } } $condition_info = Db::table("new_talent_condition")->findOrEmpty($params["talent_condition"]); if ($condition_info["isSalary"] == 1) { $no_empty[] = "annual_salary"; } $no_empty = array_filter($no_empty); $return = []; foreach ($no_empty as $key) { if (!$params[$key]) { $return[] = sprintf("请填写“%s”", $field_dict[$key]); } } if (count($return) > 0) { $res = ["msg" => implode("
", $return)]; echo sprintf("", json_encode($res)); exit; } if ($condition_info["bindFileTypes"] && $info["source"] == 5) { $whr[] = ["id", "in", $condition_info["bindFileTypes"]]; $whr[] = ["must", "=", 1]; } $where = []; $where[] = ["project", "=", 1]; $where[] = ["type", "=", $this->user["type"]]; $where[] = ["must", "=", 1]; $where[] = ["active", "=", 1]; $where[] = ["delete", "=", 0]; $where[] = ["isConditionFile", "<>", 1]; if ($whr) { $filetypes = Db::table("new_common_filetype")->whereOr([$where, $whr])->select()->toArray(); } else { $filetypes = Db::table("new_common_filetype")->where($where)->select()->toArray(); } $age = 0; if ($params["birthday"]) { $birthday = $params["birthday"]; $birthdayYear = substr($birthday, 0, 4); $currentYear = date("Y"); $age = $currentYear - $birthdayYear; } $ft_ids = []; $deletes = []; foreach ($filetypes as $ft) { if ($ft["option"]) { if ($ft["rel"] == "birthday") { if ($age < $ft["option"]) { $deletes[] = $ft["id"]; continue; } } else { $selectVal = $params[$ft["rel"]]; $conditions = array_filter(explode(",", $ft["option"])); if (!in_array($selectVal, $conditions)) { $deletes[] = $ft["id"]; continue; } } } $ft_ids[] = $ft["id"]; } if ($params["study_abroad"] == 1) { //选中留学,如果存在留学附件变成必传 $ft_ids = array_unique(array_merge($ft_ids, (array) $abroad_file_ids)); } else { //没选中,留学附件就算设成必传也不用验证 $ft_ids = array_diff($ft_ids, (array) $abroad_file_ids); } $whr = []; if ($id) { $whr[] = ["mainId", "=", $id]; } else { if ($params["uploadFiles"]) $whr[] = ["id", "in", $params["uploadFiles"]]; } $whr[] = ["typeId", "in", $ft_ids]; $distinct_filetypes = Db::table("new_talent_file")->where($whr)->distinct(true)->field("typeId")->select(); $upload_type_counts = count($distinct_filetypes); if ($upload_type_counts != count($ft_ids)) { $res = ["msg" => "请留意附件上传栏中带*号的内容均为必传项,请上传完整再提交审核"]; echo sprintf("", json_encode($res)); exit; } return $this->mixSave($info, $this->request, TalentState::SCND_SUBMIT); } 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])) { $res = ["msg" => "审核失败,不能再提交审核"]; echo sprintf("", json_encode($res)); exit; } $res = ["msg" => "已提交审核,请耐心等待"]; echo sprintf("", json_encode($res)); exit; } /** * 保存申报表单 * @param type $info talent_info * @param type $param request->param(); */ private function save($info, \think\Request $request, $checkState) { try { $batch = \app\common\api\BatchApi::getValidBatch(Project::INTEGRAL, $this->user["type"]); if (!$batch) { throw new ValidateException("不在人才认定申报申请时间内"); } $param = $request->param(); validate(IntegralValidator::class)->check($param); $id = $param["id"]; $files = $param["uploadFiles"]; if ($id) { if (!$info || $info["id"] != $id || $info["enterprise_id"] != $this->user["uid"]) { throw new ValidateException("没有对应的积分申报信息"); } } $all_valid_keys = ["name", "card_type", "card_number", "phone", "email"]; foreach ($all_valid_keys as $key) { $data[$key] = trim($param[$key]); } $updateDetailList = []; $insertDetailList = []; $data["batch_id"] = $batch["id"]; $detail_ids = $param["detail_id"]; $projectTypes = $param["projectType"]; $projectIds = $param["projectId"]; $item_ids = $param["item_id"]; $amounts = $param["amount"]; if ($info["real_state"] == IntegralState::VERIFY_REJECT) { //真实状态是驳回,需要判断什么字段可以提交 $modify_fields = array_filter(explode(",", $info["modify_fields"])); $tmp_data = $data; $data = []; foreach ($modify_fields as $field) { $data[$field] = $tmp_data[$field]; } $tmp_item_ids = []; if ($info["modify_files"]) { $detailCounts = count($detail_ids); for ($i = 0; $i < $detailCounts; $i++) { if (!in_array($item_ids[$i], $tmp_item_ids)) { $tmp_item_ids[] = $item_ids[$i]; } if ($detail_ids[$i]) { $updateDetailList[] = [ "id" => $detail_ids[$i], "record_id" => "", "item_id" => "", "amount" => "", "unit" => "", "file_id" ]; } else { $insertDetailList[] = [ "id" => getStringId(), "record_id" => "", "item_id" => "", "amount" => "", "unit" => "", "file_id" ]; } } } } $data["checkState"] = $checkState; $data["id"] = $id; $success_msg = "提交成功"; $error_msg = "提交失败"; if ($checkState == IntegralState::SAVE) { $success_msg = "保存成功"; if ($data["id"]) { //编辑 TalentModel::update($data); $last_log = TalentLogApi::getLastLog($data["id"], Project::INTEGRAL); if ($last_log["new_state"] != IntegralState::SAVE) { TalentLogApi::write(1, $data["id"], $checkState, "保存未提交", 1); } else { TalentLogApi::setActive($last_log["id"], 1); //更新修改时间 } } else { //新增 $data["enterprise_id"] = $this->user["uid"]; $data["id"] = getStringId(); \app\common\model\IntegralRecord::insert($data); TalentLogApi::write(Project::INTEGRAL, $data["id"], $checkState, "保存未提交", 1); $whr = []; $whr[] = ["fileId", "in", $files]; $upd_checklog["mainId"] = $data["id"]; Db::table("new_talent_checklog")->where($whr)->save($upd_checklog); } } else if ($checkState == IntegralState::SUBMIT) { if (!$info["first_submit_time"]) { $data["first_submit_time"] = date("Y-m-d H:i:s"); } else { $data["new_submit_time"] = date("Y-m-d H:i:s"); } if ($data["id"]) { \app\common\model\IntegralRecord::update($data); } else { //新增 $data["enterprise_id"] = $this->user["uid"]; $data["id"] = getStringId(); \app\common\model\IntegralRecord::insert($data); $whr = []; $whr[] = ["fileId", "in", $files]; $upd_checklog["mainId"] = $data["id"]; Db::table("new_talent_checklog")->where($whr)->save($upd_checklog); } TalentLogApi::write(Project::INTEGRAL, $id, $checkState, "确认提交审核", 1); } else { throw new ValidateException($error_msg); } if ($data["id"]) { //删除多余的附件,一般是选择人才类型留下来的 $whr = []; $whr[] = ["mainId", "=", $data["id"]]; $whr[] = ["type", "=", Project::INTEGRAL]; $whr[] = ["id", "not in", $files]; $_wait_del_files = Db::table("new_talent_file")->where($whr)->select()->toArray(); $_logfileIds[] = []; foreach ($_wait_del_files as $_del_file) { $_logfileIds[] = $_del_file["id"]; @unlink("storage/" . $_del_file ["url"]); } Db::table("new_talent_file")->where($whr)->delete(); if ($_logfileIds) { $whr = []; $whr[] = ["fileId", "in", $_logfileIds]; $_upd_checklog["description"] = "删除附件"; $_upd_checklog["updateUser"] = sprintf("%s(%s)", $this->user["account"], $this->user["companyName"] ?: $this->user["rolename"]); $_upd_checklog["updateTime"] = date("Y-m-d H:i:s"); Db::table("new_talent_checklog")->where($whr)->save($_upd_checklog); } $whr = []; $whr[] = ["id", "in", $files]; Db::table("new_talent_file")->where($whr)->save(["mainId" => $id]); $res = ["code" => 200, "msg" => $success_msg, "obj" => ["id" => $id, "checkState" => $checkState]]; $callback = $checkState == IntegralState::SAVE ? "infoCallback" : "submitCallback"; echo sprintf("", json_encode($res)); exit(); } else { throw new ValidateException($error_msg); } } catch (ValidateException $e) { $res = ["msg" => $e->getMessage()]; $callback = $checkState == IntegralState::SAVE ? "infoCallback" : "submitCallback"; echo sprintf("", json_encode($res)); exit(); } } public function delete() { $id = $this->request->param("id"); $info = IntegralRecordApi::chkIsOwner($id, $this->user["uid"]); if (!$info) { return json(["msg" => "操作失败"]); } $checkState = $info["checkState"]; if (in_array($checkState, [0, 1])) { $log = TalentLogApi::getLastLog($id, Project::INTEGRAL); if ($log["state"] > 1) { //有提交审核记录 return json(["msg" => "该申报已提交审核,无法删除"]); } } $data["id"] = $id; $data["delete"] = 1; \app\common\model\IntegralRecord::update($data); return json(["msg" => "删除成功"]); } }