diff --git a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/DateUtils.java b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/DateUtils.java
index 4337fa7b..e4941182 100644
--- a/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/DateUtils.java
+++ b/smart-switch-ruoyi/smart-switch-common/src/main/java/com/ruoyi/common/utils/DateUtils.java
@@ -332,10 +332,14 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
* 获取下一个周一
*/
public static LocalDateTime nextMonday(LocalDateTime time) {
+ LocalDateTime result;
+
if (time.getDayOfWeek() == DayOfWeek.MONDAY) {
- return time.plusDays(7);
+ result = time.plusDays(7);
} else {
- return time.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
+ result = time.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
}
+
+ return result.withHour(0).withMinute(0).withSecond(0).withNano(0);
}
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/mapper/BonusMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/mapper/BonusMapper.xml
index 9076e63e..066c6f9e 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/mapper/BonusMapper.xml
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/mapper/BonusMapper.xml
@@ -26,7 +26,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sb.payed_amount,
sb.wait_amount,
sb.to_balance,
- sb.by_hand
+ sb.by_hand,
+ sb.bst_type
@@ -53,6 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and sb.pre_pay_time <= #{query.prePayTimeEnd}
and sb.to_balance = #{query.toBalance}
and sb.by_hand = #{query.byHand}
+ and sb.bst_type = #{query.bstType}
and date(sb.pay_time) = #{query.payDate}
@@ -261,6 +263,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
wait_amount,
to_balance,
by_hand,
+ bst_type,
#{billId},
@@ -281,6 +284,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{waitAmount},
#{toBalance},
#{byHand},
+ #{bstType},
@@ -302,7 +306,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
pre_pay_time,
payed_amount,
wait_amount,
- to_balance
+ to_balance,
+ bst_type
)
values
@@ -341,6 +346,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
default,
#{i.toBalance},
default,
+ #{i.bstType},
+ default,
@@ -454,6 +461,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
wait_amount = #{data.waitAmount},
to_balance = #{data.toBalance},
by_hand = #{data.byHand},
+ bst_type = #{data.bstType},
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/BonusService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/BonusService.java
index d7b9daf5..33b87cc0 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/BonusService.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/BonusService.java
@@ -8,6 +8,7 @@ import com.ruoyi.ss.bonus.domain.Bonus;
import com.ruoyi.ss.bonus.domain.BonusProvideQuery;
import com.ruoyi.ss.bonus.domain.BonusQuery;
import com.ruoyi.ss.bonus.domain.BonusVO;
+import com.ruoyi.ss.bonus.domain.enums.BonusBstType;
import com.ruoyi.ss.bonus.domain.vo.BonusDailyAmountVO;
import com.ruoyi.ss.bonus.domain.vo.BonusMonthAmountVO;
import com.ruoyi.ss.bonus.domain.vo.ProvideBonusVO;
@@ -172,4 +173,9 @@ public interface BonusService
* 扣减分成方余额
*/
int subtractBalance(Long id, BigDecimal amount);
+
+ /**
+ * 查询分成明细
+ */
+ List selectBonusByBstId(BonusBstType bstType, Long bstId);
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/impl/BonusConverterImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/impl/BonusConverterImpl.java
index f3ddd371..2b3ac67d 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/impl/BonusConverterImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/impl/BonusConverterImpl.java
@@ -250,6 +250,9 @@ public class BonusConverterImpl implements BonusConverter {
if (dept == null) {
return null;
}
+ if (point == null) {
+ point = BigDecimal.ZERO;
+ }
Bonus po = new Bonus();
po.setStatus(BonusStatus.UN_DIVIDEND.getStatus());
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/impl/BonusServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/impl/BonusServiceImpl.java
index c4fbb1af..4d5f7c0e 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/impl/BonusServiceImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/bonus/service/impl/BonusServiceImpl.java
@@ -15,6 +15,7 @@ import com.ruoyi.ss.bonus.domain.BonusProvideQuery;
import com.ruoyi.ss.bonus.domain.BonusQuery;
import com.ruoyi.ss.bonus.domain.BonusVO;
import com.ruoyi.ss.bonus.domain.enums.BonusArrivalType;
+import com.ruoyi.ss.bonus.domain.enums.BonusBstType;
import com.ruoyi.ss.bonus.domain.enums.BonusStatus;
import com.ruoyi.ss.bonus.domain.vo.BonusDailyAmountVO;
import com.ruoyi.ss.bonus.domain.vo.BonusMonthAmountVO;
@@ -36,6 +37,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.Arrays;
+import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@@ -166,7 +168,8 @@ public class BonusServiceImpl implements BonusService
// 若需要打款到余额,根据类型,添加金额
if (bonus.getToBalance() != null && bonus.getToBalance()) {
if (BonusArrivalType.userList().contains(bonus.getArrivalType())) {
- int add = userService.addBalance(bonus.getArrivalId(), bonus.getWaitAmount(), String.format("订单分成:%s", bonus.getBillNo()), RecordBalanceBstType.RECHARGE, bonus.getBillId());
+ String reason = this.getReason(bonus.getBstType(), bonus.getBillNo());
+ int add = userService.addBalance(bonus.getArrivalId(), bonus.getWaitAmount(), reason, RecordBalanceBstType.RECHARGE, bonus.getBillId());
ServiceUtil.assertion(add != 1, "增加账户金额失败");
} else if (BonusArrivalType.deptList().contains(bonus.getArrivalType())) {
// add = deptService.addBalance(bonus.getArrivalId(), bonus.getAmount(), String.format("订单分成:%s", bonus.getBillNo()), RecordBalanceBstType.RECHARGE, bonus.getBillId());
@@ -179,6 +182,16 @@ public class BonusServiceImpl implements BonusService
return result == null ? 0 : result;
}
+ // 获取打款理由
+ private String getReason(String bstType, String billNo) {
+ if (BonusBstType.RECHARGE.getType().equals(bstType)) {
+ return String.format("充值订单分成:%s", billNo);
+ } else if (BonusBstType.VIP.getType().equals(bstType)) {
+ return String.format("VIP订单分成:%s", billNo);
+ }
+ return null;
+ }
+
@Override
public void partBonus(List bonusList, BigDecimal money) {
if (CollectionUtils.isEmptyElement(bonusList) || money == null) {
@@ -426,6 +439,17 @@ public class BonusServiceImpl implements BonusService
return result == null ? 0 : result;
}
+ @Override
+ public List selectBonusByBstId(BonusBstType bstType, Long bstId) {
+ if (bstType == null || bstId == null) {
+ return Collections.emptyList();
+ }
+ BonusQuery query = new BonusQuery();
+ query.setBstType(bstType.getType());
+ query.setBillId(bstId);
+ return this.selectBonusList(query);
+ }
+
private int batchUpdateAmount(List list) {
if (CollectionUtils.isEmptyElement(list)) {
return 0;
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/domain/enums/PayBillBstType.java b/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/domain/enums/PayBillBstType.java
index 0a6fe5d1..af84bbda 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/domain/enums/PayBillBstType.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/domain/enums/PayBillBstType.java
@@ -4,6 +4,7 @@ import com.ruoyi.ss.payBill.interfaces.AfterPay;
import com.ruoyi.ss.payBill.interfaces.AfterRefund;
import com.ruoyi.ss.transactionBill.service.impl.RechargeDepositAfterPay;
import com.ruoyi.ss.transactionBill.service.impl.RechargePayHandler;
+import com.ruoyi.ss.vipOrder.service.impl.VipOrderServiceImpl;
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -23,7 +24,7 @@ public enum PayBillBstType {
ELECTRICITY_RECHARGE("2", "电量充值订单", null, null),
RECHARGE_ORDER("4", "充值订单", RechargePayHandler.class, RechargePayHandler.class),
RECHARGE_ORDER_DEPOSIT("5", "充值订单押金", RechargeDepositAfterPay.class, null),
- VIP_ORDER("6", "VIP订单", null, null);
+ VIP_ORDER("6", "VIP订单", VipOrderServiceImpl.class, VipOrderServiceImpl.class);
private final String type;
private final String msg;
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/PayBillService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/PayBillService.java
index 155a1b80..a64acd98 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/PayBillService.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/PayBillService.java
@@ -5,6 +5,7 @@ import com.ruoyi.ss.payBill.domain.PayBill;
import com.ruoyi.ss.payBill.domain.PayBillQuery;
import com.ruoyi.ss.payBill.domain.PayBillVO;
import com.ruoyi.ss.payBill.domain.dto.PayBillRefundDTO;
+import com.ruoyi.ss.payBill.domain.enums.PayBillBstType;
import com.ruoyi.ss.payBill.domain.vo.DoPayVO;
import com.ruoyi.ss.payBill.domain.vo.PayResultVO;
import com.ruoyi.ss.refund.domain.RefundVO;
@@ -145,4 +146,9 @@ public interface PayBillService
* 按日查询支付金额
*/
List selectDailyAmount(PayBillQuery query);
+
+ /**
+ * 刷新支付结果
+ */
+ public int refreshPayResult(PayBillBstType bstType, Long bstId);
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillServiceImpl.java
index 71c53d6b..daca69c9 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillServiceImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/payBill/service/impl/PayBillServiceImpl.java
@@ -394,6 +394,15 @@ public class PayBillServiceImpl implements PayBillService
return this.refreshPayResult(Collections.singletonList(payBill));
}
+ @Override
+ public int refreshPayResult(PayBillBstType bstType, Long bstId) {
+ if (bstType == null || bstId == null) {
+ return 0;
+ }
+ List payList = this.selectByBstId(bstId, bstType.getType());
+ return this.refreshPayResult(payList);
+ }
+
@Override
public int refund(PayBillRefundDTO dto) {
// 校验订单
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java
index d382c5f1..e933fd45 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/transactionBill/service/impl/TransactionBillServiceImpl.java
@@ -1654,7 +1654,9 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
return 0;
}
- // 构建退款列表
+ // FIXME 构建退款列表
+ // FIXME 多次退款有问题,比如商户已经退款0.3元,剩余0.2元,第二次退款的时候,还是给商户分配了0.3元的退款,此时退款会失败。
+ // FIXME 需要重新考虑一下退款金额的分配规则。
List refundList = new ArrayList<>(); // 退款的列表
BigDecimal dividedAmount = BigDecimal.ZERO; // 已分配金额
for (BonusVO bonus : bonusList) {
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/domain/Vip.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/domain/Vip.java
index 22ba9648..be7b423a 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/domain/Vip.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/domain/Vip.java
@@ -77,4 +77,7 @@ public class Vip extends BaseEntity
@ApiModelProperty("限制次数")
private Integer limitCount;
+ @Excel(name = "总剩余次数")
+ @ApiModelProperty("总剩余次数")
+ private Integer surplusCount;
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/domain/VipVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/domain/VipVO.java
index 315f9db4..bdf6a88c 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/domain/VipVO.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/domain/VipVO.java
@@ -1,9 +1,5 @@
package com.ruoyi.ss.vip.domain;
-import java.util.List;
-
-import com.ruoyi.ss.store.domain.StoreVo;
-
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -26,6 +22,13 @@ public class VipVO extends Vip{
@ApiModelProperty("VIP商户ID")
private Long vipMchId;
- @ApiModelProperty("店铺列表")
- private List storeList;
+ @ApiModelProperty("店铺名称")
+ private String storeName;
+
+ @ApiModelProperty("商户名称")
+ private String mchName;
+
+ @ApiModelProperty("是否在有效期内")
+ private Boolean inValid;
+
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/mapper/VipMapper.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/mapper/VipMapper.java
index 993b7f54..ac167268 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/mapper/VipMapper.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/mapper/VipMapper.java
@@ -71,5 +71,10 @@ public interface VipMapper
/**
* 续费
*/
- int renewal(@Param("id")Long id, @Param("days") Integer days);
+ int renewal(@Param("id")Long id, @Param("days") Integer days, @Param("count") Integer count);
+
+ /**
+ * 逻辑删除
+ */
+ int logicDel(@Param("ids") List ids);
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/mapper/VipMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/mapper/VipMapper.xml
index 8949eff5..406ad397 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/mapper/VipMapper.xml
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/mapper/VipMapper.xml
@@ -6,6 +6,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+
+
+ (sv.start_time <= now() and sv.end_time >= now())
+
+
select
sv.id,
@@ -21,12 +26,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sv.round_count,
sv.limit_type,
sv.limit_count,
+ sv.surplus_count,
+ sv.deleted,
+ as in_valid,
if(su.is_real, su.real_name, su.user_name) as user_name,
svl.name as vip_level_name,
- svl.mch_id as vip_mch_id
+ svl.mch_id as vip_mch_id,
+ ss.user_id as store_mch_id,
+ ss.name as store_name,
+ if(mch.is_real, mch.real_name, mch.user_name) as mch_name
from ss_vip sv
left join sm_user su on su.user_id = sv.user_id
left join ss_vip_level svl on svl.id = sv.level_id
+ left join sm_store ss on ss.store_id = svl.store_id
+ left join sm_user mch on mch.user_id = svl.mch_id
@@ -36,12 +49,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and sv.start_time = #{query.startTime}
and sv.end_time = #{query.endTime}
and sv.discount = #{query.discount}
- and sv.store_id = #{query.storeId}
+ and sv.store_id = #{query.storeId}
+ and ss.name like concat('%',#{query.storeName},'%')
and if(su.is_real, su.real_name, su.user_name) like concat('%',#{query.userName},'%')
+ and if(mch.is_real, mch.real_name, mch.user_name) like concat('%',#{query.mchName},'%')
and svl.name like concat('%',#{query.vipLevelName},'%')
and limit_type = #{query.limitType}
and limit_count = #{query.limitCount}
and sv.id != #{query.excludeId}
+ and sv.deleted = #{query.deleted}
+ and sv.deleted = false
+
+ and
+
+ not
+
+
+
and sv.level_id in
@@ -79,12 +103,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
start_time,
end_time,
discount,
- store_id,
+ store_id,
next_reset_time,
total_count,
round_count,
limit_type,
limit_count,
+ surplus_count,
#{userId},
@@ -93,12 +118,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{startTime},
#{endTime},
#{discount},
- #{storeId},
+ #{storeId},
#{nextResetTime},
#{totalCount},
#{roundCount},
#{limitType},
#{limitCount},
+ #{surplusCount},
@@ -111,9 +137,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
- update ss_vip
- set end_time = date_add(if(now() > end_time, now(), end_time), interval #{days} day)
- where id = #{id}
+ update ss_vip sv
+ set sv.end_time = date_add(if(now() > sv.end_time, now(), sv.end_time), interval #{days} day),
+ sv.surplus_count = if (now() <= sv.end_time, sv.surplus_count + #{count}, #{count})
+ where sv.id = #{id}
@@ -123,12 +150,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
start_time = #{data.startTime},
end_time = #{data.endTime},
discount = #{data.discount},
- store_id = #{data.storeId},
+ store_id = #{data.storeId},
next_reset_time = #{data.nextResetTime},
total_count = #{data.totalCount},
round_count = #{data.roundCount},
limit_type = #{data.limitType},
limit_count = #{data.limitCount},
+ surplus_count = #{data.surplusCount},
@@ -141,4 +169,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
+
+
+
+
+ update ss_vip
+ set deleted = true
+ where id in
+
+ #{id}
+
+ and deleted = false
+
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/VipConverter.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/VipConverter.java
index 056bfae3..5a63e27a 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/VipConverter.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/VipConverter.java
@@ -12,4 +12,9 @@ public interface VipConverter {
* 订单转会员
*/
Vip toPo(VipOrderVO order);
+
+ /**
+ * 新增会员
+ */
+ Vip toPoByAdd(Vip data);
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/VipService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/VipService.java
index 8bf326dc..8ebd58d9 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/VipService.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/VipService.java
@@ -84,7 +84,16 @@ public interface VipService
/**
* 续费 VIP
+ * @param id VIP ID
+ * @param days 续费天数
+ * @param count 可用次数(叠加)
*/
- int renewal(Long id, Integer days);
+ int renewal(Long id, Integer days, Integer count);
+ /**
+ * 逻辑删除
+ * @param ids
+ * @return
+ */
+ int logicDel(List ids);
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipConverterImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipConverterImpl.java
index 4393b2f4..c7ef26bc 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipConverterImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipConverterImpl.java
@@ -3,7 +3,10 @@ package com.ruoyi.ss.vip.service.impl;
import com.ruoyi.ss.vip.domain.Vip;
import com.ruoyi.ss.vip.service.VipConverter;
import com.ruoyi.ss.vip.utils.VipUtil;
+import com.ruoyi.ss.vipLevel.domain.VipLevel;
+import com.ruoyi.ss.vipLevel.service.VipLevelService;
import com.ruoyi.ss.vipOrder.domain.VipOrderVO;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
@@ -14,6 +17,10 @@ import java.time.LocalDateTime;
*/
@Service
public class VipConverterImpl implements VipConverter {
+
+ @Autowired
+ private VipLevelService vipLevelService;
+
@Override
public Vip toPo(VipOrderVO order) {
if (order == null) {
@@ -31,8 +38,40 @@ public class VipConverterImpl implements VipConverter {
vip.setRoundCount(0);
vip.setLimitType(order.getSkuLimitType());
vip.setLimitCount(order.getSkuLimitCount());
+ vip.setSurplusCount(order.getSkuLimitTotal());
vip.setNextResetTime(VipUtil.getNextResetTime(LocalDateTime.now(), order.getSkuLimitType()));
return vip;
}
+
+
+ @Override
+ public Vip toPoByAdd(Vip data) {
+ if (data == null) {
+ return null;
+ }
+
+ VipLevel level = vipLevelService.selectVipLevelById(data.getLevelId());
+ if(level == null) {
+ return null;
+ }
+
+ Vip vip = new Vip();
+ // 自定义数据
+ vip.setUserId(data.getUserId());
+ vip.setStartTime(data.getStartTime());
+ vip.setEndTime(data.getEndTime());
+ vip.setLimitType(data.getLimitType());
+ vip.setNextResetTime(VipUtil.getNextResetTime(LocalDateTime.now(), data.getLimitType()));
+ vip.setTotalCount(0);
+ vip.setRoundCount(0);
+ vip.setLimitCount(data.getLimitCount());
+ vip.setSurplusCount(data.getSurplusCount());
+
+ // 等级数据
+ vip.setLevelId(level.getId());
+ vip.setDiscount(level.getDiscount());
+ vip.setStoreId(level.getStoreId());
+ return vip;
+ }
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipServiceImpl.java
index 049f83fb..f0c5cfca 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipServiceImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipServiceImpl.java
@@ -144,15 +144,16 @@ public class VipServiceImpl implements VipService
query.setStoreId(storeId);
query.setLimitType(limitType);
query.setLimitCount(limitCount);
+ query.setInValid(true);
return selectOne(query);
}
@Override
- public int renewal(Long id, Integer days) {
+ public int renewal(Long id, Integer days, Integer count) {
if (id == null || days == null || days < 0) {
return 0;
}
- return vipMapper.renewal(id, days);
+ return vipMapper.renewal(id, days, count);
}
private VipVO selectOne(VipQuery query) {
@@ -160,4 +161,12 @@ public class VipServiceImpl implements VipService
List vipList = selectVipList(query);
return CollectionUtils.getFirst(vipList);
}
+
+ @Override
+ public int logicDel(List ids) {
+ if (CollectionUtils.isEmptyElement(ids)) {
+ return 0;
+ }
+ return vipMapper.logicDel(ids);
+ }
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipValidatorImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipValidatorImpl.java
index 0868cd15..3cea2f9f 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipValidatorImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vip/service/impl/VipValidatorImpl.java
@@ -1,10 +1,5 @@
package com.ruoyi.ss.vip.service.impl;
-import java.util.Objects;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.ss.store.service.StoreValidator;
import com.ruoyi.ss.user.service.UserValidator;
@@ -13,6 +8,10 @@ import com.ruoyi.ss.vip.domain.VipQuery;
import com.ruoyi.ss.vip.domain.VipVO;
import com.ruoyi.ss.vip.service.VipService;
import com.ruoyi.ss.vip.service.VipValidator;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Objects;
/**
* @author wjh
@@ -48,7 +47,7 @@ public class VipValidatorImpl implements VipValidator {
return;
}
- this.checkMch(vo.getStoreMchId(), vo.getVipMchId());
+ ServiceUtil.assertion(!Objects.equals(vo.getStoreMchId(), vo.getVipMchId()), "当前VIP等级与店铺商户不一致");
}
@Override
@@ -56,10 +55,6 @@ public class VipValidatorImpl implements VipValidator {
return vo != null && userId != null && Objects.equals(vo.getStoreMchId(), userId);
}
- private void checkMch(Long storeMchId, Long vipMchId) {
- ServiceUtil.assertion(!Objects.equals(storeMchId, vipMchId), "当前选择的VIP等级与店铺商户不一致");
- }
-
/**
* 校验用户是否重复成为店铺会员
* @param id 会员ID
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/mapper/VipLevelMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/mapper/VipLevelMapper.xml
index 117766a0..f9ae4dab 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/mapper/VipLevelMapper.xml
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevel/mapper/VipLevelMapper.xml
@@ -67,7 +67,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{discount},
#{createTime},
#{description},
- #{storeId},
+ #{storeId},
@@ -85,7 +85,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
discount = #{data.discount},
create_time = #{data.createTime},
`description` = #{data.description},
- store_id = #{data.storeId},
+ store_id = #{data.storeId},
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/domain/VipLevelSku.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/domain/VipLevelSku.java
index 66ab5563..a7c47967 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/domain/VipLevelSku.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/domain/VipLevelSku.java
@@ -8,7 +8,9 @@ import com.ruoyi.system.valid.DictValid;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
+import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
/**
@@ -65,4 +67,9 @@ public class VipLevelSku extends BaseEntity
@ApiModelProperty("原价")
private BigDecimal originalPrice;
+ @Excel(name = "限制总次数")
+ @ApiModelProperty("限制总次数")
+ @Min(value = 0, message = "限制总次数不允许小于0")
+ @NotNull(message = "限制总次数不允许为空", groups = {ValidGroup.Create.class})
+ private Integer limitTotal;
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/mapper/VipLevelSkuMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/mapper/VipLevelSkuMapper.xml
index 871c7218..6f2efddd 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/mapper/VipLevelSkuMapper.xml
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipLevelSku/mapper/VipLevelSkuMapper.xml
@@ -19,7 +19,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
svls.limit_count,
svls.status,
svls.name,
- svls.original_price
+ svls.original_price,
+ svls.limit_total
from ss_vip_level_sku svls
@@ -67,6 +68,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
`status`,
`name`,
original_price,
+ limit_total,
#{id},
@@ -81,6 +83,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{status},
#{name},
#{originalPrice},
+ #{limitTotal},
@@ -98,6 +101,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
`status`,
`name`,
original_price,
+ limit_total,
values
@@ -124,6 +128,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
default,
#{i.originalPrice},
default,
+ #{i.limitTotal},
+ default,
@@ -241,6 +247,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+
+
+
+ WHEN #{item.id} THEN #{item.limitTotal}
+
+
+ WHEN #{item.id} THEN `limit_total`
+
+
+
where id in
@@ -268,6 +284,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
`status` = #{data.status},
`name` = #{data.name},
original_price = #{data.originalPrice},
+ limit_total = #{data.limitTotal},
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrder.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrder.java
index 0375bce5..d0c5cb55 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrder.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrder.java
@@ -78,6 +78,10 @@ public class VipOrder extends BaseEntity
@ApiModelProperty("sku限制次数")
private Integer skuLimitCount;
+ @Excel(name = "sku总限制次数")
+ @ApiModelProperty("sku总限制次数")
+ private Integer skuLimitTotal;
+
@Excel(name = "实付金额")
@ApiModelProperty("实付金额")
private BigDecimal amount;
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrderQuery.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrderQuery.java
index 538d37cc..16e4ac1f 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrderQuery.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/VipOrderQuery.java
@@ -1,5 +1,6 @@
package com.ruoyi.ss.vipOrder.domain;
+import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
@@ -8,4 +9,7 @@ import lombok.Data;
*/
@Data
public class VipOrderQuery extends VipOrderVO{
+
+ @ApiModelProperty("精准订单号")
+ private String eqOrderNo;
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/dto/AddPayVipOrderDTO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/dto/AddPayVipOrderDTO.java
index 730e5265..dd5d2332 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/dto/AddPayVipOrderDTO.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/dto/AddPayVipOrderDTO.java
@@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.Min;
+import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@@ -37,13 +38,17 @@ public class AddPayVipOrderDTO {
private BigDecimal skuPrice;
@ApiModelProperty("sku限制类型")
- @NotNull(message = "sku限制类型不能为空")
+ @NotBlank(message = "sku限制类型不能为空")
private String skuLimitType;
@ApiModelProperty("sku限制次数")
@NotNull(message = "sku限制次数不能为空")
private Integer skuLimitCount;
+ @ApiModelProperty("sku总限制次数")
+ @NotNull(message = "sku总限制次数不能为空")
+ private Integer skuLimitTotal;
+
@ApiModelProperty("VIP等级折扣")
@NotNull(message = "VIP等级折扣不能为空")
private BigDecimal levelDiscount;
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/vo/AddAndPayVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/vo/AddAndPayVO.java
index 1560f253..0c1a6f32 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/vo/AddAndPayVO.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/domain/vo/AddAndPayVO.java
@@ -1,6 +1,5 @@
package com.ruoyi.ss.vipOrder.domain.vo;
-import com.ruoyi.ss.vipOrder.domain.VipOrder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -11,8 +10,11 @@ import lombok.Data;
@Data
public class AddAndPayVO {
- @ApiModelProperty("订单数据")
- private VipOrder order;
+ @ApiModelProperty("订单编号")
+ private String orderNo;
+
+ @ApiModelProperty("支付订单编号")
+ private String payNo;
@ApiModelProperty("支付参数")
private Object payParams;
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/mapper/VipOrderMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/mapper/VipOrderMapper.xml
index 099214f4..cec01a02 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/mapper/VipOrderMapper.xml
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/mapper/VipOrderMapper.xml
@@ -4,9 +4,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-
-
-
+
select
@@ -25,6 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
svo.sku_price,
svo.sku_limit_type,
svo.sku_limit_count,
+ svo.sku_limit_total,
svo.amount,
svo.expire_time,
svo.pay_id,
@@ -47,6 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
and svo.id = #{query.id}
and svo.order_no like concat('%', #{query.orderNo}, '%')
+ and svo.order_no = #{query.eqOrderNo}
and svo.user_id = #{query.userId}
and svo.mch_id = #{query.mchId}
and svo.level_id = #{query.levelId}
@@ -87,7 +87,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
level_id,
level_name,
level_discount,
- level_store_id,
+ level_store_id,
level_solution,
sku_id,
sku_name,
@@ -95,6 +95,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sku_price,
sku_limit_type,
sku_limit_count,
+ sku_limit_total,
amount,
expire_time,
pay_id,
@@ -118,7 +119,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{levelId},
#{levelName},
#{levelDiscount},
- #{levelStoreId},
+ #{levelStoreId},
#{levelSolution},
#{skuId},
#{skuName},
@@ -126,6 +127,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{skuPrice},
#{skuLimitType},
#{skuLimitCount},
+ #{skuLimitTotal},
#{amount},
#{expireTime},
#{payId},
@@ -169,7 +171,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
svo.level_id = #{data.levelId},
svo.level_name = #{data.levelName},
svo.level_discount = #{data.levelDiscount},
- svo.level_store_id = #{data.levelStoreId},
+ svo.level_store_id = #{data.levelStoreId},
svo.level_solution = #{data.levelSolution},
svo.sku_id = #{data.skuId},
svo.sku_name = #{data.skuName},
@@ -177,6 +179,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
svo.sku_price = #{data.skuPrice},
svo.sku_limit_type = #{data.skuLimitType},
svo.sku_limit_count = #{data.skuLimitCount},
+ svo.sku_limit_total = #{data.skuLimitTotal},
svo.amount = #{data.amount},
svo.expire_time = #{data.expireTime},
svo.pay_id = #{data.payId},
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/VipOrderService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/VipOrderService.java
index 2ea7c317..8da41248 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/VipOrderService.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/VipOrderService.java
@@ -68,4 +68,14 @@ public interface VipOrderService
* 下单并支付
*/
AddAndPayVO addAndPay(AddPayVipOrderBO bo);
+
+ /**
+ * 刷新支付结果
+ */
+ int refreshPayResult(Long id);
+
+ /**
+ * 刷新支付结果
+ */
+ int refreshPayResult(String orderNo);
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/VipOrderValidator.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/VipOrderValidator.java
index cca6e4de..1ba92440 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/VipOrderValidator.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/VipOrderValidator.java
@@ -1,5 +1,6 @@
package com.ruoyi.ss.vipOrder.service;
+import com.ruoyi.ss.vipOrder.domain.VipOrderVO;
import com.ruoyi.ss.vipOrder.domain.bo.AddPayVipOrderBO;
/**
@@ -12,4 +13,9 @@ public interface VipOrderValidator {
* 下单并支付校验
*/
void preAddAndPay(AddPayVipOrderBO bo);
+
+ /**
+ * 判断用户是否可以查看订单
+ */
+ boolean canView(VipOrderVO order, Long userId);
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderConverterImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderConverterImpl.java
index 95e871be..a229c01c 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderConverterImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderConverterImpl.java
@@ -126,6 +126,7 @@ public class VipOrderConverterImpl implements VipOrderConverter {
order.setSkuPrice(sku.getPrice());
order.setSkuLimitType(sku.getLimitType());
order.setSkuLimitCount(sku.getLimitCount());
+ order.setSkuLimitTotal(sku.getLimitTotal());
}
// 渠道信息
ChannelVO channel = bo.getChannel();
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderServiceImpl.java
index 04094174..0888296c 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderServiceImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderServiceImpl.java
@@ -1,14 +1,18 @@
package com.ruoyi.ss.vipOrder.service.impl;
+import com.github.pagehelper.PageHelper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServiceUtil;
import com.ruoyi.common.utils.SnowFlakeUtil;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.bonus.domain.Bonus;
import com.ruoyi.ss.bonus.service.BonusConverter;
import com.ruoyi.ss.bonus.service.BonusService;
import com.ruoyi.ss.payBill.domain.PayBill;
import com.ruoyi.ss.payBill.domain.PayBillVO;
import com.ruoyi.ss.payBill.domain.bo.RefundSuccessBO;
+import com.ruoyi.ss.payBill.domain.enums.PayBillBstType;
import com.ruoyi.ss.payBill.domain.vo.DoPayVO;
import com.ruoyi.ss.payBill.interfaces.AfterPay;
import com.ruoyi.ss.payBill.interfaces.AfterRefund;
@@ -165,8 +169,6 @@ public class VipOrderServiceImpl implements VipOrderService, AfterPay, AfterRefu
// 转为订单数据
VipOrder order = vipOrderConverter.toOrder(bo);
ServiceUtil.assertion(order == null, "订单数据为空");
- // 订单数据加入结果集和上下文
- result.setOrder(order);
bo.setOrder(order);
// 操作数据库
@@ -180,11 +182,20 @@ public class VipOrderServiceImpl implements VipOrderService, AfterPay, AfterRefu
ServiceUtil.assertion(pay == null, "支付单数据为空");
DoPayVO payResult = payBillService.createPayBill(pay);
ServiceUtil.assertion(payResult == null, "调起支付失败");
+
+ // 构造结果集
result.setPayParams(payResult.getPayParams());
+ result.setPayNo(pay.getPayNo());
+ result.setOrderNo(order.getOrderNo());
return insert;
});
+ // TODO 模拟支付成功
+ scheduledExecutorService.schedule(() -> {
+ payBillService.handleSuccess(result.getPayNo(), LocalDateTime.now());
+ }, 3, TimeUnit.SECONDS);
+
return result;
}
@@ -248,7 +259,7 @@ public class VipOrderServiceImpl implements VipOrderService, AfterPay, AfterRefu
);
// 可兼容操作
if (vip != null ) {
- int renewal = vipService.renewal(vip.getId(), order.getSkuTime());
+ int renewal = vipService.renewal(vip.getId(), order.getSkuTime(), order.getSkuLimitTotal());
ServiceUtil.assertion(renewal != 1, "续费ID为%s的VIP失败", vip.getId());
return renewal;
}
@@ -274,4 +285,38 @@ public class VipOrderServiceImpl implements VipOrderService, AfterPay, AfterRefu
public int onRefundSuccess(RefundSuccessBO bo) {
return 0;
}
+
+ @Override
+ public int refreshPayResult(Long id) {
+ if (id == null) {
+ return 0;
+ }
+ return payBillService.refreshPayResult(PayBillBstType.VIP_ORDER, id);
+ }
+
+ @Override
+ public int refreshPayResult(String orderNo) {
+ if (StringUtils.isBlank(orderNo)) {
+ return 0;
+ }
+ VipOrderVO order = selectVipOrderByOrderNo(orderNo);
+ if (order == null || order.getId() == null) {
+ return 0;
+ }
+ return payBillService.refreshPayResult(PayBillBstType.VIP_ORDER, order.getId());
+ }
+
+ // 根据订单号查询订单
+ private VipOrderVO selectVipOrderByOrderNo(String orderNo) {
+ VipOrderQuery query = new VipOrderQuery();
+ query.setEqOrderNo(orderNo);
+ return this.selectOne(query);
+ }
+
+ // 根据查询条件查询一个订单
+ private VipOrderVO selectOne(VipOrderQuery query) {
+ PageHelper.startPage(1, 1);
+ List list = this.selectVipOrderList(query);
+ return CollectionUtils.firstElement(list);
+ }
}
diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderValidatorImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderValidatorImpl.java
index b4b9d1bf..b5e8f3ae 100644
--- a/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderValidatorImpl.java
+++ b/smart-switch-service/src/main/java/com/ruoyi/ss/vipOrder/service/impl/VipOrderValidatorImpl.java
@@ -2,6 +2,10 @@ package com.ruoyi.ss.vipOrder.service.impl;
import com.ruoyi.common.utils.MathUtils;
import com.ruoyi.common.utils.ServiceUtil;
+import com.ruoyi.ss.bonus.domain.BonusVO;
+import com.ruoyi.ss.bonus.domain.enums.BonusArrivalType;
+import com.ruoyi.ss.bonus.domain.enums.BonusBstType;
+import com.ruoyi.ss.bonus.service.BonusService;
import com.ruoyi.ss.channel.domain.ChannelVO;
import com.ruoyi.ss.user.domain.SmUserVO;
import com.ruoyi.ss.vip.domain.VipVO;
@@ -9,6 +13,7 @@ import com.ruoyi.ss.vip.service.VipService;
import com.ruoyi.ss.vipLevel.domain.VipLevelVO;
import com.ruoyi.ss.vipLevelSku.domain.VipLevelSkuVO;
import com.ruoyi.ss.vipLevelSku.domain.enums.VipLevelSkuStatus;
+import com.ruoyi.ss.vipOrder.domain.VipOrderVO;
import com.ruoyi.ss.vipOrder.domain.bo.AddPayVipOrderBO;
import com.ruoyi.ss.vipOrder.domain.dto.AddPayVipOrderDTO;
import com.ruoyi.ss.vipOrder.service.VipOrderValidator;
@@ -16,6 +21,7 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import java.util.List;
import java.util.Objects;
/**
@@ -28,6 +34,9 @@ public class VipOrderValidatorImpl implements VipOrderValidator {
@Autowired
private VipService vipService;
+ @Autowired
+ private BonusService bonusService;
+
@Override
public void preAddAndPay(AddPayVipOrderBO bo) {
ServiceUtil.assertion(bo == null, "参数错误");
@@ -41,20 +50,21 @@ public class VipOrderValidatorImpl implements VipOrderValidator {
// 校验用户前端查看到的数据和后台数据是否一致
ServiceUtil.assertion(sku == null, "ID为%sVIP等级价格不存在", dto.getSkuId());
- ServiceUtil.assertion(level == null, "的VIP等级不存在");
+ ServiceUtil.assertion(level == null, "ID为%s的VIP等级不存在", sku.getLevelId());
ServiceUtil.assertion(!VipLevelSkuStatus.ON_SALE.getStatus().equals(sku.getStatus()), "ID为%s的SKU目前不可购买", sku.getId());
- ServiceUtil.assertion(!Objects.equals(dto.getSkuLimitType(), sku.getLimitType()), "当前使用限制已发生变化,请重新下单");
- ServiceUtil.assertion(!Objects.equals(dto.getSkuLimitCount(), sku.getLimitCount()), "当前限制次数已发生变化,请重新下单");
+ ServiceUtil.assertion(!Objects.equals(dto.getSkuLimitType(), sku.getLimitType()), "当前使用限制已发生变化,请重新下单。当前值:%s,最新值:%s", dto.getSkuLimitType(), sku.getLimitType());
+ ServiceUtil.assertion(!Objects.equals(dto.getSkuLimitCount(), sku.getLimitCount()), "当前限制次数已发生变化,请重新下单。当前值:%s,最新值:%s", dto.getSkuLimitCount(), sku.getLimitCount());
+ ServiceUtil.assertion(!Objects.equals(dto.getSkuLimitTotal(), sku.getLimitTotal()), "当前总限制次数已发生变化,请重新下单。当前值:%s,最新值:%s", dto.getSkuLimitTotal(), sku.getLimitTotal());
ServiceUtil.assertion(sku.getPrice() == null, "价格不允许为空,请重新下单");
- ServiceUtil.assertion(!MathUtils.equals(dto.getSkuPrice(), sku.getPrice()), "当前价格已发生变化,请重新下单");
- ServiceUtil.assertion(!Objects.equals(dto.getSkuTime(), sku.getTime()), "当前可购买的时长已发生变化,请重新下单");
- ServiceUtil.assertion(!MathUtils.equals(dto.getLevelDiscount(), level.getDiscount()), "当前折扣已发生变化,请重新下单");
- ServiceUtil.assertion(!Objects.equals(dto.getLevelStoreId(), level.getStoreId()), "当前可用店铺已发生变化,请重新下单");
+ ServiceUtil.assertion(!MathUtils.equals(dto.getSkuPrice(), sku.getPrice()), "当前价格已发生变化,请重新下单。当前值:%s,最新值:%s", dto.getSkuPrice(), sku.getPrice());
+ ServiceUtil.assertion(!Objects.equals(dto.getSkuTime(), sku.getTime()), "当前可购买的时长已发生变化,请重新下单。当前值:%s,最新值:%s", dto.getSkuTime(), sku.getTime());
+ ServiceUtil.assertion(!MathUtils.equals(dto.getLevelDiscount(), level.getDiscount()), "当前折扣已发生变化,请重新下单。当前值:%s,最新值:%s", dto.getLevelDiscount(), level.getDiscount());
+ ServiceUtil.assertion(!Objects.equals(dto.getLevelStoreId(), level.getStoreId()), "当前可用店铺已发生变化,请重新下单。当前值:%s,最新值:%s", dto.getLevelStoreId(), level.getStoreId());
// 商户是否存在
- ServiceUtil.assertion(mch == null, "商户不存在");
+ ServiceUtil.assertion(mch == null, "ID为%s的商户不存在", level.getMchId());
// 用户是否存在
- ServiceUtil.assertion(user == null, "下单用户不存在");
+ ServiceUtil.assertion(user == null, "当前下单用户不存在");
// 校验渠道是否可用
ServiceUtil.assertion(channel == null, "ID为%s的支付渠道不存在", dto.getChannelId());
@@ -89,4 +99,38 @@ public class VipOrderValidatorImpl implements VipOrderValidator {
return vip != null;
}
+
+ @Override
+ public boolean canView(VipOrderVO order, Long userId) {
+ if (order == null || userId == null) {
+ return false;
+ }
+ return isBonus(order, userId) || isUser(order, userId);
+ }
+
+ /**
+ * 判断用户是否是订单的分成方
+ */
+ private boolean isBonus(VipOrderVO order, Long userId) {
+ if (order == null || userId == null) {
+ return false;
+ }
+
+ // 查询订单的分成方
+ List bonusList = bonusService.selectBonusByBstId(BonusBstType.VIP, order.getId());
+
+ // 判断用户是否分成方
+ return bonusList.stream()
+ .anyMatch(bonus ->
+ BonusArrivalType.userList().contains(bonus.getArrivalType())
+ && Objects.equals(bonus.getArrivalId(), userId)
+ );
+ }
+
+ /**
+ * 判断用户是否是订单的创建者
+ */
+ private boolean isUser(VipOrderVO order, Long userId) {
+ return userId != null && order != null && Objects.equals(order.getUserId(), userId);
+ }
}
diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppVipOrderController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppVipOrderController.java
index 5fdb885e..4d439661 100644
--- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppVipOrderController.java
+++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppVipOrderController.java
@@ -2,17 +2,19 @@ package com.ruoyi.web.controller.app;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.ss.vipLevel.domain.enums.VipLevelSolution;
+import com.ruoyi.ss.vipOrder.domain.VipOrderQuery;
+import com.ruoyi.ss.vipOrder.domain.VipOrderVO;
import com.ruoyi.ss.vipOrder.domain.bo.AddPayVipOrderBO;
import com.ruoyi.ss.vipOrder.domain.dto.AddPayVipOrderDTO;
import com.ruoyi.ss.vipOrder.service.VipOrderConverter;
import com.ruoyi.ss.vipOrder.service.VipOrderService;
+import com.ruoyi.ss.vipOrder.service.VipOrderValidator;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
/**
* @author wjh
@@ -28,12 +30,39 @@ public class AppVipOrderController extends BaseController {
@Autowired
private VipOrderConverter vipOrderConverter;
+ @Autowired
+ private VipOrderValidator vipOrderValidator;
+
@ApiOperation("下单并发起支付")
@PostMapping
- public AjaxResult addAndPay(@RequestBody AddPayVipOrderDTO dto) {
+ public AjaxResult addAndPay(@RequestBody @Validated AddPayVipOrderDTO dto) {
dto.setSolution(VipLevelSolution.SAME.getCode());
AddPayVipOrderBO bo = vipOrderConverter.toBO(dto);
return success(vipOrderService.addAndPay(bo));
}
+ @ApiOperation("刷新支付结果")
+ @PutMapping("/refreshPayResult")
+ public AjaxResult refreshPayResult(String orderNo) {
+ return toAjax(vipOrderService.refreshPayResult(orderNo));
+ }
+
+ @ApiOperation("查询本人订单列表")
+ @GetMapping("/list")
+ public TableDataInfo list(VipOrderQuery query) {
+ startPage();
+ query.setUserId(getUserId());
+ return getDataTable(vipOrderService.selectVipOrderList(query));
+ }
+
+ @ApiOperation("通过ID查询订单详情")
+ @GetMapping("/detail/{id}")
+ public AjaxResult detail(@PathVariable Long id) {
+ VipOrderVO order = vipOrderService.selectVipOrderById(id);
+ if (!vipOrderValidator.canView(order, getUserId())) {
+ return error("您没有权限查看该订单");
+ }
+ return success(order);
+ }
+
}
diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipController.java
index 151829e3..62e10da5 100644
--- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipController.java
+++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipController.java
@@ -3,6 +3,7 @@ package com.ruoyi.web.controller.ss;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.ValidGroup;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
@@ -10,9 +11,11 @@ import com.ruoyi.ss.vip.domain.Vip;
import com.ruoyi.ss.vip.domain.VipQuery;
import com.ruoyi.ss.vip.domain.VipVO;
import com.ruoyi.ss.vip.service.VipAssembler;
+import com.ruoyi.ss.vip.service.VipConverter;
import com.ruoyi.ss.vip.service.VipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
@@ -32,6 +35,9 @@ public class VipController extends BaseController
@Autowired
private VipService vipService;
+ @Autowired
+ private VipConverter vipConverter;
+
@Autowired
private VipAssembler vipAssembler;
@@ -79,8 +85,9 @@ public class VipController extends BaseController
@PreAuthorize("@ss.hasPermi('ss:vip:add')")
@Log(title = "会员", businessType = BusinessType.INSERT)
@PostMapping
- public AjaxResult add(@RequestBody Vip vip)
+ public AjaxResult add(@RequestBody @Validated(ValidGroup.Create.class) Vip vip)
{
+ vip = vipConverter.toPoByAdd(vip);
return toAjax(vipService.insertVip(vip));
}
@@ -91,7 +98,8 @@ public class VipController extends BaseController
@Log(title = "会员", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody Vip vip) {
- return toAjax(vipService.updateVip(vip));
+ return error("会员修改功能暂未开放");
+ // return toAjax(vipService.updateVip(vip));
}
/**
@@ -100,8 +108,8 @@ public class VipController extends BaseController
@PreAuthorize("@ss.hasPermi('ss:vip:remove')")
@Log(title = "会员", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
- public AjaxResult remove(@PathVariable Long[] ids)
+ public AjaxResult remove(@PathVariable List ids)
{
- return toAjax(vipService.deleteVipByIds(ids));
+ return toAjax(vipService.logicDel(ids));
}
}
diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipOrderController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipOrderController.java
index 9b9c47d8..95d134a8 100644
--- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipOrderController.java
+++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/ss/VipOrderController.java
@@ -6,7 +6,6 @@ import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.ss.vipOrder.domain.VipOrder;
import com.ruoyi.ss.vipOrder.domain.VipOrderQuery;
import com.ruoyi.ss.vipOrder.domain.VipOrderVO;
import com.ruoyi.ss.vipOrder.service.VipOrderAssembler;
@@ -72,35 +71,14 @@ public class VipOrderController extends BaseController
}
/**
- * 新增会员订单
+ * 刷新支付结果
*/
- @PreAuthorize("@ss.hasPermi('ss:vipOrder:add')")
- @Log(title = "会员订单", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@RequestBody VipOrder vipOrder)
- {
- return toAjax(vipOrderService.insertVipOrder(vipOrder));
- }
-
- /**
- * 修改会员订单
- */
- @PreAuthorize("@ss.hasPermi('ss:vipOrder:edit')")
+ @PreAuthorize("@ss.hasPermi('ss:vipOrder:refreshPayResult')")
@Log(title = "会员订单", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@RequestBody VipOrder vipOrder)
- {
- return toAjax(vipOrderService.updateVipOrder(vipOrder));
+ @PutMapping("/refreshPayResult")
+ public AjaxResult refreshPayResult(Long id) {
+ return toAjax(vipOrderService.refreshPayResult(id));
}
- /**
- * 删除会员订单
- */
- @PreAuthorize("@ss.hasPermi('ss:vipOrder:remove')")
- @Log(title = "会员订单", businessType = BusinessType.DELETE)
- @DeleteMapping("/{ids}")
- public AjaxResult remove(@PathVariable Long[] ids)
- {
- return toAjax(vipOrderService.deleteVipOrderByIds(ids));
- }
+
}