|
|
@@ -155,6 +155,17 @@ public class EnrollmentController {
|
|
|
}
|
|
|
|
|
|
String inviteCode = body.get("inviteCode") == null ? "" : body.get("inviteCode").toString().trim();
|
|
|
+ // 邀请链:先解析邀请人,报名单冗余 inviter_id(被邀请人记录邀请人信息,便于平台奖励);不能自己邀自己
|
|
|
+ TrainUser inviter = null;
|
|
|
+ if (StringUtils.hasText(inviteCode)) {
|
|
|
+ inviter = trainUserMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<TrainUser>()
|
|
|
+ .eq(TrainUser::getInviteCode, inviteCode)
|
|
|
+ .last("LIMIT 1"));
|
|
|
+ if (inviter != null && inviter.getId().equals(userId)) {
|
|
|
+ inviter = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
TrainEnrollment e = new TrainEnrollment();
|
|
|
e.setUid(userId);
|
|
|
e.setCourseId(courseId);
|
|
|
@@ -166,32 +177,27 @@ public class EnrollmentController {
|
|
|
e.setTopProblems(body.get("topProblems") == null ? null : body.get("topProblems").toString());
|
|
|
e.setSource(StringUtils.hasText(inviteCode) ? "invite" : "scene");
|
|
|
e.setInviteCode(StringUtils.hasText(inviteCode) ? inviteCode : null);
|
|
|
+ e.setInviterId(inviter != null ? inviter.getId() : null);
|
|
|
e.setStatus("pending");
|
|
|
trainEnrollmentMapper.insert(e);
|
|
|
|
|
|
// 转介绍关系(幂等:uk_code_invitee 唯一键兜底)
|
|
|
- if (StringUtils.hasText(inviteCode)) {
|
|
|
- TrainUser inviter = trainUserMapper.selectOne(
|
|
|
- new LambdaQueryWrapper<TrainUser>()
|
|
|
- .eq(TrainUser::getInviteCode, inviteCode)
|
|
|
- .last("LIMIT 1"));
|
|
|
- if (inviter != null && !inviter.getId().equals(userId)) {
|
|
|
- Long invCount = trainInviteMapper.selectCount(
|
|
|
- new LambdaQueryWrapper<TrainInvite>()
|
|
|
- .eq(TrainInvite::getInviteCode, inviteCode)
|
|
|
- .eq(TrainInvite::getInviteeId, userId));
|
|
|
- if (invCount == null || invCount == 0) {
|
|
|
- TrainInvite inv = new TrainInvite();
|
|
|
- inv.setInviterId(inviter.getId());
|
|
|
- inv.setInviteeId(userId);
|
|
|
- inv.setInviteCode(inviteCode);
|
|
|
- inv.setSuccessful(0);
|
|
|
- inv.setRewardStatus("pending");
|
|
|
- try {
|
|
|
- trainInviteMapper.insert(inv);
|
|
|
- } catch (Exception ex) {
|
|
|
- // 唯一键冲突(并发重复注册)可忽略
|
|
|
- }
|
|
|
+ if (inviter != null) {
|
|
|
+ Long invCount = trainInviteMapper.selectCount(
|
|
|
+ new LambdaQueryWrapper<TrainInvite>()
|
|
|
+ .eq(TrainInvite::getInviteCode, inviteCode)
|
|
|
+ .eq(TrainInvite::getInviteeId, userId));
|
|
|
+ if (invCount == null || invCount == 0) {
|
|
|
+ TrainInvite inv = new TrainInvite();
|
|
|
+ inv.setInviterId(inviter.getId());
|
|
|
+ inv.setInviteeId(userId);
|
|
|
+ inv.setInviteCode(inviteCode);
|
|
|
+ inv.setSuccessful(0);
|
|
|
+ inv.setRewardStatus("pending");
|
|
|
+ try {
|
|
|
+ trainInviteMapper.insert(inv);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ // 唯一键冲突(并发重复注册)可忽略
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -241,6 +247,7 @@ public class EnrollmentController {
|
|
|
row.put("phone", e.getPhone());
|
|
|
row.put("source", e.getSource());
|
|
|
row.put("inviteCode", e.getInviteCode());
|
|
|
+ row.put("inviterId", e.getInviterId());
|
|
|
row.put("status", e.getStatus());
|
|
|
// 学籍(V4.0 §3.4.1):生效时间/有效期 + 派生状态(active/dormant/none)
|
|
|
row.put("enrolledAt", e.getEnrolledAt());
|