满减活动校验 以及 创建时 时间段初始化
This commit is contained in:
parent
2deac81268
commit
d87e84c5bb
|
|
@ -51,7 +51,6 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ShopUser getShopUserInfo(Long shopId, long userId) {
|
||||
Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
|
||||
|
|
@ -117,6 +116,11 @@ public class ShopUserServiceImpl extends ServiceImpl<ShopUserMapper, ShopUser> i
|
|||
shopUser.setConsumeCount(userInfo.getConsumeCount() + 1);
|
||||
shopUser.setConsumeAmount(userInfo.getConsumeAmount().add(shopUserEditDTO.getMoney()));
|
||||
updateById(shopUser);
|
||||
} else if (shopUserEditDTO.getType() == 1 && shopUserEditDTO.getBizEnum().getCode().contains("In")) {
|
||||
ShopUser shopUser = new ShopUser();
|
||||
shopUser.setId(userInfo.getId());
|
||||
shopUser.setRechargeCount(userInfo.getRechargeCount() + 1);
|
||||
updateById(shopUser);
|
||||
}
|
||||
return userFlow.getId();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
|
|||
import com.czg.TimeQueryParam;
|
||||
import com.czg.account.entity.ShopInfo;
|
||||
import com.czg.account.service.ShopInfoService;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.market.dto.MkDiscountActivityDTO;
|
||||
import com.czg.market.entity.MkDiscountActivity;
|
||||
import com.czg.market.entity.MkDiscountThreshold;
|
||||
|
|
@ -21,7 +22,11 @@ import jakarta.annotation.Resource;
|
|||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
|
||||
/**
|
||||
* 商家满减活动表 服务层实现。
|
||||
|
|
@ -62,11 +67,17 @@ public class MkDiscountActivityServiceImpl extends ServiceImpl<MkDiscountActivit
|
|||
MkDiscountActivityDTO activityDTO = getActivityByShopId(shopId);
|
||||
AssertUtil.isNull(activityDTO, "店铺未配置满减活动");
|
||||
//检查是否开启了优惠券抵扣
|
||||
AssertUtil.isNotEqual(activityDTO.getCouponShare() == 1, couponShare, "满减活动与优惠券不可共用");
|
||||
if (couponShare && activityDTO.getCouponShare() == 0) {
|
||||
throw new CzgException("满减活动与优惠券不可共用");
|
||||
}
|
||||
//检查是否开启了会员抵扣
|
||||
AssertUtil.isNotEqual(activityDTO.getVipPriceShare() == 1, vipShare, "满减活动与会员价不可共用");
|
||||
if (vipShare && activityDTO.getVipPriceShare() == 0) {
|
||||
throw new CzgException("满减活动与会员价不可共用");
|
||||
}
|
||||
//检查是否开启了积分抵扣
|
||||
AssertUtil.isNotEqual(activityDTO.getPointsShare() == 1, pointsShare, "满减活动与积分抵扣不可共用");
|
||||
if (pointsShare && activityDTO.getPointsShare() == 0) {
|
||||
throw new CzgException("满减活动与积分抵扣不可共用");
|
||||
}
|
||||
return activityDTO;
|
||||
}
|
||||
|
||||
|
|
@ -95,6 +106,7 @@ public class MkDiscountActivityServiceImpl extends ServiceImpl<MkDiscountActivit
|
|||
if (CollUtil.isEmpty(param.getThresholds())) {
|
||||
throw new IllegalArgumentException("活动必须配置满减阈值");
|
||||
}
|
||||
validateAndInitStatus(param);
|
||||
MkDiscountActivity activity = BeanUtil.toBean(param, MkDiscountActivity.class);
|
||||
save(activity);
|
||||
for (MkDiscountThreshold threshold : param.getThresholds()) {
|
||||
|
|
@ -108,6 +120,7 @@ public class MkDiscountActivityServiceImpl extends ServiceImpl<MkDiscountActivit
|
|||
if (CollUtil.isEmpty(param.getThresholds())) {
|
||||
throw new IllegalArgumentException("活动必须配置满减阈值");
|
||||
}
|
||||
validateAndInitStatus(param);
|
||||
MkDiscountActivity activity = BeanUtil.toBean(param, MkDiscountActivity.class);
|
||||
updateById(activity, true);
|
||||
thresholdMapper.deleteByQuery(
|
||||
|
|
@ -123,4 +136,38 @@ public class MkDiscountActivityServiceImpl extends ServiceImpl<MkDiscountActivit
|
|||
public void deleteActivity(Long id) {
|
||||
updateById(new MkDiscountActivity().setIsDel(true).setUpdateTime(LocalDateTime.now()).setId(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验时间有效性并初始化状态
|
||||
*/
|
||||
private void validateAndInitStatus(MkDiscountActivityDTO param) {
|
||||
LocalDate startDate;
|
||||
LocalDate endDate;
|
||||
LocalDate currentDate = LocalDate.now();
|
||||
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
startDate = LocalDate.parse(param.getValidStartTime(), formatter);
|
||||
endDate = LocalDate.parse(param.getValidEndTime(), formatter);
|
||||
} catch (DateTimeParseException e) {
|
||||
throw new IllegalArgumentException("时间格式不正确,请使用yyyy-MM-dd格式");
|
||||
}
|
||||
|
||||
// 校验开始时间不能晚于结束时间
|
||||
if (startDate.isAfter(endDate)) {
|
||||
throw new IllegalArgumentException("有效期开始时间不能晚于结束时间");
|
||||
}
|
||||
|
||||
// 根据时间初始化状态
|
||||
if (currentDate.isBefore(startDate)) {
|
||||
// 当前日期在开始日期之前-未开始
|
||||
param.setStatus(1);
|
||||
} else if (currentDate.isAfter(endDate)) {
|
||||
// 当前日期在结束日期之后-已结束
|
||||
param.setStatus(3);
|
||||
} else {
|
||||
// 这里先默认设置为进行中,具体由定时任务根据时段更新
|
||||
param.setStatus(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -338,7 +338,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||
if (param.getDiscountActAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||
//检查满减活动是否开启
|
||||
discountAct = discountActService.checkDiscountAct(orderInfo.getShopId(),
|
||||
CollUtil.isNotEmpty(param.getCouponList()), param.isVipPrice(), param.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0);
|
||||
CollUtil.isNotEmpty(param.getCouponList()), param.isVipPrice(),
|
||||
param.getPointsDiscountAmount().compareTo(BigDecimal.ZERO) > 0);
|
||||
}
|
||||
orderInfo.setSeatNum(param.getSeatNum());
|
||||
if (shopInfo.getIsTableFee() != 1 && shopInfo.getTableFee().compareTo(BigDecimal.ZERO) != 0) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue