登录修改

This commit is contained in:
wangh 2023-11-29 11:50:58 +08:00
parent cec9d85b3a
commit b25c52f6de
15 changed files with 293 additions and 42 deletions

View File

@ -35,31 +35,6 @@ public class MtInvitation extends BaseEntity {
* 状态启用禁用 * 状态启用禁用
*/ */
private String status; private String status;
/**
* 创建时间
*/
private Date createTime;
/**
* 创建人
*/
private String createBy;
/**
* 更新时间
*/
private Date updateTime;
/**
* 更新人
*/
private String updateBy;

View File

@ -55,5 +55,24 @@ public class UserBalance extends BaseEntity implements Serializable {
*/ */
private String refuelMoney; private String refuelMoney;
/**
* 等级ID
*/
private Integer gradeId;
/**
* 加油次数
*/
private Integer consumeNum;
/**
* 副卡信息
*/
private String secondCard;
/**
* 固定等级
*/
private String fixingLevel;
} }

View File

@ -23,6 +23,9 @@ public interface MtInvitationMapper {
*/ */
MtInvitation queryById(Integer id); MtInvitation queryById(Integer id);
MtInvitation queryByStoreId(Integer storeId,Integer userId);
/** /**
* 查询指定行数据 * 查询指定行数据
* *

View File

@ -23,6 +23,15 @@
where id = #{id} where id = #{id}
</select> </select>
<!--查询单个-->
<select id="queryByStoreId" resultMap="MtInvitationMap">
select
id, userId, storeId, staffId, inviterId, status, create_time, create_by, update_time, update_by
from mt_invitation
where storeId = #{storeId} and user_id = #{userId}
</select>
<!--查询指定行数据--> <!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="MtInvitationMap"> <select id="queryAllByLimit" resultMap="MtInvitationMap">
select select

View File

@ -34,4 +34,12 @@ public interface UserBalanceService extends IService<UserBalance> {
* @return * @return
*/ */
public UserBalance selectUserBalance(int userId); public UserBalance selectUserBalance(int userId);
/**
* 根据用户id和店铺id查询用户余额信息
* @param userId
* @return
*/
public UserBalance selectUserBalance(int userId, int storeId);
} }

View File

@ -38,4 +38,13 @@ public class UserBalanceServiceImpl extends ServiceImpl<UserBalanceMapper, UserB
UserBalance balance = baseMapper.selectOne(queryWrapper); UserBalance balance = baseMapper.selectOne(queryWrapper);
return balance; return balance;
} }
@Override
public UserBalance selectUserBalance(int userId, int storeId) {
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("mt_user_id",userId);
queryWrapper.eq("store_id",storeId);
UserBalance balance = baseMapper.selectOne(queryWrapper);
return balance;
}
} }

View File

@ -95,6 +95,7 @@ public interface MemberService extends IService<MtUser> {
* @throws BusinessCheckException * @throws BusinessCheckException
*/ */
MtUser queryMemberByOpenId(Integer merchantId, String openId, JSONObject userInfo) throws BusinessCheckException; MtUser queryMemberByOpenId(Integer merchantId, String openId, JSONObject userInfo) throws BusinessCheckException;
MtUser queryMemberByOpenId2(String openId, JSONObject userInfo) throws BusinessCheckException;
/** /**
* 根据会员组ID获取会员组信息 * 根据会员组ID获取会员组信息
@ -113,6 +114,9 @@ public interface MemberService extends IService<MtUser> {
*/ */
MtUser queryMemberByMobile(Integer merchantId, String mobile) throws BusinessCheckException; MtUser queryMemberByMobile(Integer merchantId, String mobile) throws BusinessCheckException;
MtUser queryMemberByMobile2(String mobile) throws BusinessCheckException;
/** /**
* 根据会员号获取会员信息 * 根据会员号获取会员信息
* *

View File

@ -1,6 +1,7 @@
package com.fuint.common.service; package com.fuint.common.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.fuint.business.userManager.entity.UserBalance;
import com.fuint.framework.exception.BusinessCheckException; import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationRequest; import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse; import com.fuint.framework.pagination.PaginationResponse;
@ -75,4 +76,12 @@ public interface UserGradeService extends IService<MtUserGrade> {
* @throws BusinessCheckException * @throws BusinessCheckException
* */ * */
List<MtUserGrade> getPayUserGradeList(Integer merchantId, MtUser userInfo) throws BusinessCheckException; List<MtUserGrade> getPayUserGradeList(Integer merchantId, MtUser userInfo) throws BusinessCheckException;
/**
* 获取最低等级
* @param storeId
* @return
*/
public MtUserGrade getLowGrade(int storeId);
} }

