TalentAllowanceApi.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <?php
  2. namespace app\common\api;
  3. use app\common\model\TalentAllowance as TaModel;
  4. use app\common\state\MainState;
  5. use think\facade\Db;
  6. use app\common\state\CommonConst;
  7. use app\common\state\AllowanceProjectEnum;
  8. use app\common\model\TalentAllowanceArrange;
  9. use app\common\model\AmountStandard as AsModel;
  10. use app\common\state\AllowanceStateEnum;
  11. /**
  12. * Description of TalentAllowanceApi
  13. *
  14. * @author sgq
  15. */
  16. class TalentAllowanceApi {
  17. public static function getList($params) {
  18. $user = session("user");
  19. $order = trim($params["order"]) ?: "desc";
  20. $offset = trim($params["offset"]) ?: 0;
  21. $limit = trim($params["limit"]) ?: 10;
  22. $where = [];
  23. $where[] = ["ta.delete", "=", 0];
  24. $where[] = ["ta.enterpriseId", "=", $user["uid"]];
  25. if ($_where = self::setTalentAllowanceInfo($params)) {
  26. $where = array_merge($where, $_where);
  27. }
  28. $count = TaModel::where($where)->alias("ta")->leftJoin("un_enterprise e", "e.id=ta.enterpriseId")->count();
  29. $list = TaModel::where($where)->alias("ta")->leftJoin("un_enterprise e", "e.id=ta.enterpriseId")->field("ta.*")->limit($offset, $limit)->order("year {$order},ta.createTime {$order}")->select()->toArray();
  30. $levelList = DictApi::selectByParentCode("talent_arrange");
  31. $talentTypeList = DictApi::selectByParentCode("enterprise_tag");
  32. $streetList = DictApi::selectByParentCode("street");
  33. $identifyConditionIds = array_filter(array_unique(array_column($list, "identifyCondition")));
  34. $whr[] = ["id", "in", $identifyConditionIds];
  35. $whr[] = ["type", "=", $user["type"]];
  36. $identifyConditionKvList = TalentConditionApi::getKvList($whr);
  37. foreach ($list as $key => $item) {
  38. $list[$key]["talentArrangeName"] = $levelList[$item["talentArrange"]];
  39. $list[$key]["talentTypeName"] = $talentTypeList[$item["talentType"]];
  40. $list[$key]["addressName"] = $streetList[$item["address"]];
  41. $list[$key]["identifyConditionText"] = $identifyConditionKvList[$item["identifyCondition"]];
  42. }
  43. return ["total" => $count, "rows" => $list];
  44. }
  45. public static function getHospitalExamineList($params) {
  46. $user = session("user");
  47. $order = trim($params["order"]) ?: "desc";
  48. $offset = trim($params["offset"]) ?: 0;
  49. $limit = trim($params["limit"]) ?: 10;
  50. $where = [];
  51. $where[] = ["ta.delete", "=", 0];
  52. $where[] = ["ta.type", "=", 5];
  53. $where[] = ["e.medicalCommunityId", "=", $user["medicalCommunityId"]];
  54. $where[] = ["e.isGeneral", "=", 2];
  55. if ($_where = self::setTalentAllowanceInfo($params)) {
  56. $where = array_merge($where, $_where);
  57. }
  58. $whereRaw = "ta.id>0";
  59. if (\StrUtil::isNotEmpAndNull($params["checkState"])) {
  60. switch ($params["checkState"]) {
  61. case -1:
  62. $where[] = ["ta.checkState", "=", AllowanceStateEnum::NOTPASS];
  63. break;
  64. case -2:
  65. $where[] = ["ta.checkState", "=", AllowanceStateEnum::SAVE];
  66. break;
  67. case 1:
  68. $where[] = ["ta.checkState", "=", AllowanceStateEnum::NEED_GENERAL_CHECK];
  69. $whereRaw = "ta.highProcess is null or ta.highProcess < 1";
  70. break;
  71. case 2:
  72. $where[] = ["ta.checkState", "=", AllowanceStateEnum::GENERAL_REJECT];
  73. break;
  74. case 3:
  75. $where[] = ["ta.checkState", "=", AllowanceStateEnum::REVIEW_PASS];
  76. $where[] = ["ta.publicState", "=", 5];
  77. break;
  78. case 4:
  79. $where[] = ["ta.checkState", "=", AllowanceStateEnum::FIRST_REJECT];
  80. break;
  81. case 5:
  82. $where[] = ["ta.checkState", "=", AllowanceStateEnum::FIRST_REJECT_BRANCH];
  83. break;
  84. case 6:
  85. $where[] = ["ta.publicState", "<>", 5];
  86. $whereRaw = "ta.checkState=5 or ta.checkState >= 13";
  87. break;
  88. case 9:
  89. $where[] = ["ta.checkState", "=", AllowanceStateEnum::NEED_GENERAL_CHECK];
  90. $whereRaw = "ta.highProcess is not null and ta.highProcess >= 1";
  91. break;
  92. }
  93. }
  94. $count = TaModel::where($where)->whereRaw($whereRaw)->alias("ta")->leftJoin("un_enterprise e", "e.id=ta.enterpriseId")->count();
  95. $list = TaModel::where($where)->whereRaw($whereRaw)->alias("ta")->leftJoin("un_enterprise e", "e.id=ta.enterpriseId")->field("ta.*")->limit($offset, $limit)->order("year {$order},ta.createTime {$order}")->select()->toArray();
  96. $levelList = DictApi::selectByParentCode("talent_arrange");
  97. $talentTypeList = DictApi::selectByParentCode("enterprise_tag");
  98. $streetList = DictApi::selectByParentCode("street");
  99. $identifyConditionIds = array_filter(array_unique(array_column($list, "identifyCondition")));
  100. $whr[] = ["id", "in", $identifyConditionIds];
  101. $whr[] = ["type", "=", $user["type"]];
  102. $identifyConditionKvList = TalentConditionApi::getKvList($whr);
  103. foreach ($list as $key => $item) {
  104. $list[$key]["talentArrangeName"] = $levelList[$item["talentArrange"]];
  105. $list[$key]["talentTypeName"] = $talentTypeList[$item["talentType"]];
  106. $list[$key]["addressName"] = $streetList[$item["address"]];
  107. $list[$key]["identifyConditionText"] = $identifyConditionKvList[$item["identifyCondition"]];
  108. }
  109. return ["total" => $count, "rows" => $list];
  110. }
  111. public static function setTalentAllowanceInfo($params) {
  112. $where = [];
  113. if (\StrUtil::isNotEmpAndNull($params["year"])) {
  114. $where[] = ["ta.year", "=", $params["year"]];
  115. }
  116. if (\StrUtil::isNotEmpAndNull($params["enterpriseName"])) {
  117. $where[] = ["ta.enterpriseName", "like", "%" . $params["enterpriseName"] . "%"];
  118. }
  119. if (\StrUtil::isNotEmpAndNull($params["name"])) {
  120. $where[] = ["ta.name", "like", "%" . $params["name"] . "%"];
  121. }
  122. if (\StrUtil::isNotEmpAndNull($params["talentType"])) {
  123. $where[] = ["ta.talentType", "=", $params["talentType"]];
  124. }
  125. if (\StrUtil::isNotEmpAndNull($params["talentArrange"])) {
  126. $where[] = ["ta.talentArrange", "=", $params["talentArrange"]];
  127. }
  128. if (\StrUtil::isNotEmpAndNull($params["identiryCondition"])) {
  129. $where[] = ["ta.identifyCondition", "=", $params["identifyCondition"]];
  130. }
  131. if (\StrUtil::isNotEmpAndNull($params["allowanceType"])) {
  132. $where[] = ["ta.allowanceType", "=", $params["allowanceType"]];
  133. }
  134. if (\StrUtil::isNotEmpAndNull($params["address"])) {
  135. $where[] = ["ta.address", "=", $params["address"]];
  136. }
  137. return $where;
  138. }
  139. public static function getInfoById($id) {
  140. return TaModel::findOrEmpty($id)->toArray();
  141. }
  142. public static function getApplyCountByIdCard($idCard) {
  143. $where = [];
  144. $where[] = ["idCard", "=", $idCard];
  145. $where[] = ["checkState", "<>", MainState::NOTPASS];
  146. $list = TaModel::where($where)->distinct(true)->field("substr(year,1,4) as year")->select()->toArray();
  147. $years = array_column($list, "year");
  148. return $years;
  149. }
  150. public static function getPassYearsByIdCard($idCard) {
  151. $where = [];
  152. $where[] = ["idCard", "=", $idCard];
  153. $where[] = ["checkState", "=", MainState::PASS];
  154. $list = TaModel::where($where)->distinct(true)->field("substr(year,1,4) as year")->select()->toArray();
  155. $passYears = array_column($list, "year");
  156. return $passYears;
  157. }
  158. public static function validateAllowanceType($id) {
  159. $info = ["id" => $id];
  160. $old = self::getInfoById($id);
  161. $info["type"] = $old["type"];
  162. $info["allowanceType"] = $old["allowanceType"];
  163. $enterpriseMap = \app\common\model\Enterprise::where("type", $old["type"])->column("name", "id");
  164. /* * 查询工作单位记录 */
  165. $initDetailList = \app\common\model\TalentAllowancecontractDetail::where("mainId", $info["id"])->select()->toArray();
  166. $detaiPdList = []; //用于判定类型
  167. $detailMonthList = []; //用于计算月份
  168. foreach ($initDetailList as $detail) {
  169. $projectList = \app\common\model\TalentAllowanceProject::where("baseId", $detail["id"])->select()->toArray();
  170. $projectMap = [];
  171. foreach ($projectList as $project) {
  172. $projectMap[$project["project"]] = $project;
  173. }
  174. $detail["list"] = $projectList;
  175. $detail["projectMap"] = $projectMap;
  176. $detail["enterpriseName"] = $enterpriseMap[$detail["enterpriseId"]];
  177. /* * 筛选符合条件的人才标签 */
  178. $detaiPdList[] = $detail;
  179. $detailMonthList[] = $detail;
  180. }
  181. $monthMap = self::mergeMonth($detailMonthList);
  182. $monthAndDayMap = self::mergeMonthNeedDay($detailMonthList);
  183. $info["recommendAllowanceType"] = 1;
  184. $info["recommendAllowanceMsg"] = [];
  185. $projectList = \app\common\model\TalentAllowanceProject::where("mainId", $id)->select()->toArray();
  186. $set = self::valideAllowanceType($info, $projectList, $monthMap, $monthAndDayMap);
  187. $info["recommendAllowanceMsg"][] = "综合以上所有判断得到最终补贴类型为:";
  188. if ($info["recommendAllowanceType"] == 1) {
  189. $info["recommendAllowanceMsg"][] = "<span style='color:red;font-weight:bold;'>工作津贴</span>;";
  190. $info["recommendAllowanceMsg"][] = "可享受月份为:";
  191. $info["recommendAllowanceMsg"][] = "<span style='color:red;font-weight:bold;'>" . implode(",", $set) . "</span>;";
  192. }
  193. if ($info["recommendAllowanceType"] == 2)
  194. $info["recommendAllowanceMsg"][] = "<span style='color:red;font-weight:bold;'>一次性交通补贴</span>;";
  195. if ($info["recommendAllowanceType"] == 3)
  196. $info["recommendAllowanceMsg"][] = "<span style='color:red;font-weight:bold;'>不予兑现</span>;";
  197. usort($set, function($a, $b) {
  198. return (int) $a - (int) $b;
  199. });
  200. $info["recommendMonths"] = implode(",", $set);
  201. self::calculateAllowance($info, $set, $detailMonthList);
  202. return $info;
  203. }
  204. /**
  205. * 集成电路津补贴总校验
  206. * */
  207. private static function valideAllowanceType(&$info, $projectList, $monthMap, $monthAndDayMap) {
  208. $set = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"];
  209. /* * 2.判定合同月份、工作月份、五险和个税是否满足重叠6个月要求* */
  210. $contractSet = self::chkMonths($monthMap[AllowanceProjectEnum::PROJECT_CONTRACT], $info, "上年度合同月份", "①");
  211. $workdaySet = self::chkMonths($monthMap[AllowanceProjectEnum::PROJECT_ATTENDANCE], $info, "上年度工作月份", "②");
  212. $wageSet = self::chkMonths($monthMap[AllowanceProjectEnum::PROJECT_WAGES], $info, "上年度工资发放月份", "③");
  213. $pensionSet = self::chkMonths($monthMap[AllowanceProjectEnum::PROJECT_SB_PENSION], $info, "养老保险", "④");
  214. $unemploymentSet = self::chkMonths($monthMap[AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT], $info, "失业保险", "⑤");
  215. $medicaSet = self::chkMonths($monthMap[AllowanceProjectEnum::PROJECT_SB_MEDICA], $info, "医疗保险", "⑥");
  216. $taxSet = self::chkMonths($monthMap[AllowanceProjectEnum::PROJECT_TAX], $info, "个税", "⑦");
  217. $str = "工作合同月份、考勤月份、工资发放月份";
  218. if ($info["type"] == CommonConst::ENTERPRISE_WJ) {
  219. $str = "工作合同月份、考勤月份";
  220. $set = array_intersect($set, $contractSet);
  221. $set = array_intersect($set, $workdaySet);
  222. $checkSet = $set;
  223. $set = array_intersect($set, $pensionSet);
  224. $set = array_intersect($set, $taxSet);
  225. } else if ($info["type"] == CommonConst::ENTERPRISE_GJ) {
  226. $set = array_intersect($set, $contractSet);
  227. $set = array_intersect($set, $workdaySet);
  228. $set = array_intersect($set, $wageSet);
  229. $checkSet = $set;
  230. $set = array_intersect($set, $pensionSet);
  231. $set = array_intersect($set, $taxSet);
  232. } else {
  233. $set = array_intersect($set, $contractSet);
  234. $set = array_intersect($set, $workdaySet);
  235. $set = array_intersect($set, $wageSet);
  236. $checkSet = $set;
  237. $set = array_intersect($set, $pensionSet);
  238. $set = array_intersect($set, $unemploymentSet);
  239. $set = array_intersect($set, $medicaSet);
  240. $set = array_intersect($set, $taxSet);
  241. }
  242. usort($set, function($a, $b) {
  243. return (int) $a - (int) $b;
  244. });
  245. if ($info["recommendAllowanceType"] == 1) {
  246. if (count($checkSet) < 6) {
  247. //如果全部满足6个月,但是重叠时间不满足6个月,开始检测是否符合交通补贴要求
  248. $info["recommendAllowanceType"] = 2;
  249. $info["recommendAllowanceMsg"][] = "上年度{$str}交集月份不满足6个月(" . implode(",", $checkSet) . "),无法享受工作津贴(×)";
  250. } else {
  251. //检查连续缴纳月份是否满足6个月
  252. $count = 1;
  253. foreach ($checkSet as $s) {
  254. $currentVal = intval($s);
  255. $nextVal = $currentVal + 1;
  256. $nextKey = str_pad($nextVal, 2, "0", STR_PAD_LEFT);
  257. if (in_array($nextKey, $checkSet)) {
  258. $count++;
  259. if ($count >= 6) {
  260. break;
  261. }
  262. } else {
  263. $count = 1;
  264. }
  265. }
  266. if ($count < 6) {
  267. $info["recommendAllowanceType"] = 2;
  268. $info["recommendAllowanceMsg"][] = "上年度{$str}交集月份不满足连续缴纳6个月(" . implode(",", $checkSet) . "),无法享受工作津贴(×)";
  269. }
  270. }
  271. }
  272. if ($info["recommendAllowanceType"] == 2) {
  273. //判断境内工作时间是否大于30天
  274. if ($info["allowanceType"] == 2) {
  275. $totalDays = 0;
  276. $workmonths = $monthAndDayMap[AllowanceProjectEnum::PROJECT_ATTENDANCE];
  277. foreach ($workmonths as $days) {
  278. $totalDays += $days;
  279. }
  280. if ($totalDays < 30) {
  281. $info["recommendAllowanceType"] = 3;
  282. $info["recommendAllowanceMsg"][] = "全年在我市工作仅{$totalDays}天,未达到30天,无法享受一次性交通津贴(×)";
  283. }
  284. } else {
  285. if (count($workdaySet) == 0) {
  286. $info["recommendAllowanceType"] = 3;
  287. $info["recommendAllowanceMsg"][] = "全年在我市工作未达到30天,无法享受一次性交通津贴(×)";
  288. } else {
  289. $info["recommendAllowanceType"] = 2;
  290. $info["recommendAllowanceMsg"][] = "*首选为工作津贴,未录入实际工作天数,需要进一步核实提交的相关附件是否满足全年在我市工作30天";
  291. }
  292. }
  293. }
  294. return $set;
  295. }
  296. /**
  297. * 计算津补贴
  298. */
  299. private static function calculateAllowance(&$info, $retainMonths, $detailMonthList) {
  300. /* * 查询人才层次变更记录 */
  301. $arrangeList = TalentAllowanceArrange::where("mainId", $info["id"])->order("talentArrange")->select()->toArray();
  302. foreach ($arrangeList as &$arrange) {
  303. $where = [];
  304. $where[] = ["type", "=", $info["type"]];
  305. $where[] = ["allowanceType", "in", [1, 2]];
  306. $where[] = ["talentArrange", "=", $arrange["talentArrange"]];
  307. $list = AsModel::where($where)->field("money,allowanceType")->select()->toArray();
  308. foreach ($list as $amount) {
  309. if ($amount["allowanceType"] == 1) {
  310. $arrange["jobMoney"] = $amount["money"];
  311. }
  312. if ($amount["allowanceType"] == 2) {
  313. $arrange["jtMoney"] = $amount["money"];
  314. }
  315. }
  316. }unset($arrange);
  317. /* * * 容器 */
  318. $jobMoney = 0.00; //计算所得工作津贴
  319. $jtMoney = 0.00; //计算所得一次性交通补贴
  320. $recommendMonths = []; //推荐月份
  321. $talentArrange = null;
  322. /* * *********计算************* */
  323. $msgBulider = [];
  324. $identifyExpiredName = "人才证书有效期";
  325. if ($info["type"] == CommonConst::ENTERPRISE_JC) {
  326. $identifyExpiredName = "认定条件有效期";
  327. }
  328. switch ($info["recommendAllowanceType"]) {
  329. case 1:
  330. foreach ($arrangeList as &$arrange) {
  331. if (\StrUtil::isNotEmpAndNull($arrange["prepareMonths"])) {
  332. $levelList = array_filter(explode(",", $arrange["prepareMonths"]));
  333. $levelList = array_intersect($levelList, $retainMonths);
  334. $total = round($arrange["jobMoney"] * count($levelList), 2);
  335. $jobMoney += $total;
  336. $msgBulider[] = sprintf("%d(%s)x%s(第%d层次)", count($levelList), $levelList ? implode(",", $levelList) : "", $arrange["jobMoney"], $arrange["talentArrange"]);
  337. $recommendMonths = array_merge($recommendMonths, $levelList);
  338. usort($recommendMonths, function($a, $b) {
  339. return (int) $a - (int) $b;
  340. });
  341. $arrange["months"] = implode(",", $levelList);
  342. $arrange["count"] = count($levelList);
  343. $arrange["total"] = $total;
  344. } else {
  345. $msgBulider[] = sprintf("0()x%s(第%d层次)", $arrange["jobMoney"], $arrange["talentArrange"]);
  346. $arrange["count"] = 0;
  347. $arrange["total"] = 0.00;
  348. }
  349. }unset($arrange);
  350. $info["recommendMonths"] = implode(",", $recommendMonths);
  351. $info["recommendAllowanceMsg"][] = "通过与{$identifyExpiredName}取交集得到最终可享受月份:";
  352. $info["recommendAllowanceMsg"][] = "<span style='color:red;font-weight:bold;'>" . implode(",", $recommendMonths) . "</span>;";
  353. $info["recommendAllowanceMsg"][] = "经过计算:兑现月份" . count($recommendMonths) . "个月,人才津贴为<span style='color:red;font-weight:bold;'>" . $jobMoney . "</span>;";
  354. $info["recommendMoney"] = $jobMoney;
  355. $info["recommendMoneyDesc"] = implode("+", $msgBulider);
  356. $updAllowance["id"] = $info["id"];
  357. $updAllowance["virtualAmount"] = $jobMoney;
  358. TaModel::update($updAllowance);
  359. break;
  360. case 2:
  361. foreach ($arrangeList as $arrange) {
  362. $jtMoney = $arrange["jtMoney"];
  363. $talentArrange = $arrange["talentArrange"];
  364. }
  365. $info["recommendMoney"] = $jtMoney;
  366. $info["recommendMonths"] = "";
  367. $info["recommendMoneyDesc"] = "一次性交通补贴";
  368. $info["workAllowanceMoney"] = 0.00;
  369. $info["developAllowanceMoney"] = 0.00;
  370. $info["recommendTalentArrange"] = $talentArrange;
  371. $updAllowance["id"] = $info["id"];
  372. $updAllowance["virtualAmount"] = $jtMoney;
  373. TaModel::update($updAllowance);
  374. break;
  375. case 3:
  376. $info["recommendMoney"] = 0.00;
  377. $info["recommendMonths"] = "";
  378. $info["recommendMoneyDesc"] = "不予兑现";
  379. $info["workAllowanceMoney"] = 0.00;
  380. $info["developAllowanceMoney"] = 0.00;
  381. break;
  382. }
  383. return $arrangeList;
  384. }
  385. /**
  386. * 判定是否交足6个月(集成电路)
  387. * @param set
  388. * @param info
  389. * @param name
  390. */
  391. private static function chkMonths($set, &$info, $name, $sort) {
  392. if ($name == "上年度工作月份") {
  393. if ($info["allowanceType"] == 2) {
  394. $tmp = [];
  395. foreach ($set as $s) {
  396. $_s = explode("=", $s);
  397. $month = $_s[0];
  398. $days = $_s[1];
  399. if ($days > 0) {
  400. $tmp[] = $month;
  401. }
  402. }
  403. $set = $tmp;
  404. }
  405. }
  406. $preCheckProjects = ["①", "②", "③"];
  407. if ($info["type"] == CommonConst::ENTERPRISE_WJ) {
  408. $preCheckProjects = ["①", "②"];
  409. }
  410. if ($info["recommendAllowanceType"] == 1 && (!$set || count($set) < 6) && in_array($sort, $preCheckProjects)) {
  411. $info["recommendAllowanceType"] = 2;
  412. $info["recommendAllowanceMsg"][] = $sort . $name . "不足6个月,无法享受工作津贴(×)";
  413. }
  414. return $set;
  415. }
  416. //合并所有项目的月份
  417. private static function mergeMonth($detailList) {
  418. $contractList = [];
  419. $taxList = [];
  420. $wagesList = [];
  421. $pensionList = [];
  422. $unemploymentList = [];
  423. $medicaList = [];
  424. $attendanceList = [];
  425. $workdayList = [];
  426. foreach ($detailList as $detail) {
  427. $projectMap = $detail["projectMap"];
  428. if ($detail["months"]) {
  429. $tmp = array_filter(explode(",", $detail["months"]));
  430. $contractList = array_merge($contractList, $tmp);
  431. }
  432. if ($projectMap[AllowanceProjectEnum::PROJECT_TAX] && \StrUtil::isNotEmpAndNull($projectMap[AllowanceProjectEnum::PROJECT_TAX]["months"])) {
  433. $tmp = array_filter(explode(",", $projectMap[AllowanceProjectEnum::PROJECT_TAX]["months"]));
  434. $taxList = array_merge($taxList, $tmp);
  435. }
  436. if ($projectMap[AllowanceProjectEnum::PROJECT_WAGES] && \StrUtil::isNotEmpAndNull($projectMap[AllowanceProjectEnum::PROJECT_WAGES]["months"])) {
  437. $tmp = array_filter(explode(",", $projectMap[AllowanceProjectEnum::PROJECT_WAGES]["months"]));
  438. $wagesList = array_merge($wagesList, $tmp);
  439. }
  440. if ($projectMap[AllowanceProjectEnum::PROJECT_SB_PENSION] && \StrUtil::isNotEmpAndNull($projectMap[AllowanceProjectEnum::PROJECT_SB_PENSION]["months"])) {
  441. $tmp = array_filter(explode(",", $projectMap[AllowanceProjectEnum::PROJECT_SB_PENSION]["months"]));
  442. $pensionList = array_merge($pensionList, $tmp);
  443. }
  444. if ($projectMap[AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT] && \StrUtil::isNotEmpAndNull($projectMap[AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT]["months"])) {
  445. $tmp = array_filter(explode(",", $projectMap[AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT]["months"]));
  446. $unemploymentList = array_merge($unemploymentList, $tmp);
  447. }
  448. if ($projectMap[AllowanceProjectEnum::PROJECT_SB_MEDICA] && \StrUtil::isNotEmpAndNull($projectMap[AllowanceProjectEnum::PROJECT_SB_MEDICA]["months"])) {
  449. $tmp = array_filter(explode(",", $projectMap[AllowanceProjectEnum::PROJECT_SB_MEDICA]["months"]));
  450. $medicaList = array_merge($medicaList, $tmp);
  451. }
  452. if ($projectMap[AllowanceProjectEnum::PROJECT_ATTENDANCE] && \StrUtil::isNotEmpAndNull($projectMap[AllowanceProjectEnum::PROJECT_ATTENDANCE]["months"])) {
  453. $tmp = array_filter(explode(",", $projectMap[AllowanceProjectEnum::PROJECT_ATTENDANCE]["months"]));
  454. $attendanceList = array_merge($attendanceList, $tmp);
  455. }
  456. if ($projectMap[AllowanceProjectEnum::PROJECT_WORKDAY] && \StrUtil::isNotEmpAndNull($projectMap[AllowanceProjectEnum::PROJECT_WORKDAY]["months"])) {
  457. $tmp = array_filter(explode(",", $projectMap[AllowanceProjectEnum::PROJECT_WORKDAY]["months"]));
  458. $workdayList = array_merge($workdayList, $tmp);
  459. }
  460. }
  461. $map = [
  462. AllowanceProjectEnum::PROJECT_CONTRACT => $contractList,
  463. AllowanceProjectEnum::PROJECT_TAX => $taxList,
  464. AllowanceProjectEnum::PROJECT_WAGES => $wagesList,
  465. AllowanceProjectEnum::PROJECT_SB_PENSION => $pensionList,
  466. AllowanceProjectEnum::PROJECT_SB_UNEMPLOYMENT => $unemploymentList,
  467. AllowanceProjectEnum::PROJECT_SB_MEDICA => $medicaList,
  468. AllowanceProjectEnum::PROJECT_ATTENDANCE => $attendanceList,
  469. AllowanceProjectEnum::PROJECT_WORKDAY => $workdayList,
  470. ];
  471. return $map;
  472. }
  473. /**
  474. * 合并多个单位带有天数的项目的月份如考勤1月30天,
  475. * */
  476. private static function mergeMonthNeedDay($detailList) {
  477. $attendMap = [];
  478. $workDayMap = [];
  479. foreach ($detailList as $detail) {
  480. $attendMap = self::getMergeMonthNeedDayMap($detail["projectMap"][AllowanceProjectEnum::PROJECT_ATTENDANCE], $attendMap);
  481. $workDayMap = self::getMergeMonthNeedDayMap($detail["projectMap"][AllowanceProjectEnum::PROJECT_WORKDAY], $workDayMap);
  482. }
  483. $res = [
  484. AllowanceProjectEnum::PROJECT_ATTENDANCE => $attendMap,
  485. AllowanceProjectEnum::PROJECT_WORKDAY => $workDayMap
  486. ];
  487. return $res;
  488. }
  489. private static function getMergeMonthNeedDayMap($project, $map) {
  490. if (\StrUtil::isNotEmpAndNull($project["months"])) {
  491. $monthAndDayList = array_filter(explode(",", $project["months"]));
  492. for ($i = 0; $i < count($monthAndDayList); $i++) {
  493. $obj = explode("=", $monthAndDayList[$i]);
  494. $month = $obj[0];
  495. $day = is_numeric($obj[1]) ? $obj[1] : 0;
  496. $count = $map[$month];
  497. if ($count == 0) {
  498. $map[$month] = $day;
  499. } else {
  500. $map[$month] = $day + $count;
  501. }
  502. }
  503. }
  504. return $map;
  505. }
  506. }