TalentAllowance.php 14 KB

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