补充邀请相关权益发放
This commit is contained in:
@@ -9,6 +9,7 @@ import org.jiayunet.mapper.UserMapper;
|
|||||||
import org.jiayunet.pojo.po.User;
|
import org.jiayunet.pojo.po.User;
|
||||||
import org.jiayunet.pojo.po.UserInvite;
|
import org.jiayunet.pojo.po.UserInvite;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
@@ -18,7 +19,7 @@ import java.time.Instant;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户注册服务
|
* 用户注册服务
|
||||||
* <p>依赖:UserMapper(用户持久化)、UserInviteMapper(邀请记录持久化)</p>
|
* <p>依赖:UserMapper(用户持久化)、UserInviteMapper(邀请记录持久化)、MemberGrantService(会员权益发放)</p>
|
||||||
* <p>使用表:bg_user(创建用户、查询邀请人)、bg_user_invite(写入邀请关系)</p>
|
* <p>使用表:bg_user(创建用户、查询邀请人)、bg_user_invite(写入邀请关系)</p>
|
||||||
*
|
*
|
||||||
* @author zk
|
* @author zk
|
||||||
@@ -48,6 +49,15 @@ public class UserRegisterService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserInviteMapper userInviteMapper;
|
private UserInviteMapper userInviteMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MemberGrantService memberGrantService;
|
||||||
|
|
||||||
|
@Value("${app.reward.register-days:3}")
|
||||||
|
private int registerDays;
|
||||||
|
|
||||||
|
@Value("${app.reward.invite-days:7}")
|
||||||
|
private int inviteDays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册新用户
|
* 注册新用户
|
||||||
* <p>1. 创建用户并生成邀请码 2. 若携带邀请码则绑定邀请关系</p>
|
* <p>1. 创建用户并生成邀请码 2. 若携带邀请码则绑定邀请关系</p>
|
||||||
@@ -73,6 +83,9 @@ public class UserRegisterService {
|
|||||||
bindInvite(user, inviteCode);
|
bindInvite(user, inviteCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 发放新用户注册会员权益
|
||||||
|
memberGrantService.grant(user.getId(), registerDays);
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,10 +95,7 @@ public class UserRegisterService {
|
|||||||
*/
|
*/
|
||||||
private void bindInvite(User user, String inviteCode) {
|
private void bindInvite(User user, String inviteCode) {
|
||||||
// 查找邀请人
|
// 查找邀请人
|
||||||
User inviter = userMapper.selectOne(
|
User inviter = userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getInviteCode, inviteCode));
|
||||||
new LambdaQueryWrapper<User>()
|
|
||||||
.eq(User::getInviteCode, inviteCode)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (inviter == null) {
|
if (inviter == null) {
|
||||||
log.warn("邀请码无效 inviteCode:{} userId:{}", inviteCode, user.getId());
|
log.warn("邀请码无效 inviteCode:{} userId:{}", inviteCode, user.getId());
|
||||||
@@ -102,8 +112,12 @@ public class UserRegisterService {
|
|||||||
invite.setUserId(user.getId());
|
invite.setUserId(user.getId());
|
||||||
invite.setInviterId(inviter.getId());
|
invite.setInviterId(inviter.getId());
|
||||||
invite.setInviteCode(inviteCode);
|
invite.setInviteCode(inviteCode);
|
||||||
|
invite.setRewardDays(inviteDays);
|
||||||
invite.setCreateTime(Instant.now());
|
invite.setCreateTime(Instant.now());
|
||||||
userInviteMapper.insert(invite);
|
userInviteMapper.insert(invite);
|
||||||
|
|
||||||
|
// 发放邀请人会员权益
|
||||||
|
memberGrantService.grant(inviter.getId(), inviteDays);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -88,6 +88,13 @@ app:
|
|||||||
# 非会员最大限制数量
|
# 非会员最大限制数量
|
||||||
max-count: 5
|
max-count: 5
|
||||||
|
|
||||||
|
# 会员权益奖励配置
|
||||||
|
reward:
|
||||||
|
# 新用户注册赠送会员天数
|
||||||
|
register-days: 3
|
||||||
|
# 邀请好友奖励会员天数
|
||||||
|
invite-days: 7
|
||||||
|
|
||||||
# AI 多供应商配置,第一个为默认 provider
|
# AI 多供应商配置,第一个为默认 provider
|
||||||
# base-url 配到版本路径,如 DeepSeek: https://api.deepseek.com/v1,豆包: https://ark.cn-beijing.volces.com/api/v3
|
# base-url 配到版本路径,如 DeepSeek: https://api.deepseek.com/v1,豆包: https://ark.cn-beijing.volces.com/api/v3
|
||||||
ai:
|
ai:
|
||||||
|
|||||||
Reference in New Issue
Block a user