From 3e9ce32124446cd42c1d50f0bbc9876dd4299b3d Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Mon, 11 Sep 2023 12:05:58 +0800
Subject: [PATCH] 优惠卷
---
src/main/java/cc/mrbird/febs/mall/entity/MallOrderItem.java | 2 +
src/main/java/cc/mrbird/febs/rabbit/enumerates/RabbitQueueEnum.java | 5 ++
src/main/java/cc/mrbird/febs/pay/controller/XcxPayController.java | 5 ++
src/main/java/cc/mrbird/febs/common/configure/RabbitConfigure.java | 16 ++++++++
src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java | 10 +++++
src/main/java/cc/mrbird/febs/mall/dto/AddOrderDto.java | 3 +
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java | 35 +++++++++++++++++
src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java | 17 ++++++++
src/main/java/cc/mrbird/febs/rabbit/constants/QueueConstants.java | 2 +
src/main/java/cc/mrbird/febs/rabbit/producter/AgentProducer.java | 7 +++
src/main/java/cc/mrbird/febs/mall/service/IMemberProfitService.java | 2 +
11 files changed, 103 insertions(+), 1 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/common/configure/RabbitConfigure.java b/src/main/java/cc/mrbird/febs/common/configure/RabbitConfigure.java
index 50797b6..32b3b5e 100644
--- a/src/main/java/cc/mrbird/febs/common/configure/RabbitConfigure.java
+++ b/src/main/java/cc/mrbird/febs/common/configure/RabbitConfigure.java
@@ -122,4 +122,20 @@
return BindingBuilder.bind(orderReturnMoneyQueue()).to(orderReturnMoneyExchange()).with(RabbitQueueEnum.ORDER_RETURN_MONEY.getRoute());
}
+
+ @Bean
+ public DirectExchange orderCouponExchange() {
+ return new DirectExchange(RabbitQueueEnum.ORDER_COUPON.getExchange());
+ }
+
+ @Bean
+ public Queue orderCouponQueue() {
+ return new Queue(QueueConstants.ORDER_COUPON);
+ }
+
+ @Bean
+ public Binding orderCouponBind() {
+ return BindingBuilder.bind(orderCouponQueue()).to(orderCouponExchange()).with(RabbitQueueEnum.ORDER_COUPON.getRoute());
+ }
+
}
diff --git a/src/main/java/cc/mrbird/febs/mall/dto/AddOrderDto.java b/src/main/java/cc/mrbird/febs/mall/dto/AddOrderDto.java
index c3bb84e..da3a145 100644
--- a/src/main/java/cc/mrbird/febs/mall/dto/AddOrderDto.java
+++ b/src/main/java/cc/mrbird/febs/mall/dto/AddOrderDto.java
@@ -41,6 +41,9 @@
@ApiModelProperty(value = "1-普通订单/2-积分订单")
private Integer orderType;
+ @ApiModelProperty(value = "会员优惠卷ID")
+ private Long memberCouponId;
+
@ApiModelProperty(value = "商品明细")
private List<AddOrderItemDto> items;
diff --git a/src/main/java/cc/mrbird/febs/mall/entity/MallOrderItem.java b/src/main/java/cc/mrbird/febs/mall/entity/MallOrderItem.java
index c162af5..8fecef8 100644
--- a/src/main/java/cc/mrbird/febs/mall/entity/MallOrderItem.java
+++ b/src/main/java/cc/mrbird/febs/mall/entity/MallOrderItem.java
@@ -19,6 +19,8 @@
private Long skuId;
+ private Long memberCouponId;
+
private Long goodsId;
private String goodsName;
diff --git a/src/main/java/cc/mrbird/febs/mall/service/IMemberProfitService.java b/src/main/java/cc/mrbird/febs/mall/service/IMemberProfitService.java
index 2d7a643..853979d 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/IMemberProfitService.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/IMemberProfitService.java
@@ -39,4 +39,6 @@
* 店补/董事
*/
void storeAndDirectorProfit(Date profitDate);
+
+ void getOrderCoupon(Long orderId);
}
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
index 3eb553e..00f656f 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java
@@ -45,6 +45,7 @@
import java.math.BigDecimal;
import java.util.*;
+import java.util.stream.Collectors;
/**
* @author wzy
@@ -82,6 +83,8 @@
private final IApiMallTeamLeaderService iApiMallTeamLeaderService;
private final IMallElectronicFenceService iMallElectronicFenceService;
private final MallElectronicFenceMapper mallElectronicFenceMapper;
+ private final MallMemberCouponMapper mallMemberCouponMapper;
+ private final MallGoodsCouponMapper mallGoodsCouponMapper;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -183,6 +186,36 @@
}
BigDecimal amount = sku.getPresentPrice().multiply(BigDecimal.valueOf(item.getCnt()));
+ //是否使用优惠卷
+ if(ObjectUtil.isNotEmpty(addOrderDto.getMemberCouponId())){
+ Long memberCouponId = addOrderDto.getMemberCouponId();
+ MallMemberCoupon mallMemberCoupon = mallMemberCouponMapper.selectById(memberCouponId);
+ if(ObjectUtil.isEmpty(mallMemberCoupon)){
+ throw new FebsException(mallMemberCoupon.getCouponName()+"无法使用");
+ }
+ Integer state = mallMemberCoupon.getState();
+ if(1 != state){
+ throw new FebsException(mallMemberCoupon.getCouponName()+"无法使用");
+ }
+ Long goodsId = mallMemberCoupon.getGoodsId();
+ if(goodsId != sku.getGoodsId()){
+ throw new FebsException(sku.getGoodsName()+"无法使用"+mallMemberCoupon.getCouponName());
+ }
+ MallGoodsCoupon mallGoodsCoupon = mallGoodsCouponMapper.selectById(mallMemberCoupon.getCouponId());
+ if(ObjectUtil.isEmpty(mallGoodsCoupon)){
+ throw new FebsException(mallGoodsCoupon.getName()+"无法使用");
+ }
+ Integer stateCoupon = mallGoodsCoupon.getState();
+ if(2 != stateCoupon){
+ throw new FebsException(mallGoodsCoupon.getName()+"无法使用");
+ }
+ BigDecimal costAmount = mallGoodsCoupon.getCostAmount();
+ BigDecimal realAmount = mallGoodsCoupon.getRealAmount();
+ if(amount.compareTo(costAmount) >= 0){
+ amount = amount.subtract(realAmount);
+ orderItem.setMemberCouponId(memberCouponId);
+ }
+ }
orderItem.setAmount(amount);
orderItem.setCnt(item.getCnt());
orderItem.setOrderId(orderInfo.getId());
@@ -366,6 +399,8 @@
orderInfo.setDeliveryState(OrderDeliveryStateEnum.DELIVERY_WAIT.getValue());
mallMoneyFlowService.addMoneyFlow(member.getId(), orderInfo.getAmount().negate(), MoneyFlowTypeEnum.PAY.getValue(), orderInfo.getOrderNo(), FlowTypeEnum.BALANCE.getValue(),"余额支付",2);
+
+ agentProducer.sendOrderCoupon(orderInfo.getId());
break;
case "4":
if (orderInfo.getOrderType() != 2) {
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java
index 89dab43..642f7f9 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/MemberProfitServiceImpl.java
@@ -27,6 +27,7 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
+import java.util.stream.Collectors;
/**
* @author wzy
@@ -46,6 +47,7 @@
private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
private final MallMoneyFlowMapper mallMoneyFlowMapper;
private final MallAchieveRecordMapper mallAchieveRecordMapper;
+ private final MallMemberCouponMapper mallMemberCouponMapper;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -477,4 +479,19 @@
}
log.info("#####==店补/董事==end==######");
}
+
+ @Override
+ public void getOrderCoupon(Long orderId) {
+ List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderId);
+ if(CollUtil.isNotEmpty(mallOrderItemList)){
+ List<Long> memberCouponIds = mallOrderItemList.stream().map(MallOrderItem::getMemberCouponId).collect(Collectors.toList());
+ if(CollUtil.isNotEmpty(memberCouponIds)){
+ for(Long memberCouponId : memberCouponIds){
+ MallMemberCoupon mallMemberCoupon = mallMemberCouponMapper.selectById(memberCouponId);
+ mallMemberCoupon.setState(2);
+ mallMemberCouponMapper.updateById(mallMemberCoupon);
+ }
+ }
+ }
+ }
}
diff --git a/src/main/java/cc/mrbird/febs/pay/controller/XcxPayController.java b/src/main/java/cc/mrbird/febs/pay/controller/XcxPayController.java
index 9e68dfc..2dcefa6 100644
--- a/src/main/java/cc/mrbird/febs/pay/controller/XcxPayController.java
+++ b/src/main/java/cc/mrbird/febs/pay/controller/XcxPayController.java
@@ -21,6 +21,7 @@
import cc.mrbird.febs.pay.util.Signature;
import cc.mrbird.febs.pay.util.Util;
import cc.mrbird.febs.pay.util.WechatConfigure;
+import cc.mrbird.febs.rabbit.producter.AgentProducer;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
@@ -72,6 +73,8 @@
private IApiMallMemberService mallMemberService;
@Autowired
private MallAgentRecordMapper mallAgentRecordMapper;
+ @Autowired
+ private AgentProducer agentProducer;
@Autowired
private IXcxPayService iXcxPayService;
@@ -306,6 +309,8 @@
order.setDeliveryState(OrderDeliveryStateEnum.DELIVERY_WAIT.getValue());
mallOrderInfoMapper.updateById(order);
+ agentProducer.sendOrderCoupon(order.getId());
+
mallMoneyFlowService.addMoneyFlow(
order.getMemberId(),
order.getAmount().negate(),
diff --git a/src/main/java/cc/mrbird/febs/rabbit/constants/QueueConstants.java b/src/main/java/cc/mrbird/febs/rabbit/constants/QueueConstants.java
index 702f5f9..a473a08 100644
--- a/src/main/java/cc/mrbird/febs/rabbit/constants/QueueConstants.java
+++ b/src/main/java/cc/mrbird/febs/rabbit/constants/QueueConstants.java
@@ -10,4 +10,6 @@
public static final String AGENT_AUTO_LEVEL_UP = "queue_agent_auto_level_up_qay";
public static final String AGENT_RETURN_MONEY = "queue_agent_return_money_qay";
public static final String ORDER_RETURN_MONEY = "queue_order_return_money_qay";
+
+ public static final String ORDER_COUPON = "queue_order_coupon";
}
diff --git a/src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java b/src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java
index a32d98e..9fe3dea 100644
--- a/src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java
+++ b/src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java
@@ -72,4 +72,14 @@
log.error("订单返利异常:", e);
}
}
+
+ @RabbitListener(queues = QueueConstants.ORDER_COUPON)
+ public void getOrderCoupon(Long orderId) {
+ log.info("收到使用优惠卷消息:{}", orderId);
+ try {
+ memberProfitService.getOrderCoupon(orderId);
+ } catch (Exception e) {
+ log.error("使用优惠卷异常:", e);
+ }
+ }
}
diff --git a/src/main/java/cc/mrbird/febs/rabbit/enumerates/RabbitQueueEnum.java b/src/main/java/cc/mrbird/febs/rabbit/enumerates/RabbitQueueEnum.java
index 25b2216..87376dd 100644
--- a/src/main/java/cc/mrbird/febs/rabbit/enumerates/RabbitQueueEnum.java
+++ b/src/main/java/cc/mrbird/febs/rabbit/enumerates/RabbitQueueEnum.java
@@ -1,5 +1,6 @@
package cc.mrbird.febs.rabbit.enumerates;
+import cc.mrbird.febs.rabbit.constants.QueueConstants;
import lombok.Getter;
@Getter
@@ -12,7 +13,9 @@
AGENT_REUTRN_MONEY("exchange_agent_return_money_qay", "route_key_agent_return_money_qay", "queue_agent_return_money_qay"),
- ORDER_RETURN_MONEY("exchange_order_return_money_qay", "route_key_order_return_money_qay", "queue_order_return_money_qay");
+ ORDER_RETURN_MONEY("exchange_order_return_money_qay", "route_key_order_return_money_qay", "queue_order_return_money_qay"),
+
+ ORDER_COUPON("exchange_order_coupon", "route_key_order_coupon", QueueConstants.ORDER_COUPON);
private String exchange;
diff --git a/src/main/java/cc/mrbird/febs/rabbit/producter/AgentProducer.java b/src/main/java/cc/mrbird/febs/rabbit/producter/AgentProducer.java
index 0ddb24b..281c171 100644
--- a/src/main/java/cc/mrbird/febs/rabbit/producter/AgentProducer.java
+++ b/src/main/java/cc/mrbird/febs/rabbit/producter/AgentProducer.java
@@ -76,4 +76,11 @@
log.info("发送返利消息:{}", orderId);
rabbitTemplate.convertAndSend(RabbitQueueEnum.AGENT_REUTRN_MONEY.getExchange(), RabbitQueueEnum.AGENT_REUTRN_MONEY.getRoute(), orderId);
}
+
+
+ public void sendOrderCoupon(Long id) {
+ log.info("发送使用优惠卷消息:{}", id);
+ CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
+ rabbitTemplate.convertAndSend(RabbitQueueEnum.ORDER_COUPON.getExchange(), RabbitQueueEnum.ORDER_COUPON.getRoute(), id, correlationData);
+ }
}
--
Gitblit v1.9.1