From 7c48413d6b6c611558e80ec1e08126eac9ee104a Mon Sep 17 00:00:00 2001 From: lifenlong Date: Sat, 24 Jul 2021 17:06:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=93=E7=AE=97=E5=8D=95=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=A7=AF=E5=88=86=E3=80=81=E7=A0=8D=E4=BB=B7=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=BB=93=E7=AE=97=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/cart/entity/enums/CartTypeEnum.java | 8 ++-- .../cart/render/impl/CartPriceRender.java | 44 ++++++++++++++++--- .../modules/order/order/entity/dos/Order.java | 11 ++++- .../order/order/entity/dos/StoreFlow.java | 11 +++++ .../order/entity/dto/PriceDetailDTO.java | 3 ++ .../entity/enums/OrderPromotionTypeEnum.java | 10 ++++- .../serviceimpl/StoreFlowServiceImpl.java | 20 ++++++--- .../lili/modules/store/entity/dos/Bill.java | 7 +++ .../lili/modules/store/mapper/BillMapper.java | 5 ++- .../store/serviceimpl/BillServiceImpl.java | 6 ++- update-sql/version4.2to4.3.sql | 5 +++ 11 files changed, 110 insertions(+), 20 deletions(-) create mode 100644 update-sql/version4.2to4.3.sql diff --git a/framework/src/main/java/cn/lili/modules/order/cart/entity/enums/CartTypeEnum.java b/framework/src/main/java/cn/lili/modules/order/cart/entity/enums/CartTypeEnum.java index d1aee55a..5949526a 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/entity/enums/CartTypeEnum.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/entity/enums/CartTypeEnum.java @@ -16,6 +16,10 @@ public enum CartTypeEnum { * 立即购买 */ BUY_NOW, + /** + * 虚拟商品 + */ + VIRTUAL, /** * 拼团 */ @@ -24,10 +28,6 @@ public enum CartTypeEnum { * 积分 */ POINTS, - /** - * 虚拟商品 - */ - VIRTUAL, /** * 砍价商品 */ diff --git a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CartPriceRender.java b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CartPriceRender.java index 52a1b215..7b6525cf 100644 --- a/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CartPriceRender.java +++ b/framework/src/main/java/cn/lili/modules/order/cart/render/impl/CartPriceRender.java @@ -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); } } diff --git a/framework/src/main/java/cn/lili/modules/order/order/entity/dos/Order.java b/framework/src/main/java/cn/lili/modules/order/order/entity/dos/Order.java index ee226f97..7a02f2d7 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/entity/dos/Order.java +++ b/framework/src/main/java/cn/lili/modules/order/order/entity/dos/Order.java @@ -278,8 +278,17 @@ public class Order extends BaseEntity { //判断是否为拼团订单,如果为拼团订单获取拼团ID,判断是否为主订单 if (tradeDTO.getCartTypeEnum().name().equals(PromotionTypeEnum.PINTUAN.name())) { - Optional pintuanId = cartVO.getSkuList().get(0).getPromotions().stream().filter(i -> i.getPromotionType().equals(PromotionTypeEnum.PINTUAN.name())).map(PromotionGoods::getPromotionId).findFirst(); + Optional 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 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 kanjiaId = cartVO.getSkuList().get(0).getPromotions().stream() + .filter(i -> i.getPromotionType().equals(PromotionTypeEnum.KANJIA.name())).map(PromotionGoods::getPromotionId).findFirst(); + promotionId = kanjiaId.get(); } } } diff --git a/framework/src/main/java/cn/lili/modules/order/order/entity/dos/StoreFlow.java b/framework/src/main/java/cn/lili/modules/order/order/entity/dos/StoreFlow.java index c4747861..5f3813ec 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/entity/dos/StoreFlow.java +++ b/framework/src/main/java/cn/lili/modules/order/order/entity/dos/StoreFlow.java @@ -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; diff --git a/framework/src/main/java/cn/lili/modules/order/order/entity/dto/PriceDetailDTO.java b/framework/src/main/java/cn/lili/modules/order/order/entity/dto/PriceDetailDTO.java index 06ab410c..df94d02c 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/entity/dto/PriceDetailDTO.java +++ b/framework/src/main/java/cn/lili/modules/order/order/entity/dto/PriceDetailDTO.java @@ -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; diff --git a/framework/src/main/java/cn/lili/modules/order/order/entity/enums/OrderPromotionTypeEnum.java b/framework/src/main/java/cn/lili/modules/order/order/entity/enums/OrderPromotionTypeEnum.java index ac06e73c..f3f0a8b7 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/entity/enums/OrderPromotionTypeEnum.java +++ b/framework/src/main/java/cn/lili/modules/order/order/entity/enums/OrderPromotionTypeEnum.java @@ -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 } diff --git a/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/StoreFlowServiceImpl.java b/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/StoreFlowServiceImpl.java index 5eb8d19f..46c84483 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/StoreFlowServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/order/order/serviceimpl/StoreFlowServiceImpl.java @@ -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 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 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); } } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/store/entity/dos/Bill.java b/framework/src/main/java/cn/lili/modules/store/entity/dos/Bill.java index 8f0aaaf5..19f96dd9 100644 --- a/framework/src/main/java/cn/lili/modules/store/entity/dos/Bill.java +++ b/framework/src/main/java/cn/lili/modules/store/entity/dos/Bill.java @@ -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; diff --git a/framework/src/main/java/cn/lili/modules/store/mapper/BillMapper.java b/framework/src/main/java/cn/lili/modules/store/mapper/BillMapper.java index 9fdef23f..040ab507 100644 --- a/framework/src/main/java/cn/lili/modules/store/mapper/BillMapper.java +++ b/framework/src/main/java/cn/lili/modules/store/mapper/BillMapper.java @@ -37,7 +37,10 @@ public interface BillMapper extends BaseMapper { */ @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 queryWrapper); /** diff --git a/framework/src/main/java/cn/lili/modules/store/serviceimpl/BillServiceImpl.java b/framework/src/main/java/cn/lili/modules/store/serviceimpl/BillServiceImpl.java index e72d7729..6dfe5fdd 100644 --- a/framework/src/main/java/cn/lili/modules/store/serviceimpl/BillServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/store/serviceimpl/BillServiceImpl.java @@ -89,7 +89,11 @@ public class BillServiceImpl extends ServiceImpl 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()); } diff --git a/update-sql/version4.2to4.3.sql b/update-sql/version4.2to4.3.sql new file mode 100644 index 00000000..52e00042 --- /dev/null +++ b/update-sql/version4.2to4.3.sql @@ -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 '砍价商品结算金额'; \ No newline at end of file