TalentAllowance.php 19 KB

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