| | |
| | | package com.ruoyi.member.service.impl.coupon; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | 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.StringUtils; |
| | | import com.ruoyi.common.core.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.core.utils.uuid.IdUtils; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | 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.pojo.coupon.*; |
| | | 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.coupon.*; |
| | | 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.constant.DelayTaskEnum; |
| | | import com.ruoyi.system.api.domain.dto.*; |
| | | import com.ruoyi.system.api.domain.poji.activity.Activity; |
| | | import com.ruoyi.system.api.domain.poji.config.DelayTask; |
| | | import com.ruoyi.system.api.domain.poji.goods.Goods; |
| | | import com.ruoyi.system.api.domain.poji.member.Member; |
| | | import com.ruoyi.system.api.domain.poji.member.MemberCoupon; |
| | | import com.ruoyi.system.api.domain.vo.MerGoodsPriceListVo; |
| | | import com.ruoyi.system.api.domain.vo.MgtSimpleShopVo; |
| | | import com.ruoyi.system.api.service.RemoteActivityService; |
| | | import com.ruoyi.system.api.service.RemoteConfigService; |
| | | import com.ruoyi.system.api.service.RemoteGoodsService; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import com.ruoyi.system.api.service.RemoteShopService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | @Resource |
| | | private RemoteActivityService remoteActivityService; |
| | | |
| | | @Resource |
| | | private MemberCouponRecordService memberCouponRecordService; |
| | | |
| | | @Resource |
| | | private RemoteShopService remoteShopService; |
| | | |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | @Resource |
| | | private RemoteConfigService remoteConfigService; |
| | | |
| | | /** |
| | | * @description 平台获取优惠券列表 |
| | | * @author jqs |
| | |
| | | List<MgtCouponPageVo> mgtCouponPageVoList = couponMapper.pageMgtCoupon(page, mgtCouponPageDto); |
| | | //处理使用限制和有效期 |
| | | if(mgtCouponPageVoList!=null&&!mgtCouponPageVoList.isEmpty()){ |
| | | Integer couponType; |
| | | String couponType; |
| | | Integer validTimeType; |
| | | Date validStartTime; |
| | | Date validEndTime; |
| | |
| | | BigDecimal discountPercent; |
| | | String useLimit = ""; |
| | | for(MgtCouponPageVo mgtCouponPageVo : mgtCouponPageVoList){ |
| | | useLimit = null; |
| | | //处理使用限制 |
| | | 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; |
| | | if(couponType.equals("满减")){ |
| | | moneyThreshold = mgtCouponPageVo.getMoneyThreshold(); |
| | | discountMoney = mgtCouponPageVo.getDiscountMoney(); |
| | | useLimit = "满" + moneyThreshold.toString() + "减" + discountMoney.toString() + "元"; |
| | | } |
| | | if(couponType.equals("折扣")){ |
| | | discountPercent = mgtCouponPageVo.getDiscountPercent(); |
| | | useLimit = discountPercent.toString() + "折"; |
| | | } |
| | | if(couponType.equals("代金")){ |
| | | discountMoney = mgtCouponPageVo.getDiscountMoney(); |
| | | useLimit = discountMoney.toString(); |
| | | } |
| | | mgtCouponPageVo.setUseLimit(useLimit); |
| | | //处理有效期 |
| | |
| | | if(validTimeType==1){ |
| | | validStartTime = mgtCouponPageVo.getValidStartTime(); |
| | | validEndTime = mgtCouponPageVo.getValidEndTime(); |
| | | validTime = DateUtils.dateTime(validStartTime) + '-' + DateUtils.dateTime(validEndTime); |
| | | validTime = DateUtils.parseDateToStr("yyyy-MM-dd",validStartTime) + '-' + DateUtils.parseDateToStr("yyyy-MM-dd",validEndTime); |
| | | }else if(validTimeType==2){ |
| | | validDay = mgtCouponPageVo.getValidDay(); |
| | | validTime = "领取之日起" + validDay.toString() + "天"; |
| | |
| | | mgtCouponGoodsListVo.setGoodsId(goods.getGoodsId()); |
| | | mgtCouponGoodsListVo.setGoodsName(goods.getGoodsName()); |
| | | mgtCouponGoodsListVo.setGoodsNo(goods.getGoodsNo()); |
| | | mgtCouponGoodsListVo.setGoodsType(goods.getGoodsType()); |
| | | //商品类型1周期2服务3体验4单品 |
| | | switch (goods.getGoodsType()){ |
| | | case 1: |
| | | mgtCouponGoodsListVo.setGoodsType("周期"); |
| | | mgtCouponGoodsListVo.setGoodsTypeName("周期"); |
| | | break; |
| | | case 2: |
| | | mgtCouponGoodsListVo.setGoodsType("服务"); |
| | | mgtCouponGoodsListVo.setGoodsTypeName("服务"); |
| | | break; |
| | | case 3: |
| | | mgtCouponGoodsListVo.setGoodsType("体验"); |
| | | mgtCouponGoodsListVo.setGoodsTypeName("体验"); |
| | | break; |
| | | case 4: |
| | | mgtCouponGoodsListVo.setGoodsType("单品"); |
| | | mgtCouponGoodsListVo.setGoodsTypeName("单品"); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | } |
| | | } |
| | | //判断优惠券是否指定发放用户 |
| | | if(coupon.getSendType()==5&&coupon.getRelationType()==1){ |
| | | if(coupon.getSendTarget()==5&&coupon.getRelationType()==1){ |
| | | //获取优惠券发放用户 |
| | | List<MgtCouponMemberListVo> relUserList = couponRelUserService.listCouponMemberVo(coupon.getCouponId()); |
| | | mgtCouponGetVo.setRelUserList(relUserList); |
| | | } |
| | | //获取活动名称 |
| | | if(coupon.getSendTarget()==5&&coupon.getRelationType()==2){ |
| | | Activity activity = remoteActivityService.getActivity(coupon.getRelationActivityId()).getData(); |
| | | mgtCouponGetVo.setRelationActivityName(activity.getActivityName()); |
| | | } |
| | | if(mgtCouponGetVo.getSendLimitFlag()==0){ |
| | | mgtCouponGetVo.setSendLimitNumber(null); |
| | | } |
| | | return mgtCouponGetVo; |
| | | } |
| | | |
| | | /** |
| | | * @description 平台获取优惠券编辑信息 |
| | | * @author jqs |
| | | * @date 2023/6/13 14:29 |
| | | * @param merBaseGetDto |
| | | * @return MgtCouponGetVo |
| | | */ |
| | | @Override |
| | | public MerCouponGetVo getMerCouponVo(MerBaseGetDto merBaseGetDto){ |
| | | MerCouponGetVo merCouponGetVo = new MerCouponGetVo(); |
| | | Coupon coupon = this.getById(merBaseGetDto.getId()); |
| | | BeanUtils.copyProperties(coupon, merCouponGetVo); |
| | | //判断优惠券是否为指定商品 |
| | | if(coupon.getUseScope()==2){ |
| | | String relGoodsIds = coupon.getRelGoodsIds(); |
| | | if(StringUtils.isNotBlank(relGoodsIds)){ |
| | | //获取指定商品列表 |
| | | MerGoodsPriceListDto merGoodsPriceListDto = new MerGoodsPriceListDto(); |
| | | merGoodsPriceListDto.setGoodsIds(relGoodsIds); |
| | | merGoodsPriceListDto.setShopId(merBaseGetDto.getShopId()); |
| | | List<MerGoodsPriceListVo> goodsList = remoteGoodsService.listGoodsPriceByGoodsId(merGoodsPriceListDto).getData(); |
| | | if(goodsList!=null&&!goodsList.isEmpty()){ |
| | | merCouponGetVo.setRelGoodsList(goodsList); |
| | | } |
| | | } |
| | | } |
| | | //判断优惠券是否指定发放用户 |
| | | if(coupon.getSendTarget()==5&&coupon.getRelationType()==1){ |
| | | //获取优惠券发放用户 |
| | | List<MgtCouponMemberListVo> relUserList = couponRelUserService.listCouponMemberVo(coupon.getCouponId()); |
| | | merCouponGetVo.setRelUserList(relUserList); |
| | | } |
| | | if(merCouponGetVo.getSendLimitFlag()==0){ |
| | | merCouponGetVo.setSendLimitNumber(null); |
| | | } |
| | | return merCouponGetVo; |
| | | } |
| | | |
| | | /** |
| | |
| | | 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); |
| | | // couponTotal = couponTotalService.getById(mgtCouponEditDto.getCouponId()); |
| | | // if(couponTotal.getSendCount()!=null&&couponTotal.getSendCount()>0){ |
| | | // throw new ServiceException(AppErrorConstant.COUPON_SENT_EDIT); |
| | | // } |
| | | /** |
| | | * 一:不可修改 |
| | | * 1、优惠券类型 |
| | | * 2、发放方式 |
| | | * 3、优惠券金额 |
| | | * 4、使用期限类型 |
| | | * 5、有效时间段:开始时间不能修改,结束时间可以修改 |
| | | * 二:部分可修改 |
| | | * 1、发放方式为指定发放时 |
| | | * 定时发放:已到发放时间不可修改 |
| | | * 立即发放:不可修改 |
| | | * 2、适用范围 |
| | | * 全部商品:不可修改 |
| | | * 部分商品:只能增加商品 |
| | | * 3、发放数量:只能增加 |
| | | * 不限制:不可修改 |
| | | * 4、用户可领数量:只能增加 |
| | | * 三:可修改 |
| | | * 1、优惠券名称 |
| | | * 2、宣传海报 |
| | | * 四:发放对象 |
| | | * 1、未到发放时间都可以修改 |
| | | * 2、已到发放时间,只有自定义时可修改,且只能增加用户 |
| | | */ |
| | | if(!coupon.getCouponType().equals(mgtCouponEditDto.getCouponType())){ |
| | | throw new ServiceException("不能修改优惠券类型"); |
| | | } |
| | | if(!coupon.getSendType().equals(mgtCouponEditDto.getSendType())){ |
| | | throw new ServiceException("不能修改优惠券发放方式"); |
| | | } |
| | | if(null != mgtCouponEditDto.getMoneyThreshold() && coupon.getMoneyThreshold().compareTo(mgtCouponEditDto.getMoneyThreshold()) != 0){ |
| | | throw new ServiceException("不能修改优惠券金额"); |
| | | } |
| | | if(null != mgtCouponEditDto.getDiscountMoney() && coupon.getDiscountMoney().compareTo(mgtCouponEditDto.getDiscountMoney()) != 0){ |
| | | throw new ServiceException("不能修改优惠券金额"); |
| | | } |
| | | if(null != mgtCouponEditDto.getDiscountPercent() && coupon.getDiscountPercent().compareTo(mgtCouponEditDto.getDiscountPercent()) != 0){ |
| | | throw new ServiceException("不能修改优惠券折扣"); |
| | | } |
| | | if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() == 2 && System.currentTimeMillis() >= coupon.getSendTime().getTime() && null != mgtCouponEditDto.getValidTimeType() && !coupon.getValidTimeType().equals(mgtCouponEditDto.getValidTimeType())){ |
| | | throw new ServiceException("不能修改优惠券适用期限类型"); |
| | | } |
| | | if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() == 2 && System.currentTimeMillis() >= coupon.getSendTime().getTime() && null != mgtCouponEditDto.getValidTimeType() && coupon.getValidTimeType() == 1 && !coupon.getValidStartTime().equals(mgtCouponEditDto.getValidStartTime())){ |
| | | throw new ServiceException("不能修改优惠券有效期开始时间"); |
| | | } |
| | | if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 1 && mgtCouponEditDto.getSendTimeType() != 1){ |
| | | throw new ServiceException("不能修改优惠券发放方式"); |
| | | } |
| | | if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() != 2 && System.currentTimeMillis() <= coupon.getSendTime().getTime()){ |
| | | throw new ServiceException("不能修改优惠券发放方式"); |
| | | } |
| | | if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() == 2 && System.currentTimeMillis() >= coupon.getSendTime().getTime()){ |
| | | throw new ServiceException("不能修改优惠券发放时间"); |
| | | } |
| | | if(coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && mgtCouponEditDto.getSendTimeType() == 2 && System.currentTimeMillis() >= coupon.getSendTime().getTime() && coupon.getUseScope() == 1 && !coupon.getUseScope().equals(mgtCouponEditDto.getUseScope())){ |
| | | throw new ServiceException("不能修改优惠券适用范围"); |
| | | } |
| | | |
| | | if(coupon.getUseScope() == 2 && coupon.getUseScope().equals(mgtCouponEditDto.getUseScope())){ |
| | | List<String> relGoodsIdList = mgtCouponEditDto.getRelGoodsIdList(); |
| | | List<CouponRelGoods> list = couponRelGoodsService.list(new QueryWrapper<CouponRelGoods>().eq("coupon_id", coupon.getCouponId()).eq("del_flag", 0)); |
| | | for (CouponRelGoods couponRelGoods : list) { |
| | | if(!relGoodsIdList.contains(couponRelGoods.getGoodsId())){ |
| | | throw new ServiceException("不能删除优惠券适用商品"); |
| | | } |
| | | } |
| | | } |
| | | if(coupon.getSendLimitFlag() == 0 && mgtCouponEditDto.getSendLimitFlag() != 0){ |
| | | throw new ServiceException("不能修改优惠券发放数量限制"); |
| | | } |
| | | if(coupon.getSendLimitFlag() == 1 && mgtCouponEditDto.getSendLimitFlag() == 1 && coupon.getSendLimitNumber().compareTo(mgtCouponEditDto.getSendLimitNumber()) > 0){ |
| | | throw new ServiceException("不能修改优惠券发放数量限制"); |
| | | } |
| | | if(coupon.getLimitNumber().compareTo(mgtCouponEditDto.getLimitNumber()) > 0){ |
| | | throw new ServiceException("只能增加优惠券领取数量"); |
| | | } |
| | | List<CouponRelUser> list = couponRelUserService.list(new QueryWrapper<CouponRelUser>().eq("coupon_id", coupon.getCouponId()).eq("del_flag", 0)); |
| | | List<Long> relUserIdList = mgtCouponEditDto.getRelUserIdList(); |
| | | for (CouponRelUser couponRelUser : list) { |
| | | if(!relUserIdList.contains(couponRelUser.getUserId())){ |
| | | throw new ServiceException("只能增加优惠发放对象"); |
| | | } |
| | | } |
| | | if(relUserIdList.size() != list.size() && coupon.getSendType() == 2 && coupon.getSendTimeType() == 1){ |
| | | throw new ServiceException("只能修改优惠发放对象"); |
| | | } |
| | | if(relUserIdList.size() != list.size() && coupon.getSendType() == 2 && coupon.getSendTimeType() == 2 && System.currentTimeMillis() <= coupon.getSendTime().getTime()){ |
| | | throw new ServiceException("只能修改优惠发放对象"); |
| | | } |
| | | |
| | | couponRelUserService.deleteCouponRelByCouponId(coupon.getCouponId()); |
| | | couponRelGoodsService.deleteCouponRelByCouponId(coupon.getCouponId()); |
| | | |
| | | }else{ |
| | | coupon = new Coupon(); |
| | | String couponId = IdUtils.simpleUUID(); |
| | |
| | | coupon.setCreateUserId(mgtCouponEditDto.getUserId()); |
| | | coupon.setCouponFrom(1); |
| | | coupon.setAuditStatus(2); |
| | | coupon.setLimitNumber(1); |
| | | coupon.setSendFlag(0); |
| | | //创建优惠券统计 |
| | | couponTotal = new CouponTotal(); |
| | | couponTotal.setCouponId(couponId); |
| | |
| | | coupon.setCouponType(mgtCouponEditDto.getCouponType()); |
| | | coupon.setCouponName(mgtCouponEditDto.getCouponName()); |
| | | coupon.setSendType(mgtCouponEditDto.getSendType()); |
| | | coupon.setSendTarget(mgtCouponEditDto.getSendTarget()); |
| | | coupon.setSendTimeType(mgtCouponEditDto.getSendTimeType()); |
| | | coupon.setSendTime(mgtCouponEditDto.getSendTime()); |
| | | coupon.setMoneyThreshold(mgtCouponEditDto.getMoneyThreshold()); |
| | |
| | | coupon.setRelationType(mgtCouponEditDto.getRelationType()); |
| | | coupon.setRelationActivityType(mgtCouponEditDto.getRelationActivityType()); |
| | | coupon.setRelationActivityId(mgtCouponEditDto.getRelationActivityId()); |
| | | coupon.setPropagandaPoster(mgtCouponEditDto.getPropagandaPoster()); |
| | | //指定发放优惠券不做发放数限制 |
| | | if(coupon.getSendType()==2){ |
| | | mgtCouponEditDto.setSendLimitFlag(0); |
| | | } |
| | | coupon.setSendLimitFlag(mgtCouponEditDto.getSendLimitFlag()); |
| | | if(mgtCouponEditDto.getSendLimitFlag()==1){ |
| | | coupon.setSendLimitNumber(mgtCouponEditDto.getSendLimitNumber()); |
| | | }else{ |
| | | coupon.setSendLimitNumber(0); |
| | | } |
| | | coupon.setLimitNumber(mgtCouponEditDto.getLimitNumber()); |
| | | //判断是否指定商品 |
| | | if(coupon.getUseScope()==2&&!mgtCouponEditDto.getRelGoodsIdList().isEmpty()){ |
| | | List<String> relGoodsIdList = mgtCouponEditDto.getRelGoodsIdList(); |
| | |
| | | coupon.setRelGoodsIds(relGoodsIds); |
| | | } |
| | | //判断是否指定用户 |
| | | List<Long> relUserIdList = null; |
| | | if(coupon.getSendType()==5&&coupon.getRelationType()==1&&!mgtCouponEditDto.getRelUserIdList().isEmpty()){ |
| | | List<Long> relUserIdList; |
| | | if(coupon.getSendTarget()==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()); |
| | | List<CouponRelUser> couponRelUserList = new ArrayList<>(); |
| | | CouponRelUser couponRelUser; |
| | | StringJoiner userIdSj = new StringJoiner(","); |
| | | for(Long userId : relUserIdList){ |
| | | couponRelUser = new CouponRelUser(); |
| | | couponRelUser.setDelFlag(0); |
| | | couponRelUser.setCouponId(coupon.getCouponId()); |
| | | couponRelUser.setUserId(userId); |
| | | couponRelUserList.add(couponRelUser); |
| | | userIdSj.add(userId.toString()); |
| | | } |
| | | couponRelUserService.saveBatch(couponRelUserList); |
| | | coupon.setRelUserIds(userIdSj.toString()); |
| | | } else { |
| | | relUserIdList = null; |
| | | } |
| | | this.saveOrUpdate(coupon); |
| | | //处理优惠券发放 |
| | | if(coupon.getSendTimeType()==1){ |
| | | sendCoupon(coupon,relUserIdList); |
| | | if(coupon.getSendFlag() == 0 && coupon.getSendType()==2&&coupon.getSendTimeType()==1){ |
| | | CompletableFuture.runAsync(()->sendCoupon(coupon,relUserIdList)); |
| | | coupon.setSendFlag(1); |
| | | this.saveOrUpdate(coupon); |
| | | }else{ |
| | | this.saveOrUpdate(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(); |
| | | Integer sendTarget = coupon.getSendTarget(); |
| | | List<Long> userIdList = new ArrayList<>(); |
| | | if(sendType >= 2 && sendType <= 4){ |
| | | userIdList = memberService.listIdBySendType(sendType); |
| | | }else if(sendType == 5){ |
| | | Long shopId = null; |
| | | if(coupon.getCouponFrom()==2 && sendTarget==3){ |
| | | shopId = coupon.getShopId(); |
| | | } |
| | | if(sendTarget >= 2 && sendTarget <= 4){ |
| | | userIdList = memberService.listIdBySendType(sendTarget,shopId); |
| | | }else if(sendTarget == 5){ |
| | | //关联类型1.用户管理筛选2.活动管理筛选 |
| | | if(coupon.getRelationType()==2){ |
| | | Integer relationActivityType = coupon.getRelationActivityType(); |
| | |
| | | userIdList = relUserIdList; |
| | | } |
| | | } |
| | | if(!relUserIdList.isEmpty()){ |
| | | //商户发送全部,则发送没有绑定的会员及绑定了当前商户端会员 |
| | | if(coupon.getCouponFrom() == 2 && sendTarget == 2){ |
| | | shopId = coupon.getShopId(); |
| | | userIdList = memberService.listIdBySendType2(shopId); |
| | | } |
| | | |
| | | |
| | | if(userIdList!=null&&!userIdList.isEmpty()){ |
| | | List<MemberCoupon> memberCouponList = new ArrayList<>(); |
| | | MemberCoupon memberCoupon; |
| | | Integer sendTotal = 0; |
| | | String memberCouponId; |
| | | Integer sendPerson = 0; |
| | | Integer sendUserTotal; |
| | | for(Long userId : userIdList){ |
| | | memberCouponId = IdUtils.simpleUUID(); |
| | | if(coupon.getCouponFrom()==2){ |
| | | for(int i=0;i<coupon.getLimitNumber();i++){ |
| | | memberCoupon = new MemberCoupon(); |
| | | memberCoupon.setDelFlag(0); |
| | | memberCoupon.setCouponId(coupon.getCouponId()); |
| | | memberCoupon.setUserId(userId); |
| | | memberCoupon.setShopId(coupon.getShopId()); |
| | | memberCoupon.setCouponType(coupon.getCouponType()); |
| | | if(coupon.getCouponType()==1){ |
| | | memberCoupon.setMoneyThreshold(coupon.getMoneyThreshold()); |
| | | memberCoupon.setDiscountMoney(coupon.getDiscountMoney()); |
| | | }else if(coupon.getCouponType()==2){ |
| | | memberCoupon.setDiscountPercent(coupon.getDiscountPercent()); |
| | | }else if(coupon.getCouponType()==3){ |
| | | memberCoupon.setDiscountMoney(coupon.getDiscountMoney()); |
| | | }else{ |
| | | memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds()); |
| | | } |
| | | memberCoupon.setCouponStatus(coupon.getCouponStatus()); |
| | | memberCoupon.setCouponName(coupon.getCouponName()); |
| | | memberCoupon.setSendType(coupon.getSendType()); |
| | | memberCoupon.setSendTarget(coupon.getSendTarget()); |
| | | memberCoupon.setSendTimeType(coupon.getSendTimeType()); |
| | | memberCoupon.setSendTime(coupon.getSendTime()); |
| | | memberCoupon.setUseScope(coupon.getUseScope()); |
| | | if(memberCoupon.getUseScope()==2){ |
| | | memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds()); |
| | | } |
| | | memberCoupon.setValidTimeType(coupon.getValidTimeType()); |
| | | memberCoupon.setValidStartTime(coupon.getValidStartTime()); |
| | | memberCoupon.setValidEndTime(coupon.getValidEndTime()); |
| | | memberCoupon.setValidDay(coupon.getValidDay()); |
| | | memberCoupon.setCouponFrom(coupon.getCouponFrom()); |
| | | memberCoupon.setReceiveTime(nowTime); |
| | | //有效期处理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; |
| | | if(coupon.getSendType()==1){ |
| | | sendUserTotal = memberCouponService.totalMemberCouponByUserAndCoupon(userId,coupon.getCouponId()); |
| | | if(sendUserTotal!=null&&sendUserTotal>0){ |
| | | }else{ |
| | | sendPerson = sendPerson + 1; |
| | | } |
| | | } |
| | | memberCouponRecordService.updateMemberCouponRecord(coupon,userId,1); |
| | | } |
| | | }else{ |
| | | for (Integer i = 0; i < coupon.getLimitNumber(); i++) { |
| | | memberCoupon = new MemberCoupon(); |
| | | memberCoupon.setDelFlag(0); |
| | | memberCoupon.setCouponId(coupon.getCouponId()); |
| | | memberCoupon.setUserId(userId); |
| | | //memberCoupon.setShopId(coupon.getShopId()); |
| | | memberCoupon.setCouponType(coupon.getCouponType()); |
| | | if(coupon.getCouponType()==1){ |
| | | memberCoupon.setMoneyThreshold(coupon.getMoneyThreshold()); |
| | | memberCoupon.setDiscountMoney(coupon.getDiscountMoney()); |
| | | }else if(coupon.getCouponType()==2){ |
| | | memberCoupon.setDiscountPercent(coupon.getDiscountPercent()); |
| | | }else if(coupon.getCouponType()==3){ |
| | | memberCoupon.setDiscountMoney(coupon.getDiscountMoney()); |
| | | }else{ |
| | | memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds()); |
| | | } |
| | | memberCoupon.setCouponStatus(coupon.getCouponStatus()); |
| | | memberCoupon.setCouponName(coupon.getCouponName()); |
| | | memberCoupon.setSendType(coupon.getSendType()); |
| | | memberCoupon.setSendTarget(coupon.getSendTarget()); |
| | | memberCoupon.setSendTimeType(coupon.getSendTimeType()); |
| | | memberCoupon.setSendTime(coupon.getSendTime()); |
| | | memberCoupon.setUseScope(coupon.getUseScope()); |
| | | if(memberCoupon.getUseScope()==2){ |
| | | memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds()); |
| | | } |
| | | memberCoupon.setValidTimeType(coupon.getValidTimeType()); |
| | | memberCoupon.setValidStartTime(coupon.getValidStartTime()); |
| | | memberCoupon.setValidEndTime(coupon.getValidEndTime()); |
| | | memberCoupon.setValidDay(coupon.getValidDay()); |
| | | memberCoupon.setCouponFrom(coupon.getCouponFrom()); |
| | | memberCoupon.setReceiveTime(nowTime); |
| | | //有效期处理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; |
| | | if(coupon.getSendType()==1){ |
| | | sendUserTotal = memberCouponService.totalMemberCouponByUserAndCoupon(userId,coupon.getCouponId()); |
| | | if(sendUserTotal!=null&&sendUserTotal>0){ |
| | | }else{ |
| | | sendPerson = sendPerson + 1; |
| | | } |
| | | } |
| | | memberCouponRecordService.updateMemberCouponRecord(coupon,userId,1); |
| | | } |
| | | } |
| | | } |
| | | memberCouponService.saveBatch(memberCouponList); |
| | | //处理优惠券统计 |
| | | if(sendTotal>0){ |
| | | couponMapper.updateCouponTotal(coupon.getCouponId(),sendTotal,sendPerson); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | private void sendCouponNow(Coupon coupon, List<Long> relUserIdList){ |
| | | //1.手动领取2.全部用户3.会员用户4非会员用户5自定义 |
| | | Date nowTime = new Date(); |
| | | Integer sendTarget = coupon.getSendTarget(); |
| | | List<Long> userIdList = new ArrayList<>(); |
| | | Long shopId = null; |
| | | if(coupon.getCouponFrom()==2 && sendTarget==3){ |
| | | shopId = coupon.getShopId(); |
| | | } |
| | | if(sendTarget >= 2 && sendTarget <= 4){ |
| | | userIdList = memberService.listIdBySendType(sendTarget,shopId); |
| | | }else if(sendTarget == 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(coupon.getCouponFrom() == 2 && sendTarget == 2){ |
| | | shopId = coupon.getShopId(); |
| | | userIdList = memberService.listIdBySendType2(shopId); |
| | | } |
| | | |
| | | if(relUserIdList!=null&&!relUserIdList.isEmpty()){ |
| | | List<MemberCoupon> memberCouponList = new ArrayList<>(); |
| | | MemberCoupon memberCoupon; |
| | | Integer sendTotal = 0; |
| | | Integer sendPerson = 0; |
| | | Integer sendUserTotal; |
| | | for(Long userId : userIdList){ |
| | | memberCoupon = new MemberCoupon(); |
| | | memberCoupon.setId(memberCouponId); |
| | | memberCoupon.setDelFlag(0); |
| | | memberCoupon.setCouponId(coupon.getCouponId()); |
| | | memberCoupon.setUserId(userId); |
| | | if(coupon.getCouponFrom()==2){ |
| | | memberCoupon.setShopId(coupon.getShopId()); |
| | | } |
| | | memberCoupon.setCouponType(coupon.getCouponType()); |
| | | memberCoupon.setCouponStatus(coupon.getCouponStatus()); |
| | | memberCoupon.setCouponName(coupon.getCouponName()); |
| | | memberCoupon.setSendType(coupon.getSendType()); |
| | | if(coupon.getCouponType()==1){ |
| | | memberCoupon.setMoneyThreshold(coupon.getMoneyThreshold()); |
| | | memberCoupon.setDiscountMoney(coupon.getDiscountMoney()); |
| | | }else if(coupon.getCouponType()==2){ |
| | | memberCoupon.setDiscountPercent(coupon.getDiscountPercent()); |
| | | }else if(coupon.getCouponType()==3){ |
| | | memberCoupon.setDiscountMoney(coupon.getDiscountMoney()); |
| | | }else{ |
| | | memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds()); |
| | | } |
| | | memberCoupon.setSendTarget(coupon.getSendTarget()); |
| | | memberCoupon.setSendTimeType(coupon.getSendTimeType()); |
| | | memberCoupon.setSendTime(coupon.getSendTime()); |
| | | memberCoupon.setMoneyThreshold(coupon.getMoneyThreshold()); |
| | | memberCoupon.setDiscountMoney(coupon.getDiscountMoney()); |
| | | memberCoupon.setDiscountPercent(coupon.getDiscountPercent()); |
| | | memberCoupon.setUseScope(coupon.getUseScope()); |
| | | if(memberCoupon.getUseScope()==2){ |
| | | memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds()); |
| | | } |
| | | memberCoupon.setValidTimeType(coupon.getValidTimeType()); |
| | | memberCoupon.setValidStartTime(coupon.getValidStartTime()); |
| | | memberCoupon.setValidEndTime(coupon.getValidEndTime()); |
| | | memberCoupon.setValidDay(coupon.getValidDay()); |
| | | memberCoupon.setCouponFrom(coupon.getCouponFrom()); |
| | | memberCoupon.setReceiveTime(nowTime); |
| | | memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds()); |
| | | //有效期处理1.时间段2.领取之日起 |
| | | if(coupon.getValidTimeType()==1){ |
| | | memberCoupon.setDeadlineTime(coupon.getValidEndTime()); |
| | |
| | | } |
| | | memberCouponList.add(memberCoupon); |
| | | sendTotal = sendTotal + 1; |
| | | if(coupon.getSendType()==1){ |
| | | sendUserTotal = memberCouponService.totalMemberCouponByUserAndCoupon(userId,coupon.getCouponId()); |
| | | if(sendUserTotal!=null&&sendUserTotal>0){ |
| | | }else{ |
| | | sendPerson = sendPerson + 1; |
| | | } |
| | | } |
| | | memberCouponRecordService.updateMemberCouponRecord(coupon,userId,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); |
| | | couponMapper.updateCouponTotal(coupon.getCouponId(),sendTotal,sendPerson); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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); |
| | | } |
| | | // if(couponTotal.getSendCount()!=null&&couponTotal.getSendCount()>0){ |
| | | // throw new ServiceException(AppErrorConstant.COUPON_SENT_DEL); |
| | | // } |
| | | coupon.setCouponStatus(-1); |
| | | coupon.setDelFlag(1); |
| | | coupon.setUpdateUserId(mgtBaseGetDto.getUserId()); |
| | |
| | | */ |
| | | @Override |
| | | public void timingSendCoupon(){ |
| | | //获取1小时内需要发送的优惠券 |
| | | 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()); |
| | | queryWrapper.eq(Coupon::getSendFlag,0); |
| | | Date checkTime = DateUtils.addMinutes(new Date(),61); |
| | | queryWrapper.le(Coupon::getSendTime, checkTime); |
| | | 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<>(); |
| | | } |
| | | for(Coupon coupon : couponList) { |
| | | String couponId = coupon.getCouponId(); |
| | | Date sendTime = coupon.getSendTime(); |
| | | long currentTimeMillis = System.currentTimeMillis(); |
| | | long timeDifference = currentTimeMillis - sendTime.getTime(); |
| | | DelayTask delayTask = remoteConfigService.getDelayTask(DelayTaskEnum.COUPON_SEND_DELAY_TASK.getCode()+"-"+couponId).getData(); |
| | | if(delayTask==null){ |
| | | //创建延时任务控制优惠券定时发放 |
| | | redisService.setCacheObject(DelayTaskEnum.COUPON_SEND_DELAY_TASK.getCode()+"-"+couponId,sendTime,timeDifference, TimeUnit.MILLISECONDS); |
| | | delayTask = new DelayTask(); |
| | | delayTask.setDelFlag(0); |
| | | delayTask.setCreateTime(new Date()); |
| | | delayTask.setEndTime(sendTime); |
| | | delayTask.setRedisKey(DelayTaskEnum.COUPON_SEND_DELAY_TASK.getCode()+"-"+couponId); |
| | | remoteConfigService.addDelayTask(delayTask); |
| | | } |
| | | //发送优惠券 |
| | | sendCoupon(coupon, userIdList); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 定时发送优惠券 |
| | | * @author jqs |
| | | * @date 2023/7/12 12:01 |
| | | * @param couponId |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void autoTimeSendCoupon(String couponId){ |
| | | List<CouponRelUser> couponRelUserList; |
| | | List<Long> userIdList = new ArrayList<>(); |
| | | Coupon coupon = this.getById(couponId); |
| | | if(coupon.getSendTarget()==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<>(); |
| | | } |
| | | } |
| | | //发送优惠券 |
| | | sendCouponNow(coupon, userIdList); |
| | | } |
| | | |
| | | /** |
| | |
| | | Date validEndTime; |
| | | Integer validDay; |
| | | String validTime = ""; |
| | | HashSet<Long> shopIdSet = new HashSet<>(); |
| | | for(MgtCouponAuditPageVo mgtCouponAuditPageVo : mgtCouponAuditPageVoList){ |
| | | //处理有效期 |
| | | validTimeType = mgtCouponAuditPageVo.getValidTimeType(); |
| | | if(validTimeType==1){ |
| | | validStartTime = mgtCouponAuditPageVo.getValidStartTime(); |
| | | validEndTime = mgtCouponAuditPageVo.getValidEndTime(); |
| | | validTime = DateUtils.dateTime(validStartTime) + '-' + DateUtils.dateTime(validEndTime); |
| | | validTime = DateUtils.parseDateToStr("yyyy-MM-dd",validStartTime) + '-' + DateUtils.parseDateToStr("yyyy-MM-dd",validEndTime); |
| | | }else if(validTimeType==2){ |
| | | validDay = mgtCouponAuditPageVo.getValidDay(); |
| | | validTime = "领取之日起" + validDay.toString() + "天"; |
| | | } |
| | | mgtCouponAuditPageVo.setValidTime(validTime); |
| | | if(mgtCouponAuditPageVo.getShopId()!=null){ |
| | | shopIdSet.add(mgtCouponAuditPageVo.getShopId()); |
| | | } |
| | | } |
| | | String shopJoinedString = String.join(",", shopIdSet.stream().map(Object::toString).collect(Collectors.toList())); |
| | | MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); |
| | | mgtBaseBathDto.setIds(shopJoinedString); |
| | | List<MgtSimpleShopVo> simpleShopVoList = remoteShopService.listShopSimpleVoByIds(mgtBaseBathDto).getData(); |
| | | Map<Long, MgtSimpleShopVo> shopMap = simpleShopVoList.stream() |
| | | .collect(Collectors.toMap(MgtSimpleShopVo::getShopId, Function.identity())); |
| | | for(MgtCouponAuditPageVo mgtCouponAuditPageVo : mgtCouponAuditPageVoList){ |
| | | if(mgtCouponAuditPageVo.getShopId()!=null){ |
| | | MgtSimpleShopVo mgtSimpleShopVo = shopMap.get(mgtCouponAuditPageVo.getShopId()); |
| | | if(null != mgtSimpleShopVo){ |
| | | mgtCouponAuditPageVo.setShopName(mgtSimpleShopVo.getShopName()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | String useLimit = ""; |
| | | for(MgtCouponAuditPageVo mgtCouponAuditPageVo : mgtCouponAuditPageVoList){ |
| | | useLimit = null; |
| | | //处理使用限制 |
| | | String couponType = mgtCouponAuditPageVo.getCouponType(); |
| | | if(couponType.equals("满减")){ |
| | | BigDecimal moneyThreshold = mgtCouponAuditPageVo.getMoneyThreshold(); |
| | | BigDecimal discountMoney = mgtCouponAuditPageVo.getDiscountMoney(); |
| | | useLimit = "满" + moneyThreshold.toString() + "减" + discountMoney.toString() + "元"; |
| | | } |
| | | if(couponType.equals("折扣")){ |
| | | BigDecimal discountPercent = mgtCouponAuditPageVo.getDiscountPercent(); |
| | | useLimit = discountPercent.toString() + "折"; |
| | | } |
| | | if(couponType.equals("代金")){ |
| | | BigDecimal discountMoney = mgtCouponAuditPageVo.getDiscountMoney(); |
| | | useLimit = discountMoney.toString(); |
| | | } |
| | | mgtCouponAuditPageVo.setUseLimit(useLimit); |
| | | } |
| | | return mgtCouponAuditPageVoList; |
| | | } |
| | |
| | | mgtCouponGoodsListVo.setGoodsId(goods.getGoodsId()); |
| | | mgtCouponGoodsListVo.setGoodsName(goods.getGoodsName()); |
| | | mgtCouponGoodsListVo.setGoodsNo(goods.getGoodsNo()); |
| | | mgtCouponGoodsListVo.setGoodsType(goods.getGoodsType()); |
| | | //商品类型1周期2服务3体验4单品 |
| | | switch (goods.getGoodsType()){ |
| | | case 1: |
| | | mgtCouponGoodsListVo.setGoodsType("周期"); |
| | | mgtCouponGoodsListVo.setGoodsTypeName("周期"); |
| | | break; |
| | | case 2: |
| | | mgtCouponGoodsListVo.setGoodsType("服务"); |
| | | mgtCouponGoodsListVo.setGoodsTypeName("服务"); |
| | | break; |
| | | case 3: |
| | | mgtCouponGoodsListVo.setGoodsType("体验"); |
| | | mgtCouponGoodsListVo.setGoodsTypeName("体验"); |
| | | break; |
| | | case 4: |
| | | mgtCouponGoodsListVo.setGoodsType("单品"); |
| | | mgtCouponGoodsListVo.setGoodsTypeName("单品"); |
| | | break; |
| | | default: |
| | | break; |
| | |
| | | } |
| | | } |
| | | //判断优惠券是否指定发放用户 |
| | | if(coupon.getSendType()==5&&coupon.getRelationType()==1){ |
| | | if(coupon.getSendTarget()==5&&coupon.getRelationType()==1){ |
| | | //获取优惠券发放用户 |
| | | List<MgtCouponMemberListVo> relUserList = couponRelUserService.listCouponMemberVo(coupon.getCouponId()); |
| | | mgtCouponAuditGetVo.setRelUserList(relUserList); |
| | |
| | | public void auditMgtCoupon(MgtCouponAuditDto mgtCouponAuditDto){ |
| | | Coupon coupon = this.getById(mgtCouponAuditDto.getCouponId()); |
| | | //判断优惠券是否审核 |
| | | if(coupon.getCouponStatus()!=1){ |
| | | if(coupon.getAuditStatus()!=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){ |
| | | if(coupon.getAuditStatus()==2&&coupon.getSendType()==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()){ |
| | |
| | | } |
| | | //发放优惠券 |
| | | sendCoupon(coupon, userIdList); |
| | | coupon.setSendFlag(1); |
| | | } |
| | | this.saveOrUpdate(coupon); |
| | | } |
| | | |
| | | /** |
| | | * @description 平台获取优惠券列表 |
| | | * @author jqs |
| | | * @date 2023/6/30 16:53 |
| | | * @param page |
| | | * @param merPageDto |
| | | * @return List<MerCouponPageVo> |
| | | */ |
| | | @Override |
| | | public List<MerCouponPageVo> pagePlatformMerCoupon(Page page, MerPageDto merPageDto){ |
| | | List<MerCouponPageVo> couponPageVoList = couponMapper.pagePlatformMerCoupon(page, merPageDto); |
| | | //处理使用限制和有效期 |
| | | if(couponPageVoList!=null&&!couponPageVoList.isEmpty()){ |
| | | Integer couponType; |
| | | Integer validTimeType; |
| | | Date validStartTime; |
| | | Date validEndTime; |
| | | Integer validDay; |
| | | String validTime = ""; |
| | | BigDecimal moneyThreshold; |
| | | BigDecimal discountMoney; |
| | | BigDecimal discountPercent; |
| | | String useLimit = ""; |
| | | for(MerCouponPageVo merCouponPageVo : couponPageVoList){ |
| | | //处理使用限制 |
| | | couponType = merCouponPageVo.getCouponType(); |
| | | switch (couponType){ |
| | | case 1: |
| | | moneyThreshold = merCouponPageVo.getMoneyThreshold(); |
| | | discountMoney = merCouponPageVo.getDiscountMoney(); |
| | | useLimit = "满" + moneyThreshold.toString() + "减" + discountMoney.toString() + "元"; |
| | | break; |
| | | case 2: |
| | | break; |
| | | case 3: |
| | | break; |
| | | case 4: |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | merCouponPageVo.setUseLimit(useLimit); |
| | | //处理有效期 |
| | | validTimeType = merCouponPageVo.getValidTimeType(); |
| | | if(validTimeType==1){ |
| | | validStartTime = merCouponPageVo.getValidStartTime(); |
| | | validEndTime = merCouponPageVo.getValidEndTime(); |
| | | validTime = DateUtils.parseDateToStr("yyyy.MM.dd",validStartTime) + '-' + DateUtils.parseDateToStr("yyyy.MM.dd",validEndTime); |
| | | }else if(validTimeType==2){ |
| | | validDay = merCouponPageVo.getValidDay(); |
| | | validTime = "领取之日起" + validDay.toString() + "天"; |
| | | } |
| | | merCouponPageVo.setValidTime(validTime); |
| | | merCouponPageVo.setCouponCode("https://hongruitang.oss-cn-beijing.aliyuncs.com/2023/8/3/couponCode.jpg"); |
| | | } |
| | | } |
| | | return couponPageVoList; |
| | | } |
| | | |
| | | /** |
| | | * @description 获取商户优惠券列表 |
| | | * @author jqs |
| | | * @date 2023/6/30 16:53 |
| | | * @param page |
| | | * @param merPageDto |
| | | * @return List<MerCouponPageVo> |
| | | */ |
| | | @Override |
| | | public List<MerCouponPageVo> pageShopMerCoupon(Page page, MerCouponPageDto merPageDto){ |
| | | List<MerCouponPageVo> couponPageVoList = couponMapper.pageShopMerCoupon(page, merPageDto); |
| | | //处理使用限制和有效期 |
| | | if(couponPageVoList!=null&&!couponPageVoList.isEmpty()){ |
| | | Integer couponType; |
| | | Integer validTimeType; |
| | | Date validStartTime; |
| | | Date validEndTime; |
| | | Integer validDay; |
| | | String validTime = ""; |
| | | BigDecimal moneyThreshold; |
| | | BigDecimal discountMoney; |
| | | BigDecimal discountPercent; |
| | | String useLimit = ""; |
| | | for(MerCouponPageVo merCouponPageVo : couponPageVoList){ |
| | | //处理使用限制 |
| | | couponType = merCouponPageVo.getCouponType(); |
| | | switch (couponType){ |
| | | case 1: |
| | | moneyThreshold = merCouponPageVo.getMoneyThreshold(); |
| | | discountMoney = merCouponPageVo.getDiscountMoney(); |
| | | useLimit = "满" + moneyThreshold.toString() + "减" + discountMoney.toString() + "元"; |
| | | break; |
| | | case 2: |
| | | break; |
| | | case 3: |
| | | break; |
| | | case 4: |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | merCouponPageVo.setUseLimit(useLimit); |
| | | //处理有效期 |
| | | validTimeType = merCouponPageVo.getValidTimeType(); |
| | | if(validTimeType==1){ |
| | | validStartTime = merCouponPageVo.getValidStartTime(); |
| | | validEndTime = merCouponPageVo.getValidEndTime(); |
| | | validTime = DateUtils.parseDateToStr("yyyy.MM.dd",validStartTime) + '-' + DateUtils.parseDateToStr("yyyy.MM.dd",validEndTime); |
| | | }else if(validTimeType==2){ |
| | | validDay = merCouponPageVo.getValidDay(); |
| | | validTime = "领取之日起" + validDay.toString() + "天"; |
| | | } |
| | | merCouponPageVo.setValidTime(validTime); |
| | | } |
| | | } |
| | | return couponPageVoList; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @description 商户编辑优惠券 |
| | | * @author jqs |
| | | * @date 2023/7/3 9:21 |
| | | * @param merCouponEditDto |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void editMerCoupon(MerCouponEditDto merCouponEditDto){ |
| | | //编辑优惠券 |
| | | Coupon coupon; |
| | | CouponTotal couponTotal; |
| | | if(StringUtils.isNotBlank(merCouponEditDto.getCouponId())){ |
| | | coupon = this.getById(merCouponEditDto.getCouponId()); |
| | | if(coupon.getAuditStatus()!=3){ |
| | | throw new ServiceException(AppErrorConstant.COUPON_AUDIT_EDIT); |
| | | } |
| | | couponRelUserService.deleteCouponRelByCouponId(coupon.getCouponId()); |
| | | couponRelGoodsService.deleteCouponRelByCouponId(coupon.getCouponId()); |
| | | coupon.setCouponStatus(1); |
| | | }else{ |
| | | //初始化新优惠券 |
| | | coupon = new Coupon(); |
| | | String couponId = IdUtils.simpleUUID(); |
| | | coupon.setCouponId(couponId); |
| | | coupon.setDelFlag(0); |
| | | coupon.setShopId(merCouponEditDto.getShopId()); |
| | | coupon.setCouponStatus(1); |
| | | coupon.setCreateTime(new Date()); |
| | | coupon.setCreateUserId(merCouponEditDto.getUserId()); |
| | | coupon.setCouponFrom(2); |
| | | coupon.setSendFlag(0); |
| | | coupon.setLimitNumber(merCouponEditDto.getLimitNumber()); |
| | | //创建优惠券统计 |
| | | couponTotal = new CouponTotal(); |
| | | couponTotal.setCouponId(couponId); |
| | | couponTotal.setSendCount(0); |
| | | couponTotal.setSendUserCount(0); |
| | | couponTotalService.save(couponTotal); |
| | | } |
| | | //优惠券赋值 |
| | | coupon.setAuditStatus(1); |
| | | coupon.setCouponType(merCouponEditDto.getCouponType()); |
| | | coupon.setCouponName(merCouponEditDto.getCouponName()); |
| | | coupon.setSendType(merCouponEditDto.getSendType()); |
| | | coupon.setSendTarget(merCouponEditDto.getSendTarget()); |
| | | //商户端默认立即发放 |
| | | coupon.setSendTimeType(1); |
| | | coupon.setSendTime(merCouponEditDto.getSendTime()); |
| | | coupon.setMoneyThreshold(merCouponEditDto.getMoneyThreshold()); |
| | | coupon.setDiscountMoney(merCouponEditDto.getDiscountMoney()); |
| | | coupon.setDiscountPercent(merCouponEditDto.getDiscountPercent()); |
| | | coupon.setUseScope(merCouponEditDto.getUseScope()); |
| | | coupon.setValidTimeType(merCouponEditDto.getValidTimeType()); |
| | | coupon.setValidStartTime(merCouponEditDto.getValidStartTime()); |
| | | coupon.setValidEndTime(merCouponEditDto.getValidEndTime()); |
| | | coupon.setLimitNumber(merCouponEditDto.getLimitNumber()); |
| | | coupon.setValidDay(merCouponEditDto.getValidDay()); |
| | | coupon.setUpdateTime(new Date()); |
| | | coupon.setUpdateUserId(merCouponEditDto.getUserId()); |
| | | coupon.setRelationType(1); |
| | | coupon.setPropagandaPoster(merCouponEditDto.getPropagandaPoster()); |
| | | //指定发放优惠券不做发放数限制 |
| | | if(coupon.getSendType()==2){ |
| | | merCouponEditDto.setSendLimitFlag(0); |
| | | } |
| | | coupon.setSendLimitFlag(merCouponEditDto.getSendLimitFlag()); |
| | | if(merCouponEditDto.getSendLimitFlag()==1){ |
| | | coupon.setSendLimitNumber(merCouponEditDto.getSendLimitNumber()); |
| | | }else{ |
| | | coupon.setSendLimitNumber(0); |
| | | } |
| | | //判断是否指定商品 |
| | | if(coupon.getUseScope()==2&&!merCouponEditDto.getRelGoodsIdList().isEmpty()){ |
| | | List<String> relGoodsIdList = merCouponEditDto.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.getSendTarget()==5&&coupon.getRelationType()==1&&!merCouponEditDto.getRelUserIdList().isEmpty()){ |
| | | relUserIdList = merCouponEditDto.getRelUserIdList(); |
| | | List<CouponRelUser> couponRelUserList = new ArrayList<>(); |
| | | CouponRelUser couponRelUser; |
| | | StringJoiner userIdSj = new StringJoiner(","); |
| | | for(Long userId : relUserIdList){ |
| | | couponRelUser = new CouponRelUser(); |
| | | couponRelUser.setDelFlag(0); |
| | | couponRelUser.setCouponId(coupon.getCouponId()); |
| | | couponRelUser.setUserId(userId); |
| | | couponRelUserList.add(couponRelUser); |
| | | userIdSj.add(userId.toString()); |
| | | } |
| | | couponRelUserService.saveBatch(couponRelUserList); |
| | | coupon.setRelUserIds(userIdSj.toString()); |
| | | } |
| | | this.saveOrUpdate(coupon); |
| | | } |
| | | |
| | | /** |
| | | * @description 商户删除优惠券 |
| | | * @author jqs |
| | | * @date 2023/7/3 15:04 |
| | | * @param merBaseGetDto |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void deleteMerCoupon(MerBaseGetDto merBaseGetDto){ |
| | | Coupon coupon = this.getById(merBaseGetDto.getId()); |
| | | coupon.setCouponStatus(-1); |
| | | coupon.setDelFlag(1); |
| | | coupon.setUpdateUserId(merBaseGetDto.getUserId()); |
| | | coupon.setUpdateTime(new Date()); |
| | | this.saveOrUpdate(coupon); |
| | | } |
| | | |
| | | /** |
| | | * @description 发送用户优惠券礼物 |
| | | * @author jqs |
| | | * @date 2023/7/7 19:54 |
| | | * @param giftSendDtoList |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void sendCouponGift(List<BirthdayGiftSendDto> giftSendDtoList){ |
| | | // 获取第一个用户和商店的ID |
| | | Long userId = giftSendDtoList.get(0).getUserId(); |
| | | Long shopId = giftSendDtoList.get(0).getShopId(); |
| | | |
| | | // 初始化变量 |
| | | String couponId; |
| | | Coupon coupon; |
| | | List<MemberCoupon> memberCouponList = new ArrayList<>(); |
| | | MemberCoupon memberCoupon; |
| | | |
| | | // 遍历生日礼物发送DTO列表 |
| | | for(BirthdayGiftSendDto birthdayGiftSendDto : giftSendDtoList){ |
| | | // 获取优惠券ID并查询优惠券信息 |
| | | couponId = birthdayGiftSendDto.getCouponId(); |
| | | coupon = this.getById(couponId); |
| | | // 判断优惠券是否存在或已失效 |
| | | if(coupon==null||coupon.getCouponStatus()!=1){ |
| | | throw new ServiceException(AppErrorConstant.COUPON_GET_ERROR); |
| | | } |
| | | // 根据优惠券数量生成会员优惠券列表 |
| | | for(int i=0;i<birthdayGiftSendDto.getCouponNumber();i++){ |
| | | memberCoupon = new MemberCoupon(); |
| | | memberCoupon.setDelFlag(0); |
| | | memberCoupon.setCouponId(couponId); |
| | | memberCoupon.setUserId(userId); |
| | | memberCoupon.setShopId(shopId); |
| | | // 根据优惠券类型设置会员优惠券信息 |
| | | if(coupon.getCouponType()==1){ |
| | | memberCoupon.setMoneyThreshold(coupon.getMoneyThreshold()); |
| | | memberCoupon.setDiscountMoney(coupon.getDiscountMoney()); |
| | | }else if(coupon.getCouponType()==2){ |
| | | memberCoupon.setDiscountPercent(coupon.getDiscountPercent()); |
| | | }else if(coupon.getCouponType()==3){ |
| | | memberCoupon.setDiscountMoney(coupon.getDiscountMoney()); |
| | | }else{ |
| | | memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds()); |
| | | } |
| | | memberCoupon.setCouponStatus(coupon.getCouponStatus()); |
| | | memberCoupon.setCouponName(coupon.getCouponName()); |
| | | memberCoupon.setSendType(coupon.getSendType()); |
| | | memberCoupon.setSendTarget(coupon.getSendTarget()); |
| | | memberCoupon.setSendTimeType(coupon.getSendTimeType()); |
| | | memberCoupon.setSendTime(coupon.getSendTime()); |
| | | memberCoupon.setUseScope(coupon.getUseScope()); |
| | | // 如果优惠券适用范围为指定商品,则设置关联商品ID |
| | | if(memberCoupon.getUseScope()==2){ |
| | | memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds()); |
| | | } |
| | | memberCoupon.setValidTimeType(coupon.getValidTimeType()); |
| | | memberCoupon.setValidStartTime(coupon.getValidStartTime()); |
| | | memberCoupon.setValidEndTime(coupon.getValidEndTime()); |
| | | memberCoupon.setValidDay(coupon.getValidDay()); |
| | | memberCoupon.setCouponFrom(coupon.getCouponFrom()); |
| | | memberCoupon.setReceiveTime(new Date()); |
| | | // 根据有效期类型设置会员优惠券的截止时间 |
| | | if(coupon.getValidTimeType()==1){ |
| | | memberCoupon.setDeadlineTime(coupon.getValidEndTime()); |
| | | }else if(coupon.getValidTimeType()==2){ |
| | | memberCoupon.setDeadlineTime(DateUtils.addDays(new Date(),coupon.getValidDay())); |
| | | } |
| | | memberCouponList.add(memberCoupon); |
| | | } |
| | | // 更新会员优惠券记录 |
| | | memberCouponRecordService.updateMemberCouponRecord(coupon,userId,birthdayGiftSendDto.getCouponNumber()); |
| | | } |
| | | // 批量保存会员优惠券列表 |
| | | memberCouponService.saveBatch(memberCouponList); |
| | | } |
| | | |
| | | /** |
| | | * @description 用户分页获取可领取优惠券列表 |
| | | * @author jqs |
| | | * @date 2023/7/9 16:16 |
| | | * @param page |
| | | * @param appPageDto |
| | | * @return List<AppUnGetCouponPageVo> |
| | | */ |
| | | @Override |
| | | public List<AppGetAbleCouponPageVo> pageAppUserGetAbleCoupon(Page page, AppPageDto appPageDto, Member member){ |
| | | //获取用户当前已领取完优惠券 |
| | | List<String> unUserGetList = couponMapper.listUserUnGetCoupon(appPageDto.getUserId()); |
| | | //获取当前已领取完优惠券 |
| | | List<String> unGetList = couponMapper.listUnGetCoupon(); |
| | | //合并不可领取优惠券列表 |
| | | HashSet<String> mergedList = new HashSet<>(); |
| | | mergedList.addAll(unUserGetList); |
| | | mergedList.addAll(unGetList); |
| | | unGetList = new ArrayList<>(mergedList); |
| | | List<AppGetAbleCouponPageVo> getAbleCouponPageVoList = couponMapper.getAbleCouponPageVoList(page, member.getRelationShopId(),member.getUserId(),member.getBindingFlag(), unGetList); |
| | | //处理商品限制 |
| | | if(!getAbleCouponPageVoList.isEmpty()){ |
| | | String relGoodsIds; |
| | | HashSet<Long> shopIdSet = new HashSet<>(); |
| | | HashSet<String> goodsIdSet = new HashSet<>(); |
| | | String[] goodsIdArr; |
| | | for(AppGetAbleCouponPageVo getAbleCouponPageVo : getAbleCouponPageVoList){ |
| | | if(getAbleCouponPageVo.getShopId()!=null){ |
| | | shopIdSet.add(getAbleCouponPageVo.getShopId()); |
| | | } |
| | | if(StringUtils.isNotBlank(getAbleCouponPageVo.getRelGoodsIds())){ |
| | | relGoodsIds = getAbleCouponPageVo.getRelGoodsIds(); |
| | | goodsIdArr = relGoodsIds.split(","); |
| | | for(String str : goodsIdArr){ |
| | | goodsIdSet.add(str); |
| | | } |
| | | } |
| | | } |
| | | //获取关联商户和商品信息并转换为Map |
| | | String shopJoinedString; |
| | | Map<Long, MgtSimpleShopVo> shopMap = null; |
| | | if(shopIdSet!=null&&!shopIdSet.isEmpty()) { |
| | | shopJoinedString = String.join(",", shopIdSet.stream().map(Object::toString).collect(Collectors.toList())); |
| | | MgtBaseBathDto mgtBaseBathDto = new MgtBaseBathDto(); |
| | | mgtBaseBathDto.setIds(shopJoinedString); |
| | | List<MgtSimpleShopVo> simpleShopVoList = remoteShopService.listShopSimpleVoByIds(mgtBaseBathDto).getData(); |
| | | shopMap = simpleShopVoList.stream() |
| | | .collect(Collectors.toMap(MgtSimpleShopVo::getShopId, Function.identity())); |
| | | } |
| | | String goodsJoinedString = null; |
| | | if(goodsIdSet!=null&&!goodsIdSet.isEmpty()){ |
| | | goodsJoinedString = String.join(",", goodsIdSet.stream().map(Object::toString).collect(Collectors.toList())); |
| | | } |
| | | Map<String, Goods> goodsMap = null; |
| | | if(goodsJoinedString!=null){ |
| | | List<Goods> goodsList = remoteGoodsService.listGoodsByGoodsId(goodsJoinedString).getData(); |
| | | goodsMap = goodsList.stream() |
| | | .collect(Collectors.toMap(Goods::getGoodsId, Function.identity())); |
| | | } |
| | | //处理返回信息 |
| | | String shopLimit = "全门店通用"; |
| | | String goodsLimit; |
| | | StringJoiner goodsNameSj; |
| | | for(AppGetAbleCouponPageVo getAbleCouponPageVo : getAbleCouponPageVoList){ |
| | | goodsLimit = null; |
| | | goodsNameSj = new StringJoiner(","); |
| | | //商户限制 |
| | | if(getAbleCouponPageVo.getShopId()!=null){ |
| | | shopLimit = shopMap.get(getAbleCouponPageVo.getShopId()).getShopName()+"可用"; |
| | | } |
| | | getAbleCouponPageVo.setShopLimit(shopLimit); |
| | | //商品限制 |
| | | if(StringUtils.isNotBlank(getAbleCouponPageVo.getRelGoodsIds())){ |
| | | relGoodsIds = getAbleCouponPageVo.getRelGoodsIds(); |
| | | goodsIdArr = relGoodsIds.split(","); |
| | | for(String goodsIs : goodsIdArr){ |
| | | if(goodsMap.get(goodsIs)!=null){ |
| | | goodsNameSj.add(goodsMap.get(goodsIs).getGoodsName()); |
| | | }else{ |
| | | log.debug("用户优惠券未找到关联商品"+getAbleCouponPageVo.getCouponId()+"-"+getAbleCouponPageVo.getRelGoodsIds()); |
| | | } |
| | | } |
| | | goodsLimit = goodsNameSj.toString(); |
| | | } |
| | | getAbleCouponPageVo.setGoodsLimit(goodsLimit); |
| | | } |
| | | } |
| | | return getAbleCouponPageVoList; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * @description 用户领取优惠券 |
| | | * @author jqs |
| | | * @date 2023/7/11 15:04 |
| | | * @param couponId |
| | | * @param shopId |
| | | * @return void |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void appGetCoupon(String couponId,Long userId,Long shopId){ |
| | | Coupon coupon = this.getById(couponId); |
| | | //判断优惠券状态 |
| | | if(coupon==null||coupon.getDelFlag()==1||coupon.getCouponStatus()!=1||coupon.getSendType()!=1){ |
| | | throw new ServiceException(AppErrorConstant.COUPON_GET_ERROR); |
| | | } |
| | | //判断优惠券用户领取状态 |
| | | MemberCouponRecord memberCouponRecord = memberCouponRecordService.getByCouponIdAndUserId(couponId,userId); |
| | | if(memberCouponRecord!=null&&memberCouponRecord.getLimitFlag()==1){ |
| | | throw new ServiceException(AppErrorConstant.COUPON_GET_ALL); |
| | | } |
| | | //判断优惠券发放状态 |
| | | if(coupon.getSendLimitFlag()==1&&coupon.getSendLimitNumber()>0){ |
| | | CouponTotal couponTotal = couponTotalService.getById(couponId); |
| | | if(couponTotal.getSendCount()>=coupon.getSendLimitNumber()){ |
| | | throw new ServiceException(AppErrorConstant.COUPON_GET_ALL); |
| | | } |
| | | } |
| | | //生成用户优惠券 |
| | | MemberCoupon memberCoupon = new MemberCoupon(); |
| | | memberCoupon.setDelFlag(0); |
| | | memberCoupon.setCouponId(couponId); |
| | | memberCoupon.setUserId(userId); |
| | | if(coupon.getCouponFrom()==2){ |
| | | memberCoupon.setShopId(shopId); |
| | | } |
| | | memberCoupon.setCouponType(coupon.getCouponType()); |
| | | if(coupon.getCouponType()==1){ |
| | | memberCoupon.setMoneyThreshold(coupon.getMoneyThreshold()); |
| | | memberCoupon.setDiscountMoney(coupon.getDiscountMoney()); |
| | | }else if(coupon.getCouponType()==2){ |
| | | memberCoupon.setDiscountPercent(coupon.getDiscountPercent()); |
| | | }else if(coupon.getCouponType()==3){ |
| | | memberCoupon.setDiscountMoney(coupon.getDiscountMoney()); |
| | | }else{ |
| | | memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds()); |
| | | } |
| | | memberCoupon.setCouponStatus(coupon.getCouponStatus()); |
| | | memberCoupon.setCouponName(coupon.getCouponName()); |
| | | memberCoupon.setSendType(coupon.getSendType()); |
| | | memberCoupon.setSendTarget(coupon.getSendTarget()); |
| | | memberCoupon.setSendTimeType(coupon.getSendTimeType()); |
| | | memberCoupon.setSendTime(coupon.getSendTime()); |
| | | memberCoupon.setUseScope(coupon.getUseScope()); |
| | | if(memberCoupon.getUseScope()==2){ |
| | | memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds()); |
| | | } |
| | | memberCoupon.setValidTimeType(coupon.getValidTimeType()); |
| | | memberCoupon.setValidStartTime(coupon.getValidStartTime()); |
| | | memberCoupon.setValidEndTime(coupon.getValidEndTime()); |
| | | memberCoupon.setValidDay(coupon.getValidDay()); |
| | | memberCoupon.setCouponFrom(coupon.getCouponFrom()); |
| | | memberCoupon.setReceiveTime(new Date()); |
| | | //有效期处理1.时间段2.领取之日起 |
| | | if(coupon.getValidTimeType()==1){ |
| | | memberCoupon.setDeadlineTime(coupon.getValidEndTime()); |
| | | }else if(coupon.getValidTimeType()==2){ |
| | | memberCoupon.setDeadlineTime(DateUtils.addDays(new Date(),coupon.getValidDay())); |
| | | } |
| | | memberCouponRecordService.updateMemberCouponRecord(coupon,userId,1); |
| | | memberCouponService.insert(memberCoupon); |
| | | } |
| | | |
| | | /** |
| | | * @description 获取商户优惠券审核统计 |
| | | * @author jqs |
| | | * @date 2023/7/28 11:30 |
| | | * @param shopId |
| | | * @return MetAuditCouponTotalVo |
| | | */ |
| | | @Override |
| | | public MetAuditCouponTotalVo getMetAuditCouponTotal(Long shopId){ |
| | | MetAuditCouponTotalVo metAuditCouponTotalVo = new MetAuditCouponTotalVo(); |
| | | LambdaQueryWrapper<Coupon> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Coupon::getDelFlag,0); |
| | | queryWrapper.eq(Coupon::getCouponFrom,2); |
| | | queryWrapper.eq(Coupon::getShopId,shopId); |
| | | queryWrapper.eq(Coupon::getCouponStatus,1); |
| | | queryWrapper.eq(Coupon::getAuditStatus,1); |
| | | Integer unAuditTotal = this.count(queryWrapper); |
| | | queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(Coupon::getDelFlag,0); |
| | | queryWrapper.eq(Coupon::getCouponFrom,2); |
| | | queryWrapper.eq(Coupon::getShopId,shopId); |
| | | queryWrapper.eq(Coupon::getCouponStatus,1); |
| | | queryWrapper.eq(Coupon::getAuditStatus,3); |
| | | Integer refuseTotal = this.count(queryWrapper); |
| | | metAuditCouponTotalVo.setUnAuditTotal(unAuditTotal); |
| | | metAuditCouponTotalVo.setRefuseTotal(refuseTotal); |
| | | return metAuditCouponTotalVo; |
| | | } |
| | | } |