修改 10086 为常量

This commit is contained in:
gong
2025-12-11 18:36:35 +08:00
parent e4ea8de704
commit 1ed69dd986
6 changed files with 42 additions and 34 deletions

View File

@@ -3,6 +3,7 @@ package com.czg.service.market.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopUserService;
import com.czg.constant.MarketConstants;
import com.czg.exception.CzgException;
import com.czg.market.dto.ChatCouponDTO;
import com.czg.market.dto.MkShopCouponGiftDTO;
@@ -59,8 +60,8 @@ public class ChatCouponServiceImpl extends ServiceImpl<ChatCouponMapper, ChatCou
.shopId(shopId)
.title(chatCoupon.getTitle())
.getLimit(chatCoupon.getGetLimit() == null ? 1 : chatCoupon.getGetLimit())
.giveNum(chatCoupon.getGiveNum() == null ? -10086 : chatCoupon.getGiveNum())
.leftNum(chatCoupon.getGiveNum() == null ? -10086 : chatCoupon.getGiveNum())
.giveNum(chatCoupon.getGiveNum() == null ? MarketConstants.Num.NOT_LIMIT : chatCoupon.getGiveNum())
.leftNum(chatCoupon.getGiveNum() == null ? MarketConstants.Num.NOT_LIMIT : chatCoupon.getGiveNum())
.useNum(0)
.couponId(chatCoupon.getCouponId())
.build();

View File

