diff --git a/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/marriagebounty/entity/MarriageBountyOrder.java b/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/marriagebounty/entity/MarriageBountyOrder.java index 0cc1d34..0195712 100644 --- a/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/marriagebounty/entity/MarriageBountyOrder.java +++ b/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/marriagebounty/entity/MarriageBountyOrder.java @@ -46,6 +46,9 @@ public class MarriageBountyOrder extends Entity { @ApiModelProperty("奖励金额") private BigDecimal rewardAmount; + @ApiModelProperty("付款金额") + private BigDecimal paidAmount; + @ApiModelProperty("状态") private MarriageBountyOrderStatusEnum status; diff --git a/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/order/entity/Order.java b/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/order/entity/Order.java index 00e37df..6b9714a 100644 --- a/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/order/entity/Order.java +++ b/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/order/entity/Order.java @@ -37,6 +37,12 @@ public class Order extends Entity { @ApiModelProperty("订单号") private String orderCode; + @ApiModelProperty("原始金额") + private BigDecimal originalAmount ; + + @ApiModelProperty("折扣金额") + private BigDecimal discountAmount; + @ApiModelProperty("结算金额") private BigDecimal settlementAmount; diff --git a/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/order/entity/OrderItem.java b/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/order/entity/OrderItem.java index 6cbedbd..fceedc8 100644 --- a/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/order/entity/OrderItem.java +++ b/dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/order/entity/OrderItem.java @@ -46,6 +46,12 @@ public class OrderItem extends Entity { @ApiModelProperty("数量") private Integer quantity; + @ApiModelProperty("原始金额") + private BigDecimal originalAmount ; + + @ApiModelProperty("折扣金额") + private BigDecimal discountAmount; + @ApiModelProperty("结算金额") private BigDecimal settlementAmount; diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/marriagebounty/MarriageBountyOrderApplicationService.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/marriagebounty/MarriageBountyOrderApplicationService.java index b71a798..58bac5e 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/marriagebounty/MarriageBountyOrderApplicationService.java +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/marriagebounty/MarriageBountyOrderApplicationService.java @@ -95,7 +95,9 @@ public class MarriageBountyOrderApplicationService extends BaseApplicationServic } } marriageBountyOrder.calculateRewardAmount(); + marriageBountyOrder.setPaidAmount(marriageBountyOrder.getPaidAmount().add(order.getSettlementAmount())); productRecord.setRewardAmount(marriageBountyOrder.getRewardAmount()); + marriageBountyOrder.setProductRecordList(Collections.singletonList(productRecord)); marriageBountyOrderAggregate.update(marriageBountyOrder); } @@ -123,6 +125,7 @@ public class MarriageBountyOrderApplicationService extends BaseApplicationServic marriageBountyOrder.setOrderRewardList(orderRewardList); marriageBountyOrder.setInsertOrderRewardList(orderRewardList); marriageBountyOrder.calculateRewardAmount(); + marriageBountyOrder.setPaidAmount(order.getSettlementAmount()); productRecord.setRewardAmount(marriageBountyOrder.getRewardAmount()); marriageBountyOrder.setProductRecordList(Collections.singletonList(productRecord)); BaseDomainEvent event = marriageBountyOrderAggregate.create(marriageBountyOrder); diff --git a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/order/OrderApplicationService.java b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/order/OrderApplicationService.java index 9fb84bc..aed4149 100644 --- a/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/order/OrderApplicationService.java +++ b/dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/order/OrderApplicationService.java @@ -130,12 +130,16 @@ public class OrderApplicationService extends BaseApplicationService { public void countOrderAmount(Order order, Boolean allowFree) { if (CollUtil.isNotEmpty(order.getOrderItemList())) { - BigDecimal totalSettlementAmount = BigDecimal.ZERO; + BigDecimal totalOriginalAmount = BigDecimal.ZERO; for (OrderItem orderItem : order.getOrderItemList()) { - orderItem.setSettlementAmount(orderItem.getUnitSettlementPrice().multiply(BigDecimal.valueOf(orderItem.getQuantity()))); - totalSettlementAmount = totalSettlementAmount.add(orderItem.getSettlementAmount()); + orderItem.setOriginalAmount(orderItem.getUnitSettlementPrice().multiply(BigDecimal.valueOf(orderItem.getQuantity()))); + orderItem.setDiscountAmount(BigDecimal.ZERO); + orderItem.setSettlementAmount(orderItem.getOriginalAmount()); + totalOriginalAmount = totalOriginalAmount.add(orderItem.getOriginalAmount()); } - order.setSettlementAmount(totalSettlementAmount); + order.setOriginalAmount(totalOriginalAmount); + order.setDiscountAmount(BigDecimal.ZERO); + order.setSettlementAmount(order.getOriginalAmount()); if (!allowFree && order.getSettlementAmount().compareTo(BigDecimal.ZERO) <= 0) { throw new BizException("订单金额应该大于0"); } @@ -198,7 +202,7 @@ public class OrderApplicationService extends BaseApplicationService { //2. 填充订单信息 fillMarriageBountyOrderInfo(order, productList, meetingQuantity); //3. 订单金额计算 - countOrderAmount(order, false); + countMarriageBountyOrderAmount(marriageBountyOrder.getPublishType(), order); //3.1. 低消确认 MarriageBountyOrder existMarriageBountyOrder = marriageBountyOrderQueryService.queryBy(order.getUserId(), order.getMiId(), MarriageBountyOrderStatusEnum.MATCHMAKING, MarriageBountyOrderPaymentStatusEnum.PAID); @@ -225,6 +229,48 @@ public class OrderApplicationService extends BaseApplicationService { return new UserSubmitOrderVo(order.getId(), paymentOrder.getId(), false); } + /** + * 计算招亲榜的订单金额 + * + * @param publishType + * @param order + */ + private void countMarriageBountyOrderAmount(PublishIdentityTypeEnum publishType, + Order order) { + if (PublishIdentityTypeEnum.MATCHMAKER.equals(publishType)) { + //红娘发榜的话,则下单不需要给发布嘉宾邀请金额+发榜佣金 + //获取红娘身份 + RewardConfig guestCertificationReward = rewardConfigQueryService.queryGuestCertificationReward(order.getUserId()); + RewardConfig publishMarriageBountyReward = rewardConfigQueryService.queryPublishMarriageBountyReward(order.getUserId()); + if (CollUtil.isNotEmpty(order.getOrderItemList())) { + BigDecimal totalOriginalAmount = BigDecimal.ZERO; + BigDecimal totalDiscountAmount = BigDecimal.ZERO; + for (OrderItem orderItem : order.getOrderItemList()) { + orderItem.setOriginalAmount(orderItem.getUnitSettlementPrice().multiply(BigDecimal.valueOf(orderItem.getQuantity()))); + BigDecimal discountAmount = BigDecimal.ZERO; + if (Objects.nonNull(guestCertificationReward)) { + discountAmount = discountAmount.add(guestCertificationReward.calculateReward(orderItem.getOriginalAmount())); + } + if (Objects.nonNull(publishMarriageBountyReward)) { + discountAmount = discountAmount.add(publishMarriageBountyReward.calculateReward(orderItem.getOriginalAmount())); + } + orderItem.setDiscountAmount(discountAmount); + orderItem.setSettlementAmount(orderItem.getOriginalAmount().subtract(discountAmount)); + totalOriginalAmount = totalOriginalAmount.add(orderItem.getOriginalAmount()); + totalDiscountAmount = totalDiscountAmount.add(discountAmount); + } + order.setOriginalAmount(totalOriginalAmount); + order.setDiscountAmount(totalDiscountAmount); + order.setSettlementAmount(order.getOriginalAmount().subtract(totalDiscountAmount)); + if (order.getSettlementAmount().compareTo(BigDecimal.ZERO) <= 0) { + throw new BizException("订单金额应该大于0"); + } + } + } else { + countOrderAmount(order, false); + } + } + private void checkMinAmount(MarriageBountyOrder marriageBountyOrder, Order order) { RewardTypeEnum rewardType = marriageBountyOrder.getMinAmountType(); RewardConfig rewardConfig = rewardConfigQueryService.queryByRewardType(rewardType);