|
|
@@ -5,6 +5,7 @@ import com.etotem.num.config.JwtConfig;
|
|
|
import com.etotem.num.entity.User;
|
|
|
import com.etotem.num.repository.UserRepository;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.security.SecureRandom;
|
|
|
import java.time.LocalDate;
|
|
|
@@ -61,6 +62,13 @@ public class UserService {
|
|
|
userRepository.save(user);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * US-6.2: Login or register with optional referrer binding.
|
|
|
+ * - New user + valid referrerCode → set invitedBy + increment referrer's directCount
|
|
|
+ * - Invalid/self/empty referrerCode → ignore (invitedBy stays null)
|
|
|
+ * - Existing user → ignore referrerCode (do not override)
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
public String loginOrRegister(String openid, String nickname, String avatarUrl, String referralCode) {
|
|
|
User user = userRepository.findByOpenid(openid).orElse(null);
|
|
|
if (user == null) {
|
|
|
@@ -76,6 +84,8 @@ public class UserService {
|
|
|
// US-6.2 §9: Self-invitation check
|
|
|
if (!inviter.get().getOpenid().equals(openid)) {
|
|
|
user.setInvitedBy(inviter.get().getId());
|
|
|
+ // US-6.2: After successful binding, increment referrer's directCount (atomic)
|
|
|
+ userRepository.incrementDirectCount(inviter.get().getId());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -185,7 +195,7 @@ public class UserService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Generate a referral code for a user after successful payment.
|
|
|
+ * US-6.1: Generate a referral code for a user after successful payment.
|
|
|
* 推广码由注册时生成改为付费后生成 (requirements-changelog v20260529.1)
|
|
|
*/
|
|
|
public void generateReferralCodeForUser(Long userId) {
|