935090232@qq.com
2022-03-08 beafd056e04f33eca7d9efcd7fc4a5b633fd0dfa
zq-erp/src/main/java/com/matrix/system/hive/service/imp/SysOrderServiceImpl.java
@@ -1,6 +1,8 @@
package com.matrix.system.hive.service.imp;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.google.common.collect.Lists;
import com.matrix.component.asyncmessage.AsyncMessageManager;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.exception.GlobleException;
@@ -26,6 +28,8 @@
import com.matrix.system.enums.OperationFunctionEnum;
import com.matrix.system.hive.bean.*;
import com.matrix.system.hive.dao.*;
import com.matrix.system.hive.dto.GoodsSealLimitDto;
import com.matrix.system.hive.dto.OrderItemDto;
import com.matrix.system.hive.plugin.util.CollectionUtils;
import com.matrix.system.hive.plugin.util.MoneyUtil;
import com.matrix.system.hive.pojo.CzXkVo;
@@ -553,6 +557,8 @@
        addVipScore(pageOrder);
    }
    /**
@@ -601,11 +607,22 @@
    }
    private void checkOrder(SysOrder pageOrder) {
        //检查交易限制调整
        checkSealLimit(pageOrder);
        //检查交易限制调整 jyytodo 测试一下
        GoodsSealLimitDto goodsSealLimitDto = new GoodsSealLimitDto();
        goodsSealLimitDto.setVipId(pageOrder.getVipId());
        goodsSealLimitDto.setOrderItemDtoList(Lists.newArrayList());
        pageOrder.getItems().forEach(e->{
            goodsSealLimitDto.getOrderItemDtoList().add(BeanUtil.copyProperties(e, OrderItemDto.class));
        });
        shoppingGoodsService.checkGoodsSealLimit(goodsSealLimitDto);
        //检查业绩设置
        checkOrderAchieve(pageOrder);
    }
    /**
     * 检查业绩设置是否合理
@@ -638,40 +655,7 @@
    }
    /**
     * 检查产品销售次数
     */
    private void checkSealLimit(SysOrder pageOrder) {
        pageOrder.getItems().forEach(item -> {
            ShoppingGoods shopGoods = shoppingGoodsDao.selectById(item.getGoodsId());
            //最大销售次数检测
            Integer maxNum = shopGoods.getCarMaxSaleCount();
            if (maxNum != null && maxNum != 0) {
                Integer buyNum = orderItemDao.selectByGoodsId(shopGoods.getId(), null);
                if ((buyNum + item.getCount()) > maxNum) {
                    throw new GlobleException(shopGoods.getName() + "已超过最大销售数量");
                }
                if ((buyNum + item.getCount()) == maxNum) {
                    if (!shopGoods.getStaus().equals(Dictionary.BUSINESS_STATE_DOWN)) {
                        shopGoods.setStaus(Dictionary.BUSINESS_STATE_DOWN);
                        shoppingGoodsDao.update(shopGoods);
                    }
                }
            }
            //每人限购次数检测
            Integer onceCount = shopGoods.getIsOnce();
            if (onceCount != null && onceCount != 0) {
                Integer buyOnceCount = orderItemDao.selectByGoodsId(shopGoods.getId(), pageOrder.getVipId());
                if ((buyOnceCount + item.getCount()) > onceCount) {
                    throw new GlobleException(shopGoods.getName() + "每人限购" + onceCount + "次");
                }
            }
        });
    }
    /**
@@ -1045,7 +1029,7 @@
     * @date 2016年9月19日
     */
    public void addMoneyCardUse(SysOrder sourceOrder) {
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        List<SysOrderItem> orderItemList = sourceOrder.getItems();
        for (SysOrderItem sysOrderItem : orderItemList) {
            // 如果购买的是充值卡
@@ -1084,6 +1068,7 @@
                    moneyCardUse.setFailTime(invalidTime);
                    moneyCardUseDao.insert(moneyCardUse);
                }
            }
        }