From 6ab383249b70a9646ffde1474b59dcc7d0b97df6 Mon Sep 17 00:00:00 2001
From: jiangqs <343695869@qq.com>
Date: 星期日, 06 八月 2023 15:05:15 +0800
Subject: [PATCH] bug

---
 ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java |  296 ++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 203 insertions(+), 93 deletions(-)

diff --git a/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java b/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java
index 1f7a536..0cf4ebc 100644
--- a/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java
+++ b/ruoyi-modules/ruoyi-member/src/main/java/com/ruoyi/member/service/impl/coupon/CouponServiceImpl.java
@@ -21,9 +21,11 @@
 import com.ruoyi.system.api.domain.dto.*;
 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;
@@ -33,10 +35,9 @@
 
 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.TimeUnit;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -117,6 +118,15 @@
                     discountMoney = mgtCouponPageVo.getDiscountMoney();
                     useLimit = "满" + moneyThreshold.toString() + "减" + discountMoney.toString() + "元";
                 }
+                if(couponType.equals("折扣")){
+                    moneyThreshold = mgtCouponPageVo.getMoneyThreshold();
+                    discountPercent = mgtCouponPageVo.getDiscountPercent();
+                    useLimit = discountPercent.toString() + "折";
+                }
+                if(couponType.equals("抵扣")){
+                    discountMoney = mgtCouponPageVo.getDiscountMoney();
+                    useLimit = discountMoney.toString();
+                }
                 mgtCouponPageVo.setUseLimit(useLimit);
                 //处理有效期
                 validTimeType = mgtCouponPageVo.getValidTimeType();
@@ -187,7 +197,7 @@
             }
         }
         //判断优惠券是否指定发放用户