View File

@ -29,6 +29,8 @@ public interface WeixinService {
JSONObject getWxProfile(Integer merchantId, String code) throws BusinessCheckException; JSONObject getWxProfile(Integer merchantId, String code) throws BusinessCheckException;
JSONObject getWxProfile2(String code) throws BusinessCheckException;
JSONObject getWxOpenId(Integer merchantId, String code) throws BusinessCheckException; JSONObject getWxOpenId(Integer merchantId, String code) throws BusinessCheckException;
String getPhoneNumber(String encryptedData, String session_key, String iv); String getPhoneNumber(String encryptedData, String session_key, String iv);

View File

@ -1,11 +1,18 @@
package com.fuint.common.service.impl; package com.fuint.common.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.business.store.entity.MtStore; import com.fuint.business.store.entity.MtStore;
import com.fuint.business.store.service.StoreService; import com.fuint.business.store.service.StoreService;
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.MtInvitationService;
import com.fuint.business.userManager.service.UserBalanceService;
import com.fuint.common.dto.AccountInfo; import com.fuint.common.dto.AccountInfo;
import com.fuint.common.dto.MemberTopDto; import com.fuint.common.dto.MemberTopDto;
import com.fuint.common.dto.UserDto; import com.fuint.common.dto.UserDto;
@ -104,6 +111,8 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
@Resource @Resource
private UserActionService userActionService; private UserActionService userActionService;
@Resource
private MtInvitationMapper mtInvitationMapper;
/** /**
* 更新活跃时间 * 更新活跃时间
* @param userId 会员ID * @param userId 会员ID
@ -483,7 +492,7 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
} }
/** /**
* 根据手机号获取会员信息 * 根据手机号和商户好获取会员信息
* *
* @param merchantId * @param merchantId
* @param mobile 手机号 * @param mobile 手机号
@ -502,6 +511,22 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
} }
} }
/**
* 根据手机号获取会员信息
*
* @param mobile 手机号
* @throws BusinessCheckException
*/
@Override
public MtUser queryMemberByMobile2(String mobile) {
List<MtUser> mtUser = mtUserMapper.queryMemberByMobile2(mobile);
if (mtUser.size() > 0) {
return mtUser.get(0);
} else {
return null;
}
}
/** /**
* 根据会员号号获取会员信息 * 根据会员号号获取会员信息
* *
@ -626,7 +651,6 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
if (StringUtil.isEmpty(nickName) && StringUtil.isNotEmpty(mobile)) { if (StringUtil.isEmpty(nickName) && StringUtil.isNotEmpty(mobile)) {
nickName = mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2"); nickName = mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})","$1****$2");
} }
// mtUser.setMerchantId(merchantId);
String userNo = CommonUtil.createUserNo(); String userNo = CommonUtil.createUserNo();
mobile = CommonUtil.replaceXSS(mobile); mobile = CommonUtil.replaceXSS(mobile);
avatar = CommonUtil.replaceXSS(avatar); avatar = CommonUtil.replaceXSS(avatar);
@ -636,10 +660,12 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
mtUser.setAvatar(avatar); mtUser.setAvatar(avatar);
mtUser.setName(nickName); mtUser.setName(nickName);
mtUser.setOpenId(openId); mtUser.setOpenId(openId);
// MtUserGrade grade = userGradeService.getInitUserGrade(merchantId); MtUserGrade grade = userGradeService.getInitUserGrade(merchantId);
// if (grade != null) { // if (grade != null) {
// mtUser.setGradeId(grade.getId() + ""); // mtUser.setGradeId(grade.getId() + "");
// } // }
// 设置会员等级
Date time = new Date(); Date time = new Date();
mtUser.setCreateTime(time); mtUser.setCreateTime(time);
mtUser.setUpdateTime(time); mtUser.setUpdateTime(time);
@ -693,6 +719,151 @@ public class MemberServiceImpl extends ServiceImpl<MtUserMapper, MtUser> impleme
return user; return user;
} }
@Resource
private UserBalanceService userBalanceService;
@Override
public MtUser queryMemberByOpenId2(String openId, JSONObject userInfo) throws BusinessCheckException {
// merchantId 可以不需要
MtUser user = mtUserMapper.queryMemberByOpenId2(openId);
String avatar = StringUtil.isNotEmpty(userInfo.getString("avatarUrl")) ? userInfo.getString("avatarUrl") : "";
String gender = StringUtil.isNotEmpty(userInfo.getString("gender")) ? userInfo.getString("gender") : GenderEnum.MAN.getKey().toString();
String country = StringUtil.isNotEmpty(userInfo.getString("country")) ? userInfo.getString("country") : "";
String province = StringUtil.isNotEmpty(userInfo.getString("province")) ? userInfo.getString("province") : "";
String city = StringUtil.isNotEmpty(userInfo.getString("city")) ? userInfo.getString("city") : "";
String storeId = StringUtil.isNotEmpty(userInfo.getString("storeId")) ? userInfo.getString("storeId") : "";
String nickName = StringUtil.isNotEmpty(userInfo.getString("nickName")) ? userInfo.getString("nickName") : "";
String staffId = StringUtil.isNotEmpty(userInfo.getString("staffId")) ? userInfo.getString("staffId") : "";
String inviterId = StringUtil.isNotEmpty(userInfo.getString("inviterId")) ? userInfo.getString("inviterId") : "";
String mobile = StringUtil.isNotEmpty(userInfo.getString("phone")) ? userInfo.getString("phone") : "";
String source = StringUtil.isNotEmpty(userInfo.getString("source")) ? userInfo.getString("source") : MemberSourceEnum.WECHAT_LOGIN.getKey();
// todo
// 创建 根据 Storeid判断
// 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);
// 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(StatusEnum.ENABLED.getKey());
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);
MtUserGrade lowGrade = userGradeService.getLowGrade(Integer.parseInt(storeId));
if (ObjectUtil.isNotEmpty(lowGrade) && ObjectUtil.isNotEmpty(lowGrade.getId())) {
userBalanceAdd.setGradeId(lowGrade.getId());
}
// 新增会员余额信息
userBalanceService.insertUserBalance(userBalanceAdd);
}
// 查询关联表里面是否有信息
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));
}
// 新增关联表信息
// 查询是否有
}
} else {
// 已被禁用
if (user.getStatus().equals(StatusEnum.DISABLE.getKey())) {
return null;
}
// 补充手机号
if (StringUtil.isNotEmpty(mobile)) {
user.setMobile(mobile);
updateById(user);
}
// 补充会员号
// if (StringUtil.isEmpty(user.getUserNo())) {
// user.setUserNo(CommonUtil.createUserNo());
// updateById(user);
// }
}
return user;
}
/** /**
* 根据等级ID获取会员等级信息 * 根据等级ID获取会员等级信息
* *

View File

@ -226,4 +226,10 @@ public class UserGradeServiceImpl extends ServiceImpl<MtUserGradeMapper, MtUserG
return dataList; return dataList;
} }
@Override
public MtUserGrade getLowGrade(int storeId) {
MtUserGrade one = this.getOne(new LambdaQueryWrapper<MtUserGrade>().orderByAsc(MtUserGrade::getGrade).last("limit 1"));
return one;
}
} }

View File

@ -306,6 +306,31 @@ public class WeixinServiceImpl implements WeixinService {
return null; return null;
} }
@Override
public JSONObject getWxProfile2(String code) throws BusinessCheckException {
String wxAppId = env.getProperty("wxpay.appId");
String wxAppSecret = env.getProperty("wxpay.appSecret");
String wxAccessUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";
String url = String.format(wxAccessUrl, wxAppId, wxAppSecret, code);
try {
String response = HttpRESTDataClient.requestGet(url);
JSONObject json = (JSONObject) JSONObject.parse(response);
if (!json.containsKey("errcode")) {
logger.error("拿到code信息code = " + json);
return json;
} else {
logger.error("获取微信getWxProfile出错code = " + json.containsKey("errcode") + ",msg="+ json.get("errmsg"));
}
} catch (Exception e) {
logger.error("获取微信getWxProfile异常" + e.getMessage());
}
return null;
}
/** /**
* 获取公众号openId * 获取公众号openId
* *

View File

@ -96,11 +96,10 @@ public class ClientSignController extends BaseController {
JSONObject paramsObj = new JSONObject(param); JSONObject paramsObj = new JSONObject(param);
logger.info("微信授权登录参数:{}", param); logger.info("微信授权登录参数:{}", param);
JSONObject userInfo = paramsObj.getJSONObject("userInfo"); JSONObject userInfo = paramsObj.getJSONObject("userInfo");
String storeId = ObjectUtil.isEmpty(userInfo.get("storeId"))? "0" : userInfo.get("storeId").toString(); String storeId = ObjectUtil.isEmpty(userInfo.get("storeId"))? "" : userInfo.get("storeId").toString();
String merchantNo = ObjectUtil.isEmpty(userInfo.get("merchantNo"))? "" : userInfo.get("merchantNo").toString(); String staffId = ObjectUtil.isEmpty(userInfo.get("staffId"))? "" : userInfo.get("staffId").toString();
// Integer merchantId = merchantService.getMerchantId(merchantNo); //获取商户号 String inviterId = ObjectUtil.isEmpty(userInfo.get("inviterId"))? "" : userInfo.get("inviterId").toString();
Integer merchantId = null; JSONObject loginInfo = weixinService.getWxProfile2(param.get("code").toString()); // 发起的登录请求 merchantId用来获取商户的appid 目前用不到
JSONObject loginInfo = weixinService.getWxProfile(merchantId, param.get("code").toString()); // 发起的登录请求 merchantId用来获取商户的appid 目前用不到
if (loginInfo == null) { if (loginInfo == null) {
return getFailureResult(0, "微信登录失败"); return getFailureResult(0, "微信登录失败");
} }
@ -116,15 +115,14 @@ public class ClientSignController extends BaseController {
// userInfo.put("phone", phone); // userInfo.put("phone", phone);
// } // }
// 默认店铺主页 () // 默认店铺主页 ()
if (storeId == null || StringUtil.isEmpty(storeId)) { // if (storeId == null || StringUtil.isEmpty(storeId)) {
MtStore mtStore = storeService.getDefaultStore(merchantNo); // MtStore mtStore = storeService.getDefaultStore(merchantNo);
if (mtStore != null) { // if (mtStore != null) {
storeId = mtStore.getId().toString(); // storeId = mtStore.getId().toString();
} // }
} // }
// if ()
// userInfo.put("storeId", storeId); MtUser mtUser = memberService.queryMemberByOpenId2(loginInfo.get("openid").toString(), userInfo);
MtUser mtUser = memberService.queryMemberByOpenId(merchantId, loginInfo.get("openid").toString(), userInfo);
if (mtUser == null) { if (mtUser == null) {
return getFailureResult(0, "用户状态异常"); return getFailureResult(0, "用户状态异常");
} }

View File

@ -17,10 +17,14 @@ public interface MtUserMapper extends BaseMapper<MtUser> {
List<MtUser> queryMemberByMobile(@Param("merchantId") Integer merchantId, @Param("mobile") String mobile); List<MtUser> queryMemberByMobile(@Param("merchantId") Integer merchantId, @Param("mobile") String mobile);
List<MtUser> queryMemberByMobile2(@Param("mobile") String mobile);
List<MtUser> queryMemberByName(@Param("merchantId") Integer merchantId, @Param("name") String name); List<MtUser> queryMemberByName(@Param("merchantId") Integer merchantId, @Param("name") String name);
MtUser queryMemberByOpenId(@Param("merchantId") Integer merchantId, @Param("openId") String openId); MtUser queryMemberByOpenId(@Param("merchantId") Integer merchantId, @Param("openId") String openId);
MtUser queryMemberByOpenId2(@Param("openId") String openId);
List<MtUser> findMembersByUserNo(@Param("merchantId") Integer merchantId, @Param("userNo") String userNo); List<MtUser> findMembersByUserNo(@Param("merchantId") Integer merchantId, @Param("userNo") String userNo);
void updateActiveTime(@Param("userId") Integer userId, @Param("updateTime") Date updateTime); void updateActiveTime(@Param("userId") Integer userId, @Param("updateTime") Date updateTime);

View File

@ -8,6 +8,10 @@
</if> </if>
</select> </select>
<select id="queryMemberByMobile2" resultType="com.fuint.repository.model.MtUser">
select * from mt_user t where t.MOBILE = #{mobile} limit 1
</select>
<select id="queryMemberByName" resultType="com.fuint.repository.model.MtUser"> <select id="queryMemberByName" resultType="com.fuint.repository.model.MtUser">
select * from mt_user t where t.NAME = #{name} and t.STATUS = 'A' select * from mt_user t where t.NAME = #{name} and t.STATUS = 'A'
<if test="merchantId != null and merchantId > 0"> <if test="merchantId != null and merchantId > 0">
@ -23,6 +27,11 @@
limit 1 limit 1
</select> </select>
<select id="queryMemberByOpenId2" resultType="com.fuint.repository.model.MtUser">
select * from mt_user t where t.OPEN_ID = #{openId} and t.STATUS = 'A'
limit 1
</select>
<select id="findMembersByUserNo" resultType="com.fuint.repository.model.MtUser"> <select id="findMembersByUserNo" resultType="com.fuint.repository.model.MtUser">
select * from mt_user t where t.USER_NO = #{userNo} and t.STATUS = 'A' select * from mt_user t where t.USER_NO = #{userNo} and t.STATUS = 'A'
<if test="merchantId != null and merchantId > 0"> <if test="merchantId != null and merchantId > 0">