From d0cf2cb2c352bdeb146aad2bb57ba7d39cef3bbd Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期二, 03 十一月 2026 17:59:04 +0800
Subject: [PATCH] 完善会员审批及门户配置

---
 yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java
index 72de06f..4f21422 100644
--- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java
+++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java
@@ -40,6 +40,7 @@
 import lombok.Setter;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.ApplicationEventPublisher;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.stereotype.Service;
@@ -101,6 +102,10 @@
     private RoleService roleService;
     @Resource
     private PermissionService permissionService;
+    @Autowired(required = false)
+    private WxcpMembershipRegistration wxcpMembershipRegistration;
+    @Resource
+    private WxcpPasswordSetupGrant wxcpPasswordSetupGrant;
 
     /**
      * 楠岃瘉鐮佺殑寮�鍏筹紝榛樿涓� true
@@ -118,6 +123,7 @@
             createLoginLog(null, username, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS);
             throw exception(AUTH_LOGIN_BAD_CREDENTIALS);
         }
+
         if (!userService.isPasswordMatch(password, user.getPassword())) {
             createLoginLog(user.getId(), username, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS);
             throw exception(AUTH_LOGIN_BAD_CREDENTIALS);
@@ -141,6 +147,14 @@
 
         // 濡傛灉 socialType 闈炵┖锛岃鏄庨渶瑕佺粦瀹氱ぞ浜ょ敤鎴�
         if (reqVO.getSocialType() != null) {
+            if (WECHAT_ENTERPRISE_TYPE.equals(reqVO.getSocialType())) {
+                SocialUserRespDTO social = socialUserService.getSocialUserByCode(getUserType().getValue(),
+                        reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState());
+                if (wxcpMembershipRegistration == null || social == null
+                        || wxcpMembershipRegistration.hasPendingApplication(social.getOpenid())) {
+                    throw exception(AUTH_WXCP_MEMBERSHIP_PENDING);
+                }
+            }
             socialUserService.bindSocialUser(new SocialUserBindReqDTO(user.getId(), getUserType().getValue(),
                     reqVO.getSocialType(), reqVO.getSocialCode(), reqVO.getSocialState()));
         }
@@ -228,6 +242,11 @@
         AdminUserDO user = bindUserId != null ? userService.getUser(bindUserId) : null;
 
         if (user == null) {
+            if (WECHAT_ENTERPRISE_TYPE.equals(reqVO.getType())) {
+                if (wxcpMembershipRegistration == null) throw new IllegalStateException("浼氬憳娉ㄥ唽鏈嶅姟涓嶅彲鐢�");
+                wxcpMembershipRegistration.startIfAbsent(socialUser.getOpenid(), socialUser.getNickname(), socialUser.getMobile());
+                return null; // 鎻愪氦浜嬪姟鍚庣敱 Controller 杩斿洖寰呭鏍告彁绀猴紝涓嶇鍙戜护鐗�
+            }
             // 2.1 棣栨鐧诲綍锛屾垨鍘熺粦瀹氱敤鎴峰凡琚垹闄わ細鑷姩娉ㄥ唽鏂扮敤鎴峰苟锛堟敼锛夌粦瀹�
             //
             // 鍘熺粦瀹氱敤鎴峰凡鍒犻櫎鏃跺繀椤昏蛋杩欐潯璺細鍚﹀垯璇ヤ紒涓氭垚鍛樹細姘镐箙鍗″湪銆岀敤鎴蜂笉瀛樺湪銆嶁�斺��
@@ -245,8 +264,12 @@
                     user.getId(), user.getUsername(), reqVO.getType());
         }
 
+        if (CommonStatusEnum.isDisable(user.getStatus())) throw exception(AUTH_LOGIN_USER_DISABLED);
         // 3. 鍒涘缓 Token 浠ょ墝锛岃褰曠櫥褰曟棩蹇�
         AuthLoginRespVO result = createTokenAfterLoginSuccess(user.getId(), user.getUsername(), LoginLogTypeEnum.LOGIN_SOCIAL);
+        if (WECHAT_ENTERPRISE_TYPE.equals(reqVO.getType())) {
+            wxcpPasswordSetupGrant.issue(result.getAccessToken(), user.getId());
+        }
 
         // 4. 鍙戝竷绀句氦鐧诲綍浜嬩欢锛堜緵鍏朵粬妯″潡鐩戝惉锛屽鍙戦�佷紒涓氬井淇¢�氱煡锛�
         eventPublisher.publishEvent(new SocialLoginEvent(
@@ -435,4 +458,4 @@
 
         userService.updateUserPassword(userByMobile.getId(), reqVO.getPassword());
     }
-}
\ No newline at end of file
+}

--
Gitblit v1.9.3