结算页优惠券金额错误问题处理。
购物车相关金额渲染代码优化
This commit is contained in:
parent
6c95679ad2
commit
db56984cf3
@ -6,13 +6,15 @@ package cn.lili.modules.order.cart.entity.enums;
|
|||||||
public enum RenderStepEnums {
|
public enum RenderStepEnums {
|
||||||
|
|
||||||
CHECK_DATA("校验商品"),
|
CHECK_DATA("校验商品"),
|
||||||
|
CHECKED_FILTER("选择商品过滤"),
|
||||||
CART_SN("交易编号创建"),
|
CART_SN("交易编号创建"),
|
||||||
COUPON("优惠券价格渲染"),
|
COUPON("优惠券价格渲染"),
|
||||||
SKU_FREIGHT("运费计算"),
|
SKU_FREIGHT("运费计算"),
|
||||||
SKU_PROMOTION("商品促销计算"),
|
SKU_PROMOTION("商品促销计算"),
|
||||||
|
FULL_DISCOUNT("满减计算"),
|
||||||
CART_PRICE("购物车金额计算"),
|
CART_PRICE("购物车金额计算"),
|
||||||
DISTRIBUTION("分销佣金计算"),
|
DISTRIBUTION("分销人员佣金计算"),
|
||||||
FULL_DISCOUNT("满减计算");
|
PLATFORM_COMMISSION("平台佣金");
|
||||||
|
|
||||||
private String distribution;
|
private String distribution;
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ public interface CartRenderStep {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染一笔交易
|
* 渲染一笔交易
|
||||||
* 0-》 校验商品 1-》 满优惠渲染 2-》渲染优惠 3-》优惠券渲染 4-》计算运费 5-》计算价格 6-》分销渲染 7-》其他渲染
|
|
||||||
*
|
*
|
||||||
* @param tradeDTO 交易DTO
|
* @param tradeDTO 交易DTO
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,80 @@
|
|||||||
|
package cn.lili.modules.order.cart.render;
|
||||||
|
|
||||||
|
import cn.lili.modules.order.cart.entity.enums.RenderStepEnums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 价格渲染 步骤声明
|
||||||
|
*
|
||||||
|
* @author Chopper
|
||||||
|
* @version v1.0
|
||||||
|
* 2021-08-13 16:15
|
||||||
|
*/
|
||||||
|
public class RenderStepStatement {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 购物车购物车渲染
|
||||||
|
* 校验商品 》 满优惠渲染 》 渲染优惠 》计算价格
|
||||||
|
*/
|
||||||
|
public static RenderStepEnums[] cartRender = {
|
||||||
|
RenderStepEnums.CHECK_DATA,
|
||||||
|
RenderStepEnums.FULL_DISCOUNT,
|
||||||
|
RenderStepEnums.SKU_PROMOTION,
|
||||||
|
RenderStepEnums.CART_PRICE};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结算页渲染
|
||||||
|
* 过滤选择的商品 》 校验商品 》 满优惠渲染 》 渲染优惠 》
|
||||||
|
* 优惠券渲染 》 计算运费 》 计算价格
|
||||||
|
*/
|
||||||
|
public static RenderStepEnums[] checkedRender = {
|
||||||
|
RenderStepEnums.CHECKED_FILTER,
|
||||||
|
RenderStepEnums.CHECK_DATA,
|
||||||
|
RenderStepEnums.FULL_DISCOUNT,
|
||||||
|
RenderStepEnums.SKU_PROMOTION,
|
||||||
|
RenderStepEnums.COUPON,
|
||||||
|
RenderStepEnums.SKU_FREIGHT,
|
||||||
|
RenderStepEnums.CART_PRICE,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单个商品优惠,不需要渲染满减优惠
|
||||||
|
* 用于特殊场景:例如积分商品,拼团商品,虚拟商品等等
|
||||||
|
*/
|
||||||
|
public static RenderStepEnums[] checkedSingleRender = {
|
||||||
|
RenderStepEnums.CHECK_DATA,
|
||||||
|
RenderStepEnums.SKU_PROMOTION,
|
||||||
|
RenderStepEnums.SKU_FREIGHT,
|
||||||
|
RenderStepEnums.CART_PRICE
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 交易创建前渲染
|
||||||
|
* 渲染购物车 生成SN 》分销人员佣金渲染 》平台佣金渲染
|
||||||
|
*/
|
||||||
|
public static RenderStepEnums[] singleTradeRender = {
|
||||||
|
RenderStepEnums.CHECK_DATA,
|
||||||
|
RenderStepEnums.SKU_PROMOTION,
|
||||||
|
RenderStepEnums.SKU_FREIGHT,
|
||||||
|
RenderStepEnums.CART_PRICE,
|
||||||
|
RenderStepEnums.CART_SN,
|
||||||
|
RenderStepEnums.DISTRIBUTION,
|
||||||
|
RenderStepEnums.PLATFORM_COMMISSION
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* 交易创建前渲染
|
||||||
|
* 渲染购物车 生成SN 》分销人员佣金渲染 》平台佣金渲染
|
||||||
|
*/
|
||||||
|
public static RenderStepEnums[] tradeRender = {
|
||||||
|
RenderStepEnums.CHECKED_FILTER,
|
||||||
|
RenderStepEnums.CHECK_DATA,
|
||||||
|
RenderStepEnums.FULL_DISCOUNT,
|
||||||
|
RenderStepEnums.SKU_PROMOTION,
|
||||||
|
RenderStepEnums.COUPON,
|
||||||
|
RenderStepEnums.SKU_FREIGHT,
|
||||||
|
RenderStepEnums.CART_PRICE,
|
||||||
|
RenderStepEnums.CART_SN,
|
||||||
|
RenderStepEnums.DISTRIBUTION,
|
||||||
|
RenderStepEnums.PLATFORM_COMMISSION
|
||||||
|
};
|
||||||
|
}
|
@ -3,8 +3,6 @@ package cn.lili.modules.order.cart.render;
|
|||||||
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
|
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
|
||||||
import cn.lili.modules.order.cart.entity.enums.CartTypeEnum;
|
import cn.lili.modules.order.cart.entity.enums.CartTypeEnum;
|
||||||
import cn.lili.modules.order.cart.entity.enums.RenderStepEnums;
|
import cn.lili.modules.order.cart.entity.enums.RenderStepEnums;
|
||||||
import cn.lili.modules.order.cart.entity.vo.CartSkuVO;
|
|
||||||
import cn.lili.modules.order.cart.entity.vo.CartVO;
|
|
||||||
import cn.lili.modules.order.cart.service.CartService;
|
import cn.lili.modules.order.cart.service.CartService;
|
||||||
import cn.lili.modules.order.order.entity.dos.Trade;
|
import cn.lili.modules.order.order.entity.dos.Trade;
|
||||||
import cn.lili.modules.order.order.service.TradeService;
|
import cn.lili.modules.order.order.service.TradeService;
|
||||||
@ -12,9 +10,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 交易构造&&创建
|
* 交易构造&&创建
|
||||||
@ -43,44 +39,6 @@ public class TradeBuilder {
|
|||||||
private CartService cartService;
|
private CartService cartService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 渲染整比交易
|
|
||||||
* 校验商品 》 满优惠渲染 》 渲染优惠 》 优惠券渲染 》 计算运费 》 计算价格 》 分销渲染 》 订单SN初始化
|
|
||||||
*/
|
|
||||||
RenderStepEnums[] defaultRender = {
|
|
||||||
RenderStepEnums.CHECK_DATA,
|
|
||||||
RenderStepEnums.FULL_DISCOUNT,
|
|
||||||
RenderStepEnums.SKU_PROMOTION,
|
|
||||||
RenderStepEnums.COUPON,
|
|
||||||
RenderStepEnums.SKU_FREIGHT,
|
|
||||||
RenderStepEnums.CART_PRICE,
|
|
||||||
RenderStepEnums.DISTRIBUTION,
|
|
||||||
RenderStepEnums.CART_SN
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 单个商品优惠,不需要渲染满减优惠
|
|
||||||
* 用于特殊场景:例如积分商品,拼团商品,虚拟商品等等
|
|
||||||
*/
|
|
||||||
RenderStepEnums[] singleRender = {
|
|
||||||
RenderStepEnums.CHECK_DATA,
|
|
||||||
RenderStepEnums.SKU_PROMOTION,
|
|
||||||
RenderStepEnums.SKU_FREIGHT,
|
|
||||||
RenderStepEnums.CART_PRICE,
|
|
||||||
RenderStepEnums.DISTRIBUTION,
|
|
||||||
RenderStepEnums.CART_SN};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 购物车购物车渲染
|
|
||||||
* 校验商品 》 满优惠渲染 》 渲染优惠 》计算价格
|
|
||||||
*/
|
|
||||||
RenderStepEnums[] cartRender = {
|
|
||||||
RenderStepEnums.CHECK_DATA,
|
|
||||||
RenderStepEnums.FULL_DISCOUNT,
|
|
||||||
RenderStepEnums.SKU_PROMOTION,
|
|
||||||
RenderStepEnums.CART_PRICE};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造购物车
|
* 构造购物车
|
||||||
* 购物车与结算信息不一致的地方主要是优惠券计算和运费计算,其他规则都是一致都
|
* 购物车与结算信息不一致的地方主要是优惠券计算和运费计算,其他规则都是一致都
|
||||||
@ -99,73 +57,23 @@ public class TradeBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//按照计划进行渲染
|
//按照计划进行渲染
|
||||||
for (RenderStepEnums step : cartRender) {
|
renderCartBySteps(tradeDTO, RenderStepStatement.cartRender);
|
||||||
for (CartRenderStep render : cartRenderSteps) {
|
|
||||||
try {
|
|
||||||
if (render.step().equals(step)) {
|
|
||||||
render.render(tradeDTO);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("购物车{}渲染异常:", render.getClass(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tradeDTO;
|
return tradeDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造一笔交易
|
* 构造结算页面
|
||||||
* 1.从缓存中读取交易数据
|
|
||||||
* 2.从购物车列表中筛选出已选择的SKU列表存入交易中
|
|
||||||
* 3.渲染整个交易(0-> 校验商品 1-》 满优惠渲染 2->渲染优惠 3->优惠券渲染 4->计算运费 5->计算价格 6->分销渲染 7->其他渲染)
|
|
||||||
* 4.将已选择的购物车列表存入交易中
|
|
||||||
*
|
|
||||||
* @param checkedWay 购物车类型
|
|
||||||
* @return 购物车展示信息
|
|
||||||
*/
|
*/
|
||||||
public TradeDTO buildTrade(CartTypeEnum checkedWay) {
|
public TradeDTO buildChecked(CartTypeEnum checkedWay) {
|
||||||
//读取对应购物车的商品信息
|
//读取对应购物车的商品信息
|
||||||
TradeDTO tradeDTO = cartService.readDTO(checkedWay);
|
TradeDTO tradeDTO = cartService.readDTO(checkedWay);
|
||||||
//将购物车到sku未选择信息过滤
|
//需要对购物车渲染
|
||||||
List<CartSkuVO> collect = tradeDTO.getSkuList().parallelStream().filter(i -> Boolean.TRUE.equals(i.getChecked())).collect(Collectors.toList());
|
if (isSingle(checkedWay)) {
|
||||||
tradeDTO.setSkuList(collect);
|
renderCartBySteps(tradeDTO, RenderStepStatement.checkedRender);
|
||||||
if (checkedWay.equals(CartTypeEnum.CART) || checkedWay.equals(CartTypeEnum.BUY_NOW) || checkedWay.equals(CartTypeEnum.VIRTUAL)) {
|
|
||||||
//按照计划进行渲染
|
|
||||||
for (RenderStepEnums step : defaultRender) {
|
|
||||||
for (CartRenderStep render : cartRenderSteps) {
|
|
||||||
try {
|
|
||||||
if (render.step().equals(step)) {
|
|
||||||
render.render(tradeDTO);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("购物车{}渲染异常:", render.getClass(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
for (RenderStepEnums step : singleRender) {
|
renderCartBySteps(tradeDTO, RenderStepStatement.checkedSingleRender);
|
||||||
for (CartRenderStep render : cartRenderSteps) {
|
|
||||||
try {
|
|
||||||
if (render.step().equals(step)) {
|
|
||||||
render.render(tradeDTO);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("购物车{}渲染异常:", render.getClass(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//购物车信息接受
|
|
||||||
List<CartVO> cartVOList = new ArrayList<>();
|
|
||||||
//循环购物车信息
|
|
||||||
for (CartVO cartVO : tradeDTO.getCartList()) {
|
|
||||||
//如果商品选中,则加入到对应购物车
|
|
||||||
cartVO.setSkuList(cartVO.getSkuList().stream().filter(j -> Boolean.TRUE.equals(j.getChecked())).collect(Collectors.toList()));
|
|
||||||
cartVOList.add(cartVO);
|
|
||||||
}
|
|
||||||
tradeDTO.setCartList(cartVOList);
|
|
||||||
return tradeDTO;
|
return tradeDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +86,47 @@ public class TradeBuilder {
|
|||||||
* @return 交易信息
|
* @return 交易信息
|
||||||
*/
|
*/
|
||||||
public Trade createTrade(CartTypeEnum checkedWay) {
|
public Trade createTrade(CartTypeEnum checkedWay) {
|
||||||
TradeDTO tradeDTO = this.buildTrade(checkedWay);
|
//读取对应购物车的商品信息
|
||||||
|
TradeDTO tradeDTO = cartService.readDTO(checkedWay);
|
||||||
|
|
||||||
|
//需要对购物车渲染
|
||||||
|
if (isSingle(checkedWay)) {
|
||||||
|
renderCartBySteps(tradeDTO, RenderStepStatement.singleTradeRender);
|
||||||
|
} else {
|
||||||
|
renderCartBySteps(tradeDTO, RenderStepStatement.tradeRender);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return tradeService.createTrade(tradeDTO);
|
return tradeService.createTrade(tradeDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否为单品渲染
|
||||||
|
*
|
||||||
|
* @param checkedWay 购物车类型
|
||||||
|
* @return 返回是否单品
|
||||||
|
*/
|
||||||
|
private boolean isSingle(CartTypeEnum checkedWay) {
|
||||||
|
return (checkedWay.equals(CartTypeEnum.CART) || checkedWay.equals(CartTypeEnum.BUY_NOW) || checkedWay.equals(CartTypeEnum.VIRTUAL));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据渲染步骤,渲染购物车信息
|
||||||
|
*
|
||||||
|
* @param tradeDTO 交易DTO
|
||||||
|
* @param defaultRender 渲染枚举
|
||||||
|
*/
|
||||||
|
private void renderCartBySteps(TradeDTO tradeDTO, RenderStepEnums[] defaultRender) {
|
||||||
|
for (RenderStepEnums step : defaultRender) {
|
||||||
|
for (CartRenderStep render : cartRenderSteps) {
|
||||||
|
try {
|
||||||
|
if (render.step().equals(step)) {
|
||||||
|
render.render(tradeDTO);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("购物车{}渲染异常:", render.getClass(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ import cn.lili.modules.promotion.entity.vos.PointsGoodsVO;
|
|||||||
import cn.lili.modules.promotion.service.KanjiaActivityGoodsService;
|
import cn.lili.modules.promotion.service.KanjiaActivityGoodsService;
|
||||||
import cn.lili.modules.promotion.service.PointsGoodsService;
|
import cn.lili.modules.promotion.service.PointsGoodsService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.annotation.Order;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -29,7 +28,6 @@ import java.util.Map;
|
|||||||
* @author Chopper
|
* @author Chopper
|
||||||
* @see CartVO
|
* @see CartVO
|
||||||
*/
|
*/
|
||||||
@Order(5)
|
|
||||||
@Service
|
@Service
|
||||||
public class CartPriceRender implements CartRenderStep {
|
public class CartPriceRender implements CartRenderStep {
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import org.springframework.stereotype.Service;
|
|||||||
* @author Chopper
|
* @author Chopper
|
||||||
* @since 2020-07-02 14:47
|
* @since 2020-07-02 14:47
|
||||||
*/
|
*/
|
||||||
@Order(7)
|
|
||||||
@Service
|
@Service
|
||||||
public class CartSnRender implements CartRenderStep {
|
public class CartSnRender implements CartRenderStep {
|
||||||
|
|
||||||
|
@ -40,7 +40,6 @@ import java.util.stream.Collectors;
|
|||||||
* @author Chopper
|
* @author Chopper
|
||||||
* @since 2020-07-02 14:47
|
* @since 2020-07-02 14:47
|
||||||
*/
|
*/
|
||||||
@Order(0)
|
|
||||||
@Service
|
@Service
|
||||||
public class CheckDataRender implements CartRenderStep {
|
public class CheckDataRender implements CartRenderStep {
|
||||||
|
|
||||||
|
@ -0,0 +1,46 @@
|
|||||||
|
package cn.lili.modules.order.cart.render.impl;
|
||||||
|
|
||||||
|
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
|
||||||
|
import cn.lili.modules.order.cart.entity.enums.RenderStepEnums;
|
||||||
|
import cn.lili.modules.order.cart.entity.vo.CartSkuVO;
|
||||||
|
import cn.lili.modules.order.cart.entity.vo.CartVO;
|
||||||
|
import cn.lili.modules.order.cart.render.CartRenderStep;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 佣金计算
|
||||||
|
*
|
||||||
|
* @author Chopper
|
||||||
|
* @see CartVO
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class CheckedFilterRender implements CartRenderStep {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderStepEnums step() {
|
||||||
|
return RenderStepEnums.CHECKED_FILTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(TradeDTO tradeDTO) {
|
||||||
|
//将购物车到sku未选择信息过滤
|
||||||
|
List<CartSkuVO> collect = tradeDTO.getSkuList().parallelStream().filter(i -> Boolean.TRUE.equals(i.getChecked())).collect(Collectors.toList());
|
||||||
|
tradeDTO.setSkuList(collect);
|
||||||
|
|
||||||
|
//购物车信息过滤
|
||||||
|
List<CartVO> cartVOList = new ArrayList<>();
|
||||||
|
//循环购物车信息
|
||||||
|
for (CartVO cartVO : tradeDTO.getCartList()) {
|
||||||
|
//如果商品选中,则加入到对应购物车
|
||||||
|
cartVO.setSkuList(cartVO.getSkuList().stream().filter(j -> Boolean.TRUE.equals(j.getChecked())).collect(Collectors.toList()));
|
||||||
|
cartVOList.add(cartVO);
|
||||||
|
}
|
||||||
|
tradeDTO.setCartList(cartVOList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,118 @@
|
|||||||
|
package cn.lili.modules.order.cart.render.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.lili.modules.goods.service.CategoryService;
|
||||||
|
import cn.lili.modules.order.cart.entity.dto.TradeDTO;
|
||||||
|
import cn.lili.modules.order.cart.entity.enums.CartTypeEnum;
|
||||||
|
import cn.lili.modules.order.cart.entity.enums.RenderStepEnums;
|
||||||
|
import cn.lili.modules.order.cart.entity.vo.CartSkuVO;
|
||||||
|
import cn.lili.modules.order.cart.entity.vo.CartVO;
|
||||||
|
import cn.lili.modules.order.cart.render.CartRenderStep;
|
||||||
|
import cn.lili.modules.order.order.entity.dto.PriceDetailDTO;
|
||||||
|
import cn.lili.modules.promotion.entity.dto.KanjiaActivityGoodsDTO;
|
||||||
|
import cn.lili.modules.promotion.entity.vos.PointsGoodsVO;
|
||||||
|
import cn.lili.modules.promotion.service.KanjiaActivityGoodsService;
|
||||||
|
import cn.lili.modules.promotion.service.PointsGoodsService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 佣金计算
|
||||||
|
*
|
||||||
|
* @author Chopper
|
||||||
|
* @see CartVO
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class CommissionRender implements CartRenderStep {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品分类
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private CategoryService categoryService;
|
||||||
|
/**
|
||||||
|
* 积分商品
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private PointsGoodsService pointsGoodsService;
|
||||||
|
/**
|
||||||
|
* 砍价商品
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private KanjiaActivityGoodsService kanjiaActivityGoodsService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderStepEnums step() {
|
||||||
|
return RenderStepEnums.PLATFORM_COMMISSION;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(TradeDTO tradeDTO) {
|
||||||
|
buildCartPrice(tradeDTO);
|
||||||
|
buildTradePrice(tradeDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 购物车佣金计算
|
||||||
|
*
|
||||||
|
* @param tradeDTO 购物车展示信息
|
||||||
|
*/
|
||||||
|
void buildCartPrice(TradeDTO tradeDTO) {
|
||||||
|
//购物车列表
|
||||||
|
List<CartVO> cartVOS = tradeDTO.getCartList();
|
||||||
|
|
||||||
|
//计算购物车价格
|
||||||
|
for (CartVO cart : cartVOS) {
|
||||||
|
//累加价格
|
||||||
|
List<PriceDetailDTO> priceDetailDTOS = new ArrayList<>();
|
||||||
|
for (CartSkuVO cartSkuVO : cart.getSkuList()) {
|
||||||
|
|
||||||
|
PriceDetailDTO priceDetailDTO = cartSkuVO.getPriceDetailDTO();
|
||||||
|
//平台佣金根据分类计算
|
||||||
|
String categoryId = cartSkuVO.getGoodsSku().getCategoryPath()
|
||||||
|
.substring(cartSkuVO.getGoodsSku().getCategoryPath().lastIndexOf(",") + 1);
|
||||||
|
if (StrUtil.isNotEmpty(categoryId)) {
|
||||||
|
Double commissionRate = categoryService.getById(categoryId).getCommissionRate();
|
||||||
|
priceDetailDTO.setCommission(commissionRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
//如果积分订单 积分订单,单独操作订单结算金额和商家结算字段
|
||||||
|
if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.POINTS)) {
|
||||||
|
PointsGoodsVO pointsGoodsVO = pointsGoodsService.getPointsGoodsVOByMongo(cartSkuVO.getGoodsSku().getId());
|
||||||
|
priceDetailDTO.setBillPrice(pointsGoodsVO.getSettlementPrice());
|
||||||
|
priceDetailDTO.setSettlementPrice(pointsGoodsVO.getSettlementPrice());
|
||||||
|
}
|
||||||
|
//如果砍价订单 计算金额,单独操作订单结算金额和商家结算字段
|
||||||
|
else if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.KANJIA)) {
|
||||||
|
KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO = kanjiaActivityGoodsService.getKanJiaGoodsBySku(cartSkuVO.getGoodsSku().getId());
|
||||||
|
priceDetailDTO.setBillPrice(kanjiaActivityGoodsDTO.getSettlementPrice());
|
||||||
|
priceDetailDTO.setSettlementPrice(kanjiaActivityGoodsDTO.getSettlementPrice());
|
||||||
|
}
|
||||||
|
|
||||||
|
priceDetailDTOS.add(priceDetailDTO);
|
||||||
|
}
|
||||||
|
cart.getPriceDetailDTO().accumulationPriceDTO(priceDetailDTOS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 再次总计金额
|
||||||
|
*
|
||||||
|
* @param tradeDTO 购物车展示信息
|
||||||
|
*/
|
||||||
|
void buildTradePrice(TradeDTO tradeDTO) {
|
||||||
|
//购物车列表
|
||||||
|
List<CartVO> cartVOS = tradeDTO.getCartList();
|
||||||
|
|
||||||
|
List<PriceDetailDTO> priceDetailDTOS = new ArrayList<>();
|
||||||
|
for (CartVO cart : cartVOS) {
|
||||||
|
priceDetailDTOS.add(cart.getPriceDetailDTO());
|
||||||
|
}
|
||||||
|
tradeDTO.getPriceDetailDTO().accumulationPriceDTO(priceDetailDTOS);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -18,7 +18,6 @@ import java.util.Map;
|
|||||||
* @author Chopper
|
* @author Chopper
|
||||||
* @since 2020-07-02 14:47
|
* @since 2020-07-02 14:47
|
||||||
*/
|
*/
|
||||||
@Order(3)
|
|
||||||
@Service
|
@Service
|
||||||
public class CouponRender implements CartRenderStep {
|
public class CouponRender implements CartRenderStep {
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ import org.springframework.stereotype.Service;
|
|||||||
* @since 2020-07-02 14:47
|
* @since 2020-07-02 14:47
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@Order(6)
|
|
||||||
public class DistributionPriceRender implements CartRenderStep {
|
public class DistributionPriceRender implements CartRenderStep {
|
||||||
/**
|
/**
|
||||||
* 缓存
|
* 缓存
|
||||||
@ -53,7 +52,6 @@ public class DistributionPriceRender implements CartRenderStep {
|
|||||||
if(cartSkuVO.getDistributionGoods()!=null){
|
if(cartSkuVO.getDistributionGoods()!=null){
|
||||||
cartSkuVO.getPriceDetailDTO().setDistributionCommission(CurrencyUtil.mul(cartSkuVO.getNum(), cartSkuVO.getDistributionGoods().getCommission()));
|
cartSkuVO.getPriceDetailDTO().setDistributionCommission(CurrencyUtil.mul(cartSkuVO.getNum(), cartSkuVO.getDistributionGoods().getCommission()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ import java.util.stream.Collectors;
|
|||||||
* @since 2020-04-01 10:27 上午
|
* @since 2020-04-01 10:27 上午
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@Order(1)
|
|
||||||
public class FullDiscountRender implements CartRenderStep {
|
public class FullDiscountRender implements CartRenderStep {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -25,7 +25,6 @@ import java.util.List;
|
|||||||
* @author Chopper
|
* @author Chopper
|
||||||
* @since 2020-07-02 14:47
|
* @since 2020-07-02 14:47
|
||||||
*/
|
*/
|
||||||
@Order(4)
|
|
||||||
@Service
|
@Service
|
||||||
public class SkuFreightRender implements CartRenderStep {
|
public class SkuFreightRender implements CartRenderStep {
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ import cn.lili.modules.promotion.entity.dto.StorePromotionPriceDTO;
|
|||||||
import cn.lili.modules.promotion.service.PromotionGoodsService;
|
import cn.lili.modules.promotion.service.PromotionGoodsService;
|
||||||
import cn.lili.modules.promotion.service.PromotionPriceService;
|
import cn.lili.modules.promotion.service.PromotionPriceService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.core.annotation.Order;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -36,11 +35,9 @@ import java.util.stream.Collectors;
|
|||||||
* @since 2020-07-02 14:47
|
* @since 2020-07-02 14:47
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@Order(2)
|
|
||||||
public class SkuPromotionRender implements CartRenderStep {
|
public class SkuPromotionRender implements CartRenderStep {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 促销计算
|
* 促销计算
|
||||||
*/
|
*/
|
||||||
@ -108,7 +105,7 @@ public class SkuPromotionRender implements CartRenderStep {
|
|||||||
//店铺优惠券集合
|
//店铺优惠券集合
|
||||||
List<MemberCoupon> memberCoupons = this.getMemberCoupons(tradeDTO);
|
List<MemberCoupon> memberCoupons = this.getMemberCoupons(tradeDTO);
|
||||||
//调用价格计算模块,返回价格计算结果
|
//调用价格计算模块,返回价格计算结果
|
||||||
PromotionPriceDTO promotionPrice = promotionPriceService.calculationPromotionPrice(promotionPriceParamList, memberCoupons,tradeDTO.getCartTypeEnum());
|
PromotionPriceDTO promotionPrice = promotionPriceService.calculationPromotionPrice(promotionPriceParamList, memberCoupons, tradeDTO.getCartTypeEnum());
|
||||||
// 分配计算后的促销
|
// 分配计算后的促销
|
||||||
this.distributionPromotionPrice(tradeDTO, promotionPrice);
|
this.distributionPromotionPrice(tradeDTO, promotionPrice);
|
||||||
}
|
}
|
||||||
@ -174,27 +171,32 @@ public class SkuPromotionRender implements CartRenderStep {
|
|||||||
*/
|
*/
|
||||||
private void distributionPromotionPrice(TradeDTO tradeDTO, PromotionPriceDTO promotionPrice) {
|
private void distributionPromotionPrice(TradeDTO tradeDTO, PromotionPriceDTO promotionPrice) {
|
||||||
|
|
||||||
|
//根据店铺分配店铺价格计算结果
|
||||||
for (CartVO cartVO : tradeDTO.getCartList()) {
|
for (CartVO cartVO : tradeDTO.getCartList()) {
|
||||||
//根据店铺分配店铺价格计算结果
|
|
||||||
Optional<StorePromotionPriceDTO> storePromotionPriceDTOOptional = promotionPrice.getStorePromotionPriceList().parallelStream().filter(i -> i.getStoreId().equals(cartVO.getStoreId())).findAny();
|
//根据店铺id分组
|
||||||
|
Optional<StorePromotionPriceDTO> storePromotionPriceDTOOptional =
|
||||||
|
promotionPrice.getStorePromotionPriceList().parallelStream().filter(i -> i.getStoreId().equals(cartVO.getStoreId())).findAny();
|
||||||
|
|
||||||
|
//参数有效 则分发
|
||||||
if (storePromotionPriceDTOOptional.isPresent()) {
|
if (storePromotionPriceDTOOptional.isPresent()) {
|
||||||
StorePromotionPriceDTO storePromotionPriceDTO = storePromotionPriceDTOOptional.get();
|
StorePromotionPriceDTO storePromotionPriceDTO = storePromotionPriceDTOOptional.get();
|
||||||
//根据商品分配商品结果计算结果
|
//根据商品分配商品结果计算结果
|
||||||
this.distributionSkuPromotionPrice(cartVO.getSkuList(), storePromotionPriceDTO);
|
this.distributionSkuPromotionPrice(cartVO.getSkuList(), storePromotionPriceDTO);
|
||||||
|
|
||||||
PriceDetailDTO sSpd = new PriceDetailDTO();
|
PriceDetailDTO priceDetailDTO = new PriceDetailDTO();
|
||||||
PriceDetailVO sPd = new PriceDetailVO();
|
PriceDetailVO priceDetailVO = new PriceDetailVO();
|
||||||
sSpd.setGoodsPrice(storePromotionPriceDTO.getTotalOriginPrice());
|
priceDetailDTO.setGoodsPrice(storePromotionPriceDTO.getTotalOriginPrice());
|
||||||
sSpd.setDiscountPrice(storePromotionPriceDTO.getTotalDiscountPrice());
|
priceDetailDTO.setDiscountPrice(storePromotionPriceDTO.getTotalDiscountPrice());
|
||||||
sSpd.setCouponPrice(storePromotionPriceDTO.getTotalCouponPrice());
|
priceDetailDTO.setCouponPrice(storePromotionPriceDTO.getTotalCouponPrice());
|
||||||
sSpd.setPayPoint(storePromotionPriceDTO.getTotalPoints().intValue());
|
priceDetailDTO.setPayPoint(storePromotionPriceDTO.getTotalPoints().intValue());
|
||||||
|
|
||||||
sPd.setOriginalPrice(storePromotionPriceDTO.getTotalOriginPrice());
|
priceDetailVO.setOriginalPrice(storePromotionPriceDTO.getTotalOriginPrice());
|
||||||
sPd.setFinalePrice(storePromotionPriceDTO.getTotalFinalePrice());
|
priceDetailVO.setFinalePrice(storePromotionPriceDTO.getTotalFinalePrice());
|
||||||
sPd.setDiscountPrice(storePromotionPriceDTO.getTotalDiscountPrice());
|
priceDetailVO.setDiscountPrice(storePromotionPriceDTO.getTotalDiscountPrice());
|
||||||
sPd.setPayPoint(storePromotionPriceDTO.getTotalPoints().intValue());
|
priceDetailVO.setPayPoint(storePromotionPriceDTO.getTotalPoints().intValue());
|
||||||
cartVO.setPriceDetailDTO(sSpd);
|
cartVO.setPriceDetailDTO(priceDetailDTO);
|
||||||
cartVO.setPriceDetailVO(sPd);
|
cartVO.setPriceDetailVO(priceDetailVO);
|
||||||
cartVO.setWeight(storePromotionPriceDTO.getTotalWeight());
|
cartVO.setWeight(storePromotionPriceDTO.getTotalWeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,7 @@ public class CartServiceImpl implements CartService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TradeDTO getCheckedTradeDTO(CartTypeEnum way) {
|
public TradeDTO getCheckedTradeDTO(CartTypeEnum way) {
|
||||||
return tradeBuilder.buildTrade(way);
|
return tradeBuilder.buildChecked(way);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,6 +99,9 @@ public class PriceDetailDTO implements Serializable {
|
|||||||
if (originalPrice == 0D) {
|
if (originalPrice == 0D) {
|
||||||
return flowPrice;
|
return flowPrice;
|
||||||
}
|
}
|
||||||
|
if (originalPrice < 0) {
|
||||||
|
return 0d;
|
||||||
|
}
|
||||||
return originalPrice;
|
return originalPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,9 +163,14 @@ public class PriceDetailDTO implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void countBill() {
|
public void countBill() {
|
||||||
|
|
||||||
|
//如果结算信息包含结算金额,则最终结算金额直接等于该交易 平台与商户的结算金额
|
||||||
|
if (settlementPrice > 0) {
|
||||||
|
billPrice = settlementPrice;
|
||||||
|
}
|
||||||
|
|
||||||
//如果是普通订单最终结算金额 = flowPrice - platFormCommission - distributionCommission
|
//如果是普通订单最终结算金额 = flowPrice - platFormCommission - distributionCommission
|
||||||
billPrice = CurrencyUtil.sub(CurrencyUtil.sub(flowPrice, platFormCommission), distributionCommission);
|
billPrice = CurrencyUtil.sub(CurrencyUtil.sub(flowPrice, platFormCommission), distributionCommission);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -174,11 +182,13 @@ public class PriceDetailDTO implements Serializable {
|
|||||||
public void accumulationPriceDTO(List<PriceDetailDTO> priceDetailDTOS) {
|
public void accumulationPriceDTO(List<PriceDetailDTO> priceDetailDTOS) {
|
||||||
|
|
||||||
|
|
||||||
|
double originalPrice = 0d;
|
||||||
double goodsPrice = 0d;
|
double goodsPrice = 0d;
|
||||||
double freightPrice = 0d;
|
double freightPrice = 0d;
|
||||||
|
|
||||||
int payPoint = 0;
|
int payPoint = 0;
|
||||||
double discountPrice = 0d;
|
double discountPrice = 0d;
|
||||||
|
double couponPrice = 0d;
|
||||||
|
|
||||||
double distributionCommission = 0d;
|
double distributionCommission = 0d;
|
||||||
double platFormCommission = 0d;
|
double platFormCommission = 0d;
|
||||||
@ -191,17 +201,21 @@ public class PriceDetailDTO implements Serializable {
|
|||||||
|
|
||||||
double flowPrice = 0d;
|
double flowPrice = 0d;
|
||||||
double billPrice = 0d;
|
double billPrice = 0d;
|
||||||
|
double settlementPrice = 0d;
|
||||||
|
|
||||||
|
|
||||||
for (PriceDetailDTO price : priceDetailDTOS) {
|
for (PriceDetailDTO price : priceDetailDTOS) {
|
||||||
|
|
||||||
|
originalPrice = CurrencyUtil.add(originalPrice, price.getOriginalPrice());
|
||||||
goodsPrice = CurrencyUtil.add(goodsPrice, price.getGoodsPrice());
|
goodsPrice = CurrencyUtil.add(goodsPrice, price.getGoodsPrice());
|
||||||
freightPrice = CurrencyUtil.add(freightPrice, price.getFreightPrice());
|
freightPrice = CurrencyUtil.add(freightPrice, price.getFreightPrice());
|
||||||
|
|
||||||
payPoint = payPoint + price.getPayPoint();
|
payPoint = payPoint + price.getPayPoint();
|
||||||
discountPrice = CurrencyUtil.add(discountPrice, price.getDiscountPrice());
|
discountPrice = CurrencyUtil.add(discountPrice, price.getDiscountPrice());
|
||||||
|
couponPrice = CurrencyUtil.add(couponPrice, price.getCouponPrice());
|
||||||
|
|
||||||
updatePrice = CurrencyUtil.add(updatePrice, price.getUpdatePrice());
|
updatePrice = CurrencyUtil.add(updatePrice, price.getUpdatePrice());
|
||||||
|
|
||||||
|
|
||||||
distributionCommission = CurrencyUtil.add(distributionCommission, price.getDistributionCommission());
|
distributionCommission = CurrencyUtil.add(distributionCommission, price.getDistributionCommission());
|
||||||
platFormCommission = CurrencyUtil.add(platFormCommission, price.getPlatFormCommission());
|
platFormCommission = CurrencyUtil.add(platFormCommission, price.getPlatFormCommission());
|
||||||
|
|
||||||
@ -211,14 +225,19 @@ public class PriceDetailDTO implements Serializable {
|
|||||||
|
|
||||||
flowPrice = CurrencyUtil.add(flowPrice, price.getFlowPrice());
|
flowPrice = CurrencyUtil.add(flowPrice, price.getFlowPrice());
|
||||||
billPrice = CurrencyUtil.add(billPrice, price.getBillPrice());
|
billPrice = CurrencyUtil.add(billPrice, price.getBillPrice());
|
||||||
|
settlementPrice = CurrencyUtil.add(settlementPrice, price.getSettlementPrice());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.setOriginalPrice(originalPrice);
|
||||||
this.setGoodsPrice(goodsPrice);
|
this.setGoodsPrice(goodsPrice);
|
||||||
this.setFreightPrice(freightPrice);
|
this.setFreightPrice(freightPrice);
|
||||||
|
|
||||||
this.setPayPoint(payPoint);
|
this.setPayPoint(payPoint);
|
||||||
this.setUpdatePrice(updatePrice);
|
this.setCouponPrice(couponPrice);
|
||||||
this.setDiscountPrice(discountPrice);
|
this.setDiscountPrice(discountPrice);
|
||||||
|
|
||||||
|
this.setUpdatePrice(updatePrice);
|
||||||
|
|
||||||
this.setDistributionCommission(distributionCommission);
|
this.setDistributionCommission(distributionCommission);
|
||||||
this.setPlatFormCommission(platFormCommission);
|
this.setPlatFormCommission(platFormCommission);
|
||||||
|
|
||||||
@ -228,6 +247,7 @@ public class PriceDetailDTO implements Serializable {
|
|||||||
|
|
||||||
this.setFlowPrice(flowPrice);
|
this.setFlowPrice(flowPrice);
|
||||||
this.setBillPrice(billPrice);
|
this.setBillPrice(billPrice);
|
||||||
|
this.setSettlementPrice(settlementPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user