TalentAllowance.php 18 KB

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