| | |
| | | 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.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.account.api.model.UserCoupon; |
| | |
| | | import com.ruoyi.other.api.domain.PointSetting; |
| | | import com.ruoyi.other.api.feignClient.GoodsClient; |
| | | import com.ruoyi.other.api.feignClient.PointSettingClient; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | @ApiOperation(value = "已领取列表", tags = {"小程序-个人中心-优惠劵"}) |
| | | public R<Page<UserCoupon>> minelist(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @ApiParam("1未使用2已使用3已过期") Integer status) { |
| | | Long userid = tokenService.getLoginUserApplet().getUserid(); |
| | | Page<UserCoupon> page = userCouponService.lambdaQuery() |
| | | .isNull(status!=null&&(status==1||status==3),UserCoupon::getUseTime) |
| | | .isNotNull(status!=null&&status==2,UserCoupon::getUseTime) |
| | | .lt(status!=null&&status==3,UserCoupon::getEndTime, LocalDateTime.now()) |
| | | .eq(UserCoupon::getAppUserId, userid).page(Page.of(pageNum-1, pageSize)); |
| | | LambdaQueryChainWrapper<UserCoupon> chainWrapper = userCouponService.lambdaQuery() |
| | | .eq(UserCoupon::getAppUserId, userid); |
| | | if(null != status && 1 == status){ |
| | | chainWrapper.isNull(UserCoupon::getUseTime).gt(UserCoupon::getEndTime, LocalDateTime.now()); |
| | | } |
| | | if(null != status && 2 == status){ |
| | | chainWrapper.isNotNull(UserCoupon::getUseTime); |
| | | } |
| | | if(null != status && 3 == status){ |
| | | chainWrapper.isNull(UserCoupon::getUseTime).lt(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(); |
| | |
| | | if (vo.getCouponType()==4){ |
| | | List<String> goodNames = new ArrayList<>(); |
| | | if (vo.getForGoodIds().equals("-1")){ |
| | | goodNames.add("全部商品"); |
| | | }else{ |
| | | 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 { |
| | | String[] split = vo.getForGoodIds().split(","); |
| | | R<List<Goods>> goodsById = goodsClient.getGoodsById(split); |
| | | if (goodsById.getData()!=null){ |
| | |
| | | goodNames.add(datum.getName()); |
| | | } |
| | | } |
| | | vo.setGoodNames(goodNames); |
| | | } |
| | | vo.setGoodNames(goodNames); |
| | | } |
| | | |
| | | record.setCouponInfoVo(vo); |
| | | if (record.getUseTime()==null){ |
| | | record.setStatus(1); |
| | | if (record.getEndTime().isBefore(LocalDateTime.now())){ |
| | | record.setStatus(3); |
| | | } |
| | | }else { |
| | | if(null != record.getUseTime()){ |
| | | record.setStatus(2); |
| | | }else{ |
| | | if(record.getEndTime().isBefore(LocalDateTime.now())){ |
| | | record.setStatus(3); |
| | | }else{ |
| | | record.setStatus(1); |
| | | } |
| | | } |
| | | |
| | | AppUser appUser = appUserService.getById(record.getAppUserId()); |
| | | record.setUserName(appUser.getName()); |
| | | record.setPhone(appUser.getPhone()); |
| | |
| | | |
| | | @GetMapping("/mine/list1") |
| | | @ApiOperation(value = "已领取列表", tags = {"管理后台-优惠劵"}) |
| | | public R<Page<UserCoupon>> list1(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @ApiParam("1未使用2已使用3已过期") Integer status, Integer id) { |
| | | public R<Page<UserCoupon>> list1(@RequestParam Integer pageNum, |
| | | @RequestParam Integer pageSize, |
| | | String userName, |
| | | @ApiParam("1未使用2已使用3已过期") Integer status, |
| | | String phone, |
| | | Integer id) { |
| | | |
| | | LambdaQueryWrapper<AppUser> queryWrapper = new LambdaQueryWrapper<>(); |
| | | |
| | | if (!StringUtils.isEmpty(phone)) { |
| | | queryWrapper.like(AppUser::getPhone, phone); |
| | | } |
| | | if (!StringUtils.isEmpty(userName)) { |
| | | queryWrapper.like(AppUser::getName, userName); |
| | | } |
| | | |
| | | List<AppUser> appUserList = appUserService.list(queryWrapper); |
| | | |
| | | if (CollectionUtils.isEmpty(appUserList)) { |
| | | return R.ok(Page.of(pageNum, pageSize)); |
| | | } |
| | | |
| | | List<Long> appUserIds = appUserList.stream().map(AppUser::getId).distinct().collect(Collectors.toList()); |
| | | |
| | | |
| | | Page<UserCoupon> page = userCouponService.lambdaQuery() |
| | | .isNull(status!=null&&(status==1||status==3),UserCoupon::getUseTime) |
| | | .isNotNull(status!=null&&status==2,UserCoupon::getUseTime) |
| | | .eq(UserCoupon::getCouponId, id) |
| | | .in(!CollectionUtils.isEmpty(appUserIds),UserCoupon::getAppUserId, appUserIds) |
| | | .lt(status!=null&&status==3,UserCoupon::getEndTime, LocalDateTime.now()).page(Page.of(pageNum-1, pageSize)); |
| | | for (UserCoupon record : page.getRecords()) { |
| | | record.setIdStr(record.getId().toString()); |
| | |
| | | appUserService.updateById(byId); |
| | | |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(11); |
| | | userPoint.setType(15); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(point); |
| | | userPoint.setBalance(byId.getLavePoint()); |
| | |
| | | userCouponService.updateById(userCoupon); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取用户优惠券详情 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @PostMapping("/getUserCoupon") |
| | | public R<UserCoupon> getUserCoupon(@RequestParam("id") Long id){ |
| | | UserCoupon userCoupon = userCouponService.getById(id); |
| | | return R.ok(userCoupon); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 编辑用户优惠券 |
| | | * @return |
| | | */ |
| | | @PostMapping("/editUserCoupon") |
| | | public R editUserCoupon(@RequestBody UserCoupon userCoupon){ |
| | | userCouponService.updateById(userCoupon); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 编辑用户优惠券使用时间 |
| | | * @param userCoupon |
| | | * @return |
| | | */ |
| | | @PostMapping("/editReturnUse") |
| | | public R editReturnUse(@RequestBody UserCoupon userCoupon){ |
| | | userCouponService.update(new LambdaUpdateWrapper<UserCoupon>().eq(UserCoupon::getId, userCoupon.getId()) |
| | | .set(UserCoupon::getUseTime, userCoupon.getUseTime())); |
| | | return R.ok(); |
| | | } |
| | | } |
| | | |