This commit is contained in:
2026-03-16 14:40:05 +08:00
6 changed files with 150 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package admin_agent
import (
"context"
"encoding/hex"
"ycc-server/app/main/api/internal/svc"
"ycc-server/app/main/api/internal/types"
@@ -79,11 +80,25 @@ func (l *AdminGetAgentListLogic) AdminGetAgentList(req *types.AdminGetAgentListR
// 查询钱包信息
wallet, _ := l.svcCtx.AgentWalletModel.FindOneByAgentId(l.ctx, agent.Id)
// 查询实名认证信息
// 查询实名认证信息(数据库姓名明文、身份证密文,解密后明文返回不脱敏)
realNameInfo, _ := l.svcCtx.AgentRealNameModel.FindOneByAgentId(l.ctx, agent.Id)
isRealName := false
if realNameInfo != nil && realNameInfo.VerifyTime.Valid {
isRealName = true // verify_time不为空表示已通过三要素核验
realName := ""
idCardPlain := "" // 解密后明文返回
if realNameInfo != nil {
if realNameInfo.VerifyTime.Valid {
isRealName = true // verify_time不为空表示已通过三要素核验
}
realName = realNameInfo.Name
if realNameInfo.IdCard != "" {
key, keyErr := hex.DecodeString(l.svcCtx.Config.Encrypt.SecretKey)
if keyErr == nil {
decrypted, err := crypto.DecryptIDCard(realNameInfo.IdCard, key)
if err == nil {
idCardPlain = decrypted
}
}
}
}
wechatId := ""
@@ -116,6 +131,8 @@ func (l *AdminGetAgentListLogic) AdminGetAgentList(req *types.AdminGetAgentListR
FrozenBalance: 0,
WithdrawnAmount: 0,
IsRealName: isRealName,
RealName: realName,
IdCardPlain: idCardPlain,
CreateTime: agent.CreateTime.Format("2006-01-02 15:04:05"),
}

View File

@@ -0,0 +1,69 @@
package admin_agent
import (
"context"
"regexp"
"ycc-server/app/main/model"
"ycc-server/common/xerr"
"ycc-server/pkg/lzkit/crypto"
"github.com/pkg/errors"
"ycc-server/app/main/api/internal/svc"
"ycc-server/app/main/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
// 手机号正则11 位大陆手机号
var mobileRegexp = regexp.MustCompile(`^1[3-9]\d{9}$`)
type AdminUpdateAgentMobileLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAdminUpdateAgentMobileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminUpdateAgentMobileLogic {
return &AdminUpdateAgentMobileLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AdminUpdateAgentMobileLogic) AdminUpdateAgentMobile(req *types.AdminUpdateAgentMobileReq) (resp *types.AdminUpdateAgentMobileResp, err error) {
// 1. 校验手机号格式
if req.Mobile == "" {
return nil, errors.Wrapf(xerr.NewErrMsg("手机号不能为空"), "")
}
if !mobileRegexp.MatchString(req.Mobile) {
return nil, errors.Wrapf(xerr.NewErrMsg("手机号格式不正确"), "")
}
// 2. 查询代理
agent, err := l.svcCtx.AgentModel.FindOne(l.ctx, req.AgentId)
if err != nil {
if errors.Is(err, model.ErrNotFound) {
return nil, errors.Wrapf(xerr.NewErrMsg("代理不存在"), "")
}
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询代理失败, %v", err)
}
// 3. 加密新手机号
encryptedMobile, err := crypto.EncryptMobile(req.Mobile, l.svcCtx.Config.Encrypt.SecretKey)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "加密手机号失败, %v", err)
}
// 4. 更新代理手机号
agent.Mobile = encryptedMobile
if err := l.svcCtx.AgentModel.UpdateWithVersion(l.ctx, nil, agent); err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新手机号失败, %v", err)
}
return &types.AdminUpdateAgentMobileResp{
Success: true,
}, nil
}