From 4f65db3a1766fea81630d31a648c1c14b2d21c24 Mon Sep 17 00:00:00 2001 From: Hentua <wangdoubleone@gmail.com> Date: Sun, 23 Apr 2023 17:51:23 +0800 Subject: [PATCH] fix --- src/main/java/cc/mrbird/febs/mall/mapper/MallMemberMapper.java | 2 + src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java | 6 ++ src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java | 37 +++++++++++++++++- src/main/java/cc/mrbird/febs/mall/quartz/ProfitJob.java | 12 +++++- src/main/resources/mapper/modules/MallMemberMapper.xml | 11 +++++ src/main/java/cc/mrbird/febs/mall/service/IMemberProfitService.java | 2 6 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java b/src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java index 4eb99d8..3e59707 100644 --- a/src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java +++ b/src/main/java/cc/mrbird/febs/common/enumerates/DataDictionaryEnum.java @@ -86,7 +86,11 @@ INTERNET_LEVEL_BONUS("INTERNET_LEVEL_BONUS", ""), ALL_INTERNET_BONUS("MEIYE_BONUS_TYPE", "ALL_BONUS"), - ALL_INTERNET_BONUS_RELEASE("MEIYE_BONUS_TYPE", "BONUS_RELEASE"); + ALL_INTERNET_BONUS_RELEASE("MEIYE_BONUS_TYPE", "BONUS_RELEASE"), + + AGENT_ALL_BONUS("MEIYE_BONUS_TYPE", "AGENT_ALL_BONUS"), + PARNER_ALL_BONUS("MEIYE_BONUS_TYPE", "PARNER_ALL_BONUS"), + AGENT_BONUS_RELEASE("MEIYE_BONUS_TYPE", "AGENT_BONUS_RELEASE"); private String type; private String code; diff --git a/src/main/java/cc/mrbird/febs/mall/mapper/MallMemberMapper.java b/src/main/java/cc/mrbird/febs/mall/mapper/MallMemberMapper.java index f0c7f9f..71b3e40 100644 --- a/src/main/java/cc/mrbird/febs/mall/mapper/MallMemberMapper.java +++ b/src/main/java/cc/mrbird/febs/mall/mapper/MallMemberMapper.java @@ -105,4 +105,6 @@ List<MallMember> selectParentMemberList(@Param("list") List<String> inviteIds, @Param("refererId") String refererId, @Param("limit") Integer limit); List<MallMember> selectMemberAfterLevelList(String level); + + List<MallMember> selectAgentOrPartnetMemberList(@Param("memberLevel") Integer memberLevel); } diff --git a/src/main/java/cc/mrbird/febs/mall/quartz/ProfitJob.java b/src/main/java/cc/mrbird/febs/mall/quartz/ProfitJob.java index e56cc42..a6e2bf9 100644 --- a/src/main/java/cc/mrbird/febs/mall/quartz/ProfitJob.java +++ b/src/main/java/cc/mrbird/febs/mall/quartz/ProfitJob.java @@ -1,5 +1,6 @@ package cc.mrbird.febs.mall.quartz; +import cc.mrbird.febs.common.enumerates.AccountLevelEnums; import cc.mrbird.febs.common.enumerates.AgentLevelEnum; import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum; import cc.mrbird.febs.common.utils.MallUtils; @@ -41,8 +42,15 @@ * 代理分红 */ @Scheduled(cron = "0 30 0 * * ?") - public void profitJob() { - memberProfitService.agentProfit(); + public void agentProfitJob() { + log.info("运行代理分红程序"); + memberProfitService.agentProfit(AccountLevelEnums.VVIP.getLevel()); + } + + @Scheduled(cron = "5 30 0 * * ?") + public void partnerProfitJob() { + log.info("运行股东分红程序"); + memberProfitService.agentProfit(AccountLevelEnums.VVVIP.getLevel()); } /** diff --git a/src/main/java/cc/mrbird/febs/mall/service/IMemberProfitService.java b/src/main/java/cc/mrbird/febs/mall/service/IMemberProfitService.java index bb312ee..d2dbc4c 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/IMemberProfitService.java +++ b/src/main/java/cc/mrbird/febs/mall/service/IMemberProfitService.java @@ -15,7 +15,7 @@ /** * 代理分红 */ - void agentProfit(); + void agentProfit(Integer type); void allInternetProfit(); } diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java index f3b48a0..9290189 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java @@ -287,8 +287,39 @@ @Override @Transactional(rollbackFor = Exception.class) - public void agentProfit() { + public void agentProfit(Integer type) { log.info("#####==代理分红==start==#####"); + if (type == null) { + return; + } + + MallSystemSetting systemSetting = mallSystemSettingMapper.selectById(1L); + if (systemSetting == null) { + log.info("没有系统配置"); + return; + } + + BigDecimal hundred = BigDecimal.valueOf(100); + DataDictionaryCustom dic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(DataDictionaryEnum.AGENT_BONUS_RELEASE.getType(), DataDictionaryEnum.AGENT_BONUS_RELEASE.getCode()); + if (dic == null || StrUtil.isBlank(dic.getValue()) || Integer.parseInt(dic.getValue()) == 0) { + log.info("不进行全网分红"); + return; + } + + // 全网分红 + BigDecimal waitToBonus = systemSetting.getAllBonus().multiply(new BigDecimal(dic.getValue()).divide(hundred, 2, RoundingMode.HALF_UP)); + + // 代理 + List<MallMember> mallMembers = mallMemberMapper.selectAgentOrPartnetMemberList(type); + if (CollUtil.isEmpty(mallMembers) || waitToBonus.compareTo(BigDecimal.ZERO) < 1) { + log.info("待分红金额不足或会员不足"); + return; + } + + BigDecimal perBonus = waitToBonus.divide(new BigDecimal(mallMembers.size()), 2, RoundingMode.HALF_UP); + mallMembers.forEach(item -> { + changeScoreAndCommission(item.getId(), perBonus, type.equals(AccountLevelEnums.VVIP.getLevel()) ? MoneyFlowTypeEnum.AGENT_BONUS.getValue() : MoneyFlowTypeEnum.PARTNER_BONUS.getValue(), null); + }); log.info("#####==代理分红==end==#####"); } @@ -363,14 +394,14 @@ for (Map.Entry<String, List<MallMember>> entry : levelMemberMap.entrySet()) { BigDecimal levelBonus = levelBonusMap.get(entry.getKey()); List<MallMember> memberList = entry.getValue(); - + if (CollUtil.isEmpty(memberList) || levelBonus.compareTo(BigDecimal.ZERO) < 1) { continue; } BigDecimal perBonus = levelBonus.divide(BigDecimal.valueOf(memberList.size()), 2, RoundingMode.HALF_UP); memberList.forEach(item -> { - changeScoreAndCommission(item.getId(), perBonus, 2, null); + changeScoreAndCommission(item.getId(), perBonus, MoneyFlowTypeEnum.ALL_INTERNET_BONUS.getValue(), null); }); } diff --git a/src/main/resources/mapper/modules/MallMemberMapper.xml b/src/main/resources/mapper/modules/MallMemberMapper.xml index 6e75bff..e068693 100644 --- a/src/main/resources/mapper/modules/MallMemberMapper.xml +++ b/src/main/resources/mapper/modules/MallMemberMapper.xml @@ -480,4 +480,15 @@ GROUP BY m.id </select> + + <select id="selectAgentOrPartnetMemberList" resultType="cc.mrbird.febs.mall.entity.MallMember"> + select * from mall_membebr a + where 1=1 + <if test="level == 2"> + a.account_level in (2, 3) + </if> + <if test="level == 3"> + a.account_level = 3 + </if> + </select> </mapper> \ No newline at end of file -- Gitblit v1.9.1