From 5b275c38c82bd54496dc2b2d268cde1ec9ec2b29 Mon Sep 17 00:00:00 2001
From: 陶杰 <1378534974@qq.com>
Date: 星期日, 29 十二月 2024 14:58:23 +0800
Subject: [PATCH] 1.行政区划:(高德、腾讯)相关修改

---
 src/main/java/com/mzl/flower/web/login/CustomerLoginController.java |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/mzl/flower/web/login/CustomerLoginController.java b/src/main/java/com/mzl/flower/web/login/CustomerLoginController.java
index 1f5b9a9..f0b1510 100644
--- a/src/main/java/com/mzl/flower/web/login/CustomerLoginController.java
+++ b/src/main/java/com/mzl/flower/web/login/CustomerLoginController.java
@@ -14,7 +14,12 @@
 import com.mzl.flower.constant.Constants;
 import com.mzl.flower.dto.request.CreateWechatUserDTO;
 import com.mzl.flower.dto.request.UserLoginDTO;
+import com.mzl.flower.dto.response.customer.CustomerDTO;
+import com.mzl.flower.dto.response.wx.WxUserVO;
 import com.mzl.flower.entity.system.User;
+import com.mzl.flower.mapper.customer.CustomerMapper;
+import com.mzl.flower.service.customer.CustomerService;
+import com.mzl.flower.service.impl.WechatUserDetailsService;
 import com.mzl.flower.service.login.LoginService;
 import com.mzl.flower.service.system.UserService;
 import com.mzl.flower.service.system.WeChatService;
@@ -33,10 +38,12 @@
 import org.springframework.security.oauth2.common.OAuth2RefreshToken;
 import org.springframework.security.oauth2.provider.token.TokenStore;
 import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
+import org.springframework.util.ObjectUtils;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.constraints.NotBlank;
+import java.util.Map;
 
 @Slf4j
 @RestController
@@ -61,6 +68,9 @@
     @Autowired
     private UserService userService;
 
+    @Autowired
+    private CustomerMapper customerMapper;
+
 
     @Autowired
     private TokenStore tokenStore;
@@ -68,6 +78,7 @@
     public static final String TOKEN_KEY = "TOKEN-KEY";
 
     public static final String SEPARATOR = ":";
+
 
     @PostMapping("/login/wechat")
     @ApiOperation(value = "微信小程序登录", notes = "微信小程序登录")
@@ -77,6 +88,17 @@
         String openId = session.getOpenid();
         String sessionKey = session.getSessionKey();
         String unionId = session.getUnionid();
+        // 判断当前用户账号是否存在
+        dto.setOpenId(openId);
+        dto.setSessionKey(sessionKey);
+        dto.setUnionId(unionId);
+        dto.setUserType(Constants.USER_TYPE.customer.name());
+
+        User existUserByOpenId = userService.getExistUserByOpenId(openId, sessionKey, unionId, Constants.USER_TYPE.customer.name());
+        if(ObjectUtils.isEmpty(existUserByOpenId)){
+            userService.registWxUser(dto);
+        }
+
         User user = userService.findUserByOpenId(openId, sessionKey, unionId
                 , dto.getImgUrl(), dto.getNickname(),Constants.USER_TYPE.customer.name());
         String tokenCache = stringCacheClient.get(TOKEN_KEY + SEPARATOR + user.getId());
@@ -99,6 +121,23 @@
             log.error(e.getMessage(), e);
             throw new BaseException(R.RUNTIME_EXCEPTION.getCode(), "登录错误");
         }
+    }
+
+    @PostMapping("/wx/getuserphonenumber")
+    @ApiOperation(value = "获取当前授权的手机号")
+    public ResponseEntity<ReturnDataDTO> getuserphonenumber(@RequestBody CreateWechatUserDTO dto) throws Exception{
+        return returnData(R.SUCCESS.getCode(), weChatService.getuserphonenumber(dto));
+    }
+
+    @PostMapping("/wx/getExistUserByOpenId")
+    @ApiOperation(value = "查看当前微信号是否已经绑定了用户")
+    public ResponseEntity<ReturnDataDTO> getExistUserByOpenId(@RequestBody CreateWechatUserDTO dto) throws Exception{
+        WxMaJscode2SessionResult session = weChatService.getWxMaSessionInfo(dto.getCode());
+        String openId = session.getOpenid();
+        String sessionKey = session.getSessionKey();
+        String unionId = session.getUnionid();
+        User user=userService.getExistUserByOpenId(openId, sessionKey, unionId,dto.getUserType());
+        return returnData(R.SUCCESS.getCode(), new WxUserVO(openId,sessionKey,unionId,user));
     }
 
     @GetMapping("/wx/jscode2session")
@@ -124,6 +163,13 @@
         User user = userService.findByTel(username, Constants.USER_TYPE.customer.name());
         if(user == null){
             throw new ValidationException("用户不存在");
+        }
+        CustomerDTO currentCustomer = customerMapper.getCurrentCustomer(user.getId());
+        if (ObjectUtils.isEmpty(currentCustomer)) {
+            throw new ValidationException("用户不存在");
+        }
+        if (currentCustomer.getIsEnabled() == false) {
+            throw new ValidationException("用户已禁用,请联系管理员");
         }
         String tokenCache = stringCacheClient.get(TOKEN_KEY + SEPARATOR + user.getId());
         if (StringUtils.isNotBlank(tokenCache))  {
@@ -171,6 +217,13 @@
         if(user == null){
             throw new ValidationException("用户不存在");
         }
+        CustomerDTO currentCustomer = customerMapper.getCurrentCustomer(user.getId());
+        if (ObjectUtils.isEmpty(currentCustomer)) {
+            throw new ValidationException("用户不存在");
+        }
+        if (currentCustomer.getIsEnabled() == false) {
+            throw new ValidationException("用户已禁用,请联系管理员");
+        }
         String tokenCache = stringCacheClient.get(TOKEN_KEY + SEPARATOR + user.getId());
         if (StringUtils.isNotBlank(tokenCache))  {
             //强制删除token,下线

--
Gitblit v1.9.3