Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
usedCarAuction
/
aus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 4f2f311d
authored
Apr 13, 2026
by
章家宝
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat:【优惠券需求】优惠券新增小程序核销接口
1 parent
94617f21
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
7 deletions
aus-api/src/main/java/com/glsx/usedcar/web/api/coupon/CouponAccountController.java
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponVerificationService.java
aus-core/src/main/java/com/glsx/usedcar/module/coupon/vo/CouponVerifyReqVO.java
aus-core/src/main/java/com/glsx/usedcar/module/coupon/vo/CouponVerifyRespVO.java
aus-api/src/main/java/com/glsx/usedcar/web/api/coupon/CouponAccountController.java
View file @
4f2f311
...
@@ -2,17 +2,22 @@ package com.glsx.usedcar.web.api.coupon;
...
@@ -2,17 +2,22 @@ package com.glsx.usedcar.web.api.coupon;
import
com.glsx.usedcar.module.account.entity.Account
;
import
com.glsx.usedcar.module.account.entity.Account
;
import
com.glsx.usedcar.module.coupon.service.CouponAccountService
;
import
com.glsx.usedcar.module.coupon.service.CouponAccountService
;
import
com.glsx.usedcar.module.coupon.service.CouponVerificationService
;
import
com.glsx.usedcar.module.coupon.vo.CouponAccountRespVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponAccountRespVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponPopupRespVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponPopupRespVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponVerifyReqVO
;
import
com.glsx.usedcar.module.coupon.vo.CouponVerifyRespVO
;
import
com.glsx.usedcar.resp.BaseResp
;
import
com.glsx.usedcar.resp.BaseResp
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.Parameter
;
import
io.swagger.v3.oas.annotations.Parameter
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.validation.Valid
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
java.math.BigDecimal
;
import
java.util.List
;
import
java.util.List
;
import
static
com
.
glsx
.
usedcar
.
web
.
WebConstants
.
LOGIN_ACCOUNT
;
import
static
com
.
glsx
.
usedcar
.
web
.
WebConstants
.
LOGIN_ACCOUNT
;
...
@@ -28,6 +33,7 @@ import static com.glsx.usedcar.web.WebConstants.LOGIN_ACCOUNT;
...
@@ -28,6 +33,7 @@ import static com.glsx.usedcar.web.WebConstants.LOGIN_ACCOUNT;
public
class
CouponAccountController
{
public
class
CouponAccountController
{
private
final
CouponAccountService
couponAccountService
;
private
final
CouponAccountService
couponAccountService
;
private
final
CouponVerificationService
couponVerificationService
;
@Operation
(
summary
=
"获取我的优惠券列表"
,
description
=
"查询当前登录用户的优惠券列表,支持按状态筛选"
)
@Operation
(
summary
=
"获取我的优惠券列表"
,
description
=
"查询当前登录用户的优惠券列表,支持按状态筛选"
)
@GetMapping
(
"/myList"
)
@GetMapping
(
"/myList"
)
...
@@ -121,4 +127,39 @@ public class CouponAccountController {
...
@@ -121,4 +127,39 @@ public class CouponAccountController {
return
BaseResp
.
fail
(
"系统异常:统计失败"
);
return
BaseResp
.
fail
(
"系统异常:统计失败"
);
}
}
}
}
@Operation
(
summary
=
"核销优惠券"
,
description
=
"订单支付时使用优惠券进行核销"
)
@PostMapping
(
"/verify"
)
public
BaseResp
<
CouponVerifyRespVO
>
verifyCoupon
(
@RequestAttribute
(
value
=
LOGIN_ACCOUNT
,
required
=
false
)
Account
account
,
@Valid
@RequestBody
CouponVerifyReqVO
reqVO
)
{
log
.
info
(
"【接口请求】核销优惠券,accountId={}, orderId={}, couponId={}"
,
account
.
getAccountId
(),
reqVO
.
getOrderId
(),
reqVO
.
getCouponId
());
try
{
Integer
accountId
=
account
.
getAccountId
();
BigDecimal
actualDeduction
=
couponVerificationService
.
useCouponForOrder
(
accountId
,
reqVO
.
getOrderId
(),
reqVO
.
getOrderCode
(),
reqVO
.
getCouponId
(),
reqVO
.
getTransactionAmount
(),
reqVO
.
getVehicleId
(),
reqVO
.
getVehicleInfo
()
);
CouponVerifyRespVO
respVO
=
new
CouponVerifyRespVO
();
respVO
.
setCouponId
(
reqVO
.
getCouponId
());
respVO
.
setOrderId
(
reqVO
.
getOrderId
());
respVO
.
setActualDeduction
(
actualDeduction
);
log
.
info
(
"【接口响应】核销优惠券成功,actualDeduction={}"
,
actualDeduction
);
return
BaseResp
.
success
(
respVO
);
}
catch
(
BusinessCodeException
be
)
{
log
.
error
(
"【接口响应】核销优惠券失败,couponId={}"
,
reqVO
.
getCouponId
(),
be
);
return
BaseResp
.
fail
(
be
.
getCode
().
toString
(),
be
.
getMessage
());
}
catch
(
Exception
e
)
{
log
.
error
(
"【接口响应】核销优惠券异常,couponId={}"
,
reqVO
.
getCouponId
(),
e
);
return
BaseResp
.
fail
(
"系统异常:核销优惠券失败"
);
}
}
}
}
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponVerificationService.java
View file @
4f2f311
...
@@ -96,13 +96,6 @@ public class CouponVerificationService {
...
@@ -96,13 +96,6 @@ public class CouponVerificationService {
return
false
;
return
false
;
}
}
}
}
// TODO: 检查优惠券适用范围(车型、价格区间等)
// 后续可以根据业务需求扩展,例如:
// - 检查是否限定特定车型
// - 检查是否限定特定价格区间
// - 检查是否限定特定卖家/买家
return
true
;
return
true
;
}
}
...
...
aus-core/src/main/java/com/glsx/usedcar/module/coupon/vo/CouponVerifyReqVO.java
0 → 100644
View file @
4f2f311
package
com
.
glsx
.
usedcar
.
module
.
coupon
.
vo
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
jakarta.validation.constraints.NotBlank
;
import
jakarta.validation.constraints.NotNull
;
import
lombok.Data
;
import
java.math.BigDecimal
;
/**
* 优惠券核销请求 VO
*/
@Data
@Schema
(
description
=
"优惠券核销请求参数"
)
public
class
CouponVerifyReqVO
{
@Schema
(
description
=
"优惠券实例 ID"
,
requiredMode
=
Schema
.
RequiredMode
.
REQUIRED
,
example
=
"CPN202403250001"
)
@NotBlank
(
message
=
"优惠券ID不能为空"
)
private
String
couponId
;
@Schema
(
description
=
"订单 ID"
,
requiredMode
=
Schema
.
RequiredMode
.
REQUIRED
,
example
=
"10001"
)
@NotNull
(
message
=
"订单ID不能为空"
)
private
Integer
orderId
;
@Schema
(
description
=
"订单编号"
,
requiredMode
=
Schema
.
RequiredMode
.
REQUIRED
,
example
=
"AUC202403250001"
)
@NotBlank
(
message
=
"订单编号不能为空"
)
private
String
orderCode
;
@Schema
(
description
=
"订单成交价(元)"
,
requiredMode
=
Schema
.
RequiredMode
.
REQUIRED
,
example
=
"50000.00"
)
@NotNull
(
message
=
"订单成交价不能为空"
)
private
BigDecimal
transactionAmount
;
@Schema
(
description
=
"车辆 ID"
,
example
=
"20001"
)
private
Integer
vehicleId
;
@Schema
(
description
=
"车辆信息"
,
example
=
"宝马 3系 2023款"
)
private
String
vehicleInfo
;
}
aus-core/src/main/java/com/glsx/usedcar/module/coupon/vo/CouponVerifyRespVO.java
0 → 100644
View file @
4f2f311
package
com
.
glsx
.
usedcar
.
module
.
coupon
.
vo
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
lombok.Data
;
import
java.math.BigDecimal
;
/**
* 优惠券核销响应 VO
*/
@Data
@Schema
(
description
=
"优惠券核销响应结果"
)
public
class
CouponVerifyRespVO
{
@Schema
(
description
=
"优惠券实例 ID"
,
example
=
"CPN202403250001"
)
private
String
couponId
;
@Schema
(
description
=
"订单 ID"
,
example
=
"10001"
)
private
Integer
orderId
;
@Schema
(
description
=
"实际抵扣金额(元)"
,
example
=
"1000.00"
)
private
BigDecimal
actualDeduction
;
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment