邀请功能

master
胡锐 3 months ago
parent 2055860be5
commit 4c15dde34a
  1. 6
      cweb/src/main/java/com/hfkj/controller/ClientController.java
  2. 22
      cweb/src/main/java/com/hfkj/controller/UserController.java
  3. 2
      cweb/src/main/java/com/hfkj/controller/UserInviteCodeController.java
  4. 20
      service/src/main/java/com/hfkj/dao/BsUserInviteCodeMapper.java
  5. 14
      service/src/main/java/com/hfkj/dao/BsUserInviteCodeSqlProvider.java
  6. 16
      service/src/main/java/com/hfkj/entity/BsUserInviteCode.java
  7. 70
      service/src/main/java/com/hfkj/entity/BsUserInviteCodeExample.java
  8. 7
      service/src/main/java/com/hfkj/service/user/BsUserInviteCodeService.java
  9. 13
      service/src/main/java/com/hfkj/service/user/BsUserService.java
  10. 36
      service/src/main/java/com/hfkj/service/user/impl/BsUserInviteCodeServiceImpl.java
  11. 36
      service/src/main/java/com/hfkj/service/user/impl/BsUserServiceImpl.java

@ -53,8 +53,8 @@ public class ClientController {
) { ) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
// 邀请码 // 邀请码人id
String inviteCode = body.getString("inviteCode"); Long inviteUseId = body.getLong("inviteUseId");
// 手机号 // 手机号
String phone = body.getString("phone"); String phone = body.getString("phone");
// 校验手机号格式 // 校验手机号格式
@ -74,7 +74,7 @@ public class ClientController {
} }
redisUtil.del("SMS_LOGIN_CODE:" + phone); redisUtil.del("SMS_LOGIN_CODE:" + phone);
return ResponseMsgUtil.success(userService.login(phone, UserLoginType.SMS, new HashMap<>(), inviteCode)); return ResponseMsgUtil.success(userService.login(phone, UserLoginType.SMS, new HashMap<>(), inviteUseId));
} catch (Exception e) { } catch (Exception e) {
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);

@ -123,6 +123,28 @@ public class UserController {
} }
} }
@RequestMapping(value = "/bindInviteUser", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "绑定邀请人Id")
public ResponseData bindInviteUser(@RequestBody JSONObject body) {
try {
if (body == null || body.getLong("inviteUseId") == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class);
if (StringUtils.isNotBlank(userSession.getUser().getPhone())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "手机号已绑定");
}
// 绑定邀请人
userService.bindInviteUser(userSession.getUser().getId(), body.getLong("inviteUseId"));
return ResponseMsgUtil.success(userCenter.getSessionModel(UserSessionObject.class));
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/verifyUpdPhoneSmsCode", method = RequestMethod.POST) @RequestMapping(value = "/verifyUpdPhoneSmsCode", method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "验证修改手机号验证码") @ApiOperation(value = "验证修改手机号验证码")

@ -47,7 +47,7 @@ public class UserInviteCodeController {
} }
Map<String,Object> param = new HashMap<>(); Map<String,Object> param = new HashMap<>();
// 邀请码 // 邀请码
param.put("inviteCode", userInviteCode.getInviteCode()); param.put("inviteUserId", userInviteCode.getUserId());
// 二维码 // 二维码
param.put("qrCode", userInviteCode.getQrCodeImg()); param.put("qrCode", userInviteCode.getQrCodeImg());
return ResponseMsgUtil.success(param); return ResponseMsgUtil.success(param);

