| | |
| | | package cc.mrbird.febs; |
| | | |
| | | import cc.mrbird.febs.mall.service.IAgentService; |
| | | import cc.mrbird.febs.mall.service.IMemberProfitService; |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.common.enumerates.*; |
| | | 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.*; |
| | | import cc.mrbird.febs.mall.mapper.*; |
| | | import cc.mrbird.febs.mall.quartz.OrderSettlementJob; |
| | | import cc.mrbird.febs.mall.service.*; |
| | | import cc.mrbird.febs.mall.vo.ApiMallSubsidyAmountInfoVo; |
| | | 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.collection.CollUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSON; |
| | | import cn.hutool.json.JSONUtil; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | |
| | | @Test |
| | | public void dynamicProfit() { |
| | | memberProfitService.dynamicProfit(45L); |
| | | memberProfitService.dynamicProfit(21L); |
| | | } |
| | | @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; |
| | | |
| | | @Autowired |
| | | private MallMemberMapper memberMapper; |
| | | |
| | | @Autowired |
| | | private MallMoneyFlowMapper mallMoneyFlowMapper; |
| | | |
| | | @Autowired |
| | | private IApiMallMemberWalletService memberWalletService; |
| | | |
| | | @Autowired |
| | | private IMallMoneyFlowService mallMoneyFlowService; |
| | | |
| | | @Autowired |
| | | private AgentProducer agentProducer; |
| | | |
| | | @Autowired |
| | | private DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | |
| | | @Test |
| | | public void directorProfitTest() { |
| | | Long directRewardId = 587L; |
| | | MallOrderInfo orderInfo = mallOrderInfoMapper.selectById(directRewardId); |
| | | if(ObjectUtil.isEmpty(orderInfo)){ |
| | | return; |
| | | } |
| | | Integer status = orderInfo.getStatus(); |
| | | if(OrderStatusEnum.FINISH.getValue() != status){ |
| | | return; |
| | | } |
| | | //下单补贴金额 |
| | | BigDecimal subsidyAmount = orderInfo.getSubsidyAmount(); |
| | | //下单人 |
| | | Long memberId = orderInfo.getMemberId(); |
| | | MallMember mallMember = memberMapper.selectById(memberId); |
| | | /** |
| | | * 生成补贴的流水记录 |
| | | * 1、待生效 |
| | | * 2、返利对象,下单人 |
| | | * 3、金额,补贴金额 |
| | | */ |
| | | Long subsidyAmountFlowId = mallMoneyFlowService.addMoneyFlow( |
| | | mallMember.getId(), |
| | | orderInfo.getOrderNo(), |
| | | subsidyAmount.setScale(2, BigDecimal.ROUND_DOWN), |
| | | MallMoneyFlowTypeEnum.MARKET_SUBSIDIES.getCode(), |
| | | MallMoneyFlow.STATUS_SUCCESS, |
| | | MallMoneyFlow.IS_RETURN_Y, |
| | | mallMember.getId(), |
| | | FlowTypeEnum.BALANCE.getValue(), |
| | | MallMoneyFlowTypeEnum.MARKET_SUBSIDIES.getName() |
| | | ); |
| | | |
| | | memberWalletService.addBalance(subsidyAmount.setScale(2, BigDecimal.ROUND_DOWN),mallMember.getId()); |
| | | |
| | | /** |
| | | * 生成直推返利的流水记录 |
| | | * 1、待生效 |
| | | * 2、返利对象:下单人的直推上级 |
| | | * 3、金额:返利比例乘以补贴金额 |
| | | */ |
| | | /** |
| | | * 生成分享奖励的流水记录 |
| | | * 1、待生效 |
| | | * 2、返利对象:下单人的直推上级 10%,直推的直推 5% |
| | | * 3、金额:补贴金额乘以分享奖励的比例 |
| | | */ |
| | | //下单人的直推上级 |
| | | 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)){ |
| | | DataDictionaryCustom shareTwoDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.LEVEL_TWO.getType(), |
| | | DataDictionaryEnum.LEVEL_TWO.getCode() |
| | | ); |
| | | BigDecimal shareTwo = new BigDecimal(shareTwoDic.getValue()).multiply(new BigDecimal(0.01)).setScale(2,BigDecimal.ROUND_DOWN); |
| | | BigDecimal shareTwoAmount = subsidyAmount.multiply(shareTwo).setScale(4, BigDecimal.ROUND_DOWN); |
| | | Long shareTwoFlowId = mallMoneyFlowService.addMoneyFlow( |
| | | mallMember.getId(), |
| | | orderInfo.getOrderNo(), |
| | | shareTwoAmount, |
| | | MallMoneyFlowTypeEnum.SHARE_REWARD_TWO.getCode(), |
| | | MallMoneyFlow.STATUS_SUCCESS, |
| | | MallMoneyFlow.IS_RETURN_Y, |
| | | mallMemberTwo.getId(), |
| | | FlowTypeEnum.BALANCE.getValue(), |
| | | MallMoneyFlowTypeEnum.SHARE_REWARD_TWO.getName() |
| | | ); |
| | | memberWalletService.addBalance(shareTwoAmount,mallMemberTwo.getId()); |
| | | } |
| | | /** |
| | | * 团队管理补贴 |
| | | */ |
| | | //下单人所有的上级 |
| | | String referrerIds = mallMember.getReferrerIds(); |
| | | List<String> refererIdList = StrUtil.split(referrerIds, ",", -1, true, true); |
| | | //下单人所有符合条件的上级-邀请码 |
| | | ArrayList<String> refererIdListUp = new ArrayList<>(); |
| | | //初始级别即当前下单人的级别 |
| | | String levelStart = mallMember.getLevel(); |
| | | if(CollUtil.isNotEmpty(refererIdList)){ |
| | | for(String inviteId : refererIdList){ |
| | | MallMember mallMemberUp = memberMapper.selectInfoByInviteId(inviteId); |
| | | String levelUp = mallMemberUp.getLevel(); |
| | | //团队补贴从区代开始 |
| | | if(!MemberAgentLevelEnum.AGENT.getName().equals(levelUp)){ |
| | | //比较两个代理级别,同级别或者大于下单人的级别都保留 |
| | | int compareLevel = MemberAgentLevelEnum.AGENT_ONE.compareLevel(levelUp,levelStart); |
| | | if(0 < compareLevel){ |
| | | levelStart = levelUp; |
| | | refererIdListUp.add(inviteId); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if(CollUtil.isNotEmpty(refererIdListUp)){ |
| | | levelStart = mallMember.getLevel(); |
| | | for(String inviteId : refererIdList){ |
| | | MallMember mallMemberUp = memberMapper.selectInfoByInviteId(inviteId); |
| | | String levelUp = mallMemberUp.getLevel(); |
| | | //获取团队分享比例 |
| | | BigDecimal manageSubsidyPercent = getManageSubsidyPercent(levelStart, levelUp); |
| | | if(manageSubsidyPercent.compareTo(BigDecimal.ZERO) > 0){ |
| | | BigDecimal teamManageAmount = subsidyAmount.multiply(manageSubsidyPercent).setScale(4, BigDecimal.ROUND_DOWN); |
| | | //生成团队分享流水 |
| | | Long teamManageFlowId = mallMoneyFlowService.addMoneyFlow( |
| | | mallMember.getId(), |
| | | orderInfo.getOrderNo(), |
| | | teamManageAmount, |
| | | MallMoneyFlowTypeEnum.TEAM_REWARD.getCode(), |
| | | MallMoneyFlow.STATUS_SUCCESS, |
| | | MallMoneyFlow.IS_RETURN_Y, |
| | | mallMemberUp.getId(), |
| | | FlowTypeEnum.BALANCE.getValue(), |
| | | MallMoneyFlowTypeEnum.TEAM_REWARD.getName() |
| | | ); |
| | | |
| | | memberWalletService.addBalance(teamManageAmount,mallMemberUp.getId()); |
| | | } |
| | | levelStart = levelUp; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据传入的两个级别,比较之后获取对应的团队管理奖励比例 |
| | | * @param levelStart |
| | | * @param levelUp |
| | | * @return |
| | | */ |
| | | private BigDecimal getManageSubsidyPercent(String levelStart,String levelUp){ |
| | | BigDecimal manageSubsidyPercent = BigDecimal.ZERO; |
| | | String agentCodeStart = MemberAgentLevelEnum.AGENT_ONE.getCodeByName(levelStart); |
| | | String agentCodeUp = MemberAgentLevelEnum.AGENT_ONE.getCodeByName(levelUp); |
| | | int compareLevel = MemberAgentLevelEnum.AGENT_ONE.compareLevel(levelUp, levelStart); |
| | | //如果是平级 |
| | | if(compareLevel == 2){ |
| | | manageSubsidyPercent = getDicSubsidyPercent(agentCodeStart); |
| | | } |
| | | //如果不是平级 |
| | | if(compareLevel == 1){ |
| | | //1、初始级别不能是会员 |
| | | //2、当前级别的上一个级别是否是levelStart, |
| | | // 满足,需要减去levelStart的团队管理奖励 |
| | | String minLevel = MemberAgentLevelEnum.AGENT_ONE.minLevel(agentCodeUp); |
| | | if(levelStart.equals(minLevel) |
| | | && !MemberAgentLevelEnum.AGENT.getName().equals(levelStart)){ |
| | | BigDecimal dicManageSubsidyPercentUp = getDicManageSubsidyPercent(agentCodeUp); |
| | | BigDecimal dicManageSubsidyPercentStart = getDicManageSubsidyPercent(agentCodeStart); |
| | | manageSubsidyPercent = dicManageSubsidyPercentUp.subtract(dicManageSubsidyPercentStart); |
| | | }else{ |
| | | manageSubsidyPercent = getDicManageSubsidyPercent(agentCodeUp); |
| | | } |
| | | } |
| | | return manageSubsidyPercent; |
| | | } |
| | | |
| | | /** |
| | | * 获取对应的团队管理奖励比例 |
| | | * @param agentCode |
| | | * @return |
| | | */ |
| | | private BigDecimal getDicManageSubsidyPercent(String agentCode){ |
| | | BigDecimal manageSubsidyPercent = BigDecimal.ZERO; |
| | | DataDictionaryCustom agentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.AGENT_ONE.getType(), |
| | | agentCode |
| | | ); |
| | | cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(agentDic.getValue()); |
| | | String manageSubsidyPercentStr = jsonObject.get("manageSubsidyPercent").toString(); |
| | | manageSubsidyPercent = new BigDecimal(manageSubsidyPercentStr) |
| | | .multiply(new BigDecimal(0.01)) |
| | | .setScale(2,BigDecimal.ROUND_DOWN); |
| | | return manageSubsidyPercent; |
| | | } |
| | | |
| | | /** |
| | | * 获取对应的平级团队管理奖励比例 |
| | | * @param agentCode |
| | | * @return |
| | | */ |
| | | private BigDecimal getDicSubsidyPercent(String agentCode){ |
| | | BigDecimal subsidyPercent = BigDecimal.ZERO; |
| | | DataDictionaryCustom agentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | DataDictionaryEnum.AGENT_ONE.getType(), |
| | | agentCode |
| | | ); |
| | | cn.hutool.json.JSONObject jsonObject = JSONUtil.parseObj(agentDic.getValue()); |
| | | String subsidyPercentStr = jsonObject.get("manageSubsidyPercent").toString(); |
| | | subsidyPercent = new BigDecimal(subsidyPercentStr) |
| | | .multiply(new BigDecimal(0.01)) |
| | | .setScale(2,BigDecimal.ROUND_DOWN); |
| | | return subsidyPercent; |
| | | } |
| | | |
| | | @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() { |
| | | // Map<String, Integer> map = new HashMap<>(); |
| | | // BigDecimal amount = new BigDecimal("100"); |
| | | // map.put("amount", 1); |
| | | // changeAmount(map); |
| | | // System.out.println(map.get("amount")); |
| | | // } |
| | | // |
| | | // public void changeAmount(Map<String, Integer> amount) { |
| | | // amount.put("amount", 2); |
| | | // } |
| | | // |
| | | // @Test |
| | | // public void scorePool(){ |
| | | // memberProfitService.scorePool(); |
| | | // } |
| | | // |
| | | // @Test |
| | | // public void staticProfit(){ |
| | | // memberProfitService.staticProfit(null); |
| | | // } |
| | | // |
| | | // @Autowired |
| | | // private OrderSettlementJob orderSettlementJob; |
| | | // |
| | | // @Test |
| | | // public void orderSettlementJobTest() { |
| | | //// orderSettlementJob.normalGoodsSettlementJob(); |
| | | // |
| | | // mallAchieveService.add(83L); |
| | | // } |
| | | // |
| | | // |
| | | // @Autowired |
| | | // private UnipayService unipayService; |
| | | // @Test |
| | | // public void unipay(){ |
| | | // UnipayDto unipayDto = new UnipayDto(); |
| | | // unipayDto.setAmount(new BigDecimal("0.01")); |
| | | // unipayDto.setFrpCode("ALIPAY_H5"); |
| | | // unipayDto.setTradeMerchantNo("777180800385820"); |
| | | //// unipayDto.setFrpCode("WEIXIN_APP3"); |
| | | // unipayDto.setOrderNo("2022082316415386395"); |
| | | // unipayDto.setProductName("洗护套装"); |
| | | // unipayService.unipay(unipayDto); |
| | | // } |
| | | // @Test |
| | | // public void getAgreeMentPaySms(){ |
| | | // AgreeMentPaySmsDto agreeMentPaySmsDto = new AgreeMentPaySmsDto(); |
| | | // agreeMentPaySmsDto.setOrderNo("2022082617305930328"); |
| | | // |
| | | // BigDecimal value = new BigDecimal("0.1").setScale(2, BigDecimal.ROUND_DOWN); |
| | | // DecimalFormat decimalFormat = new DecimalFormat("0.00#"); |
| | | // String strVal = decimalFormat.format(value); |
| | | // agreeMentPaySmsDto.setOrderAmount(new BigDecimal(strVal)); |
| | | // agreeMentPaySmsDto.setName("肖永"); |
| | | // agreeMentPaySmsDto.setCreatedTime(DateUtil.now()); |
| | | // agreeMentPaySmsDto.setIdType("1"); |
| | | // agreeMentPaySmsDto.setIdCardNum("430321199310113713"); |
| | | // agreeMentPaySmsDto.setBankNo("6222031901002389639"); |
| | | // agreeMentPaySmsDto.setPhone("15274802129"); |
| | | // String agreeMentPaySms = unipayService.getAgreeMentPaySms(agreeMentPaySmsDto); |
| | | // if("JS000000".equals(agreeMentPaySms)){ |
| | | // System.out.println("获取成功"); |
| | | // }else{ |
| | | // System.out.println(agreeMentPaySms); |
| | | // } |
| | | // } |
| | | // |
| | | // @Test |
| | | // public void agreementSign(){ |
| | | // AgreementSignDto agreementSignDto = new AgreementSignDto(); |
| | | // agreementSignDto.setOrderNo("2022082614465345250"); |
| | | // agreementSignDto.setSmsCode("841243"); |
| | | // unipayService.agreementSign(agreementSignDto); |
| | | // } |
| | | // |
| | | // @Test |
| | | // public void agreementPay(){ |
| | | // AgreementPayDto agreementPayDto = new AgreementPayDto(); |
| | | // agreementPayDto.setOrderNo("2022082614465345250"); |
| | | // |
| | | // BigDecimal value = new BigDecimal("0.1").setScale(2, BigDecimal.ROUND_DOWN); |
| | | // DecimalFormat decimalFormat = new DecimalFormat("0.00#"); |
| | | // String strVal = decimalFormat.format(value); |
| | | // agreementPayDto.setOrderAmount(new BigDecimal(strVal)); |
| | | // agreementPayDto.setOrderTime(DateUtil.now()); |
| | | // agreementPayDto.setOrderDesc("测试"); |
| | | // agreementPayDto.setBankNo("6222031901002389639"); |
| | | // unipayService.agreementPay(agreementPayDto); |
| | | // } |
| | | // |
| | | // @Test |
| | | // public void singlePay(){ |
| | | // /** |
| | | // * 调用汇聚代付 |
| | | // */ |
| | | // String orderNo = MallUtils.getOrderNum("W"); |
| | | // SinglePayDto singlePayDto = new SinglePayDto(); |
| | | // singlePayDto.setMerchantOrderNo(orderNo); |
| | | // singlePayDto.setReceiverAccountNoEncBankNo("6222031903210023839639"); |
| | | // singlePayDto.setReceiverAccountNoEncName("肖永"); |
| | | // singlePayDto.setReceiverAccountType("201"); |
| | | // BigDecimal paidAmount = new BigDecimal(1.00); |
| | | // singlePayDto.setPaidAmount(paidAmount); |
| | | // singlePayDto.setCurrency("201"); |
| | | // singlePayDto.setIsChecked("202"); |
| | | // singlePayDto.setPaidDesc("用户提现"); |
| | | // singlePayDto.setPaidUse("202"); |
| | | // String singlePayRep = unipayService.singlePay(singlePayDto); |
| | | // |
| | | // System.out.println(singlePayRep); |
| | | // } |
| | | } |