Commit f83974d3 by 章家宝

feat:查询优惠券详情的时候校验用户是否归属该优惠券

1 parent d1570b53
...@@ -72,7 +72,8 @@ public class CouponAccountController { ...@@ -72,7 +72,8 @@ public class CouponAccountController {
@RequestAttribute(value = LOGIN_ACCOUNT, required = true) Account account) { @RequestAttribute(value = LOGIN_ACCOUNT, required = true) Account account) {
log.info("【接口请求】获取优惠券详情,couponId={}", couponId); log.info("【接口请求】获取优惠券详情,couponId={}", couponId);
try { try {
CouponAccountRespVO result = couponAccountService.getCouponDetail(couponId); Integer accountId = account.getAccountId();
CouponAccountRespVO result = couponAccountService.getCouponDetail(couponId, accountId);
return BaseResp.success(result); return BaseResp.success(result);
} catch (BusinessCodeException be) { } catch (BusinessCodeException be) {
log.error("【接口响应】获取优惠券详情失败,couponId={}", couponId, be); log.error("【接口响应】获取优惠券详情失败,couponId={}", couponId, be);
......
...@@ -178,9 +178,13 @@ public class CouponAccountService { ...@@ -178,9 +178,13 @@ public class CouponAccountService {
/** /**
* 获取优惠券详情 * 获取优惠券详情
*/ */
public CouponAccountRespVO getCouponDetail(String couponId) { public CouponAccountRespVO getCouponDetail(String couponId, Integer accountId) {
CouponAccount coupon = couponAccountRepository.findByCouponIdAndDeleteFlag(couponId, DeleteFlag.NOT_DELETED.getCode()) CouponAccount coupon = couponAccountRepository.findByCouponIdAndDeleteFlag(couponId, DeleteFlag.NOT_DELETED.getCode())
.orElseThrow(() -> new BusinessCodeException(ErrorCodeEnum.COMMON_ERROR, "优惠券不存在")); .orElseThrow(() -> new BusinessCodeException(ErrorCodeEnum.COMMON_ERROR, "优惠券不存在"));
// 判断是否是该用户的优惠券
if (!coupon.getAccountId().equals(accountId)) {
throw new BusinessCodeException(ErrorCodeEnum.COMMON_ERROR, "该优惠券不属于当前用户");
}
return couponConverter.couponAccountMapRespVO(coupon); return couponConverter.couponAccountMapRespVO(coupon);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!