新增提现实名认证
This commit is contained in:
@@ -65,6 +65,9 @@ service main {
|
||||
// 下级贡献详情
|
||||
@handler GetAgentSubordinateContributionDetail
|
||||
get /subordinate/contribution/detail (GetAgentSubordinateContributionDetailReq) returns (GetAgentSubordinateContributionDetailResp)
|
||||
|
||||
@handler AgentRealName
|
||||
post /real_name (AgentRealNameReq) returns (AgentRealNameResp)
|
||||
}
|
||||
|
||||
type (
|
||||
@@ -75,8 +78,8 @@ type (
|
||||
level string `json:"level"`
|
||||
region string `json:"region"`
|
||||
mobile string `json:"mobile"`
|
||||
wechatID string `json:"wechat_id"`
|
||||
expiryTime string `json:"expiry_time"`
|
||||
isRealName bool `json:"is_real_name"`
|
||||
}
|
||||
// 查询代理申请状态响应
|
||||
AgentAuditStatusResp {
|
||||
@@ -150,6 +153,16 @@ type (
|
||||
DescendantWithdrawCount int64 `json:"descendant_withdraw_count"` // 下级提现次数
|
||||
DescendantWithdrawAmount float64 `json:"descendant_withdraw_amount"` // 下级提现总额
|
||||
}
|
||||
|
||||
AgentRealNameReq {
|
||||
Name string `json:"name"`
|
||||
IDCard string `json:"id_card"`
|
||||
Mobile string `json:"mobile"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
AgentRealNameResp {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
)
|
||||
|
||||
@server (
|
||||
@@ -331,7 +344,6 @@ type (
|
||||
AgentApplyReq {
|
||||
Region string `json:"region"`
|
||||
Mobile string `json:"mobile"`
|
||||
WechatID string `json:"wechat_id"`
|
||||
Code string `json:"code"`
|
||||
Ancestor string `json:"ancestor,optional"`
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ service main {
|
||||
@handler queryShareDetail
|
||||
get /query/share/:id (QueryShareDetailReq) returns (QueryShareDetailResp)
|
||||
|
||||
@doc "查询示例"
|
||||
@doc "查询示例"
|
||||
@handler queryExample
|
||||
get /query/example (QueryExampleReq) returns (QueryExampleResp)
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"tydata-server/app/user/cmd/api/internal/logic/agent"
|
||||
"tydata-server/app/user/cmd/api/internal/svc"
|
||||
"tydata-server/app/user/cmd/api/internal/types"
|
||||
"tydata-server/common/result"
|
||||
"tydata-server/pkg/lzkit/validator"
|
||||
)
|
||||
|
||||
func AgentRealNameHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AgentRealNameReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
if err := validator.Validate(req); err != nil {
|
||||
result.ParamValidateErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
l := agent.NewAgentRealNameLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AgentRealName(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
||||
@@ -40,6 +40,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/product_config",
|
||||
Handler: agent.GetAgentProductConfigHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/real_name",
|
||||
Handler: agent.AgentRealNameHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/subordinate/contribution/detail",
|
||||
|
||||
99
app/user/cmd/api/internal/logic/agent/agentrealnamelogic.go
Normal file
99
app/user/cmd/api/internal/logic/agent/agentrealnamelogic.go
Normal file
@@ -0,0 +1,99 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"tydata-server/app/user/cmd/api/internal/service"
|
||||
"tydata-server/app/user/cmd/api/internal/svc"
|
||||
"tydata-server/app/user/cmd/api/internal/types"
|
||||
"tydata-server/app/user/model"
|
||||
"tydata-server/common/ctxdata"
|
||||
"tydata-server/common/xerr"
|
||||
"tydata-server/pkg/lzkit/crypto"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
)
|
||||
|
||||
type AgentRealNameLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAgentRealNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AgentRealNameLogic {
|
||||
return &AgentRealNameLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AgentRealNameLogic) AgentRealName(req *types.AgentRealNameReq) (resp *types.AgentRealNameResp, err error) {
|
||||
userID, err := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户ID失败, %v", err)
|
||||
}
|
||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||
encryptedMobile, err := crypto.EncryptMobile(req.Mobile, secretKey)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "代理实名, 加密手机号失败: %v", err)
|
||||
}
|
||||
// 检查手机号是否在一分钟内已发送过验证码
|
||||
redisKey := fmt.Sprintf("%s:%s", "realName", encryptedMobile)
|
||||
cacheCode, err := l.svcCtx.Redis.Get(redisKey)
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("验证码已过期"), "代理实名, 验证码过期: %s", encryptedMobile)
|
||||
}
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "代理实名, 读取验证码redis缓存失败, mobile: %s, err: %+v", encryptedMobile, err)
|
||||
}
|
||||
if cacheCode != req.Code {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("验证码不正确"), "代理实名, 验证码不正确: %s", encryptedMobile)
|
||||
}
|
||||
agent, err := l.svcCtx.AgentModel.FindOneByUserId(l.ctx, userID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取代理信息失败, %v", err)
|
||||
}
|
||||
|
||||
agentRealName, err := l.svcCtx.AgentRealNameModel.FindOneByAgentId(l.ctx, agent.Id)
|
||||
if err != nil && !errors.Is(err, model.ErrNotFound) {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取代理实名信息失败, %v", err)
|
||||
}
|
||||
|
||||
if agentRealName != nil && agentRealName.Status == model.AgentRealNameStatusApproved {
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("代理实名信息已审核通过"), "代理实名信息已审核通过")
|
||||
}
|
||||
// 三要素验证
|
||||
threeVerification := service.ThreeFactorVerificationRequest{
|
||||
Name: req.Name,
|
||||
IDCard: req.IDCard,
|
||||
Mobile: req.Mobile,
|
||||
}
|
||||
verification, err := l.svcCtx.VerificationService.ThreeFactorVerification(threeVerification)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "三要素验证失败: %v", err)
|
||||
}
|
||||
if !verification.Passed {
|
||||
return nil, errors.Wrapf(xerr.NewErrCodeMsg(xerr.SERVER_COMMON_ERROR, verification.Err.Error()), "三要素验证不通过: %v", err)
|
||||
}
|
||||
agentRealName = &model.AgentRealName{
|
||||
AgentId: agent.Id,
|
||||
Status: model.AgentRealNameStatusApproved,
|
||||
Name: req.Name,
|
||||
IdCard: req.IDCard,
|
||||
ApproveTime: sql.NullTime{Time: time.Now(), Valid: true},
|
||||
}
|
||||
_, err = l.svcCtx.AgentRealNameModel.Insert(l.ctx, nil, agentRealName)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "添加代理实名信息失败, %v", err)
|
||||
}
|
||||
|
||||
return &types.AgentRealNameResp{
|
||||
Status: agentRealName.Status,
|
||||
}, nil
|
||||
}
|
||||
@@ -66,7 +66,19 @@ func (l *AgentWithdrawalLogic) AgentWithdrawal(req *types.WithdrawalReq) (*types
|
||||
if err != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询代理信息失败: %v", err)
|
||||
}
|
||||
|
||||
agentRealName, err := l.svcCtx.AgentRealNameModel.FindOneByAgentId(l.ctx, agentModel.Id)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
return errors.Wrapf(xerr.NewErrMsg("您未进行实名认证, 无法提现"), "您未进行实名认证")
|
||||
}
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "查询代理实名信息失败: %v", err)
|
||||
}
|
||||
if agentRealName.Status != model.AgentRealNameStatusApproved {
|
||||
return errors.Wrapf(xerr.NewErrMsg("您的实名认证未通过, 无法提现"), "您的实名认证未通过")
|
||||
}
|
||||
if agentRealName.Name != req.PayeeName {
|
||||
return errors.Wrapf(xerr.NewErrMsg("您的实名认证信息不匹配, 无法提现"), "您的实名认证信息不匹配")
|
||||
}
|
||||
// 查询钱包
|
||||
agentWallet, err := l.svcCtx.AgentWalletModel.FindOneByAgentId(l.ctx, agentModel.Id)
|
||||
if err != nil {
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
jwtx "tydata-server/common/jwt"
|
||||
"tydata-server/common/xerr"
|
||||
"tydata-server/pkg/lzkit/crypto"
|
||||
"tydata-server/pkg/lzkit/lzUtils"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
@@ -108,7 +107,6 @@ func (l *ApplyForAgentLogic) ApplyForAgent(req *types.AgentApplyReq) (resp *type
|
||||
agentAudit.UserId = user.Id
|
||||
agentAudit.Mobile = encryptedMobile
|
||||
agentAudit.Region = req.Region
|
||||
agentAudit.WechatId = lzUtils.StringToNullString(req.WechatID)
|
||||
agentAudit.Status = 1
|
||||
_, insetAgentAuditErr := l.svcCtx.AgentAuditModel.Insert(transCtx, session, &agentAudit)
|
||||
if insetAgentAuditErr != nil {
|
||||
@@ -132,7 +130,6 @@ func (l *ApplyForAgentLogic) ApplyForAgent(req *types.AgentApplyReq) (resp *type
|
||||
agentModel.Region = agentAudit.Region
|
||||
agentModel.LevelName = model.AgentLeveNameNormal
|
||||
agentModel.UserId = agentAudit.UserId
|
||||
agentModel.WechatId = lzUtils.StringToNullString(req.WechatID)
|
||||
agentModelInsert, insertAgentModelErr := l.svcCtx.AgentModel.Insert(transCtx, session, &agentModel)
|
||||
if insertAgentModelErr != nil {
|
||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "代理申请, 新增代理失败: %+v", insertAgentModelErr)
|
||||
|
||||
@@ -6,12 +6,12 @@ import (
|
||||
"tydata-server/common/ctxdata"
|
||||
"tydata-server/common/xerr"
|
||||
"tydata-server/pkg/lzkit/crypto"
|
||||
"tydata-server/pkg/lzkit/lzUtils"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"tydata-server/app/user/cmd/api/internal/svc"
|
||||
"tydata-server/app/user/cmd/api/internal/types"
|
||||
"tydata-server/app/user/model"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -64,6 +64,15 @@ func (l *GetAgentInfoLogic) GetAgentInfo() (resp *types.AgentInfoResp, err error
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取代理信息, 解密手机号失败: %v", err)
|
||||
}
|
||||
|
||||
IsRealName := false
|
||||
agentRealName, err := l.svcCtx.AgentRealNameModel.FindOneByAgentId(l.ctx, agent.Id)
|
||||
if err != nil && !errors.Is(err, model.ErrNotFound) {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取代理实名信息失败, %v", err)
|
||||
}
|
||||
if agentRealName != nil {
|
||||
IsRealName = true
|
||||
}
|
||||
return &types.AgentInfoResp{
|
||||
AgentID: agent.Id,
|
||||
Level: agent.LevelName,
|
||||
@@ -72,6 +81,6 @@ func (l *GetAgentInfoLogic) GetAgentInfo() (resp *types.AgentInfoResp, err error
|
||||
Region: agent.Region,
|
||||
Mobile: agent.Mobile,
|
||||
ExpiryTime: agent.MembershipExpiryTime.Time.Format("2006-01-02 15:04:05"),
|
||||
WechatID: lzUtils.NullStringToString(agent.WechatId),
|
||||
IsRealName: IsRealName,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ type ServiceContext struct {
|
||||
AgentPlatformDeductionModel model.AgentPlatformDeductionModel
|
||||
AgentActiveStatModel model.AgentActiveStatModel
|
||||
AgentWithdrawalModel model.AgentWithdrawalModel
|
||||
AgentRealNameModel model.AgentRealNameModel
|
||||
ExampleModel model.ExampleModel
|
||||
GlobalNotificationsModel model.GlobalNotificationsModel
|
||||
AlipayService *service.AliPayService
|
||||
@@ -104,6 +105,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
agentPlatformDeductionModel := model.NewAgentPlatformDeductionModel(db, c.CacheRedis)
|
||||
agentActiveStatModel := model.NewAgentActiveStatModel(db, c.CacheRedis)
|
||||
agentWithdrawalModel := model.NewAgentWithdrawalModel(db, c.CacheRedis)
|
||||
agentRealNameModel := model.NewAgentRealNameModel(db, c.CacheRedis)
|
||||
exampleModel := model.NewExampleModel(db, c.CacheRedis)
|
||||
|
||||
alipayService := service.NewAliPayService(c)
|
||||
@@ -156,6 +158,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
||||
AgentPlatformDeductionModel: agentPlatformDeductionModel,
|
||||
AgentActiveStatModel: agentActiveStatModel,
|
||||
AgentWithdrawalModel: agentWithdrawalModel,
|
||||
AgentRealNameModel: agentRealNameModel,
|
||||
ExampleModel: exampleModel,
|
||||
UserService: userService,
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ type AgentActivateMembershipResp struct {
|
||||
type AgentApplyReq struct {
|
||||
Region string `json:"region"`
|
||||
Mobile string `json:"mobile"`
|
||||
WechatID string `json:"wechat_id"`
|
||||
Code string `json:"code"`
|
||||
Ancestor string `json:"ancestor,optional"`
|
||||
}
|
||||
@@ -58,8 +57,8 @@ type AgentInfoResp struct {
|
||||
Level string `json:"level"`
|
||||
Region string `json:"region"`
|
||||
Mobile string `json:"mobile"`
|
||||
WechatID string `json:"wechat_id"`
|
||||
ExpiryTime string `json:"expiry_time"`
|
||||
IsRealName bool `json:"is_real_name"`
|
||||
}
|
||||
|
||||
type AgentMembershipProductConfigReq struct {
|
||||
@@ -98,6 +97,17 @@ type AgentProductConfigResp struct {
|
||||
AgentProductConfig []AgentProductConfig
|
||||
}
|
||||
|
||||
type AgentRealNameReq struct {
|
||||
Name string `json:"name"`
|
||||
IDCard string `json:"id_card"`
|
||||
Mobile string `json:"mobile"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type AgentRealNameResp struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type AgentSubordinateContributionDetail struct {
|
||||
ID int64 `json:"id"`
|
||||
CreateTime string `json:"create_time"`
|
||||
|
||||
Reference in New Issue
Block a user