From f8c9479d2f33515376e5c0d87734edec2e15ad6f Mon Sep 17 00:00:00 2001
From: 44323 <443237572@qq.com>
Date: 星期三, 15 十一月 2023 09:31:27 +0800
Subject: [PATCH] 后台bug修改

---
 cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java |  176 +++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 123 insertions(+), 53 deletions(-)

diff --git a/cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java b/cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java
index f531216..533c5d4 100644
--- a/cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java
+++ b/cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java
@@ -1,4 +1,5 @@
 package com.dsh.activity.controller;
+import java.util.Date;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
@@ -12,15 +13,18 @@
 import com.dsh.activity.feignclient.account.AppUserClient;
 import com.dsh.activity.feignclient.account.CityClient;
 import com.dsh.activity.feignclient.account.StoreStaffClient;
+import com.dsh.activity.feignclient.account.StudentClient;
+import com.dsh.activity.feignclient.account.model.AppUserByNameAndPhoneDTO;
 import com.dsh.activity.feignclient.account.model.TCityManager;
-import com.dsh.activity.feignclient.account.model.TStoreStaff;
 import com.dsh.activity.feignclient.model.CouponExamineListSearch;
 import com.dsh.activity.feignclient.model.CouponListOfSearch;
+import com.dsh.activity.feignclient.model.TAppUser;
 import com.dsh.activity.feignclient.other.OperatorClient;
 import com.dsh.activity.feignclient.other.RegionClient;
 import com.dsh.activity.feignclient.other.StoreClient;
 import com.dsh.activity.feignclient.other.model.CityDataAndProvinceDataVo;
 import com.dsh.activity.feignclient.other.model.Store;
+import com.dsh.activity.feignclient.other.model.StoreInfoDto;
 import com.dsh.activity.feignclient.other.model.TOperatorCity;
 import com.dsh.activity.model.CouponListVo;
 import com.dsh.activity.model.CouponRecordQuery;
@@ -40,7 +44,6 @@
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
-import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -82,6 +85,7 @@
     private StoreClient stoClient;
 
 
+
     @Resource
     private RegionClient regionClient;
 
@@ -93,6 +97,8 @@
 
     @Autowired
     private AppUserClient appUserClient;
