TalentAllowance.php 18 KB

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