TalentAllowance.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <?php
  2. namespace app\job;
  3. use think\queue\Job;
  4. use think\facade\Log;
  5. use think\facade\Db;
  6. use app\common\api\TalentState;
  7. use app\common\state\ProjectState;
  8. use app\common\model\TalentChecklog;
  9. use app\common\model\TalentAllowance as TaModel;
  10. use app\common\state\MainState;
  11. use app\common\api\LocationApi;
  12. use app\enterprise\model\TalentTypeChange;
  13. use app\common\state\AllowanceProjectEnum;
  14. use app\common\state\AllowanceTypeEnum;
  15. /**
  16. * Description of TalentAllowance
  17. *
  18. * @author sgq
  19. */
  20. class TalentAllowance {
  21. public function fire(Job $job, $data) {
  22. if ($this->deal($data)) {
  23. $job->delete();
  24. return true;
  25. }
  26. if ($job->attempts() >= 3) {
  27. $job->delete();
  28. return false;
  29. }
  30. $job->release(10); //10秒后重试
  31. }
  32. /**
  33. * 处理业务逻辑
  34. * @param type $data
  35. * @return bool
  36. */
  37. public function deal($data): bool {
  38. switch ($data["type"]) {
  39. case 1:
  40. //添加保存未提交的津补贴申报
  41. try {
  42. $method = $data["method"];
  43. $talentId = $data["talentId"];
  44. $importRow = $data["data"];
  45. $enterprise = $data["enterprise"];
  46. $year = $data["year"];
  47. $allowanceType = $data["allowanceType"];
  48. if ($method == 1) {
  49. $ti = \app\common\api\VerifyApi::getTalentInfoById($talentId);
  50. if ($ti["talent_type"] == 1 && $ti["enterpriseType"] == \app\common\state\CommonConst::ENTERPRISE_WJ && $allowanceType == AllowanceTypeEnum::JBT_JT) {
  51. return false;
  52. }
  53. } else {
  54. $where[] = ["card_number", "=", $importRow[1]];
  55. $where[] = ["delete", "=", 0];
  56. $where[] = ["checkState", "=", TalentState::CERTIFICATED];
  57. $ti = Db::table("new_talent_info")->where($where)->order("talent_arrange asc")->find();
  58. $talentId = $ti["id"];
  59. $ti = \app\common\api\VerifyApi::getTalentInfoById($talentId);
  60. if ($ti["talent_type"] == 1 && $ti["enterpriseType"] == \app\common\state\CommonConst::ENTERPRISE_WJ && $allowanceType == AllowanceTypeEnum::JBT_JT) {
  61. return false;
  62. }
  63. }
  64. if ($ti["checkState"] != TalentState::CERTIFICATED || $ti["enterprise_id"] != $enterprise["uid"] || !$year || !$allowanceType) {
  65. return false;
  66. }
  67. $where = [];
  68. $where[] = ["year", "=", $year];
  69. $where[] = ["delete", "=", 0];
  70. $where[] = ["idCard", "=", $ti["card_number"]];
  71. $where[] = ["checkState", "not in", [MainState::NOTPASS, MainState::PASS]];
  72. $exists = TaModel::where($where)->find();
  73. if ($exists) {
  74. return false;
  75. }
  76. $data = [
  77. "talentId" => $talentId,
  78. "enterpriseId" => $ti["enterprise_id"],
  79. "enterpriseName" => $enterprise["name"],
  80. "year" => $year,
  81. "source" => $ti["source"],
  82. "qzgccrcActiveTime" => $ti["certificateExpireTime"],
  83. "talentType" => $ti["enterpriseTag"],
  84. "address" => $ti["street"],
  85. "name" => $ti["name"],
  86. "sex" => $ti["sex"],
  87. "cardType" => $ti["card_type"],
  88. "idCard" => $ti["card_number"],
  89. "firstInJJTime" => $ti["fst_work_time"],
  90. "entryTime" => $ti["cur_entry_time"],
  91. "post" => $ti["position"],
  92. "phone" => $ti["phone"],
  93. "talentArrange" => $ti["talent_arrange"],
  94. "identifyCondition" => $ti["talent_condition"],
  95. "identifyGetTime" => $ti["identifyGetTime"],
  96. "identifyOutTime" => $ti["identifyExpireTime"],
  97. "identifyConditionName" => $ti["identifyConditionName"],
  98. "identifyMonth" => $ti["identifyMonth"],
  99. "bank" => $ti["bank"],
  100. "bankNetwork" => $ti["bank_branch_name"],
  101. "bankAccount" => $ti["bank_account"],
  102. "bankNumber" => $ti["bank_number"],
  103. "checkState" => 1,
  104. "type" => $enterprise["type"],
  105. "provinceCode" => $ti["province"],
  106. "provinceName" => LocationApi::getNameByCode($ti["province"]),
  107. "cityCode" => $ti["city"],
  108. "cityName" => LocationApi::getNameByCode($ti["city"]),
  109. "countyCode" => $ti["county"],
  110. "countyName" => LocationApi::getNameByCode($ti["county"]),
  111. "isSupple" => 2,
  112. "createTime" => date("Y-m-d H:i:s"),
  113. "createUser" => $enterprise["uid"],
  114. "id" => getStringId(),
  115. "allowanceType" => $allowanceType
  116. ];
  117. $submitTime = $ti["first_submit_time"] ? $ti["first_submit_time"] : $ti["new_submit_time"];
  118. $identifyYear = date("Y", strtotime($submitTime));
  119. $year = substr($year, 0, 4);
  120. if ((($ti["enterpriseType"] == \app\common\state\CommonConst::ENTERPRISE_JC) || (in_array($ti["enterpriseType"], [\app\common\state\CommonConst::ENTERPRISE_WJ, \app\common\state\CommonConst::ENTERPRISE_GJ]) && $year != 2023)) && $identifyYear > $year) {
  121. return false;
  122. }
  123. /* * 1.获取上一年度的人才层次 */
  124. $arrangeList = $this->getLastYearTalentType($data, $ti);
  125. if (!$arrangeList) {
  126. if ($ti["enterpriseType"] == \app\common\state\CommonConst::ENTERPRISE_JC) {
  127. $identifyYear = substr($ti["identifyMonth"], 0, 4);
  128. if (!$year || !$identifyYear || $identifyYear > $year) {
  129. return false;
  130. }
  131. } else {
  132. return false;
  133. }
  134. }
  135. /* * 2.获取上一年度所在单位* */
  136. $contractDetailList = $this->getConcatList($ti, $data, $year); //保存上一年度的工作单位
  137. if (!$contractDetailList) {
  138. return false;
  139. }
  140. TaModel::insert($data);
  141. \app\common\model\TalentAllowancecontractDetail::insertAll($contractDetailList);
  142. /**
  143. * 4.添加津补贴核查项目
  144. */
  145. //核查项目详情表
  146. if ($method == 1) {
  147. $this->createAllowanceProject($data, $contractDetailList);
  148. } else {
  149. $this->createAllowanceProject_m2($data, $contractDetailList, $importRow);
  150. }
  151. \app\common\model\TalentAllowanceArrange::insertAll($arrangeList);
  152. //添加日志
  153. TalentChecklog::create([
  154. 'id' => getStringId(),
  155. 'mainId' => $data['id'],
  156. 'type' => intval(ProjectState::JBT),
  157. 'typeFileId' => null,
  158. 'active' => 1,
  159. 'state' => 1,
  160. 'step' => 0,
  161. 'stateChange' => "保存未提交",
  162. 'description' => "添加津补贴申报",
  163. 'createTime' => date("Y-m-d H:i:s", time()),
  164. 'createUser' => sprintf("%s(%s)", $enterprise["account"], $enterprise["companyName"])
  165. ]);
  166. return true;
  167. } catch (\Exception $e) {
  168. Log::write($e->getMessage(), "error");
  169. }
  170. break;
  171. }
  172. return false;
  173. }
  174. /* * 获取上一年度的人才层次变更信息 */
  175. private function getLastYearTalentType($info, $talentInfo) {
  176. $year = substr($info["year"], 0, 4);
  177. $arrangeList = [];
  178. /* * * 添加人才层次记录 */
  179. $oldStartTimeField = "oldIdentifyMonth";
  180. $newStartTimeField = "newIdentifyMonth";
  181. if ($info["type"] == \app\common\state\CommonConst::ENTERPRISE_JC) {
  182. $oldStartTimeField = "oldIdentifyGetTime";
  183. $newStartTimeField = "newIdentifyGetTime";
  184. }
  185. if (in_array($info["type"], [\app\common\state\CommonConst::ENTERPRISE_WJ]) && date("Y", strtotime($talentInfo["identifyMonth"])) == "2023") {
  186. $talentInfo["identifyMonth"] = "2022-12-01"; //让卫健包含2023全年
  187. }
  188. $where = [];
  189. $where[] = ["idCard", "=", $info["idCard"]];
  190. $where[] = ["checkState", "=", MainState::PASS];
  191. $where[] = ["isPublic", "=", 6];
  192. $where[] = [$oldStartTimeField, "<=", $year . "-12-31"];
  193. $typeList = TalentTypeChange::where($where)->field("oldTalentArrange,oldIdentifyCondition,oldIdentifyGetTime,oldIdentifyOutTime,oldIdentifyMonth,oldCertificateStartTime,oldCertificateOutTime,newIdentifyMonth,newIdentifyGetTime")->order("createTime desc")->select()->toArray();
  194. $typeList[] = [
  195. "oldTalentArrange" => $talentInfo["talent_arrange"],
  196. "oldIdentifyCondition" => $talentInfo["talent_condition"],
  197. "oldIdentifyGetTime" => $talentInfo["identifyGetTime"],
  198. "oldIdentifyOutTime" => $talentInfo["identifyExpireTime"],
  199. "oldIdentifyMonth" => $talentInfo["identifyMonth"],
  200. "oldCertificateStartTime" => $talentInfo["certificateGetTime"],
  201. "oldCertificateOutTime" => $talentInfo["certificateExpireTime"],
  202. "newIdentifyMonth" => $year . "-12-31",
  203. "newIdentifyGetTime" => $year . "-12-31"
  204. ];
  205. if (in_array($info["idCard"], \app\common\api\VerifyApi::getTwiceIdentifyPersons())) {
  206. $whr = [];
  207. $whr[] = ["ti.checkState", "=", TalentState::CERTIFICATED];
  208. $whr[] = ["ti.enterprise_id", "=", $talentInfo["enterpriseId"]];
  209. $whr[] = ["e.type", "=", $talentInfo["enterpriseType"]];
  210. $whr[] = ["ti.id", "<>", $talentInfo["id"]];
  211. $whr[] = ["card_number", "=", $info["idCard"]];
  212. $otherChangeList = \app\enterprise\model\Talent::alias("ti")->leftJoin("un_enterprise e", "e.id=ti.enterprise_id")->field("ti.*,e.`type` as eType")->order("identifyMonth desc")->where($whr)->select()->toArray();
  213. foreach ($otherChangeList as $k => $oc) {
  214. if ($k == 0) {
  215. $newIdentifyMonth = $talentInfo["identifyMonth"];
  216. $newIdentifyGetTime = $talentInfo["identifyGetTime"];
  217. } else {
  218. $newIdentifyMonth = $oc[$k - 1]["identifyMonth"];
  219. $newIdentifyGetTime = $oc[$k - 1]["identifyGetTime"];
  220. }
  221. $typeList[] = [
  222. "oldTalentArrange" => $oc["talent_arrange"],
  223. "oldIdentifyCondition" => $oc["talent_condition"],
  224. "oldIdentifyGetTime" => $oc["identifyGetTime"],
  225. "oldIdentifyOutTime" => $oc["identifyExpireTime"],
  226. "oldIdentifyMonth" => $oc["identifyMonth"],
  227. "oldCertificateStartTime" => $oc["certificateGetTime"],
  228. "oldCertificateOutTime" => $oc["certificateExpireTime"],
  229. "newIdentifyMonth" => $newIdentifyMonth,
  230. "newIdentifyGetTime" => $newIdentifyGetTime
  231. ];
  232. }
  233. }
  234. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  235. /* * 获取上一年度有效的人才层次 */
  236. usort($typeList, function($a, $b) {
  237. return (int) $b["oldTalentArrange"] - (int) $a["oldTalentArrange"];
  238. });
  239. $commonMonth = [];
  240. foreach ($typeList as $talentTypeChange) {
  241. $startTime = $talentTypeChange[$oldStartTimeField];
  242. $endTime = $talentTypeChange[$newStartTimeField];
  243. if (in_array($info["type"], [\app\common\state\CommonConst::ENTERPRISE_GJ])) {
  244. $monthList = \DateUtil::getMonthBetweenDatesNotEnd($startTime, $endTime);
  245. if ($endTime == $year . "-12-31") {
  246. $monthList[] = $year . "-12";
  247. }
  248. } else {
  249. $monthList = \DateUtil::getMonthBetweenDatesNotBegin($startTime, $endTime);
  250. }
  251. if ($monthList) {
  252. $monthList = array_intersect($monthList, $totalMonth);
  253. }
  254. if ($monthList) {
  255. $months = implode(",", $monthList);
  256. $monthList = array_filter($monthList, function($value) use ($commonMonth) {
  257. return !in_array($value, $commonMonth);
  258. });
  259. $commonMonth = array_filter(array_merge($commonMonth, $monthList));
  260. if (count($monthList) > 0) {
  261. $arrange = [
  262. "id" => getStringId(),
  263. "mainId" => $info["id"],
  264. "talentArrange" => $talentTypeChange["oldTalentArrange"],
  265. "identifyCondition" => $talentTypeChange["oldIdentifyCondition"],
  266. "startTime" => $startTime,
  267. "endTime" => $endTime,
  268. "prepareMonths" => null,
  269. "description" => "申报年度有效月份:" . $months,
  270. "identifyConditionName" => $talentTypeChange["oldIdentifyConditionName"],
  271. "identifyConditionGetTime" => $talentTypeChange["oldIdentifyGetTime"],
  272. ];
  273. $sb = '';
  274. foreach ($monthList as $month) {
  275. $sb .= substr($month, 5, 2) . ",";
  276. }
  277. $arrange["prepareMonths"] = rtrim($sb, ",");
  278. $arrangeList[] = $arrange;
  279. }
  280. }
  281. }
  282. return $arrangeList;
  283. }
  284. /**
  285. * @param
  286. * @returns void
  287. * @author Liu
  288. * @date 2020/4/26
  289. * @description 获取上一年度所在单位
  290. * */
  291. private function getConcatList($talentInfo, $info, $year) {
  292. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  293. /** 添加申报人才上一年度工作单位记录 */
  294. $where = [];
  295. $where[] = ["idCard", "=", $talentInfo["card_number"]];
  296. $where[] = ["checkState", "=", 3];
  297. $quitList = \app\common\model\TalentQuit::where($where)->field("enterpriseId,enterpriseName,talentType,identifyGetTime,starttime,endtime,entryTime,quitTime,post")->select()->toArray();
  298. /* * * 将最新的人才数据转为工作变更记录(为了统一处理) */
  299. if ($talentInfo["active"] == 1) {
  300. $labor_contract_rangetime = explode(" - ", $talentInfo["labor_contract_rangetime"]);
  301. $starttime = $labor_contract_rangetime[0];
  302. $endtime = $labor_contract_rangetime[1];
  303. $quitList[] = [
  304. "enterpriseId" => $talentInfo["enterprise_id"],
  305. "enterpriseName" => $talentInfo["enterpriseName"],
  306. "talentType" => $talentInfo["enterpriseTag"],
  307. "identifyGetTime" => $talentInfo["identifyGetTime"],
  308. "starttime" => $starttime,
  309. "endtime" => $endtime,
  310. "entryTime" => $talentInfo["cur_entry_time"],
  311. "quitTime" => null,
  312. "post" => $talentInfo["position"]
  313. ];
  314. }
  315. $list = [];
  316. foreach ($quitList as $quit) {
  317. $monthList = \DateUtil::getMonthBetweenDates($quit["entryTime"], \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"]);
  318. $monthList = array_intersect($monthList, $totalMonth);
  319. if ($monthList) {
  320. $sb = '';
  321. foreach ($monthList as $month) {
  322. $sb .= substr($month, 5, 2) . ",";
  323. }
  324. $list[] = [
  325. "id" => getStringId(),
  326. "mainId" => $info["id"],
  327. "enterpriseId" => $quit["enterpriseId"],
  328. "talentType" => $quit["talentType"],
  329. "startTime" => $quit["starttime"],
  330. "endTime" => $quit["endtime"],
  331. "entryTime" => $quit["entryTime"],
  332. "quitTime" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"],
  333. "letterTime" => $quit["letterTime"],
  334. "gygb" => $quit["gygb"],
  335. "identifyGetTime" => $quit["identifyGetTime"],
  336. "isQuit" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? 2 : 1,
  337. "post" => $quit["post"],
  338. "months" => rtrim($sb, ",")
  339. ];
  340. }
  341. }
  342. return $list;
  343. }
  344. private function createAllowanceProject($info, $contractList) {
  345. $count = 0;
  346. foreach ($contractList as $detail) {
  347. $count++;
  348. $projects = AllowanceProjectEnum::getProjectsByEnterpriseType($info["type"], $info["enterpriseId"]);
  349. $list = [];
  350. foreach ($projects as $project) {
  351. $months = "";
  352. if ($count == count($contractList) && $info["allowanceType"] == AllowanceTypeEnum::JBT_TALENT)
  353. $months = "01,02,03,04,05,06,07,08,09,10,11,12";
  354. $list[] = [
  355. "mainId" => $info["id"],
  356. "baseId" => $detail["id"],
  357. "enterpriseId" => $detail["enterpriseId"],
  358. "project" => $project,
  359. "months" => $months,
  360. "isLock" => 1,
  361. "createTime" => date("Y-m-d H:i:s")
  362. ];
  363. }
  364. \app\common\model\TalentAllowanceProject::insertAll($list);
  365. }
  366. }
  367. private function createAllowanceProject_m2($info, $contractList, $rowdata) {
  368. $count = 0;
  369. $projects = AllowanceProjectEnum::getProjectsByEnterpriseType($info["type"], $info["enterpriseId"]);
  370. $need_extra_project = getJsonConfig("../sys_config.json", "talent_allowance_need_extra_project");
  371. foreach ($contractList as $detail) {
  372. $count++;
  373. $list = [];
  374. for ($i = 3; $i < count($rowdata); $i++) {
  375. $project = 1;
  376. switch ($i) {
  377. case 3:
  378. $project = AllowanceProjectEnum::PROJECT_TAX;
  379. break;
  380. case 4:
  381. $project = AllowanceProjectEnum::PROJECT_WAGES;
  382. break;
  383. case 5:
  384. $project = AllowanceProjectEnum::PROJECT_ATTENDANCE;
  385. break;
  386. case 6:
  387. $project = AllowanceProjectEnum::PROJECT_SB_PENSION;
  388. break;
  389. case 7:
  390. if ($info["type"] == \app\common\state\CommonConst::ENTERPRISE_GJ && $need_extra_project[$info["enterpriseId"]]) {
  391. $project = $need_extra_project[$info["enterpriseId"]][0];
  392. } else {
  393. $project = AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT;
  394. }
  395. break;
  396. case 8:
  397. if ($info["type"] == \app\common\state\CommonConst::ENTERPRISE_GJ && $need_extra_project[$info["enterpriseId"]]) {
  398. $project = $need_extra_project[$info["enterpriseId"]][1];
  399. } else {
  400. $project = AllowanceProjectEnum::PROJECT_SB_MEDICA;
  401. }
  402. break;
  403. }
  404. if (!in_array($project, $projects))
  405. continue;
  406. $months = "";
  407. if ($count == count($contractList)) {
  408. if ($info["allowanceType"] == 2 && $i == 5) {
  409. $monthstr = str_replace([" ", ","], ",", trim($rowdata[5]));
  410. $monthstr = str_replace(":", ":", $monthstr);
  411. $months = array_filter(explode(",", $monthstr));
  412. $tmp = [];
  413. for ($n = 0; $n < count($months); $n++) {
  414. list($a, $b) = explode(":", $months[$n]);
  415. $a = str_pad($a, 2, 0, STR_PAD_LEFT);
  416. $tmp[] = sprintf("%s=%s", $a, $b);
  417. }
  418. $months = $tmp ? implode(",", $tmp) : "";
  419. } else {
  420. $monthstr = str_replace([" ", ","], ",", trim($rowdata[$i]));
  421. $months = array_filter(explode(",", $monthstr));
  422. for ($n = 0; $n < count($months); $n++) {
  423. $months[$n] = str_pad($months[$n], 2, 0, STR_PAD_LEFT);
  424. }
  425. $months = $months ? implode(",", $months) : "";
  426. }
  427. }
  428. $list[] = [
  429. "mainId" => $info["id"],
  430. "baseId" => $detail["id"],
  431. "enterpriseId" => $detail["enterpriseId"],
  432. "project" => $project,
  433. "months" => $months,
  434. "isLock" => 1,
  435. "createTime" => date("Y-m-d H:i:s")
  436. ];
  437. }
  438. \app\common\model\TalentAllowanceProject::insertAll($list);
  439. }
  440. }
  441. }