xiaoyong931011
2023-03-15 c8553669f87a7bc4df3b2279ad4473b6b212a127
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -14,10 +14,7 @@
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
import cc.mrbird.febs.mall.service.*;
import cc.mrbird.febs.mall.vo.ApiShopApplyVo;
import cc.mrbird.febs.mall.vo.OrderDetailVo;
import cc.mrbird.febs.mall.vo.OrderListVo;
import cc.mrbird.febs.mall.vo.OrderRefundVo;
import cc.mrbird.febs.mall.vo.*;
import cc.mrbird.febs.pay.model.AgreementPayDto;
import cc.mrbird.febs.pay.model.AgreementSignDto;
import cc.mrbird.febs.pay.model.UnipayDto;
@@ -42,6 +39,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.*;
@@ -79,6 +77,7 @@
    private final MallShopApplyMapper mallShopApplyMapper;
    private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
    private final MallAchieveRecordMapper mallAchieveRecordMapper;
    private final MallMemberWalletMapper mallMemberWalletMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
@@ -349,10 +348,11 @@
                orderInfo.setPayTime(new Date());
                orderInfo.setPayResult("1");
                changeWallet(orderInfo.getId(), member.getId());
                changeWallet(orderInfo.getId());
                //发送补贴消息
                agentProducer.sendPerkMoneyMsg(orderInfo.getId());
                //发送代理自动升级消息
                agentProducer.sendAutoLevelUpMsg(member.getId());
