|
|
@ -18,9 +18,11 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import org.dromara.system.domain.BusinessCoupon; |
|
|
|
import org.dromara.system.domain.BusinessCoupon; |
|
|
|
|
|
|
|
import org.dromara.system.domain.SysUser; |
|
|
|
import org.dromara.system.domain.bo.*; |
|
|
|
import org.dromara.system.domain.bo.*; |
|
|
|
import org.dromara.system.domain.vo.*; |
|
|
|
import org.dromara.system.domain.vo.*; |
|
|
|
import org.dromara.system.mapper.PromotionCouponTemplateMapper; |
|
|
|
import org.dromara.system.mapper.PromotionCouponTemplateMapper; |
|
|
|
|
|
|
|
import org.dromara.system.mapper.SysUserMapper; |
|
|
|
import org.dromara.system.service.*; |
|
|
|
import org.dromara.system.service.*; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.dromara.system.domain.PromotionCoupon; |
|
|
|
import org.dromara.system.domain.PromotionCoupon; |
|
|
@ -58,6 +60,8 @@ public class PromotionCouponServiceImpl implements IPromotionCouponService { |
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
private ISysBusinessService sysBusinessService; |
|
|
|
private ISysBusinessService sysBusinessService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
|
|
private SysUserMapper sysUserMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
@Resource |
|
|
|
private PromotionCouponTemplateMapper promotionCouponTemplateMapper; |
|
|
|
private PromotionCouponTemplateMapper promotionCouponTemplateMapper; |
|
|
@ -135,6 +139,7 @@ public class PromotionCouponServiceImpl implements IPromotionCouponService { |
|
|
|
lqw.eq(bo.getValidStartTime() != null, PromotionCoupon::getValidStartTime, bo.getValidStartTime()); |
|
|
|
lqw.eq(bo.getValidStartTime() != null, PromotionCoupon::getValidStartTime, bo.getValidStartTime()); |
|
|
|
lqw.eq(bo.getValidEndTime() != null, PromotionCoupon::getValidEndTime, bo.getValidEndTime()); |
|
|
|
lqw.eq(bo.getValidEndTime() != null, PromotionCoupon::getValidEndTime, bo.getValidEndTime()); |
|
|
|
lqw.eq(bo.getProductScopeType() != null, PromotionCoupon::getProductScopeType, bo.getProductScopeType()); |
|
|
|
lqw.eq(bo.getProductScopeType() != null, PromotionCoupon::getProductScopeType, bo.getProductScopeType()); |
|
|
|
|
|
|
|
lqw.in(bo.getProductScopeTypeList() != null, PromotionCoupon::getProductScopeType, bo.getProductScopeTypeList()); |
|
|
|
lqw.eq(bo.getDiscountType() != null, PromotionCoupon::getDiscountType, bo.getDiscountType()); |
|
|
|
lqw.eq(bo.getDiscountType() != null, PromotionCoupon::getDiscountType, bo.getDiscountType()); |
|
|
|
lqw.eq(bo.getDiscountPercent() != null, PromotionCoupon::getDiscountPercent, bo.getDiscountPercent()); |
|
|
|
lqw.eq(bo.getDiscountPercent() != null, PromotionCoupon::getDiscountPercent, bo.getDiscountPercent()); |
|
|
|
lqw.eq(bo.getDiscountPrice() != null, PromotionCoupon::getDiscountPrice, bo.getDiscountPrice()); |
|
|
|
lqw.eq(bo.getDiscountPrice() != null, PromotionCoupon::getDiscountPrice, bo.getDiscountPrice()); |
|
|
@ -237,7 +242,7 @@ public class PromotionCouponServiceImpl implements IPromotionCouponService { |
|
|
|
allFilter.setUserId(bo.getUserId()); |
|
|
|
allFilter.setUserId(bo.getUserId()); |
|
|
|
allFilter.setStatus(1L); |
|
|
|
allFilter.setStatus(1L); |
|
|
|
allFilter.setEffective(true); |
|
|
|
allFilter.setEffective(true); |
|
|
|
allFilter.setProductScopeType(1L); |
|
|
|
allFilter.setProductScopeTypeList(List.of(1L, 2L)); |
|
|
|
allFilter.setAmount(bo.getAmount()); |
|
|
|
allFilter.setAmount(bo.getAmount()); |
|
|
|
List<PromotionCouponVo> allPromotionCouponVos = queryList(allFilter); |
|
|
|
List<PromotionCouponVo> allPromotionCouponVos = queryList(allFilter); |
|
|
|
list.addAll(allPromotionCouponVos); |
|
|
|
list.addAll(allPromotionCouponVos); |
|
|
@ -349,6 +354,18 @@ public class PromotionCouponServiceImpl implements IPromotionCouponService { |
|
|
|
if (ObjectUtil.notEqual(couponTemplate.getTakeType(), takeType)) { |
|
|
|
if (ObjectUtil.notEqual(couponTemplate.getTakeType(), takeType)) { |
|
|
|
throw new ServiceException("领取方式不正确"); |
|
|
|
throw new ServiceException("领取方式不正确"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//新人优惠券
|
|
|
|
|
|
|
|
if(couponTemplate.getProductScopeType() == 4L && couponTemplate.getRegisterDate() != null){ |
|
|
|
|
|
|
|
QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
|
|
queryWrapper.in("user_id", userIds); |
|
|
|
|
|
|
|
queryWrapper.apply("date_format(create_time , '%y-%m-%d') >= date_format({0} , '%y-%m-%d') ", couponTemplate.getRegisterDate() ); |
|
|
|
|
|
|
|
Long count = sysUserMapper.selectCount(queryWrapper); |
|
|
|
|
|
|
|
if(count == 0){ |
|
|
|
|
|
|
|
//用户创建时间小于优惠券的注册时间则不能领取
|
|
|
|
|
|
|
|
String dateStr = DateUtil.format(couponTemplate.getRegisterDate() ,"YYYY年MM月dd日"); |
|
|
|
|
|
|
|
throw new ServiceException("该优惠券仅对"+dateStr+"后注册的用户领取"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
for (Long userId : userIds) { |
|
|
|
for (Long userId : userIds) { |
|
|
|
QueryWrapper<PromotionCoupon> queryWrapper = new QueryWrapper<>(); |
|
|
|
QueryWrapper<PromotionCoupon> queryWrapper = new QueryWrapper<>(); |
|
|
|
queryWrapper.eq("user_id", userId); |
|
|
|
queryWrapper.eq("user_id", userId); |
|
|
@ -373,7 +390,7 @@ public class PromotionCouponServiceImpl implements IPromotionCouponService { |
|
|
|
int update = baseMapper.update(luw); |
|
|
|
int update = baseMapper.update(luw); |
|
|
|
PromotionCouponVo coupon = selectByIdAndUserId(id, userId); |
|
|
|
PromotionCouponVo coupon = selectByIdAndUserId(id, userId); |
|
|
|
if (coupon != null) { |
|
|
|
if (coupon != null) { |
|
|
|
promotionCouponTemplateMapper.addUseCouponCount(coupon.getTemplateId()); |
|
|
|
promotionCouponTemplateMapper.addUseCouponCount(coupon.getTemplateId()); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (update == 0) { |
|
|
|
if (update == 0) { |
|
|
@ -428,7 +445,7 @@ public class PromotionCouponServiceImpl implements IPromotionCouponService { |
|
|
|
if (ObjectUtil.notEqual(coupon.getStatus(), 2L)) { |
|
|
|
if (ObjectUtil.notEqual(coupon.getStatus(), 2L)) { |
|
|
|
throw new ServiceException("优惠劵不是已使用状态"); |
|
|
|
throw new ServiceException("优惠劵不是已使用状态"); |
|
|
|
} |
|
|
|
} |
|
|
|
// 退还
|
|
|
|
// 退还
|
|
|
|
Long status = DateUtil.compare(new Date(), coupon.getValidEndTime(), "yyyy-MM-dd")> 0 ? 3L : 1L; |
|
|
|
Long status = DateUtil.compare(new Date(), coupon.getValidEndTime(), "yyyy-MM-dd")> 0 ? 3L : 1L; |
|
|
|
LambdaUpdateWrapper<PromotionCoupon> luw = new LambdaUpdateWrapper<>(); |
|
|
|
LambdaUpdateWrapper<PromotionCoupon> luw = new LambdaUpdateWrapper<>(); |
|
|
|
luw.set( PromotionCoupon::getStatus, status); |
|
|
|
luw.set( PromotionCoupon::getStatus, status); |
|
|
|