diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CouponDto.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CouponDto.java index a5165da..c231702 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CouponDto.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/CouponDto.java @@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.entity.dto; import lombok.Data; import javax.validation.constraints.NotNull; +import java.math.BigDecimal; @Data public class CouponDto { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopCouponServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopCouponServiceImpl.java index 4fa3354..efbbc9a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopCouponServiceImpl.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopCouponServiceImpl.java @@ -87,7 +87,7 @@ public class TbShopCouponServiceImpl implements TbShopCouponService { boolean isUse = true; TbShopCoupon tbShopCoupon = couponMapper.queryById(tbUserCouponVo.getCouponId()); StringBuilder useRestrictions = new StringBuilder("每天 "); - if (tbShopCoupon.getType().equals(1)) { + if (amount != null && tbShopCoupon.getType().equals(1)) { if (amount.compareTo(tbShopCoupon.getFullAmount()) < 0) { isUse = false; } @@ -125,39 +125,29 @@ public class TbShopCouponServiceImpl implements TbShopCouponService { if (param.getOrderId() != null) { TbShopUser tbShopUser = shopUserMapper.selectByUserIdAndShopId(param.getUserId().toString(), param.getShopId().toString()); - TbOrderInfo tbOrderInfo = orderInfoMapper.selectByPrimaryKey(param.getOrderId()); - List tbOrderDetails = orderDetailMapper.selectAllByOrderId(param.getOrderId()); - Set pros = tbOrderDetails.stream().map(TbOrderDetail::getProductId).collect(Collectors.toSet()); - if (CollectionUtil.isNotEmpty(tbOrderDetails)) { - List tbUserCouponVos = inRecordMapper.queryByVipIdAndShopId(Arrays.asList(Integer.valueOf(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(Arrays.asList(Integer.valueOf(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())) { - setCouponInfo(coupons, tbUserCouponVo, tbOrderInfo.getAmount(), week, now, formatter); - } - 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); - } - } + //券id 券使用描述 + Map coupons = new HashMap<>(); + for (TbUserCouponVo tbUserCouponVo : tbUserCouponVos) { + if (!coupons.containsKey(tbUserCouponVo.getCouponId())) { + setCouponInfo(coupons, tbUserCouponVo, null, week ,now, formatter); } - tbUserCouponVos.sort(Comparator.comparing(TbUserCouponVo::isUse).reversed().thenComparing(TbUserCouponVo::getExpireTime)); - return new Result(CodeEnum.SUCCESS, tbUserCouponVos); + 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 Result(CodeEnum.SUCCESS, tbUserCouponVos); } } else { List tbShopUser = shopUserMapper.selectAllByUserId(param.getUserId().toString()); - if(CollectionUtil.isNotEmpty(tbShopUser)){ + if (CollectionUtil.isNotEmpty(tbShopUser)) { List ids = tbShopUser.stream().map(TbShopUser::getId).map(Integer::valueOf).collect(Collectors.toList()); if (param.getStatus().equals(1)) { return new Result(CodeEnum.SUCCESS, inRecordMapper.queryByVipIdAndShopId(ids, param.getShopId())); @@ -189,7 +179,7 @@ public class TbShopCouponServiceImpl implements TbShopCouponService { TbShopShareRecord shareRecord = shareRecordMapper.queryById(inRecord.getSourceActId()); if (shareRecord.getMethod().equals("use")) { shareRecord.setStatus(3); - shareRecordService.give(shareRecord,shareRecord.getInvitedId()); + shareRecordService.give(shareRecord, shareRecord.getInvitedId()); shareRecordMapper.update(shareRecord); } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareRecordServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareRecordServiceImpl.java index d5d905b..7a19b97 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareRecordServiceImpl.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareRecordServiceImpl.java @@ -68,23 +68,23 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService { @Override public Map query(TbShopShareRecord tbShopShareRecord) { Map result = tbShopShareRecordMapper.statisticsRecord(tbShopShareRecord); - if(CollectionUtil.isEmpty(result)){ - result=new HashMap<>(); - result.put("isSuccess",0); - result.put("isFail",0); + if (CollectionUtil.isEmpty(result)) { + result = new HashMap<>(); + result.put("isSuccess", 0); + result.put("isFail", 0); } PageHelper.startPage(tbShopShareRecord.getPage(), tbShopShareRecord.getSize()); List records; - if(tbShopShareRecord.isSuccess()){ + if (tbShopShareRecord.isSuccess()) { records = tbShopShareRecordMapper.queryIsSuccess(tbShopShareRecord); - }else { + } else { records = tbShopShareRecordMapper.queryIsNoSuccess(tbShopShareRecord); } for (TbShopShareRecord shareRecord : records) { shareRecord.setBeInvitedName(userInfoMapper.selectNameByPrimaryKey(shareRecord.getBeInvitedId())); } - result.put("records",new PageInfo<>()); + result.put("records", new PageInfo<>()); return result; } @@ -129,7 +129,7 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService { tbShopShareRecord.setShopId(tbShopShareRecord.getShopId()); tbShopShareRecord.setCreateTime(new Date()); tbShopShareRecord.setUpdateTime(new Date()); - }else { + } else { query.setUpdateTime(new Date()); } if (shopUserInfo == null) { @@ -139,7 +139,7 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService { } saveShopUser(tbShopShareRecord.getBeInvitedId(), tbShopShareRecord.getShopId()); } else { - if (query == null){ + if (query == null) { tbShopShareRecord.setStatus(0); tbShopShareRecordMapper.insert(tbShopShareRecord); } @@ -150,6 +150,9 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService { for (TbShopShare.ShareCoupons newCoupon : tbShopShare.getNewCoupons()) { TbShopCoupon coupon = couponMapper.queryById(newCoupon.getCouponId()); if (coupon != null) { + if (coupon.getLeftNumber() <= 0) { + query.setStatus(0); + } if (coupon.getType() == 1) { //满减 newCoupon.setType(1); @@ -286,6 +289,8 @@ public class TbShopShareRecordServiceImpl implements TbShopShareRecordService { } } activateInRecordMapper.insertBatch(actGiveRecords); + tbShopCoupon.setLeftNumber(tbShopCoupon.getLeftNumber()-newCoupon.getCouponNum()); + couponMapper.update(tbShopCoupon); } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareServiceImpl.java index bf6bde3..61795d8 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareServiceImpl.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/TbShopShareServiceImpl.java @@ -40,6 +40,9 @@ public class TbShopShareServiceImpl implements TbShopShareService { for (TbShopShare.ShareCoupons newCoupon : tbShopShare.getNewCoupons()) { TbShopCoupon coupon = couponMapper.queryById(newCoupon.getCouponId()); if (coupon != null) { + if (coupon.getLeftNumber() <= 0) { + tbShopShare.setStatus(0); + } if (coupon.getType() == 1) { //满减 newCoupon.setType(1);