Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jiedao-api-boot-master
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lanbaoming
jiedao-api-boot-master
Commits
82c6c4ca
Commit
82c6c4ca
authored
Jul 25, 2024
by
zhaobiyan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
兑换礼品流程增加积分更新,兑换记录插入
parent
b5756901
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
10 deletions
+66
-10
RedeemRewardReqVO.java
...yudao/module/reward/api/reward/dto/RedeemRewardReqVO.java
+3
-2
RewardRedeemStatusEnum.java
...der/yudao/module/reward/enums/RewardRedeemStatusEnum.java
+24
-0
RedeemRewardApiImpl.java
...r/yudao/module/reward/api/reward/RedeemRewardApiImpl.java
+39
-8
No files found.
yudao-module-reward/yudao-module-reward-api/src/main/java/cn/iocoder/yudao/module/reward/api/reward/dto/RedeemRewardReqVO.java
View file @
82c6c4ca
...
...
@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
import
lombok.Data
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
java.math.BigDecimal
;
import
java.util.Date
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
common
.
util
.
date
.
DateUtils
.
FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND
;
...
...
@@ -19,7 +20,7 @@ public class RedeemRewardReqVO {
private
Long
rewardId
;
@ApiModelProperty
(
value
=
"兑换数量"
)
private
Integer
c
ount
;
private
Integer
rewardC
ount
;
@ApiModelProperty
(
value
=
"兑换方式,同领取方式(1上门领取,2包邮到家,3邮寄到付)"
)
private
Integer
redeemType
;
...
...
@@ -28,7 +29,7 @@ public class RedeemRewardReqVO {
private
Integer
entrance
;
@ApiModelProperty
(
value
=
"费用数字(两位小数)"
)
private
Integer
expenses
;
private
BigDecimal
expenses
;
@ApiModelProperty
(
value
=
"费用币种(字典配置)"
)
private
Integer
currency
;
...
...
yudao-module-reward/yudao-module-reward-api/src/main/java/cn/iocoder/yudao/module/reward/enums/RewardRedeemStatusEnum.java
0 → 100644
View file @
82c6c4ca
package
cn
.
iocoder
.
yudao
.
module
.
reward
.
enums
;
public
enum
RewardRedeemStatusEnum
{
REDEEMING
(
1
,
"兑换中"
),
REDEEMED
(
2
,
"已兑换"
),
CANCELED
(
3
,
"已取消"
)
;
private
final
int
value
;
private
final
String
name
;
RewardRedeemStatusEnum
(
int
value
,
String
name
)
{
this
.
value
=
value
;
this
.
name
=
name
;
}
public
int
getValue
()
{
return
value
;
}
public
String
getName
()
{
return
name
;
}
}
yudao-module-reward/yudao-module-reward-impl/src/main/java/cn/iocoder/yudao/module/reward/api/reward/RedeemRewardApiImpl.java
View file @
82c6c4ca
package
cn
.
iocoder
.
yudao
.
module
.
reward
.
api
.
reward
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.core.lang.generator.SnowflakeGenerator
;
import
cn.iocoder.yudao.framework.redis.helper.RedisDistributedLock
;
import
cn.iocoder.yudao.module.member.api.score.MemberUserScoreApi
;
import
cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreOperateReqDTO
;
import
cn.iocoder.yudao.module.member.api.user.MemberUserApi
;
import
cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO
;
import
cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum
;
import
cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardReqVO
;
import
cn.iocoder.yudao.module.reward.api.reward.dto.RedeemRewardRespDTO
;
import
cn.iocoder.yudao.module.reward.dal.dataobject.redeem.RewardRedeemDO
;
import
cn.iocoder.yudao.module.reward.dal.dataobject.reward.RewardDO
;
import
cn.iocoder.yudao.module.reward.dal.mysql.redeem.RewardRedeemMapper
;
import
cn.iocoder.yudao.module.reward.dal.mysql.reward.RewardMapper
;
import
cn.iocoder.yudao.module.reward.enums.RewardRedeemStatusEnum
;
import
org.springframework.stereotype.Service
;
import
org.springframework.validation.annotation.Validated
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.*
;
import
static
cn
.
iocoder
.
yudao
.
framework
.
common
.
exception
.
util
.
ServiceExceptionUtil
.
exception
;
import
static
cn
.
iocoder
.
yudao
.
module
.
infra
.
enums
.
ErrorCodeConstants
.
GET_LOCK_FAILED
;
...
...
@@ -27,9 +33,15 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
@Resource
private
RewardMapper
rewardMapper
;
@Resource
private
RewardRedeemMapper
rewardRedeemMapper
;
@Resource
private
MemberUserApi
memberUserApi
;
@Resource
private
RedisDistributedLock
redisDistributedLock
;
@Resource
private
MemberUserScoreApi
memberUserScoreApi
;
@Resource
private
SnowflakeGenerator
snowflakeGenerator
;
@Override
public
RedeemRewardRespDTO
redeemReward
(
RedeemRewardReqVO
redeemRewardReqVO
)
{
...
...
@@ -56,11 +68,11 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
throw
exception
(
REWARD_NOT_ENABLE
);
}
// 会员积分不够
if
(
holdScore
<
rewardDO
.
getPointsRequire
()
*
redeemRewardReqVO
.
getCount
())
{
if
(
holdScore
<
rewardDO
.
getPointsRequire
()
*
redeemRewardReqVO
.
get
Reward
Count
())
{
throw
exception
(
REWARD_SCORE_NOT_ENOUGH
);
}
// 礼品数量不够
if
(
rewardDO
.
getQuantityRemain
()
<
redeemRewardReqVO
.
getCount
())
{
if
(
rewardDO
.
getQuantityRemain
()
<
redeemRewardReqVO
.
get
Reward
Count
())
{
throw
exception
(
REWARD_COUNT_NOT_ENOUGH
);
}
// 兑换方式不匹配
...
...
@@ -73,9 +85,9 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
rewardMapper
.
updateById
(
rewardDO
);
// 添加兑换记录
Long
redeemId
=
addRedeemRecord
(
redeemRewardReqVO
);
// 更新会员积分
updateMemberScore
(
redeemRewardReqVO
,
rewardDO
,
redeemId
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
...
...
@@ -85,6 +97,25 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
return
null
;
}
private
void
updateMemberScore
(
RedeemRewardReqVO
redeemRewardReqVO
,
RewardDO
rewardDO
,
Long
redeemId
)
{
Map
<
String
,
Object
>
extParam
=
new
HashMap
<>();
extParam
.
put
(
"redeemId"
,
redeemId
);
memberUserScoreApi
.
operateScore
(
MemberUserScoreOperateReqDTO
.
builder
()
.
memberId
(
redeemRewardReqVO
.
getMemberId
())
.
sourceType
(
ScoreSourceTypeEnum
.
EXCHANGE_REWARD
)
.
scoreCount
(
redeemRewardReqVO
.
getRewardCount
()*
rewardDO
.
getPointsRequire
())
.
extParam
(
extParam
)
.
build
());
}
private
Long
addRedeemRecord
(
RedeemRewardReqVO
redeemRewardReqVO
)
{
RewardRedeemDO
rewardRedeemDO
=
BeanUtil
.
copyProperties
(
redeemRewardReqVO
,
RewardRedeemDO
.
class
);
rewardRedeemDO
.
setId
(
snowflakeGenerator
.
next
());
rewardRedeemDO
.
setStatus
(
RewardRedeemStatusEnum
.
REDEEMING
.
getValue
());
rewardRedeemMapper
.
insert
(
rewardRedeemDO
);
return
rewardRedeemDO
.
getId
();
}
@Override
public
List
<
RedeemRewardRespDTO
>
redeemRewards
(
List
<
RedeemRewardReqVO
>
redeemRewardReqVOList
)
{
Long
rewardId
=
redeemRewardReqVOList
.
get
(
0
).
getRewardId
();
...
...
@@ -115,7 +146,7 @@ public class RedeemRewardApiImpl implements RedeemRewardApi {
memberIds
.
add
(
redeemRewardReqVO
.
getMemberId
());
members
.
add
(
memberUserApi
.
getUser
(
redeemRewardReqVO
.
getMemberId
()));
// 记录兑换总数
totalCount
+=
redeemRewardReqVO
.
getCount
();
totalCount
+=
redeemRewardReqVO
.
get
Reward
Count
();
}
// 查询会员列表,获取积分列表
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment