diff --git a/consumer/src/main/java/cn/lili/timetask/handler/impl/order/RechargeOrderTaskExecute.java b/consumer/src/main/java/cn/lili/timetask/handler/impl/order/RechargeOrderTaskExecute.java new file mode 100644 index 00000000..b64f740c --- /dev/null +++ b/consumer/src/main/java/cn/lili/timetask/handler/impl/order/RechargeOrderTaskExecute.java @@ -0,0 +1,61 @@ +package cn.lili.timetask.handler.impl.order; + +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import cn.hutool.json.JSONUtil; +import cn.lili.modules.order.order.entity.enums.PayStatusEnum; +import cn.lili.modules.order.trade.entity.dos.Recharge; +import cn.lili.modules.order.trade.service.RechargeService; +import cn.lili.modules.system.entity.dos.Setting; +import cn.lili.modules.system.entity.dto.OrderSetting; +import cn.lili.modules.system.entity.enums.SettingEnum; +import cn.lili.modules.system.service.SettingService; +import cn.lili.timetask.handler.EveryMinuteExecute; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 充值订单自动取消(每分钟执行) + * + * @author zhuhai + * @since 2021/3/11 + **/ +@Slf4j +@Component +public class RechargeOrderTaskExecute implements EveryMinuteExecute { + /** + * 充值 + */ + @Autowired + private RechargeService rechargeService; + /** + * 设置 + */ + @Autowired + private SettingService settingService; + + + @Override + public void execute() { + Setting setting = settingService.get(SettingEnum.ORDER_SETTING.name()); + OrderSetting orderSetting = JSONUtil.toBean(setting.getSettingValue(), OrderSetting.class); + if (orderSetting != null && orderSetting.getAutoCancel() != null) { + //充值订单自动取消时间 = 当前时间 - 自动取消时间分钟数 + DateTime cancelTime = DateUtil.offsetMinute(DateUtil.date(), -orderSetting.getAutoCancel()); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(Recharge::getPayStatus, PayStatusEnum.UNPAID.name()); + //充值订单创建时间 <= 订单自动取消时间 + queryWrapper.le(Recharge::getCreateTime, cancelTime); + List list = rechargeService.list(queryWrapper); + List cancelSnList = list.stream().map(Recharge::getRechargeSn).collect(Collectors.toList()); + for (String sn : cancelSnList) { + rechargeService.rechargeOrderCancel(sn); + } + } + } +} diff --git a/framework/src/main/java/cn/lili/common/enums/ResultCode.java b/framework/src/main/java/cn/lili/common/enums/ResultCode.java index b77b1230..5b364610 100644 --- a/framework/src/main/java/cn/lili/common/enums/ResultCode.java +++ b/framework/src/main/java/cn/lili/common/enums/ResultCode.java @@ -234,17 +234,18 @@ public enum ResultCode { /** * 活动 */ - PROMOTION_GOODS_NOT_EXIT(40001, "当前促销商品不存在!"), - PROMOTION_SAME_ACTIVE_EXIST(40002,"当前时间内已存在同类活动"), - PROMOTION_START_TIME_ERROR(40003,"活动起始时间不能大于活动结束时间"), - PROMOTION_TIME_ERROR(40004,"活动起始时间必须大于当前时间"), - PROMOTION_SAME_ERROR(40005,"当前时间段已存在相同活动!"), - PROMOTION_GOODS_ERROR(40006,"请选择要参与活动的商品"), - PROMOTION_STATUS_END(40007,"当前活动已停止"), - PROMOTION_UPDATE_ERROR(40008,"当前活动已开始/结束,无法编辑!"), - PROMOTION_ACTIVITY_GOODS_ERROR(40009,"当前活动已经开始无法添加商品"), - PROMOTION_ACTIVITY_ERROR(40009,"当前促销活动不存在"), - PROMOTION_LOG_EXIST(40010,"活动已参加,已发重复参加"), + PROMOTION_GOODS_NOT_EXIT(40000, "当前促销商品不存在!"), + PROMOTION_SAME_ACTIVE_EXIST(40001, "当前时间内已存在同类活动"), + PROMOTION_START_TIME_ERROR(40002, "活动起始时间不能小于当前时间"), + PROMOTION_END_TIME_ERROR(40003, "活动结束时间不能小于当前时间"), + PROMOTION_TIME_ERROR(40004, "活动起始时间必须大于结束时间"), + PROMOTION_SAME_ERROR(40005, "当前时间段已存在相同活动!"), + PROMOTION_GOODS_ERROR(40006, "请选择要参与活动的商品"), + PROMOTION_STATUS_END(40007, "当前活动已停止"), + PROMOTION_UPDATE_ERROR(40008, "当前活动已开始/结束,无法编辑!"), + PROMOTION_ACTIVITY_GOODS_ERROR(40009, "当前活动已经开始无法添加商品"), + PROMOTION_ACTIVITY_ERROR(400010, "当前促销活动不存在"), + PROMOTION_LOG_EXIST(40011, "活动已参加,已发重复参加"), /** * 优惠券 diff --git a/framework/src/main/java/cn/lili/modules/order/order/entity/enums/PayStatusEnum.java b/framework/src/main/java/cn/lili/modules/order/order/entity/enums/PayStatusEnum.java index 33188e2c..b32b1a89 100644 --- a/framework/src/main/java/cn/lili/modules/order/order/entity/enums/PayStatusEnum.java +++ b/framework/src/main/java/cn/lili/modules/order/order/entity/enums/PayStatusEnum.java @@ -11,8 +11,9 @@ public enum PayStatusEnum { /** * 支付状态 */ - UNPAID("未付款"), - PAID("已付款"); + UNPAID("待付款"), + PAID("已付款"), + CANCEL("已取消"); private final String description; diff --git a/framework/src/main/java/cn/lili/modules/order/trade/service/RechargeService.java b/framework/src/main/java/cn/lili/modules/order/trade/service/RechargeService.java index 3c3cd946..e7034250 100644 --- a/framework/src/main/java/cn/lili/modules/order/trade/service/RechargeService.java +++ b/framework/src/main/java/cn/lili/modules/order/trade/service/RechargeService.java @@ -35,11 +35,11 @@ public interface RechargeService extends IService { /** * 支付成功 * - * @param sn 充值订单编号 - * @param receivableNo 流水no + * @param sn 充值订单编号 + * @param receivableNo 流水no * @param paymentMethod 支付方式 */ - void paySuccess(String sn, String receivableNo,String paymentMethod); + void paySuccess(String sn, String receivableNo, String paymentMethod); /** * 根据充值订单号查询充值信息 @@ -49,4 +49,11 @@ public interface RechargeService extends IService { */ Recharge getRecharge(String sn); + /** + * 充值订单取消 + * + * @param sn 充值订单sn + */ + void rechargeOrderCancel(String sn); + } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/order/trade/serviceimpl/RechargeServiceImpl.java b/framework/src/main/java/cn/lili/modules/order/trade/serviceimpl/RechargeServiceImpl.java index e1baf0dc..0c905c44 100644 --- a/framework/src/main/java/cn/lili/modules/order/trade/serviceimpl/RechargeServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/order/trade/serviceimpl/RechargeServiceImpl.java @@ -77,7 +77,7 @@ public class RechargeServiceImpl extends ServiceImpl i } @Override - public void paySuccess(String sn, String receivableNo,String paymentMethod) { + public void paySuccess(String sn, String receivableNo, String paymentMethod) { //根据sn获取支付账单 Recharge recharge = this.getOne(new QueryWrapper().eq("recharge_sn", sn)); //如果支付账单不为空则进行一下逻辑 @@ -103,4 +103,13 @@ public class RechargeServiceImpl extends ServiceImpl i throw new ServiceException(ResultCode.ORDER_NOT_EXIST); } + + @Override + public void rechargeOrderCancel(String sn) { + Recharge recharge = this.getOne(new QueryWrapper().eq("recharge_sn", sn)); + if (recharge != null) { + recharge.setPayStatus(PayStatusEnum.CANCEL.name()); + this.updateById(recharge); + } + } } \ No newline at end of file diff --git a/framework/src/main/java/cn/lili/modules/promotion/entity/dto/BasePromotion.java b/framework/src/main/java/cn/lili/modules/promotion/entity/dto/BasePromotion.java index 255b340b..01ac39f8 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/entity/dto/BasePromotion.java +++ b/framework/src/main/java/cn/lili/modules/promotion/entity/dto/BasePromotion.java @@ -1,15 +1,13 @@ package cn.lili.modules.promotion.entity.dto; -import cn.lili.mybatis.BaseEntity; import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum; +import cn.lili.mybatis.BaseEntity; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.persistence.MappedSuperclass; -import javax.validation.constraints.Min; import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; import java.util.Date; /** @@ -34,12 +32,10 @@ public class BasePromotion extends BaseEntity { @ApiModelProperty(value = "活动名称", required = true) private String promotionName; - @Min(message = "活动开始时间不能为空", value = 0) @ApiModelProperty(value = "活动开始时间", required = true) @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") private Date startTime; - @Min(message = "活动结束时间不能为空", value = 0) @ApiModelProperty(value = "活动结束时间", required = true) @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") private Date endTime; @@ -48,6 +44,5 @@ public class BasePromotion extends BaseEntity { * @see PromotionStatusEnum */ @ApiModelProperty(value = "活动状态") - @NotNull(message = "活动状态不能为空") private String promotionStatus; } diff --git a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java index e12c770f..cbed7771 100644 --- a/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/promotion/serviceimpl/CouponServiceImpl.java @@ -297,6 +297,7 @@ public class CouponServiceImpl extends ServiceImpl impleme */ private void checkParam(CouponVO coupon) { + //优惠券限制领取数量 if (coupon.getCouponLimitNum() < 0) { throw new ServiceException(ResultCode.COUPON_LIMIT_NUM_LESS_THAN_0); } @@ -304,18 +305,21 @@ public class CouponServiceImpl extends ServiceImpl impleme if (coupon.getPublishNum() != 0 && coupon.getCouponLimitNum() > coupon.getPublishNum()) { throw new ServiceException(ResultCode.COUPON_LIMIT_GREATER_THAN_PUBLISH); } + //打折优惠券大于10折 boolean discountCoupon = (coupon.getCouponType().equals(CouponTypeEnum.DISCOUNT.name()) && (coupon.getCouponDiscount() < 0 && coupon.getCouponDiscount() > 10)); if (discountCoupon) { throw new ServiceException(ResultCode.COUPON_DISCOUNT_ERROR); } + //优惠券为固定时间类型 if (coupon.getRangeDayType() != null && coupon.getRangeDayType().equals(CouponRangeDayEnum.FIXEDTIME.name())) { long nowTime = DateUtil.getDateline() * 1000; - if (coupon.getStartTime().getTime() < nowTime && coupon.getEndTime().getTime() > nowTime) { - throw new ServiceException(ResultCode.PROMOTION_TIME_ERROR); + //固定时间的优惠券不能小于当前时间 + if (coupon.getEndTime().getTime() < nowTime) { + throw new ServiceException(ResultCode.PROMOTION_END_TIME_ERROR); } - + //促销通用时间校验 PromotionTools.checkPromotionTime(coupon.getStartTime().getTime(), coupon.getEndTime().getTime()); }