'提交代码'

dev-discount
= 4 years ago
parent 2459d0505f
commit 0cbf984e9b
  1. 38
      hai-cweb/src/main/java/com/cweb/controller/HighUserController.java
  2. 3
      hai-cweb/src/main/java/com/cweb/controller/WechatController.java
  3. 10
      hai-service/src/main/java/com/hai/service/HighUserService.java
  4. 35
      hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java

@ -18,6 +18,8 @@ import com.hai.service.HighUserCouponService;
import com.hai.service.HighUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -29,6 +31,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @Auther: 袁野
@ -79,37 +82,34 @@ public class HighUserController {
}
@RequestMapping(value = "/updateUserPhone", method = RequestMethod.GET)
@RequestMapping(value = "/bindUserPhone", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "修改用户手机号")
public ResponseData updateUserPhone(@RequestParam(value = "phone", required = true) String phone,
@ApiOperation(value = "绑定用户手机号")
public ResponseData bindUserPhone(@RequestParam(value = "phone", required = true) String phone,
@RequestParam(value = "code", required = true) String code,
HttpServletRequest request) {
HttpServletRequest request, HttpServletResponse response) {
try {
VerifyCode verifyCode = VerifyCodeStorage.getDate(phone);
if(verifyCode == null) {
log.error("HighUserController --> updateUserPhone() error!", "验证码错误");
log.error("HighUserController --> bindUserPhone() error!", "验证码错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "验证码错误");
}
if(!verifyCode.getObject().equals(code)) {
log.error("HighUserController --> updateUserPhone() error!", "验证码错误");
log.error("HighUserController --> bindUserPhone() error!", "验证码错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "验证码错误");
}
// 用户
SessionObject sessionObject = userCenter.getSessionObject(request);
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
HighUser highUser = highUserService.findByUserId(userInfoModel.getHighUser().getId());
if (highUser == null) {
log.error("HighUserController --> updateUserPhone() error!", "未找到用户");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到用户");
}
highUser.setPhone(phone);
highUserService.updateUser(highUser);
return ResponseMsgUtil.success("修改成功");
HighUser highUser = highUserService.bindUserPhone(phone, request);
HighUserModel highUserModel = new HighUserModel();
highUser.setPassword(null);
highUserModel.setHighUser(highUser);
SessionObject so = new SessionObject(highUser.getOpenId(), 1 , highUserModel);
userCenter.save(request, response, so);
return ResponseMsgUtil.success(so);
} catch (Exception e) {
log.error("HighUserController --> updateUserPhone() error!", e);
log.error("HighUserController --> bindUserPhone() error!", e);
return ResponseMsgUtil.exception(e);
}
}

@ -146,7 +146,6 @@ public class WechatController {
highUserService.insertUser(user);
} else {
user.setPhone(phoneNoInfo.getPurePhoneNumber());
user.setOpenId(openId);;
highUserService.updateUser(user);
}
@ -203,7 +202,6 @@ public class WechatController {
user.setName(userInfo.getNickName());
highUserService.insertUser(user);
} else {
user.setOpenId(openId);
user.setHeaderImg(userInfo.getAvatarUrl());
user.setName(userInfo.getNickName());
highUserService.updateUser(user);
@ -314,7 +312,6 @@ public class WechatController {
user.setName(userInfo.getString("nickname"));
highUserService.insertUser(user);
} else {
user.setOpenId(openid);
user.setHeaderImg(userInfo.getString("headimgurl"));
user.setName(userInfo.getString("nickname"));
highUserService.updateUser(user);

@ -2,6 +2,7 @@ package com.hai.service;
import com.hai.entity.HighUser;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@ -53,6 +54,15 @@ public interface HighUserService {
**/
HighUser findByPhone(String phone);
/**
* 绑定手机号
* @param phone
* @param request
* @return
* @throws Exception
*/
HighUser bindUserPhone(String phone, HttpServletRequest request) throws Exception;
/**
*
* @Title: updateUser

@ -3,11 +3,14 @@ package com.hai.service.impl;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter;
import com.hai.common.utils.DateUtil;
import com.hai.dao.HighUserMapper;
import com.hai.entity.HighGoldRec;
import com.hai.entity.HighUser;
import com.hai.entity.HighUserExample;
import com.hai.model.HighUserModel;
import com.hai.service.HighGoldRecService;
import com.hai.service.HighUserService;
import org.apache.commons.lang3.StringUtils;
@ -16,6 +19,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;
@ -32,6 +36,9 @@ public class HighUserServiceImpl implements HighUserService {
@Resource
private HighGoldRecService highGoldRecService;
@Resource
private UserCenter userCenter;
@Override
public List<HighUser> getListUser(Map<String, String> map) {
@ -76,7 +83,7 @@ public class HighUserServiceImpl implements HighUserService {
@Override
public HighUser findByPhone(String phone) {
HighUserExample example = new HighUserExample();
example.createCriteria().andPhoneEqualTo(phone);
example.createCriteria().andPhoneEqualTo(phone).andStatusEqualTo(1);
List<HighUser> list = highUserMapper.selectByExample(example);
if (list != null && list.size() > 0) {
return list.get(0);
@ -84,6 +91,32 @@ public class HighUserServiceImpl implements HighUserService {
return null;
}
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW)
public HighUser bindUserPhone(String phone, HttpServletRequest request) throws Exception {
// 查询手机号是否被绑定
HighUser user = findByPhone(phone);
if (user != null && StringUtils.isNotBlank(user.getOpenId())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "手机号已被绑定");
}
// 用户
SessionObject sessionObject = userCenter.getSessionObject(request);
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
HighUser highUser = findByUserId(userInfoModel.getHighUser().getId());
if (highUser == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到用户");
}
highUser.setStatus(0);
highUserMapper.updateByPrimaryKey(highUser);
user.setHeaderImg(highUser.getHeaderImg());
user.setName(highUser.getName());
user.setOpenId(highUser.getOpenId());
highUserMapper.updateByPrimaryKey(user);
return user;
}
@Override
public void updateUser(HighUser highUser) {
highUserMapper.updateByPrimaryKeySelective(highUser);

Loading…
Cancel
Save