|
@@ -1,5 +1,6 @@
|
|
|
package com.caimei.service.impl;
|
|
|
|
|
|
+import com.caimei.mapper.CouponMapper;
|
|
|
import com.caimei.mapper.OrderMapper;
|
|
|
import com.caimei.mapper.ProductMapper;
|
|
|
import com.caimei.mapper.ShoppingCartMapper;
|
|
@@ -17,9 +18,7 @@ import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* Description
|
|
@@ -35,6 +34,8 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
|
|
private ProductMapper productMapper;
|
|
|
@Resource
|
|
|
private OrderMapper orderMapper;
|
|
|
+ @Resource
|
|
|
+ private CouponMapper couponMapper;
|
|
|
@Value("${caimei.oldapi}")
|
|
|
private String domain;
|
|
|
|
|
@@ -66,7 +67,7 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
|
|
shopList.forEach(shop -> {
|
|
|
shop.setLogo(ProductUtils.getImageURL("shopLogo", shop.getLogo(), 0, domain));
|
|
|
BigDecimal shopTotalPrice = BigDecimal.ZERO;
|
|
|
- List<CartProductVo> productList = shoppingCartMapper.findByShopCartProduct(shop.getShopId(), userId);
|
|
|
+ List<CartProductVo> productList = shoppingCartMapper.getCartProductsByShopId(shop.getShopId(), userId);
|
|
|
for (CartProductVo product : productList) {
|
|
|
setPrice(product, userId, null);
|
|
|
shopTotalPrice = MathUtil.add(shopTotalPrice, MathUtil.mul(product.getProductCount(), product.getPrice()));
|
|
@@ -76,7 +77,7 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
|
|
});
|
|
|
map.put("shopList", shopList);
|
|
|
//失效商品
|
|
|
- List<CartProductVo> products = shoppingCartMapper.findExpiredGoods(userId);
|
|
|
+ List<CartProductVo> products = shoppingCartMapper.getInvalidProducts(userId);
|
|
|
map.put("products", products);
|
|
|
//商品数量
|
|
|
Integer cartQuantity = shoppingCartMapper.getCartQuantity(userId);
|
|
@@ -88,20 +89,20 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
|
|
* 设置活动价格阶梯
|
|
|
*/
|
|
|
@Override
|
|
|
- public void setPrice(CartProductVo product, Integer userId, Integer collageFlag) {
|
|
|
- //税费
|
|
|
- boolean addTaxFlag = ("0".equals(product.getIncludedTax()) && ("1".equals(product.getInvoiceType()) || "2".equals(product.getInvoiceType())));
|
|
|
- // 活动id
|
|
|
- Integer activityId = productMapper.findActivityByProductId(product.getProductId());
|
|
|
+ public void setPrice(CartProductVo product, Integer userId, Integer collageFlag) {// 活动id
|
|
|
+ Integer activityId = productMapper.getActivityIdByProductId(product.getProductId());
|
|
|
// 拼团商品
|
|
|
CmHeheCollageProductPo collageProduct = productMapper.findCollageProduct(product.getProductId());
|
|
|
+ // 限时特价
|
|
|
+ BigDecimal discountPrice = productMapper.getDiscountPrice(product.getProductId());
|
|
|
if (activityId != null && activityId > 0) {
|
|
|
product.setActiveStatus(1);
|
|
|
//活动阶梯
|
|
|
- List<ActivityLadderVo> ladderList = productMapper.findActivityLadder(activityId, product.getProductId());
|
|
|
+ List<ActivityLadderVo> ladderList = productMapper.getActivityLadderList(activityId, product.getProductId());
|
|
|
if (ladderList != null && ladderList.size() > 0) {
|
|
|
for (ActivityLadderVo ladder : ladderList) {
|
|
|
if (product.getProductCount() >= ladder.getBuyNum()) {
|
|
|
+ // 根据商品数量设置价格
|
|
|
product.setPrice(ladder.getBuyPrice());
|
|
|
}
|
|
|
}
|
|
@@ -110,29 +111,86 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
|
|
} else if (null != collageProduct && null != collageFlag && 1 == collageFlag) {
|
|
|
product.setCollageStatus(1);
|
|
|
product.setPrice(collageProduct.getPrice());
|
|
|
+ } else if (discountPrice != null) {
|
|
|
+ // 限时特价
|
|
|
+ product.setPrice(discountPrice);
|
|
|
+ product.setDiscountStatus(1);
|
|
|
}
|
|
|
List<ActivityLadderVo> ladderList = product.getLadderList();
|
|
|
- // 查询商品折扣,设置折扣价
|
|
|
+ // 内部优惠折扣
|
|
|
Integer discount = productMapper.findProductDiscount(product.getProductId(), userId);
|
|
|
if (null != discount && discount > 0) {
|
|
|
- product.setPrice(MathUtil.div(MathUtil.mul(product.getPrice(), discount), 100));
|
|
|
+ product.setPrice(MathUtil.div(MathUtil.mul(product.getPrice(), discount), 100, 2));
|
|
|
+ if (null != product.getNormalPrice()) {
|
|
|
+ product.setNormalPrice(MathUtil.div(MathUtil.mul(product.getNormalPrice(), discount), 100, 2));
|
|
|
+ }
|
|
|
if (null != ladderList) {
|
|
|
- ladderList.forEach(ladder->{
|
|
|
- ladder.setBuyPrice((MathUtil.div(MathUtil.mul(ladder.getBuyPrice(), discount), 100)));
|
|
|
- });
|
|
|
+ ladderList.forEach(ladder-> ladder.setBuyPrice((MathUtil.div(MathUtil.mul(ladder.getBuyPrice(), discount), 100, 2))));
|
|
|
}
|
|
|
}
|
|
|
+ //税费
|
|
|
+ boolean addTaxFlag = ("0".equals(product.getIncludedTax()) && ("1".equals(product.getInvoiceType()) || "2".equals(product.getInvoiceType())));
|
|
|
// 为商品价格和阶梯列表添加税费
|
|
|
if (addTaxFlag) {
|
|
|
BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(product.getPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
|
|
|
- product.setPrice(MathUtil.add(addedValueTax, product.getPrice()));
|
|
|
+ BigDecimal price = MathUtil.add(product.getPrice(), addedValueTax);
|
|
|
+ product.setPrice(price);
|
|
|
+ if (null != product.getNormalPrice()) {
|
|
|
+ addedValueTax = MathUtil.div(MathUtil.mul(product.getNormalPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
|
|
|
+ price = MathUtil.add(product.getNormalPrice(), addedValueTax);
|
|
|
+ product.setNormalPrice(price);
|
|
|
+ }
|
|
|
if (null != ladderList) {
|
|
|
ladderList.forEach(ladder->{
|
|
|
BigDecimal ladderTax = MathUtil.div(MathUtil.mul(ladder.getBuyPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
|
|
|
- ladder.setBuyPrice(MathUtil.add(ladderTax, ladder.getBuyPrice()));
|
|
|
+ ladder.setBuyPrice(MathUtil.add(ladder.getBuyPrice(), ladderTax));
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
+ // 查询用户的注册时间
|
|
|
+ Date registerTime = couponMapper.getUserRegisterTime(userId);
|
|
|
+ String[] productIdArr = {product.getProductId().toString()};
|
|
|
+ // 用户在该商品上可领取的优惠券列表
|
|
|
+ List<CouponVo> couponList = couponMapper.findCouponList(userId, productIdArr, registerTime, null);
|
|
|
+ if (null != userId) {
|
|
|
+ // 用户在该商品上已领取未使用的优惠券列表
|
|
|
+ List<CouponVo> receiveCouponList = couponMapper.findReceiveCouponList(userId, productIdArr, null, 1);
|
|
|
+ couponList.addAll(receiveCouponList);
|
|
|
+ }
|
|
|
+ // 单价满足优惠条件的优惠券列表
|
|
|
+ List<CouponVo> ableCouponList = new ArrayList<>();
|
|
|
+ // 单价不满足优惠条件的优惠券列表
|
|
|
+ List<CouponVo> unableCouponList = new ArrayList<>();
|
|
|
+ if (couponList.size() > 0) {
|
|
|
+ // 有可用优惠券
|
|
|
+ couponList.forEach(coupon->{
|
|
|
+ if (1 == coupon.getNoThresholdFlag() || MathUtil.compare(product.getPrice(), coupon.getTouchPrice()) > 0) {
|
|
|
+ ableCouponList.add(coupon);
|
|
|
+ } else {
|
|
|
+ unableCouponList.add(coupon);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (ableCouponList.size() > 0) {
|
|
|
+ // 根据优惠金额排序,优惠金额大的排前面
|
|
|
+ ableCouponList.sort((o1, o2) -> o2.getCouponAmount().compareTo(o1.getCouponAmount()));
|
|
|
+ CouponVo biggestCoupon = ableCouponList.get(0);
|
|
|
+ // 现价-最大优惠金额=券后价
|
|
|
+ product.setCouponPrice(MathUtil.sub(product.getPrice(), biggestCoupon.getCouponAmount()));
|
|
|
+ // 原价-最大优惠金额=原价券后价
|
|
|
+ product.setNormalCouponPrice(MathUtil.sub(product.getNormalPrice(), biggestCoupon.getCouponAmount()));
|
|
|
+ // 优惠券id
|
|
|
+ product.setCouponId(biggestCoupon.getCouponId());
|
|
|
+ // 券后价标签
|
|
|
+ product.setCouponStatus(1);
|
|
|
+ } else {
|
|
|
+ // 根据优惠条件排序,条件小的排前面
|
|
|
+ unableCouponList.sort(Comparator.comparing(CouponVo::getTouchPrice));
|
|
|
+ // 优惠券信息
|
|
|
+ product.setCouponStatus(2);
|
|
|
+ CouponVo smallestCoupon = unableCouponList.get(0);
|
|
|
+ product.setCouponInfo("券|满" + smallestCoupon.getTouchPrice() + "元减" + smallestCoupon.getCouponAmount());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -149,7 +207,7 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
|
|
|
cart.setProductCount(orderProduct.getNum());
|
|
|
Integer heUserId = orderProduct.getHeUserId();
|
|
|
if (heUserId != null && heUserId > 0) {
|
|
|
- Integer activityId = productMapper.findActivityByProductId(orderProduct.getProductId());
|
|
|
+ Integer activityId = productMapper.getActivityIdByProductId(orderProduct.getProductId());
|
|
|
if (activityId != null && activityId > 0) {
|
|
|
cart.setHeUserId(heUserId);
|
|
|
} else {
|