From f249c277d066e151a84b766a6b82c3bbdbe1326b Mon Sep 17 00:00:00 2001
From: 陶杰 <1378534974@qq.com>
Date: 星期二, 03 九月 2024 13:24:01 +0800
Subject: [PATCH] 1.优惠券-所有修改方法dto自传id 2.优惠券-积分-批量接口改成post方法 3.优惠券-定时任务-会员优惠券每月一号凌晨未使用自动过期 4.优惠券-优惠券下单接口
---
src/main/java/com/mzl/flower/service/impl/coupon/CouponRecordServiceImpl.java | 94 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 91 insertions(+), 3 deletions(-)
diff --git a/src/main/java/com/mzl/flower/service/impl/coupon/CouponRecordServiceImpl.java b/src/main/java/com/mzl/flower/service/impl/coupon/CouponRecordServiceImpl.java
index 2de8630..18e029a 100644
--- a/src/main/java/com/mzl/flower/service/impl/coupon/CouponRecordServiceImpl.java
+++ b/src/main/java/com/mzl/flower/service/impl/coupon/CouponRecordServiceImpl.java
@@ -32,6 +32,7 @@
import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
@@ -248,6 +249,7 @@
public boolean grantVipCouponRecordList() {
try{
+
LocalDateTime now = LocalDateTime.now();
LocalDateTime firstDayStart = now.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0).withNano(0);
LocalDateTime lastDayEnd = now.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59).withNano(0);
@@ -271,11 +273,16 @@
couponRecordDO.setEffectiveStart(firstDayStart);
couponRecordDO.setEffectiveEnd(lastDayEnd);
couponRecordDO.setMemberId(couponTemplateDO.getMemberId());
-
// 创建信息
couponRecordDO.create();
- return couponRecordDO;
- }).collect(Collectors.toList());
+ if(!checkCurMonVipCouponExists(couponRecordDO.getCouponId(),couponRecordDO.getCustomerId(),firstDayStart,lastDayEnd)){
+ return couponRecordDO;
+ }else{
+ return null;
+ }
+
+ }).filter(Objects::nonNull)
+ .collect(Collectors.toList());
// 批量保存等级下的优惠券信息
saveBatch(gradeCouponRecordList);
@@ -395,4 +402,85 @@
// 将未使用的优惠券直接过期
couponRecordMapperCustom.checkCouponExpired(dto);
}
+
+ @Override
+ public boolean checkCurMonVipCouponExists(String couponId, Long customId, LocalDateTime startDateTime, LocalDateTime endDateTime) {
+
+ LocalDateTime now = LocalDateTime.now();
+ LocalDateTime firstDayStart = now.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0).withNano(0);
+ LocalDateTime lastDayEnd = now.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59).withNano(0);
+ if(null==startDateTime){
+ startDateTime=firstDayStart;
+ }
+ if(null==endDateTime){
+ endDateTime=lastDayEnd;
+ }
+
+ QueryWrapper<CouponRecordDO> queryWrapper=new QueryWrapper<>();
+ queryWrapper.lambda().eq(CouponRecordDO::getDeleted,TrueOrFalseEnum.FALSE.isFlag())
+ .eq(CouponRecordDO::getCouponId,couponId)
+ .eq(CouponRecordDO::getCustomerId,customId)
+ .eq(CouponRecordDO::getEffectiveStart,startDateTime)
+ .eq(CouponRecordDO::getEffectiveEnd,endDateTime);
+ return baseMapper.selectCount(queryWrapper)>0;
+
+ }
+
+ @Transactional
+ @Override
+ public boolean useCoupon(String couponId, String orderId) {
+ // 优惠券为空
+ if(StringUtils.isBlank(couponId)){
+ throw new IllegalArgumentException("无效的优惠券");
+ }
+ // 验证优惠券存在且有效
+ final CouponRecordDO couponRecordDO = baseMapper.selectById(couponId);
+ if(null==couponRecordDO || StringUtils.isBlank(couponRecordDO.getOrderId()) ){
+ throw new IllegalArgumentException("无效的优惠券");
+ }
+ if(couponRecordDO.getStatus().equals(CouponUsedStatusEnum.USED.getType())){
+ throw new IllegalArgumentException("优惠券已经被使用");
+ }
+ if(couponRecordDO.getStatus().equals(CouponUsedStatusEnum.EXPIRED.getType()) || LocalDateTime.now().isAfter(couponRecordDO.getEffectiveEnd())){
+ throw new IllegalArgumentException("优惠券已过期");
+ }
+ if(StringUtils.isBlank(orderId)){
+ throw new IllegalArgumentException("订单id不能为空");
+ }
+
+ // 优惠券使用操作
+ couponRecordDO.setStatus(CouponUsedStatusEnum.USED.getType());
+ couponRecordDO.setUsedTime(LocalDateTime.now());
+ couponRecordDO.setOrderId(orderId);
+
+ return baseMapper.updateById(couponRecordDO)>0;
+ }
+
+ @Transactional
+ @Override
+ public boolean cancelCouponUsage(String couponId, String orderId) {
+ // 查询订单使用的优惠券
+ final CouponRecordDO couponRecordDO = getCouponByOrderId(orderId);
+ // TODO
+
+ return false;
+ }
+
+ @Override
+ public List<CouponRecordDO> getCouponListByOrderId(String orderId) {
+ QueryWrapper<CouponRecordDO> queryWrapper=new QueryWrapper<>();
+ queryWrapper.lambda().eq(CouponRecordDO::getDeleted,TrueOrFalseEnum.FALSE.isFlag())
+ .eq(CouponRecordDO::getOrderId,orderId);
+
+ return baseMapper.selectList(queryWrapper);
+ }
+
+ @Override
+ public CouponRecordDO getCouponByOrderId(String orderId) {
+ final List<CouponRecordDO> couponRecordDOList = getCouponListByOrderId(orderId);
+ if(CollectionUtils.isNotEmpty(couponRecordDOList)){
+ return couponRecordDOList.get(0);
+ }
+ return null;
+ }
}
--
Gitblit v1.9.3