Просмотр исходного кода

小程序登录,成为创客

licailing 5 лет назад
Родитель
Сommit
5fa1a1e064

+ 1 - 1
src/main/java/com/izouma/jiashanxia/service/CouponService.java

@@ -12,7 +12,7 @@ import org.springframework.stereotype.Service;
 @AllArgsConstructor
 public class CouponService {
 
-    private CouponRepo couponRepo;
+    private final CouponRepo couponRepo;
 
     public Page<Coupon> all(PageQuery pageQuery) {
         return couponRepo.findAll(JpaUtils.toSpecification(pageQuery, Coupon.class), JpaUtils.toPageRequest(pageQuery));

+ 14 - 13
src/main/java/com/izouma/jiashanxia/service/UserService.java

@@ -126,7 +126,7 @@ public class UserService {
         return user;
     }
 
-    public User loginMa(String code, Long parent) {
+    public User loginMa(String code, Long parent, Boolean expert) {
         try {
             WxMaJscode2SessionResult result = wxMaService.jsCode2SessionInfo(code);
             String openId = result.getOpenid();
@@ -135,11 +135,17 @@ public class UserService {
             if (userInfo != null) {
                 // 插入上级
                 if (ObjectUtil.isNotNull(parent)) {
-                    Long parent1 = this.getParent(parent, userInfo);
-                    if (ObjectUtil.isNotNull(parent1)) {
+//                    Long parent1 = this.getParent(parent, userInfo);
+                    // 邀请成为创客
+                    if (expert && !userInfo.isVip()) {
+                        userInfo.setVip(true);
+                        userInfo.setMember(Member.EXPERT);
+                    }
+                    // 成为他的上级
+                    if (ObjectUtil.isNull(userInfo.getParent())) {
                         userInfo.setParent(parent);
-                        userRepo.saveAndFlush(userInfo);
                     }
+                    userRepo.saveAndFlush(userInfo);
                 }
                 userInfo.setSessionKey(sessionKey);
                 return userInfo;
@@ -155,18 +161,13 @@ public class UserService {
                     .teamFounder(false)
                     .sessionKey(sessionKey)
                     .member(Member.NORMAL)
-//                    .promote(BigDecimal.ZERO)
-//                    .maker(BigDecimal.ZERO)
                     .withdraw(BigDecimal.ZERO)
                     .cacheAmount(BigDecimal.ZERO)
                     .build();
-            // 插入上级
-//            if (ObjectUtil.isNotNull(parent)) {
-//                Long parent1 = this.getParent(parent, userInfo);
-//                if (ObjectUtil.isNotNull(parent1)) {
-//                    userInfo.setParent(parent);
-//                }
-//            }
+            if (ObjectUtil.isNotEmpty(parent) && expert) {
+                userInfo.setVip(true);
+                userInfo.setMember(Member.EXPERT);
+            }
             userInfo = userRepo.saveAndFlush(userInfo);
             log.info("loginMa {}", userInfo.getCreatedAt());
             return userInfo;

+ 2 - 2
src/main/java/com/izouma/jiashanxia/web/AuthenticationController.java

@@ -76,10 +76,10 @@ public class AuthenticationController {
 
     @PostMapping("/maLogin")
     @ApiOperation(value = "小程序登录")
-    public Map<String, String> maLogin(String code, Long parent) {
+    public Map<String, String> maLogin(String code, Long parent, Boolean expert) {
         try {
             Map<String, String> map = new HashMap<>();
-            User user = userService.loginMa(code, parent);
+            User user = userService.loginMa(code, parent, expert);
             map.put("token", jwtTokenUtil.generateToken(JwtUserFactory.create(user)));
             map.put("sessionKey", user.getSessionKey());
             return map;