package agent import ( "context" "github.com/pkg/errors" "qnc-server/app/user/model" "qnc-server/common/xerr" "qnc-server/pkg/lzkit/lzUtils" "time" "qnc-server/app/user/cmd/api/internal/svc" "qnc-server/app/user/cmd/api/internal/types" "github.com/zeromicro/go-zero/core/logx" ) type ApplyForAgentLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewApplyForAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApplyForAgentLogic { return &ApplyForAgentLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *ApplyForAgentLogic) ApplyForAgent(req *types.AgentApplyReq) (resp *types.AgentApplyResp, err error) { var agentAudit model.AgentAudit agentAudit.Mobile = req.Mobile agentAudit.Region = req.Region agentAudit.WechatId = lzUtils.StringToNullString(req.WechatID) agentAudit.Status = 0 agentAuditInsert, err := l.svcCtx.AgentAuditModel.Insert(l.ctx, nil, &agentAudit) if err != nil { return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "代理申请, 保存代理信息失败: %+v", err) } go func() { // 延迟 10 秒 <-time.After(10 * time.Second) // 查找刚刚插入的数据 agentAuditID, _ := agentAuditInsert.LastInsertId() agentAuditRow, _ := l.svcCtx.AgentAuditModel.FindOne(l.ctx, agentAuditID) l.svcCtx.AgentAuditModel.UpdateWithVersion(l.ctx, nil, agentAuditRow) }() return nil, nil }