@ -39,14 +39,12 @@ public interface BsUserInviteCodeMapper extends BsUserInviteCodeMapperExt {
int deleteByPrimaryKey(Long id); int deleteByPrimaryKey(Long id);
@Insert({ @Insert({
"insert into bs_user_invite_code (user_id, invite_code, ", "insert into bs_user_invite_code (user_id, qr_code_img, ",
"qr_code_img, `status`, ", "`status`, create_time, ",
"create_time, ext_1, ", "ext_1, ext_2, ext_3)",
"ext_2, ext_3)", "values (#{userId,jdbcType=BIGINT}, #{qrCodeImg,jdbcType=VARCHAR}, ",
"values (#{userId,jdbcType=BIGINT}, #{inviteCode,jdbcType=VARCHAR}, ", "#{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ",
"#{qrCodeImg,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, ", "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})"
"#{createTime,jdbcType=TIMESTAMP}, #{ext1,jdbcType=VARCHAR}, ",
"#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})"
}) })
@Options(useGeneratedKeys=true,keyProperty="id") @Options(useGeneratedKeys=true,keyProperty="id")
int insert(BsUserInviteCode record); int insert(BsUserInviteCode record);
@ -59,7 +57,6 @@ public interface BsUserInviteCodeMapper extends BsUserInviteCodeMapperExt {
@Results({ @Results({
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
@Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT), @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
@Result(column="invite_code", property="inviteCode", jdbcType=JdbcType.VARCHAR),
@Result(column="qr_code_img", property="qrCodeImg", jdbcType=JdbcType.VARCHAR), @Result(column="qr_code_img", property="qrCodeImg", jdbcType=JdbcType.VARCHAR),
@Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
@ -71,15 +68,13 @@ public interface BsUserInviteCodeMapper extends BsUserInviteCodeMapperExt {
@Select({ @Select({
"select", "select",
"id, user_id, invite_code, qr_code_img, `status`, create_time, ext_1, ext_2, ", "id, user_id, qr_code_img, `status`, create_time, ext_1, ext_2, ext_3",
"ext_3",
"from bs_user_invite_code", "from bs_user_invite_code",
"where id = #{id,jdbcType=BIGINT}" "where id = #{id,jdbcType=BIGINT}"
}) })
@Results({ @Results({
@Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
@Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT), @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
@Result(column="invite_code", property="inviteCode", jdbcType=JdbcType.VARCHAR),
@Result(column="qr_code_img", property="qrCodeImg", jdbcType=JdbcType.VARCHAR), @Result(column="qr_code_img", property="qrCodeImg", jdbcType=JdbcType.VARCHAR),
@Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
@ -101,7 +96,6 @@ public interface BsUserInviteCodeMapper extends BsUserInviteCodeMapperExt {
@Update({ @Update({
"update bs_user_invite_code", "update bs_user_invite_code",
"set user_id = #{userId,jdbcType=BIGINT},", "set user_id = #{userId,jdbcType=BIGINT},",
"invite_code = #{inviteCode,jdbcType=VARCHAR},",
"qr_code_img = #{qrCodeImg,jdbcType=VARCHAR},", "qr_code_img = #{qrCodeImg,jdbcType=VARCHAR},",
"`status` = #{status,jdbcType=INTEGER},", "`status` = #{status,jdbcType=INTEGER},",
"create_time = #{createTime,jdbcType=TIMESTAMP},", "create_time = #{createTime,jdbcType=TIMESTAMP},",

@ -32,10 +32,6 @@ public class BsUserInviteCodeSqlProvider {
sql.VALUES("user_id", "#{userId,jdbcType=BIGINT}"); sql.VALUES("user_id", "#{userId,jdbcType=BIGINT}");
} }
if (record.getInviteCode() != null) {
sql.VALUES("invite_code", "#{inviteCode,jdbcType=VARCHAR}");
}
if (record.getQrCodeImg() != null) { if (record.getQrCodeImg() != null) {
sql.VALUES("qr_code_img", "#{qrCodeImg,jdbcType=VARCHAR}"); sql.VALUES("qr_code_img", "#{qrCodeImg,jdbcType=VARCHAR}");
} }
@ -71,7 +67,6 @@ public class BsUserInviteCodeSqlProvider {
sql.SELECT("id"); sql.SELECT("id");
} }
sql.SELECT("user_id"); sql.SELECT("user_id");
sql.SELECT("invite_code");
sql.SELECT("qr_code_img"); sql.SELECT("qr_code_img");
sql.SELECT("`status`"); sql.SELECT("`status`");
sql.SELECT("create_time"); sql.SELECT("create_time");
@ -103,10 +98,6 @@ public class BsUserInviteCodeSqlProvider {
sql.SET("user_id = #{record.userId,jdbcType=BIGINT}"); sql.SET("user_id = #{record.userId,jdbcType=BIGINT}");
} }
if (record.getInviteCode() != null) {
sql.SET("invite_code = #{record.inviteCode,jdbcType=VARCHAR}");
}
if (record.getQrCodeImg() != null) { if (record.getQrCodeImg() != null) {
sql.SET("qr_code_img = #{record.qrCodeImg,jdbcType=VARCHAR}"); sql.SET("qr_code_img = #{record.qrCodeImg,jdbcType=VARCHAR}");
} }
@ -141,7 +132,6 @@ public class BsUserInviteCodeSqlProvider {
sql.SET("id = #{record.id,jdbcType=BIGINT}"); sql.SET("id = #{record.id,jdbcType=BIGINT}");
sql.SET("user_id = #{record.userId,jdbcType=BIGINT}"); sql.SET("user_id = #{record.userId,jdbcType=BIGINT}");
sql.SET("invite_code = #{record.inviteCode,jdbcType=VARCHAR}");
sql.SET("qr_code_img = #{record.qrCodeImg,jdbcType=VARCHAR}"); sql.SET("qr_code_img = #{record.qrCodeImg,jdbcType=VARCHAR}");
sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); sql.SET("`status` = #{record.status,jdbcType=INTEGER}");
sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}");
@ -162,10 +152,6 @@ public class BsUserInviteCodeSqlProvider {
sql.SET("user_id = #{userId,jdbcType=BIGINT}"); sql.SET("user_id = #{userId,jdbcType=BIGINT}");
} }
if (record.getInviteCode() != null) {
sql.SET("invite_code = #{inviteCode,jdbcType=VARCHAR}");
}
if (record.getQrCodeImg() != null) { if (record.getQrCodeImg() != null) {
sql.SET("qr_code_img = #{qrCodeImg,jdbcType=VARCHAR}"); sql.SET("qr_code_img = #{qrCodeImg,jdbcType=VARCHAR}");
} }

@ -23,11 +23,6 @@ public class BsUserInviteCode implements Serializable {
*/ */
private Long userId; private Long userId;
/**
* 邀请码
*/
private String inviteCode;
/** /**
* 二维码地址 * 二维码地址
*/ */
@ -67,14 +62,6 @@ public class BsUserInviteCode implements Serializable {
this.userId = userId; this.userId = userId;
} }
public String getInviteCode() {
return inviteCode;
}
public void setInviteCode(String inviteCode) {
this.inviteCode = inviteCode;
}
public String getQrCodeImg() { public String getQrCodeImg() {
return qrCodeImg; return qrCodeImg;
} }
@ -137,7 +124,6 @@ public class BsUserInviteCode implements Serializable {
BsUserInviteCode other = (BsUserInviteCode) that; BsUserInviteCode other = (BsUserInviteCode) that;
return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
&& (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
&& (this.getInviteCode() == null ? other.getInviteCode() == null : this.getInviteCode().equals(other.getInviteCode()))
&& (this.getQrCodeImg() == null ? other.getQrCodeImg() == null : this.getQrCodeImg().equals(other.getQrCodeImg())) && (this.getQrCodeImg() == null ? other.getQrCodeImg() == null : this.getQrCodeImg().equals(other.getQrCodeImg()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
@ -152,7 +138,6 @@ public class BsUserInviteCode implements Serializable {
int result = 1; int result = 1;
result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode()); result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
result = prime * result + ((getInviteCode() == null) ? 0 : getInviteCode().hashCode());
result = prime * result + ((getQrCodeImg() == null) ? 0 : getQrCodeImg().hashCode()); result = prime * result + ((getQrCodeImg() == null) ? 0 : getQrCodeImg().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
@ -170,7 +155,6 @@ public class BsUserInviteCode implements Serializable {
sb.append("Hash = ").append(hashCode()); sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id); sb.append(", id=").append(id);
sb.append(", userId=").append(userId); sb.append(", userId=").append(userId);
sb.append(", inviteCode=").append(inviteCode);
sb.append(", qrCodeImg=").append(qrCodeImg); sb.append(", qrCodeImg=").append(qrCodeImg);
sb.append(", status=").append(status); sb.append(", status=").append(status);
sb.append(", createTime=").append(createTime); sb.append(", createTime=").append(createTime);

@ -245,76 +245,6 @@ public class BsUserInviteCodeExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andInviteCodeIsNull() {
addCriterion("invite_code is null");
return (Criteria) this;
}
public Criteria andInviteCodeIsNotNull() {
addCriterion("invite_code is not null");
return (Criteria) this;
}
public Criteria andInviteCodeEqualTo(String value) {
addCriterion("invite_code =", value, "inviteCode");
return (Criteria) this;
}
public Criteria andInviteCodeNotEqualTo(String value) {
addCriterion("invite_code <>", value, "inviteCode");
return (Criteria) this;
}
public Criteria andInviteCodeGreaterThan(String value) {
addCriterion("invite_code >", value, "inviteCode");
return (Criteria) this;
}
public Criteria andInviteCodeGreaterThanOrEqualTo(String value) {
addCriterion("invite_code >=", value, "inviteCode");
return (Criteria) this;
}
public Criteria andInviteCodeLessThan(String value) {
addCriterion("invite_code <", value, "inviteCode");
return (Criteria) this;
}
public Criteria andInviteCodeLessThanOrEqualTo(String value) {
addCriterion("invite_code <=", value, "inviteCode");
return (Criteria) this;
}
public Criteria andInviteCodeLike(String value) {
addCriterion("invite_code like", value, "inviteCode");
return (Criteria) this;
}
public Criteria andInviteCodeNotLike(String value) {
addCriterion("invite_code not like", value, "inviteCode");
return (Criteria) this;
}
public Criteria andInviteCodeIn(List<String> values) {
addCriterion("invite_code in", values, "inviteCode");
return (Criteria) this;
}
public Criteria andInviteCodeNotIn(List<String> values) {
addCriterion("invite_code not in", values, "inviteCode");
return (Criteria) this;
}
public Criteria andInviteCodeBetween(String value1, String value2) {
addCriterion("invite_code between", value1, value2, "inviteCode");
return (Criteria) this;
}
public Criteria andInviteCodeNotBetween(String value1, String value2) {
addCriterion("invite_code not between", value1, value2, "inviteCode");
return (Criteria) this;
}
public Criteria andQrCodeImgIsNull() { public Criteria andQrCodeImgIsNull() {
addCriterion("qr_code_img is null"); addCriterion("qr_code_img is null");
return (Criteria) this; return (Criteria) this;

@ -26,11 +26,4 @@ public interface BsUserInviteCodeService {
*/ */
BsUserInviteCode getDetail(Long userId); BsUserInviteCode getDetail(Long userId);
/**
* 查询邀请码
* @param inviteCode
* @return
*/
BsUserInviteCode getDetail(String inviteCode);
} }

@ -33,6 +33,13 @@ public interface BsUserService {
*/ */
void updateWechatNum(Long userId, String wechatNum) throws Exception; void updateWechatNum(Long userId, String wechatNum) throws Exception;
/**
* 绑定邀请人
* @param userId
* @param inviteUseId
*/
void bindInviteUser(Long userId, Long inviteUseId) throws Exception;
/** /**
* 查询详情 * 查询详情
* @param userId * @param userId
@ -51,18 +58,20 @@ public interface BsUserService {
* 用户注册 * 用户注册
* @param phone 手机号 * @param phone 手机号
* @param other 其他参数 * @param other 其他参数
* @param inviteUseId 邀请人id
* @return * @return
* @throws Exception * @throws Exception
*/ */
BsUser register(String phone, Map<String, Object> other, String inviteCode); BsUser register(String phone, Map<String, Object> other, Long inviteUseId);
/** /**
* 用户登录 * 用户登录
* @param phone 用户手机号 * @param phone 用户手机号
* @param other 其他参数 * @param other 其他参数
* @param inviteUseId 邀请人id
* @return * @return
* @throws Exception * @throws Exception
*/ */
SessionObject login(String phone, UserLoginType loginType, Map<String, Object> other,String inviteCode) throws Exception; SessionObject login(String phone, UserLoginType loginType, Map<String, Object> other,Long inviteUseId) throws Exception;
} }

@ -31,29 +31,17 @@ public class BsUserInviteCodeServiceImpl implements BsUserInviteCodeService {
private CommonSysConfig commonSysConfig; private CommonSysConfig commonSysConfig;
private final static String CACHE_KEY = "USER_INVITE_CODE"; private final static String CACHE_KEY = "USER_INVITE_CODE";
private String generateInviteCode() {
// 生成8位随机数
String inviteCode = RandomUtils.number(8, true);
// 查询是否存在,存在就重新生成
if (getDetail(inviteCode) != null) {
generateInviteCode();
}
return inviteCode;
}
@Override @Override
public BsUserInviteCode create(Long userId) throws Exception { public BsUserInviteCode create(Long userId) throws Exception {
BsUserInviteCode data = new BsUserInviteCode(); BsUserInviteCode data = new BsUserInviteCode();
data.setUserId(userId); data.setUserId(userId);
data.setInviteCode(generateInviteCode());
data.setCreateTime(new Date()); data.setCreateTime(new Date());
data.setStatus(1); data.setStatus(1);
System.out.println(commonSysConfig.getDomain()); System.out.println(commonSysConfig.getDomain());
// 生成二维码 // 生成二维码
String fileUrl = "/userInviteCode/"+data.getInviteCode()+".png"; String fileUrl = "/userInviteCode/"+data.getUserId()+".png";
QRCodeGenerator.generateQRCodeImage( QRCodeGenerator.generateQRCodeImage(
data.getInviteCode(), ""+data.getUserId(),
260, 260,
260, 260,
commonSysConfig.getFilesystem() + fileUrl commonSysConfig.getFilesystem() + fileUrl
@ -63,38 +51,28 @@ public class BsUserInviteCodeServiceImpl implements BsUserInviteCodeService {
data.setQrCodeImg(fileUrl); data.setQrCodeImg(fileUrl);
userInviteCodeMapper.insert(data); userInviteCodeMapper.insert(data);
// 缓存 // 缓存
redisUtil.hset(CACHE_KEY, data.getInviteCode(), data); redisUtil.hset(CACHE_KEY, data.getUserId()+"", data);
return data; return data;
} }
@Override @Override
public BsUserInviteCode getDetail(Long userId) { public BsUserInviteCode getDetail(Long userId) {
BsUserInviteCodeExample example = new BsUserInviteCodeExample();
example.createCriteria().andUserIdEqualTo(userId).andStatusNotEqualTo(0);
List<BsUserInviteCode> list = userInviteCodeMapper.selectByExample(example);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
@Override
public BsUserInviteCode getDetail(String inviteCode) {
// 缓存 // 缓存
Object cache = redisUtil.hget(CACHE_KEY, inviteCode); Object cache = redisUtil.hget(CACHE_KEY, ""+userId);
if (cache != null) { if (cache != null) {
return (BsUserInviteCode) cache; return (BsUserInviteCode) cache;
} }
BsUserInviteCodeExample example = new BsUserInviteCodeExample(); BsUserInviteCodeExample example = new BsUserInviteCodeExample();
example.createCriteria().andInviteCodeEqualTo(inviteCode).andStatusNotEqualTo(0); example.createCriteria().andUserIdEqualTo(userId).andStatusNotEqualTo(0);
List<BsUserInviteCode> list = userInviteCodeMapper.selectByExample(example); List<BsUserInviteCode> list = userInviteCodeMapper.selectByExample(example);
if (!list.isEmpty()) { if (!list.isEmpty()) {
BsUserInviteCode data = list.get(0); BsUserInviteCode data = list.get(0);
// 缓存 // 缓存
redisUtil.hset(CACHE_KEY, data.getInviteCode(), data); redisUtil.hset(CACHE_KEY, ""+data.getUserId(), data);
return data; return data;
} }
return null; return null;
} }
} }

@ -116,6 +116,29 @@ public class BsUserServiceImpl implements BsUserService {
userCenter.save(sessionObject); userCenter.save(sessionObject);
} }
@Override
public void bindInviteUser(Long userId, Long inviteUseId) throws Exception {
// 查询用户
BsUser user = getUser(userId);
if (user == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到用户");
}
if (user.getInviteUserId() != null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "已绑定过邀请人");
}
if (getUser(inviteUseId) == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的邀请人Id");
}
user.setInviteUserId(inviteUseId);
editData(user);
// 更新session
UserSessionObject session = new UserSessionObject();
session.setUser(user);
SessionObject sessionObject = new SessionObject(userToken(user.getId()), session);
userCenter.save(sessionObject);
}
@Override @Override
public BsUser getUser(Long userId) { public BsUser getUser(Long userId) {
return userMapper.selectByPrimaryKey(userId); return userMapper.selectByPrimaryKey(userId);
@ -142,20 +165,21 @@ public class BsUserServiceImpl implements BsUserService {
@Override @Override
@Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class}) @Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class})
public BsUser register(String phone, Map<String, Object> other, String inviteCode) { public BsUser register(String phone, Map<String, Object> other, Long inviteUseId) {
// 查询手机号 // 查询手机号
if (getUser(phone) != null) { if (getUser(phone) != null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户手机号已存在,请更换"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户手机号已存在,请更换");
} }
if (StringUtils.isNotBlank(inviteCode)) { BsUser user = new BsUser();
if (inviteUseId != null) {
// 校验邀请码 // 校验邀请码
BsUserInviteCode userInviteCode = userInviteCodeService.getDetail(inviteCode); BsUserInviteCode userInviteCode = userInviteCodeService.getDetail(inviteUseId);
if (userInviteCode == null) { if (userInviteCode == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无效的邀请码"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无效的邀请码");
} }
user.setInviteUserId(userInviteCode.getUserId());
} }
BsUser user = new BsUser();
user.setHeadImg(MapUtils.getString(other,"headImg")); user.setHeadImg(MapUtils.getString(other,"headImg"));
user.setName( user.setName(
StringUtils.isNotBlank(MapUtils.getString(other,"name")) StringUtils.isNotBlank(MapUtils.getString(other,"name"))
@ -175,11 +199,11 @@ public class BsUserServiceImpl implements BsUserService {
@Override @Override
@Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class}) @Transactional(propagation= Propagation.REQUIRED,rollbackFor= {RuntimeException.class})
public SessionObject login(String phone, UserLoginType loginType, Map<String, Object> other, String inviteCode) throws Exception { public SessionObject login(String phone, UserLoginType loginType, Map<String, Object> other, Long inviteUseId) throws Exception {
// 查询用户 // 查询用户
BsUser user = getUser(phone); BsUser user = getUser(phone);
if (user == null) { if (user == null) {
user = register(phone, other, inviteCode); user = register(phone, other, inviteUseId);
} }
// 缓存 // 缓存
UserSessionObject session = new UserSessionObject(); UserSessionObject session = new UserSessionObject();

Loading…
Cancel
Save