|
|
@@ -3,8 +3,10 @@ package com.cyksj.web.controller.coupon;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
+import com.cyksj.mapper.manage.coupon.CouponSkuMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponUserMapper;
|
|
|
import com.cyksj.model.entity.Coupon;
|
|
|
import com.cyksj.model.entity.CouponUser;
|
|
|
@@ -24,7 +26,6 @@ import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.List;
|
|
|
|
|
|
/*
|
|
|
*项目名: netflix
|
|
|
@@ -44,29 +45,20 @@ public class CouponFrontController {
|
|
|
|
|
|
private final RedisService redisService;
|
|
|
|
|
|
+ private final CouponSkuMapper couponSkuMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 优惠卷领取中心列表
|
|
|
*/
|
|
|
@GetMapping("/center/list")
|
|
|
- public Result<SearchResult<CouponActiveView>> couponCenterList(HttpServletRequest request) {
|
|
|
+ public Result<Page<CouponActiveView>> couponCenterList(@RequestParam(defaultValue = "1") Long start, @RequestParam(defaultValue = "5") Long limit) {
|
|
|
Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
- SearchResult<CouponActiveView> search = beanSearcher.search(CouponActiveView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
- search.getDataList().forEach(data -> {
|
|
|
- CouponUser couponUser = couponUserMapper.selectOne(Wrappers.lambdaQuery(CouponUser.class).eq(CouponUser::getCouponId, data.getCouponId()).eq(CouponUser::getUserId, userId).select(CouponUser::getId).last("limit 1"));
|
|
|
- if (couponUser == null) {
|
|
|
- if (data.getRemainNum() <= 0) {
|
|
|
- //已领完
|
|
|
- data.setCouponStatus(CouponActiveView.CouponStatus.over);
|
|
|
- } else {
|
|
|
- //待领取
|
|
|
- data.setCouponStatus(CouponActiveView.CouponStatus.collecting);
|
|
|
- }
|
|
|
- } else {
|
|
|
- //已领取
|
|
|
- data.setCouponStatus(CouponActiveView.CouponStatus.received);
|
|
|
- }
|
|
|
+ Page<CouponActiveView> page = couponUserMapper.couponCenterList(userId, new Page<>(start, limit));
|
|
|
+ page.getRecords().forEach(data -> {
|
|
|
+ String str = couponSkuMapper.selectGoodsSkuStr(data.getCouponId());
|
|
|
+ data.setGoodsSkuStr(str.replaceAll(",", "/").replaceAll(";", ""));
|
|
|
});
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(page);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -85,16 +77,20 @@ public class CouponFrontController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 可用优惠卷
|
|
|
+ * 可用优惠卷展示数量
|
|
|
*/
|
|
|
- @GetMapping("/available/list")
|
|
|
- public Result<SearchResult<CouponUserView>> availableCouponList(Long skuId, Boolean isRenew) {
|
|
|
+ @GetMapping("/available/num")
|
|
|
+ public Result<Integer> availableCouponNum(Long skuId, Boolean isRenew) {
|
|
|
Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
Integer count = couponUserMapper.countAvailableCouponList(skuId, userId, isRenew);
|
|
|
- List<CouponUserView> couponActiveViewList = couponFontService.getAvailableCouponList(skuId, userId, isRenew);
|
|
|
- SearchResult<CouponUserView> couponUserViews = new SearchResult<>(couponActiveViewList);
|
|
|
- couponUserViews.setTotalCount(count);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(couponUserViews);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(count);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/available/list")
|
|
|
+ public Result<Page<CouponUserView>> availableCouponList(Long skuId, Boolean isRenew, @RequestParam(defaultValue = "1") Long start, @RequestParam(defaultValue = "5") Long limit) {
|
|
|
+ Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
+ Page<CouponUserView> couponActiveViewList = couponFontService.getAvailableCouponList(skuId, userId, isRenew, start, limit);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(couponActiveViewList);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -123,6 +119,8 @@ public class CouponFrontController {
|
|
|
//已领取
|
|
|
data.setCouponStatus(CouponActiveView.CouponStatus.received);
|
|
|
}
|
|
|
+ String str = couponSkuMapper.selectGoodsSkuStr(data.getCouponId());
|
|
|
+ data.setGoodsSkuStr(str.replaceAll(",", "/").replaceAll(";", ""));
|
|
|
});
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|