用户邀请码
邀请注册送湖分
This commit is contained in:
@@ -15,10 +15,8 @@ import com.peanut.common.utils.MD5Utils;
|
|||||||
import com.peanut.common.utils.MailUtil;
|
import com.peanut.common.utils.MailUtil;
|
||||||
import com.peanut.modules.book.service.*;
|
import com.peanut.modules.book.service.*;
|
||||||
import com.peanut.modules.book.to.PageIdDto;
|
import com.peanut.modules.book.to.PageIdDto;
|
||||||
import com.peanut.modules.common.entity.BookBuyConfigEntity;
|
import com.peanut.modules.common.entity.*;
|
||||||
import com.peanut.modules.common.entity.BookEntity;
|
import com.peanut.modules.common.service.UserInviteRegisterService;
|
||||||
import com.peanut.modules.common.entity.MyUserEntity;
|
|
||||||
import com.peanut.modules.common.entity.TransactionDetailsEntity;
|
|
||||||
import com.peanut.modules.sys.service.SysUserTokenService;
|
import com.peanut.modules.sys.service.SysUserTokenService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -58,6 +56,8 @@ public class MyUserController {
|
|||||||
private BookService bookService;
|
private BookService bookService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private TransactionDetailsService transactionDetailsService;
|
private TransactionDetailsService transactionDetailsService;
|
||||||
|
@Autowired
|
||||||
|
private UserInviteRegisterService inviteRegisterService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表
|
* 列表
|
||||||
@@ -79,7 +79,11 @@ public class MyUserController {
|
|||||||
public R getUserList(@RequestBody PageIdDto p){
|
public R getUserList(@RequestBody PageIdDto p){
|
||||||
LambdaQueryWrapper<MyUserEntity> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<MyUserEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.and(p.getKey()!="",k->k.like(MyUserEntity::getName,p.getKey()).or().like(MyUserEntity::getTel,p.getKey()).or().like(MyUserEntity::getEmail,p.getKey()));
|
wrapper.and(p.getKey()!="",k->k.like(MyUserEntity::getName,p.getKey()).or().like(MyUserEntity::getTel,p.getKey()).or().like(MyUserEntity::getEmail,p.getKey()));
|
||||||
|
if (!StringUtils.isEmpty(p.getVipType())){
|
||||||
|
wrapper.eq(MyUserEntity::getVip,p.getVipType());
|
||||||
|
}
|
||||||
wrapper.orderByDesc(MyUserEntity::getCreateTime);
|
wrapper.orderByDesc(MyUserEntity::getCreateTime);
|
||||||
|
|
||||||
Page<MyUserEntity> myUserEntityPage = userService.getBaseMapper().selectPage(new Page<MyUserEntity>(p.getPage(), p.getLimit()), wrapper);
|
Page<MyUserEntity> myUserEntityPage = userService.getBaseMapper().selectPage(new Page<MyUserEntity>(p.getPage(), p.getLimit()), wrapper);
|
||||||
|
|
||||||
return R.ok().put("user",myUserEntityPage);
|
return R.ok().put("user",myUserEntityPage);
|
||||||
@@ -338,7 +342,8 @@ public class MyUserController {
|
|||||||
* 常规注册 / 验证码 登录
|
* 常规注册 / 验证码 登录
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/registerOrLogin")
|
@RequestMapping("/registerOrLogin")
|
||||||
public R register(String tel, String code) {
|
@Transactional
|
||||||
|
public R registerOrLogin(String tel, String code,String inviteCode) {
|
||||||
String redisCode = redisTemplate.opsForValue().get("RegistCode" + tel);
|
String redisCode = redisTemplate.opsForValue().get("RegistCode" + tel);
|
||||||
System.out.println(redisCode);
|
System.out.println(redisCode);
|
||||||
if (StringUtils.isEmpty(redisCode)){
|
if (StringUtils.isEmpty(redisCode)){
|
||||||
@@ -348,6 +353,15 @@ public class MyUserController {
|
|||||||
if (!lcode.equals(code)) {
|
if (!lcode.equals(code)) {
|
||||||
return R.error(500,"验证码不符!");
|
return R.error(500,"验证码不符!");
|
||||||
}
|
}
|
||||||
|
//校验邀请码
|
||||||
|
MyUserEntity inviteUser = null;
|
||||||
|
if (!StringUtils.isEmpty(inviteCode)) {
|
||||||
|
inviteUser = userService.getOne(new LambdaQueryWrapper<MyUserEntity>()
|
||||||
|
.eq(MyUserEntity::getInviteCode, inviteCode));
|
||||||
|
if (inviteUser == null) {
|
||||||
|
return R.error("邀请码有误");
|
||||||
|
}
|
||||||
|
}
|
||||||
//查询是否存在当前用户手机号
|
//查询是否存在当前用户手机号
|
||||||
LambdaQueryWrapper<MyUserEntity> wrapper = new LambdaQueryWrapper();
|
LambdaQueryWrapper<MyUserEntity> wrapper = new LambdaQueryWrapper();
|
||||||
if (tel.contains("@")){
|
if (tel.contains("@")){
|
||||||
@@ -366,7 +380,18 @@ public class MyUserController {
|
|||||||
}else {
|
}else {
|
||||||
myUserEntity.setTel(tel);
|
myUserEntity.setTel(tel);
|
||||||
}
|
}
|
||||||
|
myUserEntity.setInviteCode(inviteRegisterService.generateInviteCode());
|
||||||
userService.save(myUserEntity);
|
userService.save(myUserEntity);
|
||||||
|
//添加邀请记录
|
||||||
|
if (!StringUtils.isEmpty(inviteCode)){
|
||||||
|
myUserEntity.setInviteCode(inviteCode);
|
||||||
|
userService.updateById(myUserEntity);
|
||||||
|
UserInviteRegister inviteRegister = new UserInviteRegister();
|
||||||
|
inviteRegister.setUserId(inviteUser.getId());
|
||||||
|
inviteRegister.setInvitedUserId(myUserEntity.getId());
|
||||||
|
inviteRegisterService.save(inviteRegister);
|
||||||
|
inviteRegisterService.checkInviteRegisterCount(inviteUser.getId());
|
||||||
|
}
|
||||||
R r = sysUserTokenService.createToken(myUserEntity.getId());
|
R r = sysUserTokenService.createToken(myUserEntity.getId());
|
||||||
return R.ok("注册成功").put("userInfo",myUserEntity).put("token",r);
|
return R.ok("注册成功").put("userInfo",myUserEntity).put("token",r);
|
||||||
}else {
|
}else {
|
||||||
|
|||||||
@@ -8,14 +8,17 @@ import com.peanut.common.utils.R;
|
|||||||
import com.peanut.common.utils.ShiroUtils;
|
import com.peanut.common.utils.ShiroUtils;
|
||||||
import com.peanut.modules.common.entity.ClassUser;
|
import com.peanut.modules.common.entity.ClassUser;
|
||||||
import com.peanut.modules.common.entity.MyUserEntity;
|
import com.peanut.modules.common.entity.MyUserEntity;
|
||||||
|
import com.peanut.modules.common.entity.UserInviteRegister;
|
||||||
import com.peanut.modules.common.entity.UserVip;
|
import com.peanut.modules.common.entity.UserVip;
|
||||||
import com.peanut.modules.common.service.ClassEntityService;
|
import com.peanut.modules.common.service.ClassEntityService;
|
||||||
import com.peanut.modules.common.service.MyUserService;
|
import com.peanut.modules.common.service.MyUserService;
|
||||||
|
import com.peanut.modules.common.service.UserInviteRegisterService;
|
||||||
import com.peanut.modules.common.service.UserVipService;
|
import com.peanut.modules.common.service.UserVipService;
|
||||||
import com.peanut.modules.sys.service.SysUserTokenService;
|
import com.peanut.modules.sys.service.SysUserTokenService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
@@ -42,6 +45,8 @@ public class UserController {
|
|||||||
private SysUserTokenService sysUserTokenService;
|
private SysUserTokenService sysUserTokenService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserVipService userVipService;
|
private UserVipService userVipService;
|
||||||
|
@Autowired
|
||||||
|
private UserInviteRegisterService inviteRegisterService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 常规注册 发短信验证码
|
* 常规注册 发短信验证码
|
||||||
@@ -197,7 +202,8 @@ public class UserController {
|
|||||||
* 验证码注册或登录
|
* 验证码注册或登录
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/registerOrLogin")
|
@RequestMapping("/registerOrLogin")
|
||||||
public R register(String tel, String code) {
|
@Transactional
|
||||||
|
public R register(String tel, String code,String inviteCode) {
|
||||||
String redisCode = redisTemplate.opsForValue().get("RegistCode" + tel);
|
String redisCode = redisTemplate.opsForValue().get("RegistCode" + tel);
|
||||||
System.out.println(redisCode);
|
System.out.println(redisCode);
|
||||||
if (StringUtils.isEmpty(redisCode)){
|
if (StringUtils.isEmpty(redisCode)){
|
||||||
@@ -207,6 +213,15 @@ public class UserController {
|
|||||||
if (!lcode.equals(code)) {
|
if (!lcode.equals(code)) {
|
||||||
return R.error(500,"验证码不符!");
|
return R.error(500,"验证码不符!");
|
||||||
}
|
}
|
||||||
|
//校验邀请码
|
||||||
|
MyUserEntity inviteUser = null;
|
||||||
|
if (!StringUtils.isEmpty(inviteCode)) {
|
||||||
|
inviteUser = userService.getOne(new LambdaQueryWrapper<MyUserEntity>()
|
||||||
|
.eq(MyUserEntity::getInviteCode, inviteCode));
|
||||||
|
if (inviteUser == null) {
|
||||||
|
return R.error("邀请码有误");
|
||||||
|
}
|
||||||
|
}
|
||||||
//查询是否存在当前用户
|
//查询是否存在当前用户
|
||||||
LambdaQueryWrapper<MyUserEntity> wrapper = new LambdaQueryWrapper();
|
LambdaQueryWrapper<MyUserEntity> wrapper = new LambdaQueryWrapper();
|
||||||
if (tel.contains("@")){
|
if (tel.contains("@")){
|
||||||
@@ -224,6 +239,16 @@ public class UserController {
|
|||||||
myUserEntity.setTel(tel);
|
myUserEntity.setTel(tel);
|
||||||
}
|
}
|
||||||
userService.save(myUserEntity);
|
userService.save(myUserEntity);
|
||||||
|
//添加邀请记录
|
||||||
|
if (!StringUtils.isEmpty(inviteCode)){
|
||||||
|
myUserEntity.setInviteCode(inviteCode);
|
||||||
|
userService.updateById(myUserEntity);
|
||||||
|
UserInviteRegister inviteRegister = new UserInviteRegister();
|
||||||
|
inviteRegister.setUserId(inviteUser.getId());
|
||||||
|
inviteRegister.setInvitedUserId(myUserEntity.getId());
|
||||||
|
inviteRegisterService.save(inviteRegister);
|
||||||
|
inviteRegisterService.checkInviteRegisterCount(inviteUser.getId());
|
||||||
|
}
|
||||||
R r = sysUserTokenService.createToken(myUserEntity.getId());
|
R r = sysUserTokenService.createToken(myUserEntity.getId());
|
||||||
return R.ok("注册成功").put("userInfo",myUserEntity).put("token",r);
|
return R.ok("注册成功").put("userInfo",myUserEntity).put("token",r);
|
||||||
}else {
|
}else {
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package com.peanut.modules.common.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||||
|
import com.peanut.common.utils.R;
|
||||||
|
import com.peanut.common.utils.ShiroUtils;
|
||||||
|
import com.peanut.modules.common.entity.*;
|
||||||
|
import com.peanut.modules.common.service.MyUserService;
|
||||||
|
import com.peanut.modules.common.service.UserInviteCourseService;
|
||||||
|
import com.peanut.modules.common.service.UserInviteRegisterService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户邀请管理
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController("commonUserInvite")
|
||||||
|
@RequestMapping("common/userInvite")
|
||||||
|
public class UserInviteController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserInviteRegisterService inviteRegisterService;
|
||||||
|
@Autowired
|
||||||
|
private UserInviteCourseService inviteCourseService;
|
||||||
|
@Autowired
|
||||||
|
private MyUserService myUserService;
|
||||||
|
|
||||||
|
|
||||||
|
//获取邀请注册记录列表
|
||||||
|
@RequestMapping("/getInviteRegisterList")
|
||||||
|
public R getInviteRegisterList(@RequestBody Map<String,Object> params) {
|
||||||
|
MPJLambdaWrapper<UserInviteRegister> wrapper = new MPJLambdaWrapper();
|
||||||
|
wrapper.leftJoin(MyUserEntity.class,MyUserEntity::getId,UserInviteRegister::getUserId);
|
||||||
|
wrapper.leftJoin(MyUserEntity.class,MyUserEntity::getId,UserInviteRegister::getInvitedUserId);
|
||||||
|
wrapper.select("t.create_time");
|
||||||
|
wrapper.select("t1.name,t1.nickname,t1.tel,t1.email");
|
||||||
|
wrapper.select("t2.name invitedName,t2.nickname invitedNickname,t2.tel invitedTel,t2.email invitedEmail");
|
||||||
|
wrapper.orderByDesc(UserInviteRegister::getId);
|
||||||
|
if (StringUtils.isNotBlank(params.get("userInfo").toString())){
|
||||||
|
wrapper.and(t->t.like(MyUserEntity::getName,params.get("userInfo")).or().like(MyUserEntity::getNickname,params.get("userInfo"))
|
||||||
|
.or().like(MyUserEntity::getTel,params.get("userInfo")).or().like(MyUserEntity::getEmail,params.get("userInfo")));
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(params.get("invitedUserInfo").toString())){
|
||||||
|
wrapper.and(t->t.like(MyUserEntity::getName,params.get("invitedUserInfo")).or().like(MyUserEntity::getNickname,params.get("invitedUserInfo"))
|
||||||
|
.or().like(MyUserEntity::getTel,params.get("invitedUserInfo")).or().like(MyUserEntity::getEmail,params.get("invitedUserInfo")));
|
||||||
|
}
|
||||||
|
Page<Map<String,Object>> page = inviteRegisterService.pageMaps(new Page<>((int)params.get("page"), (int)params.get("limit")), wrapper);
|
||||||
|
return R.ok().put("result", page);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取邀请购买课程记录列表
|
||||||
|
@RequestMapping("/getInviteCourseList")
|
||||||
|
public R getInviteCourseList(@RequestBody Map<String,Object> params) {
|
||||||
|
MPJLambdaWrapper<UserInviteCourse> wrapper = new MPJLambdaWrapper();
|
||||||
|
wrapper.leftJoin(MyUserEntity.class,MyUserEntity::getId,UserInviteCourse::getUserId);
|
||||||
|
wrapper.leftJoin(MyUserEntity.class,MyUserEntity::getId,UserInviteCourse::getInvitedUserId);
|
||||||
|
wrapper.leftJoin(BuyOrder.class,BuyOrder::getOrderId,UserInviteCourse::getOrderId);
|
||||||
|
wrapper.leftJoin(CourseEntity.class,CourseEntity::getId,UserInviteCourse::getCourseId);
|
||||||
|
wrapper.leftJoin(CourseCatalogueEntity.class,CourseCatalogueEntity::getId,UserInviteCourse::getCatalogueId);
|
||||||
|
wrapper.select("t.create_time");
|
||||||
|
wrapper.select("t1.name,t1.nickname,t1.tel,t1.email");
|
||||||
|
wrapper.select("t2.name invitedName,t2.nickname invitedNickname,t2.tel invitedTel,t2.email invitedEmail");
|
||||||
|
wrapper.select("t3.order_sn,t4.title,t5.title catalogueTitle");
|
||||||
|
wrapper.orderByDesc(UserInviteCourse::getId);
|
||||||
|
if (StringUtils.isNotBlank(params.get("userInfo").toString())){
|
||||||
|
wrapper.and(t->t.like(MyUserEntity::getName,params.get("userInfo")).or().like(MyUserEntity::getNickname,params.get("userInfo"))
|
||||||
|
.or().like(MyUserEntity::getTel,params.get("userInfo")).or().like(MyUserEntity::getEmail,params.get("userInfo")));
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(params.get("invitedUserInfo").toString())){
|
||||||
|
wrapper.and(t->t.like(MyUserEntity::getName,params.get("invitedUserInfo")).or().like(MyUserEntity::getNickname,params.get("invitedUserInfo"))
|
||||||
|
.or().like(MyUserEntity::getTel,params.get("invitedUserInfo")).or().like(MyUserEntity::getEmail,params.get("invitedUserInfo")));
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(params.get("courseName").toString())){
|
||||||
|
wrapper.like(CourseEntity::getTitle,params.get("courseName"));
|
||||||
|
}
|
||||||
|
Page<Map<String,Object>> page = inviteCourseService.pageMaps(new Page<>((int)params.get("page"), (int)params.get("limit")), wrapper);
|
||||||
|
return R.ok().put("result", page);
|
||||||
|
}
|
||||||
|
|
||||||
|
//生成邀请码
|
||||||
|
@RequestMapping("/generateInviteCode")
|
||||||
|
public R generateInviteCode() {
|
||||||
|
MyUserEntity userEntity = myUserService.getById(ShiroUtils.getUId());
|
||||||
|
String code = inviteRegisterService.generateInviteCode();
|
||||||
|
userEntity.setInviteCode(code);
|
||||||
|
myUserService.updateById(userEntity);
|
||||||
|
return R.ok();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.peanut.modules.common.dao;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.peanut.modules.common.entity.UserInviteCourse;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface UserInviteCourseDao extends BaseMapper<UserInviteCourse> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.peanut.modules.common.dao;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.peanut.modules.common.entity.UserInviteRegister;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface UserInviteRegisterDao extends BaseMapper<UserInviteRegister> {
|
||||||
|
}
|
||||||
@@ -80,6 +80,11 @@ public class MyUserEntity implements Serializable {
|
|||||||
* 积分
|
* 积分
|
||||||
*/
|
*/
|
||||||
private BigDecimal jf;
|
private BigDecimal jf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邀请码
|
||||||
|
*/
|
||||||
|
private String inviteCode;
|
||||||
/**
|
/**
|
||||||
* 阅读时间
|
* 阅读时间
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.peanut.modules.common.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("user_invite_course")
|
||||||
|
public class UserInviteCourse {
|
||||||
|
|
||||||
|
@TableId
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private Integer userId;
|
||||||
|
|
||||||
|
private Integer invitedUserId;
|
||||||
|
|
||||||
|
private Integer orderId;
|
||||||
|
|
||||||
|
private Integer courseId;
|
||||||
|
|
||||||
|
private Integer catalogueId;
|
||||||
|
//已计算湖分
|
||||||
|
private Integer countContribution;
|
||||||
|
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.peanut.modules.common.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("user_invite_register")
|
||||||
|
public class UserInviteRegister {
|
||||||
|
|
||||||
|
@TableId
|
||||||
|
private Integer id;
|
||||||
|
//邀请人
|
||||||
|
private Integer userId;
|
||||||
|
//被邀请人
|
||||||
|
private Integer invitedUserId;
|
||||||
|
//已计算湖分
|
||||||
|
private Integer countContribution;
|
||||||
|
|
||||||
|
private Date createTime;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.peanut.modules.common.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.peanut.modules.common.entity.UserInviteCourse;
|
||||||
|
|
||||||
|
public interface UserInviteCourseService extends IService<UserInviteCourse> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.peanut.modules.common.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.peanut.modules.common.entity.UserInviteRegister;
|
||||||
|
|
||||||
|
public interface UserInviteRegisterService extends IService<UserInviteRegister> {
|
||||||
|
|
||||||
|
void checkInviteRegisterCount(int userId);
|
||||||
|
|
||||||
|
String generateInviteCode();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.peanut.modules.common.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.peanut.modules.common.dao.UserInviteCourseDao;
|
||||||
|
import com.peanut.modules.common.entity.UserInviteCourse;
|
||||||
|
import com.peanut.modules.common.service.UserInviteCourseService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service("commonUserInviteCourseService")
|
||||||
|
public class UserInviteCourseServiceImpl extends ServiceImpl<UserInviteCourseDao, UserInviteCourse> implements UserInviteCourseService {
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.peanut.modules.common.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.peanut.modules.common.dao.MyUserDao;
|
||||||
|
import com.peanut.modules.common.dao.UserContributionDao;
|
||||||
|
import com.peanut.modules.common.dao.UserInviteRegisterDao;
|
||||||
|
import com.peanut.modules.common.entity.MyUserEntity;
|
||||||
|
import com.peanut.modules.common.entity.UserContribution;
|
||||||
|
import com.peanut.modules.common.entity.UserInviteRegister;
|
||||||
|
import com.peanut.modules.common.service.UserInviteRegisterService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service("commonUserInviteRegisterService")
|
||||||
|
public class UserInviteRegisterServiceImpl extends ServiceImpl<UserInviteRegisterDao, UserInviteRegister> implements UserInviteRegisterService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserContributionDao userContributionDao;
|
||||||
|
@Autowired
|
||||||
|
private MyUserDao myUserDao;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void checkInviteRegisterCount(int userId) {
|
||||||
|
//邀请人数(未计算过湖分)
|
||||||
|
List<UserInviteRegister> registers = this.baseMapper.selectList(new LambdaQueryWrapper<UserInviteRegister>()
|
||||||
|
.eq(UserInviteRegister::getCountContribution,0)
|
||||||
|
.eq(UserInviteRegister::getUserId,userId));
|
||||||
|
if (registers.size()==10){
|
||||||
|
UserContribution userContribution = new UserContribution();
|
||||||
|
userContribution.setUserId(userId);
|
||||||
|
userContribution.setDetail("邀请人数达到10人");
|
||||||
|
userContribution.setScore(1.0);
|
||||||
|
userContribution.setType("11");
|
||||||
|
userContributionDao.insert(userContribution);
|
||||||
|
for (UserInviteRegister register:registers){
|
||||||
|
register.setCountContribution(1);
|
||||||
|
this.baseMapper.updateById(register);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generateInviteCode() {
|
||||||
|
String code = "";
|
||||||
|
String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // 邀请码字符集
|
||||||
|
StringBuilder inviteCode = new StringBuilder();
|
||||||
|
Random random = new Random();
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
int index = random.nextInt(chars.length());
|
||||||
|
inviteCode.append(chars.charAt(index));
|
||||||
|
}
|
||||||
|
int count = myUserDao.selectCount(new LambdaQueryWrapper<MyUserEntity>()
|
||||||
|
.eq(MyUserEntity::getInviteCode,inviteCode.toString()));
|
||||||
|
if (count > 0) {
|
||||||
|
code = generateInviteCode();
|
||||||
|
}else {
|
||||||
|
code = inviteCode.toString();
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user