TalentAllowance.php 14 KB

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