1.设备分成计算修改,待测试;

2.用户登录无需手机号
This commit is contained in:
墨大叔 2024-10-09 11:27:47 +08:00
parent 6ef91e7506
commit 3bb4f33182
6 changed files with 33 additions and 28 deletions

View File

@ -259,28 +259,21 @@ public class SysLoginService
// 通过登录授权码获取到用户信息
WxMaJscode2SessionResult wxMaJscode2SessionResult = wxAuthService.wxJsCode2Session(body.getLoginCode());
ServiceUtil.assertion(wxMaJscode2SessionResult == null, "获取微信openId失败");
// 通过openId查询用户判断是否微信用户
SmUser user = smUserService.selectSmUserByWxOpenId(wxMaJscode2SessionResult.getOpenid());
String openId = wxMaJscode2SessionResult.getOpenid();
SmUser user = smUserService.selectSmUserByWxOpenId(openId);
// 不是微信老用户则将微信与手机号绑定
// 不是微信用户则使用openId进行注册
if (user == null || Objects.equals(user.getDelFlag(), UserStatus.DELETED.getCode())) {
ServiceUtil.assertion(body.getMobileCode() == null, "请提供微信手机号授权码", 10003);
// 通过授权码获取微信手机号
String phoneNumber = getWxPhoneNumber(body.getMobileCode());
ServiceUtil.assertion(StringUtils.isBlank(phoneNumber), "获取授权手机号失败");
// 判断用户是否注册未注册的自动注册
user = smUserService.selectUserByPhone(phoneNumber);
if(ObjectUtils.isEmpty(user)){
user = registerWx(phoneNumber, wxMaJscode2SessionResult);
}
user = registerWx(openId);
}
ServiceUtil.assertion(user == null, "用户不存在");
Authentication authentication = null;
try {
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(user.getPhonenumber(), Constants.CUSTOM_LOGIN_WX);
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(openId, Constants.CUSTOM_LOGIN_WX);
// 用户名和密码等信息保存在一个上下文中只要是同一线程等会就能拿到用户名和密码也就是能在loadUserByUsername(String username)方法中进行密码验证等
AuthenticationContextHolder.setContext(authenticationToken);
// 把用户登录类型放在上下文中的details属性中在UserDetailsServiceImpl.loadUserByUsername中获取
@ -303,20 +296,19 @@ public class SysLoginService
/**
* 注册微信用户
* @param phoneNumber 手机号
* @param wxMaJscode2SessionResult 微信用户信息
* @return
* @param openId 微信OpenId
*/
private SmUser registerWx(String phoneNumber, WxMaJscode2SessionResult wxMaJscode2SessionResult) {
private SmUser registerWx(String openId) {
if (StringUtils.isBlank(openId)) {
return null;
}
String name = "微信用户" + openId.substring(openId.length() - 4);
// 添加用户
SmUser newUser = new SmUser();
newUser.setUserName(phoneNumber);
newUser.setPhonenumber(phoneNumber);
newUser.setNickName("微信用户" + phoneNumber.substring(phoneNumber.length() - 4));
newUser.setLoginIp(IpUtils.getIpAddr());
newUser.setLoginDate(DateUtils.getNowDate());
newUser.setCreateTime(DateUtils.getNowDate());
newUser.setWxOpenId(wxMaJscode2SessionResult.getOpenid());
newUser.setUserName(name);
newUser.setWxOpenId(openId);
smUserService.insertSmUser(newUser);
// 添加微信账户

View File

@ -60,7 +60,7 @@ public class UserDetailsServiceImpl implements UserDetailsService
return createLoginUser(user);
} else if(Constants.USER_TYPE_WX.equals(userType)) {
// app 用户微信登录
SmUser user = smUserService.selectUserByPhone(username);
SmUser user = smUserService.selectSmUserByWxOpenId(username);
this.checkUser(user, username);
return createLoginUser(user);
} else if(Constants.USER_TYPE_APP.equals(userType)) {

View File

@ -123,6 +123,7 @@ public class BonusConverterImpl implements BonusConverter {
// 代理模式
else if (DeviceServiceMode.AGENT.getMode().equals(device.getServiceMode())) {
// 平台收取服务费
ServiceUtil.assertion(agent == null, "代理商不存在,请联系管理员处理");
ServiceUtil.assertion(agent.getAgentServiceRate() == null, "代理商服务费未配置");
ServiceUtil.assertion(device.getAgentServiceRate() == null, "代理商设备服务费未配置");
@ -130,7 +131,7 @@ public class BonusConverterImpl implements BonusConverter {
point = point.subtract(agent.getAgentServiceRate());
// 代理商收取服务费
result.add(this.toPo(agent, device.getAgentServiceRate(), agent.getUserId().toString()));
result.add(this.toPo(agent, device.getAgentServiceRate().subtract(agent.getAgentServiceRate()), agent.getUserId().toString()));
point = point.subtract(device.getAgentServiceRate());
}

View File

@ -81,6 +81,9 @@ public class DeviceVO extends Device implements IotDevice {
@ApiModelProperty("最终生效的服务费率")
private BigDecimal realServiceRate;
@ApiModelProperty("代理商本人服务费")
private BigDecimal agentUserServiceRate;
@ApiModelProperty("代理名称")
private String agentName;

View File

@ -163,7 +163,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
su.user_name as user_name,
su.service_rate as user_service_rate,
sua.user_name as agent_name,
sua.phonenumber as agent_mobile
sua.phonenumber as agent_mobile,
sua.agent_service_rate as agent_user_service_rate
from sm_device sd
left join sm_model sm on sm.model_id = sd.model_id
left join sm_store ss on ss.store_id = sd.store_id

View File

@ -8,6 +8,7 @@ import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.collection.CollectionUtils;
import com.ruoyi.ss.device.domain.DeviceBO;
import com.ruoyi.ss.device.domain.DeviceQuery;
import com.ruoyi.ss.device.domain.enums.DeviceServiceMode;
import com.ruoyi.ss.device.domain.vo.DeviceVO;
import com.ruoyi.ss.device.service.DeviceService;
import com.ruoyi.ss.device.service.DeviceValidator;
@ -176,6 +177,13 @@ public class DeviceValidatorImpl extends BaseValidator implements DeviceValidato
ServiceUtil.assertion(this.isRepeatMac(vo.getDeviceId(), vo.getMac2()), "MAC-2重复:" + vo.getMac2());
ServiceUtil.assertion(this.isRepeatSn(vo.getDeviceId(), vo.getDeviceNo()), "SN重复");
// 若是代理模式则代理商服务费不允许 小于 代理商本人的服务费
if (DeviceServiceMode.AGENT.getMode().equals(vo.getServiceMode())) {
ServiceUtil.assertion(vo.getAgentId() == null, "代理商不允许为空");
ServiceUtil.assertion(vo.getAgentServiceRate() == null || vo.getAgentUserServiceRate() == null, "设备代理商服务费或平台代理商服务费不允许为空");
ServiceUtil.assertion(vo.getAgentServiceRate().compareTo(vo.getAgentUserServiceRate()) < 0, "设备服务费不允许小于平台收取代理商的服务费:" + vo.getAgentUserServiceRate() + "%");
}
}
@Override