You've already forked FrameTour-BE
feat(coupon): 添加景区ID过滤功能以查询用户可用优惠券
- 在getUserCoupons接口中添加scenicId参数支持 - 修改couponService实现以按景区ID过滤优惠券 - 添加空值检查跳过无效配置的优惠券 - 更新接口文档添加scenicId参数说明
This commit is contained in:
@@ -58,13 +58,13 @@ public class PriceCalculationController {
|
|||||||
* 查询用户可用优惠券(包含领取记录信息)
|
* 查询用户可用优惠券(包含领取记录信息)
|
||||||
*/
|
*/
|
||||||
@GetMapping("/coupons/my-coupons")
|
@GetMapping("/coupons/my-coupons")
|
||||||
public ApiResponse<List<UserCouponResp>> getUserCoupons() {
|
public ApiResponse<List<UserCouponResp>> getUserCoupons(@RequestParam(required = false) String scenicId) {
|
||||||
Long userId = getUserId();
|
Long userId = getUserId();
|
||||||
if (userId == null) {
|
if (userId == null) {
|
||||||
return ApiResponse.fail("用户未登录");
|
return ApiResponse.fail("用户未登录");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<UserCouponResp> coupons = couponService.getUserAvailableCoupons(userId);
|
List<UserCouponResp> coupons = couponService.getUserAvailableCoupons(userId, scenicId);
|
||||||
|
|
||||||
return ApiResponse.success(coupons);
|
return ApiResponse.success(coupons);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,9 +59,10 @@ public interface ICouponService {
|
|||||||
* 查询用户可用优惠券(包含领取记录信息)
|
* 查询用户可用优惠券(包含领取记录信息)
|
||||||
*
|
*
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
|
* @param scenicId 景区ID,传入时仅返回该景区可用的优惠券,NULL时返回全部
|
||||||
* @return 用户优惠券列表(包含领取记录+优惠券配置)
|
* @return 用户优惠券列表(包含领取记录+优惠券配置)
|
||||||
*/
|
*/
|
||||||
List<UserCouponResp> getUserAvailableCoupons(Long userId);
|
List<UserCouponResp> getUserAvailableCoupons(Long userId, String scenicId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 领取优惠券(内部调用方法)
|
* 领取优惠券(内部调用方法)
|
||||||
|
|||||||
@@ -295,15 +295,19 @@ public class CouponServiceImpl implements ICouponService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserCouponResp> getUserAvailableCoupons(Long userId) {
|
public List<UserCouponResp> getUserAvailableCoupons(Long userId, String scenicId) {
|
||||||
List<PriceCouponClaimRecord> records = couponClaimRecordMapper.selectUserAvailableCoupons(userId);
|
List<PriceCouponClaimRecord> records = couponClaimRecordMapper.selectUserAvailableCoupons(userId);
|
||||||
List<UserCouponResp> coupons = new ArrayList<>();
|
List<UserCouponResp> coupons = new ArrayList<>();
|
||||||
|
|
||||||
for (PriceCouponClaimRecord record : records) {
|
for (PriceCouponClaimRecord record : records) {
|
||||||
PriceCouponConfig config = couponConfigMapper.selectById(record.getCouponId());
|
PriceCouponConfig config = couponConfigMapper.selectById(record.getCouponId());
|
||||||
if (config != null) {
|
if (config == null) {
|
||||||
coupons.add(buildUserCouponResp(record, config));
|
continue;
|
||||||
}
|
}
|
||||||
|
if (scenicId != null && config.getScenicId() != null && !scenicId.equals(config.getScenicId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
coupons.add(buildUserCouponResp(record, config));
|
||||||
}
|
}
|
||||||
|
|
||||||
return coupons;
|
return coupons;
|
||||||
|
|||||||
Reference in New Issue
Block a user