登录接口

This commit is contained in:
wangh 2023-11-30 11:07:26 +08:00
parent 415369a430
commit 9ff4038838
7 changed files with 345 additions and 150 deletions

View File

@ -13,8 +13,10 @@ import com.fuint.business.userManager.entity.MtInvitation;
import com.fuint.business.userManager.entity.UserBalance;
import com.fuint.business.userManager.mapper.MtInvitationMapper;
import com.fuint.business.userManager.mapper.UserBalanceMapper;
import com.fuint.business.userManager.service.LJUserService;
import com.fuint.business.userManager.service.MtInvitationService;
import com.fuint.business.userManager.service.UserBalanceService;
import com.fuint.business.userManager.vo.LJUserVo;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.dto.MemberTopDto;
import com.fuint.common.dto.UserDto;
@ -725,9 +727,10 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
@Resource
private UserBalanceService userBalanceService;
@Autowired
@Resource
private ILJStoreService iljStoreService;
@Resource
LJUserService ljUserService;
@Override
public MtUser queryMemberByOpenId2(String openId, JSONObject userInfo) throws BusinessCheckException {
@ -747,130 +750,236 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
String source = StringUtil.isNotEmpty(userInfo.getString("source")) ? userInfo.getString("source") : MemberSourceEnum.WECHAT_LOGIN.getKey();
// openid没有时使用手机号
if (user == null) {
// 根绝手机号查询是否有该用户 没有则新建 有就更新
if (ObjectUtil.isNotEmpty(mobile) || "".equals(mobile)) {
MtUser mtUserMobile = queryMemberByMobile2(mobile);
MtUser mtUser = new MtUser();
if (StringUtil.isNotEmpty(mobile)) {
MtUser mtUserMobile = queryMemberByMobile2(mobile);
if (mtUserMobile != null) {
mtUser = mtUserMobile;
if (ObjectUtil.isEmpty(mtUserMobile)) {
// 新增
// LJUserVo userVo = new LJUserVo();
mtUser.setOpenId(openId);
mtUser.setMobile(mobile);
mtUser.setCreateTime(new Date());
mtUser.setUpdateTime(new Date());
mtUser.setDescription("微信登录自动注册");
mtUser.setStatus("qy");
mtUser.setSex(Integer.parseInt(gender));
mtUser.setUserNo(editUserNo());
// 微信用户 12 0未知
if (gender.equals(GenderEnum.FEMALE.getKey().toString())) {
gender = GenderEnum.UNKNOWN.getKey().toString();
} else if (gender.equals(GenderEnum.UNKNOWN.getKey().toString())) {
gender = GenderEnum.FEMALE.getKey().toString();
}
}
// 昵称为空用手机号
if (StringUtil.isEmpty(nickName) && StringUtil.isNotEmpty(mobile)) {
nickName = mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
}
String userNo = CommonUtil.createUserNo();
mobile = CommonUtil.replaceXSS(mobile);
avatar = CommonUtil.replaceXSS(avatar);
nickName = CommonUtil.replaceXSS(nickName);
mtUser.setUserNo(userNo);
mtUser.setMobile(mobile);
mtUser.setAvatar(avatar);
mtUser.setName(nickName);
mtUser.setOpenId(openId);
// MtUserGrade grade = userGradeService.getInitUserGrade(merchantId);
// if (grade != null) {
// mtUser.setGradeId(grade.getId() + "");
// }
Date time = new Date();
mtUser.setCreateTime(time);
mtUser.setUpdateTime(time);
mtUser.setBalance(new BigDecimal(0));
mtUser.setPoint(0);
mtUser.setDescription("微信登录自动注册");
mtUser.setIdcard("");
mtUser.setStatus("qy");
mtUser.setAddress(country + province + city);
// 微信用户 12 0未知
if (gender.equals(GenderEnum.FEMALE.getKey().toString())) {
gender = GenderEnum.UNKNOWN.getKey().toString();
} else if (gender.equals(GenderEnum.UNKNOWN.getKey().toString())) {
gender = GenderEnum.FEMALE.getKey().toString();
}
mtUser.setSex(Integer.parseInt(gender));
if (StringUtil.isNotEmpty(storeId)) {
mtUser.setStoreId(Integer.parseInt(storeId));
} else {
mtUser.setStoreId(0);
}
mtUser.setSource(source);
mtUser.setCreateTime(new Date());
mtUser.setUpdateTime(new Date());
if (mtUser.getId() == null || mtUser.getId() <= 0) {
save(mtUser);
} else {
updateById(mtUser);
}
user = mtUserMapper.queryMemberByOpenId2(openId);
// 新增余额信息
if (ObjectUtil.isNotEmpty(storeId) && storeId !="") {
// 根据userid和stortId查询是否存在对应的余额信息
UserBalance userBalance = userBalanceService.selectUserBalance(user.getId(), Integer.parseInt(storeId));
if (ObjectUtil.isEmpty(userBalance)) {
// 新增余额信息
UserBalance userBalanceAdd = new UserBalance();
userBalanceAdd.setMtUserId(user.getId());
userBalanceAdd.setStoreId(Integer.parseInt(storeId));
userBalanceAdd.setCardBalance(0.0);
userBalanceAdd.setPoints(0);
userBalanceAdd.setGrowthValue(0);
userBalanceAdd.setConsumeNum(0);
// 新增余额信息
if (ObjectUtil.isNotEmpty(storeId) && storeId !="") {
// 根据userid和stortId查询是否存在对应的余额信息
UserBalance userBalance = userBalanceService.selectUserBalance(user.getId(), Integer.parseInt(storeId));
if (ObjectUtil.isEmpty(userBalance)) {
// 新增余额信息
UserBalance userBalanceAdd = new UserBalance();
userBalanceAdd.setMtUserId(user.getId());
userBalanceAdd.setStoreId(Integer.parseInt(storeId));
userBalanceAdd.setCardBalance(0.0);
userBalanceAdd.setPoints(0);
userBalanceAdd.setGrowthValue(0);
userBalanceAdd.setConsumeNum(0);
MtUserGrade lowGrade = userGradeService.getLowGrade(Integer.parseInt(storeId));
if (ObjectUtil.isNotEmpty(lowGrade) && ObjectUtil.isNotEmpty(lowGrade.getId())) {
userBalanceAdd.setGradeId(lowGrade.getId());
MtUserGrade lowGrade = userGradeService.getLowGrade(Integer.parseInt(storeId));
if (ObjectUtil.isNotEmpty(lowGrade) && ObjectUtil.isNotEmpty(lowGrade.getId())) {
userBalanceAdd.setGradeId(lowGrade.getId());
}
// 新增会员余额信息
userBalanceService.insertUserBalance(userBalanceAdd);
}
LJStore store = iljStoreService.selectStoreByStoreId(Integer.parseInt(storeId));
// 查询关联表里面是否有信息
MtInvitation mtInvitation1 = mtInvitationMapper.queryByStoreId(Integer.parseInt(storeId), user.getId());
if (ObjectUtil.isEmpty(mtInvitation1)) {
MtInvitation mtInvitation = new MtInvitation();
mtInvitation.setUserId(user.getId());
mtInvitation.setStoreId(Integer.parseInt(storeId));
mtInvitation.setStaffId(Integer.parseInt(staffId));
mtInvitation.setInviterId(Integer.parseInt(inviterId));
if (!ObjectUtil.isEmpty(store)){
mtInvitation.setChainStoreId(store.getChainStoreId());
}
mtInvitationMapper.insert(mtInvitation);
}
// 新增会员余额信息
userBalanceService.insertUserBalance(userBalanceAdd);
}
LJStore store = iljStoreService.selectStoreByStoreId(Integer.parseInt(storeId));
// 查询关联表里面是否有信息
MtInvitation mtInvitation1 = mtInvitationMapper.queryByStoreId(Integer.parseInt(storeId), user.getId());
if (ObjectUtil.isEmpty(mtInvitation1)) {
MtInvitation mtInvitation = new MtInvitation();
mtInvitation.setUserId(user.getId());
mtInvitation.setStoreId(Integer.parseInt(storeId));
mtInvitation.setStaffId(Integer.parseInt(staffId));
mtInvitation.setInviterId(Integer.parseInt(inviterId));
if (!ObjectUtil.isEmpty(store)){
mtInvitation.setChainStoreId(store.getChainStoreId());
return mtUser;
}else {
// 已被禁用
if (user.getStatus().equals(StatusEnum.DISABLE.getKey())) {
return null;
}
// 修改
mtUserMobile.setOpenId(openId);
updateById(mtUserMobile);
if (ObjectUtil.isNotEmpty(storeId) && storeId !="") {
MtInvitation mtInvitation1 = mtInvitationMapper.queryByStoreId(Integer.parseInt(storeId), user.getId());
if (ObjectUtil.isEmpty(mtInvitation1)) {
MtInvitation mtInvitation = new MtInvitation();
mtInvitation.setUserId(user.getId());
mtInvitation.setStoreId(Integer.parseInt(storeId));
mtInvitation.setStaffId(Integer.parseInt(staffId));
mtInvitation.setInviterId(Integer.parseInt(inviterId));
mtInvitationMapper.insert(mtInvitation);
}
mtInvitationMapper.insert(mtInvitation);
}
}
return mtUserMobile;
} else {
// 已被禁用
if (user.getStatus().equals(StatusEnum.DISABLE.getKey())) {
return null;
}
// 补充手机号
if (StringUtil.isNotEmpty(mobile)) {
user.setMobile(mobile);
updateById(user);
}
if (ObjectUtil.isNotEmpty(storeId) && storeId !="") {
MtInvitation mtInvitation1 = mtInvitationMapper.queryByStoreId(Integer.parseInt(storeId), user.getId());
if (ObjectUtil.isEmpty(mtInvitation1)) {
MtInvitation mtInvitation = new MtInvitation();
mtInvitation.setUserId(user.getId());
mtInvitation.setStoreId(Integer.parseInt(storeId));
mtInvitation.setStaffId(Integer.parseInt(staffId));
mtInvitation.setInviterId(Integer.parseInt(inviterId));
mtInvitationMapper.insert(mtInvitation);
}
}
// 使用openId查询
return null;
}
return user;
// // openid没有时使用手机号
// if (user == null) {
// MtUser mtUser = new MtUser();
// if (StringUtil.isNotEmpty(mobile)) {
// MtUser mtUserMobile = queryMemberByMobile2(mobile);
// if (mtUserMobile != null) {
// mtUser = mtUserMobile;
// }
// }
// // 昵称为空用手机号
// if (StringUtil.isEmpty(nickName) && StringUtil.isNotEmpty(mobile)) {
// nickName = mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
// }
// String userNo = CommonUtil.createUserNo();
// mobile = CommonUtil.replaceXSS(mobile);
// avatar = CommonUtil.replaceXSS(avatar);
// nickName = CommonUtil.replaceXSS(nickName);
// mtUser.setUserNo(userNo);
// mtUser.setMobile(mobile);
// mtUser.setAvatar(avatar);
// mtUser.setName(nickName);
// mtUser.setOpenId(openId);
//
// Date time = new Date();
// mtUser.setCreateTime(time);
// mtUser.setUpdateTime(time);
// mtUser.setBalance(new BigDecimal(0));
// mtUser.setPoint(0);
// mtUser.setDescription("微信登录自动注册");
// mtUser.setIdcard("");
// mtUser.setStatus("qy");
// // 微信用户 12 0未知
// if (gender.equals(GenderEnum.FEMALE.getKey().toString())) {
// gender = GenderEnum.UNKNOWN.getKey().toString();
// } else if (gender.equals(GenderEnum.UNKNOWN.getKey().toString())) {
// gender = GenderEnum.FEMALE.getKey().toString();
// }
// mtUser.setSex(Integer.parseInt(gender));
//
// mtUser.setSource(source);
// if (mtUser.getId() == null || mtUser.getId() <= 0) {
// save(mtUser);
// } else {
// updateById(mtUser);
// }
//
// user = mtUserMapper.queryMemberByOpenId2(openId);
//
// // 新增余额信息
// if (ObjectUtil.isNotEmpty(storeId) && storeId !="") {
// // 根据userid和stortId查询是否存在对应的余额信息
// UserBalance userBalance = userBalanceService.selectUserBalance(user.getId(), Integer.parseInt(storeId));
// if (ObjectUtil.isEmpty(userBalance)) {
// // 新增余额信息
// UserBalance userBalanceAdd = new UserBalance();
// userBalanceAdd.setMtUserId(user.getId());
// userBalanceAdd.setStoreId(Integer.parseInt(storeId));
// userBalanceAdd.setCardBalance(0.0);
// userBalanceAdd.setPoints(0);
// userBalanceAdd.setGrowthValue(0);
// userBalanceAdd.setConsumeNum(0);
//
// MtUserGrade lowGrade = userGradeService.getLowGrade(Integer.parseInt(storeId));
// if (ObjectUtil.isNotEmpty(lowGrade) && ObjectUtil.isNotEmpty(lowGrade.getId())) {
// userBalanceAdd.setGradeId(lowGrade.getId());
// }
// // 新增会员余额信息
// userBalanceService.insertUserBalance(userBalanceAdd);
// }
// LJStore store = iljStoreService.selectStoreByStoreId(Integer.parseInt(storeId));
// // 查询关联表里面是否有信息
// MtInvitation mtInvitation1 = mtInvitationMapper.queryByStoreId(Integer.parseInt(storeId), user.getId());
// if (ObjectUtil.isEmpty(mtInvitation1)) {
// MtInvitation mtInvitation = new MtInvitation();
// mtInvitation.setUserId(user.getId());
// mtInvitation.setStoreId(Integer.parseInt(storeId));
// mtInvitation.setStaffId(Integer.parseInt(staffId));
// mtInvitation.setInviterId(Integer.parseInt(inviterId));
// if (!ObjectUtil.isEmpty(store)){
// mtInvitation.setChainStoreId(store.getChainStoreId());
// }
// mtInvitationMapper.insert(mtInvitation);
// }
// }
// } else {
// // 已被禁用
// if (user.getStatus().equals(StatusEnum.DISABLE.getKey())) {
// return null;
// }
// // 补充手机号
// if (StringUtil.isNotEmpty(mobile)) {
// user.setMobile(mobile);
// updateById(user);
// }
//
// if (ObjectUtil.isNotEmpty(storeId) && storeId !="") {
// MtInvitation mtInvitation1 = mtInvitationMapper.queryByStoreId(Integer.parseInt(storeId), user.getId());
// if (ObjectUtil.isEmpty(mtInvitation1)) {
// MtInvitation mtInvitation = new MtInvitation();
// mtInvitation.setUserId(user.getId());
// mtInvitation.setStoreId(Integer.parseInt(storeId));
// mtInvitation.setStaffId(Integer.parseInt(staffId));
// mtInvitation.setInviterId(Integer.parseInt(inviterId));
// mtInvitationMapper.insert(mtInvitation);
// }
// }
// }
//
// return user;
}
//生成用户编号
private String editUserNo() {
Random random = new Random();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 7; i++) {
sb.append(random.nextInt(10));
}
String digits = sb.toString();
int sum = 0;
for (int i = 0; i < digits.length(); i++) {
int digit = Integer.parseInt(String.valueOf(digits.charAt(i)));
if (i % 2 == 0) {
sum += digit;
} else {
sum += digit * 3;
}
}
int checksum = (10 - (sum % 10)) % 10;
String number = digits + checksum;
return number;
}

View File

@ -106,66 +106,32 @@ public class ClientSignController extends BaseController {
logger.info("微信授权登录参数:{}", param);
JSONObject userInfo = paramsObj.getJSONObject("userInfo");
String storeId = ObjectUtil.isEmpty(userInfo.get("storeId"))? "" : userInfo.get("storeId").toString();
String staffId = ObjectUtil.isEmpty(userInfo.get("staffId"))? "" : userInfo.get("staffId").toString();
String inviterId = ObjectUtil.isEmpty(userInfo.get("inviterId"))? "" : userInfo.get("inviterId").toString();
// String staffId = ObjectUtil.isEmpty(userInfo.get("staffId"))? "" : userInfo.get("staffId").toString();
// String inviterId = ObjectUtil.isEmpty(userInfo.get("inviterId"))? "" : userInfo.get("inviterId").toString();
JSONObject loginInfo = weixinService.getWxProfile2(param.get("code").toString()); // 发起的登录请求 merchantId用来获取商户的appid 目前用不到
if (loginInfo == null) {
return getFailureResult(0, "微信登录失败");
}
// 获取用户信息
// String type = userInfo.getString("type");
// type.equals("phone") &&
// String encryptedData = userInfo.getString("encryptedData");
// userInfo.put("phone", "");
// userInfo.put("source", MemberSourceEnum.WECHAT_LOGIN.getKey());
// if (StringUtil.isNotEmpty(encryptedData)) {
// String phone = weixinService.getPhoneNumber(userInfo.get("encryptedData").toString(), loginInfo.get("session_key").toString(), userInfo.get("iv").toString());
// userInfo.put("phone", phone);
// }
// 默认店铺主页 ()
// if (storeId == null || StringUtil.isEmpty(storeId)) {
// MtStore mtStore = storeService.getDefaultStore(merchantNo);
// if (mtStore != null) {
// storeId = mtStore.getId().toString();
// }
// }
MtUser mtUser = memberService.queryMemberByOpenId2(loginInfo.get("openid").toString(), userInfo);
if (mtUser == null) {
return getFailureResult(0, "用户状态异常");
}
String userAgent = request.getHeader("user-agent");
// String token = TokenUtil.generateToken(userAgent, mtUser.getId());
// UserInfo userLoginInfo = new UserInfo();
// userLoginInfo.setId(mtUser.getId());
// userLoginInfo.setStoreId(storeId);
//
// userLoginInfo.setToken(token);
// TokenUtil.saveToken(userLoginInfo);
//
// Map<String, Object> result = new HashMap<>();
// result.put("token", token);
// result.put("userId", mtUser.getId());
// result.put("userName", mtUser.getName());
// result.put("openId", mtUser.getOpenId());
AccountInfo accountInfo = new AccountInfo();
accountInfo.setId(mtUser.getId());
accountInfo.setDeptId(-1L);
if (ObjectUtil.isNotEmpty(storeId) && storeId!= "") {
accountInfo.setStoreId(Integer.parseInt(storeId));
}
String token1 = TokenUtil.generateToken(userAgent, mtUser.getId());
accountInfo.setToken(token1);
String token = TokenUtil.generateToken(userAgent, mtUser.getId());
accountInfo.setToken(token);
TokenUtil.saveAccountToken(accountInfo);
LoginResponse response = new LoginResponse();
response.setLogin(true);
response.setToken(token1);
response.setToken(token);
response.setTokenCreatedTime(new Date());
// return getSuccessResult(response);
return getSuccessResult("登录成功", response);
}

View File

@ -81,6 +81,4 @@
position: fixed;
top: 0px;
}
</style>

View File

@ -75,6 +75,7 @@
userInfo: {
storeId: 0,
staffId: "",
phone:'17753808121'
},
type: 'phone',

View File

@ -0,0 +1,8 @@
const getters = {
token: state => state.user.token,
avatar: state => state.user.avatar,
name: state => state.user.name,
roles: state => state.user.roles,
permissions: state => state.user.permissions
}
export default getters

View File

@ -0,0 +1,15 @@
import Vue from 'vue'
import Vuex from 'vuex'
import user from '@/store/modules/user'
import getters from './getters'
Vue.use(Vuex)
const store = new Vuex.Store({
modules: {
user
},
getters
})
export default store

View File

@ -0,0 +1,98 @@
import config from '@/config'
import storage from '@/utils/storage'
import constant from '@/utils/constant'
import { login, logout, getInfo } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'
const baseUrl = config.baseUrl
const user = {
state: {
token: getToken(),
name: storage.get(constant.name),
avatar: storage.get(constant.avatar),
roles: storage.get(constant.roles),
permissions: storage.get(constant.permissions)
},
mutations: {
SET_TOKEN: (state, token) => {
state.token = token
},
SET_NAME: (state, name) => {
state.name = name
storage.set(constant.name, name)
},
SET_AVATAR: (state, avatar) => {
state.avatar = avatar
storage.set(constant.avatar, avatar)
},
SET_ROLES: (state, roles) => {
state.roles = roles
storage.set(constant.roles, roles)
},
SET_PERMISSIONS: (state, permissions) => {
state.permissions = permissions
storage.set(constant.permissions, permissions)
}
},
actions: {
// 登录
Login({ commit }, userInfo) {
const username = userInfo.username.trim()
const password = userInfo.password
const code = userInfo.code
const uuid = userInfo.uuid
return new Promise((resolve, reject) => {
login(username, password, code, uuid).then(res => {
setToken(res.token)
commit('SET_TOKEN', res.token)
resolve()
}).catch(error => {
reject(error)
})
})
},
// 获取用户信息
GetInfo({ commit, state }) {
return new Promise((resolve, reject) => {
getInfo().then(res => {
const user = res.user
const avatar = baseUrl + user.avatar
const username = (user == null || user.userName == "" || user.userName == null) ? "" : user.userName
if (res.roles && res.roles.length > 0) {
commit('SET_ROLES', res.roles)
commit('SET_PERMISSIONS', res.permissions)
} else {
commit('SET_ROLES', ['ROLE_DEFAULT'])
}
commit('SET_NAME', username)
commit('SET_AVATAR', avatar)
resolve(res)
}).catch(error => {
reject(error)
})
})
},
// 退出系统
LogOut({ commit, state }) {
return new Promise((resolve, reject) => {
logout(state.token).then(() => {
commit('SET_TOKEN', '')
commit('SET_ROLES', [])
commit('SET_PERMISSIONS', [])
removeToken()
storage.clean()
resolve()
}).catch(error => {
reject(error)
})
})
}
}
}
export default user