From aa45034a86358b11be0890223193a3320d4ec9ad Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 13 Nov 2024 15:48:55 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=A1=B5=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=88=B8=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/dto/CouponDto.java | 3 + .../service/impl/TbShopCouponServiceImpl.java | 80 ++++--------------- 2 files changed, 20 insertions(+), 63 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/CouponDto.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/CouponDto.java index 4fae54c4..9feaf698 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/CouponDto.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/CouponDto.java @@ -2,6 +2,8 @@ package cn.ysk.cashier.dto; import lombok.Data; +import java.math.BigDecimal; + @Data public class CouponDto { private Integer shopId; @@ -9,4 +11,5 @@ public class CouponDto { //-1已过期 1未使用 2已使用 private Integer status; private Integer orderId; + private BigDecimal amount; } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java index 4bcf236e..023a6d64 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java @@ -235,70 +235,24 @@ public class TbShopCouponServiceImpl extends ServiceImpl find(CouponDto param) { TbShopUser tbShopUser = shopUserRepository.selectByUserIdAndShopId(param.getUserId().toString(), param.getShopId().toString()); if (param.getOrderId() != null) { - TbOrderInfo tbOrderInfo = orderInfoRepository.findById(param.getOrderId()).orElse(null); - if (tbOrderInfo != null) { - List tbOrderDetails = orderDetailRepository.searchDetailByOrderId(param.getOrderId()); - Set pros = tbOrderDetails.stream().map(TbOrderDetail::getProductId).collect(Collectors.toSet()); - if (CollectionUtil.isNotEmpty(tbOrderDetails)) { - List tbUserCouponVos = inRecordMapper.queryByVipIdAndShopId(tbShopUser.getId(), param.getShopId()); - if (CollectionUtil.isNotEmpty(tbUserCouponVos)) { - String week = DateUtil.dayOfWeekEnum(new Date()).toChinese("周"); - LocalTime now = LocalTime.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); + List tbUserCouponVos = inRecordMapper.queryByVipIdAndShopId(tbShopUser.getId(), param.getShopId()); + if (CollectionUtil.isNotEmpty(tbUserCouponVos)) { + String week = DateUtil.dayOfWeekEnum(new Date()).toChinese("周"); + LocalTime now = LocalTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss"); - //券id 券使用描述 - Map coupons = new HashMap<>(); - for (TbUserCouponVo tbUserCouponVo : tbUserCouponVos) { - if (!coupons.containsKey(tbUserCouponVo.getCouponId())) { - JsonObject json = new JsonObject(); - boolean isUse = true; - TbShopCoupon tbShopCoupon = tbShopCouponmapper.selectById(tbUserCouponVo.getCouponId()); - StringBuilder useRestrictions = new StringBuilder("每天 "); - if (tbShopCoupon.getType().equals(1)) { - if (tbOrderInfo.getOrderAmount().compareTo(tbShopCoupon.getFullAmount()) < 0) { - isUse = false; - } - } - if (StringUtils.isNotBlank(tbShopCoupon.getUserDays())) { - String[] split = tbShopCoupon.getUserDays().split(","); - if (split.length != 7) { - useRestrictions = new StringBuilder(tbShopCoupon.getUserDays() + " "); - } - if (!tbShopCoupon.getUserDays().contains(week)) { - isUse = false; - } - } - if (tbShopCoupon.getUseTimeType().equals("custom")) { - if (now.isBefore(tbShopCoupon.getUseStartTime()) || now.isAfter(tbShopCoupon.getUseEndTime())) { - isUse = false; - } - useRestrictions.append( - tbShopCoupon.getUseStartTime().format(formatter) - + "-" - + tbShopCoupon.getUseEndTime().format(formatter)); - } else { - useRestrictions.append("全时段"); - } - useRestrictions.append(" 可用"); - json.addProperty("isUse", isUse); - json.addProperty("useRestrictions", useRestrictions.toString()); - - coupons.put(tbUserCouponVo.getCouponId(), json); - } - JsonObject couponJson = coupons.get(tbUserCouponVo.getCouponId()); - tbUserCouponVo.setUseRestrictions(couponJson.get("useRestrictions").toString()); - if (tbUserCouponVo.getType().equals(1)) { - tbUserCouponVo.setUse(couponJson.get("isUse").getAsBoolean()); - } else if (tbUserCouponVo.getType().equals(2) && couponJson.get("isUse").getAsBoolean()) { - if (!pros.contains(tbUserCouponVo.getProId())) { - tbUserCouponVo.setUse(false); - } - } - } - tbUserCouponVos.sort(Comparator.comparing(TbUserCouponVo::isUse).reversed().thenComparing(TbUserCouponVo::getExpireTime)); - return new ResponseEntity<>(tbUserCouponVos, HttpStatus.OK); + //券id 券使用描述 + Map coupons = new HashMap<>(); + for (TbUserCouponVo tbUserCouponVo : tbUserCouponVos) { + if (!coupons.containsKey(tbUserCouponVo.getCouponId())) { + setCouponInfo(coupons, tbUserCouponVo, null, week ,now, formatter); } + JsonObject couponJson = coupons.get(tbUserCouponVo.getCouponId()); + tbUserCouponVo.setUseRestrictions(couponJson.get("useRestrictions").toString()); + tbUserCouponVo.setUse(couponJson.get("isUse").getAsBoolean()); } + tbUserCouponVos.sort(Comparator.comparing(TbUserCouponVo::isUse).reversed().thenComparing(TbUserCouponVo::getExpireTime)); + return new ResponseEntity<>(tbUserCouponVos, HttpStatus.OK); } } return new ResponseEntity<>(HttpStatus.OK); @@ -321,7 +275,7 @@ public class TbShopCouponServiceImpl extends ServiceImpl(){{ + return new HashMap() {{ put("fullReductionCoupon", fullReductionCoupon); put("productCoupon", productCoupon); }}; From 41a86cf574a268546b00c34cc4566f6ce34cb199 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 13 Nov 2024 17:15:03 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E4=BC=98=E6=83=A0=E5=88=B8=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/mapper/TbActivateMapper.java | 17 +++++++++++++++++ .../service/impl/TbShopCouponServiceImpl.java | 13 +++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateMapper.java index c1b193b4..3b8366af 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateMapper.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateMapper.java @@ -1,7 +1,15 @@ package cn.ysk.cashier.mybatis.mapper; +import cn.ysk.cashier.dto.shop.TbShopUserQueryCriteria; import cn.ysk.cashier.mybatis.entity.TbActivate; +import cn.ysk.cashier.vo.ShopUserInfoVo; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; /** * @author Administrator @@ -11,6 +19,15 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; */ public interface TbActivateMapper extends BaseMapper { + + @Select("") + List queActByCouponId(@Param("couponId") Integer couponId); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java index 023a6d64..560fef57 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java @@ -10,10 +10,7 @@ import cn.ysk.cashier.dto.QueryReceiveDto; import cn.ysk.cashier.dto.TbShopCouponQueryCriteria; import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.mybatis.entity.*; -import cn.ysk.cashier.mybatis.mapper.TbActivateInRecordMapper; -import cn.ysk.cashier.mybatis.mapper.TbActivateOutRecordMapper; -import cn.ysk.cashier.mybatis.mapper.TbMShopUserMapper; -import cn.ysk.cashier.mybatis.mapper.TbShopCouponMapper; +import cn.ysk.cashier.mybatis.mapper.*; import cn.ysk.cashier.mybatis.service.*; import cn.ysk.cashier.mybatis.vo.TbShopCouponVo; import cn.ysk.cashier.pojo.order.TbCashierCart; @@ -59,6 +56,8 @@ public class TbShopCouponServiceImpl extends ServiceImpl tbActivates = activateMapper.queActByCouponId(id); + if(CollectionUtil.isNotEmpty(tbActivates)){ + throw new BadRequestException("该优惠券已关联活动,请解绑后删除"); + } + } tbShopCouponmapper.deleteBatchIds(Arrays.asList(ids)); for (Integer id : ids) { couProductService.remove(new LambdaQueryWrapper().eq(TbCouponProduct::getCouponId, id)); From 1d2ef2fdf518b17fadc516f88fae04d3fb6d698d Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Wed, 13 Nov 2024 18:23:42 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E5=A5=96=E5=8A=B1=E5=88=B8=E4=B8=8D?= =?UTF-8?q?=E5=8F=97=20=E4=BC=98=E6=83=A0=E5=88=B8=E5=8F=91=E6=94=BE?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E7=9A=84=E9=99=90=E5=88=B6=20=E4=B8=8D?= =?UTF-8?q?=E6=89=A3=E9=99=A4=E5=8F=91=E6=94=BE=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/TbShopShareRecordServiceImpl.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareRecordServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareRecordServiceImpl.java index c536e378..e79672d3 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareRecordServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareRecordServiceImpl.java @@ -54,14 +54,14 @@ public class TbShopShareRecordServiceImpl extends ServiceImpl coupons) { + public void giveCoupon(TbShopShare shopShare, TbShopUser tbShopUser, List coupons, boolean isReward) { for (TbShopShare.ShareCoupons newCoupon : coupons) { TbShopCoupon tbShopCoupon = couponMapper.selectById(newCoupon.getCouponId()); Date start = new Date(); @@ -91,7 +91,11 @@ public class TbShopShareRecordServiceImpl extends ServiceImpl Date: Thu, 14 Nov 2024 10:34:35 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=20=E7=BD=AE=E7=A9=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis/service/impl/TbActivateServiceImpl.java | 11 ++++++++++- .../service/impl/TbShopShareRecordServiceImpl.java | 8 +++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java index f7a25436..23583aff 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java @@ -6,6 +6,7 @@ import cn.ysk.cashier.mybatis.mapper.TbActivateMapper; import cn.ysk.cashier.mybatis.service.TbActivateService; import cn.ysk.cashier.mybatis.service.TbShopCouponService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -44,7 +45,15 @@ public class TbActivateServiceImpl extends ServiceImpl 0) { - activateMapper.updateById(activate); + UpdateWrapper updateWrapper = new UpdateWrapper<>(); + updateWrapper.eq("id", activate.getId()).setEntity(activate); + if (Objects.isNull(activate.getCouponId())) { + updateWrapper.set("couponId", null); + } + if (Objects.isNull(activate.getGiftPoints())) { + updateWrapper.set("giftPoints", null); + } + activateMapper.update(updateWrapper); } else { activateMapper.insert(activate); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareRecordServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareRecordServiceImpl.java index e79672d3..fbadec6a 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareRecordServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopShareRecordServiceImpl.java @@ -54,14 +54,14 @@ public class TbShopShareRecordServiceImpl extends ServiceImpl coupons, boolean isReward) { + public void giveCoupon(TbShopShare shopShare, TbShopUser tbShopUser, List coupons ,Integer flowId, boolean isReward) { for (TbShopShare.ShareCoupons newCoupon : coupons) { TbShopCoupon tbShopCoupon = couponMapper.selectById(newCoupon.getCouponId()); Date start = new Date(); @@ -89,6 +89,7 @@ public class TbShopShareRecordServiceImpl extends ServiceImpl Date: Thu, 14 Nov 2024 10:39:19 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=20=E7=BD=AE=E7=A9=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/mybatis/service/impl/TbActivateServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java index 23583aff..92d10c13 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java @@ -48,10 +48,10 @@ public class TbActivateServiceImpl extends ServiceImpl updateWrapper = new UpdateWrapper<>(); updateWrapper.eq("id", activate.getId()).setEntity(activate); if (Objects.isNull(activate.getCouponId())) { - updateWrapper.set("couponId", null); + updateWrapper.set("coupon_id", null); } if (Objects.isNull(activate.getGiftPoints())) { - updateWrapper.set("giftPoints", null); + updateWrapper.set("gift_points", null); } activateMapper.update(updateWrapper); } else { From e84d6557966d274a313c1cc19448fa9a708a4808 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 14 Nov 2024 10:43:12 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=20=E7=BD=AE=E7=A9=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java index 92d10c13..175c8810 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java @@ -46,7 +46,7 @@ public class TbActivateServiceImpl extends ServiceImpl 0) { UpdateWrapper updateWrapper = new UpdateWrapper<>(); - updateWrapper.eq("id", activate.getId()).setEntity(activate); + updateWrapper.setEntity(activate); if (Objects.isNull(activate.getCouponId())) { updateWrapper.set("coupon_id", null); } From 65c9667d9fbe07dde3bd5311c9cba9d72b30aac7 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 14 Nov 2024 10:59:17 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=20=E7=BD=AE=E7=A9=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/ysk/cashier/mybatis/entity/TbActivate.java | 3 +++ .../mybatis/service/impl/TbActivateServiceImpl.java | 10 +--------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbActivate.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbActivate.java index 4fdc0ef0..d3596a4c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbActivate.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbActivate.java @@ -1,6 +1,7 @@ package cn.ysk.cashier.mybatis.entity; import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.FieldStrategy; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.extension.activerecord.Model; @@ -17,10 +18,12 @@ public class TbActivate extends Model { //赠送金额 private Integer giftAmount; //赠送积分 + @TableField(updateStrategy = FieldStrategy.ALWAYS) private Integer giftPoints; //是否使用优惠卷 0否 1是 private Integer isUseCoupon; //优惠卷id + @TableField(updateStrategy = FieldStrategy.ALWAYS) private Integer couponId; @TableField(exist = false) private String couponName; diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java index 175c8810..af45a72c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java @@ -45,15 +45,7 @@ public class TbActivateServiceImpl extends ServiceImpl 0) { - UpdateWrapper updateWrapper = new UpdateWrapper<>(); - updateWrapper.setEntity(activate); - if (Objects.isNull(activate.getCouponId())) { - updateWrapper.set("coupon_id", null); - } - if (Objects.isNull(activate.getGiftPoints())) { - updateWrapper.set("gift_points", null); - } - activateMapper.update(updateWrapper); + activateMapper.updateById(activate); } else { activateMapper.insert(activate); } From 08351e626045780a07572e3440cf6c212ec1f9d6 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 14 Nov 2024 11:22:21 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=20=E7=BD=AE=E7=A9=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/TbActivateServiceImpl.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java index af45a72c..ab47c3e1 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateServiceImpl.java @@ -45,8 +45,22 @@ public class TbActivateServiceImpl extends ServiceImpl 0) { + if(activate.getIsUseCoupon()==0){ + activate.setCouponId(null); + } else if (activate.getIsUseCoupon()==1) { + if (activate.getCouponId() == null) { + throw new RuntimeException("优惠券不能为空"); + } + } activateMapper.updateById(activate); } else { + if(activate.getIsUseCoupon()==0){ + activate.setCouponId(null); + } else if (activate.getIsUseCoupon()==1) { + if (activate.getCouponId() == null) { + throw new RuntimeException("优惠券不能为空"); + } + } activateMapper.insert(activate); } } From 42775cae36ea5ac786b6539ab73a38d9db844057 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 14 Nov 2024 13:53:10 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E6=9C=AA=E4=BD=BF=E7=94=A8=E5=88=B8=20?= =?UTF-8?q?=E4=B8=8D=E5=8F=AF=E7=94=A8=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java | 5 +++++ .../mybatis/service/impl/TbShopCouponServiceImpl.java | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java index 676a0c34..ece33c8c 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java @@ -44,6 +44,11 @@ public interface TbActivateInRecordMapper extends BaseMapper " order by inRecord.use_end_time asc") List queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId); + @Select("SELECT sum( over_num ) from tb_activate_in_record" + + " where coupon_id = #{couponId} and now() < use_end_time group by coupon_id ") + int countNoUseCoupon(@Param("couponId") Integer couponId); + + @Update("update tb_activate_in_record" + " set over_num = #{overNum}" + " where id = #{id}") diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java index 560fef57..b2a80ac0 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java @@ -160,6 +160,10 @@ public class TbShopCouponServiceImpl extends ServiceImpl 0) { + throw new BadRequestException("该优惠券有发放后未使用,无法删除"); + } } tbShopCouponmapper.deleteBatchIds(Arrays.asList(ids)); for (Integer id : ids) { From aba8d9b52466a21bf6c0d0fe5661c61a7957b51e Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 14 Nov 2024 14:15:09 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E6=9C=AA=E4=BD=BF=E7=94=A8=E5=88=B8=20?= =?UTF-8?q?=E4=B8=8D=E5=8F=AF=E7=94=A8=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java index ece33c8c..2b47b89b 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java @@ -45,7 +45,8 @@ public interface TbActivateInRecordMapper extends BaseMapper List queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId); @Select("SELECT sum( over_num ) from tb_activate_in_record" + - " where coupon_id = #{couponId} and now() < use_end_time group by coupon_id ") + " where coupon_id = #{couponId} " + + " and now() < use_end_time group by coupon_id ") int countNoUseCoupon(@Param("couponId") Integer couponId); From 2e4ef9a0a53768c2e23685ed44f77c282b3aeedd Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 14 Nov 2024 14:18:00 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E6=9C=AA=E4=BD=BF=E7=94=A8=E5=88=B8=20?= =?UTF-8?q?=E4=B8=8D=E5=8F=AF=E7=94=A8=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cashier/mybatis/mapper/TbActivateInRecordMapper.java | 2 +- .../mybatis/service/impl/TbShopCouponServiceImpl.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java index 2b47b89b..ddcc059d 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateInRecordMapper.java @@ -47,7 +47,7 @@ public interface TbActivateInRecordMapper extends BaseMapper @Select("SELECT sum( over_num ) from tb_activate_in_record" + " where coupon_id = #{couponId} " + " and now() < use_end_time group by coupon_id ") - int countNoUseCoupon(@Param("couponId") Integer couponId); + Integer countNoUseCoupon(@Param("couponId") Integer couponId); @Update("update tb_activate_in_record" + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java index b2a80ac0..3554e500 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbShopCouponServiceImpl.java @@ -157,11 +157,11 @@ public class TbShopCouponServiceImpl extends ServiceImpl tbActivates = activateMapper.queActByCouponId(id); - if(CollectionUtil.isNotEmpty(tbActivates)){ + if (CollectionUtil.isNotEmpty(tbActivates)) { throw new BadRequestException("该优惠券已关联活动,请解绑后删除"); } - int i = inRecordMapper.countNoUseCoupon(id); - if (i > 0) { + Integer i = inRecordMapper.countNoUseCoupon(id); + if (i != null && i > 0) { throw new BadRequestException("该优惠券有发放后未使用,无法删除"); } } @@ -254,7 +254,7 @@ public class TbShopCouponServiceImpl extends ServiceImpl coupons = new HashMap<>(); for (TbUserCouponVo tbUserCouponVo : tbUserCouponVos) { if (!coupons.containsKey(tbUserCouponVo.getCouponId())) { - setCouponInfo(coupons, tbUserCouponVo, null, week ,now, formatter); + setCouponInfo(coupons, tbUserCouponVo, null, week, now, formatter); } JsonObject couponJson = coupons.get(tbUserCouponVo.getCouponId()); tbUserCouponVo.setUseRestrictions(couponJson.get("useRestrictions").toString());