'提交代码'

dev-discount
胡锐 4 years ago
parent 0cbf984e9b
commit 1cf9ad598a
  1. 87
      hai-cweb/src/main/java/com/cweb/controller/HighUserCommonController.java
  2. 31
      hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java

@ -0,0 +1,87 @@
package com.cweb.controller;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.alibaba.fastjson.JSONObject;
import com.cweb.config.SessionKeyCache;
import com.cweb.config.WxMaConfiguration;
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.security.VerifyCode;
import com.hai.common.security.VerifyCodeStorage;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.HighUser;
import com.hai.model.HighUserModel;
import com.hai.model.ResponseData;
import com.hai.service.HighUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
@Controller
@RequestMapping(value = "/user")
@Api(value = "用户共用接口")
public class HighUserCommonController {
private static final Logger log = LoggerFactory.getLogger(WechatController.class);
@Resource
private HighUserService highUserService;
@Resource
private UserCenter userCenter;
@RequestMapping(value = "/login", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "登录接口【用户不存在会自动注册】")
public ResponseData login(@RequestParam(value = "phone", required = true) String phone,
@RequestParam(value = "code", required = true) String code,
HttpServletRequest request, HttpServletResponse response) {
try {
VerifyCode verifyCode = VerifyCodeStorage.getDate(phone);
if(verifyCode == null) {
log.error("HighUserController --> bindUserPhone() error!", "验证码错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "验证码错误");
}
if(!verifyCode.getObject().equals(code)) {
log.error("HighUserController --> bindUserPhone() error!", "验证码错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "验证码错误");
}
HighUser user = highUserService.findByPhone(phone);
if(user == null) {
user = new HighUser();
user.setName("用户" + System.currentTimeMillis());
user.setPhone(phone);
user.setGold(0);
user.setRegTime(new Date());
user.setStatus(1);
highUserService.insertUser(user);
}
// 定义个人所有数据
HighUserModel highUserModel = new HighUserModel();
user.setPassword(null);
highUserModel.setHighUser(user);
SessionObject so = new SessionObject(user.getOpenId(), 1 , highUserModel);
userCenter.save(request, response, so);
return ResponseMsgUtil.success(so);
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
}

@ -94,12 +94,6 @@ public class HighUserServiceImpl implements HighUserService {
@Override @Override
@Transactional(propagation= Propagation.REQUIRES_NEW) @Transactional(propagation= Propagation.REQUIRES_NEW)
public HighUser bindUserPhone(String phone, HttpServletRequest request) throws Exception { 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); SessionObject sessionObject = userCenter.getSessionObject(request);
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
@ -107,14 +101,25 @@ public class HighUserServiceImpl implements HighUserService {
if (highUser == null) { if (highUser == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到用户"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到用户");
} }
highUser.setStatus(0);
highUserMapper.updateByPrimaryKey(highUser);
user.setHeaderImg(highUser.getHeaderImg()); // 查询手机号是否被绑定
user.setName(highUser.getName()); HighUser user = findByPhone(phone);
user.setOpenId(highUser.getOpenId()); if (user != null) {
highUserMapper.updateByPrimaryKey(user); if (StringUtils.isNotBlank(user.getOpenId())) {
return user; 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;
}
highUser.setPhone(phone);
highUserMapper.updateByPrimaryKey(highUser);
return highUser;
} }
@Override @Override

Loading…
Cancel
Save