|
@@ -0,0 +1,301 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\job;
|
|
|
+
|
|
|
+use think\queue\Job;
|
|
|
+use think\facade\Log;
|
|
|
+use think\facade\Db;
|
|
|
+use app\common\api\TalentState;
|
|
|
+use app\common\state\ProjectState;
|
|
|
+use app\common\model\TalentChecklog;
|
|
|
+use app\common\model\TalentAllowance as TaModel;
|
|
|
+use app\common\state\MainState;
|
|
|
+use app\common\api\LocationApi;
|
|
|
+use app\enterprise\model\TalentTypeChange;
|
|
|
+use app\common\state\AllowanceProjectEnum;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Description of TalentAllowance
|
|
|
+ *
|
|
|
+ * @author sgq
|
|
|
+ */
|
|
|
+class TalentAllowance {
|
|
|
+
|
|
|
+ public function fire(Job $job, $data) {
|
|
|
+ if ($this->deal($data)) {
|
|
|
+ $job->delete();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if ($job->attempts() >= 3) {
|
|
|
+ $job->delete();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $job->release(10); //10秒后重试
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理业务逻辑
|
|
|
+ * @param type $data
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public function deal($data): bool {
|
|
|
+ switch ($data["type"]) {
|
|
|
+ case 1:
|
|
|
+ //添加保存未提交的津补贴申报
|
|
|
+ try {
|
|
|
+ $talentId = $data["talentId"];
|
|
|
+ $enterprise = $data["enterprise"];
|
|
|
+ $year = $data["year"];
|
|
|
+ $allowanceType = $data["allowanceType"];
|
|
|
+
|
|
|
+ $ti = \app\common\api\VerifyApi::getTalentInfoById($talentId);
|
|
|
+ if ($ti["checkState"] != TalentState::CERTIFICATED || $ti["enterprise_id"] != $enterprise["uid"] || !$year || !$allowanceType) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $where = [];
|
|
|
+ $where[] = ["year", "=", $year];
|
|
|
+ $where[] = ["idCard", "=", $ti["card_number"]];
|
|
|
+ $where[] = ["checkState", "not in", [MainState::NOTPASS, MainState::PASS]];
|
|
|
+ $exists = TaModel::where($where)->find();
|
|
|
+ if ($exists) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ "talentId" => $talentId,
|
|
|
+ "enterpriseId" => $ti["enterprise_id"],
|
|
|
+ "enterpriseName" => $enterprise["name"],
|
|
|
+ "year" => $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" => $enterprise["type"],
|
|
|
+ "provinceCode" => $ti["province"],
|
|
|
+ "provinceName" => LocationApi::getNameByCode($ti["province"]),
|
|
|
+ "cityCode" => $ti["city"],
|
|
|
+ "cityName" => LocationApi::getNameByCode($ti["city"]),
|
|
|
+ "countyCode" => $ti["county"],
|
|
|
+ "countyName" => LocationApi::getNameByCode($ti["county"]),
|
|
|
+ "isSupple" => 2,
|
|
|
+ "createTime" => date("Y-m-d H:i:s"),
|
|
|
+ "createUser" => $enterprise["uid"],
|
|
|
+ "id" => getStringId(),
|
|
|
+ "allowanceType" => $allowanceType
|
|
|
+ ];
|
|
|
+ /* * 1.获取上一年度的人才层次 */
|
|
|
+ $arrangeList = $this->getLastYearTalentType($data, $ti);
|
|
|
+ if (!$arrangeList) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ /* * 2.获取上一年度所在单位* */
|
|
|
+ $contractDetailList = $this->getConcatList($ti, $data, $year); //保存上一年度的工作单位
|
|
|
+ if (!$contractDetailList) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ 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)", $enterprise["account"], $enterprise["companyName"])
|
|
|
+ ]);
|
|
|
+ return true;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::write($e->getMessage(), "error");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* * 获取上一年度的人才层次变更信息 */
|
|
|
+
|
|
|
+ private function getLastYearTalentType($info, $talentInfo) {
|
|
|
+ $arrangeList = [];
|
|
|
+ /* * * 添加人才层次记录 */
|
|
|
+ $where = [];
|
|
|
+ $where[] = ["talentId", "=", $info["talentId"]];
|
|
|
+ $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[] = ["talentId", "=", $talentInfo["id"]];
|
|
|
+ $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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|