TalentAllowanceApi.php 31 KB

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