区分用户平台

This commit is contained in:
邱贞招 2024-10-22 21:55:14 +08:00
parent 149c5ca4c4
commit 68c33f753b
14 changed files with 67 additions and 30 deletions

View File

@ -3,13 +3,17 @@ package com.ruoyi.web.controller.app;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.ServiceConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.AsArticleClassify;
import com.ruoyi.common.core.domain.entity.RlUser;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.system.domain.EtArticle;
import com.ruoyi.system.domain.RlFunction;
import com.ruoyi.system.domain.agent.RlAgent;
@ -72,6 +76,23 @@ public class AppController extends BaseController
@Resource
private IRlUserService userService;
@Autowired
private SysLoginService loginService;
/**
* 验证码登录
*/
@PostMapping("/appCodeLogin")
public AjaxResult appCodeLogin(@RequestBody LoginBody loginBody) {
AjaxResult ajax = AjaxResult.success();
/**通过手机号找到用户名*/
String phone = loginBody.getPhone();
// 生成令牌
String token = loginService.appCodeLogin(phone, loginBody.getPhoneCode(),loginBody.getPassword(), loginBody.getUuid(), ServiceConstants.APPLET_TYPE_USER);
ajax.put(Constants.TOKEN, token);
return ajax;
}
/**
* 查询城市列表
*/

View File

@ -286,7 +286,7 @@ public class AppAgentController extends BaseController
{
logger.info("上传收款码【collectionCode="+collectionCode+",用户提现渠道id[userWithdrawChannelId]="+userWithdrawChannelId+"");
RlUserWithdraw userWithdraw = new RlUserWithdraw();
userWithdraw.setChannelId(userWithdrawChannelId);
userWithdraw.setUserChannelId(userWithdrawChannelId);
userWithdraw.setCollectionCode(collectionCode);
int i = userWithdrawService.updateRlUserWithdraw(userWithdraw);
return toAjax(i);

View File

@ -117,7 +117,7 @@ public class AppAdminController extends BaseController
/**通过手机号找到用户名*/
String phone = loginBody.getPhone();
// 生成令牌
String token = loginService.appCodeLogin(phone, loginBody.getPhoneCode(),loginBody.getPassword(), loginBody.getUuid());
String token = loginService.appCodeLogin(phone, loginBody.getPhoneCode(),loginBody.getPassword(), loginBody.getUuid(),ServiceConstants.APPLET_TYPE_MERCHANT);
ajax.put(Constants.TOKEN, token);
return ajax;
}

View File

@ -118,7 +118,7 @@ public class SysLoginController
/**通过手机号找到用户名*/
String phone = loginBody.getPhone();
// 生成令牌
String token = loginService.appCodeLogin(phone, loginBody.getPhoneCode(),loginBody.getPassword(), loginBody.getUuid());
String token = loginService.appCodeLogin(phone, loginBody.getPhoneCode(),loginBody.getPassword(), loginBody.getUuid(),ServiceConstants.APPLET_TYPE_MERCHANT);
ajax.put(Constants.TOKEN, token);
return ajax;
}

View File

@ -1,6 +1,7 @@
package com.ruoyi.web.controller.system;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.ServiceConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.RlUser;
@ -127,7 +128,7 @@ public class SysRoleController extends BaseController
if (StringUtils.isNotNull(loginUser.getUser()) && !loginUser.getUser().isAdmin())
{
loginUser.setPermissions(permissionService.getMenuPermission(loginUser.getUser()));
loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName()));
loginUser.setUser(userService.selectUserByUserName(loginUser.getUser().getUserName(), ServiceConstants.APPLET_TYPE_MERCHANT));
tokenService.setLoginUser(loginUser);
}
return success();

View File

