diff --git a/api/consts/option.go b/api/consts/option.go index 3acefa6e..c70abb54 100644 --- a/api/consts/option.go +++ b/api/consts/option.go @@ -93,3 +93,8 @@ const ( MerchantWeixin = 40 //商户方微信 CPAccount = 51 //中金支付电子账户 ) + +const ( + StreamerAuthApproval_OneOffVersion = 0 + StreamerAuthApproval_SeparateVersion = 1 +) diff --git a/api/errcode/errcode.go b/api/errcode/errcode.go index f160f619..15e8480b 100644 --- a/api/errcode/errcode.go +++ b/api/errcode/errcode.go @@ -109,6 +109,8 @@ var ErrCodeMsgMap = map[ErrCode]string{ ErrCodeStreamerAuthApprovalDetailsInviterIsNotAStreamer: "邀请人非主播", ErrCodeStreamerAuthApprovalDetailsNotAStreamerToBe: "该主播尚未通过“网红入驻审核”,请先前往审核", ErrCodeStreamerAuthApprovalDetailsNotInApprovingStatus: "所选完善审批中有项目状态错误,请刷新后重试", + ErrCodeStreamerAuthApprovalOneOffVersionExist: "请勿重复提交入驻申请,详情请联系客服", + ErrCodeStreamerAuthApprovalSeparateVersionExist: "请勿重复提交入驻申请,详情请联系客服", ErrCodeStreamerSrvFail: "主播服务错误", ErrCodeStreamerNotExist: "主播不存在", @@ -388,6 +390,8 @@ const ( ErrCodeStreamerAuthApprovalDetailsInviterIsNotAStreamer ErrCode = -12205 // 女神认证完善审批表邀请人非主播 ErrCodeStreamerAuthApprovalDetailsNotAStreamerToBe ErrCode = -12206 // 女神认证完善审批表申请人非准主播 ErrCodeStreamerAuthApprovalDetailsNotInApprovingStatus ErrCode = -12207 // 女神认证完善审批表非人审中状态 + ErrCodeStreamerAuthApprovalOneOffVersionExist ErrCode = -12208 // 女神认证批表已提交旧表 + ErrCodeStreamerAuthApprovalSeparateVersionExist ErrCode = -12209 // 女神认证批表已提交新表 // Streamer: 13xxx ErrCodeStreamerSrvOk ErrCode = ErrCodeOk diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index cd9cd924..54d27643 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -144,6 +144,7 @@ const ( COLStreamerAuthApprovalHis = "streamer_auth_approval_his" COLStreamerAuthApprovalBasicHis = "streamer_auth_approval_basic_his" COLStreamerAuthApprovalDetailsHis = "streamer_auth_approval_details_his" + COLStreamerAuthApprovalVersion = "streamer_auth_approval_version" DBStreamer = "streamer" COLStreamer = "streamer" @@ -425,6 +426,11 @@ func (m *Mongo) getColStreamerAuthApprovalDetailsHis() *qmgo.Collection { return m.clientMix.Database(DBStreamerAuthApproval).Collection(COLStreamerAuthApprovalDetailsHis) } +// 女神认证审批版本表 +func (m *Mongo) getColStreamerAuthApprovalVersion() *qmgo.Collection { + return m.clientMix.Database(DBStreamerAuthApproval).Collection(COLStreamerAuthApprovalVersion) +} + // 主播表 func (m *Mongo) getColStreamer() *qmgo.Collection { return m.clientMix.Database(DBStreamer).Collection(COLStreamer) @@ -2353,6 +2359,26 @@ func (m *Mongo) CreateBatchStreamerAuthApprovalHis(ctx *gin.Context, streameraut return err } +func (m *Mongo) CreateStreamerAuthApprovalVersion(ctx *gin.Context, streamerauthapprovalversion *dbstruct.StreamerAuthApprovalVersion) error { + col := m.getColStreamerAuthApprovalVersion() + _, err := col.InsertOne(ctx, streamerauthapprovalversion) + return err +} + +func (m *Mongo) GetStreamerAuthApprovalVersion(ctx *gin.Context, id int64) (*dbstruct.StreamerAuthApprovalVersion, error) { + streamerauthapprovalversion := &dbstruct.StreamerAuthApprovalVersion{} + col := m.getColStreamerAuthApprovalVersion() + query := qmgo.M{ + "_id": id, + } + err := col.Find(ctx, query).One(streamerauthapprovalversion) + if err == qmgo.ErrNoSuchDocuments { + err = nil + return nil, err + } + return streamerauthapprovalversion, err +} + // 女神认证入站审批表相关 func (m *Mongo) CreateStreamerAuthApprovalBasic(ctx *gin.Context, streamerauthapprovalbasic *dbstruct.StreamerAuthApprovalBasic) error { col := m.getColStreamerAuthApprovalBasic() diff --git a/app/mix/service/apiservice_business_validation.go b/app/mix/service/apiservice_business_validation.go index bf47206e..556ef672 100644 --- a/app/mix/service/apiservice_business_validation.go +++ b/app/mix/service/apiservice_business_validation.go @@ -429,6 +429,8 @@ func (s *Service) ApiCreateStreamerAuthApprovalBusinessValidate(ctx *gin.Context EnsureMediaIsSuccessfullyUploaded(req.StreamerAuthApproval.Album). EnsureMediaIsSuccessfullyUploaded(req.StreamerAuthApproval.Shorts). EnsureIsOperatingHisOwn(util.DerefInt64(req.StreamerAuthApproval.Mid)). + EnsureStreamerAuthApprovalIsUnique(_DefaultStreamerAuthApproval.OpCreateStreamerAuthApprovalVersion, _DefaultStreamerAuthApproval.GetStreamerAuthApprovalVersion, + consts.StreamerAuthApproval_OneOffVersion, req.BaseRequest.Mid). Validate(). Collect() if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk { @@ -490,6 +492,8 @@ func (s *Service) ApiCreateStreamerAuthApprovalBasicBusinessValidate(ctx *gin.Co EnsureIsNotThisRole(consts.Streamer). EnsureMediaIsSuccessfullyUploaded(req.StreamerAuthApprovalBasic.Avatar). EnsureMediaIsSuccessfullyUploaded(req.StreamerAuthApprovalBasic.AccountShot). + EnsureStreamerAuthApprovalIsUnique(_DefaultStreamerAuthApproval.OpCreateStreamerAuthApprovalVersion, _DefaultStreamerAuthApproval.GetStreamerAuthApprovalVersion, + consts.StreamerAuthApproval_SeparateVersion, req.BaseRequest.Mid). Validate(). Collect() if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk { diff --git a/app/mix/service/business_validator/auth.go b/app/mix/service/business_validator/auth.go index 414c2ccd..1384bb26 100644 --- a/app/mix/service/business_validator/auth.go +++ b/app/mix/service/business_validator/auth.go @@ -737,6 +737,41 @@ func (l *AuthBusinessValidator) EnsureStreamerAuthApprovalBasicCreated(fun func( return l } +func (l *AuthBusinessValidator) EnsureStreamerAuthApprovalIsUnique(createFunc func(*gin.Context, *dbstruct.StreamerAuthApprovalVersion) error, queryFunc func(*gin.Context, int64) (*dbstruct.StreamerAuthApprovalVersion, error), + version int64, mid int64) *AuthBusinessValidator { + l.oplist = append(l.oplist, func() { + streamerauthapprovalversion, err := queryFunc(l.ctx, mid) + if err != nil { + logger.Error("StreamerAuthApprovalVersion Get fail, err: %v", err) + l.ec = errcode.ErrCodeStreamerAuthApprovalSrvFail + return + } + if streamerauthapprovalversion == nil { + err := createFunc(l.ctx, &dbstruct.StreamerAuthApprovalVersion{ + Id: mid, + Version: version, + }) + if err != nil { + logger.Error("StreamerAuthApprovalVersion Create fail, err: %v", err) + l.ec = errcode.ErrCodeStreamerAuthApprovalSrvFail + return + } + return + } + if streamerauthapprovalversion.Version != version { + if streamerauthapprovalversion.Version == consts.StreamerAuthApproval_OneOffVersion { + l.ec = errcode.ErrCodeStreamerAuthApprovalOneOffVersionExist + return + } + if streamerauthapprovalversion.Version == consts.StreamerAuthApproval_SeparateVersion { + l.ec = errcode.ErrCodeStreamerAuthApprovalSeparateVersionExist + return + } + } + }) + return l +} + // 执行校验 func (a *AuthBusinessValidator) Validate() *AuthBusinessValidator { a.BusinessValidateStream.Validate() diff --git a/app/mix/service/logic/streamerauthapproval.go b/app/mix/service/logic/streamerauthapproval.go index d05e5dca..c928aaea 100644 --- a/app/mix/service/logic/streamerauthapproval.go +++ b/app/mix/service/logic/streamerauthapproval.go @@ -154,3 +154,21 @@ func (p *StreamerAuthApproval) GetStreamerAuthApprovalListByIds(ctx *gin.Context } return list, nil } + +func (p *StreamerAuthApproval) OpCreateStreamerAuthApprovalVersion(ctx *gin.Context, version *dbstruct.StreamerAuthApprovalVersion) error { + err := p.store.CreateStreamerAuthApprovalVersion(ctx, version) + if err != nil { + logger.Error("CreateStreamerAuthApprovalVersion fail, err: %v", err) + return err + } + return nil +} + +func (p *StreamerAuthApproval) GetStreamerAuthApprovalVersion(ctx *gin.Context, id int64) (*dbstruct.StreamerAuthApprovalVersion, error) { + version, err := p.store.GetStreamerAuthApprovalVersion(ctx, id) + if err != nil { + logger.Error("GetStreamerAuthApprovalVersion fail, err: %v", err) + return nil, err + } + return version, nil +} diff --git a/dbstruct/streamerauthapproval.go b/dbstruct/streamerauthapproval.go index b1196d77..d292511c 100644 --- a/dbstruct/streamerauthapproval.go +++ b/dbstruct/streamerauthapproval.go @@ -128,3 +128,8 @@ func (p *StreamerAuthApprovalDetails) GetApproveStatus() int64 { } return 0 } + +type StreamerAuthApprovalVersion struct { + Id int64 `json:"id" bson:"_id"` //id,主播的mid + Version int64 `json:"version" bson:"version"` //版本号 +}