TalentAllowance.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. return false;
  127. }
  128. /* * 2.获取上一年度所在单位* */
  129. $contractDetailList = $this->getConcatList($ti, $data, $year); //保存上一年度的工作单位
  130. if (!$contractDetailList) {
  131. return false;
  132. }
  133. TaModel::insert($data);
  134. \app\common\model\TalentAllowancecontractDetail::insertAll($contractDetailList);
  135. /**
  136. * 4.添加津补贴核查项目
  137. */
  138. //核查项目详情表
  139. if ($method == 1) {
  140. $this->createAllowanceProject($data, $contractDetailList);
  141. } else {
  142. $this->createAllowanceProject_m2($data, $contractDetailList, $importRow);
  143. }
  144. \app\common\model\TalentAllowanceArrange::insertAll($arrangeList);
  145. //添加日志
  146. TalentChecklog::create([
  147. 'id' => getStringId(),
  148. 'mainId' => $data['id'],
  149. 'type' => intval(ProjectState::JBT),
  150. 'typeFileId' => null,
  151. 'active' => 1,
  152. 'state' => 1,
  153. 'step' => 0,
  154. 'stateChange' => "保存未提交",
  155. 'description' => "添加津补贴申报",
  156. 'createTime' => date("Y-m-d H:i:s", time()),
  157. 'createUser' => sprintf("%s(%s)", $enterprise["account"], $enterprise["companyName"])
  158. ]);
  159. return true;
  160. } catch (\Exception $e) {
  161. Log::write($e->getMessage(), "error");
  162. }
  163. break;
  164. }
  165. return false;
  166. }
  167. /* * 获取上一年度的人才层次变更信息 */
  168. private function getLastYearTalentType($info, $talentInfo) {
  169. $year = substr($info["year"], 0, 4);
  170. $arrangeList = [];
  171. /* * * 添加人才层次记录 */
  172. $oldStartTimeField = "oldIdentifyMonth";
  173. $newStartTimeField = "newIdentifyMonth";
  174. if ($info["type"] == \app\common\state\CommonConst::ENTERPRISE_JC) {
  175. $oldStartTimeField = "oldIdentifyGetTime";
  176. $newStartTimeField = "newIdentifyGetTime";
  177. }
  178. if (in_array($info["type"], [\app\common\state\CommonConst::ENTERPRISE_WJ, \app\common\state\CommonConst::ENTERPRISE_GJ]) && date("Y", strtotime($talentInfo["identifyMonth"])) == "2023") {
  179. $talentInfo["identifyMonth"] = "2022-12-01"; //让卫健高教包含2023全年
  180. }
  181. $where = [];
  182. $where[] = ["idCard", "=", $info["idCard"]];
  183. $where[] = ["checkState", "=", MainState::PASS];
  184. $where[] = ["isPublic", ">=", 5];
  185. $where[] = [$oldStartTimeField, "<=", $year . "-12-31"];
  186. $typeList = TalentTypeChange::where($where)->field("oldTalentArrange,oldIdentifyCondition,oldIdentifyGetTime,oldIdentifyOutTime,oldIdentifyMonth,oldCertificateStartTime,oldCertificateOutTime,newIdentifyMonth,newIdentifyGetTime")->order("createTime desc")->select()->toArray();
  187. $typeList[] = [
  188. "oldTalentArrange" => $talentInfo["talent_arrange"],
  189. "oldIdentifyCondition" => $talentInfo["talent_condition"],
  190. "oldIdentifyGetTime" => $talentInfo["identifyGetTime"],
  191. "oldIdentifyOutTime" => $talentInfo["identifyExpireTime"],
  192. "oldIdentifyMonth" => $talentInfo["identifyMonth"],
  193. "oldCertificateStartTime" => $talentInfo["certificateGetTime"],
  194. "oldCertificateOutTime" => $talentInfo["certificateExpireTime"],
  195. "newIdentifyMonth" => $year . "-12-31",
  196. "newIdentifyGetTime" => $year . "-12-31"
  197. ];
  198. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  199. /* * 获取上一年度有效的人才层次 */
  200. usort($typeList, function($a, $b) {
  201. return (int) $b["oldTalentArrange"] - (int) $a["oldTalentArrange"];
  202. });
  203. $commonMonth = [];
  204. foreach ($typeList as $talentTypeChange) {
  205. $startTime = $talentTypeChange[$oldStartTimeField];
  206. $endTime = $talentTypeChange[$newStartTimeField];
  207. $monthList = \DateUtil::getMonthBetweenDatesNotBegin($startTime, $endTime);
  208. if ($monthList) {
  209. $monthList = array_intersect($monthList, $totalMonth);
  210. }
  211. if ($monthList) {
  212. $months = implode(",", $monthList);
  213. $monthList = array_filter($monthList, function($value) use ($commonMonth) {
  214. return !in_array($value, $commonMonth);
  215. });
  216. $commonMonth = array_filter(array_merge($commonMonth, $monthList));
  217. if (count($monthList) > 0) {
  218. $arrange = [
  219. "id" => getStringId(),
  220. "mainId" => $info["id"],
  221. "talentArrange" => $talentTypeChange["oldTalentArrange"],
  222. "identifyCondition" => $talentTypeChange["oldIdentifyCondition"],
  223. "startTime" => $startTime,
  224. "endTime" => $endTime,
  225. "prepareMonths" => null,
  226. "description" => "申报年度有效月份:" . $months,
  227. "identifyConditionName" => $talentTypeChange["oldIdentifyConditionName"],
  228. "identifyConditionGetTime" => $talentTypeChange["oldIdentifyGetTime"],
  229. ];
  230. $sb = '';
  231. foreach ($monthList as $month) {
  232. $sb .= substr($month, 5, 2) . ",";
  233. }
  234. $arrange["prepareMonths"] = rtrim($sb, ",");
  235. $arrangeList[] = $arrange;
  236. }
  237. }
  238. }
  239. return $arrangeList;
  240. }
  241. /**
  242. * @param
  243. * @returns void
  244. * @author Liu
  245. * @date 2020/4/26
  246. * @description 获取上一年度所在单位
  247. * */
  248. private function getConcatList($talentInfo, $info, $year) {
  249. $totalMonth = \DateUtil::getMonthBetweenDates($year . "-01-01", $year . "-12-31");
  250. /** 添加申报人才上一年度工作单位记录 */
  251. $where = [];
  252. $where[] = ["idCard", "=", $talentInfo["card_number"]];
  253. $where[] = ["checkState", "=", 3];
  254. $quitList = \app\common\model\TalentQuit::where($where)->field("enterpriseId,enterpriseName,talentType,identifyGetTime,starttime,endtime,entryTime,quitTime,post")->select()->toArray();
  255. /* * * 将最新的人才数据转为工作变更记录(为了统一处理) */
  256. if ($talentInfo["active"] == 1) {
  257. $labor_contract_rangetime = explode(" - ", $talentInfo["labor_contract_rangetime"]);
  258. $starttime = $labor_contract_rangetime[0];
  259. $endtime = $labor_contract_rangetime[1];
  260. $quitList[] = [
  261. "enterpriseId" => $talentInfo["enterprise_id"],
  262. "enterpriseName" => $talentInfo["enterpriseName"],
  263. "talentType" => $talentInfo["enterpriseTag"],
  264. "identifyGetTime" => $talentInfo["identifyGetTime"],
  265. "starttime" => $starttime,
  266. "endtime" => $endtime,
  267. "entryTime" => $talentInfo["cur_entry_time"],
  268. "quitTime" => null,
  269. "post" => $talentInfo["position"]
  270. ];
  271. }
  272. $list = [];
  273. foreach ($quitList as $quit) {
  274. $monthList = \DateUtil::getMonthBetweenDates($quit["entryTime"], \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"]);
  275. $monthList = array_intersect($monthList, $totalMonth);
  276. if ($monthList) {
  277. $sb = '';
  278. foreach ($monthList as $month) {
  279. $sb .= substr($month, 5, 2) . ",";
  280. }
  281. $list[] = [
  282. "id" => getStringId(),
  283. "mainId" => $info["id"],
  284. "enterpriseId" => $quit["enterpriseId"],
  285. "talentType" => $quit["talentType"],
  286. "startTime" => $quit["starttime"],
  287. "endTime" => $quit["endtime"],
  288. "entryTime" => $quit["entryTime"],
  289. "quitTime" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? $year . "-12-31" : $quit["quitTime"],
  290. "letterTime" => $quit["letterTime"],
  291. "gygb" => $quit["gygb"],
  292. "identifyGetTime" => $quit["identifyGetTime"],
  293. "isQuit" => \StrUtil::isEmpOrNull($quit["quitTime"]) ? 2 : 1,
  294. "post" => $quit["post"],
  295. "months" => rtrim($sb, ",")
  296. ];
  297. }
  298. }
  299. return $list;
  300. }
  301. private function createAllowanceProject($info, $contractList) {
  302. $count = 0;
  303. foreach ($contractList as $detail) {
  304. $count++;
  305. $projects = AllowanceProjectEnum::getProjectsByEnterpriseType($info["type"]);
  306. $list = [];
  307. foreach ($projects as $project) {
  308. $months = "";
  309. if ($count == count($contractList) && $info["allowanceType"] == AllowanceTypeEnum::JBT_TALENT)
  310. $months = "01,02,03,04,05,06,07,08,09,10,11,12";
  311. $list[] = [
  312. "mainId" => $info["id"],
  313. "baseId" => $detail["id"],
  314. "enterpriseId" => $detail["enterpriseId"],
  315. "project" => $project,
  316. "months" => $months,
  317. "isLock" => 1,
  318. "createTime" => date("Y-m-d H:i:s")
  319. ];
  320. }
  321. \app\common\model\TalentAllowanceProject::insertAll($list);
  322. }
  323. }
  324. private function createAllowanceProject_m2($info, $contractList, $rowdata) {
  325. $count = 0;
  326. $projects = AllowanceProjectEnum::getProjectsByEnterpriseType($info["type"]);
  327. foreach ($contractList as $detail) {
  328. $count++;
  329. $list = [];
  330. for ($i = 3; $i < count($rowdata); $i++) {
  331. $project = 1;
  332. switch ($i) {
  333. case 3:
  334. $project = AllowanceProjectEnum::PROJECT_TAX;
  335. break;
  336. case 4:
  337. $project = AllowanceProjectEnum::PROJECT_WAGES;
  338. break;
  339. case 5:
  340. $project = AllowanceProjectEnum::PROJECT_ATTENDANCE;
  341. break;
  342. case 6:
  343. $project = AllowanceProjectEnum::PROJECT_SB_PENSION;
  344. break;
  345. case 7:
  346. $project = AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT;
  347. break;
  348. case 8:
  349. $project = AllowanceProjectEnum::PROJECT_SB_MEDICA;
  350. break;
  351. }
  352. if (!in_array($project, $projects))
  353. continue;
  354. $months = "";
  355. if ($count == count($contractList)) {
  356. if ($info["allowanceType"] == 2 && $i == 5) {
  357. $monthstr = str_replace([" ", ","], ",", trim($rowdata[5]));
  358. $monthstr = str_replace(":", ":", $monthstr);
  359. $months = array_filter(explode(",", $monthstr));
  360. $tmp = [];
  361. for ($n = 0; $n < count($months); $n++) {
  362. list($a, $b) = explode(":", $months[$n]);
  363. $a = str_pad($a, 2, 0, STR_PAD_LEFT);
  364. $tmp[] = sprintf("%s=%s", $a, $b);
  365. }
  366. $months = $tmp ? implode(",", $tmp) : "";
  367. } else {
  368. $monthstr = str_replace([" ", ","], ",", trim($rowdata[$i]));
  369. $months = array_filter(explode(",", $monthstr));
  370. for ($n = 0; $n < count($months); $n++) {
  371. $months[$n] = str_pad($months[$n], 2, 0, STR_PAD_LEFT);
  372. }
  373. $months = $months ? implode(",", $months) : "";
  374. }
  375. }
  376. $list[] = [
  377. "mainId" => $info["id"],
  378. "baseId" => $detail["id"],
  379. "enterpriseId" => $detail["enterpriseId"],
  380. "project" => $project,
  381. "months" => $months,
  382. "isLock" => 1,
  383. "createTime" => date("Y-m-d H:i:s")
  384. ];
  385. }
  386. \app\common\model\TalentAllowanceProject::insertAll($list);
  387. }
  388. }
  389. }