| | |
| | | public R<Page<UserCoupon>> minelist(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @ApiParam("1未使用2已使用3已过期") Integer status) { |
| | | Long userid = tokenService.getLoginUserApplet().getUserid(); |
| | | LambdaQueryChainWrapper<UserCoupon> chainWrapper = userCouponService.lambdaQuery() |
| | | .eq(UserCoupon::getAppUserId, userid); |
| | | .eq(UserCoupon::getAppUserId, userid) |
| | | .isNotNull(UserCoupon::getCouponInfo); |
| | | if(null != status && 1 == status){ |
| | | chainWrapper.isNull(UserCoupon::getUseTime).gt(UserCoupon::getEndTime, LocalDateTime.now()); |
| | | } |
| | |
| | | Page<UserCoupon> page = chainWrapper.page(Page.of(pageNum-1, pageSize)); |
| | | for (UserCoupon record : page.getRecords()) { |
| | | record.setIdStr(record.getId().toString()); |
| | | CouponInfo data = couponClient.detail(record.getCouponId()).getData(); |
| | | CouponInfoVo vo = new CouponInfoVo(); |
| | | BeanUtils.copyProperties(data,vo); |
| | | String couponInfo = record.getCouponInfo(); |
| | | CouponInfoVo vo = JSON.parseObject(couponInfo, CouponInfoVo.class); |
| | | // BeanUtils.copyProperties(data,vo); |
| | | //如果是商品券,将商品名称返回 |
| | | if (vo.getCouponType()==4){ |
| | | if (vo != null && vo.getCouponType()==4){ |
| | | List<String> goodNames = new ArrayList<>(); |
| | | if (vo.getForGoodIds().equals("-1")){ |
| | | List<Goods> data1 = goodsClient.getAllGoods().getData(); |
| | | List<String> collect = data1.stream().map(Goods::getName).collect(Collectors.toList()); |
| | | goodNames.addAll(collect); |
| | | }else if(StringUtils.isEmpty(data.getForGoodIds())){ |
| | | goodNames.addAll(JSON.parseArray(data.getGoodsNameJson(), String.class)); |
| | | }else if(StringUtils.isEmpty(vo.getForGoodIds())){ |
| | | goodNames.addAll(JSON.parseArray(vo.getGoodsNameJson(), String.class)); |
| | | }else { |
| | | String[] split = vo.getForGoodIds().split(","); |
| | | R<List<Goods>> goodsById = goodsClient.getGoodsById(split); |
| | |
| | | if (data==null){ |
| | | return R.fail("当前优惠券不存在,请刷新后重试"); |
| | | } |
| | | if(data.getDelFlag() == 1 || data.getShelfStatus() == 0){ |
| | | return R.fail("当前优惠券不存在,请刷新后重试"); |
| | | } |
| | | long count = userCouponService.count(new LambdaQueryWrapper<UserCoupon>().eq(UserCoupon::getCouponId, couponId).eq(UserCoupon::getDelFlag, 0)); |
| | | if(data.getSendNum() <= count){ |
| | | return R.fail("当前优惠券已全部领取完毕"); |
| | |
| | | byId.setLavePoint(byId.getLavePoint() - point); |
| | | appUserService.updateById(byId); |
| | | |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(11); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(point); |
| | | userPoint.setBalance(byId.getLavePoint()); |
| | | userPoint.setAppUserId(userid); |
| | | userPoint.setObjectId(Long.valueOf(data.getId())); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPointService.save(userPoint); |
| | | if(point > 0){ |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(15); |
| | | userPoint.setVariablePoint(point); |
| | | userPoint.setAppUserId(userid); |
| | | userPoint.setObjectId(Long.valueOf(data.getId())); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setChangeDirection(-1); |
| | | userPointService.save(userPoint); |
| | | } |
| | | } |
| | | |
| | | |
| | | //增加优惠券记录,根据时间类型设置开始结束时间 |
| | | UserCoupon userCoupon = new UserCoupon(); |
| | | userCoupon.setAppUserId(userid); |
| | | userCoupon.setCouponInfo(JSON.toJSONString(data)); |
| | | if (data.getPeriodType()==1) { |
| | | userCoupon.setStartTime(data.getPeriodStartTime().atTime(0, 0, 0)); |
| | | userCoupon.setEndTime(data.getPeriodEndTime().atTime(23, 59, 59)); |
| | |
| | | @PostMapping("/getCouponInfo") |
| | | public R<CouponInfoVo> getCouponInfo(@RequestParam("userCouponId") Long userCouponId){ |
| | | UserCoupon userCoupon = userCouponService.getById(userCouponId); |
| | | CouponInfo data = couponClient.detail(userCoupon.getCouponId()).getData(); |
| | | CouponInfoVo couponInfoVo = new CouponInfoVo(); |
| | | BeanUtils.copyProperties(data, couponInfoVo); |
| | | String jsonStr = userCoupon.getCouponInfo(); |
| | | CouponInfoVo couponInfoVo = JSON.parseObject(jsonStr, CouponInfoVo.class); |
| | | return R.ok(couponInfoVo); |
| | | } |
| | | |