//                agentProducer.sendOrderReturn(orderInfo.getId());
                break;
            case "4":
                if (orderInfo.getOrderType() != 2) {
@@ -431,10 +431,10 @@
     *      增加贡献值,增加流水
     *      产生一条业绩记录
     * @param orderId
     * @param memberId
     */
    public void changeWallet(Long orderId,Long memberId){
    public void changeWallet(Long orderId){
        MallOrderInfo orderInfo = this.baseMapper.selectById(orderId);
        Long memberId = orderInfo.getMemberId();
        boolean hasTc = false;
        //总贡献值
        BigDecimal starSum = BigDecimal.ZERO;
@@ -453,7 +453,7 @@
                 */
                if (mallGoods.getIsNormal() == 2) {
                    hasTc = true;
                    BigDecimal star = mallGoods.getStar();
                    BigDecimal star = mallGoods.getStar()==null ? BigDecimal.ZERO : mallGoods.getStar();
                    starSum = starSum.add(star);
                    scoreSum = scoreSum.add(
                            new BigDecimal(mallGoods.getPresentPrice())
@@ -466,13 +466,40 @@
             * 增加贡献值,增加流水
             */
            if (starSum.compareTo(BigDecimal.ZERO) > 0) {
                memberWalletService.add(starSum, memberId, "star");
                mallMoneyFlowService.addMoneyFlow(
                        memberId,
                        starSum,
                        MoneyFlowTypeEnum.STAR.getValue(),
                        orderInfo.getOrderNo(),
                        FlowTypeEnum.STAR.getValue());
                //系统设置的个人贡献点最大值
                DataDictionaryCustom starGetDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                        DataDictionaryEnum.STAR_GET.getType(),
                        DataDictionaryEnum.STAR_GET.getCode());
                if(ObjectUtil.isNotEmpty(starGetDic)){
                    String starGetStr = StrUtil.isEmpty(starGetDic.getValue()) ? "0" : starGetDic.getValue();
                    BigDecimal starGet = new BigDecimal(starGetStr);
                    MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(memberId);
                    BigDecimal star = new BigDecimal(mallMemberWallet.getStar());
                    if(starGet.compareTo(star.add(starSum)) < 0){
                        if(starGet.compareTo(star) > 0){
                            BigDecimal subtract = starGet.subtract(star);
                            if(subtract.compareTo(starSum) < 0){
                                starSum = subtract;
                            }
                            mallMemberWalletMapper.addStarByMemberId(starSum.intValue(), memberId);
                            mallMoneyFlowService.addMoneyFlow(
                                    memberId,
                                    starSum,
                                    MoneyFlowTypeEnum.STAR.getValue(),
                                    orderInfo.getOrderNo(),
                                    FlowTypeEnum.STAR.getValue());
                        }
                    }else{
                        mallMemberWalletMapper.addStarByMemberId(starSum.intValue(), memberId);
                        mallMoneyFlowService.addMoneyFlow(
                                memberId,
                                starSum,
                                MoneyFlowTypeEnum.STAR.getValue(),
                                orderInfo.getOrderNo(),
                                FlowTypeEnum.STAR.getValue());
                    }
                }
            }
            /**
             * 增加补贴额度
@@ -807,18 +834,41 @@
    }
    @Override
    public boolean judgeCreateOrder(AddOrderDto addOrderDto) {
        boolean flag = false;
    public FebsResponse judgeCreateOrder(AddOrderDto addOrderDto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        if (CollUtil.isEmpty(addOrderDto.getItems())) {
            return false;
            throw new FebsException("请选择购买商品");
        }
        boolean hasTc = false;
        BigDecimal total = BigDecimal.ZERO;
        for (AddOrderItemDto item : addOrderDto.getItems()) {
                MallGoodsSku sku = mallGoodsSkuMapper.selectSkuInfoById(item.getSkuId());
                MallGoods mallGoods = mallGoodsMapper.selectById(sku.getGoodsId());
                /**
                 * 贡献点判断
                 */
                if (mallGoods.getIsNormal() == 2) {
                    hasTc = true;
                }
                BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt()));
                total = total.add(amount);
        }
        if(hasTc){
            //系统设置的个人贡献点最大值
            DataDictionaryCustom starGetDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                    DataDictionaryEnum.STAR_GET.getType(),
                    DataDictionaryEnum.STAR_GET.getCode());
            if(ObjectUtil.isNotEmpty(starGetDic)){
                String starGetStr = StrUtil.isEmpty(starGetDic.getValue()) ? "0" : starGetDic.getValue();
                BigDecimal starGet = new BigDecimal(starGetStr);
                MallMemberWallet mallMemberWallet = mallMemberWalletMapper.selectWalletByMemberId(memberId);
                BigDecimal star = new BigDecimal(mallMemberWallet.getStar());
                if(starGet.compareTo(star) <= 0){
                    throw new FebsException("无法购买套餐");
                }
            }
        }
        /**
         * 使用积分折扣现金
@@ -834,21 +884,35 @@
        BigDecimal score = ObjectUtil.isEmpty(addOrderDto.getScore()) ? BigDecimal.ZERO : addOrderDto.getScore();
        if(ObjectUtil.isNotEmpty(scorePercentDic)){
            //商品的现金折扣比例
            BigDecimal scorePercent = new BigDecimal(scorePercentDic.getValue()).divide(new BigDecimal(100), BigDecimal.ROUND_DOWN);
            BigDecimal scorePercent = new BigDecimal(scorePercentDic.getValue()).multiply(BigDecimal.valueOf(0.01));
            //最大折扣金额对应需要的总积分数目
            BigDecimal scorePercentMaxAmount = total.multiply(scorePercent);
            BigDecimal scoreChange = BigDecimal.ONE;
            if(ObjectUtil.isNotEmpty(scoreChangeDic)){
                scoreChange = new BigDecimal(scoreChangeDic.getValue()).abs().setScale(2,BigDecimal.ROUND_DOWN);
            }
            scorePercentMaxAmount = scorePercentMaxAmount.multiply(scoreChange);
            scorePercentMaxAmount = scorePercentMaxAmount.multiply(scoreChange).setScale(2,BigDecimal.ROUND_DOWN);
            if(scorePercentMaxAmount.compareTo(score) < 0){
                return false;
                throw new FebsException("最多可使用"+scorePercentMaxAmount+"积分");
            }
        }else{
            flag = true;
        }
        return flag;
        return new FebsResponse().success();
    }
    @Override
    public ApiScoreSetVo myScoreSet() {
        ApiScoreSetVo apiScoreSetVo = new ApiScoreSetVo();
        DataDictionaryCustom scorePercentDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.SCORE_PERCENT.getType(),
                DataDictionaryEnum.SCORE_PERCENT.getCode()
        );
        DataDictionaryCustom scoreChangeDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
                DataDictionaryEnum.SCORE_CHANGE.getType(),
                DataDictionaryEnum.SCORE_CHANGE.getCode()
        );
        apiScoreSetVo.setScorePercent(new BigDecimal(scorePercentDic.getValue()).multiply(BigDecimal.valueOf(0.01)).setScale(2,BigDecimal.ROUND_DOWN));
        apiScoreSetVo.setScoreChange(new BigDecimal(scoreChangeDic.getValue()).setScale(2,BigDecimal.ROUND_DOWN));
        return apiScoreSetVo;
    }
}