| | |
| | | package cc.mrbird.febs; |
| | | |
| | | import cc.mrbird.febs.common.enumerates.AgentLevelEnum; |
| | | import cc.mrbird.febs.common.enumerates.DataDictionaryEnum; |
| | | import cc.mrbird.febs.common.exception.FebsException; |
| | | import cc.mrbird.febs.common.utils.LoginUserUtil; |
| | | import cc.mrbird.febs.mall.dto.AgentLevelUpdateDto; |
| | | import cc.mrbird.febs.mall.dto.ApiMallActWinDetailsDto; |
| | | import cc.mrbird.febs.common.enumerates.FlowTypeEnum; |
| | | import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum; |
| | | import cc.mrbird.febs.mall.entity.*; |
| | | import cc.mrbird.febs.mall.mapper.*; |
| | | import cc.mrbird.febs.mall.quartz.ProfitJob; |
| | | import cc.mrbird.febs.mall.service.IAgentService; |
| | | import cc.mrbird.febs.mall.vo.ApiMallActWinDetailsVo; |
| | | import cc.mrbird.febs.mall.vo.ApiMallAwardDetailsVo; |
| | | import cc.mrbird.febs.rabbit.consumer.AgentConsumer; |
| | | import cc.mrbird.febs.rabbit.producter.AgentProducer; |
| | | import cc.mrbird.febs.mall.service.IMallMoneyFlowService; |
| | | import cc.mrbird.febs.pay.model.RefundStatus; |
| | | import cc.mrbird.febs.pay.util.FiuuRefundUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.aspectj.weaver.loadtime.Agent; |
| | | 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.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2021-09-25 |
| | | **/ |
| | | @Slf4j |
| | | @SpringBootTest |
| | | public class AgentTest { |
| | | |
| | | @Autowired |
| | | private AgentProducer agentProducer; |
| | | private MallActivityMapper mallActivityMapper; |
| | | |
| | | @Autowired |
| | | private DataDictionaryCustomMapper dataDictionaryCustomMapper; |
| | | private MallRefundMapper mallRefundMapper; |
| | | |
| | | @Autowired |
| | | private IAgentService agentService; |
| | | private MallOrderInfoMapper mallOrderInfoMapper; |
| | | |
| | | @Autowired |
| | | private MallGoodsStyleMapper mallGoodsStyleMapper; |
| | | private MallOrderItemMapper mallOrderItemMapper; |
| | | |
| | | @Autowired |
| | | private MallActAwardSetMapper mallActAwardSetMapper; |
| | | private MallGoodsSkuMapper mallGoodsSkuMapper; |
| | | |
| | | @Autowired |
| | | private MallMemberMapper mallMemberMapper; |
| | | private MallGoodsMapper mallGoodsMapper; |
| | | |
| | | @Autowired |
| | | private MallActWinRecordMapper mallActWinRecordMapper; |
| | | private FiuuRefundUtil fiuuRefundUtil; |
| | | |
| | | @Autowired |
| | | private MallActLuckdrawRecordMapper mallActLuckdrawRecordMapper; |
| | | @Autowired |
| | | private MallMemberWalletMapper mallMemberWalletMapper; |
| | | @Autowired |
| | | private MallActSetMapper mallActSetMapper; |
| | | // @Test |
| | | // public void skusTest() { |
| | | // ApiMallAwardDetailsVo apiMallAwardDetailsVo = new ApiMallAwardDetailsVo(); |
| | | // Long memberId = 4L; |
| | | // Long actId = 1L; |
| | | // MallMember mallMember = mallMemberMapper.selectById(memberId); |
| | | // if(ObjectUtil.isEmpty(mallMember)){ |
| | | // throw new FebsException("用户不存在"); |
| | | // } |
| | | // |
| | | // MallActSet mallActSet = mallActSetMapper.selectById(actId); |
| | | // if(ObjectUtil.isEmpty(mallActSet)){ |
| | | // throw new FebsException("活动不存在"); |
| | | // } |
| | | // Integer actStatus = mallActSet.getActStatus(); |
| | | // if(MallActSet.ACT_STATUS_DISABLED == actStatus){ |
| | | // throw new FebsException("活动还没开始"); |
| | | // } |
| | | // /** |
| | | // * 获取用户积分数,判断能不能抽奖 |
| | | // * 减少对应的积分数量 |
| | | // * 较少奖品的已抽奖 |
| | | // * 生成一条抽奖记录 |
| | | // */ |
| | | // |
| | | // MallMemberWallet wallet = mallMemberWalletMapper.selectWalletByMemberId(memberId); |
| | | // if(ObjectUtil.isEmpty(wallet)){ |
| | | // throw new FebsException("账户不存在"); |
| | | // } |
| | | // BigDecimal commission = wallet.getCommission(); |
| | | // BigDecimal prizeScore = wallet.getPrizeScore(); |
| | | // Integer actScoreCnt = mallActSet.getActScoreCnt(); |
| | | // if(prizeScore.compareTo(new BigDecimal(actScoreCnt))<0){ |
| | | // throw new FebsException("竞猜积分不足"); |
| | | // } |
| | | // /** |
| | | // * 中奖概率 20% |
| | | // * 每次抽奖产生一个随机数要大于8,则中奖 |
| | | // * 历史10条抽奖记录有中奖过,中奖记录少于两条,则中奖 |
| | | // */ |
| | | // //获取中奖概率 |
| | | // DataDictionaryCustom scoreDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | // DataDictionaryEnum.WIN_SCORE.getType(), |
| | | // DataDictionaryEnum.WIN_SCORE.getCode()); |
| | | // DataDictionaryCustom cashDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode( |
| | | // DataDictionaryEnum.WIN_CASH.getType(), |
| | | // DataDictionaryEnum.WIN_CASH.getCode()); |
| | | // String scoreDicValue = scoreDic.getValue(); |
| | | // String cashDicValue = cashDic.getValue(); |
| | | // BigDecimal totalProbability = new BigDecimal(scoreDicValue).add(new BigDecimal(cashDicValue)); |
| | | // //获取那个更大一点的几率 |
| | | // BigDecimal maxProbability = BigDecimal.ZERO; |
| | | // BigDecimal minProbability = BigDecimal.ZERO; |
| | | // Integer maxAwardType = 0; |
| | | // Integer minAwardType = 0; |
| | | // if(new BigDecimal(scoreDicValue).compareTo(new BigDecimal(cashDicValue)) < 0){ |
| | | // maxProbability = new BigDecimal(cashDicValue); |
| | | // minProbability = new BigDecimal(scoreDicValue); |
| | | // maxAwardType = MallActAwardSet.AWARD_TYPE_YJ; |
| | | // minAwardType = MallActAwardSet.AWARD_TYPE_JF; |
| | | // }else{ |
| | | // maxProbability = new BigDecimal(scoreDicValue); |
| | | // minProbability = new BigDecimal(cashDicValue); |
| | | // maxAwardType = MallActAwardSet.AWARD_TYPE_JF; |
| | | // minAwardType = MallActAwardSet.AWARD_TYPE_YJ; |
| | | // } |
| | | // |
| | | // BigDecimal multiply = totalProbability.multiply(new BigDecimal(100)); |
| | | // BigDecimal failureScope = new BigDecimal(100).subtract(multiply); |
| | | // int randomInt = 90; |
| | | // //小于failureScope这个数字,则没中奖 |
| | | // if(new BigDecimal(randomInt).compareTo(failureScope) <= 0){ |
| | | // //抽奖记录 |
| | | // MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord(); |
| | | // mallActLuckdrawRecord.setActId(actId); |
| | | // mallActLuckdrawRecord.setActName(mallActSet.getActName()); |
| | | // mallActLuckdrawRecord.setMemberId(memberId); |
| | | // mallActLuckdrawRecord.setActScoreCnt(actScoreCnt); |
| | | // mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_DISABLED); |
| | | // mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord); |
| | | // |
| | | // List<MallActAwardSet> mallActAwardSetXXCY = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId, MallActAwardSet.AWARD_TYPE_XXCY); |
| | | // if(CollUtil.isNotEmpty(mallActAwardSetXXCY)){ |
| | | // apiMallAwardDetailsVo.setAwardImage(mallActAwardSetXXCY.get(0).getAwardImage()); |
| | | // apiMallAwardDetailsVo.setAwardName(mallActAwardSetXXCY.get(0).getAwardName()); |
| | | // }else{ |
| | | // apiMallAwardDetailsVo.setAwardName("未中奖"); |
| | | // } |
| | | // }else if(new BigDecimal(randomInt).compareTo(failureScope) > 0 |
| | | // && new BigDecimal(randomInt).compareTo(failureScope.add(maxProbability.multiply(new BigDecimal(100)))) <= 0){ |
| | | // //大于failureScope.add(maxProbability.multiply(new BigDecimal(100)))这个数字,则中奖 |
| | | // //获取最新的十条抽奖记录 |
| | | // List<MallActLuckdrawRecord> records = mallActLuckdrawRecordMapper.selectRecordByMemberIdAndActId(memberId,actId); |
| | | // if(CollUtil.isNotEmpty(records)){ |
| | | // //中奖次数 |
| | | // Integer count = 0; |
| | | // for(MallActLuckdrawRecord mallActLuckdrawRecord : records){ |
| | | // Integer status = mallActLuckdrawRecord.getStatus(); |
| | | // if(MallActLuckdrawRecord.STATUS_ENABLE == status){ |
| | | // count = count + 1; |
| | | // } |
| | | // } |
| | | // if(new BigDecimal(count).compareTo(maxProbability.multiply(new BigDecimal(10))) < 0){ |
| | | // //获取活动下该类别的奖品 |
| | | // List<MallActAwardSet> mallActAwardSets = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId,maxAwardType); |
| | | // if(CollUtil.isEmpty(mallActAwardSets)){ |
| | | // //抽奖记录 |
| | | // MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord(); |
| | | // mallActLuckdrawRecord.setActId(actId); |
| | | // mallActLuckdrawRecord.setActName(mallActSet.getActName()); |
| | | // mallActLuckdrawRecord.setMemberId(memberId); |
| | | // mallActLuckdrawRecord.setActScoreCnt(actScoreCnt); |
| | | // mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_DISABLED); |
| | | // mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord); |
| | | // |
| | | // List<MallActAwardSet> mallActAwardSetXXCY = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId, MallActAwardSet.AWARD_TYPE_XXCY); |
| | | // if(CollUtil.isNotEmpty(mallActAwardSetXXCY)){ |
| | | // apiMallAwardDetailsVo.setAwardImage(mallActAwardSetXXCY.get(0).getAwardImage()); |
| | | // apiMallAwardDetailsVo.setAwardName(mallActAwardSetXXCY.get(0).getAwardName()); |
| | | // }else{ |
| | | // apiMallAwardDetailsVo.setAwardName("未中奖"); |
| | | // } |
| | | // }else{ |
| | | // List<MallActAwardSet> idList = new ArrayList(); |
| | | // for(MallActAwardSet mallActAwardSet : mallActAwardSets){ |
| | | // Integer awardTotal = mallActAwardSet.getAwardTotal(); |
| | | // Integer awardCnt = mallActAwardSet.getAwardCnt(); |
| | | // if(awardCnt < awardTotal){ |
| | | // idList.add(mallActAwardSet); |
| | | // } |
| | | // } |
| | | // MallActAwardSet mallActAwardSet = new MallActAwardSet(); |
| | | // if(idList.size() <= 1){ |
| | | // mallActAwardSet = idList.get(0); |
| | | // }else{ |
| | | // int randomIdIndex = RandomUtil.randomInt(0, idList.size()-1); |
| | | // mallActAwardSet = idList.get(randomIdIndex); |
| | | // } |
| | | // mallActAwardSet.setAwardCnt(mallActAwardSet.getAwardCnt() + 1); |
| | | // mallActAwardSetMapper.updateById(mallActAwardSet); |
| | | // |
| | | // MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord(); |
| | | // mallActLuckdrawRecord.setActId(actId); |
| | | // mallActLuckdrawRecord.setActName(mallActSet.getActName()); |
| | | // mallActLuckdrawRecord.setMemberId(memberId); |
| | | // mallActLuckdrawRecord.setActScoreCnt(actScoreCnt); |
| | | // mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_ENABLE); |
| | | // mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord); |
| | | // |
| | | // MallActWinRecord mallActWinRecord = new MallActWinRecord(); |
| | | // mallActWinRecord.setMemberId(memberId); |
| | | // mallActWinRecord.setActId(actId); |
| | | // mallActWinRecord.setActName(mallActSet.getActName()); |
| | | // mallActWinRecord.setAwardId(mallActAwardSet.getId()); |
| | | // mallActWinRecord.setAwardName(mallActAwardSet.getAwardName()); |
| | | // mallActWinRecord.setAwardType(mallActAwardSet.getAwardType()); |
| | | // mallActWinRecord.setAwardValue(mallActAwardSet.getAwardValue()); |
| | | // mallActWinRecord.setRecordId(mallActLuckdrawRecord.getId()); |
| | | // mallActWinRecordMapper.insert(mallActWinRecord); |
| | | // |
| | | // apiMallAwardDetailsVo.setAwardName(mallActAwardSet.getAwardName()); |
| | | // apiMallAwardDetailsVo.setAwardType(mallActAwardSet.getAwardType()); |
| | | // apiMallAwardDetailsVo.setAwardValue(mallActAwardSet.getAwardValue()); |
| | | // apiMallAwardDetailsVo.setAwardImage(mallActAwardSet.getAwardImage()); |
| | | // |
| | | // if(MallActAwardSet.AWARD_TYPE_JF == mallActAwardSet.getAwardType()){ |
| | | // prizeScore = prizeScore.add(new BigDecimal(mallActAwardSet.getAwardValue())); |
| | | // }else if(MallActAwardSet.AWARD_TYPE_YJ == mallActAwardSet.getAwardType()){ |
| | | // commission = commission.add(new BigDecimal(mallActAwardSet.getAwardValue())); |
| | | // } |
| | | // } |
| | | // }else{ |
| | | // //抽奖记录 |
| | | // MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord(); |
| | | // mallActLuckdrawRecord.setActId(actId); |
| | | // mallActLuckdrawRecord.setActName(mallActSet.getActName()); |
| | | // mallActLuckdrawRecord.setMemberId(memberId); |
| | | // mallActLuckdrawRecord.setActScoreCnt(actScoreCnt); |
| | | // mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_DISABLED); |
| | | // mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord); |
| | | // |
| | | // List<MallActAwardSet> mallActAwardSetXXCY = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId, MallActAwardSet.AWARD_TYPE_XXCY); |
| | | // if(CollUtil.isNotEmpty(mallActAwardSetXXCY)){ |
| | | // apiMallAwardDetailsVo.setAwardImage(mallActAwardSetXXCY.get(0).getAwardImage()); |
| | | // apiMallAwardDetailsVo.setAwardName(mallActAwardSetXXCY.get(0).getAwardName()); |
| | | // }else{ |
| | | // apiMallAwardDetailsVo.setAwardName("未中奖"); |
| | | // } |
| | | // } |
| | | // }else{ |
| | | // //获取活动下该类别的奖品 |
| | | // List<MallActAwardSet> mallActAwardSets = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId,maxAwardType); |
| | | // if(CollUtil.isEmpty(mallActAwardSets)){ |
| | | // //抽奖记录 |
| | | // MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord(); |
| | | // mallActLuckdrawRecord.setActId(actId); |
| | | // mallActLuckdrawRecord.setActName(mallActSet.getActName()); |
| | | // mallActLuckdrawRecord.setMemberId(memberId); |
| | | // mallActLuckdrawRecord.setActScoreCnt(actScoreCnt); |
| | | // mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_DISABLED); |
| | | // mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord); |
| | | // |
| | | // List<MallActAwardSet> mallActAwardSetXXCY = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId, MallActAwardSet.AWARD_TYPE_XXCY); |
| | | // if(CollUtil.isNotEmpty(mallActAwardSetXXCY)){ |
| | | // apiMallAwardDetailsVo.setAwardImage(mallActAwardSetXXCY.get(0).getAwardImage()); |
| | | // apiMallAwardDetailsVo.setAwardName(mallActAwardSetXXCY.get(0).getAwardName()); |
| | | // }else{ |
| | | // apiMallAwardDetailsVo.setAwardName("未中奖"); |
| | | // } |
| | | // }else{ |
| | | // List<MallActAwardSet> idList = new ArrayList(); |
| | | // for(MallActAwardSet mallActAwardSet : mallActAwardSets){ |
| | | // Integer awardTotal = mallActAwardSet.getAwardTotal(); |
| | | // Integer awardCnt = mallActAwardSet.getAwardCnt(); |
| | | // if(awardCnt < awardTotal){ |
| | | // idList.add(mallActAwardSet); |
| | | // } |
| | | // } |
| | | // MallActAwardSet mallActAwardSet = new MallActAwardSet(); |
| | | // if(idList.size() <= 1){ |
| | | // mallActAwardSet = idList.get(0); |
| | | // }else{ |
| | | // int randomIdIndex = RandomUtil.randomInt(0, idList.size()-1); |
| | | // mallActAwardSet = idList.get(randomIdIndex); |
| | | // } |
| | | // mallActAwardSet.setAwardCnt(mallActAwardSet.getAwardCnt() + 1); |
| | | // mallActAwardSetMapper.updateById(mallActAwardSet); |
| | | // |
| | | // MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord(); |
| | | // mallActLuckdrawRecord.setActId(actId); |
| | | // mallActLuckdrawRecord.setActName(mallActSet.getActName()); |
| | | // mallActLuckdrawRecord.setMemberId(memberId); |
| | | // mallActLuckdrawRecord.setActScoreCnt(actScoreCnt); |
| | | // mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_ENABLE); |
| | | // mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord); |
| | | // |
| | | // MallActWinRecord mallActWinRecord = new MallActWinRecord(); |
| | | // mallActWinRecord.setMemberId(memberId); |
| | | // mallActWinRecord.setActId(actId); |
| | | // mallActWinRecord.setActName(mallActSet.getActName()); |
| | | // mallActWinRecord.setAwardId(mallActAwardSet.getId()); |
| | | // mallActWinRecord.setAwardName(mallActAwardSet.getAwardName()); |
| | | // mallActWinRecord.setAwardType(mallActAwardSet.getAwardType()); |
| | | // mallActWinRecord.setAwardValue(mallActAwardSet.getAwardValue()); |
| | | // mallActWinRecord.setRecordId(mallActLuckdrawRecord.getId()); |
| | | // mallActWinRecordMapper.insert(mallActWinRecord); |
| | | // |
| | | // apiMallAwardDetailsVo.setAwardName(mallActAwardSet.getAwardName()); |
| | | // apiMallAwardDetailsVo.setAwardType(mallActAwardSet.getAwardType()); |
| | | // apiMallAwardDetailsVo.setAwardValue(mallActAwardSet.getAwardValue()); |
| | | // apiMallAwardDetailsVo.setAwardImage(mallActAwardSet.getAwardImage()); |
| | | // |
| | | // if(MallActAwardSet.AWARD_TYPE_JF == mallActAwardSet.getAwardType()){ |
| | | // prizeScore = prizeScore.add(new BigDecimal(mallActAwardSet.getAwardValue())); |
| | | // }else if(MallActAwardSet.AWARD_TYPE_YJ == mallActAwardSet.getAwardType()){ |
| | | // commission = commission.add(new BigDecimal(mallActAwardSet.getAwardValue())); |
| | | // } |
| | | // } |
| | | // } |
| | | // }else{ |
| | | // //中奖 |
| | | // //获取最新的十条抽奖记录 |
| | | // List<MallActLuckdrawRecord> records = mallActLuckdrawRecordMapper.selectRecordByMemberIdAndActId(memberId,actId); |
| | | // if(CollUtil.isNotEmpty(records)){ |
| | | // //中奖次数 |
| | | // Integer count = 0; |
| | | // for(MallActLuckdrawRecord mallActLuckdrawRecord : records){ |
| | | // Integer status = mallActLuckdrawRecord.getStatus(); |
| | | // if(MallActLuckdrawRecord.STATUS_ENABLE == status){ |
| | | // count = count + 1; |
| | | // } |
| | | // } |
| | | // if(new BigDecimal(count).compareTo(minProbability.multiply(new BigDecimal(10))) < 0){ |
| | | // //获取活动下该类别的奖品 |
| | | // List<MallActAwardSet> mallActAwardSets = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId,minAwardType); |
| | | // if(CollUtil.isEmpty(mallActAwardSets)){ |
| | | // //抽奖记录 |
| | | // MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord(); |
| | | // mallActLuckdrawRecord.setActId(actId); |
| | | // mallActLuckdrawRecord.setActName(mallActSet.getActName()); |
| | | // mallActLuckdrawRecord.setMemberId(memberId); |
| | | // mallActLuckdrawRecord.setActScoreCnt(actScoreCnt); |
| | | // mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_DISABLED); |
| | | // mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord); |
| | | // |
| | | // List<MallActAwardSet> mallActAwardSetXXCY = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId, MallActAwardSet.AWARD_TYPE_XXCY); |
| | | // if(CollUtil.isNotEmpty(mallActAwardSetXXCY)){ |
| | | // apiMallAwardDetailsVo.setAwardImage(mallActAwardSetXXCY.get(0).getAwardImage()); |
| | | // apiMallAwardDetailsVo.setAwardName(mallActAwardSetXXCY.get(0).getAwardName()); |
| | | // }else{ |
| | | // apiMallAwardDetailsVo.setAwardName("未中奖"); |
| | | // } |
| | | // }else{ |
| | | // List<MallActAwardSet> idList = new ArrayList(); |
| | | // for(MallActAwardSet mallActAwardSet : mallActAwardSets){ |
| | | // Integer awardTotal = mallActAwardSet.getAwardTotal(); |
| | | // Integer awardCnt = mallActAwardSet.getAwardCnt(); |
| | | // if(awardCnt < awardTotal){ |
| | | // idList.add(mallActAwardSet); |
| | | // } |
| | | // } |
| | | // MallActAwardSet mallActAwardSet = new MallActAwardSet(); |
| | | // if(idList.size() <= 1){ |
| | | // mallActAwardSet = idList.get(0); |
| | | // }else{ |
| | | // int randomIdIndex = RandomUtil.randomInt(0, idList.size()-1); |
| | | // mallActAwardSet = idList.get(randomIdIndex); |
| | | // } |
| | | // mallActAwardSet.setAwardCnt(mallActAwardSet.getAwardCnt() + 1); |
| | | // mallActAwardSetMapper.updateById(mallActAwardSet); |
| | | // |
| | | // MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord(); |
| | | // mallActLuckdrawRecord.setActId(actId); |
| | | // mallActLuckdrawRecord.setActName(mallActSet.getActName()); |
| | | // mallActLuckdrawRecord.setMemberId(memberId); |
| | | // mallActLuckdrawRecord.setActScoreCnt(actScoreCnt); |
| | | // mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_ENABLE); |
| | | // mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord); |
| | | // |
| | | // MallActWinRecord mallActWinRecord = new MallActWinRecord(); |
| | | // mallActWinRecord.setMemberId(memberId); |
| | | // mallActWinRecord.setActId(actId); |
| | | // mallActWinRecord.setActName(mallActSet.getActName()); |
| | | // mallActWinRecord.setAwardId(mallActAwardSet.getId()); |
| | | // mallActWinRecord.setAwardName(mallActAwardSet.getAwardName()); |
| | | // mallActWinRecord.setAwardType(mallActAwardSet.getAwardType()); |
| | | // mallActWinRecord.setAwardValue(mallActAwardSet.getAwardValue()); |
| | | // mallActWinRecord.setRecordId(mallActLuckdrawRecord.getId()); |
| | | // mallActWinRecordMapper.insert(mallActWinRecord); |
| | | // |
| | | // apiMallAwardDetailsVo.setAwardName(mallActAwardSet.getAwardName()); |
| | | // apiMallAwardDetailsVo.setAwardType(mallActAwardSet.getAwardType()); |
| | | // apiMallAwardDetailsVo.setAwardValue(mallActAwardSet.getAwardValue()); |
| | | // apiMallAwardDetailsVo.setAwardImage(mallActAwardSet.getAwardImage()); |
| | | // |
| | | // if(MallActAwardSet.AWARD_TYPE_JF == mallActAwardSet.getAwardType()){ |
| | | // prizeScore = prizeScore.add(new BigDecimal(mallActAwardSet.getAwardValue())); |
| | | // }else if(MallActAwardSet.AWARD_TYPE_YJ == mallActAwardSet.getAwardType()){ |
| | | // commission = commission.add(new BigDecimal(mallActAwardSet.getAwardValue())); |
| | | // } |
| | | // } |
| | | // }else{ |
| | | // //抽奖记录 |
| | | // MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord(); |
| | | // mallActLuckdrawRecord.setActId(actId); |
| | | // mallActLuckdrawRecord.setActName(mallActSet.getActName()); |
| | | // mallActLuckdrawRecord.setMemberId(memberId); |
| | | // mallActLuckdrawRecord.setActScoreCnt(actScoreCnt); |
| | | // mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_DISABLED); |
| | | // mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord); |
| | | // |
| | | // List<MallActAwardSet> mallActAwardSetXXCY = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId, MallActAwardSet.AWARD_TYPE_XXCY); |
| | | // if(CollUtil.isNotEmpty(mallActAwardSetXXCY)){ |
| | | // apiMallAwardDetailsVo.setAwardImage(mallActAwardSetXXCY.get(0).getAwardImage()); |
| | | // apiMallAwardDetailsVo.setAwardName(mallActAwardSetXXCY.get(0).getAwardName()); |
| | | // }else{ |
| | | // apiMallAwardDetailsVo.setAwardName("未中奖"); |
| | | // } |
| | | // } |
| | | // }else{ |
| | | // //获取活动下该类别的奖品 |
| | | // List<MallActAwardSet> mallActAwardSets = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId,minAwardType); |
| | | // if(CollUtil.isEmpty(mallActAwardSets)){ |
| | | // //抽奖记录 |
| | | // MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord(); |
| | | // mallActLuckdrawRecord.setActId(actId); |
| | | // mallActLuckdrawRecord.setActName(mallActSet.getActName()); |
| | | // mallActLuckdrawRecord.setMemberId(memberId); |
| | | // mallActLuckdrawRecord.setActScoreCnt(actScoreCnt); |
| | | // mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_DISABLED); |
| | | // mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord); |
| | | // |
| | | // List<MallActAwardSet> mallActAwardSetXXCY = mallActAwardSetMapper.selectMallActAwardByActIdAndAwardType(actId, MallActAwardSet.AWARD_TYPE_XXCY); |
| | | // if(CollUtil.isNotEmpty(mallActAwardSetXXCY)){ |
| | | // apiMallAwardDetailsVo.setAwardImage(mallActAwardSetXXCY.get(0).getAwardImage()); |
| | | // apiMallAwardDetailsVo.setAwardName(mallActAwardSetXXCY.get(0).getAwardName()); |
| | | // }else{ |
| | | // apiMallAwardDetailsVo.setAwardName("未中奖"); |
| | | // } |
| | | // }else{ |
| | | // List<MallActAwardSet> idList = new ArrayList(); |
| | | // for(MallActAwardSet mallActAwardSet : mallActAwardSets){ |
| | | // Integer awardTotal = mallActAwardSet.getAwardTotal(); |
| | | // Integer awardCnt = mallActAwardSet.getAwardCnt(); |
| | | // if(awardCnt < awardTotal){ |
| | | // idList.add(mallActAwardSet); |
| | | // } |
| | | // } |
| | | // MallActAwardSet mallActAwardSet = new MallActAwardSet(); |
| | | // if(idList.size() <= 1){ |
| | | // mallActAwardSet = idList.get(0); |
| | | // }else{ |
| | | // int randomIdIndex = RandomUtil.randomInt(0, idList.size()-1); |
| | | // mallActAwardSet = idList.get(randomIdIndex); |
| | | // } |
| | | // mallActAwardSet.setAwardCnt(mallActAwardSet.getAwardCnt() + 1); |
| | | // mallActAwardSetMapper.updateById(mallActAwardSet); |
| | | // |
| | | // MallActLuckdrawRecord mallActLuckdrawRecord = new MallActLuckdrawRecord(); |
| | | // mallActLuckdrawRecord.setActId(actId); |
| | | // mallActLuckdrawRecord.setActName(mallActSet.getActName()); |
| | | // mallActLuckdrawRecord.setMemberId(memberId); |
| | | // mallActLuckdrawRecord.setActScoreCnt(actScoreCnt); |
| | | // mallActLuckdrawRecord.setStatus(MallActLuckdrawRecord.STATUS_ENABLE); |
| | | // mallActLuckdrawRecordMapper.insert(mallActLuckdrawRecord); |
| | | // |
| | | // MallActWinRecord mallActWinRecord = new MallActWinRecord(); |
| | | // mallActWinRecord.setMemberId(memberId); |
| | | // mallActWinRecord.setActId(actId); |
| | | // mallActWinRecord.setActName(mallActSet.getActName()); |
| | | // mallActWinRecord.setAwardId(mallActAwardSet.getId()); |
| | | // mallActWinRecord.setAwardName(mallActAwardSet.getAwardName()); |
| | | // mallActWinRecord.setAwardType(mallActAwardSet.getAwardType()); |
| | | // mallActWinRecord.setAwardValue(mallActAwardSet.getAwardValue()); |
| | | // mallActWinRecord.setRecordId(mallActLuckdrawRecord.getId()); |
| | | // mallActWinRecordMapper.insert(mallActWinRecord); |
| | | // |
| | | // apiMallAwardDetailsVo.setAwardName(mallActAwardSet.getAwardName()); |
| | | // apiMallAwardDetailsVo.setAwardType(mallActAwardSet.getAwardType()); |
| | | // apiMallAwardDetailsVo.setAwardValue(mallActAwardSet.getAwardValue()); |
| | | // apiMallAwardDetailsVo.setAwardImage(mallActAwardSet.getAwardImage()); |
| | | // |
| | | // if(MallActAwardSet.AWARD_TYPE_JF == mallActAwardSet.getAwardType()){ |
| | | // prizeScore = prizeScore.add(new BigDecimal(mallActAwardSet.getAwardValue())); |
| | | // }else if(MallActAwardSet.AWARD_TYPE_YJ == mallActAwardSet.getAwardType()){ |
| | | // commission = commission.add(new BigDecimal(mallActAwardSet.getAwardValue())); |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // //扣竞猜积分 |
| | | // prizeScore = prizeScore.subtract(new BigDecimal(actScoreCnt)); |
| | | // wallet.setPrizeScore(prizeScore); |
| | | // wallet.setCommission(commission); |
| | | // mallMemberWalletMapper.updateAmountWithVersion(wallet); |
| | | // |
| | | // System.out.println(apiMallAwardDetailsVo); |
| | | // } |
| | | // |
| | | // @Test |
| | | // public void agentTest() { |
| | | //// agentProducer.sendDelayMsg(1L, 10000L); |
| | | // |
| | | // ApiMallActWinDetailsDto apiMallActWinDetailsDto = new ApiMallActWinDetailsDto(); |
| | | // apiMallActWinDetailsDto.setActId(1L); |
| | | // apiMallActWinDetailsDto.setPageNow(1); |
| | | // apiMallActWinDetailsDto.setPageSize(10); |
| | | // Long memberId = 4L; |
| | | // MallMember mallMember = mallMemberMapper.selectById(memberId); |
| | | // if(ObjectUtil.isEmpty(mallMember)){ |
| | | // throw new FebsException("用户不存在"); |
| | | // } |
| | | // apiMallActWinDetailsDto.setMemberId(memberId); |
| | | // |
| | | // Long actId = apiMallActWinDetailsDto.getActId(); |
| | | // MallActSet mallActSet = mallActSetMapper.selectById(actId); |
| | | // if(ObjectUtil.isEmpty(mallActSet)){ |
| | | // throw new FebsException("活动不存在"); |
| | | // } |
| | | // Page<ApiMallActWinDetailsVo> page = new Page<>(apiMallActWinDetailsDto.getPageNow(), apiMallActWinDetailsDto.getPageSize()); |
| | | // IPage<ApiMallActWinDetailsVo> apiMallActWinDetailsVoIPage = mallActWinRecordMapper.selectApiMallActWinDetailsListInPage(apiMallActWinDetailsDto, page); |
| | | // System.out.println(apiMallActWinDetailsVoIPage); |
| | | // } |
| | | // |
| | | // @Test |
| | | // public void insertAgentTest() { |
| | | //// AgentInfo agentInfo = new AgentInfo(); |
| | | //// agentInfo.setOrderType(2); |
| | | //// agentInfo.setOrderCnt(2000); |
| | | //// agentInfo.setLastCnt(3); |
| | | //// agentInfo.setDirectIncome(BigDecimal.valueOf(50)); |
| | | //// agentInfo.setTeamIncome(BigDecimal.valueOf(15)); |
| | | //// agentInfo.setTeamIncomeType(2); |
| | | //// |
| | | //// DataDictionaryCustom data = new DataDictionaryCustom(); |
| | | //// data.setType("AGENT_LEVEL_REQUIRE"); |
| | | //// data.setCode(AgentLevelEnum.FOUR_LEVEL.name()); |
| | | //// data.setValue(JSONObject.toJSONString(agentInfo)); |
| | | //// dataDictionaryCustomMapper.insert(data); |
| | | // } |
| | | // |
| | | // @Test |
| | | // public void insertData() { |
| | | // int i = 1; |
| | | // for (AgentLevelEnum value : AgentLevelEnum.values()) { |
| | | // DataDictionaryCustom data = new DataDictionaryCustom(); |
| | | // data.setType("AGENT_LEVEL"); |
| | | // data.setDescription(value.getName()); |
| | | // data.setCode(value.name()); |
| | | // data.setValue(String.valueOf(i)); |
| | | // dataDictionaryCustomMapper.insert(data); |
| | | // } |
| | | // |
| | | // } |
| | | // |
| | | // public static void main(String[] args) { |
| | | // getJson(); |
| | | // } |
| | | // |
| | | // public static void getJson(){ |
| | | // AgentLevelUpdateDto adminAgentLevelUpdateInfoVo = new AgentLevelUpdateDto(); |
| | | // String jsonStr = "{\"directIncome\":50,\"lastCnt\":3,\"orderCnt\":2000,\"orderType\":2,\"teamIncome\":15,\"teamIncomeType\":2}"; |
| | | // JSONObject jsonObject = JSONObject.parseObject(jsonStr); |
| | | // adminAgentLevelUpdateInfoVo.setDirectIncome(new BigDecimal((jsonObject.get("directIncome")==null?0:jsonObject.get("directIncome")).toString())); |
| | | // adminAgentLevelUpdateInfoVo.setLastCnt(Integer.parseInt((jsonObject.get("lastCnt")==null?0:jsonObject.get("lastCnt")).toString())); |
| | | // adminAgentLevelUpdateInfoVo.setOrderCnt(Integer.parseInt((jsonObject.get("orderCnt")==null?0:jsonObject.get("orderCnt")).toString())); |
| | | // adminAgentLevelUpdateInfoVo.setOrderType(Integer.parseInt(jsonObject.get("orderType").toString())); |
| | | // adminAgentLevelUpdateInfoVo.setTeamIncome(new BigDecimal((jsonObject.get("teamIncome")==null?0:jsonObject.get("teamIncome")).toString())); |
| | | // adminAgentLevelUpdateInfoVo.setTeamIncomeType(Integer.parseInt(jsonObject.get("orderType").toString())); |
| | | // adminAgentLevelUpdateInfoVo.setId(14L); |
| | | // AgentLevelUpdateDto agentLevelUpdateDtoJson = new AgentLevelUpdateDto(); |
| | | // agentLevelUpdateDtoJson.setDirectIncome(adminAgentLevelUpdateInfoVo.getDirectIncome()); |
| | | // agentLevelUpdateDtoJson.setLastCnt(adminAgentLevelUpdateInfoVo.getLastCnt()); |
| | | // agentLevelUpdateDtoJson.setOrderCnt(adminAgentLevelUpdateInfoVo.getOrderCnt()); |
| | | // agentLevelUpdateDtoJson.setTeamIncome(adminAgentLevelUpdateInfoVo.getTeamIncome()); |
| | | // agentLevelUpdateDtoJson.setOrderType(adminAgentLevelUpdateInfoVo.getOrderType()); |
| | | // agentLevelUpdateDtoJson.setTeamIncomeType(adminAgentLevelUpdateInfoVo.getTeamIncomeType()); |
| | | // JSONObject jsonObjectA = (JSONObject)JSONObject.toJSON(agentLevelUpdateDtoJson); |
| | | // System.out.println(jsonObjectA.toJSONString()); |
| | | // } |
| | | // |
| | | // @Test |
| | | // public void autoLevelUp() { |
| | | // // agentService.autoUpAgentLevel(3L); |
| | | //// agentProducer.sendAutoLevelUpMsg(5L); |
| | | // |
| | | // agentProducer.sendReturnMoneyMsg(2L); |
| | | // } |
| | | // |
| | | // @Test |
| | | // public void returnMoney() { |
| | | // // agentService.autoUpAgentLevel(3L); |
| | | //// agentProducer.sendAutoLevelUpMsg(5L); |
| | | //// agentProducer.sendReturnMoneyMsg(52L); |
| | | // agentService.returnMoneyToAgent(52L); |
| | | // } |
| | | // |
| | | // @Test |
| | | // public void bigdecimalTest() { |
| | | // BigDecimal aa = new BigDecimal("1.345"); |
| | | // |
| | | // System.out.println(aa.setScale(2, RoundingMode.DOWN)); |
| | | // System.out.println(aa.setScale(2, RoundingMode.UP)); |
| | | // } |
| | | // |
| | | // @Autowired |
| | | // private ProfitJob profitJob; |
| | | // |
| | | // @Test |
| | | // public void profitJobTest() { |
| | | // profitJob.profitJob(); |
| | | // } |
| | | // |
| | | // |
| | | // @Autowired |
| | | // private AgentConsumer agentConsumer; |
| | | // |
| | | // @Test |
| | | // public void orderReturnTest() { |
| | | // agentConsumer.orderReturnMoney("7"); |
| | | // } |
| | | private IMallMoneyFlowService mallMoneyFlowService; |
| | | @Test |
| | | public void refundJob() { |
| | | LambdaQueryWrapper<MallRefundEntity> mallOrderRefundLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | mallOrderRefundLambdaQueryWrapper.eq(MallRefundEntity::getState, 3); |
| | | mallOrderRefundLambdaQueryWrapper.eq(MallRefundEntity::getType, 1); |
| | | List<MallRefundEntity> mallRefundEntities = mallRefundMapper.selectList(mallOrderRefundLambdaQueryWrapper); |
| | | if(CollUtil.isEmpty(mallRefundEntities)){ |
| | | return; |
| | | } |
| | | mallRefundEntities.forEach(mallRefundEntity -> { |
| | | processRefund(mallRefundEntity); |
| | | }); |
| | | } |
| | | |
| | | private void processRefund(MallRefundEntity mallRefundEntity) { |
| | | try { |
| | | MallOrderInfo mallOrderInfo = mallOrderInfoMapper.selectById(mallRefundEntity.getOrderId()); |
| | | MallOrderItem mallOrderItem = mallOrderItemMapper.selectById(mallRefundEntity.getItemId()); |
| | | MallGoodsSku mallGoodsSku = mallGoodsSkuMapper.selectById(mallOrderItem.getSkuId()); |
| | | |
| | | String txnId = mallOrderInfo.getPayOrderNo(); |
| | | RefundStatus status = fiuuRefundUtil.pollRefundStatus(txnId); |
| | | |
| | | switch (status.getStatus()) { |
| | | case "success": |
| | | updateOnSuccess(mallRefundEntity, mallOrderInfo, mallOrderItem, mallGoodsSku); |
| | | break; |
| | | case "rejected": |
| | | updateOnRejected(mallRefundEntity, mallOrderItem); |
| | | break; |
| | | default: |
| | | log.warn("未知状态:{}", status.getStatus()); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("处理退款失败: {}", e.getMessage(), e); |
| | | } |
| | | } |
| | | |
| | | private void updateOnSuccess(MallRefundEntity mallRefundEntity, MallOrderInfo mallOrderInfo, MallOrderItem mallOrderItem, MallGoodsSku mallGoodsSku) { |
| | | mallOrderItem.setState(3); |
| | | mallOrderItemMapper.updateById(mallOrderItem); |
| | | |
| | | MallGoods mallGoods = mallGoodsMapper.selectById(mallOrderItem.getGoodsId()); |
| | | mallGoods.setStock(mallGoods.getStock() + mallOrderItem.getCnt()); |
| | | mallGoods.setVolume(mallGoods.getVolume() - mallOrderItem.getCnt()); |
| | | mallGoodsMapper.updateById(mallGoods); |
| | | |
| | | mallGoodsSku.setStock(mallGoodsSku.getStock() + mallOrderItem.getCnt()); |
| | | mallGoodsSku.setSkuVolume(mallGoodsSku.getSkuVolume() - mallOrderItem.getCnt()); |
| | | mallGoodsSkuMapper.updateById(mallGoodsSku); |
| | | |
| | | mallRefundEntity.setState(1); |
| | | mallRefundEntity.setUpdatedTime(DateUtil.date()); |
| | | mallRefundMapper.updateById(mallRefundEntity); |
| | | |
| | | mallMoneyFlowService.addMoneyFlow( |
| | | mallOrderInfo.getMemberId(), |
| | | mallRefundEntity.getAmount(), |
| | | MoneyFlowTypeEnum.WECHAT_REFUND.getValue(), |
| | | mallOrderInfo.getOrderNo(), |
| | | FlowTypeEnum.WECHAT.getValue(), |
| | | "FIUU退款", |
| | | 2); |
| | | |
| | | List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByNotInStateAndOrderId(3, mallRefundEntity.getOrderId()); |
| | | if (CollUtil.isEmpty(mallOrderItemList)) { |
| | | MallOrderInfo mallOrderRefund = mallOrderInfoMapper.selectById(mallRefundEntity.getOrderId()); |
| | | mallOrderRefund.setStatus(6); |
| | | mallOrderInfoMapper.updateById(mallOrderRefund); |
| | | } |
| | | } |
| | | |
| | | private void updateOnRejected(MallRefundEntity mallRefundEntity, MallOrderItem mallOrderItem) { |
| | | mallOrderItem.setState(1); |
| | | mallOrderItemMapper.updateById(mallOrderItem); |
| | | |
| | | mallRefundEntity.setState(2); |
| | | mallRefundMapper.updateById(mallRefundEntity); |
| | | } |
| | | |
| | | } |