From 6af0c7434178ca41e727c700af8174201a865de9 Mon Sep 17 00:00:00 2001 From: nickchange <126672920+nickchange@users.noreply.github.com> Date: 星期四, 02 十一月 2023 11:55:29 +0800 Subject: [PATCH] 10.31.8 --- cloud-server-activity/src/main/java/com/dsh/activity/controller/CouponController.java | 119 ++++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 89 insertions(+), 30 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 f49d537..63da441 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 @@ -91,7 +91,42 @@ @Autowired private AppUserClient appUserClient; + /** + * 查询注册赠送优惠券 判断当前优惠券限领数量 + */ + @ResponseBody + @PostMapping("/coupon/queryCouponByUser/{userId}") + public List<Integer> queryCouponByUser(@PathVariable("userId") Integer userId){ + 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)); + for (Coupon coupon : list) { + // 发放数量 + Integer quantityIssued = coupon.getQuantityIssued(); + // 限领数量 + Integer pickUpQuantity = coupon.getPickUpQuantity(); + // 优惠券已领取数量 + int couponId = ucService.count(new QueryWrapper<UserCoupon>().eq("couponId", coupon.getId())); + // 用户已领取该优惠券数量 + int count = ucService.count(new QueryWrapper<UserCoupon>().eq("couponId", coupon.getId() + ).eq("userId", userId)); + if (couponId>=quantityIssued){ + continue; + } + if (count>=pickUpQuantity){ + continue; + } + // 条件满足 将优惠券送给用户 + UserCoupon userCoupon = new UserCoupon(); + userCoupon.setCouponId(coupon.getId()); + userCoupon.setUserId(userId); + userCoupon.setStatus(1); + userCoupon.setInsertTime(new Date()); + ucService.save(userCoupon); + } + return null; + } @ResponseBody @PostMapping("/api/coupon/queryCouponList") @@ -164,18 +199,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(); @@ -185,24 +220,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); @@ -269,6 +304,22 @@ @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()) { + Map<String, Object> map = iterator.next(); + String endTime = (String) map.get("endTime"); + if (endTime.compareTo(currentDateStr) < 0) { + iterator.remove(); + } + } + + if (mapList.size() > 0){ for (Map<String, Object> stringObjectMap : mapList) { Integer o = (Integer) stringObjectMap.get("id"); @@ -510,6 +561,14 @@ if(dataVo.getObjType()!=1){ coupon.setAuditStatus(1); } + if (dataVo.getUserType()==1){ + coupon.setAuditStatus(2); + }else{ + coupon.setAuditStatus(1); + } + if(dataVo.getObjType()!=1){ + coupon.setAuditStatus(1); + } boolean save = couponService.save(coupon); if (save){ -- Gitblit v1.7.1