新增了邀请新用户奖励功能

This commit is contained in:
1215525055@qq.com 2025-08-07 11:07:19 +08:00
parent b68a89e963
commit f0358c7c2d
7 changed files with 320 additions and 0 deletions

View File

@ -0,0 +1,42 @@
package cn.com.tenlion.operator.controller.api.user;
import cn.com.tenlion.operator.service.user.invite.UserInviteService;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.common.component.SecurityComponent;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.pojo.result.ErrorResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* ClassName: UserInviteController
* Description: 新的邀请码功能
* Author: CBC
* Date: 2025年7月31日16:40:51
* Version: 1.0
*/
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "邀请码接口")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/user/invite")
public class UserInviteController extends DefaultBaseController {
@Autowired
private UserInviteService userInviteService;
@Autowired
protected SecurityComponent securityComponent;
@ApiOperation(value = "邀请新用户", notes = "邀请新用户")
@ApiImplicitParams({
@ApiImplicitParam(name = "userId", value = "userId", paramType = "path")
})
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@GetMapping("get")
public Object invite() {
String userId = securityComponent.getCurrentUser().getUserId();
return userInviteService.getRegisterCode(userId);
}
}

View File

@ -0,0 +1,22 @@
package cn.com.tenlion.operator.dao.user.invite;
import cn.com.tenlion.operator.pojo.dtos.user.ic.apply.UserIcApplyDTO;
import cn.com.tenlion.operator.pojo.pos.user.ic.apply.UserIcApplyPO;
import java.util.List;
import java.util.Map;
/**
* @ClassName: IUserInviteDao
* @Description:
* @Author: wanggeng
* @Date: 2024/8/8 上午11:50
* @Version: 1.0
*/
public interface IUserInviteDao {
void save(Map<String, Object> params);
Map<String, Object> get(Map<String, Object> params);
}

View File

@ -0,0 +1,24 @@
package cn.com.tenlion.operator.enums.invite;
/**
* ClassName: InviteEnum
* Description: 邀请码类型
* Author: CBC
* Date: 2025年7月31日16:37:09
* Version: 1.0
*/
public enum InviteEnum {
NEW_USER("邀请新用户");
private final String text;
InviteEnum(String text) {
this.text = text;
}
public String getText() {
return text;
}
}

View File

