Selaa lähdekoodia

我的券包 添加商铺ID查询

lutong 1 kuukausi sitten
vanhempi
commit
7f8e455e35

+ 6 - 4
alien-dining/src/main/java/shop/alien/dining/controller/DiningCouponController.java

@@ -49,7 +49,8 @@ public class DiningCouponController {
             @ApiImplicitParam(name = "size", value = "分页条数", dataType = "Integer", paramType = "query", required = false),
             @ApiImplicitParam(name = "tabType", value = "分页类型(0:全部(未使用),1:即将过期,2:已使用,3:已过期)", dataType = "String", paramType = "query", required = true),
             @ApiImplicitParam(name = "type", value = "券类型(不传:优惠券+代金券都返回,1:仅优惠券查 life_discount_coupon,4:仅代金券查 life_coupon)", dataType = "Integer", paramType = "query", required = false),
-            @ApiImplicitParam(name = "couponType", value = "优惠券类型:1=仅满减券,2=仅折扣券,不传=全部优惠券(可选,仅当type不为4时有效)", dataType = "Integer", paramType = "query", required = false)
+            @ApiImplicitParam(name = "couponType", value = "优惠券类型:1=仅满减券,2=仅折扣券,不传=全部优惠券(可选,仅当type不为4时有效)", dataType = "Integer", paramType = "query", required = false),
+            @ApiImplicitParam(name = "storeId", value = "商铺ID,可为空,传则仅返回该商铺的优惠券", dataType = "String", paramType = "query", required = false)
     })
     public R<List<LifeDiscountCouponVo>> getUserCouponList(
             HttpServletRequest request,
@@ -57,10 +58,11 @@ public class DiningCouponController {
             @RequestParam(value = "size", defaultValue = "10") int size,
             @RequestParam("tabType") String tabType,
             @RequestParam(value = "type", required = false) Integer type,
-            @RequestParam(value = "couponType", required = false) Integer couponType) {
-        log.info("DiningCouponController.getUserCouponList?page={}, size={}, tabType={}, type={}, couponType={}", page, size, tabType, type, couponType);
+            @RequestParam(value = "couponType", required = false) Integer couponType,
+            @RequestParam(value = "storeId", required = false) String storeId) {
+        log.info("DiningCouponController.getUserCouponList?page={}, size={}, tabType={}, type={}, couponType={}, storeId={}", page, size, tabType, type, couponType, storeId);
         String authorization = request.getHeader("Authorization");
-        return diningCouponService.getUserCouponList(authorization, page, size, tabType, type, couponType);
+        return diningCouponService.getUserCouponList(authorization, page, size, tabType, type, couponType, storeId);
     }
 
     /**

+ 3 - 1
alien-dining/src/main/java/shop/alien/dining/feign/AlienStoreFeign.java

@@ -54,6 +54,7 @@ public interface AlienStoreFeign {
      * @param size          每页条数(默认10)
      * @param type          券类型(不传:优惠券+代金券都返回,1:仅优惠券查 life_discount_coupon,4:仅代金券查 life_coupon)(可选)
      * @param couponType    优惠券类型:1=仅满减券,2=仅折扣券,不传=全部优惠券(可选,仅当type不为4时有效)
+     * @param storeId       商铺ID,可为空,传则仅返回该商铺的优惠券
      * @return R.data 为 List&lt;LifeDiscountCouponVo&gt;
      */
     @GetMapping("life-discount-coupon/getUserCouponList")
@@ -63,7 +64,8 @@ public interface AlienStoreFeign {
             @RequestParam(value = "page", defaultValue = "1") int page,
             @RequestParam(value = "size", defaultValue = "10") int size,
             @RequestParam(value = "type", required = false) Integer type,
-            @RequestParam(value = "couponType", required = false) Integer couponType);
+            @RequestParam(value = "couponType", required = false) Integer couponType,
+            @RequestParam(value = "storeId", required = false) String storeId);
 
     /**
      * 根据优惠券 ID 获取优惠券详情(含规则、门槛等)

+ 1 - 1
alien-dining/src/main/java/shop/alien/dining/service/DiningCouponService.java

@@ -28,7 +28,7 @@ public interface DiningCouponService {
      * @param couponType    优惠券类型:1=仅满减券,2=仅折扣券,不传=全部优惠券(可选,仅当type不为4时有效)
      * @return R.data 为 List&lt;LifeDiscountCouponVo&gt;
      */
