| | |
| | | public R<IPage<CouponInfo>> list(@RequestParam("pageNum") Integer pageNum, |
| | | @RequestParam("pageSize") Integer pageSize, |
| | | CouponInfo couponInfo) { |
| | | Integer periodType = couponInfo.getPeriodType(); |
| | | if (periodType != null && periodType.equals(0)){ |
| | | couponInfo.setPeriodType(null); |
| | | } |
| | | IPage<CouponInfo> couponInfoIPage = couponInfoService.queryCouponInfoPage(Page.of(pageNum, pageSize), couponInfo); |
| | | for (CouponInfo record : couponInfoIPage.getRecords()) { |
| | | R<Long> r = userCouponClient.getCouponCount(record.getId()); |
| | |
| | | @ApiOperation(value = "优惠劵管理-详情", tags = {"管理后台-活动管理"}) |
| | | public R<CouponInfo> detail(@RequestParam("id") Integer id) { |
| | | CouponInfo byId = couponInfoService.getById(id); |
| | | if (byId == null){ |
| | | return R.fail("优惠劵不存在"); |
| | | } |
| | | String forGoodIds = byId.getForGoodIds(); |
| | | if (!"-1".equals(forGoodIds) && StringUtils.isNotEmpty(forGoodIds)){ |
| | | List<Goods> goods = goodsService.listByIds(Arrays.asList(forGoodIds.split(","))); |
| | |
| | | AppUser appUserById = appUserClient.getAppUserById(userid); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | //查出全部可领取的优惠劵 |
| | | List<CouponInfo> list = couponInfoService.lambdaQuery().le(CouponInfo::getSendStartTime, now).ge(CouponInfo::getSendEndTime, now).eq(CouponInfo::getPersonType, 1).list(); |
| | | List<CouponInfo> list = couponInfoService.lambdaQuery() |
| | | .le(CouponInfo::getSendStartTime, now) |
| | | .ge(CouponInfo::getSendEndTime, now) |
| | | .eq(CouponInfo::getPersonType, 1) |
| | | .eq(CouponInfo::getDelFlag, 0) |
| | | .eq(CouponInfo::getShelfStatus, 1) |
| | | .list(); |
| | | //查出指定人员可领取优惠券 |
| | | List<CouponInfo> list1 = couponInfoService.lambdaQuery().le(CouponInfo::getSendStartTime, now).ge(CouponInfo::getSendEndTime, now).eq(CouponInfo::getPersonType, 2).apply("FIND_IN_SET('" + appUserById.getId() + "', person_ids)").list(); |
| | | List<CouponInfo> list1 = couponInfoService.lambdaQuery() |
| | | .le(CouponInfo::getSendStartTime, now) |
| | | .ge(CouponInfo::getSendEndTime, now) |
| | | .eq(CouponInfo::getPersonType, 2) |
| | | .eq(CouponInfo::getDelFlag, 0) |
| | | .eq(CouponInfo::getShelfStatus, 1) |
| | | .apply("FIND_IN_SET('" + appUserById.getId() + "', person_ids)") |
| | | .list(); |
| | | //查出指定会员可领取优惠劵 |
| | | List<CouponInfo> list2 = couponInfoService.lambdaQuery().le(CouponInfo::getSendStartTime, now).ge(CouponInfo::getSendEndTime, now).eq(CouponInfo::getPersonType, 3).apply("FIND_IN_SET('" + appUserById.getVipId() + "', person_ids)").list(); |
| | | List<CouponInfo> list2 = couponInfoService.lambdaQuery() |
| | | .le(CouponInfo::getSendStartTime, now) |
| | | .ge(CouponInfo::getSendEndTime, now) |
| | | .eq(CouponInfo::getPersonType, 3) |
| | | .eq(CouponInfo::getDelFlag, 0) |
| | | .eq(CouponInfo::getShelfStatus, 1) |
| | | .apply("FIND_IN_SET('" + appUserById.getVipId() + "', vip_ids)").list(); |
| | | List<CouponInfo> returnList = new ArrayList<>(); |
| | | count(userid, list, returnList); |
| | | count(userid, list1, returnList); |
| | | count(userid, list2, returnList); |
| | | returnList.addAll(list); |
| | | returnList.addAll(list1); |
| | | returnList.addAll(list2); |
| | | |
| | | List<CouponInfo> collect = returnList.stream().filter(couponInfo -> { |
| | | Integer couponInfoId = couponInfo.getId(); |
| | | Integer sendNum = couponInfo.getSendNum(); |
| | | Integer maxNum = couponInfo.getMaxNum(); |
| | | Long count = appUserClient.getCouponCount(-1L, couponInfoId).getData(); |
| | | Long count2 = appUserClient.getCouponCount(userid, couponInfoId).getData(); |
| | | return count < sendNum && count2 < maxNum; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | return R.ok(returnList); |
| | | return R.ok(collect); |
| | | } |
| | | |
| | | private void count(Long userid, List<CouponInfo> list1, List<CouponInfo> returnList) { |
| | | for (CouponInfo couponInfo : list1) { |
| | | Long count = appUserClient.getCouponCount(userid, couponInfo.getId()).getData(); |
| | | couponInfo.setMaxNum(couponInfo.getMaxNum() - count.intValue()); |
| | | for (int i = 0; i < couponInfo.getMaxNum(); i++) { |
| | | Integer couponInfoId = couponInfo.getId(); |
| | | Integer sendNum = couponInfo.getSendNum(); |
| | | Integer maxNum = couponInfo.getMaxNum(); |
| | | Long count = appUserClient.getCouponCount(-1L, couponInfoId).getData(); |
| | | if(count >= sendNum){ |
| | | continue; |
| | | } |
| | | |
| | | count = appUserClient.getCouponCount(userid, couponInfoId).getData(); |
| | | couponInfo.setMaxNum(maxNum - count.intValue()); |
| | | if(count < maxNum){ |
| | | continue; |
| | | } |
| | | for (int i = 0; i < maxNum; i++) { |
| | | returnList.add(couponInfo); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 根据类型获取有效优惠券列表 |
| | | */ |
| | | @PostMapping("/getCouponInfoByPersonType") |
| | | public R<List<CouponInfo>> getCouponInfoByPersonType(@RequestParam("personType") Integer personType){ |
| | | List<CouponInfo> list = couponInfoService.list(new LambdaUpdateWrapper<CouponInfo>().eq(CouponInfo::getPersonType, personType).eq(CouponInfo::getDelFlag, 0).eq(CouponInfo::getShelfStatus, 1).last(" and now() between period_start_time and period_end_time")); |
| | | return R.ok(list); |
| | | } |
| | | |
| | | |
| | | } |