| | |
| | | package com.ruoyi.member.service.impl.coupon; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | |
| | | import com.ruoyi.system.api.domain.poji.goods.Goods; |
| | | import com.ruoyi.system.api.service.RemoteActivityService; |
| | | import com.ruoyi.system.api.service.RemoteGoodsService; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | coupon.setUpdateTime(new Date()); |
| | | coupon.setUpdateUserId(mgtCouponEditDto.getUserId()); |
| | | coupon.setRelationType(mgtCouponEditDto.getRelationType()); |
| | | coupon.setRelationActivityType(mgtCouponEditDto.getRelationActivityType()); |
| | | coupon.setRelationActivityId(mgtCouponEditDto.getRelationActivityId()); |
| | | //判断是否指定商品 |
| | | if(coupon.getUseScope()==2&&!mgtCouponEditDto.getRelGoodsIdList().isEmpty()){ |
| | |
| | | * @param relUserIdList |
| | | * @return void |
| | | */ |
| | | private void sendCoupon(Coupon coupon,List<Long> relUserIdList){ |
| | | @Async |
| | | protected void sendCoupon(Coupon coupon, List<Long> relUserIdList){ |
| | | //1.手动领取2.全部用户3.会员用户4非会员用户5自定义 |
| | | Date nowTime = new Date(); |
| | | Integer sendType = coupon.getSendType(); |
| | |
| | | userIdList = memberService.listIdBySendType(sendType); |
| | | }else if(sendType == 5){ |
| | | //关联类型1.用户管理筛选2.活动管理筛选 |
| | | if(coupon.getRelationType()==1){ |
| | | userIdList = remoteActivityService.listUserIdByActivityId(coupon.getRelationActivityId()).getData(); |
| | | }else if(coupon.getRelationType()==2){ |
| | | if(coupon.getRelationType()==2){ |
| | | Integer relationActivityType = coupon.getRelationActivityType(); |
| | | //关联活动类型1秒杀活动 |
| | | switch(relationActivityType){ |
| | | case 1: |
| | | userIdList = remoteActivityService.listUserIdByActivityId(coupon.getRelationActivityId()).getData(); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | }else if(coupon.getRelationType()==1){ |
| | | userIdList = relUserIdList; |
| | | } |
| | | } |
| | |
| | | coupon.setUpdateTime(new Date()); |
| | | this.saveOrUpdate(coupon); |
| | | } |
| | | |
| | | /** |
| | | * @description 定时发送优惠券 |
| | | * @author jqs |
| | | * @date 2023/6/14 9:40 |
| | | * @param |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void timingSendCoupon(){ |
| | | LambdaQueryWrapper<Coupon> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Coupon::getDelFlag,0); |
| | | queryWrapper.eq(Coupon::getCouponStatus,1); |
| | | queryWrapper.eq(Coupon::getSendTimeType,2); |
| | | queryWrapper.eq(Coupon::getAuditStatus,2); |
| | | queryWrapper.eq(Coupon::getSendTime,new Date()); |
| | | List<Coupon> couponList = couponMapper.selectList(queryWrapper); |
| | | if(couponList!=null&&!couponList.isEmpty()){ |
| | | List<CouponRelUser> couponRelUserList; |
| | | List<Long> userIdList = new ArrayList<>(); |
| | | for(Coupon coupon : couponList){ |
| | | if(coupon.getSendType()==5&&coupon.getRelationType()==1){ |
| | | couponRelUserList = couponRelUserService.list(new LambdaQueryWrapper<CouponRelUser>().eq(CouponRelUser::getDelFlag,0).eq(CouponRelUser::getCouponId,coupon.getCouponId())); |
| | | if(couponRelUserList!=null&&!couponRelUserList.isEmpty()){ |
| | | userIdList = couponRelUserList.stream() |
| | | .map(CouponRelUser::getUserId) |
| | | .collect(Collectors.toList()); |
| | | }else{ |
| | | userIdList = new ArrayList<>(); |
| | | } |
| | | } |
| | | //发送优惠券 |
| | | sendCoupon(coupon, userIdList); |
| | | } |
| | | } |
| | | } |
| | | } |