TalentAllowance.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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", ">=", 5];
  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. $monthList = \DateUtil::getMonthBetweenDatesNotBegin($startTime, $endTime);
  244. if ($monthList) {
  245. $monthList = array_intersect($monthList, $totalMonth);
  246. }
  247. if ($monthList) {
  248. $months = implode(",", $monthList);
  249. $monthList = array_filter($monthList, function($value) use ($commonMonth) {
  250. return !in_array($value, $commonMonth);
  251. });
  252. $commonMonth = array_filter(array_merge($commonMonth, $monthList));
  253. if (count($monthList) > 0) {
  254. $arrange = [
  255. "id" => getStringId(),
  256. "mainId" => $info["id"],
  257. "talentArrange" => $talentTypeChange["oldTalentArrange"],
  258. "identifyCondition" => $talentTypeChange["oldIdentifyCondition"],
  259. "startTime" => $startTime,
  260. "endTime" => $endTime,
  261. "prepareMonths" => null,
  262. "description" => "申报年度有效月份:" . $months,
  263. "identifyConditionName" => $talentTypeChange["oldIdentifyConditionName"],
  264. "identifyConditionGetTime" => $talentTypeChange["oldIdentifyGetTime"],
  265. ];
  266. $sb = '';
  267. foreach ($monthList as $month) {
  268. $sb .= substr($month, 5, 2) . ",";
  269. }
  270. $arrange["prepareMonths"] = rtrim($sb, ",");
  271. $arrangeList[] = $arrange;
  272. }
  273. }
  274. }
  275. return $arrangeList;
  276. }
  277. /**
  278. * @param
  279. * @returns void
  280. * @author Liu
  281. * @date 2020/4/26
  282. * @description 获取上一年度所在单位
  283. * */
  284. private function getConcatList($talentInfo, $info, $year) {
  285. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  286. /** 添加申报人才上一年度工作单位记录 */
  287. $where = [];
  288. $where[] = ["idCard", "=", $talentInfo["card_number"]];
  289. $where[] = ["checkState", "=", 3];
  290. $quitList = \app\common\model\TalentQuit::where($where)->field("enterpriseId,enterpriseName,talentType,identifyGetTime,starttime,endtime,entryTime,quitTime,post")->select()->toArray();
  291. /* * * 将最新的人才数据转为工作变更记录(为了统一处理) */
  292. if ($talentInfo["active"] == 1) {
  293. $labor_contract_rangetime = explode(" - ", $talentInfo["labor_contract_rangetime"]);
  294. $starttime = $labor_contract_rangetime[0];
  295. $endtime = $labor_contract_rangetime[1];
  296. $quitList[] = [
  297. "enterpriseId" => $talentInfo["enterprise_id"],
  298. "enterpriseName" => $talentInfo["enterpriseName"],
  299. "talentType" => $talentInfo["enterpriseTag"],
  300. "identifyGetTime" => $talentInfo["identifyGetTime"],
  301. "starttime" => $starttime,
  302. "endtime" => $endtime,
  303. "entryTime" => $talentInfo["cur_entry_time"],
  304. "quitTime" => null,
  305. "post" => $talentInfo["position"]
  306. ];
  307. }
  308. $list = [];
  309. foreach ($quitList as $quit) {
  310. $monthList = \DateUtil::getMonthBetweenDates($quit["entryTime"], \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"]);
  311. $monthList = array_intersect($monthList, $totalMonth);
  312. if ($monthList) {
  313. $sb = '';
  314. foreach ($monthList as $month) {
  315. $sb .= substr($month, 5, 2) . ",";
  316. }
  317. $list[] = [
  318. "id" => getStringId(),
  319. "mainId" => $info["id"],
  320. "enterpriseId" => $quit["enterpriseId"],
  321. "talentType" => $quit["talentType"],
  322. "startTime" => $quit["starttime"],
  323. "endTime" => $quit["endtime"],
  324. "entryTime" => $quit["entryTime"],
  325. "quitTime" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"],
  326. "letterTime" => $quit["letterTime"],
  327. "gygb" => $quit["gygb"],
  328. "identifyGetTime" => $quit["identifyGetTime"],
  329. "isQuit" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? 2 : 1,
  330. "post" => $quit["post"],
  331. "months" => rtrim($sb, ",")
  332. ];
  333. }
  334. }
  335. return $list;
  336. }
  337. private function createAllowanceProject($info, $contractList) {
  338. $count = 0;
  339. foreach ($contractList as $detail) {
  340. $count++;
  341. $projects = AllowanceProjectEnum::getProjectsByEnterpriseType($info["type"]);
  342. $list = [];
  343. foreach ($projects as $project) {
  344. $months = "";
  345. if ($count == count($contractList) && $info["allowanceType"] == AllowanceTypeEnum::JBT_TALENT)
  346. $months = "01,02,03,04,05,06,07,08,09,10,11,12";
  347. $list[] = [
  348. "mainId" => $info["id"],
  349. "baseId" => $detail["id"],
  350. "enterpriseId" => $detail["enterpriseId"],
  351. "project" => $project,
  352. "months" => $months,
  353. "isLock" => 1,
  354. "createTime" => date("Y-m-d H:i:s")
  355. ];
  356. }
  357. \app\common\model\TalentAllowanceProject::insertAll($list);
  358. }
  359. }
  360. private function createAllowanceProject_m2($info, $contractList, $rowdata) {
  361. $count = 0;
  362. $projects = AllowanceProjectEnum::getProjectsByEnterpriseType($info["type"]);
  363. foreach ($contractList as $detail) {
  364. $count++;
  365. $list = [];
  366. for ($i = 3; $i < count($rowdata); $i++) {
  367. $project = 1;
  368. switch ($i) {
  369. case 3:
  370. $project = AllowanceProjectEnum::PROJECT_TAX;
  371. break;
  372. case 4:
  373. $project = AllowanceProjectEnum::PROJECT_WAGES;
  374. break;
  375. case 5:
  376. $project = AllowanceProjectEnum::PROJECT_ATTENDANCE;
  377. break;
  378. case 6:
  379. $project = AllowanceProjectEnum::PROJECT_SB_PENSION;
  380. break;
  381. case 7:
  382. $project = AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT;
  383. break;
  384. case 8:
  385. $project = AllowanceProjectEnum::PROJECT_SB_MEDICA;
  386. break;
  387. }
  388. if (!in_array($project, $projects))
  389. continue;
  390. $months = "";
  391. if ($count == count($contractList)) {
  392. if ($info["allowanceType"] == 2 && $i == 5) {
  393. $monthstr = str_replace([" ", ","], ",", trim($rowdata[5]));
  394. $monthstr = str_replace(":", ":", $monthstr);
  395. $months = array_filter(explode(",", $monthstr));
  396. $tmp = [];
  397. for ($n = 0; $n < count($months); $n++) {
  398. list($a, $b) = explode(":", $months[$n]);
  399. $a = str_pad($a, 2, 0, STR_PAD_LEFT);
  400. $tmp[] = sprintf("%s=%s", $a, $b);
  401. }
  402. $months = $tmp ? implode(",", $tmp) : "";
  403. } else {
  404. $monthstr = str_replace([" ", ","], ",", trim($rowdata[$i]));
  405. $months = array_filter(explode(",", $monthstr));
  406. for ($n = 0; $n < count($months); $n++) {
  407. $months[$n] = str_pad($months[$n], 2, 0, STR_PAD_LEFT);
  408. }
  409. $months = $months ? implode(",", $months) : "";
  410. }
  411. }
  412. $list[] = [
  413. "mainId" => $info["id"],
  414. "baseId" => $detail["id"],
  415. "enterpriseId" => $detail["enterpriseId"],
  416. "project" => $project,
  417. "months" => $months,
  418. "isLock" => 1,
  419. "createTime" => date("Y-m-d H:i:s")
  420. ];
  421. }
  422. \app\common\model\TalentAllowanceProject::insertAll($list);
  423. }
  424. }
  425. }