xiaoyong931011
2021-04-12 a13a93a493e7e94e28b2225c26e7e13b52d3288c
zq-erp/src/main/java/com/matrix/system/shopXcx/api/service/ShoppingCartService.java
@@ -1,8 +1,6 @@
package com.matrix.system.shopXcx.api.service;
import com.matrix.biz.bean.BizUser;
import com.matrix.component.redis.RedisUserLoginUtils;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.tools.LogUtil;
import com.matrix.system.common.dao.BusParameterSettingsDao;
import com.matrix.system.shopXcx.api.vo.ShopCartBillVo;
@@ -33,7 +31,7 @@
    @Autowired
    BusParameterSettingsDao busParameterSettingsDao;
    //计算购车选中项总价以及优惠金额
    public ShopCartBillVo buildShopCartBillVo(List<ShopCartVo> cartList) {
        ShopCartBillVo shopCartBillVo = new ShopCartBillVo();
@@ -65,23 +63,10 @@
        }
        shopCartBillVo.setCartCount(cartCount);
        shopCartBillVo.setSelectCount(selectCount);
        return shopCartBillVo;
    }
    /**
     * 计算用户的购物车产品优惠分组
     *
     * @return
     * @param shopId
     */
    public List<ShopCartVo> findUserCartList(Long shopId,Integer cartType) {
        BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class);
        String userId = loginUser.getOpenId();
        List<ShopShoppingCart> list = shoppingCartDao.selectByCartUserId(shopId,userId,cartType);
        List<ShopCartVo> cartList = buildShopCart(list);
        return cartList;
    }
    /**
@@ -91,7 +76,7 @@
     * @return
     */
    @SuppressWarnings("unchecked")
    private List<ShopCartVo> buildShopCart(List<ShopShoppingCart> list) {
    public List<ShopCartVo> buildShopCart(List<ShopShoppingCart> list) {
        //定义购物车优惠分组
@@ -112,23 +97,19 @@
        //查询购物车中的产品匹配上的所有优惠活动
        for (ShopShoppingCart shoppingCart : list) {
            if(shoppingCart.getCartType()==ShopShoppingCart.CAR_TYPE_SCORE){
                // 积分兑换产品不参加优惠
                def.getCartList().add(shoppingCart);
            }else{
                List<ShopCoupon> shopCoupons = shopCouponService.getHdListByProductId(shoppingCart.getCartProductId());
                if (CollectionUtils.isNotEmpty(shopCoupons)) {
                    // 把所有的优惠券和购物车条目先关联一下,后续可以计算优惠升级的情况
                    shoppingCart.setShopCoupons(shopCoupons);
                    for (ShopCoupon shopCoupon : shopCoupons) {
                        shopCouponMap.put(shopCoupon.getId(), shopCoupon);
                    }
                } else {
                    // 该产品没有参加优惠券
                    def.getCartList().add(shoppingCart);
                }
            }
            List<ShopCoupon> shopCoupons = shopCouponService.getHdListByProductId(shoppingCart.getCartProductId());
            if (CollectionUtils.isNotEmpty(shopCoupons)) {
                // 把所有的优惠券和购物车条目先关联一下,后续可以计算优惠升级的情况
                shoppingCart.setShopCoupons(shopCoupons);
                for (ShopCoupon shopCoupon : shopCoupons) {
                    shopCouponMap.put(shopCoupon.getId(), shopCoupon);
                }
            } else {
                // 该产品没有参加优惠券
                def.getCartList().add(shoppingCart);
            }
        }
        //计算没有优惠组的价格
@@ -270,28 +251,19 @@
        List<ShopShoppingCart> cartList = shopCartVo.getCartList();
        // 计算总价
        BigDecimal sum = BigDecimal.ZERO;
        //抵扣总积分
        BigDecimal scoreSum = BigDecimal.ZERO;
        // 选中项总价
        BigDecimal selectSum = BigDecimal.ZERO;
        for (ShopShoppingCart shopShoppingCart : cartList) {
            if(ShopShoppingCart.CAR_TYPE_MICRO==shopShoppingCart.getCartType()){
                //直接购买
                sum = sum.add(shopShoppingCart.getPrice().multiply(BigDecimal.valueOf(shopShoppingCart.getCartNumber())));
                if (shopShoppingCart.getIsSelected() == 1) {
            sum = sum.add(shopShoppingCart.getPrice().multiply(BigDecimal.valueOf(shopShoppingCart.getCartNumber())));
            if (shopShoppingCart.getIsSelected() == 1) {
                if(shopShoppingCart.getCartType()==ShopShoppingCart.CAR_TYPE_MICRO){
                    selectSum = selectSum
                            .add(shopShoppingCart.getPrice().multiply(BigDecimal.valueOf(shopShoppingCart.getCartNumber())));
                }
            }else if(ShopShoppingCart.CAR_TYPE_SCORE==shopShoppingCart.getCartType()){
                //积分兑换
                sum = sum.add(shopShoppingCart.getScorePrice().multiply(BigDecimal.valueOf(shopShoppingCart.getCartNumber())));
                if (shopShoppingCart.getIsSelected() == 1) {
                }else {
                    selectSum = selectSum
                            .add(shopShoppingCart.getScorePrice().multiply(BigDecimal.valueOf(shopShoppingCart.getCartNumber())));
                    scoreSum = scoreSum.add(new BigDecimal(shopShoppingCart.getScoreCount() * shopShoppingCart.getCartNumber()));
                }
            }else{
                throw new GlobleException("参数错误");
            }
        }
@@ -322,10 +294,9 @@
                }
            }
        } else {
                shopCartVo.setSubtotal(selectSum);
                shopCartVo.setSrcPrice(selectSum);
                shopCartVo.setSatisfactionCoupon(true);
            shopCartVo.setSubtotal(selectSum);
            shopCartVo.setSrcPrice(selectSum);
            shopCartVo.setSatisfactionCoupon(true);
        }
        shopCartVo.setScorePay(scoreSum);
    }
}