lutong 2 өдөр өмнө
parent
commit
89ec91ab97

+ 3 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/LifeDiscountCouponVo.java

@@ -54,6 +54,9 @@ public class LifeDiscountCouponVo {
     @ApiModelProperty(value = "已领取数量")
     private Integer quantityClaimed;
 
+    @ApiModelProperty(value = "好友赠券场景下,本店铺当前可支配数量(life_discount_coupon_store_friend.single_qty 按本店账号汇总)")
+    private Integer ownedQuantity;
+
     @ApiModelProperty(value = "券名称")
     private String name;
 

+ 23 - 0
alien-store/src/main/java/shop/alien/store/controller/LifeDiscountCouponController.java

@@ -114,6 +114,29 @@ public class LifeDiscountCouponController {
         return R.success("切换成功");
     }
 
+    @ApiOperation("获取优惠券详情(含好友赠券本店铺拥有数量)")
+    @ApiOperationSupport(order = 55)
+    @GetMapping("/getCouponDetailWithOwnedQty")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "couponId", value = "优惠券id(life_discount_coupon.id)", dataType = "String", paramType = "query", required = true),
+            @ApiImplicitParam(name = "storeId", value = "店铺id(store_info.id)", dataType = "String", paramType = "query", required = true)
+    })
+    public R<LifeDiscountCouponVo> getCouponDetailWithOwnedQty(@ApiIgnore @TokenInfo UserLoginInfo userLoginInfo,
+                                                               @RequestParam(value = "couponId") String couponId,
+                                                               @RequestParam(value = "storeId") String storeId) {
+        log.info("LifeDiscountCouponController.getCouponDetailWithOwnedQty?couponId={}, storeId={}", couponId, storeId);
+        try {
+            LifeDiscountCouponVo vo = lifeDiscountCouponService.getCouponDetailWithFriendOwnedQty(couponId, storeId);
+            if (vo == null) {
+                return R.fail("优惠券不存在或参数无效");
+            }
+            return R.data(vo);
+        } catch (Exception e) {
+            log.error("LifeDiscountCouponController.getCouponDetailWithOwnedQty ERROR Msg={}", e.getMessage(), e);
+            return R.fail("查询失败");
+        }
+    }
+
     @ApiOperation("获取该优惠券的明细信息")
     @ApiOperationSupport(order = 5)
     @GetMapping("/getCounponDetailById")

+ 9 - 0
alien-store/src/main/java/shop/alien/store/service/LifeDiscountCouponService.java

@@ -52,6 +52,15 @@ public interface LifeDiscountCouponService extends IService<LifeDiscountCoupon>
     LifeDiscountCouponVo getCounponDetailById(String counponId, UserLoginInfo userLoginInfo);
 
     /**
+     * 优惠券详情 + 好友赠券场景下本店铺拥有数量(store_info.id 下所有 store_user 在赠券表中 single_qty 之和,仅统计已发布 release_type=1)
+     *
+     * @param couponId 优惠券主键 life_discount_coupon.id
+     * @param storeId  店铺 id(store_info.id)
+     * @return 详情 VO,含 ownedQuantity;券不存在或参数非法时返回 null
+     */
+    LifeDiscountCouponVo getCouponDetailWithFriendOwnedQty(String couponId, String storeId);
+
+    /**
      * 获取该用户该店铺优惠券列表
      * @param couponType 优惠券类型:1=满减券,2=折扣券,null=全部优惠券
      */

+ 49 - 0
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponServiceImpl.java

@@ -67,6 +67,8 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
 
     private final StoreInfoMapper storeInfoMapper;
 
+    private final StoreUserMapper storeUserMapper;
+
     private final LifeDiscountCouponQuantumRulesService lifeDiscountCouponQuantumRulesService;
 
     private final LifeDiscountCouponUserService lifeDiscountCouponUserService;
@@ -430,6 +432,53 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
         return lifeDiscountCouponVo;
     }
 
+    @Override
+    public LifeDiscountCouponVo getCouponDetailWithFriendOwnedQty(String couponId, String storeId) {
+        if (StringUtils.isEmpty(couponId) || StringUtils.isEmpty(storeId)) {
+            return null;
+        }
+        int couponIdInt;
+        int storeIdInt;
+        try {
+            couponIdInt = Integer.parseInt(couponId.trim());
+            storeIdInt = Integer.parseInt(storeId.trim());
+        } catch (NumberFormatException e) {
+            return null;
+        }
+        if (lifeDiscountCouponMapper.selectById(couponIdInt) == null) {
+            return null;
+        }
+
+        LifeDiscountCouponVo vo = getCounponDetailById(String.valueOf(couponIdInt), null);
+
+        int owned = 0;
+        List<StoreUser> storeUsers = storeUserMapper.selectList(new LambdaQueryWrapper<StoreUser>()
+                .eq(StoreUser::getStoreId, storeIdInt)
+                .eq(StoreUser::getDeleteFlag, 0));
+        if (CollectionUtils.isNotEmpty(storeUsers)) {
+            List<Integer> userIds = storeUsers.stream()
+                    .map(StoreUser::getId)
+                    .filter(Objects::nonNull)
+                    .distinct()
+                    .collect(Collectors.toList());
+            if (CollectionUtils.isNotEmpty(userIds)) {
+                List<LifeDiscountCouponStoreFriend> rows = lifeDiscountCouponStoreFriendMapper.selectList(
+                        new LambdaQueryWrapper<LifeDiscountCouponStoreFriend>()
+                                .eq(LifeDiscountCouponStoreFriend::getCouponId, couponIdInt)
+                                .in(LifeDiscountCouponStoreFriend::getStoreUserId, userIds)
+                                .eq(LifeDiscountCouponStoreFriend::getReleaseType, 1));
+                for (LifeDiscountCouponStoreFriend row : rows) {
+                    if (row.getSingleQty() != null) {
+                        owned += row.getSingleQty();
+                    }
+                }
+            }
+        }
+
+        vo.setOwnedQuantity(owned);
+        return vo;
+    }
+
     public static Date addDaysToDateJava8(Date date, int days) {
         // 将Date转换为Instant
         Instant instant = date.toInstant();