123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827 |
- <?php
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- namespace app\enterprise\controller;
- use app\enterprise\common\EnterpriseController;
- use app\common\state\CommonConst;
- use app\common\api\BatchApi;
- use app\common\api\TalentAllowanceApi;
- use app\common\state\ProjectState;
- use app\common\api\DictApi;
- use app\common\state\MainState;
- use app\common\model\TalentAllowance as TaModel;
- use app\common\state\AllowanceProjectEnum;
- use app\common\model\TalentChecklog;
- use think\facade\Db;
- use app\common\api\Response;
- use app\common\api\UploadApi;
- use app\enterprise\model\TalentTypeChange;
- /**
- * Description of TalentAllowance
- *
- * @author sgq
- */
- class TalentAllowance extends EnterpriseController {
- public function index() {
- $tpl = "";
- switch ($this->user["type"]) {
- case CommonConst::ENTERPRISE_JC:
- $tpl = "indexIC";
- break;
- }
- return view($tpl, ['type' => $this->user["type"]]);
- }
- public function list() {
- $res = TalentAllowanceApi::getList($this->request);
- return json($res);
- }
- /**
- * 申请
- */
- public function apply(\think\Request $request) {
- $param = $request->param();
- $id = isset($param["id"]) ? $param["id"] : 0;
- $info = null;
- if ($id) {
- $info = TalentAllowanceApi::getInfoById($id);
- $this->translateToChinese($info);
- }
- if ($request->isPost()) {
- return $this->save($info, $request);
- }
- $batch = $info["year"] ?: BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
- return view("", ["year" => $batch, "type" => $this->user["type"], "row" => $info]);
- }
- public function batchApply() {
- $ids = $this->request["ids"];
- $ids = array_filter(explode(",", $ids));
- $allowanceType = $this->request["allowanceType"];
- $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"])["batch"];
- if (!$batch) {
- return new Response(Response::ERROR, "当前并无有效的申报批次进行中");
- }
- for ($i = 0; $i < count($ids); $i++) {
- queue("app\job\TalentAllowance", ["type" => 1, "talentId" => $ids[$i], "enterprise" => $this->user, "year" => $batch, "allowanceType" => $allowanceType]);
- }
- return new Response(Response::SUCCESS, "已经成功添加到计划任务,请稍候查看申报列表进行确认");
- }
- private function save($talentAllowance, \think\Request $request) {
- $response = new \stdClass();
- $response->code = 500;
- $param = $request->param();
- if (!$param) {
- $response->msg = "请填写信息后在提交";
- return $response;
- }
- if (\StrUtil::isEmpOrNull($param["talentId"])) {
- $response->msg = "请选择申报对象";
- return $response;
- }
- if (!$param["id"]) {
- $where = [];
- $where[] = ["year", "=", $param["year"]];
- $where[] = ["idCard", "=", $param["idCard"]];
- $where[] = ["checkState", "not in", [MainState::NOTPASS, MainState::PASS]];
- $exists = TaModel::where($where)->find();
- if ($exists) {
- $response->msg = "当前申请对象在当前批次中存在申请中的记录,请等待申请结束后再操作";
- return $response;
- }
- $user = $this->user;
- $ti = \app\common\api\VerifyApi::getTalentInfoById($param["talentId"]);
- $data = [
- "talentId" => $param["talentId"],
- "enterpriseId" => $ti["enterprise_id"],
- "enterpriseName" => $user["name"],
- "year" => $param["year"],
- "source" => $ti["source"],
- "qzgccrcActiveTime" => $ti["certificateExpireTime"],
- "talentType" => $ti["enterpriseTag"],
- "address" => $ti["street"],
- "name" => $ti["name"],
- "sex" => $ti["sex"],
- "cardType" => $ti["card_type"],
- "idCard" => $ti["card_number"],
- "firstInJJTime" => $ti["fst_work_time"],
- "entryTime" => $ti["cur_entry_time"],
- "post" => $ti["position"],
- "phone" => $ti["phone"],
- "talentArrange" => $ti["talent_arrange"],
- "identifyCondition" => $ti["talent_condition"],
- "identifyGetTime" => $ti["identifyGetTime"],
- "identifyOutTime" => $ti["identifyExpireTime"],
- "identifyConditionName" => $ti["identifyConditionName"],
- "identifyMonth" => $ti["identifyMonth"],
- "bank" => $ti["bank"],
- "bankNetwork" => $ti["bank_branch_name"],
- "bankAccount" => $ti["bank_account"],
- "bankNumber" => $ti["bank_number"],
- "checkState" => 1,
- "type" => $user["type"],
- "provinceCode" => $ti["province"],
- "provinceName" => \app\common\api\LocationApi::getNameByCode($ti["province"]),
- "cityCode" => $ti["city"],
- "cityName" => \app\common\api\LocationApi::getNameByCode($ti["city"]),
- "countyCode" => $ti["county"],
- "countyName" => \app\common\api\LocationApi::getNameByCode($ti["county"]),
- "isSupple" => 2,
- "createTime" => date("Y-m-d H:i:s"),
- "createUser" => $user["uid"],
- "id" => getStringId(),
- "wage" => $param["wage"],
- "allowanceType" => $param["allowanceType"]
- ];
- /* * 1.获取上一年度的人才层次 */
- $arrangeList = $this->getLastYearTalentType($data, $ti);
- if (!$arrangeList) {
- $response->msg = "上一年度暂无有效的人才层次";
- return $response;
- }
- /* * 2.获取上一年度所在单位* */
- $contractDetailList = $this->getConcatList($ti, $data, $param["year"]); //保存上一年度的工作单位
- if (!$contractDetailList) {
- $response->msg = "申报失败,原因为:申报年度不存在有效的工作单位";
- return $response;
- }
- TaModel::insert($data);
- \app\common\model\TalentAllowancecontractDetail::insertAll($contractDetailList);
- /**
- * 4.添加津补贴核查项目
- */
- //核查项目详情表
- $this->createAllowanceProject($data, $contractDetailList);
- \app\common\model\TalentAllowanceArrange::insertAll($arrangeList);
- //添加日志
- TalentChecklog::create([
- 'id' => getStringId(),
- 'mainId' => $data['id'],
- 'type' => intval(ProjectState::JBT),
- 'typeFileId' => null,
- 'active' => 1,
- 'state' => 1,
- 'step' => 0,
- 'stateChange' => "保存未提交",
- 'description' => "添加津补贴申报",
- 'createTime' => date("Y-m-d H:i:s", time()),
- 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
- ]);
- $response->msg = "保存成功";
- $response->code = 200;
- $response->obj = $data;
- return $response;
- } else {
- TaModel::update($param);
- $response->msg = "修改成功";
- $response->code = 200;
- return $response;
- }
- }
- public function getInfoByIdAndYear($id, $year) {
- $ti = \app\common\api\VerifyApi::getTalentInfoById($id);
- $data = [
- "talentId" => $id,
- "year" => $year,
- "idCard" => $ti["card_number"],
- "id" => getStringId()
- ];
- /* * 1.获取上一年度的人才层次 */
- $arrangeList = $this->getLastYearTalentType($data, $ti);
- if (!$arrangeList) {
- return new Response(Response::ERROR, "该人员上一年度暂无有效的人才层次");
- }
- /* * 2.获取上一年度所在单位* */
- $contractDetailList = $this->getConcatList($ti, $data, $year); //保存上一年度的工作单位
- if (!$contractDetailList) {
- return new Response(Response::ERROR, "该人员申报年度不存在有效的工作单位");
- }
- return new Response(Response::SUCCESS, "", $ti);
- }
- /**
- * 删除优秀人才津补贴
- */
- public function delete() {
- $id = $this->request["id"];
- $response = new \stdClass();
- $response->code = 500;
- $info = TalentAllowanceApi::getInfoById($id);
- if ($info["checkState"] != 1) {
- $response->msg = "删除失败!此数据已提交审核,无法删除!";
- return $response;
- }
- Db::startTrans();
- try {
- //删除核查项目表
- Db::table("un_talent_allowance_project")->where("mainId", $id)->delete();
- //删除合同情况表
- Db::table("un_talent_allowancecontract_detail")->where("mainId", $id)->delete();
- //删除人才层次变更表
- Db::table("un_talent_allowance_arrange")->where("mainId", $id)->delete();
- //删除日志
- $where[] = ["mainId", "=", $id];
- $where[] = ["type", "=", ProjectState::JBT];
- Db::table("new_talent_checklog")->where($where)->delete();
- //删除主表
- Db::table("un_talent_allowance_info")->delete($id);
- Db::commit();
- $response->code = 200;
- $response->msg = "删除成功";
- return $response;
- } catch (think\db\exception\DbException $e) {
- Db::rollback();
- $response->msg = $e->getMessage();
- return $response;
- }
- }
- public function detail(\think\Request $request) {
- $param = $request->param();
- $id = $param["id"];
- $info = TalentAllowanceApi::getInfoById($id);
- $this->translateToChinese($info);
- return view("", ["row" => $info]);
- }
- private function translateToChinese(&$obj) {
- if (\StrUtil::isNotEmpAndNull($obj["address"])) {
- $obj["addressName"] = DictApi::findByParentCodeAndCode("street", $obj["address"])["name"];
- }
- if (\StrUtil::isNotEmpAndNull($obj["talentType"])) {
- $obj["talentTypeName"] = DictApi::findByParentCodeAndCode("enterprise_tag", $obj["talentType"])["name"];
- }
- if (\StrUtil::isNotEmpAndNull($obj["talentArrange"])) {
- $obj["talentArrangeName"] = DictApi::findByParentCodeAndCode("talent_arrange", $obj["talentArrange"])["name"];
- }
- if (\StrUtil::isNotEmpAndNull($obj["identifyCondition"])) {
- $obj["identifyConditionText"] = \app\common\api\TalentConditionApi::getOne($obj["identifyCondition"])["name"];
- }
- if (\StrUtil::isNotEmpAndNull($obj["introductionMode"])) {
- $obj["introductionModeName"] = DictApi::findByParentCodeAndCode("import_way", $obj["introductionMode"])["name"];
- }
- }
- /* * 获取上一年度的人才层次变更信息 */
- private function getLastYearTalentType($info, $talentInfo) {
- $arrangeList = [];
- /* * * 添加人才层次记录 */
- $where = [];
- $where[] = ["idCard", "=", $info["idCard"]];
- $where[] = ["checkState", "=", MainState::PASS];
- $where[] = ["isPublic", ">=", 5];
- $where[] = ["oldIdentifyMonth", "<=", $info["year"] . "-12-31"];
- $typeList = TalentTypeChange::where($where)->field("oldTalentArrange,oldIdentifyCondition,oldIdentifyGetTime,oldIdentifyOutTime,oldIdentifyMonth,oldCertificateStartTime,oldCertificateOutTime,newIdentifyMonth")->order("createTime desc")->select()->toArray();
- $typeList[] = [
- "oldTalentArrange" => $talentInfo["talent_arrange"],
- "oldIdentifyCondition" => $talentInfo["talent_condition"],
- "oldIdentifyGetTime" => $talentInfo["identifyGetTime"],
- "oldIdentifyOutTime" => $talentInfo["identifyExpireTime"],
- "oldIdentifyMonth" => $talentInfo["identifyMonth"],
- "oldCertificateStartTime" => $talentInfo["certificateGetTime"],
- "oldCertificateOutTime" => $talentInfo["certificateExpireTime"],
- "newIdentifyMonth" => $info["year"] . "-12-31"
- ];
- $totalMonth = \DateUtil::getMonthBetweenDates($info["year"] . "-01-01", $info["year"] . "-12-31");
- /* * 获取上一年度有效的人才层次 */
- usort($typeList, function($a, $b) {
- return (int) $b["oldTalentArrange"] - (int) $a["oldTalentArrange"];
- });
- $commonMonth = [];
- foreach ($typeList as $talentTypeChange) {
- $startTime = $talentTypeChange["oldIdentifyMonth"];
- $endTime = $talentTypeChange["newIdentifyMonth"];
- $monthList = \DateUtil::getMonthBetweenDatesNotBegin($startTime, $endTime);
- if ($monthList) {
- $monthList = array_intersect($monthList, $totalMonth);
- }
- if ($monthList) {
- $months = implode(",", $monthList);
- $monthList = array_filter($monthList, function($value) use ($commonMonth) {
- return !in_array($value, $commonMonth);
- });
- $commonMonth = array_filter(array_merge($commonMonth, $monthList));
- if (count($monthList) > 0) {
- $arrange = [
- "id" => getStringId(),
- "mainId" => $info["id"],
- "talentArrange" => $talentTypeChange["oldTalentArrange"],
- "identifyCondition" => $talentTypeChange["oldIdentifyCondition"],
- "startTime" => $startTime,
- "endTime" => $endTime,
- "prepareMonths" => null,
- "description" => "申报年度有效月份:" . $months,
- "identifyConditionName" => $talentTypeChange["oldIdentifyConditionName"],
- "identifyConditionGetTime" => $talentTypeChange["oldIdentifyGetTime"],
- ];
- $sb = '';
- foreach ($monthList as $month) {
- $sb .= substr($month, 5, 2) . ",";
- }
- $arrange["prepareMonths"] = rtrim($sb, ",");
- $arrangeList[] = $arrange;
- }
- }
- }
- return $arrangeList;
- }
- /**
- * @param
- * @returns void
- * @author Liu
- * @date 2020/4/26
- * @description 获取上一年度所在单位
- * */
- private function getConcatList($talentInfo, $info, $year) {
- $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
- /** 添加申报人才上一年度工作单位记录 */
- $where = [];
- $where[] = ["idCard", "=", $talentInfo["card_number"]];
- $where[] = ["checkState", "=", 3];
- $quitList = \app\common\model\TalentQuit::where($where)->field("enterpriseId,enterpriseName,talentType,identifyGetTime,starttime,endtime,entryTime,quitTime,post")->select()->toArray();
- /* * * 将最新的人才数据转为工作变更记录(为了统一处理) */
- if ($talentInfo["active"] == 1) {
- $labor_contract_rangetime = explode(" - ", $talentInfo["labor_contract_rangetime"]);
- $starttime = $labor_contract_rangetime[0];
- $endtime = $labor_contract_rangetime[1];
- $quitList[] = [
- "enterpriseId" => $talentInfo["enterprise_id"],
- "enterpriseName" => $talentInfo["enterpriseName"],
- "talentType" => $talentInfo["enterpriseTag"],
- "identifyGetTime" => $talentInfo["identifyGetTime"],
- "starttime" => $starttime,
- "endtime" => $endtime,
- "entryTime" => $talentInfo["cur_entry_time"],
- "quitTime" => null,
- "post" => $talentInfo["position"]
- ];
- }
- $list = [];
- foreach ($quitList as $quit) {
- $monthList = \DateUtil::getMonthBetweenDates($quit["entryTime"], \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"]);
- $monthList = array_intersect($monthList, $totalMonth);
- if ($monthList) {
- $sb = '';
- foreach ($monthList as $month) {
- $sb .= substr($month, 5, 2) . ",";
- }
- $list[] = [
- "id" => getStringId(),
- "mainId" => $info["id"],
- "enterpriseId" => $quit["enterpriseId"],
- "talentType" => $quit["talentType"],
- "startTime" => $quit["starttime"],
- "endTime" => $quit["endtime"],
- "entryTime" => $quit["entryTime"],
- "quitTime" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"],
- "letterTime" => $quit["letterTime"],
- "gygb" => $quit["gygb"],
- "identifyGetTime" => $quit["identifyGetTime"],
- "isQuit" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? 2 : 1,
- "post" => $quit["post"],
- "months" => rtrim($sb, ",")
- ];
- }
- }
- return $list;
- }
- private function createAllowanceProject($info, $contractList) {
- foreach ($contractList as $detail) {
- $projects = [
- //AllowanceProjectEnum::PROJECT_CONTRACT,
- AllowanceProjectEnum::PROJECT_TAX,
- AllowanceProjectEnum::PROJECT_WAGES,
- AllowanceProjectEnum::PROJECT_ATTENDANCE,
- AllowanceProjectEnum::PROJECT_SB_PENSION,
- AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
- AllowanceProjectEnum::PROJECT_SB_MEDICA,
- //AllowanceProjectEnum::PROJECT_WORKDAY,
- ];
- $list = [];
- foreach ($projects as $project) {
- $list[] = [
- "mainId" => $info["id"],
- "baseId" => $detail["id"],
- "enterpriseId" => $detail["enterpriseId"],
- "project" => $project,
- "isLock" => 1,
- "createTime" => date("Y-m-d H:i:s")
- ];
- }
- \app\common\model\TalentAllowanceProject::insertAll($list);
- }
- }
- /**
- * 查询工作单位
- */
- public function findAllowanceContractDetail() {
- $mainId = $this->request["mainId"];
- $offset = $this->request["offset"] ?: 0;
- $limit = $this->request["limit"] ?: 1000;
- $count = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->count();
- $list = \app\common\model\TalentAllowancecontractDetail::where("mainId", $mainId)->limit($offset, $limit)->select()->toArray();
- $enterpriseMap = \app\common\model\Enterprise::column("name", "id");
- foreach ($list as &$row) {
- $row["enterpriseName"] = $enterpriseMap[$row["enterpriseId"]];
- }unset($row);
- return json(["rows" => $list, "total" => $count]);
- }
- /**
- * 查询核查项目情况
- */
- public function findAllowanceProject() {
- $mainId = $this->request["mainId"];
- $baseId = $this->request["baseId"];
- $offset = $this->request["offset"] ?: 0;
- $limit = $this->request["limit"] ?: 1000;
- $where = [];
- $where[] = ["mainId", "=", $mainId];
- $where[] = ["baseId", "=", $baseId];
- $count = \app\common\model\TalentAllowanceProject::where($where)->count();
- $list = \app\common\model\TalentAllowanceProject::where($where)->limit($offset, $limit)->select()->toArray();
- $info = TalentAllowanceApi::getInfoById($mainId);
- foreach ($list as &$project) {
- $project["projectName"] = AllowanceProjectEnum::getProjectName($project["project"]);
- if ($info["checkState"] == 1) {
- $project["isEdit"] = in_array($project["project"], [
- //AllowanceProjectEnum::PROJECT_CONTRACT,
- AllowanceProjectEnum::PROJECT_TAX,
- AllowanceProjectEnum::PROJECT_WAGES,
- AllowanceProjectEnum::PROJECT_ATTENDANCE,
- AllowanceProjectEnum::PROJECT_SB_PENSION,
- AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT,
- AllowanceProjectEnum::PROJECT_SB_MEDICA,
- //AllowanceProjectEnum::PROJECT_WORKDAY
- ]) ? 1 : 2;
- } else if ($info["checkState"] == 10) {
- $projects = explode(",", $info["projects"]);
- if (in_array($project["id"], $projects)) {
- $project["isEdit"] = 1;
- } else {
- $project["isEdit"] = 2;
- }
- } else {
- $project["isEdit"] = 2;
- }
- }unset($project);
- return json(["rows" => $list, "total" => $count]);
- }
- /**
- * 查询人才层次变更记录
- */
- public function findAllowanceArrange() {
- $mainId = $this->request["mainId"];
- $offset = $this->request["offset"] ?: 0;
- $limit = $this->request["limit"] ?: 1000;
- $where = [];
- $where[] = ["mainId", "=", $mainId];
- $count = \app\common\model\TalentAllowanceArrange::where($where)->count();
- $list = \app\common\model\TalentAllowanceArrange::where($where)->limit($offset, $limit)->select()->toArray();
- foreach ($list as &$arrange) {
- $condition = \app\common\api\TalentConditionApi::getOne($arrange["identifyCondition"]);
- $arrange["identifyConditionText"] = $condition["name"];
- $arrange["talentArrangeName"] = app\common\state\CommonConst::getLayerNameByLayer($arrange["talentArrange"]);
- }unset($arrange);
- return json(["rows" => $list, "total" => $count]);
- }
- /**
- * 修改合同起止时间
- */
- public function editContract() {
- $response = new \stdClass();
- $response->code = 500;
- $param = $this->request->param();
- if (!$param["id"]) {
- $response->msg = "系统错误,请联系管理员";
- return $response;
- }
- $detail = \app\common\model\TalentAllowancecontractDetail::find($param["id"]);
- $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
- if (\StrUtil::isEmpOrNull($param["startTime"])) {
- $response->msg = "请选择合同起始时间";
- return $response;
- }
- if (\StrUtil::isEmpOrNull($param["endTime"])) {
- $response->msg = "请选择合同截止时间";
- return $response;
- }
- \app\common\model\TalentAllowancecontractDetail::update($param);
- //添加日志
- TalentChecklog::create([
- 'id' => getStringId(),
- 'mainId' => $info['id'],
- 'type' => intval(ProjectState::JBT),
- 'typeFileId' => $param["id"],
- 'active' => 1,
- 'state' => null,
- 'step' => 0,
- 'stateChange' => null,
- 'description' => "修改工作单位合同时间为:" . $param["startTime"] . "至" . $param["endTime"],
- 'createTime' => date("Y-m-d H:i:s", time()),
- 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
- ]);
- $response->msg = "修改成功";
- $response->code = 200;
- return $response;
- }
- /**
- * 修改项目
- */
- public function editProject() {
- $response = new \stdClass();
- $response->code = 500;
- $param = $this->request->param();
- if (!$param["id"]) {
- $response->msg = "系统错误,请联系管理员";
- return $response;
- }
- $detail = \app\common\model\TalentAllowanceProject::find($param["id"]);
- $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
- \app\common\model\TalentAllowanceProject::update($param);
- //添加日志
- TalentChecklog::create([
- 'id' => getStringId(),
- 'mainId' => $info['id'],
- 'type' => intval(ProjectState::JBT),
- 'typeFileId' => $param["id"],
- 'active' => 1,
- 'state' => null,
- 'step' => 0,
- 'stateChange' => null,
- 'description' => "修改项目名:" . AllowanceProjectEnum::getProjectName($detail["project"]) . "的值为:" . $param["months"] . ";备注为:" . $param["description"],
- 'createTime' => date("Y-m-d H:i:s", time()),
- 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
- ]);
- $response->msg = "修改成功";
- $response->code = 200;
- return $response;
- }
- /**
- * 判断是否可以修改
- */
- public function validateIsEdit() {
- $id = $this->request["id"];
- $type = $this->request["type"];
- $info = null;
- if ($type == 1) { //编辑合同
- $detail = \app\common\model\TalentAllowancecontractDetail::find($id);
- } else if ($type == 2) { //编辑项目
- $detail = \app\common\model\TalentAllowanceProject::find($id);
- }
- $info = TalentAllowanceApi::getInfoById($detail["mainId"]);
- if ($info["checkState"] != 1 && $info["checkState"] != 10) {
- if ($info["checkState"] == -1) {
- return new Response(Response::ERROR, "您的申报审核不通过,无法操作");
- } else if ($info["checkState"] == 30) {
- return new Response(Response::ERROR, "您的申报已审核通过,无法操作");
- } else {
- return new Response(Response::ERROR, "您的申报正在审核中,请耐心等待");
- }
- }
- return new Response(Response::SUCCESS, "");
- }
- /**
- * 提交审核
- */
- public function submitToCheck() {
- $data = $this->request->param();
- $response = new \stdClass();
- $response->code = 500;
- if (!$data || !$data["id"]) {
- $response->msg = "提交审核失败,请先填写基础信息";
- return $response;
- }
- $old = TalentAllowanceApi::getInfoById($data["id"]);
- $batch = BatchApi::checkBatchValid(["type" => ProjectState::JBT, "year" => $old["year"], "first_submit_time" => $old["firstSubmitTime"]], $this->user["type"]);
- if ($batch["code"] != 200) {
- $response->msg = $batch["msg"];
- return $response;
- }
- if ($old["checkState"] != 1 && $old["checkState"] != 10) {
- $response->msg = "不能重复提交审核";
- return $response;
- }
- $where = [];
- $where[] = ["type", "=", $old["type"]];
- $where[] = ["project", "=", ProjectState::JBT];
- $where[] = ["isConditionFile", "in", [0, $old["allowanceType"]]];
- $where[] = ["active", "=", 1];
- $where[] = ["delete", "=", 0];
- $filetypes = Db::table("new_common_filetype")->where($where)->order("sn asc")->select()->toArray();
- $sb = [];
- $sb[] = "以下为必传附件:";
- foreach ($filetypes as $filetype) {
- if ($filetype["must"] == 1) {
- $where = [];
- $where[] = ["mainId", "=", $data["id"]];
- $where[] = ["typeId", "=", $filetype["id"]];
- $count = Db::table("new_talent_file")->where($where)->count();
- if ($count == 0) {
- $sb[] = $filetype["name"] . ";";
- }
- }
- }
- if (count($sb) > 1) {
- $response->msg = implode("<br>", $sb);
- return $response;
- }
- /**
- * 初步判断合同是否满两年
- */
- $detailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $old["id"])->select()->toArray();
- foreach ($detailList as $detail) {
- if (\StrUtil::isEmpOrNull($detail["startTime"]) || \StrUtil::isEmpOrNull($detail["endTime"])) {
- $response->msg = "合同起止时间不能为空";
- return $response;
- }
- }
- foreach ($detailList as $detail) {
- $contractEndTime = strtotime($detail["endTime"]);
- $contractStartTimeAdd2Years = strtotime("+2 years -1 day {$detail['startTime']}");
- $where = [];
- $where[] = ["mainId", "=", $data["id"]];
- $where[] = ["baseId", "=", $detail["id"]];
- $where[] = ["project", "=", AllowanceProjectEnum::PROJECT_CONTRACT];
- $updProject["months"] = $contractEndTime >= $contractStartTimeAdd2Years ? "是" : "否";
- \app\common\model\TalentAllowanceProject::where($where)->update($updProject);
- }
- $data["checkMsg"] = "";
- $data["checkState"] = 5;
- $data["files"] = "";
- $data["projects"] = "";
- $data["concats"] = "";
- $data["fields"] = "";
- $data["toDep"] = "";
- $data["process"] = null;
- if (!$old["firstSubmitTime"]) {
- $data["firstSubmitTime"] = date("Y-m-d H:i:s");
- }
- $data["newSubmitTime"] = date("Y-m-d H:i:s");
- TaModel::update($data);
- //添加日志
- TalentChecklog::create([
- 'id' => getStringId(),
- 'mainId' => $data['id'],
- 'type' => intval(ProjectState::JBT),
- 'typeFileId' => null,
- 'active' => 1,
- 'state' => 1,
- 'step' => 0,
- 'stateChange' => sprintf("%s->%s", MainState::getStateDesc(1), MainState::getStateDesc(7)),
- 'description' => "确认提交审核",
- 'createTime' => date("Y-m-d H:i:s", time()),
- 'createUser' => sprintf("%s(%s)", $this->user["account"], $this->user["companyName"])
- ]);
- $response->msg = "提交审核成功";
- $response->code = 200;
- $response->obj = 5;
- return $response;
- }
- public function updateSuppleState() {
- $id = $this->request["id"];
- $response = new \stdClass();
- $response->code = 500;
- if (\StrUtil::isEmpOrNull($id)) {
- $response->msg = "系统错误,请联系管理员";
- return $response;
- }
- $data["id"] = $id;
- $data["isSupple"] = 1;
- TaModel::update($data);
- $response->msg = "状态更新成功";
- $response->code = 200;
- return $response;
- }
- public function uploadCommonFile() {
- $batchId = $this->request["batch"];
- if (!$batchId) {
- return json(new Response(Response::ERROR, "没有提交批次信息,无法按批次归档,上传被中止"));
- }
- $batchInfo = BatchApi::getOne($batchId);
- if (!$batchInfo) {
- return json(new Response(Response::ERROR, "批次信息不存在,无法按批次归档,上传被中止"));
- }
- if (!$this->request->file()) {
- return json(new Response(Response::ERROR, "没有上传任何材料"));
- }
- $file = $this->request->file("file");
- $upload = new UploadApi();
- $result = $upload->uploadOne($file, "system", "talent/TalentAllowanceCommonFile");
- if ($result->code != 200) {
- return json(new Response(Response::ERROR, $result->msg));
- }
- $data["id"] = getStringId();
- $data["enterpriseId"] = $this->user["uid"];
- $data["batchId"] = $batchId;
- $data["batch"] = $batchInfo["batch"];
- $data["url"] = $result->filepath;
- $data["originalName"] = $file->getOriginalName();
- $data["createTime"] = date("Y-m-d H:i:s");
- $data["createUser"] = $this->user["uid"];
- $res = Db::table("un_talent_allowance_common_file")->insert($data);
- return json(new Response(Response::SUCCESS, "上传成功"));
- }
- public function listCommonFile() {
- $param = $this->request->param();
- $batchId = $param["batch"];
- $where = [["batchId", "=", $batchId], ["enterpriseId", "=", $this->user["uid"]]];
- $list = Db::table("un_talent_allowance_common_file")->where($where)->select()->toArray();
- foreach ($list as $key => $item) {
- $list[$key]["ext"] = pathinfo($item["url"])["extension"];
- $list[$key]["url"] = getStoragePath($item["url"]);
- }
- return json(["rows" => $list]);
- }
- public function deleteCommonFile() {
- $id = $this->request["id"];
- $where = [];
- $where[] = ["id", "=", $id];
- $where[] = ["enterpriseId", "=", $this->user["uid"]];
- $file = Db::table("un_talent_allowance_common_file")->where($where)->find();
- if (!$file) {
- return json(new Response(Response::ERROR, "不存在的文件,删除失败"));
- }
- if (Db::table("un_talent_allowance_common_file")->where($where)->delete()) {
- if (!empty($file["url"])) {
- $filepath = "storage/" . $file["url"];
- if (file_exists($filepath)) {
- unlink($filepath);
- }
- }
- return json(new Response(Response::SUCCESS, "删除成功"));
- }
- }
- public function findTalentAllowance() {
- $res = [];
- $batch = BatchApi::getValidBatch(ProjectState::JBT, $this->user["type"]);
- $year = $batch["batch"];
- if ($year) {
- $ids = null;
- //根据申报年度查询当前企业已申报的人才
- $where = [];
- $where[] = ["year", "=", $year];
- $where[] = ["enterpriseId", "=", $this->user["uid"]];
- $talentAllowances = TaModel::where($where)->select()->toArray();
- $ids = array_unique(array_column($talentAllowances, "talentId"));
- $whr = [];
- $whr[] = ["ti.checkState", "=", \app\common\api\TalentState::CERTIFICATED];
- $whr[] = ["ti.enterprise_id", "=", $this->user["uid"]];
- $whr[] = ["e.type", "=", $this->user["type"]];
- $whr[] = ["ti.id", "not in", $ids];
- $list = \app\enterprise\model\Talent::alias("ti")->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")->field("ti.id,ti.name,ti.card_number as idCard")->where($whr)->select()->toArray();
- foreach ($list as $info) {
- if (strtotime($year . "-12-31") >= strtotime($info["identifyMonth"])) {
- $res[] = $info;
- } else {
- $whereTypeChange = [];
- $whereTypeChange[] = ["idCard", "=", $info["idCard"]];
- $whereTypeChange[] = ["checkState", "=", MainState::PASS];
- $whereTypeChange[] = ["isPublic", "=", 6];
- $typeChanges = TalentTypeChange::where($whereTypeChange)->select()->toArray();
- foreach ($typeChanges as $typeChange) {
- if (strtotime($year . "-12-31") >= strtotime($typeChange["oldIdentifyMonth"])) {
- $res[] = $info;
- break;
- }
- }
- }
- }
- }
- return new Response(Response::SUCCESS, "", ["rows" => $res, "total" => count($res)]);
- }
- }
|