Преглед на файлове

fix 优惠卷前端展示

zoujiajian преди 3 години
родител
ревизия
17a1f13d72

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/mapper/manage/coupon/CouponActiveMapper.java

@@ -15,6 +15,6 @@ public interface CouponActiveMapper extends BaseMapper<CouponActive> {
 	@Update("update coupon_active set deleted = false where coupon_id = #{id}")
 	void deleteByCouponId(Long id);
 
-	@Update("update coupon_active set remain_num = remain - 1 where id = #{id} and  remain_num = #{remainNum} and remain_num > 0")
+	@Update("update coupon_active set remain_num = remain_num - 1 where id = #{id} and  remain_num = #{remainNum} and remain_num > 0")
 	Integer subRemainNum(@Param("id") Long id, @Param("remainNum") Integer remainNum);
 }

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/mapper/manage/coupon/CouponSkuMapper.java

@@ -2,6 +2,7 @@ package com.cyksj.mapper.manage.coupon;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.cyksj.model.entity.CouponSku;
+import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
 
 /*
@@ -14,4 +15,8 @@ public interface CouponSkuMapper extends BaseMapper<CouponSku> {
 
 	@Update("update coupon_sku set deleted = false where coupon_id = #{id}")
 	void deleteByCid(Long id);
+
+	@Select("select GROUP_CONCAT(gd.title, gdk.spec_val) from `coupon_sku` ck left join `goods_don` gd on gd.id = ck.goods_id" +
+			" left join `goods_don_sku` gdk on gdk.id = ck.sku_id where ck.coupon_id = #{couponId} and ck.deleted is true")
+	String selectGoodsSkuStr(Long couponId);
 }

+ 6 - 3
netflix-dao/src/main/java/com/cyksj/mapper/manage/coupon/CouponUserMapper.java

@@ -1,12 +1,13 @@
 package com.cyksj.mapper.manage.coupon;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.cyksj.model.entity.CouponUser;
+import com.cyksj.model.views.CouponActiveView;
 import com.cyksj.model.views.CouponUserView;
 import org.apache.ibatis.annotations.Param;
 
-import java.util.List;
-
 /*
  *项目名: netflix
  *文件名: CouponUserMapper
@@ -14,7 +15,9 @@ import java.util.List;
  *创建时间:2022/11/18 11:43
  */
 public interface CouponUserMapper extends BaseMapper<CouponUser> {
-	List<CouponUserView> getAvailableCouponList(@Param("skuId") Long skuId, @Param("userId") Long userId, @Param("isRenew") Boolean isRenew);
+	Page<CouponUserView> getAvailableCouponList(@Param("skuId") Long skuId, @Param("userId") Long userId, @Param("isRenew") Boolean isRenew, IPage<CouponUserView> page);
 
 	Integer countAvailableCouponList(@Param("skuId") Long skuId, @Param("userId") Long userId, @Param("isRenew") Boolean isRenew);
+
+	Page<CouponActiveView> couponCenterList(@Param("userId") Long userId, IPage<CouponUserView> page);
 }

+ 9 - 0
netflix-dao/src/main/java/com/cyksj/model/views/CouponActiveView.java