@@ -2,7 +2,7 @@ package com.czg.service.market.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.exceptions.ValidateException;
import com.czg.constant.MarketConstants;
import com.czg.exception.CzgException;
import com.czg.market.dto.MkCouponGiftDTO;
import com.czg.market.dto.MkShopConsumerCouponDTO;
@@ -68,7 +68,7 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
return;
}
//判断是否已被领取
if (consumerCoupon.getGiveNum() != -10086 && consumerCoupon.getGiveNum() <= consumerCoupon.getGiftNum()) {
if (consumerCoupon.getGiveNum() != MarketConstants.Num.NOT_LIMIT && consumerCoupon.getGiveNum() <= consumerCoupon.getGiftNum()) {
return;
}
List<MkCouponGiftDTO> giftCoupons = couponGiftService.getCouponGiftBySourceId(consumerCoupon.getId(), 3);
@@ -76,10 +76,10 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
return;
}
MkCouponGiftDTO giftCoupon = giftCoupons.getFirst();
if (consumerCoupon.getLeftNum() == -10086 || consumerCoupon.getLeftNum() >= giftCoupon.getNum()) {
boolean canReceive = consumerCoupon.getGetLimit() == -10086;
if (consumerCoupon.getLeftNum() == MarketConstants.Num.NOT_LIMIT || consumerCoupon.getLeftNum() >= giftCoupon.getNum()) {
boolean canReceive = consumerCoupon.getGetLimit() == MarketConstants.Num.NOT_LIMIT;
// 限量发放,校验用户已经发放数量
if (consumerCoupon.getGetLimit() != -10086) {
if (consumerCoupon.getGetLimit() != MarketConstants.Num.NOT_LIMIT) {
long count = recordService.count(new QueryWrapper().eq(MkShopCouponRecord::getShopId, shopId)
.eq(MkShopCouponRecord::getShopUserId, shopUserId)
.eq(MkShopCouponRecord::getSourceId, consumerCoupon.getId()));
@@ -99,7 +99,7 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
recordService.receiveCoupon(giftDTO, giftCoupon.getNum(), false);
//更新优惠券信息
consumerCoupon.setGiftNum(consumerCoupon.getGiftNum() + giftCoupon.getNum());
if (consumerCoupon.getLeftNum() != -10086) {
if (consumerCoupon.getLeftNum() != MarketConstants.Num.NOT_LIMIT) {
consumerCoupon.setLeftNum(consumerCoupon.getLeftNum() - giftCoupon.getNum());
}
updateById(new MkShopConsumerCoupon()
@@ -135,25 +135,13 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
@Transactional
public void updateConsumerCouponById(MkShopConsumerCouponDTO param) {
MkShopConsumerCoupon consumerCoupon = getById(param.getId());
if (consumerCoupon.getGiveNum() == -10086) {
if (param.getGiveNum() == -10086) {
param.setLeftNum(-10086);
} else {
if (param.getGiveNum() < consumerCoupon.getGiftNum()) {
throw new CzgException("修改失败 总发放数量必须大于已发放数量");
} else {
param.setLeftNum(param.getGiveNum() - consumerCoupon.getGiftNum());
}
}
if (param.getGiveNum() == MarketConstants.Num.NOT_LIMIT) {
param.setLeftNum(MarketConstants.Num.NOT_LIMIT);
} else {
if (param.getGiveNum() == -10086) {
param.setLeftNum(-10086);
if (param.getGiveNum() < consumerCoupon.getGiftNum()) {
throw new CzgException("修改失败 总发放数量必须大于已发放数量");
} else {
if (param.getGiveNum() < consumerCoupon.getGiftNum()) {
throw new CzgException("修改失败 总发放数量必须大于已发放数量");
} else {
param.setLeftNum(param.getGiveNum() - consumerCoupon.getGiftNum());
}
param.setLeftNum(param.getGiveNum() - consumerCoupon.getGiftNum());
}
}
updateById(BeanUtil.toBean(param, MkShopConsumerCoupon.class), true);

View File

@@ -16,6 +16,7 @@ import com.czg.account.service.ShopUserService;
import com.czg.account.service.UserInfoService;
import com.czg.account.vo.CouponReceiveVo;
import com.czg.account.vo.UserCouponVo;
import com.czg.constant.MarketConstants;
import com.czg.exception.CzgException;
import com.czg.market.dto.*;
import com.czg.market.entity.MkShopCouponRecord;
@@ -340,7 +341,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
}
}
coupon.setGiftNum(coupon.getGiftNum() + number);
if (coupon.getGiveNum() != -10086 && isLimit) {
if (coupon.getGiveNum() != MarketConstants.Num.NOT_LIMIT && isLimit) {
coupon.setLeftNum(coupon.getLeftNum() - number);
}
String couponJson = JSONObject.toJSONString(coupon);

View File

@@ -13,6 +13,7 @@ import com.czg.account.service.ShopInfoService;
import com.czg.account.service.ShopUserService;
import com.czg.account.vo.ShopInfoCouponVO;
import com.czg.account.vo.UserCouponVo;
import com.czg.constant.MarketConstants;
import com.czg.exception.CzgException;
import com.czg.market.dto.MkShopCouponGiftDTO;
import com.czg.market.dto.ShopCouponDTO;
@@ -124,7 +125,7 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
if ("custom".equals(coupon.getValidType()) && coupon.getValidEndTime() != null && coupon.getValidEndTime().isBefore(LocalDateTime.now())) {
continue;
}
if (coupon.getGiveNum() != -10086 && coupon.getLeftNum() <= 0) {
if (coupon.getGiveNum() != MarketConstants.Num.NOT_LIMIT && coupon.getLeftNum() <= 0) {
continue;
}
boolean isNotNewUser = true;
@@ -144,7 +145,7 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
continue;
}
}
if (isNotNewUser && coupon.getGetLimit() != -10086) {
if (isNotNewUser && coupon.getGetLimit() != MarketConstants.Num.NOT_LIMIT) {
if (coupon.getSyncId() != null) {
long count = recordService.count(new QueryWrapper()
.eq(MkShopCouponRecord::getUserId, userId)
@@ -211,8 +212,8 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
@Override
public void updateCouponById(ShopCouponDTO param) {
ShopCoupon tbShopCoupon = getById(param.getId());
if (tbShopCoupon.getGiveNum() == -10086) {
if (param.getGiveNum() != -10086) {
if (tbShopCoupon.getGiveNum() == MarketConstants.Num.NOT_LIMIT) {
if (param.getGiveNum() != MarketConstants.Num.NOT_LIMIT) {
if (param.getGiveNum() < tbShopCoupon.getGiftNum()) {
throw new CzgException("修改失败 总发放数量必须大于已发放数量");
} else {
@@ -220,8 +221,8 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
}
}
} else {
if (param.getGiveNum() == -10086) {
param.setLeftNum(-10086);
if (param.getGiveNum() == MarketConstants.Num.NOT_LIMIT) {
param.setLeftNum(MarketConstants.Num.NOT_LIMIT);
} else {
if (param.getGiveNum() < tbShopCoupon.getGiftNum()) {
throw new CzgException("修改失败 总发放数量必须大于已发放数量");
@@ -564,7 +565,7 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
useRestrictions.append("全时段");
}
useRestrictions.append(" 可用");
if (tbUserCouponVo.getUseLimit() != -10086) {
if (tbUserCouponVo.getUseLimit() != MarketConstants.Num.NOT_LIMIT) {
long useCount = recordService.count(new QueryWrapper()
.eq(MkShopCouponRecord::getCouponId, tbUserCouponVo.getCouponId())
.eq(MkShopCouponRecord::getShopUserId, shopUserId)