123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519 |
- <?php
- namespace app\enterprise\controller;
- use app\enterprise\common\EnterpriseController;
- use think\facade\Db;
- use think\facade\Log;
- use app\common\api\EnterpriseApi;
- use app\common\api\TalentLogApi;
- use think\exception\ValidateException;
- use app\common\state\ProjectState;
- use app\common\api\BatchApi;
- use app\common\api\HouseApi;
- use app\common\model\TalentLog;
- use app\common\api\DictApi;
- use app\common\state\CommonConst;
- use app\common\state\MainState;
- use app\common\api\Response;
- /**
- * Description of House
- * 购房补贴
- * @author sgq
- */
- class House extends EnterpriseController {
- public function index() {
- return view("", ['type' => session("user")['type']]);
- }
- public function list() {
- $params = $this->request;
- $order = trim($params["order"]) ?: "desc";
- $offset = trim($params["offset"]) ?: 0;
- $limit = trim($params["limit"]) ?: 10;
- $where = [];
- $where[] = ["type", "=", $this->user["type"]];
- $where[] = ["enterpriseId", "=", $this->user["uid"]];
- if ($params["year"]) {
- $where[] = ["year", "=", $params["year"]];
- }
- if (\StrUtil::isNotEmpAndNull($params["name"])) {
- $where[] = ["name", "like", "%" . $params["name"] . "%"];
- }
- if (\StrUtil::isNotEmpAndNull($params["idCard"])) {
- $where[] = ["idCard", "like", "%" . $params["idCard"] . "%"];
- }
- if ($params["talentArrange"]) {
- $where[] = ["talentArrange", "=", $params["talentArrange"]];
- }
- if (\StrUtil::isNotEmpAndNull($params["spouseName"])) {
- $where[] = ["spouseName", "like", "%" . $params["spouseName"] . "%"];
- }
- if (\StrUtil::isNotEmpAndNull($params["spouseIdcard"])) {
- $where[] = ["spouseIdcard", "like", "%" . $params["spouseIdcard"] . "%"];
- }
- if (\StrUtil::isNotEmpAndNull($params["childName"])) {
- $where[] = ["childName", "like", "%" . $params["childName"] . "%"];
- }
- if (\StrUtil::isNotEmpAndNull($params["childIdCard"])) {
- $where[] = ["childIdCard", "like", "%" . $params["childIdCard"] . "%"];
- }
- if ($params["marryStatus"]) {
- $where[] = ["marryStatus", "=", $params["marryStatus"]];
- }
- $count = Db::table("un_housepurchase")->where($where)->count();
- $list = Db::table("un_housepurchase")->where($where)->limit($offset, $limit)->order("createTime $order")->select()->toArray();
- //获取字典表婚姻状态
- $marryMap = DictApi::selectByParentCode("marry_status");
- $cardTypeMap = DictApi::selectByParentCode("card_type");
- $streetMap = DictApi::selectByParentCode("street");
- $levelMap = DictApi::selectByParentCode("talent_arrange");
- $whrCondition = [];
- $whrCondition[] = ["type", "=", $this->user["type"]];
- $conditionMap = \app\common\model\TalentCondition::where($whrCondition)->column("name", "id");
- foreach ($list as &$item) {
- $item["marryStatusName"] = $marryMap[$item["marryStatus"]];
- $item["cardTypeName"] = $cardTypeMap[$item["cardType"]];
- $item["spouseCardTypeName"] = $cardTypeMap[$item["spouseCardType"]];
- $item["childCardTypeName"] = $cardTypeMap[$item["childCardType"]];
- $item["streetName"] = $streetMap[$item["street"]];
- $item["talentArrangeName"] = $levelMap[$item["talentArrange"]];
- $item["identifyConditionCH"] = $conditionMap[$item["identifyCondition"]];
- }unset($item);
- return json(["rows" => $list, "total" => $count]);
- }
- /**
- * 申请
- */
- public function apply(\think\Request $request) {
- $param = $request->param();
- $id = isset($param["id"]) ? $param["id"] : 0;
- $vars = [];
- if ($id) {
- $info = HouseApi::getInfoById($id);
- $childrenList = HouseApi::getChildren($id);
- $houseInfo = HouseApi::getHouseInfo($info["idCard"]);
- $dicts = DictApi::selectByParentCode("card_type");
- $vars["dicts"] = $dicts;
- $vars["row"] = $info;
- $vars["hand"] = $houseInfo ? 2 : 1;
- $vars["childrenList"] = $childrenList;
- }
- if ($request->isPost()) {
- return $this->save($info, $request);
- }
- $batch = $info["year"] ?: BatchApi::getValidBatch(ProjectState::HOUSE, $this->user["type"])["batch"];
- $vars["year"] = $batch;
- $vars["type"] = $this->user["type"];
- return view("", $vars);
- }
- public function detail(\think\Request $request) {
- $info = HouseApi::getInfoById($id);
- $childrenList = HouseApi::getChildren($id);
- $dicts = DictApi::selectByParentCode("card_type");
- $vars["dicts"] = $dicts;
- $vars["row"] = $info;
- $vars["childrenList"] = $childrenList;
- $vars["type"] = $this->user["type"];
- return view("", $vars);
- }
- private function other_validate($info) {
- $responseObj = new \stdClass();
- /* 校验姓名是否与人才库一致 */
- $where = [];
- $where[] = ["checkState", ">=", \app\common\api\TalentState::REVERIFY_PASS];
- $where[] = ["checkState", "not in", [\app\common\api\TalentState::REVERIFY_REJECT, \app\common\api\TalentState::REVERIFY_FAIL]];
- $where[] = ["card_number", "=", $info["idCard"]];
- $talentInfo = Db::table("new_talent_info")->where($where)->order("createTime desc")->find();
- if ($talentInfo && $talentInfo["name"] != $info["name"]) {
- $responseObj->msg = "该证件号码的姓名与人才库姓名不匹配!";
- return $responseObj;
- }
- $year = substr($info["year"], 0, 4);
- /* 查询当前批次审核通过的数量以及当前批次未审核完成的数量 */
- $where = [];
- $where[] = ["year", "like", "{$year}%"];
- $where[] = ["idCard", "=", $info["idCard"]];
- $where[] = ["checkState", "<>", LaState::LA_NOTPASS];
- if ($info["id"]) {
- $where[] = ["id", "<>", $info["id"]];
- }
- $nowYearApplyCount = LaModel::where($where)->count();
- if ($nowYearApplyCount > 0) {
- $responseObj->msg = "不能重复申报";
- return $responseObj;
- }
- if (!$info["id"]) {
- $passYears = CommonLaApi::getPassYearsByIdCard($info["idCard"]);
- if (in_array($year, $passYears)) {
- return $responseObj->msg = "您今年度已经申报过了,每年度仅能享受一次生活补贴!";
- }
- if (count($passYears) >= 3) {
- return $responseObj->msg = "一个人最多享受三次!";
- }
- }
- $responseObj->code = 200;
- return $responseObj;
- }
- private function validateIsEdit($checkState) {
- $responseObj = new \stdClass();
- if ($checkState != LaState::LA_SAVE && $checkState != LaState::LA_BEFORE_REJECT && $checkState != LaState::LA_FIRST_REJECT) {
- if ($checkState == LaState::LA_NOTPASS) {
- $responseObj->msg = "您的申报审核不通过,无法操作";
- } else if ($checkState >= LaState::LA_PASS) {
- $responseObj->msg = "您的申报已审核通过,无法操作";
- } else {
- $responseObj->msg = "您的申报正在审核中,请耐心等待";
- }
- $responseObj->code = 500;
- return $responseObj;
- }
- $responseObj->code = 200;
- return $responseObj;
- }
- /**
- * 提交表单
- */
- public function submitToCheck() {
- try {
- $id = $this->request["id"];
- $info = CommonLaApi::getInfoById($id);
- if (!$info) {
- throw new ValidateException("提交审核失败,请先填写基础信息");
- }
- if ($info["enterpriseId"] != $this->user["uid"]) {
- throw new ValidateException("没有对应的人才认定申报信息");
- }
- $batch = BatchApi::checkBatchValid(["type" => ProjectState::LIVINGALLOWANCE, "year" => $info["year"], "first_submit_time" => $info["firstSubmitTime"]], $this->user["type"]);
- if ($batch["code"] != 200) {
- throw new ValidateException($batch["msg"]);
- }
- $response = $this->validateIsEdit($info["checkState"]);
- if ($response->code != 200) {
- throw new ValidateException($response->msg);
- }
- validate(LivingAllowanceValidator::class)->check($info);
- $response = $this->other_validate($info);
- if ($response->code != 200) {
- throw new ValidateException($response->msg);
- }
- $where = [];
- $where[] = ["mainId", "=", $id];
- $where[] = ["type", "=", ProjectState::LIVINGALLOWANCE];
- $uploadedFileTypes = Db::table("new_talent_file")->where($where)->column("distinct typeId");
- $where = [];
- $where[] = ["project", "=", ProjectState::LIVINGALLOWANCE];
- $where[] = ["type", "=", $this->user["type"]];
- $where[] = ["must", "=", 1];
- $where[] = ["active", "=", 1];
- $where[] = ["delete", "=", 0];
- $where[] = ["id", "not in", $uploadedFileTypes];
- $unUploadfiletypes = Db::table("new_common_filetype")->where($where)->select()->toArray();
- if ($unUploadfiletypes) {
- $msg = "以下附件为必传:<br>";
- foreach ($unUploadfiletypes as $ft) {
- $msg .= "<span style='color:red;'>*</span>" . $ft["name"] . "<br>";
- }
- throw new ValidateException($msg);
- }
- $data["id"] = $id;
- $data["checkState"] = LaState::LA_NEED_FIRST_CHECK;
- if (!$info["firstSubmitTime"]) {
- $data["firstSubmitTime"] = date("Y-m-d H:i:s");
- }
- $data["newSubmitTime"] = date("Y-m-d H:i:s");
- $data["checkMsg"] = "";
- $data["files"] = "";
- $data["fields"] = "";
- $res = LaModel::update($data);
- if ($res) {
- $user = session("user");
- $log["id"] = getStringId();
- $log["active"] = 1;
- $log["state"] = 1;
- $log["step"] = 0;
- $log["stateChange"] = LaState::getStateDesc($info["checkState"]) . "->" . LaState::getStateDesc($data["checkState"]);
- $log["type"] = ProjectState::LIVINGALLOWANCE;
- $log["mainId"] = $id;
- $log["description"] = "确认提交审核";
- $log["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
- $log["createTime"] = date("Y-m-d H:i:s");
- TalentLog::create($log);
- return json(["code" => 200, "msg" => "提交审核成功"]);
- }
- throw new ValidateException("提交审核失败");
- } catch (ValidateException $e) {
- $responseObj = new \stdClass();
- $responseObj->code = 500;
- $responseObj->msg = $e->getMessage();
- return json($responseObj);
- } catch (\think\Exception $e) {
- $res = ["code" => 500, "msg" => "发生预料外错误,请联系管理员处理,错误代码:" . $e->getCode()];
- $logInfo = [
- "enterprise_id" => $this->user["uid"],
- "data" => $data,
- "controller" => $this->request->controller(),
- "action" => $this->request->action(),
- "errCode" => $e->getCode(),
- "errMsg" => $e->getMessage()
- ];
- Log::write($logInfo, "error");
- return json($res);
- }
- }
- public function save($info, \think\Request $request) {
- try {
- $batch = BatchApi::checkBatchValid(["type" => ProjectState::LIVINGALLOWANCE, "year" => $info["year"], "first_submit_time" => $info["firstSubmitTime"]], $this->user["type"]);
- if ($batch["code"] != 200) {
- throw new ValidateException($batch["msg"]);
- }
- if ($info) {
- $response = $this->validateIsEdit($info["checkState"]);
- if ($response->code != 200) {
- throw new ValidateException($response->msg);
- }
- }
- $data = $request->param();
- $data["year"] = $batch["batch"];
- validate(LivingAllowanceValidator::class)->check($data);
- $response = $this->other_validate($data);
- if ($response->code != 200) {
- throw new ValidateException($response->msg);
- }
- $id = $data["id"];
- if ($id) {
- if (!$info || $info["id"] != $id || $info["enterpriseId"] != $this->user["uid"]) {
- throw new ValidateException("没有对应的人才认定申报信息");
- }
- $data["checkState"] = $info["checkState"];
- } else {
- $data["id"] = getStringId();
- $data["active"] = 1;
- $data["checkState"] = LaState::LA_SAVE;
- $data["isPublic"] = 1;
- $data["recommendIsPay"] = 0;
- $data["isPay"] = 0;
- $data["createTime"] = date("Y-m-d H:i:s");
- $data["createUser"] = $this->user["uid"];
- $data["creditStatus"] = 1;
- $count = count(CommonLaApi::getPassYearsByIdCard($data["idCard"]));
- $data["applyCount"] = $count + 1;
- if ($data["applyCount"] > 1 && !$data["personalTax"]) {
- throw new ValidateException("非首年申报必须填写个税缴交情况!");
- }
- }
- $checkState = $data["checkState"];
- $data["photo"] = $info["photo"];
- if ($request->file()) {
- $headimg = $request->file("file");
- $upload = new \app\common\api\UploadApi();
- $result = $upload->uploadOne($headimg, "image", "talent/photo");
- if ($result->code != 200) {
- throw new ValidateException($result->msg);
- }
- $file = imagecreatefromstring(file_get_contents("storage/" . $result->filepath));
- $width = imagesx($file);
- $height = imagesy($file);
- //免冠二寸照长宽413:579
- if ($width * 579 != $height * 413) {
- @unlink("storage/" . $result->filepath); //像素不符合,删除上传文件
- throw new ValidateException("近期免冠半身彩照(二寸)不符合二寸像素标准。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
- }
- if ($info && $info["photo"]) {
- //如果新照片符合像素要求,则删除旧照片
- $old_head_url = "storage/" . $info["photo"];
- if (file_exists($old_head_url))
- @unlink($old_head_url);
- }
- $data["photo"] = $result->filepath;
- }
- if (!$data["photo"])
- throw new ValidateException("请上传头像。*<span style='color:#ff0000;'>二寸像素标准[413*579]</span>");
- if ($info["checkState"] == LaState::LA_FIRST_REJECT) {
- //驳回,需要判断什么字段可以提交
- $modify_fields = array_filter(explode(",", $info["fields"]));
- $tmp_data = $data;
- $data = [];
- foreach ($modify_fields as $field) {
- $data[$field] = $tmp_data[$field];
- }
- $data["id"] = $id;
- }
- if ($id) {
- $res = LaModel::update($data);
- } else {
- $res = LaModel::insertGetId($data);
- }
- if ($res) {
- return json(["code" => 200, "msg" => "保存成功", "obj" => ["id" => $data["id"], "checkState" => $checkState]]);
- }
- throw new ValidateException("保存失败");
- } catch (ValidateException $e) {
- $responseObj = new \stdClass();
- $responseObj->code = 500;
- $responseObj->msg = $e->getMessage();
- return json($responseObj);
- } catch (\think\Exception $e) {
- $res = ["code" => 500, "msg" => "发生预料外错误,请联系管理员处理,错误代码:" . $e->getCode()];
- $logInfo = [
- "enterprise_id" => $this->user["uid"],
- "data" => $data,
- "controller" => $this->request->controller(),
- "action" => $this->request->action(),
- "errCode" => $e->getCode(),
- "errMsg" => $e->getMessage()
- ];
- Log::write($logInfo, "error");
- return json($res);
- }
- }
- public function delete() {
- $id = $this->request->param("id");
- $info = CommonLaApi::getInfoById($id);
- if (!$info || $info["enterpriseId"] != $this->user["uid"]) {
- return json(["msg" => "操作失败"]);
- }
- $checkState = $info["checkState"];
- if ($checkState != LaState::LA_SAVE) {
- return json(["msg" => "该申报已提交审核,无法删除"]);
- }
- TalentModel::delete($id);
- $where = [["mainId", "=", $id], ["type", "=", ProjectState::LIVINGALLOWANCE]];
- $list = Db::table("new_talent_file")->where($where)->select()->toArray();
- foreach ($list as $key => $file) {
- if (!empty($file["url"])) {
- $filepath = "storage/" . $file["url"];
- if (file_exists($filepath)) {
- @unlink($filepath);
- }
- }
- Db::table("new_talent_file")->delete($file["id"]);
- }
- return json(["msg" => "删除成功"]);
- }
- public function getTalentInfo($id, $year, $declareType) {
- $ti = \app\common\api\VerifyApi::getTalentInfoById($id);
- if ($ti["enterpriseType"] == CommonConst::ENTERPRISE_NORMAL) {
- $response = $this->getTalentArrange($ti, $year);
- if ($response->code == 500) {
- return $response;
- }
- }
- if (en . getType() == 1) {
- /* List<String> totalMonth = DateUtil.getMonthBetweenDates(year + "-01-01", year + "-12-31");
- TalentInfo resInfo = (TalentInfo) responseObj.getObj();
- ti.setTalentArrange(resInfo.getTalentArrange());
- ti.setIdentifyCondition(resInfo.getIdentifyCondition());
- ti.setIdentifyConditionName(resInfo.getIdentifyConditionName());
- ti.setIdentifyGetTime(resInfo.getIdentifyGetTime());
- ti.setCertificateStartTime(resInfo.getCertificateStartTime());
- ti.setQzgccrcActiveTime(resInfo.getQzgccrcActiveTime());
- /**校验上一年度人才标签 */
- /* responseObj = getTalentType(ti, declareType);
- if (responseObj.getCode() == 500) {
- return responseObj;
- }
- TalentQuit resQuit = (TalentQuit) responseObj.getObj();
- ti.setTalentType(resQuit.getTalentType()); */
- }
- //查询房产库中是否存在房产信息
- /* Housepurchase housepurchase = new Housepurchase();
- housepurchase.setIdCard(ti.getIdCard());
- HousepurchaseHouseInfo houseInfo = HousepurchaseUtil.getHouseInfo(housepurchase.getIdCard());
- Map<String, Object> res = new HashMap<>();
- res.put("talentInfo", ti);
- res.put("houseInfo", houseInfo);
- return new ResponseObj(ResponseObj.SUCCESS, "", res); */
- }
- /**
- * @param talentInfo
- * @param year
- * @description 获取上一年度的人才层次,规则如下:上一年度存在多个人才层次则取占比大的人才层次,占比相同则取人才层次高者
- * @returns com.stylefeng.guns.core.common.model.ResponseObj
- * @author Liu
- * @date 2020/5/6
- * */
- private function getTalentArrange($talentInfo, $year) {
- /**
- * 判定在申报年度内或之前是否认定,申报年度之后认定无效,根据公布入选月份判断(此处还要考虑人才层次变更)
- */
- $year = substr($year, 0, 4);
- $identifyTimeField = "identifyMonth";
- $oldStartTimeField = "oldIdentifyMonth";
- $newStartTimeField = "newIdentifyMonth";
- if ($talentInfo["enterpriseType"] == CommonConst::ENTERPRISE_JC) {
- $identifyTimeField = "identifyGetTime";
- $oldStartTimeField = "oldIdentifyGetTime";
- $newStartTimeField = "newIdentifyGetTime";
- }
- $where = [];
- $where[] = ["idCard", "=", $talentInfo["card_number"]];
- $where[] = ["checkState", "=", MainState::PASS];
- $where[] = ["isPublic", "=", 6];
- $where[] = [$oldStartTimeField, "<=", $year . "-12-31"];
- $typeChanges = TalentTypeChange::where($where)->field("oldTalentArrange,oldIdentifyCondition,oldIdentifyGetTime,oldIdentifyOutTime,oldIdentifyConditionName,oldIdentifyMonth,oldCertificateStartTime,oldCertificateOutTime,newIdentifyMonth,newIdentifyGetTime")->order("createTime desc")->select()->toArray();
- $jjList = [];
- $unionList = [];
- $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
- if (!$typeChanges && strtotime($year . "-12-31") > strtotime($talentInfo[$identifyTimeField])) {
- return new Response(Response::ERROR, "在上一年度未认定优秀人才,无法申报");
- } else {
- $typeChanges[] = [
- "oldTalentArrange" => $talentInfo["talent_arrange"],
- "oldIdentifyCondition" => $talentInfo["talent_condition"],
- "oldIdentifyGetTime" => $talentInfo["identifyGetTime"],
- "oldIdentifyOutTime" => $talentInfo["identifyExpireTime"],
- "oldIdentifyConditionName" => $talentInfo["identifyConditionName"],
- "oldIdentifyMonth" => $talentInfo["identifyMonth"],
- "oldCertificateStartTime" => $talentInfo["certificateGetTime"],
- "oldCertificateOutTime" => $talentInfo["certificateExpireTime"] ?: date("Y-m-d", strtotime(sprintf("%s +6 years -1 days", $talentInfo["certificateGetTime"]))),
- "newIdentifyMonth" => ($year + 1) . "-01-01",
- "newIdentifyGetTime" => ($year + 1) . "-01-01"
- ];
- foreach ($typeChanges as $typeChange) {
- $monthList = \DateUtil::getMonthBetweenDatesNotEnd($typeChange["oldCertificateStartTime"], $typeChange["oldCertificateOutTime"]);
- $res = \DateUtil::getEveryMonthDayBetween($typeChange["oldCertificateStartTime"], $typeChange["oldCertificateOutTime"], $monthList);
- }
- for (TalentTypeChange typeChange : typeChanges) {
- List<String> monthList = DateUtil . getMonthBetweenDatesNotEnd(typeChange . getOldCertificateStartTime(), typeChange . getOldCertificateOutTime());
- Map<String, Integer> res = DateUtil . getEveryMonthDayBetween(typeChange . getOldCertificateStartTime(), typeChange . getOldCertificateOutTime(), monthList);
- if (res . size() > 0) {
- unionList . removeAll(monthList);
- unionList . addAll(monthList);
- TalentInfo info = new TalentInfo(typeChange . getOldTalentArrange(), typeChange . getOldIdentifyCondition(), typeChange . getOldIdentifyGetTime(), typeChange . getOldIdentifyConditionName(), typeChange . getOldCertificateStartTime(), typeChange . getOldCertificateOutTime(), typeChange . getOldIdentifyMonth());
- info . setDayMap(res);
- jjList . add(info);
- }
- }
- }
- }
- }
|