From 2abd05a4ab94edfacb73edc59866a9057be6fca8 Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Thu, 22 Dec 2022 14:42:18 +0800 Subject: [PATCH] 20221221 --- src/main/java/cc/mrbird/febs/mall/vo/OrderListVo.java | 3 src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java | 82 ++++++++------- src/test/java/cc/mrbird/febs/ProfitTest.java | 159 +++++++++++++++++++++---------- src/main/resources/mapper/modules/MallMoneyFlowMapper.xml | 2 src/main/resources/mapper/modules/MallGoodsSkuMapper.xml | 6 + 5 files changed, 158 insertions(+), 94 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java index e5448c6..33b2ed4 100644 --- a/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java +++ b/src/main/java/cc/mrbird/febs/mall/service/impl/AgentServiceImpl.java @@ -203,51 +203,55 @@ * 2、返利对象:下单人的直推上级 * 3、金额:返利比例乘以补贴金额 */ - //下单人的直推上级 - MallMember mallMemberOne = memberMapper.selectInfoByInviteId(mallMember.getReferrerId()); - DataDictionaryCustom rewardPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( - DataDictionaryEnum.REWARD_PERCENT.getType(), - DataDictionaryEnum.REWARD_PERCENT.getCode() - ); - BigDecimal rewardPercent = new BigDecimal(rewardPercentDic.getValue()).multiply(new BigDecimal(0.01)).setScale(2,BigDecimal.ROUND_DOWN); - BigDecimal directRewardAmount = subsidyAmount.multiply(rewardPercent).setScale(2, BigDecimal.ROUND_DOWN); - - Long marketSubsidyFlowId = mallMoneyFlowService.addMoneyFlow( - mallMember.getId(), - orderInfo.getOrderNo(), - directRewardAmount, - MallMoneyFlowTypeEnum.DIRECT_REWARD.getCode(), - MallMoneyFlow.STATUS_SUCCESS, - MallMoneyFlow.IS_RETURN_Y, - mallMemberOne.getId(), - FlowTypeEnum.BALANCE.getValue(), - MallMoneyFlowTypeEnum.DIRECT_REWARD.getName() - ); - memberWalletService.addBalance(directRewardAmount,mallMemberOne.getId()); /** * 生成分享奖励的流水记录 * 1、待生效 * 2、返利对象:下单人的直推上级 10%,直推的直推 5% * 3、金额:补贴金额乘以分享奖励的比例 */ - DataDictionaryCustom shareOneDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( - DataDictionaryEnum.LEVEL_ONE.getType(), - DataDictionaryEnum.LEVEL_ONE.getCode() - ); - BigDecimal shareOne = new BigDecimal(shareOneDic.getValue()).multiply(new BigDecimal(0.01)).setScale(2,BigDecimal.ROUND_DOWN); - BigDecimal shareOneAmount = subsidyAmount.multiply(shareOne).setScale(2, BigDecimal.ROUND_DOWN); - Long ShareOneFlowId = mallMoneyFlowService.addMoneyFlow( - mallMember.getId(), - orderInfo.getOrderNo(), - shareOneAmount, - MallMoneyFlowTypeEnum.SHARE_REWARD_ONE.getCode(), - MallMoneyFlow.STATUS_SUCCESS, - MallMoneyFlow.IS_RETURN_Y, - mallMemberOne.getId(), - FlowTypeEnum.BALANCE.getValue(), - MallMoneyFlowTypeEnum.SHARE_REWARD_ONE.getName() - ); - memberWalletService.addBalance(shareOneAmount,mallMemberOne.getId()); + //下单人的直推上级 + MallMember mallMemberOne = memberMapper.selectInfoByInviteId(mallMember.getReferrerId()); + //生成直推返利的流水记录 + if(ObjectUtil.isNotEmpty(mallMemberOne)){ + DataDictionaryCustom rewardPercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( + DataDictionaryEnum.REWARD_PERCENT.getType(), + DataDictionaryEnum.REWARD_PERCENT.getCode() + ); + BigDecimal rewardPercent = new BigDecimal(rewardPercentDic.getValue()).multiply(new BigDecimal(0.01)).setScale(2,BigDecimal.ROUND_DOWN); + BigDecimal directRewardAmount = subsidyAmount.multiply(rewardPercent).setScale(2, BigDecimal.ROUND_DOWN); + + Long marketSubsidyFlowId = mallMoneyFlowService.addMoneyFlow( + mallMember.getId(), + orderInfo.getOrderNo(), + directRewardAmount, + MallMoneyFlowTypeEnum.DIRECT_REWARD.getCode(), + MallMoneyFlow.STATUS_SUCCESS, + MallMoneyFlow.IS_RETURN_Y, + mallMemberOne.getId(), + FlowTypeEnum.BALANCE.getValue(), + MallMoneyFlowTypeEnum.DIRECT_REWARD.getName() + ); + memberWalletService.addBalance(directRewardAmount,mallMemberOne.getId()); + DataDictionaryCustom shareOneDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( + DataDictionaryEnum.LEVEL_ONE.getType(), + DataDictionaryEnum.LEVEL_ONE.getCode() + ); + //生成分享奖励的流水记录 + BigDecimal shareOne = new BigDecimal(shareOneDic.getValue()).multiply(new BigDecimal(0.01)).setScale(2,BigDecimal.ROUND_DOWN); + BigDecimal shareOneAmount = subsidyAmount.multiply(shareOne).setScale(2, BigDecimal.ROUND_DOWN); + Long ShareOneFlowId = mallMoneyFlowService.addMoneyFlow( + mallMember.getId(), + orderInfo.getOrderNo(), + shareOneAmount, + MallMoneyFlowTypeEnum.SHARE_REWARD_ONE.getCode(), + MallMoneyFlow.STATUS_SUCCESS, + MallMoneyFlow.IS_RETURN_Y, + mallMemberOne.getId(), + FlowTypeEnum.BALANCE.getValue(), + MallMoneyFlowTypeEnum.SHARE_REWARD_ONE.getName() + ); + memberWalletService.addBalance(shareOneAmount,mallMemberOne.getId()); + } //下单人的直推上级的直推 MallMember mallMemberTwo = memberMapper.selectInfoByInviteId(mallMemberOne.getReferrerId()); if(ObjectUtil.isNotEmpty(mallMemberTwo)){ diff --git a/src/main/java/cc/mrbird/febs/mall/vo/OrderListVo.java b/src/main/java/cc/mrbird/febs/mall/vo/OrderListVo.java index 4ec2948..40eafe2 100644 --- a/src/main/java/cc/mrbird/febs/mall/vo/OrderListVo.java +++ b/src/main/java/cc/mrbird/febs/mall/vo/OrderListVo.java @@ -45,4 +45,7 @@ @ApiModelProperty(value = "评价状态 1:待评价 2:已评价") private Integer commentState; + + @ApiModelProperty(value = "补贴金额") + private Integer subsidyAmount; } diff --git a/src/main/resources/mapper/modules/MallGoodsSkuMapper.xml b/src/main/resources/mapper/modules/MallGoodsSkuMapper.xml index 99771dc..a1e5746 100644 --- a/src/main/resources/mapper/modules/MallGoodsSkuMapper.xml +++ b/src/main/resources/mapper/modules/MallGoodsSkuMapper.xml @@ -26,7 +26,11 @@ </select> <select id="selectSkuByGoodsId" resultType="cc.mrbird.febs.mall.entity.MallGoodsSku"> - select a.*, b.name styleName from mall_goods_sku a + select + a.*, + b.name styleName, + b.name goodsName + from mall_goods_sku a inner join mall_goods_style b on a.style_id=b.id where a.goods_id=#{id} </select> diff --git a/src/main/resources/mapper/modules/MallMoneyFlowMapper.xml b/src/main/resources/mapper/modules/MallMoneyFlowMapper.xml index e53d53f..368a4e2 100644 --- a/src/main/resources/mapper/modules/MallMoneyFlowMapper.xml +++ b/src/main/resources/mapper/modules/MallMoneyFlowMapper.xml @@ -138,7 +138,7 @@ <select id="selectOneByMemberIdAndOrderNoAndTypeAndStatusAndIsReturn" resultType="cc.mrbird.febs.mall.entity.MallMoneyFlow"> select a.* from mall_money_flow a - where a.memberId = #{memberId} + where a.member_id = #{memberId} and a.order_no = #{orderNo} and a.type = #{type} and a.status = #{status} diff --git a/src/test/java/cc/mrbird/febs/ProfitTest.java b/src/test/java/cc/mrbird/febs/ProfitTest.java index 6d37c66..fb10558 100644 --- a/src/test/java/cc/mrbird/febs/ProfitTest.java +++ b/src/test/java/cc/mrbird/febs/ProfitTest.java @@ -1,18 +1,31 @@ package cc.mrbird.febs; import cc.mrbird.febs.common.entity.FebsResponse; +import cc.mrbird.febs.common.enumerates.MallMoneyFlowTypeEnum; +import cc.mrbird.febs.common.enumerates.OrderStatusEnum; +import cc.mrbird.febs.common.exception.FebsException; +import cc.mrbird.febs.common.utils.AppContants; +import cc.mrbird.febs.common.utils.LoginUserUtil; import cc.mrbird.febs.common.utils.MallUtils; +import cc.mrbird.febs.mall.entity.MallMember; +import cc.mrbird.febs.mall.entity.MallMoneyFlow; +import cc.mrbird.febs.mall.entity.MallOrderInfo; import cc.mrbird.febs.mall.entity.MallOrderItem; +import cc.mrbird.febs.mall.mapper.MallMemberMapper; +import cc.mrbird.febs.mall.mapper.MallMoneyFlowMapper; import cc.mrbird.febs.mall.mapper.MallOrderInfoMapper; import cc.mrbird.febs.mall.mapper.MallOrderItemMapper; import cc.mrbird.febs.mall.quartz.OrderSettlementJob; import cc.mrbird.febs.mall.service.IAgentService; +import cc.mrbird.febs.mall.service.IApiMallMemberWalletService; import cc.mrbird.febs.mall.service.IMallAchieveService; import cc.mrbird.febs.mall.service.IMemberProfitService; import cc.mrbird.febs.pay.model.*; import cc.mrbird.febs.pay.service.UnipayService; import cc.mrbird.febs.rabbit.consumer.AgentConsumer; +import cc.mrbird.febs.rabbit.producter.AgentProducer; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -31,61 +44,101 @@ @SpringBootTest public class ProfitTest { -// @Autowired -// private AgentConsumer agentConsumer; -// -// @Autowired -// private IAgentService agentService; -// -// @Autowired -// private IMemberProfitService memberProfitService; -// + @Autowired + private AgentConsumer agentConsumer; + + @Autowired + private IAgentService agentService; + + @Autowired + private IMemberProfitService memberProfitService; + + @Test + public void dynamicProfit() { + memberProfitService.dynamicProfit(21L); + } + @Test + public void agentProfit() { + memberProfitService.agentProfit(null); + } + + // @Test -// public void dynamicProfit() { -// memberProfitService.dynamicProfit(21L); +// public void staticProfit() { +// memberProfitService.staticProfit(new Date()); // } -// @Test -// public void agentProfit() { -// memberProfitService.agentProfit(null); -// } -// -// -//// @Test -//// public void staticProfit() { -//// memberProfitService.staticProfit(new Date()); -//// } -// -// @Test -// public void thankfulProfit() { -// memberProfitService.thankfulProfit(new Date()); -// } -// -// @Test -// public void rankProfit() { -// memberProfitService.rankProfit(); -// } -// -// @Autowired -// private MallOrderInfoMapper mallOrderInfoMapper; -// -// @Test -// public void directorProfitTest() { -// memberProfitService.storeAndDirectorProfit(new Date()); -// } -// -// @Autowired -// private MallOrderItemMapper mallOrderItemMapper; -// -// @Autowired -// private IMallAchieveService mallAchieveService; -// -// @Test -// public void achieveTest() { -// List<MallOrderItem> items = mallOrderItemMapper.selectList(null); -// for (MallOrderItem item : items) { -// mallAchieveService.add(item.getId()); -// } -// } + + @Test + public void thankfulProfit() { + memberProfitService.thankfulProfit(new Date()); + } + + @Test + public void rankProfit() { + memberProfitService.rankProfit(); + } + + @Autowired + private MallOrderInfoMapper mallOrderInfoMapper; + + @Autowired + private MallMemberMapper mallMemberMapper; + + @Autowired + private MallMoneyFlowMapper mallMoneyFlowMapper; + + @Autowired + private IApiMallMemberWalletService memberWalletService; + + @Autowired + private AgentProducer agentProducer; + + @Test + public void directorProfitTest() { + MallMember member = mallMemberMapper.selectById(1L); + MallOrderInfo orderInfo = mallOrderInfoMapper.selectOrderByMemberIdAndId(member.getId(), 577L); + if (orderInfo == null || AppContants.DEL_FLAG_Y == orderInfo.getDelFlag()) { + throw new FebsException("订单不存在"); + } + + if (orderInfo.getStatus() != OrderStatusEnum.WAIT_FINISH.getValue()) { + throw new FebsException("该状态不能确认收货"); + } + + orderInfo.setStatus(OrderStatusEnum.FINISH.getValue()); + orderInfo.setReceivingTime(new Date()); + mallOrderInfoMapper.updateById(orderInfo); + /** + * 通过支付流水记录,返回下单金额 + */ + MallMoneyFlow payFlow = mallMoneyFlowMapper.selectOneByMemberIdAndOrderNoAndTypeAndStatusAndIsReturn( + member.getId(), + orderInfo.getOrderNo(), + MallMoneyFlowTypeEnum.PAY.getCode(), + MallMoneyFlow.STATUS_SUCCESS, + MallMoneyFlow.IS_RETURN_N); + if(ObjectUtil.isNotEmpty(payFlow)){ + memberWalletService.addBalance(payFlow.getAmount().negate(),payFlow.getRtMemberId()); + payFlow.setIsReturn(MallMoneyFlow.IS_RETURN_Y); + mallMoneyFlowMapper.updateById(payFlow); + } + //产生补贴流水记录 + agentProducer.sendDirectRewardMsg(orderInfo.getId()); + } + + @Autowired + private MallOrderItemMapper mallOrderItemMapper; + + @Autowired + private IMallAchieveService mallAchieveService; + + @Test + public void achieveTest() { + List<MallOrderItem> items = mallOrderItemMapper.selectList(null); + for (MallOrderItem item : items) { + mallAchieveService.add(item.getId()); + } + } // // @Test // public void paramTest() { -- Gitblit v1.9.1