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 49ef4c65
authored
Apr 14, 2026
by
章家宝
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat:【优惠券需求】小程序订单优惠券核销代码完善
1 parent
d17e9b5f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
4 deletions
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponVerificationService.java
aus-core/src/main/java/com/glsx/usedcar/module/coupon/service/CouponVerificationService.java
View file @
49ef4c6
...
@@ -224,16 +224,39 @@ public class CouponVerificationService {
...
@@ -224,16 +224,39 @@ public class CouponVerificationService {
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"优惠券已过期或未生效"
);
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"优惠券已过期或未生效"
);
}
}
// 5. 计算实际抵扣金额
// 5. 校验优惠券是否已被其他订单使用(未退回)
CouponOrderUsage
existingUsage
=
couponOrderUsageRepository
.
findByCouponIdAndDeleteFlag
(
couponId
,
DeleteFlag
.
NOT_DELETED
.
getCode
()).
orElse
(
null
);
if
(
existingUsage
!=
null
&&
existingUsage
.
getUsageStatus
()
==
1
)
{
// 状态为 1 表示已使用且未退回
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"优惠券已被其他订单使用"
);
}
// 6. 校验使用门槛
if
(
coupon
.
getThresholdAmount
()
!=
null
&&
transactionAmount
.
compareTo
(
coupon
.
getThresholdAmount
())
<
0
)
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"订单金额未达到优惠券使用门槛,门槛金额:"
+
coupon
.
getThresholdAmount
()
+
"元"
);
}
// 7. 计算实际抵扣金额
BigDecimal
actualDeduction
=
calculateActualDeduction
(
coupon
,
transactionAmount
);
BigDecimal
actualDeduction
=
calculateActualDeduction
(
coupon
,
transactionAmount
);
// 6. 更新优惠券状态为已核销
// 8. 对于阶梯券,校验是否达到阶梯门槛
if
(
CouponTypeEnum
.
TIERED_AMOUNT
.
getCode
().
equals
(
coupon
.
getCouponType
()))
{
if
(
actualDeduction
.
compareTo
(
BigDecimal
.
ZERO
)
<=
0
)
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"订单金额未达到阶梯券使用门槛"
);
}
}
// 9. 更新优惠券状态为已核销
coupon
.
setStatus
(
CouponUserStatusEnum
.
VERIFIED
.
getCode
());
coupon
.
setStatus
(
CouponUserStatusEnum
.
VERIFIED
.
getCode
());
coupon
.
setNuclearTime
(
now
);
coupon
.
setNuclearTime
(
now
);
coupon
.
setNuclearOrderId
(
orderId
);
coupon
.
setNuclearOrderId
(
orderId
);
couponAccountRepository
.
save
(
coupon
);
couponAccountRepository
.
save
(
coupon
);
//
7
. 创建订单使用记录
//
10
. 创建订单使用记录
CouponOrderUsage
usage
=
CouponOrderUsage
.
builder
()
CouponOrderUsage
usage
=
CouponOrderUsage
.
builder
()
.
usageId
(
generateUsageId
())
.
usageId
(
generateUsageId
())
.
orderId
(
orderId
)
.
orderId
(
orderId
)
...
@@ -252,7 +275,7 @@ public class CouponVerificationService {
...
@@ -252,7 +275,7 @@ public class CouponVerificationService {
usage
.
setCreateTime
(
now
);
usage
.
setCreateTime
(
now
);
couponOrderUsageRepository
.
save
(
usage
);
couponOrderUsageRepository
.
save
(
usage
);
//
8
. 创建核销记录
//
11
. 创建核销记录
CouponVerificationRecord
record
=
CouponVerificationRecord
.
builder
()
CouponVerificationRecord
record
=
CouponVerificationRecord
.
builder
()
.
recordId
(
generateRecordId
())
.
recordId
(
generateRecordId
())
.
couponId
(
couponId
)
.
couponId
(
couponId
)
...
...
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