From f6ba3e15355e22767e69f8fc14ae22523f8db8dc Mon Sep 17 00:00:00 2001 From: 44323 <443237572@qq.com> Date: 星期三, 22 十一月 2023 19:33:58 +0800 Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/PlayPai --- cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java | 252 ++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 202 insertions(+), 50 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 63da441..8958ca7 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,14 +13,19 @@ 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; import com.dsh.activity.model.request.CommodityRequest; @@ -38,6 +44,8 @@ import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import io.swagger.models.auth.In; +import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -79,6 +87,7 @@ private StoreClient stoClient; + @Resource private RegionClient regionClient; @@ -90,6 +99,8 @@ @Autowired private AppUserClient appUserClient; + @Autowired + private StudentClient studentClient; /** * 查询注册赠送优惠券 判断当前优惠券限领数量 @@ -97,6 +108,8 @@ @ResponseBody @PostMapping("/coupon/queryCouponByUser/{userId}") public List<Integer> queryCouponByUser(@PathVariable("userId") Integer userId){ + + System.err.println("到达了赠送优惠价"); List<Coupon> list = couponService.list(new QueryWrapper<Coupon>().eq("distributionMethod", 2) .le("startTime", new Date()).ge("endTime", new Date()).eq("auditStatus", 2) .eq("state", 1)); @@ -164,6 +177,35 @@ try { Coupon coupon = couponService.getById(id); return coupon; + }catch (Exception e){ + e.printStackTrace(); + return null; + } + } + + + @Autowired + private UserCouponService userCouponService; + @ResponseBody + @PostMapping("/coupon/queryCouponByUid") + public List<Coupon> queryCouponByUid(@RequestBody Integer uid){ + try { + LocalDateTime currentTime = LocalDateTime.now(); + LocalDateTime oneMinuteAgo = currentTime.minusSeconds(20); + + List<UserCoupon> list = userCouponService.list(new QueryWrapper<UserCoupon>().eq("userId", uid).ge("insertTime", oneMinuteAgo)); + List<Integer> ids = new ArrayList<>(); + for (UserCoupon userCoupon : list) { + ids.add(userCoupon.getCouponId()); + } + + if (ids.size()>0){ + List<Coupon> userId = couponService.list(new QueryWrapper<Coupon>().in("id",ids)); + return userId; + + } + + return null; }catch (Exception e){ e.printStackTrace(); return null; @@ -259,27 +301,81 @@ } - + @Autowired + private OperatorClient operatorClient; @ResponseBody @PostMapping("/base/coupon/queryCouponListSearch") public List<Map<String,Object>> getCouponListOfSearch(@RequestBody CouponListOfSearch ofSearch){ List<Map<String, Object>> mapList1 = couponService.queryCouponListOfSearch(ofSearch); - List<Map<String, Object>> mapList = new ArrayList<>(); - if(ofSearch.getStoreId()!=null){ + List<Map<String, Object>> mapList = new ArrayList<>(); + if (ofSearch.getStoreIds()==null){ + ArrayList<Integer> list = new ArrayList<>(); + ofSearch.setStoreIds(list); + } + if(ofSearch.getStoreId()!=null || ofSearch.getStoreIds().size()!=0){ for (Map<String, Object> map : mapList1) { - List<CouponStore> id = couStoreService.list(new LambdaQueryWrapper<CouponStore>().eq(CouponStore::getCouponId, map.get("id").toString())); - List<Integer> collect = id.stream().map(CouponStore::getStoreId).collect(Collectors.toList()); - if(collect.size()==0){ - collect.add(-1); - } - if(collect.contains(ofSearch.getStoreId())){ - if(collect.size()>1){ - map.put("size",1); - }else { - map.put("size",0); + // 如果当前登陆人是运营商 只能查看平台添加的优惠券应只展示使用范围为全国通用、 + // 指定城市有运营商管辖的、指定门店有运营商旗下门店 + if (ofSearch.getObjType()== 2){ + if (Integer.parseInt(String.valueOf(map.get("useScope"))) == 1){ + mapList.add(map); } - mapList.add(map); + if (Integer.parseInt(String.valueOf(map.get("useScope"))) == 2){ + // 获取到优惠券id 查询这个优惠券指定了哪些城市 + Integer id = Integer.parseInt(String.valueOf(map.get("id"))); + // 获取到运营商管理的省和市 + List<TOperatorCity> cityByOperatorId = ofSearch.getOperatorCities(); + // 拿到运营商市的code集合 + List<String> collect = cityByOperatorId.stream().filter(t -> t.getPid() != 0) + .map(tOperatorCity -> Integer.toString(tOperatorCity.getCode())) + .collect(Collectors.toList()); + List<CouponCity> couponId = cityService.list(new QueryWrapper<CouponCity>().eq("couponId", id)); + // 先判断优惠券管理的市 运营商是否有 + List<String> collect1 = couponId.stream().map(CouponCity::getCityCode) + .collect(Collectors.toList()); + // 优惠券指定的省 + List<String> collect2 = couponId.stream().map(CouponCity::getCityCode) + .collect(Collectors.toList()); + if (!Collections.disjoint(collect, collect1)){ + mapList.add(map); + }else{ + // 如果没有交集 那么还需要判断运营商是否管理了整个省 + + + } + } + if (Integer.parseInt(String.valueOf(map.get("useScope"))) == 3){ + // 获取到优惠券id 查询这个优惠券指定了哪些门店 + Integer id = Integer.parseInt(String.valueOf(map.get("id"))); + // 当前运营商管理的门店ids + List<Integer> storeIds = ofSearch.getStoreIds(); + // 优惠券指定的门店 + List<Integer> collect = couStoreService.list(new QueryWrapper<CouponStore>().eq("couponId",id) + .in("storeId", storeIds)).stream().map(CouponStore::getStoreId) + .collect(Collectors.toList()); + // 判断两个集合是否相交 + // 比较两个集合中是否有相同的元素;当两个集合中没有相同元素时返回true, + // 当有相同元素时返回false。 + if (!Collections.disjoint(collect, storeIds)){ + mapList.add(map); + } + } + }else{ + List<CouponStore> id = couStoreService.list(new LambdaQueryWrapper<CouponStore>() + .eq(CouponStore::getCouponId, map.get("id").toString())); + List<Integer> collect = id.stream().map(CouponStore::getStoreId).collect(Collectors.toList()); + if(collect.size()==0){ + collect.add(-1); + } + if(collect.contains(ofSearch.getStoreId())){ + if(collect.size()>1){ + map.put("size",1); + }else { + map.put("size",0); + } + mapList.add(map); + } } } }else { @@ -303,12 +399,11 @@ @ResponseBody @PostMapping("/base/coupon/queryCouponListSearch1") public List<Map<String,Object>> getCouponListOfSearch1(@RequestBody CouponListOfSearch ofSearch){ + // 查询全国通用的优惠券和包含指定门店的优惠券 List<Map<String, Object>> mapList = couponService.queryCouponListOfSearch1(ofSearch); - Date currentDate = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String currentDateStr = sdf.format(currentDate); - // Iterate over the mapList and remove entries where endTime is less than the current date Iterator<Map<String, Object>> iterator = mapList.iterator(); while (iterator.hasNext()) { @@ -345,11 +440,7 @@ Integer publisherType = (Integer) stringObjectMap.get("publisherType"); if (publisherType!=null) { if (publisherType == 1) { - Integer cityManagerId = (Integer) stringObjectMap.get("cityManagerId"); - TCityManager byId = citClient.getById(cityManagerId); - stringObjectMap.put("province", byId.getProvince()); - stringObjectMap.put("city", byId.getCity()); } } } @@ -368,11 +459,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()); @@ -446,14 +533,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); } @@ -513,20 +602,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()); @@ -553,24 +642,87 @@ } if (dataVo.getUserType() == 1){ coupon.setPublisherType(2); + coupon.setAuditStatus(2); + coupon.setCityManagerId(dataVo.getCityManagerId()); } if (dataVo.getUserType() == 2){ coupon.setPublisherType(1); + coupon.setAuditStatus(1); coupon.setCityManagerId(dataVo.getCityManagerId()); } - if(dataVo.getObjType()!=1){ + if (dataVo.getUserType() == 3){ + coupon.setPublisherType(3); coupon.setAuditStatus(1); - } - if (dataVo.getUserType()==1){ - coupon.setAuditStatus(2); - }else{ - coupon.setAuditStatus(1); - } - if(dataVo.getObjType()!=1){ - coupon.setAuditStatus(1); + coupon.setCityManagerId(dataVo.getCityManagerId()); } 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