-    R<List<LifeDiscountCouponVo>> getUserCouponList(String authorization, int page, int size, String tabType, Integer type, Integer couponType);
+    R<List<LifeDiscountCouponVo>> getUserCouponList(String authorization, int page, int size, String tabType, Integer type, Integer couponType, String storeId);
 
     /**
      * 根据优惠券 id 获取优惠券详情

+ 3 - 3
alien-dining/src/main/java/shop/alien/dining/service/impl/DiningCouponServiceImpl.java

@@ -40,8 +40,8 @@ public class DiningCouponServiceImpl implements DiningCouponService {
     private final LifeDiscountCouponMapper lifeDiscountCouponMapper;
 
     @Override
-    public R<List<LifeDiscountCouponVo>> getUserCouponList(String authorization, int page, int size, String tabType, Integer type, Integer couponType) {
-        log.info("DiningCouponService.getUserCouponList page={}, size={}, tabType={}, type={}, couponType={}", page, size, tabType, type, couponType);
+    public R<List<LifeDiscountCouponVo>> getUserCouponList(String authorization, int page, int size, String tabType, Integer type, Integer couponType, String storeId) {
+        log.info("DiningCouponService.getUserCouponList page={}, size={}, tabType={}, type={}, couponType={}, storeId={}", page, size, tabType, type, couponType, storeId);
         try {
             // 参数校验
             if (StringUtils.isEmpty(tabType)) {
@@ -55,7 +55,7 @@ public class DiningCouponServiceImpl implements DiningCouponService {
                 size = 10;
             }
             
-            R<List<LifeDiscountCouponVo>> result = alienStoreFeign.getUserCouponList(authorization, tabType, page, size, type, couponType);
+            R<List<LifeDiscountCouponVo>> result = alienStoreFeign.getUserCouponList(authorization, tabType, page, size, type, couponType, storeId);
             if (result == null) {
                 log.error("Feign调用返回null");
                 return R.fail("获取优惠券列表失败:服务返回为空");

+ 7 - 5
alien-store/src/main/java/shop/alien/store/controller/LifeDiscountCouponController.java

@@ -190,14 +190,16 @@ public class LifeDiscountCouponController {
             @ApiImplicitParam(name = "size", value = "分页条数", dataType = "Integer", paramType = "query", required = false),
             @ApiImplicitParam(name = "tabType", value = "分页类型(0:全部(未使用),1:即将过期,2:已使用,3:已过期)", dataType = "String", paramType = "query", required = true),
             @ApiImplicitParam(name = "type", value = "券类型(不传:优惠券+代金券都返回,1:仅优惠券查 life_discount_coupon,4:仅代金券查 life_coupon)", dataType = "Integer", paramType = "query", required = false),
-            @ApiImplicitParam(name = "couponType", value = "优惠券类型:1=仅满减券,2=仅折扣券,不传=全部优惠券(可选,仅当type不为4时有效)", dataType = "Integer", paramType = "query", required = false)
+            @ApiImplicitParam(name = "couponType", value = "优惠券类型:1=仅满减券,2=仅折扣券,不传=全部优惠券(可选,仅当type不为4时有效)", dataType = "Integer", paramType = "query", required = false),
+            @ApiImplicitParam(name = "storeId", value = "商铺ID,可为空,传则仅返回该商铺的优惠券", dataType = "String", paramType = "query", required = false)
     })
     public R<List<LifeDiscountCouponVo>> getUserCouponList(@ApiIgnore @TokenInfo UserLoginInfo userLoginInfo,
                                                            @RequestParam(value = "tabType") String tabType,
                                                            @RequestParam(defaultValue = "1") int page,
                                                            @RequestParam(defaultValue = "10") int size,
                                                            @RequestParam(required = false) Integer type,
-                                                           @RequestParam(value = "couponType", required = false) Integer couponType) {
+                                                           @RequestParam(value = "couponType", required = false) Integer couponType,
+                                                           @RequestParam(value = "storeId", required = false) String storeId) {
         try {
             // 参数校验
             if (StringUtils.isEmpty(tabType)) {
@@ -216,11 +218,11 @@ public class LifeDiscountCouponController {
                 return R.fail("优惠券类型参数错误,必须为1(满减券)或2(折扣券)");
             }
             
-            log.info("LifeDiscountCouponController.getUserCouponList?userId={}, tabType={}, page={}, size={}, type={}, couponType={}", 
-                    userLoginInfo.getUserId(), tabType, page, size, type, couponType);
+            log.info("LifeDiscountCouponController.getUserCouponList?userId={}, tabType={}, page={}, size={}, type={}, couponType={}, storeId={}", 
+                    userLoginInfo.getUserId(), tabType, page, size, type, couponType, storeId);
             
             List<LifeDiscountCouponVo> storeCouponList = lifeDiscountCouponService.getUserCouponList(
-                    userLoginInfo, page, size, tabType, type, couponType);
+                    userLoginInfo, page, size, tabType, type, couponType, storeId);
             return R.data(storeCouponList);
         } catch (IllegalArgumentException e) {
             log.error("LifeDiscountCouponController.getUserCouponList 参数错误, userId={}, error={}", 

+ 2 - 1
alien-store/src/main/java/shop/alien/store/service/LifeDiscountCouponService.java

@@ -67,8 +67,9 @@ public interface LifeDiscountCouponService extends IService<LifeDiscountCoupon>
      * 获取该用户优惠券列表
      * @param type 不传:优惠券+代金券都返回;1:仅优惠券(查 life_discount_coupon);4:仅代金券(查 life_coupon)
      * @param couponType 优惠券类型:1=满减券,2=折扣券,null=全部优惠券(仅当type不为4时有效)
+     * @param storeId 商铺ID,可为空,传则仅返回该商铺的优惠券
      */