+    @Autowired
+    private StudentClient studentClient;
 
     /**
      * 查询注册赠送优惠券 判断当前优惠券限领数量
@@ -100,7 +106,7 @@
     @ResponseBody
     @PostMapping("/coupon/queryCouponByUser/{userId}")
     public List<Integer> queryCouponByUser(@PathVariable("userId") Integer userId){
-        List<Coupon> list = couponService.list(new QueryWrapper<Coupon>().eq("distributionMethod", 2)
+        List<Coupon> list = couponService.list(new QueryWrapper<Coupon>().eq("distributionMethod", 2).eq("userPopulation",2)
                 .le("startTime", new Date()).ge("endTime", new Date()).eq("auditStatus", 2)
                 .eq("state", 1));
 
@@ -202,18 +208,18 @@
     @PostMapping("/base/coupon/getAllCoupons")
     public List<Coupon> getAllCoupons(@RequestBody CommodityRequest request){
         List<Coupon> couponList = new ArrayList<>();
-//        String provinceCode = "";
-//        String cityCode = "";
-//        if (ToolUtil.isEmpty(request.getLat()) && ToolUtil.isEmpty(request.getLon())){
-//            return couponList;
-//        }
-//        try {
-//            Map<String, String> geocode = gdMapGeocodingUtil.geocode(request.getLon(), request.getLat());
-//            provinceCode = geocode.get("provinceCode");
-//            cityCode = geocode.get("cityCode");
-//        }catch (Exception e){
-//            e.printStackTrace();
-//        }
+        String provinceCode = "";
+        String cityCode = "";
+        if (ToolUtil.isEmpty(request.getLat()) && ToolUtil.isEmpty(request.getLon())){
+            return couponList;
+        }
+        try {
+            Map<String, String> geocode = gdMapGeocodingUtil.geocode(request.getLon(), request.getLat());
+            provinceCode = geocode.get("provinceCode");
+            cityCode = geocode.get("cityCode");
+        }catch (Exception e){
+            e.printStackTrace();
+        }
         try {
             LocalDateTime currentDate = LocalDateTime.now();
 
@@ -223,24 +229,24 @@
                     .eq("status",1)
                      .le("startTime", currentDate)
                     .ge("endTime", currentDate));
-//            if (couponList.size() > 0 ){
-//                Iterator<Coupon> iterator = couponList.iterator();
-//                while (iterator.hasNext()) {
-//                    Coupon merchandise = iterator.next();
-//                    if (merchandise.getUseScope() == 2){
-//                        List<CouponCity> couponCities = cityService.list(new LambdaQueryWrapper<CouponCity>()
-//                                .eq(CouponCity::getCouponId,merchandise.getId()));
-//                        if (couponCities.size() > 0){
-//                            for (CouponCity couponCity : couponCities) {
-//                                if (!Objects.equals(couponCity.getCityCode(), cityCode) && !Objects.equals(couponCity.getProvinceCode(), provinceCode)){
-//                                    iterator.remove(); // 移除符合条件的商品
-//                                    break;
-//                                }
-//                            }
-//                        }
-//                    }
-//                }
-//            }
+            if (couponList.size() > 0 ){
+                Iterator<Coupon> iterator = couponList.iterator();
+                while (iterator.hasNext()) {
+                    Coupon merchandise = iterator.next();
+                    if (merchandise.getUseScope() == 2){
+                        List<CouponCity> couponCities = cityService.list(new LambdaQueryWrapper<CouponCity>()
+                                .eq(CouponCity::getCouponId,merchandise.getId()));
+                        if (couponCities.size() > 0){
+                            for (CouponCity couponCity : couponCities) {
+                                if (!Objects.equals(couponCity.getCityCode(), cityCode) && !Objects.equals(couponCity.getProvinceCode(), provinceCode)){
+                                    iterator.remove(); // 移除符合条件的商品
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
             return couponList;
         } catch (Exception e) {
             throw new RuntimeException(e);
@@ -424,11 +430,7 @@
             couponInfo.put("id",coupon.getId());
             couponInfo.put("auditStatus",coupon.getAuditStatus());
             couponInfo.put("publisherType",coupon.getPublisherType());
-            if (coupon.getPublisherType() == 1){
-                TCityManager byId = citClient.getById(coupon.getCityManagerId());
-                couponInfo.put("province",byId.getProvince());
-                couponInfo.put("city",byId.getCity());
-            }
+
             couponInfo.put("name",coupon.getName());
             couponInfo.put("type",coupon.getType());
             JSONObject jsonObject = JSON.parseObject(coupon.getContent());
@@ -502,14 +504,16 @@
                     List<CouponStore> list = couStoreService.list(new LambdaQueryWrapper<CouponStore>()
                             .eq(CouponStore::getCouponId,coupon.getId()));
                     if (list.size() > 0){
+                        // 获取门店ids
                         List<Integer> collect = list.stream().map(CouponStore::getStoreId).collect(Collectors.toList());
                         List<Store> storeList = stoClient.queryStoreByIds(collect);
                         if (storeList.size() > 0){
                             for (Store store : storeList) {
-                                TStoreStaff list1 = stoStaClient.baseInfo(store.getStoreStaffId());
+
+                                StoreInfoDto storeInfo = stoClient.getStoreInfo(store.getStoreStaffId());
                                 HashMap<String, Object> stringObjectHashMap = new HashMap<>();
                                 stringObjectHashMap.put("procity",store.getProvince()+store.getCity());
-                                stringObjectHashMap.put("storeAccount",list1.getName()+"+"+list1.getPhone());
+                                stringObjectHashMap.put("storeAccount",storeInfo.getInfo());
                                 stringObjectHashMap.put("storeName",store.getName());
                                 maps.add(stringObjectHashMap);
                             }
@@ -569,20 +573,20 @@
             coupon.setIllustrate(dataVo.getIllustrate());
             coupon.setDistributionMethod(dataVo.getDistributionMethod());
             coupon.setRedemptionMethod(dataVo.getExchangeMethod());
-            switch (dataVo.getExchangeMethod()){
-                case 1:
-                    coupon.setIntegral(BigDecimal.valueOf(dataVo.getRequiredPoints()));
-                    break;
-                case 2:
-                    coupon.setCash(dataVo.getRequiredCash());
-                    coupon.setIntegral(BigDecimal.valueOf(dataVo.getRequiredPoints()));
-                    break;
-                case 3:
-                    coupon.setCash(dataVo.getRequiredCash());
-                    break;
-                default:
-                    break;
+            if (dataVo.getExchangeMethod()!=null){
+                switch (dataVo.getExchangeMethod()){
+                    case 1:
+                        coupon.setIntegral(BigDecimal.valueOf(dataVo.getRequiredPoints()));
+                        break;
+
+                    case 3:
+                        coupon.setCash(dataVo.getRequiredCash());
+                        break;
+                    default:
+                        break;
+                }
             }
+
             coupon.setQuantityIssued(dataVo.getQuantityIssued());
             coupon.setPickUpQuantity(dataVo.getPickUpQuantity());
             coupon.setUseScope(dataVo.getCompany());
@@ -627,6 +631,72 @@
             }
 
             boolean save = couponService.save(coupon);
+            AppUserByNameAndPhoneDTO dto = new AppUserByNameAndPhoneDTO();
+            List<TAppUser> tAppUsers = appUserClient.queryAppUserList(dto);
+            // 发放数量
+            Integer quantityIssued = dataVo.getQuantityIssued();
+            // 限领数量
+            Integer pickUpQuantity = dataVo.getPickUpQuantity();
+            // 赠送用户数量
+            int count = quantityIssued / pickUpQuantity;
+            // 自动发券
+            if (dataVo.getDistributionMethod() == 3){
+                // 判断用户人群 再判断限领数量
+                switch (dataVo.getUserGroup()){
+                    case 1:
+                        // 给全部用户发券
+                        // 全部用户ids
+                        List<Integer> collect = tAppUsers.stream()
+                                .map(TAppUser::getId).collect(Collectors.toList());
+                        for (int i = 0; i < count; i++) {
+                                for (int j = 0; j < pickUpQuantity; j++) {
+                                    UserCoupon u1 = new UserCoupon();
+                                    u1.setCouponId(coupon.getId());
+                                    u1.setUserId(collect.get(i));
+                                    u1.setStatus(1);
+                                    u1.setVerificationUserId(null);
+                                    u1.setVerificationTime(null);
+                                    u1.setInsertTime(new Date());
+                                    ucService.save(u1);
+                                }
+                        }
+                        break;
+                    case 2:
+                        // 给年度会员发券 获取年度会员ids
+                        List<Integer> collect1 = tAppUsers.stream().filter(t -> t.getVipEndTime().after(new Date()))
+                                .map(TAppUser::getId)
+                                .collect(Collectors.toList());
+                        for (int i = 0; i < count; i++) {
+                            for (int j = 0; j < pickUpQuantity; j++) {
+                                UserCoupon u1 = new UserCoupon();
+                                u1.setCouponId(coupon.getId());
+                                u1.setUserId(collect1.get(i));
+                                u1.setStatus(1);
+                                u1.setVerificationUserId(null);
+                                u1.setVerificationTime(null);
+                                u1.setInsertTime(new Date());
+                                ucService.save(u1);
+                            }
+                        }
+                        break;
+                    case 3:
+                        // 给已有学员用户发券 获取已有学员的用户ids
+                        List<Integer> collect2 = studentClient.getHasStudentUser();
+                        for (int i = 0; i < count; i++) {
+                            for (int j = 0; j < pickUpQuantity; j++) {
+                                UserCoupon u1 = new UserCoupon();
+                                u1.setCouponId(coupon.getId());
+                                u1.setUserId(collect2.get(i));
+                                u1.setStatus(1);
+                                u1.setVerificationUserId(null);
+                                u1.setVerificationTime(null);
+                                u1.setInsertTime(new Date());
+                                ucService.save(u1);
+                            }
+                        }
+                        break;
+                }
+            }
             if (save){
                 if (dataVo.getCompany() == 3){
                     String[] split = dataVo.getStoreIds().split(",");

--
Gitblit v1.7.1