| | |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.account.api.feignClient.AppUserClient; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDate; |
| | | import java.util.Arrays; |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | |
| | | @ApiOperation(value = "优惠劵管理-详情", tags = {"管理后台-活动管理"}) |
| | | public R<CouponInfo> detail(@RequestParam("id") Integer id) { |
| | | CouponInfo byId = couponInfoService.getById(id); |
| | | byId.setGoodsNameList(JSON.parseArray(byId.getGoodsNameJson(), String.class)); |
| | | String forGoodIds = byId.getForGoodIds(); |
| | | if (StringUtils.isNotEmpty(forGoodIds)){ |
| | | if (!"-1".equals(forGoodIds) && StringUtils.isNotEmpty(forGoodIds)){ |
| | | List<Goods> goods = goodsService.listByIds(Arrays.asList(forGoodIds.split(","))); |
| | | byId.setGoods(goods); |
| | | byId.setGoodsNameList(goods.stream().map(Goods::getName).collect(Collectors.toList())); |
| | | } |
| | | String personIds = byId.getPersonIds(); |
| | | if (StringUtils.isNotEmpty(personIds)){ |
| | |
| | | public R<Void> edit(@RequestBody CouponInfo couponInfo) { |
| | | List<String> goodsNameList = couponInfo.getGoodsNameList(); |
| | | couponInfo.setGoodsNameJson(JSON.toJSONString(goodsNameList)); |
| | | if(couponInfo.getPeriodType() == 2){ |
| | | Integer periodDays = couponInfo.getPeriodDays(); |
| | | couponInfo.setPeriodStartTime(LocalDate.now()); |
| | | couponInfo.setPeriodEndTime(LocalDate.now().plusDays(periodDays)); |
| | | } |
| | | couponInfoService.updateById(couponInfo); |
| | | return R.ok(); |
| | | } |
| | |
| | | couponInfo.setShelfStatus(0); |
| | | List<String> goodsNameList = couponInfo.getGoodsNameList(); |
| | | couponInfo.setGoodsNameJson(JSON.toJSONString(goodsNameList)); |
| | | couponInfo.setShelfStatus(1); |
| | | if(couponInfo.getPeriodType() == 2){ |
| | | Integer periodDays = couponInfo.getPeriodDays(); |
| | | couponInfo.setPeriodStartTime(LocalDate.now()); |
| | | couponInfo.setPeriodEndTime(LocalDate.now().plusDays(periodDays)); |
| | | } |
| | | couponInfoService.save(couponInfo); |
| | | return R.ok(); |
| | | } |
| | |
| | | //查出指定人员可领取优惠券 |
| | | 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> 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).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); |
| | | |
| | | |
| | | return R.ok(returnList); |
| | | } |
| | | |
| | | private void count(Long userid, List<CouponInfo> list1, List<CouponInfo> returnList) { |
| | | for (CouponInfo couponInfo : list1) { |
| | | Long count = appUserClient.getCouponCount(userid, couponInfo.getId()).getData(); |
| | | Long count = appUserClient.getCouponCount(-1L, couponInfo.getId()).getData(); |
| | | if(couponInfo.getSendNum() <= count){ |
| | | couponInfo.setMaxNum(count.intValue() - couponInfo.getSendNum()); |
| | | for (int i = 0; i < couponInfo.getMaxNum(); i++) { |
| | | returnList.add(couponInfo); |
| | | } |
| | | continue; |
| | | } |
| | | count = appUserClient.getCouponCount(userid, couponInfo.getId()).getData(); |
| | | couponInfo.setMaxNum(couponInfo.getMaxNum() - count.intValue()); |
| | | for (int i = 0; i < couponInfo.getMaxNum(); i++) { |
| | | returnList.add(couponInfo); |
| | |
| | | |
| | | @GetMapping("/getReceiveRecord") |
| | | public R<IPage<UserCoupon>> getReceiveRecord(@ApiParam("页码") @RequestParam Integer pageNum, @ApiParam("大小") Integer pageSize,UserCoupon userCoupon) { |
| | | // TODO 待完善 |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据类型获取有效优惠券列表 |
| | | */ |
| | | @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); |
| | | } |
| | | |
| | | |
| | | } |
| | | |