|
|
|
@ -239,49 +239,532 @@ public class MemberService extends ServiceImpl<MemberMapper, MemberEntity> imple
|
|
|
|
|
if(!entity.getPassword().equals(new Sha256Hash(member.getPassword()).toHex())) {
|
|
|
|
|
return Result.result(501, null, "旧密码错误!");
|
|
|
|
|
}
|
|
|
|
|
if(!cacheService.isExist(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile())){
|
|
|
|
|
return Result.result(502, null, "验证码错误");
|
|
|
|
|
}
|
|
|
|
|
entity.setPassword(new Sha256Hash(member.getNowPassword()).toHex());
|
|
|
|
|
return Result.result(0, null, "修改成功");
|
|
|
|
|
}
|
|
|
|
|
package com.tamguo.modules.member.service.impl;
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
@Transactional(readOnly=true)
|
|
|
|
|
@Override
|
|
|
|
|
public Page<MemberEntity> listData(MemberCondition condition) {
|
|
|
|
|
Page<MemberEntity> page = new Page<>(condition.getPageNo(), condition.getPageSize());
|
|
|
|
|
Condition query = Condition.create();
|
|
|
|
|
if(!StringUtils.isEmpty(condition.getMobile())) {
|
|
|
|
|
query.eq("mobile", condition.getMobile());
|
|
|
|
|
}
|
|
|
|
|
if(!StringUtils.isEmpty(condition.getNickName())) {
|
|
|
|
|
query.like("nick_name", condition.getNickName());
|
|
|
|
|
}
|
|
|
|
|
if(!StringUtils.isEmpty(condition.getUsername())) {
|
|
|
|
|
query.eq("username", condition.getUsername());
|
|
|
|
|
}
|
|
|
|
|
return this.selectPage(page, query);
|
|
|
|
|
}
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.shiro.crypto.hash.Sha256Hash;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
@Transactional(readOnly=false)
|
|
|
|
|
@Override
|
|
|
|
|
public void reward(String id ,String bookId , Integer rewardPoint, BigDecimal rewardMoney) {
|
|
|
|
|
MemberEntity member = memberMapper.selectById(id);
|
|
|
|
|
|
|
|
|
|
// 更新记录
|
|
|
|
|
member.setPoint(member.getPoint() + rewardPoint);
|
|
|
|
|
member.setAmount(member.getAmount().add(rewardMoney));
|
|
|
|
|
this.updateById(member);
|
|
|
|
|
|
|
|
|
|
BookEntity book = iBookService.selectById(bookId);
|
|
|
|
|
|
|
|
|
|
// 发送短信
|
|
|
|
|
try {
|
|
|
|
|
iSmsService.sendRewardSms(member.getMobile(), member.getUsername(), book.getName(), rewardPoint, rewardMoney);
|
|
|
|
|
} catch (ClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
import com.aliyuncs.exceptions.ClientException;
|
|
|
|
|
import com.baomidou.mybatisplus.mapper.Condition;
|
|
|
|
|
import com.baomidou.mybatisplus.plugins.Page;
|
|
|
|
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
|
|
|
|
import com.tamguo.common.utils.Result;
|
|
|
|
|
import com.tamguo.common.utils.SystemConstant;
|
|
|
|
|
import com.tamguo.config.redis.CacheService;
|
|
|
|
|
import com.tamguo.modules.book.model.BookEntity;
|
|
|
|
|
import com.tamguo.modules.book.service.IBookService;
|
|
|
|
|
import com.tamguo.modules.member.dao.MemberMapper;
|
|
|
|
|
import com.tamguo.modules.member.model.MemberEntity;
|
|
|
|
|
import com.tamguo.modules.member.model.condition.MemberCondition;
|
|
|
|
|
import com.tamguo.modules.member.service.IMemberService;
|
|
|
|
|
import com.tamguo.modules.sys.service.ISmsService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* MemberServiceImpl 类,实现了 IMemberService 接口
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberEntity> implements IMemberService {
|
|
|
|
|
|
|
|
|
|
// 注入 MemberMapper
|
|
|
|
|
@Autowired
|
|
|
|
|
private MemberMapper memberMapper;
|
|
|
|
|
|
|
|
|
|
// 注入 CacheService
|
|
|
|
|
@Autowired
|
|
|
|
|
private CacheService cacheService;
|
|
|
|
|
|
|
|
|
|
// 注入 ISmsService
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISmsService iSmsService;
|
|
|
|
|
|
|
|
|
|
// 注入 IBookService
|
|
|
|
|
@Autowired
|
|
|
|
|
private IBookService iBookService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 登录方法
|
|
|
|
|
*
|
|
|
|
|
* @param username 用户名
|
|
|
|
|
* @param password 密码
|
|
|
|
|
* @return 登录结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Result login(String username, String password) {
|
|
|
|
|
// 创建 MemberEntity 对象
|
|
|
|
|
MemberEntity condition = new MemberEntity();
|
|
|
|
|
// 设置用户名
|
|
|
|
|
condition.setUsername(username);
|
|
|
|
|
// 从数据库中查询该用户
|
|
|
|
|
MemberEntity member = memberMapper.selectOne(condition);
|
|
|
|
|
// 如果用户不存在
|
|
|
|
|
if (member == null) {
|
|
|
|
|
// 返回错误结果,提示用户名 或 password 有误
|
|
|
|
|
return Result.result(201, member, "用户名或密码有误,请重新输入或找回密码");
|
|
|
|
|
}
|
|
|
|
|
// 获取该用户的登录失败次数
|
|
|
|
|
Integer loginFailureCount = this.getLoginFailureCount(member);
|
|
|
|
|
// 如果密码错误
|
|
|
|
|
if (!new Sha256Hash(password).toHex().equals(member.getPassword())) {
|
|
|
|
|
// 登录失败次数加 1
|
|
|
|
|
loginFailureCount++;
|
|
|
|
|
// 更新登录失败次数
|
|
|
|
|
this.updateLoginFailureCount(member, loginFailureCount);
|
|
|
|
|
// 返回错误结果,提示用户名 或 password 有误
|
|
|
|
|
return Result.result(202, member, "用户名或密码有误,请重新输入或找回密码");
|
|
|
|
|
}
|
|
|
|
|
// 更新登录失败次数为 0
|
|
|
|
|
this.updateLoginFailureCount(member, 0);
|
|
|
|
|
// 返回正确结果,提示登录成功
|
|
|
|
|
return Result.result(200, member, "登录成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新登录失败次数
|
|
|
|
|
*
|
|
|
|
|
* @param member 会员实体
|
|
|
|
|
* @param loginFailureCount 登录失败次数
|
|
|
|
|
*/
|
|
|
|
|
public void updateLoginFailureCount(MemberEntity member, Integer loginFailureCount) {
|
|
|
|
|
// 将登录失败次数存储到缓存中,key 为 LOGIN_FAILURE_COUNT + member.getId()
|
|
|
|
|
cacheService.setObject(SystemConstant.LOGIN_FAILURE_COUNT + member.getId(), loginFailureCount, 2 * 60 * 60);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取登录失败次数
|
|
|
|
|
*
|
|
|
|
|
* @param member 会员实体
|
|
|
|
|
* @return 登录失败次数
|
|
|
|
|
*/
|
|
|
|
|
public Integer getLoginFailureCount(MemberEntity member) {
|
|
|
|
|
// 如果 member 为空
|
|
|
|
|
if (member == null) {
|
|
|
|
|
// 返回 0
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
// 如果缓存中不存在登录失败次数
|
|
|
|
|
if (!cacheService.isExist(SystemConstant.LOGIN_FAILURE_COUNT + member.getId())) {
|
|
|
|
|
// 返回 0
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
// 从缓存中获取登录失败次数
|
|
|
|
|
return (Integer) cacheService.getObject(SystemConstant.LOGIN_FAILURE_COUNT + member.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查用户名是否存在
|
|
|
|
|
*
|
|
|
|
|
* @param username 用户名
|
|
|
|
|
* @return 检查结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Result checkUsername(String username) {
|
|
|
|
|
// 创建 MemberEntity 对象
|
|
|
|
|
MemberEntity condition = new MemberEntity();
|
|
|
|
|
// 设置用户名
|
|
|
|
|
condition.setUsername(username);
|
|
|
|
|
// 从数据库中查询该用户
|
|
|
|
|
MemberEntity member = memberMapper.selectOne(condition);
|
|
|
|
|
// 如果用户存在
|
|
|
|
|
if (member!= null) {
|
|
|
|
|
// 返回错误结果,提示该用户名已经存在
|
|
|
|
|
return Result.result(201, null, "该用户名已经存在");
|
|
|
|
|
}
|
|
|
|
|
// 返回正确结果,提示该用户名可用
|
|
|
|
|
return Result.result(200, null, "该用户名可用");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查手机号是否存在
|
|
|
|
|
*
|
|
|
|
|
* @param mobile 手机号
|
|
|
|
|
* @return 检查结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Result checkMobile(String mobile) {
|
|
|
|
|
// 创建 MemberEntity 对象
|
|
|
|
|
MemberEntity condition = new MemberEntity();
|
|
|
|
|
// 设置手机号
|
|
|
|
|
condition.setMobile(mobile);
|
|
|
|
|
// 从数据库中查询该用户
|
|
|
|
|
MemberEntity member = memberMapper.selectOne(condition);
|
|
|
|
|
// 如果用户存在
|
|
|
|
|
if (member!= null) {
|
|
|
|
|
// 返回错误结果,提示该手机号已经存在
|
|
|
|
|
return Result.result(201, null, "该手机号已经存在");
|
|
|
|
|
}
|
|
|
|
|
// 返回正确结果,提示该手机号可用
|
|
|
|
|
return Result.result(200, null, "该手机号可用");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 注册方法
|
|
|
|
|
*
|
|
|
|
|
* @param member 会员实体
|
|
|
|
|
* @return 注册结果
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(readOnly = false)
|
|
|
|
|
@Override
|
|
|
|
|
public Result register(MemberEntity member) {
|
|
|
|
|
// 创建 MemberEntity 对象
|
|
|
|
|
MemberEntity condition = new MemberEntity();
|
|
|
|
|
// 设置用户名
|
|
|
|
|
condition.setUsername(member.getUsername());
|
|
|
|
|
// 从数据库中查询该用户
|
|
|
|
|
MemberEntity m = memberMapper.selectOne(condition);
|
|
|
|
|
// 如果用户已存在
|
|
|
|
|
if (m!= null) {
|
|
|
|
|
// 返回错误结果,提示该用户已经存在
|
|
|
|
|
return Result.result(201, null, "该用户已经存在");
|
|
|
|
|
}
|
|
|
|
|
// 创建 MemberEntity 对象
|
|
|
|
|
condition = new MemberEntity();
|
|
|
|
|
// 设置手机号
|
|
|
|
|
condition.setMobile(member.getMobile());
|
|
|
|
|
// 从数据库中查询该用户
|
|
|
|
|
m = memberMapper.selectOne(condition);
|
|
|
|
|
// 如果手机号已存在
|
|
|
|
|
if (m!= null) {
|
|
|
|
|
// 返回错误结果,提示该手机号已经存在
|
|
|
|
|
return Result.result(202, null, "该手机号已经存在");
|
|
|
|
|
}
|
|
|
|
|
// 如果缓存中不存在验证码
|
|
|
|
|
if (!cacheService.isExist(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile())) {
|
|
|
|
|
// 返回错误结果,提示验证码错误
|
|
|
|
|
return Result.result(203, null, "验证码错误");
|
|
|
|
|
}
|
|
|
|
|
// 从缓存中获取验证码
|
|
|
|
|
String code = (String) cacheService.getObject(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile());
|
|
|
|
|
// 如果验证码错误
|
|
|
|
|
if (!code.equals(member.getVerifyCode())) {
|
|
|
|
|
// 返回错误结果,提示验证码错误
|
|
|
|
|
return Result.result(204, null, "验证码错误");
|
|
|
|
|
}
|
|
|
|
|
// 创建 MemberEntity 对象
|
|
|
|
|
MemberEntity entity = new MemberEntity();
|
|
|
|
|
// 设置头像
|
|
|
|
|
entity.setAvatar(SystemConstant.DEFAULT_MEMBER_AVATAR);
|
|
|
|
|
// 设置手机号
|
|
|
|
|
entity.setMobile(member.getMobile());
|
|
|
|
|
// 设置密码
|
|
|
|
|
entity.setPassword(new Sha256Hash(member.getPassword()).toHex());
|
|
|
|
|
// 设置用户名
|
|
|
|
|
entity.setUsername(member.getUsername());
|
|
|
|
|
// 设置昵称
|
|
|
|
|
entity.setNickName(member.getUsername());
|
|
|
|
|
// 设置邮箱
|
|
|
|
|
entity.setEmail(member.getEmail());
|
|
|
|
|
// 插入会员信息
|
|
|
|
|
memberMapper.insert(entity);
|
|
|
|
|
// 返回正确结果,提示注册成功
|
|
|
|
|
return Result.result(200, entity, "注册成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查帐号是否存在
|
|
|
|
|
*
|
|
|
|
|
* @param account 帐号
|
|
|
|
|
* @return 检查结果
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
@Override
|
|
|
|
|
public Result checkAccount(String account) {
|
|
|
|
|
// 如果帐号为空
|
|
|
|
|
if (StringUtils.isEmpty(account)) {
|
|
|
|
|
// 返回错误结果,提示帐号不存在
|
|
|
|
|
return Result.result(201, null, "帐号不存在!");
|
|
|
|
|
}
|
|
|
|
|
// 创建 Condition 对象
|
|
|
|
|
Condition query = Condition.create();
|
|
|
|
|
// 添加条件,根据帐号查询会员信息
|
|
|
|
|
query.eq("user_name", account).or().eq("mobile", account);
|
|
|
|
|
// 从数据库中查询会员信息
|
|
|
|
|
List<MemberEntity> members = memberMapper.selectList(query);
|
|
|
|
|
// 如果没有查询到会员信息
|
|
|
|
|
if (members.size() == 0) {
|
|
|
|
|
// 返回错误结果,提示帐号不存在
|
|
|
|
|
return Result.result(201, null, "帐号不存在!");
|
|
|
|
|
}
|
|
|
|
|
// 返回正确结果,提示帐号存在,并返回会员信息
|
|
|
|
|
return Result.result(200, members.get(0), "该帐号存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 确认帐号是否存在
|
|
|
|
|
*
|
|
|
|
|
* @param account 帐号
|
|
|
|
|
* @param veritycode 验证码
|
|
|
|
|
* @return 确认结果
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
@Override
|
|
|
|
|
public Result confirmAccount(String account, String veritycode) {
|
|
|
|
|
// 如果帐号为空
|
|
|
|
|
if (StringUtils.isEmpty(account)) {
|
|
|
|
|
// 返回错误结果,提示帐号不存在
|
|
|
|
|
return Result.result(201, null, "帐号不存在!");
|
|
|
|
|
}
|
|
|
|
|
// 创建 Condition 对象
|
|
|
|
|
Condition query = Condition.create();
|
|
|
|
|
// 添加条件,根据帐号查询会员信息
|
|
|
|
|
query.eq("username", account).or().eq("mobile", account);
|
|
|
|
|
// 从数据库中查询会员信息
|
|
|
|
|
List<MemberEntity> members = memberMapper.selectList(query);
|
|
|
|
|
// 如果没有查询到会员信息
|
|
|
|
|
if (members.size() == 0) {
|
|
|
|
|
// 返回错误结果,提示帐号不存在
|
|
|
|
|
return Result.result(201, null, "帐号不存在!");
|
|
|
|
|
}
|
|
|
|
|
// 返回正确结果,提示帐号存在,并返回会员信息
|
|
|
|
|
return Result.result(200, members.get(0), "该帐号存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 安全检查
|
|
|
|
|
*
|
|
|
|
|
* @param username 用户名
|
|
|
|
|
* @param isEmail 是否为邮箱
|
|
|
|
|
* @param vcode 验证码
|
|
|
|
|
* @return 安全检查结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Result securityCheck(String username, String isEmail, String vcode) {
|
|
|
|
|
// 创建 MemberEntity 对象
|
|
|
|
|
MemberEntity condition = new MemberEntity();
|
|
|
|
|
// 设置用户名
|
|
|
|
|
condition.setUsername(username);
|
|
|
|
|
// 从数据库中查询该用户
|
|
|
|
|
MemberEntity member = memberMapper.selectOne(condition);
|
|
|
|
|
// 如果用户不存在
|
|
|
|
|
if (member == null) {
|
|
|
|
|
// 返回错误结果,提示用户不存在
|
|
|
|
|
return Result.result(201, member, "用户不存在");
|
|
|
|
|
}
|
|
|
|
|
// 如果是邮箱验证
|
|
|
|
|
if ("1".equals(isEmail)) {
|
|
|
|
|
// 如果缓存中不存在验证码
|
|
|
|
|
if (!cacheService.isExist(SystemConstant.ALIYUN_MAIL_FIND_PASSWORD_PREFIX + member.getEmail())) {
|
|
|
|
|
// 返回错误结果,提示验证码错误
|
|
|
|
|
return Result.result(201, member, "验证码错误");
|
|
|
|
|
}
|
|
|
|
|
// 从缓存中获取验证码
|
|
|
|
|
String code = (String) cacheService.getObject(SystemConstant.ALIYUN_MAIL_FIND_PASSWORD_PREFIX + member.getEmail());
|
|
|
|
|
// 如果验证码错误
|
|
|
|
|
if (!code.equals(vcode)) {
|
|
|
|
|
// 返回错误结果,提示验证码错误
|
|
|
|
|
return Result.result(202, member, "验证码错误");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 如果缓存中不存在验证码
|
|
|
|
|
if (!cacheService.isExist(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile())) {
|
|
|
|
|
// 返回错误结果,提示验证码错误
|
|
|
|
|
return Result.result(203, member, "验证码错误");
|
|
|
|
|
}
|
|
|
|
|
// 从缓存中获取验证码
|
|
|
|
|
String code = (String) cacheService.getObject(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile());
|
|
|
|
|
// 如果验证码错误
|
|
|
|
|
if (!code.equals(vcode)) {
|
|
|
|
|
// 返回错误结果,提示验证码错误
|
|
|
|
|
return Result.result(204, member, "验证码错误");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 创建随机字符串
|
|
|
|
|
String key = UUID.randomUUID().toString();
|
|
|
|
|
// 将用户名存储到缓存中,key 为 SECURITY_CHECK_PREFIX + key
|
|
|
|
|
cacheService.setObject(SystemConstant.SECURITY_CHECK_PREFIX + key, username, 2 * 60 * 60);
|
|
|
|
|
// 返回正确结果,提示安全验证通过,并返回随机字符串
|
|
|
|
|
return Result.result(200, key, "安全验证通过");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 重置密码
|
|
|
|
|
*
|
|
|
|
|
* @param resetPasswordKey 重置密码 key
|
|
|
|
|
* @param username 用户名
|
|
|
|
|
* @param password 新密码
|
|
|
|
|
* @param verifypwd 确认密码
|
|
|
|
|
* @return 重置密码结果
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Result resetPassword(String resetPasswordKey, String username, String password, String verifypwd) {
|
|
|
|
|
// 如果缓存中存在重置密码 key
|
|
|
|
|
if (cacheService.isExist(SystemConstant.SECURITY_CHECK_PREFIX + resetPasswordKey)) {
|
|
|
|
|
// 创建 MemberEntity 对象
|
|
|
|
|
MemberEntity condition = new MemberEntity();
|
|
|
|
|
// 设置用户名
|
|
|
|
|
condition.setUsername(username);
|
|
|
|
|
// 从数据库中查询该用户
|
|
|
|
|
MemberEntity member = memberMapper.selectOne(condition);
|
|
|
|
|
// 如果密码和确认密码不一致
|
|
|
|
|
if (!password.equals(verifypwd)) {
|
|
|
|
|
// 返回错误结果,提示密码不一致
|
|
|
|
|
return Result.result(201, null, "密码不一致");
|
|
|
|
|
}
|
|
|
|
|
// 设置密码
|
|
|
|
|
member.setPassword(new Sha256Hash(password).toHex());
|
|
|
|
|
// 更新会员信息
|
|
|
|
|
memberMapper.updateById(member);
|
|
|
|
|
}
|
|
|
|
|
// 返回正确结果,提示更新成功
|
|
|
|
|
return Result.result(200, null, "更新成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新会员信息
|
|
|
|
|
*
|
|
|
|
|
* @param member 会员实体
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(readOnly = false)
|
|
|
|
|
@Override
|
|
|
|
|
public void updateMember(MemberEntity member) {
|
|
|
|
|
// 获取会员信息
|
|
|
|
|
MemberEntity entity = memberMapper.selectById(member.getId());
|
|
|
|
|
// 设置头像
|
|
|
|
|
entity.setAvatar(member.getAvatar());
|
|
|
|
|
// 设置邮箱
|
|
|
|
|
entity.setEmail(member.getEmail());
|
|
|
|
|
// 设置手机号
|
|
|
|
|
entity.setMobile(member.getMobile());
|
|
|
|
|
// 设置昵称
|
|
|
|
|
entity.setNickName(member.getNickName());
|
|
|
|
|
// 更新会员信息
|
|
|
|
|
memberMapper.updateById(entity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据 uid 查询会员信息
|
|
|
|
|
*
|
|
|
|
|
* @param uid uid
|
|
|
|
|
* @return 会员信息
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
|
|
@Override
|
|
|
|
|
public MemberEntity findByUid(String uid) {
|
|
|
|
|
// 根据 uid 查询会员信息
|
|
|
|
|
return memberMapper.selectById(uid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据用户名查询会员信息
|
|
|
|
|
*
|
|
|
|
|
* @param username 用户名
|
|
|
|
|
* @return 会员信息
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
|
|
@Override
|
|
|
|
|
public MemberEntity findByUsername(String username) {
|
|
|
|
|
// 创建 Condition 对象
|
|
|
|
|
Condition query = Condition.create();
|
|
|
|
|
// 添加条件,根据用户名查询会员信息
|
|
|
|
|
query.eq("username", username).or().eq("mobile", username).or().eq("email", username);
|
|
|
|
|
// 从数据库中查询会员信息
|
|
|
|
|
return this.selectOne(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新会员最后登录时间
|
|
|
|
|
*
|
|
|
|
|
* @param uid uid
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(readOnly = false)
|
|
|
|
|
@Override
|
|
|
|
|
public void updateLastLoginTime(String uid) {
|
|
|
|
|
// 获取会员信息
|
|
|
|
|
MemberEntity member = memberMapper.selectById(uid);
|
|
|
|
|
// 设置最后登录时间为当前时间
|
|
|
|
|
member.setLastLoginTime(new Date());
|
|
|
|
|
// 更新会员信息
|
|
|
|
|
memberMapper.updateById(member);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取当前会员信息
|
|
|
|
|
*
|
|
|
|
|
* @param id id
|
|
|
|
|
* @return 会员信息
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public MemberEntity findCurrMember(String id) {
|
|
|
|
|
// 获取会员信息
|
|
|
|
|
MemberEntity member = memberMapper.selectById(id);
|
|
|
|
|
// 将密码设置为 null
|
|
|
|
|
member.setPassword(null);
|
|
|
|
|
// 返回会员信息
|
|
|
|
|
return member;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新密码
|
|
|
|
|
*
|
|
|
|
|
* @param member 会员实体
|
|
|
|
|
* @return 更新结果
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(readOnly = false)
|
|
|
|
|
@Override
|
|
|
|
|
public Result updatePwd(MemberEntity member) {
|
|
|
|
|
// 获取会员信息
|
|
|
|
|
MemberEntity entity = memberMapper.selectById(member.getId());
|
|
|
|
|
// 如果旧密码错误
|
|
|
|
|
if (!entity.getPassword().equals(new Sha256Hash(member.getPassword()).toHex())) {
|
|
|
|
|
// 返回错误结果,提示旧密码错误
|
|
|
|
|
return Result.result(501, null, "旧密码错误!");
|
|
|
|
|
}
|
|
|
|
|
// 如果缓存中不存在验证码
|
|
|
|
|
if (!cacheService.isExist(SystemConstant.ALIYUN_MOBILE_SMS_PREFIX + member.getMobile())){
|
|
|
|
|
// 如果缓存服务中不存在指定的验证码前缀与会员手机号的组合
|
|
|
|
|
return Result.result(502, null, "验证码错误");
|
|
|
|
|
}
|
|
|
|
|
entity.setPassword(new Sha256Hash(member.getNowPassword()).toHex());
|
|
|
|
|
// 设置实体的密码为会员当前密码的 Sha256 哈希值的十六进制表示
|
|
|
|
|
return Result.result(0, null, "修改成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
@Transactional(readOnly=true)
|
|
|
|
|
@Override
|
|
|
|
|
public Page<MemberEntity> listData(MemberCondition condition) {
|
|
|
|
|
// 创建分页对象
|
|
|
|
|
Page<MemberEntity> page = new Page<>(condition.getPageNo(), condition.getPageSize());
|
|
|
|
|
Condition query = Condition.create();
|
|
|
|
|
// 如果条件中的手机号不为空
|
|
|
|
|
if(!StringUtils.isEmpty(condition.getMobile())) {
|
|
|
|
|
query.eq("mobile", condition.getMobile());
|
|
|
|
|
}
|
|
|
|
|
// 如果条件中的昵称不为空
|
|
|
|
|
if(!StringUtils.isEmpty(condition.getNickName())) {
|
|
|
|
|
query.like("nick_name", condition.getNickName());
|
|
|
|
|
}
|
|
|
|
|
// 如果条件中的用户名不为空
|
|
|
|
|
if(!StringUtils.isEmpty(condition.getUsername())) {
|
|
|
|
|
query.eq("username", condition.getUsername());
|
|
|
|
|
}
|
|
|
|
|
return this.selectPage(page, query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(readOnly=false)
|
|
|
|
|
@Override
|
|
|
|
|
public void reward(String id,String bookId, Integer rewardPoint, BigDecimal rewardMoney) {
|
|
|
|
|
MemberEntity member = memberMapper.selectById(id);
|
|
|
|
|
// 获取会员实体
|
|
|
|
|
// 更新会员的积分和金额
|
|
|
|
|
member.setPoint(member.getPoint() + rewardPoint);
|
|
|
|
|
member.setAmount(member.getAmount().add(rewardMoney));
|
|
|
|
|
this.updateById(member);
|
|
|
|
|
|
|
|
|
|
BookEntity book = iBookService.selectById(bookId);
|
|
|
|
|
// 获取书籍实体
|
|
|
|
|
|
|
|
|
|
// 发送短信
|
|
|
|
|
try {
|
|
|
|
|
iSmsService.sendRewardSms(member.getMobile(), member.getUsername(), book.getName(), rewardPoint, rewardMoney);
|
|
|
|
|
} catch (ClientException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|