@ -105,6 +105,9 @@ public class RlUser extends BaseEntity
/** 是否认证0-未认证1-已认证 */
public Boolean isAuthentication;
/** 小程序类型:1-用户端;2-商家端 */
private String appletType;
public boolean isAdmin()
{
return isAdmin(this.userId);

View File

@ -115,7 +115,7 @@ public class SysLoginService
Authentication authentication = null;
try
{
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username+"@2", password);
AuthenticationContextHolder.setContext(authenticationToken);
authenticationToken.setDetails(Constants.USER_TYPE_PC);
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
@ -157,7 +157,7 @@ public class SysLoginService
Authentication authentication = null;
try
{
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username+"@"+user.getAppletType(), password);
AuthenticationContextHolder.setContext(authenticationToken);
authenticationToken.setDetails(Constants.USER_TYPE_PC);
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
@ -312,10 +312,11 @@ public class SysLoginService
asUser.setCreateTime(DateUtils.getNowDate());
asUser.setWxopenid(openId);
asUser.setUserType(ServiceConstants.USER_TYPE_SYSTEM);
asUser.setAppletType(appletType);
log.info("【微信登录/wxlogin】用户不存在自动注册用户【{}】", JSON.toJSON(asUser));
int i = userService.insertUser(asUser);
if(i>0 && ServiceConstants.APPLET_TYPE_USER.equals(appletType)){
if(i>0 && ServiceConstants.APPLET_TYPE_MERCHANT.equals(appletType)){
/** 创建用户扩展表内容,默认的用户角色是00未分配*/
int i1= insertUserExt(asUser);
}
@ -443,8 +444,8 @@ public class SysLoginService
return openId;
}
public String appCodeLogin(String username, String code, String password, String uuid) {
RlUser user = userService.selectUserByUserName(username);
public String appCodeLogin(String username, String code, String password, String uuid,String appletType) {
RlUser user = userService.selectUserByUserName(username,appletType);
if(ObjectUtils.isEmpty(user)){
RlUser asUser = new RlUser();
asUser.setUserName(username);
@ -452,6 +453,7 @@ public class SysLoginService
asUser.setLoginIp(IpUtils.getIpAddr());
asUser.setLoginDate(DateUtils.getNowDate());
asUser.setCreateTime(DateUtils.getNowDate());
asUser.setAppletType(appletType);
log.info("【微信登录/wxlogin】用户不存在自动注册用户【{}】", JSON.toJSON(asUser));
int i = userService.insertUser(asUser);
user = asUser;
@ -474,13 +476,13 @@ public class SysLoginService
try {
UsernamePasswordAuthenticationToken authenticationToken;
if(StrUtil.isBlank(code)){
authenticationToken = new UsernamePasswordAuthenticationToken(user.getUserName(), password);
authenticationToken = new UsernamePasswordAuthenticationToken(user.getUserName()+"@"+appletType, password);
// 用户名和密码等信息保存在一个上下文中只要是同一线程等会就能拿到用户名和密码也就是能在loadUserByUsername(String username)方法中进行密码验证等
AuthenticationContextHolder.setContext(authenticationToken);
// 把用户类型放在上下文中的details属性中在UserDetailsServiceImpl.loadUserByUsername中获取
authenticationToken.setDetails(Constants.USER_TYPE_PASSWORD);
}else{
authenticationToken = new UsernamePasswordAuthenticationToken(user.getUserName(), Constants.CUSTOM_LOGIN_SMS);
authenticationToken = new UsernamePasswordAuthenticationToken(user.getUserName()+"@"+appletType, Constants.CUSTOM_LOGIN_SMS);
// 用户名和密码等信息保存在一个上下文中只要是同一线程等会就能拿到用户名和密码也就是能在loadUserByUsername(String username)方法中进行密码验证等
AuthenticationContextHolder.setContext(authenticationToken);
// 把用户类型放在上下文中的details属性中在UserDetailsServiceImpl.loadUserByUsername中获取

View File

@ -54,15 +54,21 @@ public class UserDetailsServiceImpl implements UserDetailsService
if (authentication != null && authentication.getDetails() != null) {
String userType = (String) authentication.getDetails();
RlUser user;
String appletType = "";
if(username.contains("@")){
String[] split = username.split("@");
username = split[0];
appletType = split[1];
}
if(Constants.USER_TYPE_PC.equals(userType)){
// PC用户登录
user = userService.selectUserByUserName(username);
user = userService.selectUserByUserName(username, appletType);
}else if(Constants.USER_TYPE_APP.equals(userType)){
// app用户登录 如果是app用户则用openid查询
user = asUserService.selectUserByWxopenid(username);
}else{
// app用户登录短信登录 如果是app用户则用手机号
user = userService.selectUserByUserName(username);
user = userService.selectUserByUserName(username, appletType);
verifyUser(username, user);
if(Constants.USER_TYPE_PASSWORD.equals(userType)){
if(StrUtil.isBlank(user.getPassword())){

View File

@ -52,9 +52,4 @@ public class RlUserExt extends BaseEntity
/** 代理商id */
private Long agentId;
// /** 提现手续费类型1-按比例2-按每笔 */
// private String handlingChargeType;
// /** 服务费 */
// private BigDecimal withdrawHandlingCharge;
}

View File

@ -44,9 +44,10 @@ public interface RlUserMapper
* 通过用户名查询用户
*
* @param userName 用户名
* @param appletType 小程序类型
* @return 用户对象信息
*/
public RlUser selectUserByUserName(String userName);
public RlUser selectUserByUserName(@Param("userName") String userName,@Param("appletType")String appletType);
/**
* 通过用户ID查询用户

View File

@ -49,7 +49,7 @@ public interface IRlUserService
* @param userName 用户名
* @return 用户对象信息
*/
public RlUser selectUserByUserName(String userName);
public RlUser selectUserByUserName(String userName,String appletType);
/**
* 通过用户ID查询用户

View File

@ -141,7 +141,11 @@ public class RlChangeBalanceServiceImpl implements IRlChangeBalanceService
rlChangeBalance.setBusType(busType);
BigDecimal balance = userService.selectUserBalanceById(userId);
rlChangeBalance.setBeforeBalance(balance);
rlChangeBalance.setAfterBalance(balance.add(payFee));
if(type.equals("1")){
rlChangeBalance.setAfterBalance(balance.add(payFee));
}else{
rlChangeBalance.setAfterBalance(balance.subtract(payFee));
}
rlChangeBalance.setAmount(payFee);
rlChangeBalance.setOwnerId(userId);
rlChangeBalance.setOwnerName(userName);

View File

@ -174,12 +174,13 @@ public class RlUserServiceImpl implements IRlUserService{
* 通过用户名查询用户
*
* @param userName 用户名
* @param appletType 小程序类型
* @return 用户对象信息
*/
@Override
public RlUser selectUserByUserName(String userName)
public RlUser selectUserByUserName(String userName,String appletType)
{
return rlUserMapper.selectUserByUserName(userName);
return rlUserMapper.selectUserByUserName(userName,appletType);
}
/**
@ -782,7 +783,7 @@ public class RlUserServiceImpl implements IRlUserService{
rlWithdraw.setOwnerId(user.getUserId());
rlWithdraw.setOwnerName(user.getUserName());
rlWithdraw.setOwnerPhone(user.getPhonenumber());
ChannelWithdrawVO channelWithdrawVO = etChannelWithdrawService.selectChannelWithdrawByChannelId(withdraw.getWithdrawChannelId());
ChannelWithdrawVO channelWithdrawVO = etChannelWithdrawService.selectChannelWithdrawByChannelId(withdraw.getUserWithdrawChannelId());
if(ObjectUtil.isNull(channelWithdrawVO)){
throw new ServiceException("提现渠道不存在");
}
@ -798,7 +799,7 @@ public class RlUserServiceImpl implements IRlUserService{
RlUserWithdraw rlUserWithdraw = userWithdrawService.selectRlUserWithdrawByUserChannelId(withdraw.getUserWithdrawChannelId());
if(rlUserWithdraw.getHandlingChargeType().equals(ServiceConstants.HANDLING_CHARGE_TYPE_PERCENT)){
BigDecimal handlingCharge1 = rlUserWithdraw.getWithdrawHandlingCharge();// 5.4
BigDecimal bigDecimal = handlingCharge1.divide(new BigDecimal(100), 6, BigDecimal.ROUND_HALF_UP);// 0.0054
BigDecimal bigDecimal = handlingCharge1.divide(new BigDecimal(1000), 6, BigDecimal.ROUND_HALF_UP);// 0.0054
handlingCharge = bigDecimal.multiply(withdraw.getAmount()).setScale(2, RoundingMode.HALF_UP);// 0.0054 * 1000 = 0.54
}else{
handlingCharge = rlUserWithdraw.getWithdrawHandlingCharge();

View File

@ -20,7 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectUserVo">
select u.user_id, u.user_name, u.real_name, u.id_card, u.nick_name, u.email, u.avatar,u.user_type,
u.phonenumber, u.password, u.sex, u.status,
u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.wxopenid,u.is_authentication,
u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.wxopenid,u.is_authentication,u.applet_type,
ex.balance,ex.dividend_proportion dividendProportion,ex.cooperation_time cooperationTime,ex.dividend_status dividendStatus
from rl_user u
left join rl_user_ext ex on u.user_id = ex.user_id
@ -28,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectUserList" parameterType="RlUser" resultMap="EUserResult">
select u.user_id, u.nick_name, u.user_name, u.real_name,u.email, u.avatar, u.phonenumber,u.user_type,
u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.is_authentication,a.city_id,c.name cityName,
u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.is_authentication,u.applet_type, a.city_id,c.name cityName,
ex.balance,ex.dividend_proportion dividendProportion,ex.cooperation_time cooperationTime,ex.dividend_status dividendStatus,ex.agent_id, s.name storeName,s.store_id,
u.wxopenid from rl_user u
left join rl_user_ext ex on u.user_id = ex.user_id
@ -101,14 +101,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectUserByUserName" parameterType="String" resultMap="EUserResult">
<include refid="selectUserVo"/>
where u.user_name = #{userName} and u.del_flag = '0'
where u.user_name = #{userName} and u.del_flag = '0' and u.applet_type = #{appletType}
</select>
<select id="selectUserById" parameterType="Long" resultMap="EUserResult">
select u.user_id, u.user_name, u.real_name, u.id_card, u.nick_name, u.email, u.avatar,a.city_id,c.name cityName,
ex.balance,ex.dividend_proportion dividendProportion,ex.cooperation_time cooperationTime,ex.dividend_status dividendStatus,ex.agent_id,
u.phonenumber, u.password, u.sex, u.status,u.user_type,r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status,
u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.wxopenid,u.is_authentication
u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.wxopenid,u.is_authentication, u.applet_type
from rl_user u
left join sys_user_role ur on u.user_id = ur.user_id
left join sys_role r on r.role_id = ur.role_id
@ -121,7 +121,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="myAccountInfoByUserId" parameterType="Long" resultMap="EUserResult">
select u.user_id, u.user_name, u.real_name, u.id_card, u.nick_name, u.email, u.avatar,
u.phonenumber, u.password, u.sex, u.status,u.user_type,
u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.wxopenid,u.is_authentication,
u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,u.wxopenid,u.is_authentication,u.applet_type,
ex.balance,ex.dividend_proportion dividendProportion,ex.cooperation_time cooperationTime,ex.dividend_status dividendStatus
from rl_user u
left join rl_user_ext ex on u.user_id = ex.user_id
@ -230,6 +230,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createBy != null and createBy != ''">create_by,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="wxopenid != null and wxopenid != ''">wxopenid,</if>
<if test="appletType != null and appletType != ''">applet_type,</if>
create_time
)values(
<if test="userId != null and userId != ''">#{userId},</if>
@ -247,6 +248,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="wxopenid != null and wxopenid != ''">#{wxopenid},</if>
<if test="appletType != null and appletType != ''">#{appletType},</if>
sysdate()
)
</insert>
@ -271,6 +273,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="wxopenid != null">wxopenid = #{wxopenid},</if>
<if test="appletType != null">applet_type = #{appletType},</if>
update_time = sysdate()
</set>
where user_id = #{userId}