政策相关配置文件
This commit is contained in:
@@ -745,4 +745,59 @@ public class SysLoginService
|
||||
ajax.put("isCompanyUser",appUser.getIsCompanyUser());
|
||||
return ajax;
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录注册二合一接口
|
||||
* 根据手机号查询用户,存在则登录,不存在则注册后登录
|
||||
* @param loginBody 包含姓名(必填)、电话(必填)、身份证(非必填)
|
||||
* @return
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AjaxResult loginOrRegister(LoginBody loginBody) {
|
||||
String phone = loginBody.getUsername();
|
||||
String name = loginBody.getName();
|
||||
String idCard = loginBody.getIdCard();
|
||||
|
||||
// 根据手机号查询用户
|
||||
AppUser appUser = appUserService.getPhone(phone);
|
||||
boolean isNewUser = false;
|
||||
|
||||
if (appUser == null) {
|
||||
// 用户不存在,执行注册
|
||||
appUser = new AppUser();
|
||||
appUser.setPhone(phone);
|
||||
appUser.setName(name);
|
||||
appUser.setIdCard(idCard);
|
||||
appUser.setLoginDate(new Date());
|
||||
appUserService.insertAppUser(appUser);
|
||||
isNewUser = true;
|
||||
} else {
|
||||
// 用户存在,更新信息(如果传入了新值)
|
||||
AppUser updateParam = new AppUser();
|
||||
updateParam.setUserId(appUser.getUserId());
|
||||
boolean needUpdate = false;
|
||||
if (StringUtils.isNotBlank(name) && !name.equals(appUser.getName())) {
|
||||
updateParam.setName(name);
|
||||
appUser.setName(name);
|
||||
needUpdate = true;
|
||||
}
|
||||
if (StringUtils.isNotBlank(idCard) && !idCard.equals(appUser.getIdCard())) {
|
||||
updateParam.setIdCard(idCard);
|
||||
appUser.setIdCard(idCard);
|
||||
needUpdate = true;
|
||||
}
|
||||
updateParam.setLoginDate(new Date());
|
||||
if (needUpdate) {
|
||||
appUserService.updateAppUser(updateParam);
|
||||
}
|
||||
}
|
||||
|
||||
// 生成token并返回
|
||||
String token = loginUserIdApp(appUser);
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put(Constants.TOKEN, token);
|
||||
ajax.put("isNewUser", isNewUser);
|
||||
ajax.put("idCard", appUser.getIdCard());
|
||||
return ajax;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user