@ -1,9 +1,15 @@
package cn.com.tenlion.operator.service;
import cn.com.tenlion.operator.enums.AccountItemTypeEnum;
import cn.com.tenlion.operator.enums.invite.InviteEnum;
import cn.com.tenlion.operator.pojo.dtos.user.expand.UserExpandDTO;
import cn.com.tenlion.operator.pojo.vos.accountitem.AccountItemVO;
import cn.com.tenlion.operator.pojo.vos.user.expand.UserExpandVO;
import cn.com.tenlion.operator.service.account.IAccountService;
import cn.com.tenlion.operator.service.accountitem.IAccountItemService;
import cn.com.tenlion.operator.service.user.custom.UserCustomService;
import cn.com.tenlion.operator.service.user.expand.UserExpandServiceImpl;
import cn.com.tenlion.operator.service.user.invite.UserInviteService;
import ink.wgink.exceptions.SaveException;
import ink.wgink.interfaces.expand.register.IRegisterHandlerService;
import ink.wgink.interfaces.expand.register.IRegisterWithExpandInfoHandlerService;
@ -13,9 +19,11 @@ import ink.wgink.interfaces.user.IUserExpandBaseService;
import ink.wgink.pojo.dtos.role.RoleDTO;
import ink.wgink.pojo.dtos.user.UserDTO;
import ink.wgink.service.role.service.IRoleUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
@ -33,13 +41,19 @@ public class UserRegisterService implements IRegisterHandlerService, IRegisterWi
@Autowired
private IAccountService iAccountService;
@Autowired
private IAccountItemService iAccountItemService;
@Autowired
private IRoleUserService iRoleUserService;
@Autowired
private UserExpandServiceImpl userExpandService;
@Autowired
private UserInviteService userInviteService;
@Override
public void handler(String userId, Map<String, Object> requestParams) throws Exception {
String userRole = requestParams.get("userRole").toString();
Object invite = requestParams.get("inviteCode");
RoleDTO roleDTO = iRoleBaseService.get(userRole);
if (roleDTO == null) {
throw new SaveException("角色不存在");
@ -60,6 +74,37 @@ public class UserRegisterService implements IRegisterHandlerService, IRegisterWi
userExpandVO.setWxOpenId(requestParams.get("wxOpenId") == null ? "" : requestParams.get("wxOpenId").toString());
userExpandVO.setWxUnionId(requestParams.get("wxUnionId") == null ? "" : requestParams.get("wxUnionId").toString());
userExpandService.saveOrUpdate(userId, userExpandVO);
// 给邀请人加钱
// 1. 查到邀请人信息
// 2. 加多少钱
// 3. 加钱
if(invite != null) {
String inviteCode = invite.toString();
Map<String, Object> params = new HashMap<>();
params.put("code", inviteCode);
params.put("type", InviteEnum.NEW_USER.getText());
Map<String, Object> data = userInviteService.get(params);
if (data != null) {
Integer money = Integer.valueOf(data.get("money").toString());
String remark = data.get("remark").toString();
String msg = "";
/**
* 增加子账号 2025年3月13日17:02:07
*/
String userId1 = data.get("userId").toString();
AccountItemVO accountItemVO = new AccountItemVO();
accountItemVO.setMode(1); // 入账
accountItemVO.setType(AccountItemTypeEnum.PAYMENT_SPLIT.getValue()); // 收入类型 充值 | 分账入账 | 退款入账
accountItemVO.setAccountId(userId1);
accountItemVO.setAccountMoney(money);
accountItemVO.setDescription(remark);
accountItemVO.setOrderId(userId);
accountItemVO.setOrderType("Invite");
iAccountItemService.saveReturnId(accountItemVO);
}
}
}
@Override

View File

@ -0,0 +1,62 @@
package cn.com.tenlion.operator.service.user.invite;
import cn.com.tenlion.operator.dao.user.invite.IUserInviteDao;
import cn.com.tenlion.operator.enums.invite.InviteEnum;
import cn.com.tenlion.operator.util.RandomNumberGenerator;
import cn.com.tenlion.operator.util.pay.PayUtil;
import cn.com.tenlion.projectconfig.util.ProjectConfigUtil;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.util.UUIDUtil;
import ink.wgink.util.date.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* ClassName: UserInviteService
* Description:
* Author: wanggeng
* Date: 2024/8/8 上午11:58
* Version: 1.0
*/
@Service
public class UserInviteService extends DefaultBaseService {
@Autowired
private IUserInviteDao dao;
public Map<String, Object> get(Map<String, Object> params) {
Map<String, Object> data1 = dao.get(params);
return data1;
}
public JSONObject getRegisterCode(String userId) {
JSONObject json = JSONObject.parseObject(ProjectConfigUtil.getText("IndexInvitingNewcomers"));
Double money = json.getDoubleValue("money");
String title = json.getString("title");
Map<String, Object> params = new HashMap<>();
params.put("user_id", userId);
params.put("type", InviteEnum.NEW_USER.getText());
Map<String, Object> data1 = dao.get(params);
if(data1 == null) {
Map<String, Object> data = new HashMap<>();
data.put("userId", userId);
data.put("code", RandomNumberGenerator.generateUniqueRandomNumber());
data.put("type", InviteEnum.NEW_USER.getText());
data.put("creator", userId);
data.put("gmtCreate", DateUtil.getTime());
data.put("inviteId", UUIDUtil.getUUID());
data.put("money", PayUtil.buiderMoney(money));
data.put("remark", title);
data.put("isDelete", "0");
dao.save(data);
}
data1 = dao.get(params);
json.put("code", data1.get("code"));
return json;
}
}

View File

@ -0,0 +1,64 @@
package cn.com.tenlion.operator.util;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
/**
* Cbc
* 2025年2月24日17:24:42
* 随机码生产 Random Generate
*/
public class RandomNumberGenerator {
private static final String CHARACTERS = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"; // 祛除了 容易混淆的 I O
private static final int RANDOM_NUMBER_LENGTH = 6;
private static final Random RANDOM = new Random();
private static final Set<String> GENERATED_NUMBERS = new HashSet<>();
/**
* Generates a unique 8-character long random number string.
*
* @return A unique 8-character long random number string, or null if unable to generate a unique one.
*/
public static String generateUniqueRandomNumber() {
String randomNumber;
do {
randomNumber = generateRandomNumber();
} while (GENERATED_NUMBERS.contains(randomNumber));
GENERATED_NUMBERS.add(randomNumber);
return randomNumber;
}
/**
* Generates a random 8-character long number string.
*
* @return An 8-character long random number string.
*/
private static String generateRandomNumber() {
StringBuilder sb = new StringBuilder(RANDOM_NUMBER_LENGTH);
for (int i = 0; i < RANDOM_NUMBER_LENGTH; i++) {
int index = RANDOM.nextInt(CHARACTERS.length());
sb.append(CHARACTERS.charAt(index));
}
return sb.toString();
}
/**
* Resets the set of generated numbers (for testing purposes).
*/
public static void reset() {
GENERATED_NUMBERS.clear();
}
public static void main(String[] args) {
// Testing the generator
for (int i = 0; i < 100; i++) {
System.out.println(generateUniqueRandomNumber());
}
// Reset for further testing (if needed)
// reset();
}
}

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.com.tenlion.operator.dao.user.invite.IUserInviteDao">
<insert id="save" parameterType="map">
INSERT INTO sys_user_invite (
invite_id,
code,
type,
user_id,
money,
remark,
creator,
gmt_create,
modifier,
gmt_modified,
is_delete
) VALUES (
#{inviteId},
#{code},
#{type},
#{userId},
#{money},
#{remark},
#{creator},
#{gmtCreate},
#{modifier},
#{gmtModified},
#{isDelete}
)
</insert>
<select id="get" parameterType="map" resultType="map">
SELECT
invite_id AS inviteId,
code,
type,
user_id AS userId,
money,
remark,
creator
FROM
sys_user_invite
WHERE
is_delete = 0
<if test="userId != null and userId != ''">
AND
user_id = #{userId}
</if>
<if test="code != null and code != ''">
AND
code = #{code}
</if>
<if test="type != null and type != ''">
AND
type = #{type}
</if>
</select>
</mapper>