| | |
| | | package com.ruoyi.member.service.impl.coupon; |
| | | |
| | | import com.ruoyi.member.domain.pojo.coupon.Coupon; |
| | | import com.ruoyi.member.mapper.coupon.CouponMapper; |
| | | import com.ruoyi.member.service.coupon.CouponService; |
| | | 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.common.core.utils.DateUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.core.utils.uuid.IdUtils; |
| | | import com.ruoyi.member.domain.dto.*; |
| | | import com.ruoyi.member.domain.pojo.coupon.Coupon; |
| | | import com.ruoyi.member.domain.pojo.coupon.CouponRelGoods; |
| | | import com.ruoyi.member.domain.pojo.coupon.CouponRelUser; |
| | | import com.ruoyi.member.domain.pojo.coupon.CouponTotal; |
| | | import com.ruoyi.member.domain.pojo.member.MemberCoupon; |
| | | import com.ruoyi.member.domain.vo.*; |
| | | import com.ruoyi.member.mapper.coupon.CouponMapper; |
| | | import com.ruoyi.member.service.coupon.CouponRelGoodsService; |
| | | import com.ruoyi.member.service.coupon.CouponRelUserService; |
| | | import com.ruoyi.member.service.coupon.CouponService; |
| | | import com.ruoyi.member.service.coupon.CouponTotalService; |
| | | import com.ruoyi.member.service.member.MemberCouponService; |
| | | import com.ruoyi.member.service.member.MemberService; |
| | | import com.ruoyi.system.api.constant.AppErrorConstant; |
| | | import com.ruoyi.system.api.domain.dto.MgtBaseGetDto; |
| | | 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; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class CouponServiceImpl extends ServiceImpl<CouponMapper, Coupon> implements CouponService { |
| | | |
| | | @Resource |
| | | private CouponRelUserService couponRelUserService; |
| | | |
| | | @Resource |
| | | private CouponRelGoodsService couponRelGoodsService; |
| | | |
| | | @Resource |
| | | private CouponMapper couponMapper; |
| | | |
| | | @Resource |
| | | private RemoteGoodsService remoteGoodsService; |
| | | |
| | | @Resource |
| | | private CouponTotalService couponTotalService; |
| | | |
| | | @Resource |
| | | private MemberService memberService; |
| | | |
| | | @Resource |
| | | private MemberCouponService memberCouponService; |
| | | |
| | | @Resource |
| | | private RemoteActivityService remoteActivityService; |
| | | |
| | | /** |
| | | * @description 平台获取优惠券列表 |
| | | * @author jqs |
| | | * @date 2023/6/13 11:06 |
| | | * @param page |
| | | * @param mgtCouponPageDto |
| | | * @return List<MgtCouponPageVo> |
| | | */ |
| | | @Override |
| | | public List<MgtCouponPageVo> pageMgtCoupon(Page page, MgtCouponPageDto mgtCouponPageDto){ |
| | | List<MgtCouponPageVo> mgtCouponPageVoList = couponMapper.pageMgtCoupon(page, mgtCouponPageDto); |
| | | //处理使用限制和有效期 |
| | | if(mgtCouponPageVoList!=null&&!mgtCouponPageVoList.isEmpty()){ |
| | | Integer couponType; |
| | | Integer validTimeType; |
| | | Date validStartTime; |
| | | Date validEndTime; |
| | | Integer validDay; |
| | | String validTime = ""; |
| | | BigDecimal moneyThreshold; |
| | | BigDecimal discountMoney; |
| | | BigDecimal discountPercent; |
| | | String useLimit = ""; |
| | | for(MgtCouponPageVo mgtCouponPageVo : mgtCouponPageVoList){ |
| | | //处理使用限制 |
| | | couponType = mgtCouponPageVo.getCouponType(); |
| | | switch (couponType){ |
| | | case 1: |
| | | moneyThreshold = mgtCouponPageVo.getMoneyThreshold(); |
| | | discountMoney = mgtCouponPageVo.getDiscountMoney(); |
| | | useLimit = "满" + moneyThreshold.toString() + "减" + discountMoney.toString() + "元"; |
| | | break; |
| | | case 2: |
| | | break; |
| | | case 3: |
| | | break; |
| | | case 4: |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | mgtCouponPageVo.setUseLimit(useLimit); |
| | | //处理有效期 |
| | | validTimeType = mgtCouponPageVo.getValidTimeType(); |
| | | if(validTimeType==1){ |
| | | validStartTime = mgtCouponPageVo.getValidStartTime(); |
| | | validEndTime = mgtCouponPageVo.getValidEndTime(); |
| | | validTime = DateUtils.dateTime(validStartTime) + '-' + DateUtils.dateTime(validEndTime); |
| | | }else if(validTimeType==2){ |
| | | validDay = mgtCouponPageVo.getValidDay(); |
| | | validTime = "领取之日起" + validDay.toString() + "天"; |
| | | } |
| | | mgtCouponPageVo.setValidTime(validTime); |
| | | } |
| | | } |
| | | return mgtCouponPageVoList; |
| | | } |
| | | |
| | | /** |
| | | * @description 平台获取优惠券编辑信息 |
| | | * @author jqs |
| | | * @date 2023/6/13 14:29 |
| | | * @param couponId |
| | | * @return MgtCouponGetVo |
| | | */ |
| | | @Override |
| | | public MgtCouponGetVo getMgtCouponVo(String couponId){ |
| | | MgtCouponGetVo mgtCouponGetVo = new MgtCouponGetVo(); |
| | | Coupon coupon = this.getById(couponId); |
| | | BeanUtils.copyProperties(coupon, mgtCouponGetVo); |
| | | //判断优惠券是否为指定商品 |
| | | if(coupon.getUseScope()==2){ |
| | | String relGoodsIds = coupon.getRelGoodsIds(); |
| | | if(StringUtils.isNotBlank(relGoodsIds)){ |
| | | //获取指定商品列表 |
| | | List<Goods> goodsList = remoteGoodsService.listGoodsByGoodsId(relGoodsIds).getData(); |
| | | if(!goodsList.isEmpty()){ |
| | | //转换为返回对象 |
| | | List<MgtCouponGoodsListVo> relGoodsList = new ArrayList<>(); |
| | | MgtCouponGoodsListVo mgtCouponGoodsListVo; |
| | | for(Goods goods : goodsList){ |
| | | mgtCouponGoodsListVo = new MgtCouponGoodsListVo(); |
| | | mgtCouponGoodsListVo.setGoodsId(goods.getGoodsId()); |
| | | mgtCouponGoodsListVo.setGoodsName(goods.getGoodsName()); |
| | | mgtCouponGoodsListVo.setGoodsNo(goods.getGoodsNo()); |
| | | //商品类型1周期2服务3体验4单品 |
| | | switch (goods.getGoodsType()){ |
| | | case 1: |
| | | mgtCouponGoodsListVo.setGoodsType("周期"); |
| | | break; |
| | | case 2: |
| | | mgtCouponGoodsListVo.setGoodsType("服务"); |
| | | break; |
| | | case 3: |
| | | mgtCouponGoodsListVo.setGoodsType("体验"); |
| | | break; |
| | | case 4: |
| | | mgtCouponGoodsListVo.setGoodsType("单品"); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | mgtCouponGoodsListVo.setSalesPrice(goods.getSalesPrice()); |
| | | relGoodsList.add(mgtCouponGoodsListVo); |
| | | } |
| | | mgtCouponGetVo.setRelGoodsList(relGoodsList); |
| | | } |
| | | } |
| | | } |
| | | //判断优惠券是否指定发放用户 |
| | | if(coupon.getSendType()==5&&coupon.getRelationType()==1){ |
| | | //获取优惠券发放用户 |
| | | List<MgtCouponMemberListVo> relUserList = couponRelUserService.listCouponMemberVo(coupon.getCouponId()); |
| | | mgtCouponGetVo.setRelUserList(relUserList); |
| | | } |
| | | return mgtCouponGetVo; |
| | | } |
| | | |
| | | /** |
| | | * @description 平台编辑优惠券 |
| | | * @author jqs |
| | | * @date 2023/6/13 16:50 |
| | | * @param mgtCouponEditDto |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void editMgtCoupon(MgtCouponEditDto mgtCouponEditDto){ |
| | | //编辑优惠券 |
| | | Coupon coupon; |
| | | CouponTotal couponTotal; |
| | | if(StringUtils.isNotBlank(mgtCouponEditDto.getCouponId())){ |
| | | coupon = this.getById(mgtCouponEditDto.getCouponId()); |
| | | couponTotal = couponTotalService.getById(mgtCouponEditDto.getCouponId()); |
| | | if(couponTotal.getSendCount()!=null&&couponTotal.getSendCount()>0){ |
| | | throw new ServiceException(AppErrorConstant.COUPON_SENT_EDIT); |
| | | } |
| | | couponRelUserService.deleteCouponRelByCouponId(coupon.getCouponId()); |
| | | couponRelGoodsService.deleteCouponRelByCouponId(coupon.getCouponId()); |
| | | }else{ |
| | | coupon = new Coupon(); |
| | | String couponId = IdUtils.simpleUUID(); |
| | | coupon.setCouponId(couponId); |
| | | coupon.setDelFlag(0); |
| | | coupon.setCouponStatus(1); |
| | | coupon.setCreateTime(new Date()); |
| | | coupon.setCreateUserId(mgtCouponEditDto.getUserId()); |
| | | coupon.setCouponFrom(1); |
| | | coupon.setAuditStatus(2); |
| | | //创建优惠券统计 |
| | | couponTotal = new CouponTotal(); |
| | | couponTotal.setCouponId(couponId); |
| | | couponTotal.setSendCount(0); |
| | | couponTotal.setSendUserCount(0); |
| | | couponTotalService.save(couponTotal); |
| | | } |
| | | //优惠券赋值 |
| | | coupon.setCouponType(mgtCouponEditDto.getCouponType()); |
| | | coupon.setCouponName(mgtCouponEditDto.getCouponName()); |
| | | coupon.setSendType(mgtCouponEditDto.getSendType()); |
| | | coupon.setSendTimeType(mgtCouponEditDto.getSendTimeType()); |
| | | coupon.setSendTime(mgtCouponEditDto.getSendTime()); |
| | | coupon.setMoneyThreshold(mgtCouponEditDto.getMoneyThreshold()); |
| | | coupon.setDiscountMoney(mgtCouponEditDto.getDiscountMoney()); |
| | | coupon.setDiscountPercent(mgtCouponEditDto.getDiscountPercent()); |
| | | coupon.setUseScope(mgtCouponEditDto.getUseScope()); |
| | | coupon.setValidTimeType(mgtCouponEditDto.getValidTimeType()); |
| | | coupon.setValidStartTime(mgtCouponEditDto.getValidStartTime()); |
| | | coupon.setValidEndTime(mgtCouponEditDto.getValidEndTime()); |
| | | coupon.setValidDay(mgtCouponEditDto.getValidDay()); |
| | | 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()){ |
| | | List<String> relGoodsIdList = mgtCouponEditDto.getRelGoodsIdList(); |
| | | List<CouponRelGoods> couponRelGoodsList = relGoodsIdList.stream() |
| | | .map(str -> { |
| | | CouponRelGoods couponRelGoods = new CouponRelGoods(); |
| | | couponRelGoods.setDelFlag(0); |
| | | couponRelGoods.setCouponId(coupon.getCouponId()); |
| | | couponRelGoods.setGoodsId(str); |
| | | return couponRelGoods; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | couponRelGoodsService.saveBatch(couponRelGoodsList); |
| | | String relGoodsIds = relGoodsIdList.stream().collect(Collectors.joining(",")); |
| | | coupon.setRelGoodsIds(relGoodsIds); |
| | | } |
| | | //判断是否指定用户 |
| | | List<Long> relUserIdList = null; |
| | | if(coupon.getSendType()==5&&coupon.getRelationType()==1&&!mgtCouponEditDto.getRelUserIdList().isEmpty()){ |
| | | relUserIdList = mgtCouponEditDto.getRelUserIdList(); |
| | | List<CouponRelUser> couponRelUserList = relUserIdList.stream() |
| | | .map(str -> { |
| | | CouponRelUser couponRelUser = new CouponRelUser(); |
| | | couponRelUser.setDelFlag(0); |
| | | couponRelUser.setCouponId(coupon.getCouponId()); |
| | | couponRelUser.setUserId(str); |
| | | return couponRelUser; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | couponRelUserService.saveBatch(couponRelUserList); |
| | | } |
| | | this.saveOrUpdate(coupon); |
| | | //处理优惠券发放 |
| | | if(coupon.getSendTimeType()==1){ |
| | | sendCoupon(coupon,relUserIdList); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 发送优惠券 |
| | | * @author jqs |
| | | * @date 2023/6/13 18:45 |
| | | * @param coupon |
| | | * @param relUserIdList |
| | | * @return void |
| | | */ |
| | | @Async |
| | | protected void sendCoupon(Coupon coupon, List<Long> relUserIdList){ |
| | | //1.手动领取2.全部用户3.会员用户4非会员用户5自定义 |
| | | Date nowTime = new Date(); |
| | | Integer sendType = coupon.getSendType(); |
| | | List<Long> userIdList = new ArrayList<>(); |
| | | if(sendType >= 2 && sendType <= 4){ |
| | | userIdList = memberService.listIdBySendType(sendType); |
| | | }else if(sendType == 5){ |
| | | //关联类型1.用户管理筛选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; |
| | | } |
| | | } |
| | | if(!relUserIdList.isEmpty()){ |
| | | List<MemberCoupon> memberCouponList = new ArrayList<>(); |
| | | MemberCoupon memberCoupon; |
| | | Integer sendTotal = 0; |
| | | for(Long userId : userIdList){ |
| | | memberCoupon = new MemberCoupon(); |
| | | memberCoupon.setDelFlag(0); |
| | | memberCoupon.setCouponId(coupon.getCouponId()); |
| | | memberCoupon.setUserId(userId); |
| | | memberCoupon.setCouponType(coupon.getCouponType()); |
| | | memberCoupon.setCouponStatus(coupon.getCouponStatus()); |
| | | memberCoupon.setCouponName(coupon.getCouponName()); |
| | | memberCoupon.setSendType(coupon.getSendType()); |
| | | memberCoupon.setSendTimeType(coupon.getSendTimeType()); |
| | | memberCoupon.setSendTime(coupon.getSendTime()); |
| | | memberCoupon.setMoneyThreshold(coupon.getMoneyThreshold()); |
| | | memberCoupon.setDiscountMoney(coupon.getDiscountMoney()); |
| | | memberCoupon.setDiscountPercent(coupon.getDiscountPercent()); |
| | | memberCoupon.setUseScope(coupon.getUseScope()); |
| | | memberCoupon.setValidTimeType(coupon.getValidTimeType()); |
| | | memberCoupon.setValidStartTime(coupon.getValidStartTime()); |
| | | memberCoupon.setValidEndTime(coupon.getValidEndTime()); |
| | | memberCoupon.setValidDay(coupon.getValidDay()); |
| | | memberCoupon.setReceiveTime(nowTime); |
| | | memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds()); |
| | | //有效期处理1.时间段2.领取之日起 |
| | | if(coupon.getValidTimeType()==1){ |
| | | memberCoupon.setDeadlineTime(coupon.getValidEndTime()); |
| | | }else if(coupon.getValidTimeType()==2){ |
| | | memberCoupon.setDeadlineTime(DateUtils.addDays(nowTime,coupon.getValidDay())); |
| | | } |
| | | memberCouponList.add(memberCoupon); |
| | | sendTotal = sendTotal + 1; |
| | | } |
| | | memberCouponService.saveBatch(memberCouponList); |
| | | //处理优惠券统计 |
| | | if(sendTotal>0){ |
| | | CouponTotal couponTotal = couponTotalService.getById(coupon.getCouponId()); |
| | | couponTotal.setSendCount(couponTotal.getSendCount()+sendTotal); |
| | | couponTotal.setSendUserCount(couponTotal.getSendUserCount()+sendTotal); |
| | | couponTotalService.saveOrUpdate(couponTotal); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 平台删除优惠券 |
| | | * @author jqs |
| | | * @date 2023/6/13 18:50 |
| | | * @param mgtBaseGetDto |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void deleteMgtCoupon(MgtBaseGetDto mgtBaseGetDto){ |
| | | Coupon coupon = this.getById(mgtBaseGetDto.getId()); |
| | | CouponTotal couponTotal = couponTotalService.getById(mgtBaseGetDto.getId()); |
| | | if(couponTotal.getSendCount()!=null&&couponTotal.getSendCount()>0){ |
| | | throw new ServiceException(AppErrorConstant.COUPON_SENT_DEL); |
| | | } |
| | | coupon.setCouponStatus(-1); |
| | | coupon.setDelFlag(1); |
| | | coupon.setUpdateUserId(mgtBaseGetDto.getUserId()); |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 获取优惠券选择列表 |
| | | * @author jqs |
| | | * @date 2023/6/15 14:59 |
| | | * @param mgtCouponListDto |
| | | * @return List<MgtCouponSimpleListVo> |
| | | */ |
| | | @Override |
| | | public List<MgtCouponSimpleListVo> listMgtCouponSimpleVo(MgtCouponListDto mgtCouponListDto){ |
| | | if(mgtCouponListDto.getShopId()!=null&&mgtCouponListDto.getShopId()==0){ |
| | | mgtCouponListDto.setShopId(null); |
| | | } |
| | | return couponMapper.listMgtCouponSimpleVo(mgtCouponListDto); |
| | | } |
| | | |
| | | /** |
| | | * @description 获取商户优惠券审核列表 |
| | | * @author jqs |
| | | * @date 2023/6/15 16:20 |
| | | * @param page |
| | | * @param mgtCouponAuditPageDto |
| | | * @return List<MgtCouponAuditPageVo> |
| | | */ |
| | | @Override |
| | | public List<MgtCouponAuditPageVo> pageMgtAuditCoupon(Page page, MgtCouponAuditPageDto mgtCouponAuditPageDto){ |
| | | List<MgtCouponAuditPageVo> mgtCouponAuditPageVoList = couponMapper.pageMgtAuditCoupon(page, mgtCouponAuditPageDto); |
| | | //处理使用限制和有效期 |
| | | if(mgtCouponAuditPageVoList!=null&&!mgtCouponAuditPageVoList.isEmpty()){ |
| | | Integer couponType; |
| | | Integer validTimeType; |
| | | Date validStartTime; |
| | | Date validEndTime; |
| | | Integer validDay; |
| | | String validTime = ""; |
| | | for(MgtCouponAuditPageVo mgtCouponAuditPageVo : mgtCouponAuditPageVoList){ |
| | | //处理有效期 |
| | | validTimeType = mgtCouponAuditPageVo.getValidTimeType(); |
| | | if(validTimeType==1){ |
| | | validStartTime = mgtCouponAuditPageVo.getValidStartTime(); |
| | | validEndTime = mgtCouponAuditPageVo.getValidEndTime(); |
| | | validTime = DateUtils.dateTime(validStartTime) + '-' + DateUtils.dateTime(validEndTime); |
| | | }else if(validTimeType==2){ |
| | | validDay = mgtCouponAuditPageVo.getValidDay(); |
| | | validTime = "领取之日起" + validDay.toString() + "天"; |
| | | } |
| | | mgtCouponAuditPageVo.setValidTime(validTime); |
| | | } |
| | | } |
| | | return mgtCouponAuditPageVoList; |
| | | } |
| | | |
| | | /** |
| | | * @description 获取优惠券审核信息 |
| | | * @author jqs |
| | | * @date 2023/6/15 16:36 |
| | | * @param couponId |
| | | * @return MgtCouponAuditGetVo |
| | | */ |
| | | @Override |
| | | public MgtCouponAuditGetVo getMgtCouponAuditVo(String couponId){ |
| | | MgtCouponAuditGetVo mgtCouponAuditGetVo = new MgtCouponAuditGetVo(); |
| | | Coupon coupon = this.getById(couponId); |
| | | //判断优惠券是否为指定商品 |
| | | if(coupon.getUseScope()==2){ |
| | | String relGoodsIds = coupon.getRelGoodsIds(); |
| | | if(StringUtils.isNotBlank(relGoodsIds)){ |
| | | //获取指定商品列表 |
| | | List<Goods> goodsList = remoteGoodsService.listGoodsByGoodsId(relGoodsIds).getData(); |
| | | if(!goodsList.isEmpty()){ |
| | | //转换为返回对象 |
| | | List<MgtCouponGoodsListVo> relGoodsList = new ArrayList<>(); |
| | | MgtCouponGoodsListVo mgtCouponGoodsListVo; |
| | | for(Goods goods : goodsList){ |
| | | mgtCouponGoodsListVo = new MgtCouponGoodsListVo(); |
| | | mgtCouponGoodsListVo.setGoodsId(goods.getGoodsId()); |
| | | mgtCouponGoodsListVo.setGoodsName(goods.getGoodsName()); |
| | | mgtCouponGoodsListVo.setGoodsNo(goods.getGoodsNo()); |
| | | //商品类型1周期2服务3体验4单品 |
| | | switch (goods.getGoodsType()){ |
| | | case 1: |
| | | mgtCouponGoodsListVo.setGoodsType("周期"); |
| | | break; |
| | | case 2: |
| | | mgtCouponGoodsListVo.setGoodsType("服务"); |
| | | break; |
| | | case 3: |
| | | mgtCouponGoodsListVo.setGoodsType("体验"); |
| | | break; |
| | | case 4: |
| | | mgtCouponGoodsListVo.setGoodsType("单品"); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | mgtCouponGoodsListVo.setSalesPrice(goods.getSalesPrice()); |
| | | relGoodsList.add(mgtCouponGoodsListVo); |
| | | } |
| | | mgtCouponAuditGetVo.setRelGoodsList(relGoodsList); |
| | | } |
| | | } |
| | | } |
| | | //判断优惠券是否指定发放用户 |
| | | if(coupon.getSendType()==5&&coupon.getRelationType()==1){ |
| | | //获取优惠券发放用户 |
| | | List<MgtCouponMemberListVo> relUserList = couponRelUserService.listCouponMemberVo(coupon.getCouponId()); |
| | | mgtCouponAuditGetVo.setRelUserList(relUserList); |
| | | } |
| | | return mgtCouponAuditGetVo; |
| | | } |
| | | |
| | | /** |
| | | * @description 审核优惠券 |
| | | * @author jqs |
| | | * @date 2023/6/15 16:46 |
| | | * @param mgtCouponAuditDto |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void auditMgtCoupon(MgtCouponAuditDto mgtCouponAuditDto){ |
| | | Coupon coupon = this.getById(mgtCouponAuditDto.getCouponId()); |
| | | //判断优惠券是否审核 |
| | | if(coupon.getCouponStatus()!=1){ |
| | | throw new ServiceException(AppErrorConstant.COUPON_AUDIT_DOUBLE); |
| | | } |
| | | coupon.setAuditStatus(mgtCouponAuditDto.getAuditStatus()); |
| | | coupon.setAuditReason(mgtCouponAuditDto.getAuditReason()); |
| | | coupon.setUpdateTime(new Date()); |
| | | coupon.setUpdateUserId(mgtCouponAuditDto.getUserId()); |
| | | this.saveOrUpdate(coupon); |
| | | //审核通过后判断是否立即发放 |
| | | if(coupon.getCouponStatus()==2&&coupon.getSendTimeType()==1){ |
| | | List<CouponRelUser> couponRelUserList = couponRelUserService.list(new LambdaQueryWrapper<CouponRelUser>().eq(CouponRelUser::getDelFlag,0).eq(CouponRelUser::getCouponId,coupon.getCouponId())); |
| | | List<Long> userIdList = new ArrayList<>(); |
| | | if(couponRelUserList!=null&&!couponRelUserList.isEmpty()){ |
| | | userIdList = couponRelUserList.stream() |
| | | .map(CouponRelUser::getUserId) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | //发放优惠券 |
| | | sendCoupon(coupon, userIdList); |
| | | } |
| | | } |
| | | } |