From be7a5df652f0722ae897df560b2afdb06d8c268f Mon Sep 17 00:00:00 2001
From: Hentua <wangdoubleone@gmail.com>
Date: Thu, 25 Jan 2024 22:12:48 +0800
Subject: [PATCH] 确认收货会员升级
---
src/main/java/cc/mrbird/febs/rabbit/enumerates/RabbitQueueEnum.java | 4 +
src/main/java/cc/mrbird/febs/common/configure/RabbitConfigure.java | 16 +++++
src/main/java/cc/mrbird/febs/mall/quartz/OrderSettlementJob.java | 8 ++
src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java | 10 +++
src/main/java/cc/mrbird/febs/vip/entity/MallVipConfig.java | 3
src/main/java/cc/mrbird/febs/vip/service/impl/VipCommonServiceImpl.java | 99 +++++++++++++++++++++++++++++++++
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallOrderInfoServiceImpl.java | 2
src/main/java/cc/mrbird/febs/rabbit/constants/QueueConstants.java | 1
src/main/java/cc/mrbird/febs/rabbit/producter/AgentProducer.java | 7 ++
src/main/java/cc/mrbird/febs/vip/service/IVipCommonService.java | 2
src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java | 8 ++
11 files changed, 157 insertions(+), 3 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 3dc6481..5c4f242 100644
--- a/src/main/java/cc/mrbird/febs/common/configure/RabbitConfigure.java
+++ b/src/main/java/cc/mrbird/febs/common/configure/RabbitConfigure.java
@@ -154,4 +154,20 @@
return BindingBuilder.bind(getScoreMsgQueue()).to(getScoreMsgExchange()).with(RabbitQueueEnum.GET_SCORE_MSG.getRoute());
}
+
+ @Bean
+ public DirectExchange vipLevelUp() {
+ return new DirectExchange(RabbitQueueEnum.VIP_LEVEL_UP.getExchange());
+ }
+
+ @Bean
+ public Queue vipLevelUpQueue() {
+ return new Queue(QueueConstants.VIP_LEVEL_UP);
+ }
+
+ @Bean
+ public Binding vipLevelUpBind() {
+ return BindingBuilder.bind(vipLevelUpQueue()).to(vipLevelUp()).with(RabbitQueueEnum.VIP_LEVEL_UP.getRoute());
+ }
+
}
diff --git a/src/main/java/cc/mrbird/febs/mall/quartz/OrderSettlementJob.java b/src/main/java/cc/mrbird/febs/mall/quartz/OrderSettlementJob.java
index d532430..7b9b5c7 100644
--- a/src/main/java/cc/mrbird/febs/mall/quartz/OrderSettlementJob.java
+++ b/src/main/java/cc/mrbird/febs/mall/quartz/OrderSettlementJob.java
@@ -11,6 +11,7 @@
import cc.mrbird.febs.mall.service.IMallAchieveService;
import cc.mrbird.febs.mall.service.IMallMoneyFlowService;
import cc.mrbird.febs.mall.service.IMemberProfitService;
+import cc.mrbird.febs.rabbit.producter.AgentProducer;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
@@ -68,6 +69,9 @@
@Autowired
private IMallAchieveService mallAchieveService;
+
+ @Autowired
+ private AgentProducer agentProducer;
/**
* 普通商品结算
@@ -144,6 +148,10 @@
// }
// }
mallOrderInfoMapper.updateOrderConfirmStatus(DateUtil.date(),DateUtil.offsetDay(new Date(), -value));
+
+ orderInfos.forEach(item -> {
+ agentProducer.sendVipLevelUp(item.getId());
+ });
}
}
/**
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java
index 53f5611..bf4b5ca 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/ApiMallMemberServiceImpl.java
@@ -130,7 +130,6 @@
mallMember.setName(registerDto.getName());
mallMember.setAccountStatus(MallMember.ACCOUNT_STATUS_ENABLE);
mallMember.setAccountType(MallMember.ACCOUNT_TYPE_NORMAL);
- mallMember.setLevel(AgentLevelEnum.ZERO_LEVEL.name());
mallMember.setSex("男");
mallMember.setBindPhone(registerDto.getAccount());
@@ -722,6 +721,13 @@
if (apiXcxSaveInfoDto.getBirthday() != null) {
mallMember.setBirthday(apiXcxSaveInfoDto.getBirthday());
}
+
+ List<MallVipConfig> configs = mallVipConfigMapper.selectVipConfigList();
+ if (CollUtil.isNotEmpty(configs)) {
+ MallVipConfig mallVipConfig = configs.get(0);
+ mallMember.setLevel(mallVipConfig.getCode());
+ }
+
mallMember.setSex(1 == apiXcxSaveInfoDto.getGender() ? "女" : "男");
this.baseMapper.updateById(mallMember);
return new FebsResponse().success();
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 a612d58..ca2324c 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
@@ -580,6 +580,8 @@
orderInfo.setReceivingTime(new Date());
this.baseMapper.updateById(orderInfo);
+ agentProducer.sendVipLevelUp(orderInfo.getId());
+
//生成一条团长提成记录
// Long orderInfoId = orderInfo.getId();
// List<MallOrderItem> mallOrderItemList = mallOrderItemMapper.selectListByOrderId(orderInfoId);
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 2470a96..1de63b7 100644
--- a/src/main/java/cc/mrbird/febs/rabbit/constants/QueueConstants.java
+++ b/src/main/java/cc/mrbird/febs/rabbit/constants/QueueConstants.java
@@ -14,4 +14,5 @@
public static final String ORDER_COUPON = "queue_order_coupon";
public static final String GET_SCORE_MSG = "queue_get_score_msg";
+ public static final String VIP_LEVEL_UP = "queue_vip_level_up";
}
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 972bd28..366ac20 100644
--- a/src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java
+++ b/src/main/java/cc/mrbird/febs/rabbit/consumer/AgentConsumer.java
@@ -96,4 +96,14 @@
log.error("获取积分消息异常", e);
}
}
+
+ @RabbitListener(queues = QueueConstants.VIP_LEVEL_UP)
+ public void vipLevelUp(Long orderId) {
+ log.info("收到会员升级消息:{}", orderId);
+ try {
+ vipCommonService.levelUp(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 8d11cf6..f567b9c 100644
--- a/src/main/java/cc/mrbird/febs/rabbit/enumerates/RabbitQueueEnum.java
+++ b/src/main/java/cc/mrbird/febs/rabbit/enumerates/RabbitQueueEnum.java
@@ -17,7 +17,9 @@
ORDER_COUPON("exchange_order_coupon", "route_key_order_coupon", QueueConstants.ORDER_COUPON),
- GET_SCORE_MSG("exchange_get_score_msg", "route_key_get_score_msg", QueueConstants.GET_SCORE_MSG);
+ GET_SCORE_MSG("exchange_get_score_msg", "route_key_get_score_msg", QueueConstants.GET_SCORE_MSG),
+
+ VIP_LEVEL_UP("exchange_vip_level_up", "route_key_vip_level_up", QueueConstants.VIP_LEVEL_UP);
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 d18c404..501fdbb 100644
--- a/src/main/java/cc/mrbird/febs/rabbit/producter/AgentProducer.java
+++ b/src/main/java/cc/mrbird/febs/rabbit/producter/AgentProducer.java
@@ -90,4 +90,11 @@
CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
rabbitTemplate.convertAndSend(RabbitQueueEnum.GET_SCORE_MSG.getExchange(), RabbitQueueEnum.GET_SCORE_MSG.getRoute(), orderId, correlationData);
}
+
+ public void sendVipLevelUp(Long orderId) {
+ log.info("发送会员升级消息:{}", orderId);
+
+ CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
+ rabbitTemplate.convertAndSend(RabbitQueueEnum.VIP_LEVEL_UP.getExchange(), RabbitQueueEnum.VIP_LEVEL_UP.getRoute(), orderId, correlationData);
+ }
}
diff --git a/src/main/java/cc/mrbird/febs/vip/entity/MallVipConfig.java b/src/main/java/cc/mrbird/febs/vip/entity/MallVipConfig.java
index c2d59b3..c9670a3 100644
--- a/src/main/java/cc/mrbird/febs/vip/entity/MallVipConfig.java
+++ b/src/main/java/cc/mrbird/febs/vip/entity/MallVipConfig.java
@@ -7,6 +7,7 @@
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
+import java.math.BigDecimal;
import java.util.List;
@Data
@@ -56,7 +57,7 @@
/**
* 消费金额
*/
- private Double amount;
+ private BigDecimal amount;
/**
* 指定月数
diff --git a/src/main/java/cc/mrbird/febs/vip/service/IVipCommonService.java b/src/main/java/cc/mrbird/febs/vip/service/IVipCommonService.java
index 9cf7861..e07a285 100644
--- a/src/main/java/cc/mrbird/febs/vip/service/IVipCommonService.java
+++ b/src/main/java/cc/mrbird/febs/vip/service/IVipCommonService.java
@@ -3,4 +3,6 @@
public interface IVipCommonService {
void getScore(Long orderId);
+
+ void levelUp(Long orderId);
}
diff --git a/src/main/java/cc/mrbird/febs/vip/service/impl/VipCommonServiceImpl.java b/src/main/java/cc/mrbird/febs/vip/service/impl/VipCommonServiceImpl.java
index 2f1d1b1..c62a9f9 100644
--- a/src/main/java/cc/mrbird/febs/vip/service/impl/VipCommonServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/vip/service/impl/VipCommonServiceImpl.java
@@ -3,21 +3,30 @@
import cc.mrbird.febs.common.enumerates.FlowTypeEnum;
import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum;
import cc.mrbird.febs.common.enumerates.ScoreFlowTypeEnum;
+import cc.mrbird.febs.mall.entity.MallMember;
import cc.mrbird.febs.mall.entity.MallOrderInfo;
import cc.mrbird.febs.mall.entity.MallOrderItem;
+import cc.mrbird.febs.mall.mapper.MallMemberMapper;
import cc.mrbird.febs.mall.mapper.MallOrderInfoMapper;
import cc.mrbird.febs.mall.service.IApiMallMemberWalletService;
import cc.mrbird.febs.mall.service.IApiMallOrderInfoService;
import cc.mrbird.febs.mall.service.IMallMoneyFlowService;
import cc.mrbird.febs.vip.entity.MallVipBenefits;
+import cc.mrbird.febs.vip.entity.MallVipConfig;
+import cc.mrbird.febs.vip.mapper.MallVipConfigMapper;
import cc.mrbird.febs.vip.service.IMallVipConfigService;
import cc.mrbird.febs.vip.service.IVipCommonService;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
@Slf4j
@Service
@@ -28,6 +37,8 @@
private final IMallVipConfigService mallVipConfigService;
private final IMallMoneyFlowService mallMoneyFlowService;
private final IApiMallMemberWalletService mallMemberWalletService;
+ private final MallMemberMapper mallMemberMapper;
+ private final MallVipConfigMapper mallVipConfigMapper;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -54,4 +65,92 @@
mallMoneyFlowService.addMoneyFlow(memberId, new BigDecimal(score), ScoreFlowTypeEnum.BUY.getValue(), mallOrderInfo.getOrderNo(), FlowTypeEnum.PRIZE_SCORE.getValue(), name, 2);
mallMemberWalletService.add(new BigDecimal(score), memberId, "prize_score");
}
+
+ @Override
+ public void levelUp(Long orderId) {
+ MallOrderInfo mallOrderInfo = mallOrderInfoMapper.selectOrderDetailsById(orderId);
+ if (mallOrderInfo == null) {
+ return;
+ }
+
+ MallMember member = mallMemberMapper.selectById(mallOrderInfo.getMemberId());
+ if (member == null) {
+ log.info("会员不存在");
+ return;
+ }
+
+ MallVipConfig config = mallVipConfigMapper.selectVipConfigByCode(member.getLevel());
+ if (config == null) {
+ log.info("会员等级配置不存在");
+ return;
+ }
+
+ LambdaQueryWrapper<MallVipConfig> configQuery = new LambdaQueryWrapper<>();
+ configQuery.gt(MallVipConfig::getLevel, config.getLevel())
+ .orderByAsc(MallVipConfig::getLevel)
+ .last("limit 1");
+ MallVipConfig nextLevel = mallVipConfigMapper.selectOne(configQuery);
+
+ // 指定商品
+ if (nextLevel.getType() == 1) {
+ boolean hasMatch = mallOrderInfo.getItems().stream().anyMatch(item -> {
+ return item.getGoodsId().equals(nextLevel.getTargetId());
+ });
+
+ if (!hasMatch) {
+ log.info("未购买指定商品");
+ return;
+ }
+
+ MallMember update = new MallMember();
+ update.setId(member.getId());
+ update.setLevel(nextLevel.getCode());
+ mallMemberMapper.updateById(update);
+ return;
+ }
+
+ //
+ if (nextLevel.getType() == 2) {
+ Date endTime = DateUtil.endOfDay(new Date());
+ Date startTime = getStartTime(nextLevel.getValidType());
+
+ LambdaQueryWrapper<MallOrderInfo> query = new LambdaQueryWrapper<>();
+ query.ge(MallOrderInfo::getReceivingTime, startTime)
+ .le(MallOrderInfo::getReceivingTime, endTime)
+ .eq(MallOrderInfo::getStatus, 4)
+ .eq(MallOrderInfo::getMemberId, member.getId());
+ List<MallOrderInfo> orderList = mallOrderInfoMapper.selectList(query);
+ if (CollUtil.isEmpty(orderList)) {
+ return;
+ }
+
+ double totalAmount = orderList.stream().mapToDouble(item -> {
+ return item.getAmount().doubleValue();
+ }).sum();
+
+ if (nextLevel.getAmount().compareTo(BigDecimal.valueOf(totalAmount)) > 0) {
+ log.info("未达到指定金额:{}, {}", nextLevel.getAmount(), totalAmount);
+ return;
+ }
+
+ MallMember update = new MallMember();
+ update.setId(member.getId());
+ update.setLevel(nextLevel.getCode());
+ mallMemberMapper.updateById(update);
+ }
+ }
+
+ private Date getStartTime(String type) {
+ Date date = new Date();
+ switch (type) {
+ case "day" :
+ return DateUtil.beginOfDay(date);
+ case "month":
+ return DateUtil.beginOfMonth(date);
+ case "year":
+ return DateUtil.beginOfYear(date);
+ default:
+ return date;
+ }
+ }
}
--
Gitblit v1.9.1