@@ -4,6 +4,7 @@ import com.cyksj.model.entity.Coupon;
 import com.ejlchina.searcher.bean.DbField;
 import com.ejlchina.searcher.bean.DbIgnore;
 import com.ejlchina.searcher.bean.SearchBean;
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -72,6 +73,9 @@ public class CouponActiveView {
 	@DbField("c.goods_sku_ids")
 	private String goodsSkuIds;
 
+	@DbIgnore
+	private String goodsSkuStr;
+
 	/**
 	 * 是否是有效时间
 	 */
@@ -141,6 +145,10 @@ public class CouponActiveView {
 	@DbIgnore
 	private CouponStatus couponStatus;
 
+	@DbIgnore
+	@JsonIgnore
+	private Integer order;
+
 	@DbField("ca.created_time")
 	private Date createdTime;
 
@@ -149,6 +157,7 @@ public class CouponActiveView {
 		collecting("collecting", "待领取"),
 		received("received", "已领取"),
 		over("over", "已领完"),
+		stop("stop", "停止领取"),
 		;
 		private String status;
 		private String desc;

+ 10 - 1
netflix-dao/src/main/java/com/cyksj/model/views/CouponRecommendView.java

@@ -19,7 +19,7 @@ import java.util.Date;
 @Setter
 @Getter
 @SearchBean(tables = "coupon_recommend cr left join coupon c on c.id = cr.coupon_id",
-		where = "cr.deleted is true and c.deleted is true")
+		where = "cr.deleted is true and c.deleted is true and cr.status is true")
 public class CouponRecommendView {
 	@DbField("cr.id")
 	private Long id;
@@ -57,6 +57,15 @@ public class CouponRecommendView {
 	@DbField("c.discount")
 	private BigDecimal discount;
 
+	/**
+	 * 平台规格集合
+	 */
+	@DbField("c.goods_sku_ids")
+	private String goodsSkuIds;
+
+	@DbIgnore
+	private String goodsSkuStr;
+
 	/**
 	 * 领取人范围
 	 */

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/model/views/CouponUserView.java

@@ -91,6 +91,9 @@ public class CouponUserView {
 	@DbField("c.goods_sku_ids")
 	private String goodsSkuIds;
 
+	@DbIgnore
+	private String goodsSkuStr;
+
 	/**
 	 * 是否是有效时间
 	 */

+ 43 - 0
netflix-dao/src/main/resources/mapper/CouponUserMapper.xml

@@ -5,6 +5,7 @@
 
     <select id="getAvailableCouponList" resultType="com.cyksj.model.views.CouponUserView">
         select distinct cu.id,
+                        cp.id as coupon_id,
                         cp.name,
                         cp.goods_type,
                         cp.type,
@@ -42,4 +43,46 @@
             and cp.is_renew = #{isRenew}
         </if>
     </select>
+
+    <select id="couponCenterList" resultType="com.cyksj.model.views.CouponActiveView">
+        select ca.id,
+               c.id as coupon_id,
+               c.name,
+               c.goods_type,
+               c.type,
+               c.reduce_money,
+               c.discount,
+               c.scope,
+               c.goods_sku_ids,
+               c.is_valid_time,
+               c.valid_start_time,
+               c.valid_end_time,
+               c.valid_days,
+               c.is_renew,
+               ca.num,
+               ca.`status`,
+               ca.expiry_status,
+               ca.remain_num,
+               (case
+                    when ca.expiry_status = 0 then 'stop'
+                    when ca.`status` = 0 then 'stop'
+                    when ca.remain_num &lt;= 0 then 'over'
+                    when cu.id is null then 'collecting'
+                    when cu.id is not null
+                        then 'received' end)                                                                     as couponStatus,
+               (case
+                    when ca.expiry_status = 0 then 2
+                    when ca.`status` = 0 then 2
+                    when remain_num &lt;= 0 then 3
+                    when cu.id is null then 0
+                    when cu.id is not null
+                        then 1 end)                                                                              as `order`
+        from coupon_active ca
+                 left join coupon c
+                           on c.id = ca.coupon_id
+                 left join coupon_user cu on cu.coupon_id = c.id and cu.user_id = #{userId}
+        where ca.deleted is true
+          and c.deleted is true
+        order by `order`
+    </select>
 </mapper>

+ 2 - 3
netflix-service/src/main/java/com/cyksj/service/coupon/CouponFontService.java

@@ -1,12 +1,11 @@
 package com.cyksj.service.coupon;
 
 import cn.hutool.core.date.DateTime;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.cyksj.model.request.CouponCollectReq;
 import com.cyksj.model.views.CouponUserView;
 import com.ejlchina.searcher.SearchResult;
 
-import java.util.List;
-
 /*
  *项目名: netflix
  *文件名: CouponFontService
@@ -37,7 +36,7 @@ public interface CouponFontService {
 	/**
 	 * 可用/不可用优惠卷
 	 */
-	List<CouponUserView> getAvailableCouponList(Long skuId, Long userId, Boolean isRenew);
+	Page<CouponUserView> getAvailableCouponList(Long skuId, Long userId, Boolean isRenew, Long start, Long limit);
 
 	/**
 	 * 优惠卷状态

+ 12 - 4
netflix-service/src/main/java/com/cyksj/service/coupon/impl/CouponFontServiceImpl.java

@@ -3,11 +3,13 @@ package com.cyksj.service.coupon.impl;
 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.common.annotation.NoSubmit;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
 import com.cyksj.mapper.manage.coupon.CouponActiveMapper;
 import com.cyksj.mapper.manage.coupon.CouponMapper;
+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.CouponActive;
@@ -48,6 +50,8 @@ public class CouponFontServiceImpl implements CouponFontService {
 
 	private final BeanSearcher beanSearcher;
 
+	private final CouponSkuMapper couponSkuMapper;
+
 	private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
 
 	@Override
@@ -143,20 +147,24 @@ public class CouponFontServiceImpl implements CouponFontService {
 				data.setValidEndTime(DateUtil.offsetDay(data.getValidStartTime(), data.getValidDays()));
 			}
 			this.setCouponUserStatus(data, now);
+			String str = couponSkuMapper.selectGoodsSkuStr(data.getCouponId());
+			data.setGoodsSkuStr(str.replaceAll(",", "/").replaceAll(";", ""));
 		});
 	}
 
 	@Override
-	public List<CouponUserView> getAvailableCouponList(Long skuId, Long userId, Boolean isRenew) {
+	public Page<CouponUserView> getAvailableCouponList(Long skuId, Long userId, Boolean isRenew, Long start, Long limit) {
 		DateTime now = DateTime.now();
-		List<CouponUserView> availableCouponList = couponUserMapper.getAvailableCouponList(skuId, userId, isRenew);
-		Optional.ofNullable(availableCouponList).ifPresent(list->{
-			list.stream().forEach(data->{
+		Page<CouponUserView> availableCouponList = couponUserMapper.getAvailableCouponList(skuId, userId, isRenew, new Page<>(start, limit));
+		Optional.ofNullable(availableCouponList).ifPresent(page->{
+			page.getRecords().stream().forEach(data->{
 				if (!data.getIsValidTime()) {
 					data.setValidStartTime(data.getCreatedTime());
 					data.setValidEndTime(DateUtil.offsetDay(data.getValidStartTime(), data.getValidDays()));
 				}
 				this.setCouponUserStatus(data, now);
+				String str = couponSkuMapper.selectGoodsSkuStr(data.getCouponId());
+				data.setGoodsSkuStr(str.replaceAll(",", "/").replaceAll(";", ""));
 			});
 		});
 		return availableCouponList;

+ 23 - 25
netflix-web/src/main/java/com/cyksj/web/controller/coupon/CouponFrontController.java

@@ -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);
 	}