结算单添加积分、砍价商品结算价

This commit is contained in:
lifenlong 2021-07-24 17:06:24 +08:00
parent 6607506929
commit 7c48413d6b
11 changed files with 110 additions and 20 deletions

View File

@ -16,6 +16,10 @@ public enum CartTypeEnum {
* 立即购买
*/
BUY_NOW,
/**
* 虚拟商品
*/
VIRTUAL,
/**
* 拼团
*/
@ -24,10 +28,6 @@ public enum CartTypeEnum {
* 积分
*/
POINTS,
/**
* 虚拟商品
*/
VIRTUAL,
/**
* 砍价商品
*/

View File

@ -1,13 +1,18 @@
package cn.lili.modules.order.cart.render.impl;
import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.StrUtil;
import cn.lili.common.utils.CurrencyUtil;
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.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.core.annotation.Order;
import org.springframework.stereotype.Service;
@ -33,6 +38,16 @@ public class CartPriceRender implements CartRenderStep {
*/
@Autowired
private CategoryService categoryService;
/**
* 积分商品
*/
@Autowired
private PointsGoodsService pointsGoodsService;
/**
* 砍价商品
*/
@Autowired
private KanjiaActivityGoodsService kanjiaActivityGoodsService;
@Override
public void render(TradeDTO tradeDTO) {
@ -103,18 +118,37 @@ public class CartPriceRender implements CartRenderStep {
priceDetailDTO.getCouponPrice() != null ? priceDetailDTO.getCouponPrice() : 0));
priceDetailDTO.setFlowPrice(flowPrice);
//最终结算金额 = flowPrice - platFormCommission - distributionCommission
double billPrice = CurrencyUtil.sub(CurrencyUtil.sub(flowPrice, priceDetailDTO.getPlatFormCommission()), priceDetailDTO.getDistributionCommission());
priceDetailDTO.setBillPrice(billPrice);
//如果是普通订单最终结算金额 = flowPrice - platFormCommission - distributionCommission
//砍价积分订单按照商品的结算价进行结算
if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.CART)
|| tradeDTO.getCartTypeEnum().equals(CartTypeEnum.BUY_NOW)
|| tradeDTO.getCartTypeEnum().equals(CartTypeEnum.VIRTUAL)) {
double billPrice = CurrencyUtil.sub(CurrencyUtil.sub(flowPrice, priceDetailDTO.getPlatFormCommission()), priceDetailDTO.getDistributionCommission());
priceDetailDTO.setBillPrice(billPrice);
} else 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());
}
//填写结算价格
//平台佣金
String categoryId = cartSkuVO.getGoodsSku().getCategoryPath().substring(
cartSkuVO.getGoodsSku().getCategoryPath().lastIndexOf(",") + 1
);
if (CharSequenceUtil.isNotEmpty(categoryId)) {
//平台佣金=订单金额 * 分类佣金百分比
if (StrUtil.isNotEmpty(categoryId)) {
Double platFormCommission = CurrencyUtil.div(CurrencyUtil.mul(flowPrice, categoryService.getById(categoryId).getCommissionRate()), 100);
priceDetailDTO.setPlatFormCommission(platFormCommission);
}
priceDetailDTOS.add(priceDetailDTO);
}
}

View File

@ -278,8 +278,17 @@ public class Order extends BaseEntity {
//判断是否为拼团订单如果为拼团订单获取拼团ID判断是否为主订单
if (tradeDTO.getCartTypeEnum().name().equals(PromotionTypeEnum.PINTUAN.name())) {
Optional<String> pintuanId = cartVO.getSkuList().get(0).getPromotions().stream().filter(i -> i.getPromotionType().equals(PromotionTypeEnum.PINTUAN.name())).map(PromotionGoods::getPromotionId).findFirst();
Optional<String> pintuanId = cartVO.getSkuList().get(0).getPromotions().stream()
.filter(i -> i.getPromotionType().equals(PromotionTypeEnum.PINTUAN.name())).map(PromotionGoods::getPromotionId).findFirst();
promotionId = pintuanId.get();
}else if (tradeDTO.getCartTypeEnum().name().equals(PromotionTypeEnum.POINTS_GOODS.name())) {
Optional<String> pointsGoodsId = cartVO.getSkuList().get(0).getPromotions().stream()
.filter(i -> i.getPromotionType().equals(PromotionTypeEnum.POINTS_GOODS.name())).map(PromotionGoods::getPromotionId).findFirst();
promotionId = pointsGoodsId.get();
}else if (tradeDTO.getCartTypeEnum().name().equals(PromotionTypeEnum.KANJIA.name())) {
Optional<String> kanjiaId = cartVO.getSkuList().get(0).getPromotions().stream()
.filter(i -> i.getPromotionType().equals(PromotionTypeEnum.KANJIA.name())).map(PromotionGoods::getPromotionId).findFirst();
promotionId = kanjiaId.get();
}
}
}