-        if(coupon.getSendType()==5&&coupon.getRelationType()==1){
+        if(coupon.getSendTarget()==5&&coupon.getRelationType()==1){
             //获取优惠券发放用户
             List<MgtCouponMemberListVo> relUserList = couponRelUserService.listCouponMemberVo(coupon.getCouponId());
             mgtCouponGetVo.setRelUserList(relUserList);
@@ -207,23 +217,19 @@
         MerCouponGetVo merCouponGetVo = new MerCouponGetVo();
         Coupon coupon = this.getById(couponId);
         BeanUtils.copyProperties(coupon, merCouponGetVo);
-        if(merCouponGetVo.getSendType()>1){
-            merCouponGetVo.setSendType(2);
-            merCouponGetVo.setSendTarget(merCouponGetVo.getSendType());
-        }
         //判断优惠券是否为指定商品
         if(coupon.getUseScope()==2){
             String relGoodsIds = coupon.getRelGoodsIds();
             if(StringUtils.isNotBlank(relGoodsIds)){
                 //获取指定商品列表
                 List<MerGoodsPriceListVo> goodsList = remoteGoodsService.listGoodsPriceByGoodsId(relGoodsIds).getData();
-                if(!goodsList.isEmpty()){
+                if(goodsList!=null&&!goodsList.isEmpty()){
                     merCouponGetVo.setRelGoodsList(goodsList);
                 }
             }
         }
         //判断优惠券是否指定发放用户
-        if(coupon.getSendType()==5&&coupon.getRelationType()==1){
+        if(coupon.getSendTarget()==5&&coupon.getRelationType()==1){
             //获取优惠券发放用户
             List<MgtCouponMemberListVo> relUserList = couponRelUserService.listCouponMemberVo(coupon.getCouponId());
             merCouponGetVo.setRelUserList(relUserList);
@@ -274,6 +280,7 @@
         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());
@@ -307,21 +314,24 @@
         }
         //判断是否指定用户
         List<Long> relUserIdList = null;
-        if(coupon.getSendType()==5&&coupon.getRelationType()==1&&!mgtCouponEditDto.getRelUserIdList().isEmpty()){
+        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());
         }
         //处理优惠券发放
-        if(coupon.getSendTimeType()==1){
+        if(coupon.getSendType()==2&&coupon.getSendTimeType()==1){
             sendCoupon(coupon,relUserIdList);
             coupon.setSendFlag(1);
             this.saveOrUpdate(coupon);
@@ -342,15 +352,15 @@
     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<>();
         Long shopId = null;
-        if(coupon.getCouponFrom()==2 && sendType==3){
+        if(coupon.getCouponFrom()==2 && sendTarget==3){
             shopId = coupon.getShopId();
         }
-        if(sendType >= 2 && sendType <= 4){
-            userIdList = memberService.listIdBySendType(sendType,shopId);
-        }else if(sendType == 5){
+        if(sendTarget >= 2 && sendTarget <= 4){
+            userIdList = memberService.listIdBySendType(sendTarget,shopId);
+        }else if(sendTarget == 5){
             //关联类型1.用户管理筛选2.活动管理筛选
             if(coupon.getRelationType()==2){
                 Integer relationActivityType = coupon.getRelationActivityType();
@@ -366,7 +376,7 @@
                 userIdList = relUserIdList;
             }
         }
-        if(relUserIdList!=null&&!relUserIdList.isEmpty()){
+        if(userIdList!=null&&!userIdList.isEmpty()){
             List<MemberCoupon> memberCouponList = new ArrayList<>();
             MemberCoupon memberCoupon;
             Integer sendTotal = 0;
@@ -374,45 +384,93 @@
             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());
-                memberCoupon.setCouponType(coupon.getCouponType());
-                memberCoupon.setCouponStatus(coupon.getCouponStatus());
-                memberCoupon.setCouponName(coupon.getCouponName());
-                memberCoupon.setSendType(coupon.getSendType());
-                memberCoupon.setSendTimeType(coupon.getSendTimeType());
-                memberCoupon.setSendTime(coupon.getSendTime());
-                memberCoupon.setMoneyThreshold(coupon.getMoneyThreshold());
-                memberCoupon.setDiscountMoney(coupon.getDiscountMoney());
-                memberCoupon.setDiscountPercent(coupon.getDiscountPercent());
-                memberCoupon.setUseScope(coupon.getUseScope());
-                memberCoupon.setValidTimeType(coupon.getValidTimeType());
-                memberCoupon.setValidStartTime(coupon.getValidStartTime());
-                memberCoupon.setValidEndTime(coupon.getValidEndTime());
-                memberCoupon.setValidDay(coupon.getValidDay());
-                memberCoupon.setReceiveTime(nowTime);
-                memberCoupon.setRelGoodsIds(coupon.getRelGoodsIds());
-                //有效期处理1.时间段2.领取之日起
-                if(coupon.getValidTimeType()==1){
-                    memberCoupon.setDeadlineTime(coupon.getValidEndTime());
-                }else if(coupon.getValidTimeType()==2){
-                    memberCoupon.setDeadlineTime(DateUtils.addDays(nowTime,coupon.getValidDay()));
+                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());
+                        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){
+                            }else{
+                                sendPerson = sendPerson + 1;
+                            }
+                        }
+                        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){
+                        }else{
+                            sendPerson = sendPerson + 1;
+                        }
+                    }
+                    memberCouponRecordService.updateMemberCouponRecord(coupon,userId,1);
                 }
-                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);
             //处理优惠券统计
@@ -426,15 +484,15 @@
     private void sendCouponNow(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<>();
         Long shopId = null;
-        if(coupon.getCouponFrom()==2 && sendType==3){
+        if(coupon.getCouponFrom()==2 && sendTarget==3){
             shopId = coupon.getShopId();
         }
-        if(sendType >= 2 && sendType <= 4){
-            userIdList = memberService.listIdBySendType(sendType,shopId);
-        }else if(sendType == 5){
+        if(sendTarget >= 2 && sendTarget <= 4){
+            userIdList = memberService.listIdBySendType(sendTarget,shopId);
+        }else if(sendTarget == 5){
             //关联类型1.用户管理筛选2.活动管理筛选
             if(coupon.getRelationType()==2){
                 Integer relationActivityType = coupon.getRelationActivityType();
@@ -469,6 +527,7 @@
                 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());
@@ -479,6 +538,7 @@
                 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.领取之日起
@@ -579,7 +639,7 @@
         List<CouponRelUser> couponRelUserList;
         List<Long> userIdList = new ArrayList<>();
         Coupon coupon = this.getById(couponId);
-        if(coupon.getSendType()==5&&coupon.getRelationType()==1){
+        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()
@@ -627,6 +687,7 @@
             Date validEndTime;
             Integer validDay;
             String validTime = "";
+            HashSet<Long> shopIdSet = new HashSet<>();
             for(MgtCouponAuditPageVo mgtCouponAuditPageVo : mgtCouponAuditPageVoList){
                 //处理有效期
                 validTimeType = mgtCouponAuditPageVo.getValidTimeType();
@@ -639,6 +700,20 @@
                     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){
+                    mgtCouponAuditPageVo.setShopName(shopMap.get(mgtCouponAuditPageVo.getShopId()).getShopName());
+                }
             }
         }
         return mgtCouponAuditPageVoList;
@@ -696,7 +771,7 @@
             }
         }
         //判断优惠券是否指定发放用户
-        if(coupon.getSendType()==5&&coupon.getRelationType()==1){
+        if(coupon.getSendTarget()==5&&coupon.getRelationType()==1){
             //获取优惠券发放用户
             List<MgtCouponMemberListVo> relUserList = couponRelUserService.listCouponMemberVo(coupon.getCouponId());
             mgtCouponAuditGetVo.setRelUserList(relUserList);
@@ -715,7 +790,7 @@
     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());
@@ -723,7 +798,7 @@
         coupon.setUpdateTime(new Date());
         coupon.setUpdateUserId(mgtCouponAuditDto.getUserId());
         //审核通过后判断是否立即发放
-        if(coupon.getCouponStatus()==2&&coupon.getSendTimeType()==1){
+        if(coupon.getAuditStatus()==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()){
@@ -785,7 +860,7 @@
                 if(validTimeType==1){
                     validStartTime = merCouponPageVo.getValidStartTime();
                     validEndTime = merCouponPageVo.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 = merCouponPageVo.getValidDay();
                     validTime = "领取之日起" + validDay.toString() + "天";
@@ -843,7 +918,7 @@
                 if(validTimeType==1){
                     validStartTime = merCouponPageVo.getValidStartTime();
                     validEndTime = merCouponPageVo.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 = merCouponPageVo.getValidDay();
                     validTime = "领取之日起" + validDay.toString() + "天";
@@ -899,10 +974,9 @@
         coupon.setCouponType(merCouponEditDto.getCouponType());
         coupon.setCouponName(merCouponEditDto.getCouponName());
         coupon.setSendType(merCouponEditDto.getSendType());
-        if(merCouponEditDto.getSendType()!=1){
-            coupon.setSendType(merCouponEditDto.getSendTarget());
-        }
-        coupon.setSendTimeType(merCouponEditDto.getSendTimeType());
+        coupon.setSendTarget(merCouponEditDto.getSendTarget());
+        //商户端默认立即发放
+        coupon.setSendTimeType(1);
         coupon.setSendTime(merCouponEditDto.getSendTime());
         coupon.setMoneyThreshold(merCouponEditDto.getMoneyThreshold());
         coupon.setDiscountMoney(merCouponEditDto.getDiscountMoney());
@@ -911,6 +985,7 @@
         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());
@@ -933,18 +1008,21 @@
         }
         //判断是否指定用户
         List<Long> relUserIdList = null;
-        if(coupon.getSendType()==5&&coupon.getRelationType()==1&&!merCouponEditDto.getRelUserIdList().isEmpty()){
+        if(coupon.getSendTarget()==5&&coupon.getRelationType()==1&&!merCouponEditDto.getRelUserIdList().isEmpty()){
             relUserIdList = merCouponEditDto.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());
         }
         this.saveOrUpdate(coupon);
     }
@@ -997,6 +1075,7 @@
                 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());
@@ -1007,6 +1086,7 @@
                 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){
@@ -1031,10 +1111,10 @@
      * @return  List<AppUnGetCouponPageVo>
      */
     @Override
-    public List<AppGetAbleCouponPageVo> pageAppUserGetAbleCoupon(Page page, AppPageDto appPageDto, Long shopId){
+    public List<AppGetAbleCouponPageVo> pageAppUserGetAbleCoupon(Page page, AppPageDto appPageDto, Member member){
         //获取当前已领取完优惠券
         List<String> unGetList = couponMapper.listUserUnGetCoupon(appPageDto.getUserId());
-        List<AppGetAbleCouponPageVo> getAbleCouponPageVoList = couponMapper.getAbleCouponPageVoList(page, shopId, unGetList);
+        List<AppGetAbleCouponPageVo> getAbleCouponPageVoList = couponMapper.getAbleCouponPageVoList(page, member.getRelationShopId(),member.getUserId(),member.getBindingFlag(), unGetList);
         //处理商品限制
         if(!getAbleCouponPageVoList.isEmpty()){
             String relGoodsIds;
@@ -1045,7 +1125,7 @@
                 relGoodsIds = appGetAbleCouponPageVo.getRelGoodsIds();
                 if(StringUtils.isNotBlank(relGoodsIds)){
                     goodsList = remoteGoodsService.listGoodsByGoodsId(relGoodsIds).getData();
-                    if(!goodsList.isEmpty()){
+                    if(goodsList!=null&&!goodsList.isEmpty()){
                         goodsLimitList = goodsList.stream().map(goods -> {
                             String goodsName = goods.getGoodsName();
                             goodsName = "限制" + goodsName + "适用";
@@ -1103,6 +1183,7 @@
         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());
@@ -1113,6 +1194,7 @@
         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){
@@ -1125,4 +1207,32 @@
         memberCouponRecordService.updateMemberCouponRecord(coupon,userId,1);
     }
 
+    /**
+     * @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;
+    }
 }

--
Gitblit v1.7.1