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 0f60137a
authored
May 13, 2026
by
章家宝
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat:代码优化,简化接口参数
1 parent
10cffef4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
46 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-api/src/main/java/com/glsx/usedcar/web/api/coupon/CouponAccountController.java
View file @
0f60137
...
...
@@ -125,11 +125,7 @@ public class CouponAccountController {
BigDecimal
actualDeduction
=
couponVerificationService
.
useCouponForOrder
(
accountId
,
reqVO
.
getOrderId
(),
reqVO
.
getOrderCode
(),
reqVO
.
getCouponId
(),
reqVO
.
getTransactionAmount
(),
reqVO
.
getVehicleId
(),
reqVO
.
getVehicleInfo
()
reqVO
.
getCouponId
()
);
CouponVerifyRespVO
respVO
=
new
CouponVerifyRespVO
();
...
...
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponVerificationService.java
View file @
0f60137
...
...
@@ -3,6 +3,7 @@ package com.glsx.usedcar.module.coupon.service;
import
com.glsx.usedcar.enums.common.DeleteFlag
;
import
com.glsx.usedcar.module.auction.dao.AuctionOrderDao
;
import
com.glsx.usedcar.module.auction.entity.AuctionOrder
;
import
com.glsx.usedcar.module.vehicle.entity.Vehicle
;
import
com.glsx.usedcar.module.coupon.dao.*
;
import
com.glsx.usedcar.module.coupon.entity.*
;
import
com.glsx.usedcar.module.coupon.enums.CouponTypeEnum
;
...
...
@@ -274,11 +275,7 @@ public class CouponVerificationService {
public
BigDecimal
useCouponForOrder
(
Integer
accountId
,
Integer
orderId
,
String
orderCode
,
String
couponId
,
BigDecimal
transactionAmount
,
Integer
vehicleId
,
String
vehicleInfo
)
{
String
couponId
)
{
LocalDateTime
now
=
LocalDateTime
.
now
();
...
...
@@ -286,22 +283,40 @@ public class CouponVerificationService {
CouponAccount
coupon
=
couponAccountRepository
.
findByCouponIdAndDeleteFlag
(
couponId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"优惠券不存在"
));
// 2. 校验优惠券归属
// 2. 查询订单,获取订单数据和车辆信息
AuctionOrder
order
=
auctionOrderDao
.
findByOrderId
(
orderId
);
if
(
order
==
null
)
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"订单不存在"
);
}
String
orderCode
=
order
.
getOrderCode
();
BigDecimal
orderPrice
=
BigDecimal
.
valueOf
(
order
.
getOrderPrice
());
BigDecimal
commissionPrice
=
BigDecimal
.
valueOf
(
order
.
getCommissionPrice
());
// 根据抵扣类型计算交易金额:车款抵扣用成交价,佣金抵扣用佣金
BigDecimal
transactionAmount
=
coupon
.
getDeductionType
()
!=
null
&&
coupon
.
getDeductionType
()
==
1
?
orderPrice
:
commissionPrice
;
// 获取车辆信息
Vehicle
vehicle
=
order
.
getVehicle
();
Integer
vehicleId
=
vehicle
!=
null
?
vehicle
.
getVehicleId
()
:
null
;
String
vehicleInfo
=
vehicle
!=
null
?
vehicle
.
toVehicleName
()
:
null
;
// 3. 校验优惠券归属
if
(!
coupon
.
getAccountId
().
equals
(
accountId
))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"优惠券不属于当前用户"
);
}
//
3
. 校验优惠券状态
//
4
. 校验优惠券状态
if
(!
coupon
.
getStatus
().
equals
(
CouponUserStatusEnum
.
UNUSED
.
getCode
()))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"优惠券状态不可用"
);
}
//
4
. 校验有效期
//
5
. 校验有效期
if
(
now
.
isBefore
(
coupon
.
getValidStartTime
())
||
now
.
isAfter
(
coupon
.
getValidEndTime
()))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"优惠券已过期或未生效"
);
}
//
5
. 校验订单是否已有优惠券(一个订单只能使用一张优惠券)
//
6
. 校验订单是否已有优惠券(一个订单只能使用一张优惠券)
CouponOrderUsage
existingOrderUsage
=
couponOrderUsageRepository
.
findByOrderIdAndDeleteFlag
(
orderId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
orElse
(
null
);
...
...
@@ -310,7 +325,7 @@ public class CouponVerificationService {
"该订单已使用优惠券,不可重复使用"
);
}
//
6
. 校验优惠券是否已被其他订单使用(未退回)
//
7
. 校验优惠券是否已被其他订单使用(未退回)
CouponOrderUsage
existingUsage
=
couponOrderUsageRepository
.
findByCouponIdAndDeleteFlag
(
couponId
,
DeleteFlag
.
NOT_DELETED
.
getCode
()).
orElse
(
null
);
if
(
existingUsage
!=
null
&&
existingUsage
.
getUsageStatus
()
==
1
)
{
...
...
@@ -318,17 +333,17 @@ public class CouponVerificationService {
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"优惠券已被其他订单使用"
);
}
//
7
. 校验使用门槛
//
8
. 校验使用门槛
if
(
coupon
.
getThresholdAmount
()
!=
null
&&
transactionAmount
.
compareTo
(
coupon
.
getThresholdAmount
())
<
0
)
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"订单金额未达到优惠券使用门槛,门槛金额:"
+
coupon
.
getThresholdAmount
()
+
"元"
);
}
//
8
. 计算实际抵扣金额
//
9
. 计算实际抵扣金额
BigDecimal
actualDeduction
=
calculateActualDeduction
(
coupon
,
transactionAmount
);
//
9
. 对于阶梯券,校验是否达到阶梯门槛
//
10
. 对于阶梯券,校验是否达到阶梯门槛
if
(
CouponTypeEnum
.
TIERED_AMOUNT
.
getCode
().
equals
(
coupon
.
getCouponType
()))
{
if
(
actualDeduction
.
compareTo
(
BigDecimal
.
ZERO
)
<=
0
)
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
...
...
@@ -336,13 +351,13 @@ public class CouponVerificationService {
}
}
// 1
0
. 更新优惠券状态为已核销
// 1
1
. 更新优惠券状态为已核销
coupon
.
setStatus
(
CouponUserStatusEnum
.
VERIFIED
.
getCode
());
coupon
.
setNuclearTime
(
now
);
coupon
.
setNuclearOrderId
(
orderId
);
couponAccountRepository
.
save
(
coupon
);
// 1
1
. 创建订单使用记录
// 1
2
. 创建订单使用记录
CouponOrderUsage
usage
=
CouponOrderUsage
.
builder
()
.
usageId
(
dailySequenceIdGenerator
.
getCouponUsageId
())
.
orderId
(
orderId
)
...
...
@@ -362,7 +377,7 @@ public class CouponVerificationService {
usage
.
setCreateTime
(
now
);
couponOrderUsageRepository
.
save
(
usage
);
// 1
2
. 创建核销记录
// 1
3
. 创建核销记录
CouponVerificationRecord
record
=
CouponVerificationRecord
.
builder
()
.
recordId
(
dailySequenceIdGenerator
.
getCouponVerfyRecordId
())
.
couponId
(
couponId
)
...
...
@@ -385,15 +400,11 @@ public class CouponVerificationService {
record
.
setCreateTime
(
now
);
couponVerificationRecordRepository
.
save
(
record
);
// 13. 同步更新订单金额
AuctionOrder
order
=
auctionOrderDao
.
findByOrderId
(
orderId
);
if
(
order
!=
null
)
{
order
.
setCouponDeduction
(
actualDeduction
);
BigDecimal
totalAmount
=
BigDecimal
.
valueOf
(
order
.
getOrderPrice
())
.
add
(
BigDecimal
.
valueOf
(
order
.
getCommissionPrice
()));
order
.
setActualPayAmount
(
totalAmount
.
subtract
(
actualDeduction
));
auctionOrderDao
.
save
(
order
);
}
// 14. 同步更新订单金额
order
.
setCouponDeduction
(
actualDeduction
);
BigDecimal
totalAmount
=
orderPrice
.
add
(
commissionPrice
);
order
.
setActualPayAmount
(
totalAmount
.
subtract
(
actualDeduction
));
auctionOrderDao
.
save
(
order
);
log
.
info
(
"优惠券核销成功:accountId={}, orderId={}, couponId={}, 实际抵扣={}"
,
accountId
,
orderId
,
couponId
,
actualDeduction
);
...
...
aus-core/src/main/java/com/glsx/usedcar/module/coupon/vo/CouponVerifyReqVO.java
View file @
0f60137
...
...
@@ -5,8 +5,6 @@ import jakarta.validation.constraints.NotBlank;
import
jakarta.validation.constraints.NotNull
;
import
lombok.Data
;
import
java.math.BigDecimal
;
/**
* 优惠券核销请求 VO
*/
...
...
@@ -21,18 +19,4 @@ public class CouponVerifyReqVO {
@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
;
}
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