| | |
| | | package com.ruoyi.account.controller; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.account.api.model.UserCoupon; |
| | |
| | | import io.swagger.annotations.ApiParam; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | public R<Long> getCouponCount(@RequestParam Integer couponId){ |
| | | return R.ok(userCouponService.lambdaQuery().eq(UserCoupon::getCouponId, couponId).count()); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @ResponseBody |
| | | @GetMapping("/getCouponInfoInfo") |
| | | @ApiOperation(value = "获取核销商品券详情", tags = {"小程序-个人中心-门店管理"}) |
| | | public R<UserCoupon> getCouponInfoInfo(String id){ |
| | | UserCoupon userCoupon = userCouponService.getById(id); |
| | | CouponInfo couponInfo = couponClient.detail(userCoupon.getCouponId()).getData(); |
| | | List<Goods> goods = null; |
| | | if("-1".equals(couponInfo.getForGoodIds())){ |
| | | goods = goodsClient.getGoodsByType(2).getData(); |
| | | }else{ |
| | | goods = goodsClient.getGoodsById(couponInfo.getForGoodIds().split(",")).getData(); |
| | | } |
| | | CouponInfoVo couponInfoVo = new CouponInfoVo(); |
| | | BeanUtils.copyProperties(couponInfo, couponInfoVo); |
| | | couponInfoVo.setGoodNames(goods.stream().map(Goods::getName).collect(Collectors.toList())); |
| | | userCoupon.setCouponInfoVo(couponInfoVo); |
| | | return R.ok(userCoupon); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PutMapping("/useCoupon/{id}") |
| | | @ApiOperation(value = "核销商品优惠券", tags = {"小程序-个人中心-门店管理"}) |
| | | public R useCoupon(@PathVariable("id") String id){ |
| | | UserCoupon userCoupon = userCouponService.getById(id); |
| | | if(null == userCoupon){ |
| | | return R.ok("核销码错误"); |
| | | } |
| | | if(userCoupon.getStatus() == 2){ |
| | | return R.ok("优惠券已使用"); |
| | | } |
| | | if(userCoupon.getStatus() == 3){ |
| | | return R.ok("优惠券已过期"); |
| | | } |
| | | userCoupon.setStatus(2); |
| | | userCoupon.setUseTime(LocalDateTime.now()); |
| | | userCouponService.updateById(userCoupon); |
| | | return R.ok(); |
| | | } |
| | | } |
| | | |