View File

@ -91,6 +91,17 @@ public class StoreFlow {
@ApiModelProperty(value = "流水类型PAY/REFUND 支付/退款", allowableValues = "PAY,REFUND")
private String flowType;
/**
* @see cn.lili.modules.order.order.entity.enums.OrderPromotionTypeEnum
*/
@ApiModelProperty(value = "订单促销类型")
private String orderPromotionType;
@ApiModelProperty(value = "积分活动商品结算价格")
private Double pointSettlementPrice;
@ApiModelProperty(value = "砍价活动商品结算价格")
private Double kanjiaSettlementPrice;
@ApiModelProperty(value = "平台优惠券 使用金额")
private Double siteCouponPrice;

View File

@ -81,6 +81,9 @@ public class PriceDetailDTO implements Serializable {
@ApiModelProperty(value = "流水金额(入账 出帐金额) = goodsPrice + freight - discountPrice - couponPrice + updatePrice")
private Double flowPrice;
@ApiModelProperty(value = "结算价格")
private Double settlementPrice;
@ApiModelProperty(value = "最终结算金额 = flowPrice - platFormCommission - distributionCommission")
private Double billPrice;

View File

@ -8,6 +8,10 @@ package cn.lili.modules.order.order.entity.enums;
*/
public enum OrderPromotionTypeEnum {
/**
* 普通订单
*/
NORMAL,
/**
* 赠品订单
*/
@ -19,6 +23,10 @@ public enum OrderPromotionTypeEnum {
/**
* 积分订单
*/
POINT
POINT,
/**
* 砍价订单
*/
KANJIA
}

View File

@ -7,6 +7,7 @@ import cn.lili.modules.order.order.entity.dos.Order;
import cn.lili.modules.order.order.entity.dos.OrderItem;
import cn.lili.modules.order.order.entity.dos.StoreFlow;
import cn.lili.modules.order.order.entity.enums.FlowTypeEnum;
import cn.lili.modules.order.order.entity.enums.OrderPromotionTypeEnum;
import cn.lili.modules.order.order.entity.enums.PayStatusEnum;
import cn.lili.modules.order.order.mapper.StoreFlowMapper;
import cn.lili.modules.order.order.service.OrderItemService;
@ -24,7 +25,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -62,14 +62,13 @@ public class StoreFlowServiceImpl extends ServiceImpl<StoreFlowMapper, StoreFlow
//根据订单编号获取订单数据
Order order = orderService.getBySn(orderSn);
List<String> sns = new ArrayList<>();
sns.add(order.getSn());
sns.add(order.getTradeSn());
//如果查询到多条支付记录打印日志
if (order.getPayStatus().equals(PayStatusEnum.PAID.name())) {
log.error("订单[{}]检测到重复付款,请处理", orderSn);
}
//获取订单促销类型,如果为促销订单则获取促销商品并获取结算价
String orderPromotionType = order.getOrderPromotionType();
//循环子订单记录流水
for (OrderItem item : orderItems) {
StoreFlow storeFlow = new StoreFlow();
@ -92,6 +91,13 @@ public class StoreFlowServiceImpl extends ServiceImpl<StoreFlowMapper, StoreFlow
storeFlow.setCommissionPrice(item.getPriceDetailDTO().getPlatFormCommission());
storeFlow.setDistributionRebate(item.getPriceDetailDTO().getDistributionCommission());
storeFlow.setBillPrice(item.getPriceDetailDTO().getBillPrice());
if (orderPromotionType.equals(OrderPromotionTypeEnum.NORMAL.name())) {
//如果为砍价活动填写砍价结算价
} else if (orderPromotionType.equals(OrderPromotionTypeEnum.KANJIA.name())) {
storeFlow.setKanjiaSettlementPrice(item.getPriceDetailDTO().getSettlementPrice());
} else if (orderPromotionType.equals(OrderPromotionTypeEnum.KANJIA.name())) {
storeFlow.setPointSettlementPrice(item.getPriceDetailDTO().getSettlementPrice());
}
//添加支付方式
storeFlow.setPaymentName(order.getPaymentMethod());
@ -147,9 +153,9 @@ public class StoreFlowServiceImpl extends ServiceImpl<StoreFlowMapper, StoreFlow
LambdaQueryWrapper<StoreFlow> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(StoreFlow::getStoreId, storeId);
lambdaQueryWrapper.isNotNull(distribution,StoreFlow::getDistributionRebate);
lambdaQueryWrapper.isNotNull(distribution, StoreFlow::getDistributionRebate);
lambdaQueryWrapper.between(StoreFlow::getCreateTime, startTime, endTime);
lambdaQueryWrapper.eq(StringUtils.isNotEmpty(type),StoreFlow::getFlowType, type);
lambdaQueryWrapper.eq(StringUtils.isNotEmpty(type), StoreFlow::getFlowType, type);
return this.page(PageUtil.initPage(pageVO), lambdaQueryWrapper);
}
}

View File

@ -92,6 +92,7 @@ public class Bill {
* -commissionPrice+refundCommissionPrice
* -distributionCommission+distributionRefundCommission
* +siteCouponCommission-siteCouponRefundCommission
* +kanjiaSettlementPrice+pointSettlementPrice
*/
@ApiModelProperty(value = "结算周期内订单付款总金额")
private Double orderPrice;
@ -117,6 +118,12 @@ public class Bill {
@ApiModelProperty(value = "退货平台优惠券补贴返还")
private Double siteCouponRefundCommission;
@ApiModelProperty(value = "积分商品结算价格")
private Double pointSettlementPrice;
@ApiModelProperty(value = "砍价商品结算价格")
private Double kanjiaSettlementPrice;
@ApiModelProperty(value = "最终结算金额")
private Double billPrice;

View File

@ -37,7 +37,10 @@ public interface BillMapper extends BaseMapper<Bill> {
*/
@Select("SELECT SUM( final_price ) AS orderPrice,SUM( commission_price ) AS commissionPrice" +
",SUM( distribution_rebate ) AS distributionCommission,SUM( site_coupon_commission ) AS siteCouponCommission" +
",SUM( bill_price ) AS billPrice FROM li_store_flow ${ew.customSqlSegment}")
",SUM( point_settlement_price ) AS pointSettlementPrice " +
",SUM( kanjia_settlement_price ) AS kanjiaSettlementPrice " +
",SUM( bill_price ) AS billPrice " +
"FROM li_store_flow ${ew.customSqlSegment}")
Bill getOrderBill(@Param(Constants.WRAPPER) QueryWrapper<Bill> queryWrapper);
/**

View File

@ -89,7 +89,11 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
bill.setCommissionPrice(orderBill.getCommissionPrice());
bill.setDistributionCommission(orderBill.getDistributionCommission());
bill.setSiteCouponCommission(orderBill.getSiteCouponCommission());
orderPrice = orderBill.getBillPrice();
bill.setPointSettlementPrice(orderBill.getPointSettlementPrice());
bill.setKanjiaSettlementPrice(orderBill.getKanjiaSettlementPrice());
//入账金额=订单金额+积分商品+砍价商品
orderPrice = CurrencyUtil.add(CurrencyUtil.add(orderBill.getBillPrice(), orderBill.getPointSettlementPrice()),
orderBill.getKanjiaSettlementPrice());
}

View File

@ -0,0 +1,5 @@
/** 添加结算单积分、砍价结算价信息**/
ALTER TABLE li_bill ADD point_settlement_price double DEFAULT 0.00 COMMENT '积分商品结算金额 ';
ALTER TABLE li_bill ADD kanjia_settlement_price double DEFAULT 0.00 COMMENT '砍价商品结算金额';
ALTER TABLE li_store_flow ADD point_settlement_price double DEFAULT 0.00 COMMENT '积分商品结算金额';
ALTER TABLE li_store_flow ADD kanjia_settlement_price double DEFAULT 0.00 COMMENT '砍价商品结算金额';