新增管理员邀请充值代理功能

This commit is contained in:
tianfeng 2025-12-03 17:48:10 +08:00
parent bce643360f
commit fe55cdb0c7
12 changed files with 476 additions and 1 deletions

View File

@ -222,6 +222,21 @@ public enum OfficialNoticeTypeEnum {
*/
VIOLATION_ADJUST,
/**
* 管理员邀请充值代理.
*/
ADMIN_INVITE_RECHARGE_AGENT,
/**
* 用户同意管理员成为充值代理邀请.
*/
AGREE_ADMIN_INVITE_RECHARGE_AGENT,
/**
* 用户拒绝管理员成为充值代理邀请.
*/
REFUSE_ADMIN_INVITE_RECHARGE_AGENT,
;

View File

@ -247,6 +247,21 @@ public enum TeamErrorCode implements IResponseErrorCode {
* 用户是管理员
*/
USER_IS_A_ADMIN(6055, "This user is a administrator."),
/**
* 用户不是充值代理.
*/
USER_IS_NOT_RECHARGE_AGENT(6056, "User is not a recharge agent"),
/**
* 用户已经是充值代理.
*/
USER_IS_ALREADY_A_RECHARGE_AGENT(6057, "User is already a recharge agent"),
/**
* 用户不是管理员.
*/
USER_IS_NOT_ADMIN(6058, "User is not an administrator"),
;
private final Integer code;

View File

@ -181,6 +181,71 @@ public class TeamBdRestController extends BaseController {
teamBdService.inviteAgentCancel(id);
}
/**
* 管理员邀请充值代理.
*
* @eo.name 管理员邀请充值代理.
* @eo.url /invite-recharge-agent
* @eo.method post
* @eo.request-type json
*/
@PostMapping("/invite-recharge-agent")
public void inviteRechargeAgent(@RequestBody @Validated DbLeaderInviteBdCmd cmd) {
teamBdService.inviteRechargeAgent(cmd);
}
/**
* 获取被管理员邀请消息-邀请充值代理.
*
* @eo.name 获取被管理员邀请消息-邀请充值代理.
* @eo.url /invite-recharge-agent-message
* @eo.method get
* @eo.request-type formdata
*/
@GetMapping("/invite-recharge-agent-message")
public List<BdInviteMessageCO> listInviteRechargeAgentMessage(BdInviteQryCmd cmd) {
return teamBdService.listInviteRechargeAgentMessage(cmd);
}
/**
* 获取邀请充值代理的消息-邀请充值代理.
*
* @eo.name 获取邀请充值代理的消息-邀请充值代理.
* @eo.url /invite-recharge-agent-message-own
* @eo.method get
* @eo.request-type formdata
*/
@GetMapping("/invite-recharge-agent-message-own")
public List<BdInviteMessageCO> listInviteRechargeAgentMessageOwn(BdInviteQryCmd cmd) {
return teamBdService.listInviteRechargeAgentMessageOwn(cmd);
}
/**
* 邀请充值代理-撤销.
*
* @eo.name 邀请充值代理-撤销.
* @eo.url /invite-recharge-agent-cancel/{id}
* @eo.method post
* @eo.request-type formdata
*/
@PostMapping("/invite-recharge-agent-cancel/{id}")
public void inviteRechargeAgentCancel(@PathVariable("id") String id) {
teamBdService.inviteRechargeAgentCancel(id);
}
/**
* 处理邀请-邀请充值代理.
*
* @eo.name 处理邀请-邀请充值代理.
* @eo.url /invite-recharge-agent-message-process
* @eo.method post
* @eo.request-type json
*/
@PostMapping("/invite-recharge-agent-message-process")
public void processInviteRechargeAgentMessage(@RequestBody @Validated DbInviteMessageProcessCmd cmd) {
teamBdService.processAdminInviteRechargeAgentMessage(cmd);
}
/**
* 处理邀请-邀请BD.

View File

@ -0,0 +1,98 @@
package com.red.circle.other.app.command.team;
import com.red.circle.external.inner.endpoint.message.OfficialNoticeClient;
import com.red.circle.external.inner.model.cmd.message.notice.official.NoticeExtTemplateTypeCmd;
import com.red.circle.external.inner.model.enums.message.OfficialNoticeTypeEnum;
import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.framework.core.response.CommonErrorCode;
import com.red.circle.other.app.convertor.user.UserProfileAppConvertor;
import com.red.circle.other.app.dto.cmd.team.DbLeaderInviteBdCmd;
import com.red.circle.other.app.util.OfficialNoticeUtils;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway;
import com.red.circle.other.infra.database.mongo.entity.team.bd.BdInviteAgentMessage;
import com.red.circle.other.infra.database.mongo.entity.team.bd.MessageInviteGroup;
import com.red.circle.other.infra.database.mongo.service.team.bd.BdInviteAgentMessageService;
import com.red.circle.other.infra.database.rds.service.sys.AdministratorService;
import com.red.circle.other.infra.database.rds.service.team.AdminRechargeAgentRelationService;
import com.red.circle.other.inner.asserts.team.TeamErrorCode;
import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import com.red.circle.tool.core.date.TimestampUtils;
import com.red.circle.tool.core.sequence.IdWorkerUtils;
import com.red.circle.wallet.inner.endpoint.freight.FreightGoldClient;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 管理员邀请充值代理.
*
* @author tf
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class AdminInviteRechargeAgentExe {
private final AdministratorService administratorService;
private final UserProfileGateway userProfileGateway;
private final OfficialNoticeClient officialNoticeClient;
private final UserProfileAppConvertor userProfileAppConvertor;
private final BdInviteAgentMessageService bdInviteAgentMessageService;
private final AdminRechargeAgentRelationService adminRechargeAgentRelationService;
private final FreightGoldClient freightGoldClient;
private final UserRegionGateway userRegionGateway;
public void execute(DbLeaderInviteBdCmd cmd) {
// 权限验证必须是管理员
ResponseAssert.isTrue(CommonErrorCode.INSUFFICIENT_PERMISSION,
administratorService.existsAdmin(cmd.requiredReqUserId()));
// 被邀请用户必须是充值代理
ResponseAssert.isTrue(TeamErrorCode.USER_IS_NOT_RECHARGE_AGENT,
ResponseAssert.requiredSuccess(freightGoldClient.checkFreightAgent(cmd.getInviteUserId())));
// 该用户已经被邀请过了
ResponseAssert.isFalse(TeamErrorCode.USER_IS_ALREADY_A_RECHARGE_AGENT,
adminRechargeAgentRelationService.checkRechargeAgent(cmd.getInviteUserId()));
// 验证区域是否一致
Boolean eqRegion = userRegionGateway.checkEqRegion(cmd.requiredReqUserId(),
cmd.getInviteUserId());
ResponseAssert.isTrue(TeamErrorCode.NOT_INVITE_USER_ERROR, eqRegion);
// 消息已发送
ResponseAssert.isFalse(TeamErrorCode.MESSAGE_PROCESSED,
bdInviteAgentMessageService.existsWaitMessage(cmd.requiredReqUserId(),
cmd.getInviteUserId(), MessageInviteGroup.ADMIN_INVITE_RECHARGE_AGENT.name()));
String messageId = IdWorkerUtils.getIdStr();
bdInviteAgentMessageService.add(new BdInviteAgentMessage()
.setId(messageId)
.setSysOrigin(cmd.requireReqSysOrigin())
.setUserId(cmd.requiredReqUserId())
.setInviteUserId(cmd.getInviteUserId())
.setMessage(cmd.getMessage())
.setGroup(MessageInviteGroup.ADMIN_INVITE_RECHARGE_AGENT.name())
.setCreateTime(TimestampUtils.now())
.setUpdateTime(TimestampUtils.now())
.setStatus(0)
.setExpiredTime(TimestampUtils.nowPlusDays(2))
);
UserProfileDTO userProfile = userProfileAppConvertor.toUserProfileDTO(
userProfileGateway.getByUserId(cmd.requiredReqUserId())
);
officialNoticeClient.send(NoticeExtTemplateTypeCmd.builder()
.toAccount(cmd.getInviteUserId())
.noticeType(OfficialNoticeTypeEnum.ADMIN_INVITE_RECHARGE_AGENT)
.templateParam(OfficialNoticeUtils.buildUserProfile(userProfile))
.expand(messageId)
.build()
);
}
}

View File

@ -0,0 +1,76 @@
package com.red.circle.other.app.command.team;
import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.framework.core.response.CommonErrorCode;
import com.red.circle.framework.core.response.ResponseErrorCode;
import com.red.circle.other.app.dto.cmd.team.DbInviteMessageProcessCmd;
import com.red.circle.other.infra.database.mongo.entity.team.bd.BdInviteAgentMessage;
import com.red.circle.other.infra.database.mongo.entity.team.bd.MessageInviteGroup;
import com.red.circle.other.infra.database.mongo.service.team.bd.BdInviteAgentMessageService;
import com.red.circle.other.infra.database.rds.entity.team.AdminRechargeAgentRelation;
import com.red.circle.other.infra.database.rds.service.sys.AdministratorService;
import com.red.circle.other.infra.database.rds.service.team.AdminRechargeAgentRelationService;
import com.red.circle.other.inner.asserts.team.TeamErrorCode;
import com.red.circle.tool.core.sequence.IdWorkerUtils;
import com.red.circle.wallet.inner.endpoint.freight.FreightGoldClient;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 处理管理员邀请充值代理消息.
*
* @author tf
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class AdminInviteRechargeAgentProcessExe {
private final AdministratorService administratorService;
private final BdInviteAgentMessageService bdInviteAgentMessageService;
private final AdminRechargeAgentRelationService adminRechargeAgentRelationService;
private final FreightGoldClient freightGoldClient;
public void execute(DbInviteMessageProcessCmd cmd) {
ResponseAssert.isTrue(ResponseErrorCode.REQUEST_PARAMETER_ERROR, cmd.getStatus() > 0);
BdInviteAgentMessage message = bdInviteAgentMessageService.getById(cmd.getId());
ResponseAssert.notNull(CommonErrorCode.NOT_FOUND_RECORD_INFO, message);
ResponseAssert.isTrue(CommonErrorCode.NOT_FOUND_RECORD_INFO,
Objects.equals(message.getGroup(), MessageInviteGroup.ADMIN_INVITE_RECHARGE_AGENT.name()));
// 被邀请用户必须是充值代理
ResponseAssert.isTrue(TeamErrorCode.USER_IS_NOT_RECHARGE_AGENT,
ResponseAssert.requiredSuccess(freightGoldClient.checkFreightAgent(cmd.requiredReqUserId())));
// 该用户已经被邀请过了
ResponseAssert.isFalse(TeamErrorCode.USER_IS_ALREADY_A_RECHARGE_AGENT,
adminRechargeAgentRelationService.checkRechargeAgent(cmd.requiredReqUserId()));
ResponseAssert.isTrue(CommonErrorCode.INSUFFICIENT_PERMISSION,
Objects.equals(message.getInviteUserId(), cmd.requiredReqUserId()));
ResponseAssert.isTrue(TeamErrorCode.MESSAGE_PROCESSED, Objects.equals(message.getStatus(), 0));
// 验证发起邀请的用户是否是管理员
ResponseAssert.isTrue(TeamErrorCode.USER_IS_NOT_ADMIN,
administratorService.existsAdmin(message.getUserId()));
ResponseAssert.isTrue(CommonErrorCode.OPERATING_FAILURE, bdInviteAgentMessageService.
updateStatus(cmd.getId(), message.getStatus(), cmd.getStatus(),
MessageInviteGroup.ADMIN_INVITE_RECHARGE_AGENT.name()));
if (Objects.equals(cmd.getStatus(), 1)) {
// 创建管理员与充值代理关系
adminRechargeAgentRelationService.add(new AdminRechargeAgentRelation()
.setId(IdWorkerUtils.getId())
.setSysOrigin(cmd.requireReqSysOrigin())
.setAdminUserId(message.getUserId())
.setUserId(cmd.requiredReqUserId())
);
}
}
}

View File

@ -6,6 +6,8 @@ import com.red.circle.framework.dto.PageResult;
import com.red.circle.other.app.command.team.query.*;
import com.red.circle.other.app.command.team.BdAgentInviteExe;
import com.red.circle.other.app.command.team.BdEnterSysExe;
import com.red.circle.other.app.command.team.AdminInviteRechargeAgentExe;
import com.red.circle.other.app.command.team.AdminInviteRechargeAgentProcessExe;
import com.red.circle.other.app.command.team.BdInviteMessageProcessExe;
import com.red.circle.other.app.command.team.BdLeaderInviteBdExe;
import com.red.circle.other.app.command.team.BdLeaderInviteMessageProcessExe;
@ -14,6 +16,7 @@ import com.red.circle.other.app.dto.cmd.team.BdInviteQryCmd;
import com.red.circle.other.app.dto.cmd.team.DbInviteAgentCmd;
import com.red.circle.other.app.dto.cmd.team.DbInviteMessageProcessCmd;
import com.red.circle.other.app.dto.cmd.team.DbLeaderInviteBdCmd;
import com.red.circle.other.infra.database.mongo.entity.team.bd.MessageInviteGroup;
import java.util.List;
import com.red.circle.other.inner.endpoint.team.bd.api.BdTeamInfoClientApi;
@ -44,6 +47,8 @@ public class TeamBdServiceImpl implements TeamBdService {
private final BdInviteMessageProcessExe bdInviteMessageProcessCmdExe;
private final BdLeaderInviteMessageProcessExe bdLeaderInviteMessageProcessCmdExe;
private final BdListQryExe bdListQryExe;
private final AdminInviteRechargeAgentExe adminInviteRechargeAgentExe;
private final AdminInviteRechargeAgentProcessExe adminInviteRechargeAgentProcessExe;
@Override
public String getBdRole(AppExtCommand cmd) {
@ -129,4 +134,31 @@ public class TeamBdServiceImpl implements TeamBdService {
public PageResult<BdPageCO> bdPage(BdTeamPageQryCmd qryCmd) {
return bdListQryExe.pageResult(qryCmd);
}
@Override
public void inviteRechargeAgent(DbLeaderInviteBdCmd cmd) {
adminInviteRechargeAgentExe.execute(cmd);
}
@Override
public List<BdInviteMessageCO> listInviteRechargeAgentMessage(BdInviteQryCmd cmd) {
cmd.setGroup(MessageInviteGroup.ADMIN_INVITE_RECHARGE_AGENT.name());
return bdInviteMessageQryExe.execute(cmd);
}
@Override
public List<BdInviteMessageCO> listInviteRechargeAgentMessageOwn(BdInviteQryCmd cmd) {
cmd.setGroup(MessageInviteGroup.ADMIN_INVITE_RECHARGE_AGENT.name());
return bdInviteMessageQryExe.inviteMessageOwn(cmd);
}
@Override
public void inviteRechargeAgentCancel(String id) {
bdAgentInviteCmdExe.cancel(id);
}
@Override
public void processAdminInviteRechargeAgentMessage(DbInviteMessageProcessCmd cmd) {
adminInviteRechargeAgentProcessExe.execute(cmd);
}
}

View File

@ -106,4 +106,29 @@ public interface TeamBdService {
* @param id
*/
void inviteAgentCancel(String id);
/**
* 管理员邀请充值代理.
*/
void inviteRechargeAgent(DbLeaderInviteBdCmd cmd);
/**
* 获取被管理员邀请消息-邀请充值代理.
*/
List<BdInviteMessageCO> listInviteRechargeAgentMessage(BdInviteQryCmd cmd);
/**
* 获取邀请充值代理的消息-邀请充值代理.
*/
List<BdInviteMessageCO> listInviteRechargeAgentMessageOwn(BdInviteQryCmd cmd);
/**
* 邀请充值代理-撤销.
*/
void inviteRechargeAgentCancel(String id);
/**
* 处理邀请-邀请充值代理.
*/
void processAdminInviteRechargeAgentMessage(DbInviteMessageProcessCmd cmd);
}

View File

@ -25,6 +25,11 @@ public enum MessageInviteGroup {
/**
* agent 邀请主播
*/
AGENT_INVITE_HOST
AGENT_INVITE_HOST,
/**
* 管理员邀请充值代理.
*/
ADMIN_INVITE_RECHARGE_AGENT
}

View File

@ -0,0 +1,13 @@
package com.red.circle.other.infra.database.rds.dao.team;
import com.red.circle.framework.mybatis.dao.BaseDAO;
import com.red.circle.other.infra.database.rds.entity.team.AdminRechargeAgentRelation;
/**
* 管理员充值代理关系DAO.
*
* @author tf
*/
public interface AdminRechargeAgentRelationDAO extends BaseDAO<AdminRechargeAgentRelation> {
}

View File

@ -0,0 +1,57 @@
package com.red.circle.other.infra.database.rds.entity.team;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.time.LocalDateTime;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 管理员充值代理关系表.
*
* @author tf
*/
@Data
@Accessors(chain = true)
@TableName("admin_recharge_agent_relation")
public class AdminRechargeAgentRelation {
/**
* 主键标识.
*/
@TableId("id")
private Long id;
/**
* 来源app.
*/
@TableField("sys_origin")
private String sysOrigin;
/**
* 管理员用户ID.
*/
@TableField("admin_user_id")
private Long adminUserId;
/**
* 充值代理用户ID.
*/
@TableField("user_id")
private Long userId;
/**
* 创建时间.
*/
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 修改时间.
*/
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
}

View File

@ -0,0 +1,36 @@
package com.red.circle.other.infra.database.rds.service.team;
import com.red.circle.framework.mybatis.service.BaseService;
import com.red.circle.other.infra.database.rds.entity.team.AdminRechargeAgentRelation;
/**
* 管理员充值代理关系Service.
*
* @author tf
*/
public interface AdminRechargeAgentRelationService extends BaseService<AdminRechargeAgentRelation> {
/**
* 根据用户ID查询关系.
*
* @param userId 充值代理用户ID
* @return 关系实体
*/
AdminRechargeAgentRelation getByUserId(Long userId);
/**
* 检查用户是否是充值代理.
*
* @param userId 用户ID
* @return true-是充值代理, false-不是
*/
boolean checkRechargeAgent(Long userId);
/**
* 添加关系.
*
* @param relation 关系实体
*/
void add(AdminRechargeAgentRelation relation);
}

View File

@ -0,0 +1,38 @@
package com.red.circle.other.infra.database.rds.service.team.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.red.circle.framework.mybatis.service.impl.BaseServiceImpl;
import com.red.circle.other.infra.database.rds.dao.team.AdminRechargeAgentRelationDAO;
import com.red.circle.other.infra.database.rds.entity.team.AdminRechargeAgentRelation;
import com.red.circle.other.infra.database.rds.service.team.AdminRechargeAgentRelationService;
import org.springframework.stereotype.Service;
/**
* 管理员充值代理关系Service实现.
*
* @author tf
*/
@Service
public class AdminRechargeAgentRelationServiceImpl extends
BaseServiceImpl<AdminRechargeAgentRelationDAO, AdminRechargeAgentRelation> implements
AdminRechargeAgentRelationService {
@Override
public AdminRechargeAgentRelation getByUserId(Long userId) {
return getOne(new LambdaQueryWrapper<AdminRechargeAgentRelation>()
.eq(AdminRechargeAgentRelation::getUserId, userId)
.last("LIMIT 1"));
}
@Override
public boolean checkRechargeAgent(Long userId) {
return count(new LambdaQueryWrapper<AdminRechargeAgentRelation>()
.eq(AdminRechargeAgentRelation::getUserId, userId)) > 0;
}
@Override
public void add(AdminRechargeAgentRelation relation) {
save(relation);
}
}