springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/dtos/community/microCommercialStreet/LoginWithPhoneDTO.java
New file @@ -0,0 +1,29 @@ package com.panzhihua.common.model.dtos.community.microCommercialStreet; import javax.validation.constraints.NotBlank; import javax.validation.constraints.Pattern; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; /** * @title: LoginWithPhoneDTO * @projectName: 成都呐喊信息技术有限公司-智慧社区项目 * @description: 手机号登录请求参数 * @author: hans * @date: 2022/01/06 16:40 */ @Data @ApiModel("手机号登录请求参数") public class LoginWithPhoneDTO { @ApiModelProperty("手机号") @NotBlank(message = "手机号不能为空") @Pattern(message = "手机号格式错误", regexp = "^(13[0-9]|14[01456879]|15[0-3,5-9]|16[2567]|17[0-8]|18[0-9]|19[0-3,5-9])\\d{8}$") private String phone; @ApiModelProperty("验证码") @NotBlank(message = "验证码不能为空") private String code; } springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/service/community/CommunityService.java
@@ -4,6 +4,7 @@ import com.panzhihua.common.model.dtos.PageBaseDTO; import com.panzhihua.common.model.dtos.community.microCommercialStreet.DisableOrEnableMcsMerchantDTO; import com.panzhihua.common.model.dtos.community.microCommercialStreet.LoginWithPhoneDTO; import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsGameDTO; import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsInfoDTO; import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsMerchantDTO; @@ -8079,4 +8080,12 @@ */ @PostMapping("/mcsOrder/notify") R notifyMcsOrder(@RequestBody McsOrderVO mcsOrderVO); /** * 验证码登录 * @param loginDTO * @return */ @PostMapping("/microcommercialstreet/loginWithPhone") R loginWithPhone(@RequestBody LoginWithPhoneDTO loginDTO); } springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/service/user/UserService.java
@@ -1118,4 +1118,13 @@ */ @PutMapping("checkUserIsValid") Boolean checkUserIsValid(@RequestParam("userId") Long userId, @RequestParam("type") Integer type); /** * 根据手机号、用户类型查询用户 * @param phone * @param type * @return */ @GetMapping("/getSysUserByPhone") R getSysUserByPhone(@RequestParam("phone") String phone, @RequestParam("type") Integer type); } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/api/MicroCommercialStreetApi.java
@@ -4,6 +4,7 @@ import javax.annotation.Resource; import com.panzhihua.common.model.dtos.community.microCommercialStreet.LoginWithPhoneDTO; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -421,4 +422,14 @@ @RequestParam("userId") Long userId) { return mcsMerchantService.updateOrAddMcsMerchantAfterOrder(merchantName, configId, userId); } /** * 验证码登录 * @param loginDTO * @return */ @PostMapping("/loginWithPhone") public R loginWithPhone(@RequestBody LoginWithPhoneDTO loginDTO) { return mcsMerchantService.loginWithPhone(loginDTO); } } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/McsMerchantService.java
@@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.panzhihua.common.model.dtos.community.microCommercialStreet.DisableOrEnableMcsMerchantDTO; import com.panzhihua.common.model.dtos.community.microCommercialStreet.LoginWithPhoneDTO; import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsMerchantDTO; import com.panzhihua.common.model.dtos.community.microCommercialStreet.PageMcsMerchantDTO; import com.panzhihua.common.model.vos.R; @@ -74,4 +75,11 @@ * @return */ R updateOrAddMcsMerchantAfterOrder(String merchantName, Long configId, Long userId); /** * 验证码登录 * @param loginDTO * @return */ R loginWithPhone(LoginWithPhoneDTO loginDTO); } springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/McsMerchantServiceImpl.java
@@ -9,8 +9,13 @@ import java.util.List; import javax.annotation.Resource; import javax.validation.constraints.NotBlank; import javax.validation.constraints.Pattern; import com.panzhihua.common.model.dtos.community.microCommercialStreet.LoginWithPhoneDTO; import org.springframework.beans.BeanUtils; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -54,6 +59,8 @@ private McsConfigDAO mcsConfigDAO; @Resource private McsGameDAO mcsGameDAO; @Resource private StringRedisTemplate stringRedisTemplate; /** * 新增数字商业街商家 @@ -81,8 +88,8 @@ //添加user R addUserResult = userService.addMcsMerchantUser(mcsMerchantDTO); if (R.isOk(addUserResult)) { Long merchantUserId = ((Integer) addUserResult.getData()).longValue(); mcsMerchant.setUserId(merchantUserId); LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(addUserResult.getData()), LoginUserInfoVO.class); mcsMerchant.setUserId(loginUserInfoVO.getUserId()); this.baseMapper.updateById(mcsMerchant); } else { throw new ServiceException("406", addUserResult.getMsg()); @@ -278,6 +285,47 @@ } } /** * 验证码登录 * @param loginDTO * @return */ @Override public R loginWithPhone(LoginWithPhoneDTO loginDTO) { String phone = loginDTO.getPhone(); String redisKey = String.join("::", phone, loginDTO.getCode()); Boolean hasKey = stringRedisTemplate.hasKey(redisKey); if (hasKey) { //通过验证 R r = userService.getSysUserByPhone(phone, 11); if (R.isOk(r)) { if (nonNull(r.getData())) { //已有用户 LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(r.getData()), LoginUserInfoVO.class); stringRedisTemplate.delete(redisKey); return R.ok(loginUserInfoVO); } else { //自动创建用户 McsMerchantDTO mcsMerchantDTO = new McsMerchantDTO(); mcsMerchantDTO.setAccount(phone); mcsMerchantDTO.setPassword("88888888"); mcsMerchantDTO.setAccountStatus(1); mcsMerchantDTO.setPhone(phone); R addUserResult = userService.addMcsMerchantUser(mcsMerchantDTO); if (R.isOk(addUserResult)) { LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(addUserResult.getData()), LoginUserInfoVO.class); stringRedisTemplate.delete(redisKey); return R.ok(loginUserInfoVO); } return addUserResult; } } return r; } else { return R.fail("验证码错误"); } } private void retrieveMerchantSurplusLitDays(McsMerchantVO merchantVO) { Integer publishLimit = merchantVO.getPublishLimit(); Integer publishCount = mcsGameDAO.selectPublishCount(merchantVO.getId()); springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/api/UserApi.java
@@ -1268,4 +1268,15 @@ public Boolean checkUserIsValid(@RequestParam("userId") Long userId, @RequestParam("type") Integer type) { return userService.checkUserIsValid(userId, type); } /** * 根据手机号、用户类型查询用户 * @param phone * @param type * @return */ @GetMapping("/getSysUserByPhone") public R getSysUserByPhone(@RequestParam("phone") String phone, @RequestParam("type") Integer type) { return userService.getSysUserByPhone(phone, type); } } springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/UserService.java
@@ -779,4 +779,12 @@ * @return */ Boolean checkUserIsValid(Long userId, Integer type); /** * 根据手机号、用户类型查询用户 * @param phone * @param type * @return */ R getSysUserByPhone(String phone, Integer type); } springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java
@@ -14,9 +14,7 @@ import java.util.stream.Collectors; import javax.annotation.Resource; import javax.validation.constraints.NotBlank; import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsMerchantDTO; import org.apache.commons.lang.time.DateFormatUtils; import org.apache.commons.lang.time.DateUtils; import org.springframework.beans.BeanUtils; @@ -41,6 +39,7 @@ import com.panzhihua.common.model.dtos.community.NoticeReadDTO; import com.panzhihua.common.model.dtos.community.convenient.ConvenientMerchantDTO; import com.panzhihua.common.model.dtos.community.convenient.DisableOrEnableConvenientMerchantDTO; import com.panzhihua.common.model.dtos.community.microCommercialStreet.McsMerchantDTO; import com.panzhihua.common.model.dtos.grid.EventGridMemberAddDTO; import com.panzhihua.common.model.dtos.grid.EventGridMemberEditAdminDTO; import com.panzhihua.common.model.dtos.grid.EventGridMemberEditStatusDTO; @@ -2819,17 +2818,18 @@ } // sys_user 表 sysUserDO = new SysUserDO(); String encode = new BCryptPasswordEncoder().encode(mcsMerchantDTO.getPassword()); BeanUtils.copyProperties(mcsMerchantDTO, sysUserDO); sysUserDO.setAccount(mcsMerchantDTO.getAccount()); sysUserDO.setType(11); sysUserDO.setAreaId(null); sysUserDO.setStatus(mcsMerchantDTO.getAccountStatus()); sysUserDO.setPhone(mcsMerchantDTO.getPhone()); sysUserDO.setPassword(encode); sysUserDO.setPassword(mcsMerchantDTO.getPassword()); try { userDao.insert(sysUserDO); return R.ok(sysUserDO.getUserId()); LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO(); BeanUtils.copyProperties(sysUserDO, loginUserInfoVO); return R.ok(loginUserInfoVO); } catch (Exception e) { e.printStackTrace(); log.error("修改数字商业街商家用户报错【{}】", e.getMessage()); @@ -2900,4 +2900,20 @@ } return true; } /** * 根据手机号、用户类型查询用户 * @param phone * @param type * @return */ @Override public R getSysUserByPhone(String phone, Integer type) { SysUserDO sysUserDO = userDao.selectOne(new QueryWrapper<SysUserDO>().lambda().eq(SysUserDO::getPhone, phone).eq(SysUserDO::getType, type)); LoginUserInfoVO loginUserInfoVO = new LoginUserInfoVO(); if (nonNull(sysUserDO)) { BeanUtils.copyProperties(sysUserDO, loginUserInfoVO); } return R.ok(loginUserInfoVO); } } springcloud_k8s_panzhihuazhihuishequ/shop_backstage/src/main/java/com/panzhihua/shop_backstage/api/MicroCommercialStreetApi.java
@@ -3,6 +3,7 @@ import javax.annotation.Resource; import javax.validation.Valid; import com.panzhihua.common.model.dtos.community.microCommercialStreet.LoginWithPhoneDTO; import org.springframework.beans.BeanUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; @@ -72,7 +73,7 @@ @ApiOperation(value = "微商业街商家后台登录", response = LoginReturnVO.class) @PostMapping("/merchant/login") public R login(@RequestBody @Valid LoginBody loginBody) { public R merchantLogin(@RequestBody @Valid LoginBody loginBody) { String account = loginBody.getAccount(); log.info("登录用户信息【{}】", loginBody); try { @@ -94,6 +95,29 @@ } } @ApiOperation(value = "微商业街用户登录", response = LoginReturnVO.class) @PostMapping("/loginWithPhone") public R loginWithPhone(@RequestBody @Valid LoginWithPhoneDTO loginDTO) { log.info("登录用户信息【{}】", loginDTO); try { R r = communityService.loginWithPhone(loginDTO); Boolean isValid = false; if (R.isOk(r) && r.getData() != null) { LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(r.getData()), LoginUserInfoVO.class); isValid = loginUserInfoVO.getStatus() == 1; if (isValid) { R result = tokenService.loginMcsUser(loginUserInfoVO.getAccount(), loginUserInfoVO.getPassword()); return result; } else { return R.fail("账号被禁用"); } } return R.fail(r.getMsg()); } catch (Exception e) { return R.fail("登陆失败了"); } } @ApiOperation(value = "当前登录用户信息", response = LoginMerchantUserInfoVO.class) @GetMapping("/userInfo") public R detailUser() {