| | |
| | | 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.system.api.constant.AppErrorConstant; |
| | | 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.poji.shop.Shop; |
| | | 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 com.ruoyi.system.api.service.RemoteShopService; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.concurrent.CompletableFuture; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | |
| | | useLimit = "满" + moneyThreshold.toString() + "减" + discountMoney.toString() + "元"; |
| | | } |
| | | if(couponType.equals("折扣")){ |
| | | moneyThreshold = mgtCouponPageVo.getMoneyThreshold(); |
| | | discountPercent = mgtCouponPageVo.getDiscountPercent(); |
| | | useLimit = discountPercent.toString() + "折"; |
| | | } |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | 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(0); |
| | | coupon.setLimitNumber(1); |
| | | coupon.setSendFlag(0); |
| | | //创建优惠券统计 |
| | | couponTotal = new CouponTotal(); |
| | |
| | | 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; |
| | | List<Long> relUserIdList; |
| | | if(coupon.getSendTarget()==5&&coupon.getRelationType()==1&&!mgtCouponEditDto.getRelUserIdList().isEmpty()){ |
| | | relUserIdList = mgtCouponEditDto.getRelUserIdList(); |
| | | List<CouponRelUser> couponRelUserList = new ArrayList<>(); |
| | |
| | | } |
| | | couponRelUserService.saveBatch(couponRelUserList); |
| | | coupon.setRelUserIds(userIdSj.toString()); |
| | | } else { |
| | | relUserIdList = null; |
| | | } |
| | | //处理优惠券发放 |
| | | if(coupon.getSendType()==2&&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{ |
| | |
| | | * @param relUserIdList |
| | | * @return void |
| | | */ |
| | | @Async |
| | | protected void sendCoupon(Coupon coupon, List<Long> relUserIdList){ |
| | | //1.手动领取2.全部用户3.会员用户4非会员用户5自定义 |
| | | Date nowTime = new Date(); |
| | |
| | | userIdList = relUserIdList; |
| | | } |
| | | } |
| | | //商户发送全部,则发送没有绑定的会员及绑定了当前商户端会员 |
| | | 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; |
| | | Integer sendPerson = 0; |
| | | String memberCouponId; |
| | | Integer sendUserTotal; |
| | | for(Long userId : userIdList){ |
| | | if(coupon.getCouponFrom()==2){ |
| | | for(int i=0;i<coupon.getLimitNumber();i++){ |
| | | memberCouponId = IdUtils.simpleUUID(); |
| | | memberCoupon = new MemberCoupon(); |
| | | memberCoupon.setId(memberCouponId); |
| | | 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.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()); |
| | |
| | | memberCouponRecordService.updateMemberCouponRecord(coupon,userId,1); |
| | | } |
| | | }else{ |
| | | memberCouponId = IdUtils.simpleUUID(); |
| | | memberCoupon = new MemberCoupon(); |
| | | memberCoupon.setId(memberCouponId); |
| | | memberCoupon.setDelFlag(0); |
| | | memberCoupon.setCouponId(coupon.getCouponId()); |
| | | memberCoupon.setUserId(userId); |
| | | memberCoupon.setShopId(coupon.getShopId()); |
| | | memberCoupon.setCouponType(coupon.getCouponType()); |
| | | 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.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.setCouponFrom(coupon.getCouponFrom()); |
| | | 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; |
| | | if(coupon.getSendType()==1){ |
| | | sendUserTotal = memberCouponService.totalMemberCouponByUserAndCoupon(userId,coupon.getCouponId()); |
| | | if(sendUserTotal!=null&&sendUserTotal>0){ |
| | | 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{ |
| | | sendPerson = sendPerson + 1; |
| | | 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); |
| | | } |
| | | memberCouponRecordService.updateMemberCouponRecord(coupon,userId,1); |
| | | } |
| | | } |
| | | memberCouponService.saveBatch(memberCouponList); |
| | |
| | | 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; |
| | | String memberCouponId; |
| | | Integer sendUserTotal; |
| | | for(Long userId : userIdList){ |
| | | memberCouponId = IdUtils.simpleUUID(); |
| | | memberCoupon = new MemberCoupon(); |
| | | memberCoupon.setId(memberCouponId); |
| | | memberCoupon.setDelFlag(0); |
| | | memberCoupon.setCouponId(coupon.getCouponId()); |
| | | memberCoupon.setUserId(userId); |
| | | memberCoupon.setShopId(coupon.getShopId()); |
| | | 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()); |
| | |
| | | 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()); |
| | |
| | | .collect(Collectors.toMap(MgtSimpleShopVo::getShopId, Function.identity())); |
| | | for(MgtCouponAuditPageVo mgtCouponAuditPageVo : mgtCouponAuditPageVoList){ |
| | | if(mgtCouponAuditPageVo.getShopId()!=null){ |
| | | mgtCouponAuditPageVo.setShopName(shopMap.get(mgtCouponAuditPageVo.getShopId()).getShopName()); |
| | | 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; |
| | | } |
| | |
| | | couponRelGoodsService.deleteCouponRelByCouponId(coupon.getCouponId()); |
| | | coupon.setCouponStatus(1); |
| | | }else{ |
| | | //初始化新优惠券 |
| | | coupon = new Coupon(); |
| | | String couponId = IdUtils.simpleUUID(); |
| | | coupon.setCouponId(couponId); |
| | |
| | | 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(); |
| | |
| | | */ |
| | | @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; |
| | | String memberCouponId; |
| | | |
| | | // 遍历生日礼物发送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(); |
| | | memberCouponId = IdUtils.simpleUUID(); |
| | | memberCoupon.setId(memberCouponId); |
| | | memberCoupon.setDelFlag(0); |
| | | memberCoupon.setCouponId(couponId); |
| | | memberCoupon.setUserId(userId); |
| | | 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.setMoneyThreshold(coupon.getMoneyThreshold()); |
| | | memberCoupon.setDiscountMoney(coupon.getDiscountMoney()); |
| | | memberCoupon.setDiscountPercent(coupon.getDiscountPercent()); |
| | | 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()); |
| | | //有效期处理1.时间段2.领取之日起 |
| | | // 根据有效期类型设置会员优惠券的截止时间 |
| | | if(coupon.getValidTimeType()==1){ |
| | | memberCoupon.setDeadlineTime(coupon.getValidEndTime()); |
| | | }else if(coupon.getValidTimeType()==2){ |
| | | memberCoupon.setDeadlineTime(DateUtils.addDays(new Date(),coupon.getValidDay())); |
| | | } |
| | | memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds()); |
| | | memberCouponList.add(memberCoupon); |
| | | } |
| | | // 更新会员优惠券记录 |
| | | memberCouponRecordService.updateMemberCouponRecord(coupon,userId,birthdayGiftSendDto.getCouponNumber()); |
| | | } |
| | | // 批量保存会员优惠券列表 |
| | | memberCouponService.saveBatch(memberCouponList); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public List<AppGetAbleCouponPageVo> pageAppUserGetAbleCoupon(Page page, AppPageDto appPageDto, Member member){ |
| | | //获取用户当前已领取完优惠券 |
| | | List<String> unUserGetList = couponMapper.listUserUnGetCoupon(appPageDto.getUserId()); |
| | | //获取当前已领取完优惠券 |
| | | List<String> unGetList = 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; |
| | | List<Goods> goodsList; |
| | | List<String> goodsLimitList = null; |
| | | Shop shop = null; |
| | | for(AppGetAbleCouponPageVo appGetAbleCouponPageVo : getAbleCouponPageVoList){ |
| | | relGoodsIds = appGetAbleCouponPageVo.getRelGoodsIds(); |
| | | if(StringUtils.isNotBlank(relGoodsIds)){ |
| | | goodsList = remoteGoodsService.listGoodsByGoodsId(relGoodsIds).getData(); |
| | | if(goodsList!=null&&!goodsList.isEmpty()){ |
| | | goodsLimitList = goodsList.stream().map(goods -> { |
| | | String goodsName = goods.getGoodsName(); |
| | | goodsName = "限制" + goodsName + "适用"; |
| | | return goodsName; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | }else{ |
| | | goodsLimitList = new ArrayList<>(); |
| | | if(appGetAbleCouponPageVo.getShopId()!=null){ |
| | | if(shop!=null&&shop.getShopId().equals(appGetAbleCouponPageVo.getShopId())){ |
| | | }else{ |
| | | shop = remoteShopService.getShop(appGetAbleCouponPageVo.getShopId()).getData(); |
| | | } |
| | | goodsLimitList.add(shop.getShopName()+"通用"); |
| | | }else{ |
| | | goodsLimitList.add("全场通用"); |
| | | 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); |
| | | } |
| | | } |
| | | appGetAbleCouponPageVo.setGoodsLimitList(goodsLimitList); |
| | | } |
| | | |
| | | //获取关联商户和商品信息并转换为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; |
| | | } |
| | |
| | | * @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(); |
| | | String memberCouponId = IdUtils.simpleUUID(); |
| | | memberCoupon.setId(memberCouponId); |
| | | memberCoupon.setDelFlag(0); |
| | | memberCoupon.setCouponId(couponId); |
| | | memberCoupon.setUserId(userId); |
| | | memberCoupon.setShopId(shopId); |
| | | 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.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()); |
| | |
| | | }else if(coupon.getValidTimeType()==2){ |
| | | memberCoupon.setDeadlineTime(DateUtils.addDays(new Date(),coupon.getValidDay())); |
| | | } |
| | | memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds()); |
| | | memberCouponService.save(memberCoupon); |
| | | memberCouponRecordService.updateMemberCouponRecord(coupon,userId,1); |
| | | memberCouponService.insert(memberCoupon); |
| | | } |
| | | |
| | | /** |