From ef684096ece7f699447bf567c4d89eecd9b3d200 Mon Sep 17 00:00:00 2001 From: 彭雪彬 <1724387007@qq.com> Date: Wed, 23 Jul 2025 10:57:33 +0800 Subject: [PATCH] 骑手完成订单时判断是否上传送达图片 --- oying-system/src/main/java/com/oying/modules/security/rest/AuthController.java | 97 ++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 85 insertions(+), 12 deletions(-) diff --git a/oying-system/src/main/java/com/oying/modules/security/rest/AuthController.java b/oying-system/src/main/java/com/oying/modules/security/rest/AuthController.java index 9a1f84c..5ce08d2 100644 --- a/oying-system/src/main/java/com/oying/modules/security/rest/AuthController.java +++ b/oying-system/src/main/java/com/oying/modules/security/rest/AuthController.java @@ -2,6 +2,8 @@ import cn.hutool.core.util.IdUtil; import com.alibaba.fastjson2.JSONObject; +import com.oying.modules.rider.domain.RiderInfo; +import com.oying.modules.rider.service.RiderInfoService; import com.oying.modules.security.config.CaptchaConfig; import com.oying.modules.security.config.LoginProperties; import com.oying.modules.security.config.SecurityProperties; @@ -67,6 +69,7 @@ private final WeiXinService weiXinService; private final UserService userService; private final DictDetailService dictDetailService; + private final RiderInfoService riderInfoService; @Log("账号密码登录") @ApiOperation("账号密码登录") @@ -81,7 +84,7 @@ if (StringUtils.isBlank(code)) { throw new BadRequestException("验证码不存在或已过期"); } - if (StringUtils.isBlank(authUser.getCode()) || !authUser.getCode().equalsIgnoreCase(code)) { + if (!authUser.getCode().equalsIgnoreCase(code)) { throw new BadRequestException("验证码错误"); } // 获取用户信息 @@ -120,7 +123,7 @@ if (StringUtils.isBlank(code)) { throw new BadRequestException("验证码不存在或已过期"); } - if (StringUtils.isBlank(authUser.getCode()) || !authUser.getCode().equalsIgnoreCase(code)) { + if (!authUser.getCode().equalsIgnoreCase(code)) { throw new BadRequestException("验证码错误"); } // 获取用户信息 @@ -147,22 +150,18 @@ public static final String OLD = "OLD"; public static final String NEW = "NEW"; - @Log("微信授权登录") - @ApiOperation("微信授权登录") + @Log("小程序:微信授权登录") + @ApiOperation("小程序:微信授权登录") @AnonymousPostMapping(value = "/login/weixin") public ResponseEntity<Object> loginWeixin(@Validated @RequestBody AuthUserWeixinDto authUser, HttpServletRequest request) throws Exception { JSONObject jsonObject; - switch (authUser.getCode()) { + switch (authUser.getType()) { case OLD: jsonObject = weiXinService.code2Session(authUser.getCode()); String openid = jsonObject.getString("openid"); User userDto = userService.findByOpenid(openid); if (userDto == null) { - Map<String, Object> authInfo = new HashMap<String, Object>(2) {{ - put("token", openid); - put("member", null); - }}; - return ResponseEntity.ok(authInfo); + return ResponseEntity.ok(R.success(openid)); } authUser.setUsername(userDto.getUsername()); break; @@ -174,8 +173,10 @@ //创建用户 User user = new User(); user.setUsername(phone); - user.setNickName("LYHD-" + phone); + user.setNickName("OYING-" + phone); user.setUserType(ConstantsKey.BUYER); + user.setPhone(phone); + user.setGender("男"); user.setEnabled(true); getRole(user); user.setPassword(passwordEncoder.encode(phone.substring(phone.length() - 6))); @@ -221,11 +222,83 @@ Set<Role> roles = new HashSet<>(); Role role = new Role(); DictDetail detail = dictDetailService.getDictByName(ConstantsKey.USER_TYPE_BUYER).get(0); - role.setId(Long.valueOf(detail.getLabel())); + role.setId(Long.valueOf(detail.getValue())); roles.add(role); user1.setRoles(roles); } + @Log("骑手小程序:微信授权登录") + @ApiOperation("骑手小程序:微信授权登录") + @AnonymousPostMapping(value = "/rider/login/weixin") + public ResponseEntity<Object> riderLoginWeixin(@Validated @RequestBody AuthUserWeixinDto authUser, HttpServletRequest request) throws Exception { + JSONObject jsonObject; + switch (authUser.getType()) { + case OLD: + jsonObject = weiXinService.code2SessionRider(authUser.getCode()); + String openid = jsonObject.getString("openid"); + User userDto = userService.findByRiderOpenId(openid); + if (userDto == null) { + return ResponseEntity.ok(R.success(openid)); + } + authUser.setUsername(userDto.getUsername()); + break; + case NEW: + jsonObject = weiXinService.getRiderPhoneNumber(authUser.getCode()); + String phone = jsonObject.getJSONObject("phone_info").getString("purePhoneNumber"); + User user1 = userService.findByName(phone); + if (user1 == null) { + //创建用户 + User user = new User(); + user.setUsername(phone); + user.setNickName("OYING-" + phone); + user.setUserType(ConstantsKey.BUYER); + user.setPhone(phone); + user.setGender("男"); + user.setEnabled(true); + getRole(user); + user.setPassword(passwordEncoder.encode(phone.substring(phone.length() - 6))); + user.setRiderOpenId(authUser.getUsername()); + userService.create(user); + } else { + if (user1.getUserType().equals(ConstantsKey.BUYER)) { + if (user1.getRoles() == null) { + getRole(user1); + } + } + user1.setRiderOpenId(authUser.getUsername()); + // userService.update(user1); + userService.updateRiderOpenId(user1); + } + authUser.setUsername(phone); + break; + default: + throw new BadRequestException("登录类型错误"); + + } + // 获取用户信息 + JwtUserDto jwtUser = userDetailsService.loadUserByUsername(authUser.getUsername()); + // 查询骑手信息 + RiderInfo riderInfo = riderInfoService.getRiderSourceInfo(jwtUser.getUser().getId()); + Authentication authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities()); + SecurityContextHolder.getContext().setAuthentication(authentication); + // 生成令牌 + String token = tokenProvider.createToken(jwtUser); + // 返回 token 与 用户信息 + Map<String, Object> authInfo = new HashMap<String, Object>(2) {{ + put("token", properties.getTokenStartWith() + token); + put("user", jwtUser); + put("rider", riderInfo); + }}; + if (loginProperties.isSingleLogin()) { + // 踢掉之前已经登录的token + onlineUserService.kickOutForUsername(authUser.getUsername()); + } + // 保存在线信息 + onlineUserService.save(jwtUser, token, request); + // 返回登录信息 + return ResponseEntity.ok(R.success(authInfo)); + } + @ApiOperation("临时授权") @AnonymousGetMapping(value = "/token") public ResponseEntity<Object> loginTest(@RequestParam String username, HttpServletRequest request) { -- Gitblit v1.9.3