From 90c31b4e2be82bd9a47115e939a9ad103271fbfa Mon Sep 17 00:00:00 2001
From: Hentua <wangdoubleone@gmail.com>
Date: Fri, 26 Jan 2024 22:12:40 +0800
Subject: [PATCH] fix
---
src/main/java/cc/mrbird/febs/mall/vo/OrderListVo.java | 3 +
src/main/java/cc/mrbird/febs/vip/service/impl/VipCommonServiceImpl.java | 96 ++++++++++++++++++++++++-----------------------
src/test/java/cc/mrbird/febs/ProfitTest.java | 5 ++
src/main/java/cc/mrbird/febs/vip/service/impl/MallVipBenefitsServiceImpl.java | 1
src/main/resources/mapper/modules/MallVipConfigMapper.xml | 3 +
src/main/resources/mapper/modules/MallOrderInfoMapper.xml | 1
src/main/java/cc/mrbird/febs/mall/entity/MallOrderInfo.java | 2 +
7 files changed, 63 insertions(+), 48 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/mall/entity/MallOrderInfo.java b/src/main/java/cc/mrbird/febs/mall/entity/MallOrderInfo.java
index 98d59df..5754d1c 100644
--- a/src/main/java/cc/mrbird/febs/mall/entity/MallOrderInfo.java
+++ b/src/main/java/cc/mrbird/febs/mall/entity/MallOrderInfo.java
@@ -142,4 +142,6 @@
@TableField(exist = false)
private String expressNo;
+
+ private Integer isFree;
}
diff --git a/src/main/java/cc/mrbird/febs/mall/vo/OrderListVo.java b/src/main/java/cc/mrbird/febs/mall/vo/OrderListVo.java
index fb76c4f..a1a4923 100644
--- a/src/main/java/cc/mrbird/febs/mall/vo/OrderListVo.java
+++ b/src/main/java/cc/mrbird/febs/mall/vo/OrderListVo.java
@@ -60,4 +60,7 @@
@ApiModelProperty(value = "快递单号")
private String expressNo;
+
+ @ApiModelProperty(value = "是否赠送 1-是 2-否")
+ private Integer isFree;
}
diff --git a/src/main/java/cc/mrbird/febs/vip/service/impl/MallVipBenefitsServiceImpl.java b/src/main/java/cc/mrbird/febs/vip/service/impl/MallVipBenefitsServiceImpl.java
index 6c072bb..2603b67 100644
--- a/src/main/java/cc/mrbird/febs/vip/service/impl/MallVipBenefitsServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/vip/service/impl/MallVipBenefitsServiceImpl.java
@@ -207,6 +207,7 @@
orderInfo.setStatus(OrderStatusEnum.WAIT_SHIPPING.getValue());
orderInfo.setOrderType(goods.getGoodsType());
orderInfo.setDeliveryType(2);
+ orderInfo.setIsFree(1);
orderInfo.setCarriage(BigDecimal.ZERO);
orderInfo.setAmount(BigDecimal.ZERO);
orderInfo.setAddressId(address.getId());
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 c62a9f9..baf88ea 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
@@ -85,59 +85,61 @@
return;
}
- LambdaQueryWrapper<MallVipConfig> configQuery = new LambdaQueryWrapper<>();
- configQuery.gt(MallVipConfig::getLevel, config.getLevel())
- .orderByAsc(MallVipConfig::getLevel)
- .last("limit 1");
- MallVipConfig nextLevel = mallVipConfigMapper.selectOne(configQuery);
+// 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());
- });
+ List<MallVipConfig> configs = mallVipConfigMapper.selectVipConfigList();
- if (!hasMatch) {
- log.info("未购买指定商品");
- return;
+ String nextLevelCode = "";
+ for (MallVipConfig nextLevel : configs) {
+ if (config.getLevel() >= nextLevel.getLevel()) {
+ continue;
}
- MallMember update = new MallMember();
- update.setId(member.getId());
- update.setLevel(nextLevel.getCode());
- mallMemberMapper.updateById(update);
- return;
+ // 指定商品
+ if (nextLevel.getType() == 1) {
+ boolean hasMatch = mallOrderInfo.getItems().stream().anyMatch(item -> {
+ return item.getGoodsId().equals(nextLevel.getTargetId());
+ });
+
+ if (hasMatch) {
+ nextLevelCode = nextLevel.getCode();
+ continue;
+ }
+ }
+
+ // 时间区间内金额
+ 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)) {
+ continue;
+ }
+
+ double totalAmount = orderList.stream().mapToDouble(item -> {
+ return item.getAmount().doubleValue();
+ }).sum();
+
+ if (nextLevel.getAmount().compareTo(BigDecimal.valueOf(totalAmount)) <= 0) {
+ nextLevelCode = nextLevel.getCode();
+ }
+ }
}
- //
- 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);
- }
+ MallMember update = new MallMember();
+ update.setId(member.getId());
+ update.setLevel(nextLevelCode);
+ mallMemberMapper.updateById(update);
}
private Date getStartTime(String type) {
diff --git a/src/main/resources/mapper/modules/MallOrderInfoMapper.xml b/src/main/resources/mapper/modules/MallOrderInfoMapper.xml
index e79c710..80c06bf 100644
--- a/src/main/resources/mapper/modules/MallOrderInfoMapper.xml
+++ b/src/main/resources/mapper/modules/MallOrderInfoMapper.xml
@@ -374,6 +374,7 @@
<result column="take_unique_code" property="takeUniqueCode" />
<result column="delivery_state" property="deliveryState" />
<result column="is_home" property="isHome" />
+ <result column="is_free" property="isFree" />
<result column="del_flag" property="delFlag" />
<result column="leader_name" property="leaderName" />
<result column="leader_phone" property="leaderPhone" />
diff --git a/src/main/resources/mapper/modules/MallVipConfigMapper.xml b/src/main/resources/mapper/modules/MallVipConfigMapper.xml
index 5387d10..57a7c24 100644
--- a/src/main/resources/mapper/modules/MallVipConfigMapper.xml
+++ b/src/main/resources/mapper/modules/MallVipConfigMapper.xml
@@ -8,8 +8,9 @@
<result property="thumb" column="thumb" />
<result property="level" column="level" />
<result property="validTime" column="valid_time" />
- <result property="validType" column="valid_time" />
+ <result property="validType" column="valid_type" />
<result property="type" column="type" />
+ <result property="code" column="code" />
<result property="amount" column="amount" />
<result property="times" column="times" />
<result property="targetId" column="target_id" />
diff --git a/src/test/java/cc/mrbird/febs/ProfitTest.java b/src/test/java/cc/mrbird/febs/ProfitTest.java
index 8a8d677..a5722e7 100644
--- a/src/test/java/cc/mrbird/febs/ProfitTest.java
+++ b/src/test/java/cc/mrbird/febs/ProfitTest.java
@@ -967,4 +967,9 @@
BigDecimal amount = new BigDecimal("0.15").setScale(2,BigDecimal.ROUND_DOWN);
System.out.println(amount);
}
+
+ @Test
+ public void aaaTest() {
+ agentConsumer.vipLevelUp(133L);
+ }
}
--
Gitblit v1.9.1