-    List<LifeDiscountCouponVo> getUserCouponList(UserLoginInfo userLoginInfo, int page, int size, String tabType, Integer type, Integer couponType);
+    List<LifeDiscountCouponVo> getUserCouponList(UserLoginInfo userLoginInfo, int page, int size, String tabType, Integer type, Integer couponType, String storeId);
 
     /**
      * 获取所有优惠券列表(分页)

+ 20 - 9
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponServiceImpl.java

@@ -713,10 +713,11 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
      * @param tabType 分页类型:0-全部(未使用),1-即将过期,2-已使用,3-已过期
      * @param type 券类型:1-仅优惠券,4-仅代金券,null-全部
      * @param couponType 优惠券类型:1-满减券,2-折扣券,null-全部(仅当type不为4时有效)
+     * @param storeId 商铺ID,可为空,传则仅返回该商铺的优惠券
      * @return 优惠券列表
      */
     @Override
-    public List<LifeDiscountCouponVo> getUserCouponList(UserLoginInfo userLoginInfo, int page, int size, String tabType, Integer type, Integer couponType) {
+    public List<LifeDiscountCouponVo> getUserCouponList(UserLoginInfo userLoginInfo, int page, int size, String tabType, Integer type, Integer couponType, String storeId) {
         // 参数校验
         if (userLoginInfo == null || StringUtils.isEmpty(userLoginInfo.getUserId())) {
             throw new IllegalArgumentException("用户信息不能为空");
@@ -781,7 +782,7 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
         
         // type=4:仅代金券,查询 life_coupon 表
         if (type != null && type == 4) {
-            return processVoucherCoupons(records, zoneId, localNow);
+            return processVoucherCoupons(records, zoneId, localNow, storeId);
         }
 
         // type=1 或 type=null:优惠券(或混合),查询 life_discount_coupon
@@ -797,6 +798,10 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
         if (couponType != null) {
             couponQueryWrapper.eq(LifeDiscountCoupon::getCouponType, couponType);
         }
+        // 商铺ID检索:传则仅返回该商铺的优惠券
+        if (!StringUtils.isEmpty(storeId)) {
+            couponQueryWrapper.eq(LifeDiscountCoupon::getStoreId, storeId);
+        }
         List<LifeDiscountCoupon> lifeDiscountCoupons = lifeDiscountCouponMapper.selectList(couponQueryWrapper);
         
         // 如果type=1且没有查询到优惠券,直接返回
@@ -821,8 +826,11 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
                     .filter(Objects::nonNull)
                     .collect(Collectors.toList());
             if (!voucherIdList.isEmpty()) {
-                lifeCouponsForMerge = lifeCouponMapper.selectList(
-                        new LambdaQueryWrapper<LifeCoupon>().in(LifeCoupon::getId, voucherIdList));
+                LambdaQueryWrapper<LifeCoupon> voucherWrapper = new LambdaQueryWrapper<LifeCoupon>().in(LifeCoupon::getId, voucherIdList);
+                if (!StringUtils.isEmpty(storeId)) {
+                    voucherWrapper.eq(LifeCoupon::getStoreId, storeId);
+                }
+                lifeCouponsForMerge = lifeCouponMapper.selectList(voucherWrapper);
                 List<String> voucherStoreIds = lifeCouponsForMerge.stream()
                         .map(LifeCoupon::getStoreId)
                         .filter(s -> !StringUtils.isEmpty(s))
@@ -877,8 +885,8 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
     /**
      * 处理代金券列表(type=4时使用)
      */
-    private List<LifeDiscountCouponVo> processVoucherCoupons(List<LifeDiscountCouponUser> records, 
-                                                               ZoneId zoneId, LocalDate localNow) {
+    private List<LifeDiscountCouponVo> processVoucherCoupons(List<LifeDiscountCouponUser> records,
+                                                               ZoneId zoneId, LocalDate localNow, String storeId) {
         List<LifeDiscountCouponVo> result = new ArrayList<>();
         List<String> voucherIdList = records.stream()
                 .map(LifeDiscountCouponUser::getVoucherId)
@@ -887,9 +895,12 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
         if (voucherIdList.isEmpty()) {
             return result;
         }
-        
-        List<LifeCoupon> lifeCoupons = lifeCouponMapper.selectList(
-                new LambdaQueryWrapper<LifeCoupon>().in(LifeCoupon::getId, voucherIdList));
+
+        LambdaQueryWrapper<LifeCoupon> voucherWrapper = new LambdaQueryWrapper<LifeCoupon>().in(LifeCoupon::getId, voucherIdList);
+        if (!StringUtils.isEmpty(storeId)) {
+            voucherWrapper.eq(LifeCoupon::getStoreId, storeId);
+        }
+        List<LifeCoupon> lifeCoupons = lifeCouponMapper.selectList(voucherWrapper);
         List<String> storeIdList = lifeCoupons.stream()
                 .map(LifeCoupon::getStoreId)
                 .filter(s -> !StringUtils.isEmpty(s))