804 lines
29 KiB
Go
804 lines
29 KiB
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"service/api/consts"
|
|
"service/api/errcode"
|
|
accountproto "service/api/proto/account/proto"
|
|
accountrelationproto "service/api/proto/accountrelation/proto"
|
|
loginproto "service/api/proto/login/proto"
|
|
momentproto "service/api/proto/moment/proto"
|
|
streamerproto "service/api/proto/streamer/proto"
|
|
streamerauthapprovalproto "service/api/proto/streamerauthapproval/proto"
|
|
streamerauthapprovalbasicproto "service/api/proto/streamerauthapprovalbasic/proto"
|
|
streamerauthapprovaldetailsproto "service/api/proto/streamerauthapprovaldetails/proto"
|
|
vasproto "service/api/proto/vas/proto"
|
|
vericodeproto "service/api/proto/vericode/proto"
|
|
zone_collaborator_proto "service/api/proto/zone_collaborator/proto"
|
|
zone_third_partner_proto "service/api/proto/zone_third_partner/proto"
|
|
zonemomentproto "service/api/proto/zonemoment/proto"
|
|
businessvalidator "service/app/mix/service/business_validator"
|
|
"service/bizcommon/util"
|
|
"service/dbstruct"
|
|
"service/library/logger"
|
|
"service/library/mycrypto"
|
|
|
|
goproto "google.golang.org/protobuf/proto"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// 发送验证码
|
|
func (s *Service) ApiSendVeriCodeBusinessValidate(ctx *gin.Context, req *vericodeproto.ApiSendReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
if req.Did == "" {
|
|
logger.Info("H5 send : %v", req.MobilePhone)
|
|
req.Did = mycrypto.CryptoServiceInstance().SHA256.Encrypt([]byte(req.MobilePhone))
|
|
}
|
|
|
|
resultList := businessvalidator.NewLoginBusinessValidator(ctx, req).
|
|
QueryVeriCodeSendTimes(_DefaultVeriCodeSendTimes.OpGetAndUpdate, req.Did).
|
|
EnsureVeriCodeSendTimesNotReachedDailyUpperbound().
|
|
Validate().
|
|
Collect()
|
|
ec, _ = resultList[0].(errcode.ErrCode)
|
|
if ec != errcode.ErrCodeLoginSrvOk {
|
|
logger.Error("ApiSendVeriCodeBusinessValidate business validation failed!")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 密码登录
|
|
func (s *Service) ApiLoginByPswdBusinessValidate(ctx *gin.Context, req *loginproto.ApiLoginByPswdReq) (login *dbstruct.Login, account *dbstruct.Account, ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
req.CalcPhoneHash() //计算手机号哈希
|
|
resultList := businessvalidator.NewLoginBusinessValidator(ctx, req).
|
|
QueryLogin(_DefaultLogin.OpListByPhoneHash).
|
|
EnsureLoginExist().
|
|
EnsureLoginAcctEnabled().
|
|
EnsureLoginAcctNotLocked().
|
|
EnsureLoginAcctNotBanned().
|
|
EnsurePasswordIsCorrect().
|
|
QueryAccount(_DefaultAccount.OpListByMid).
|
|
EnsureAccountExist().
|
|
Validate().
|
|
Collect()
|
|
ec, _ = resultList[0].(errcode.ErrCode)
|
|
|
|
// 2.密码错误处理
|
|
if ec == errcode.ErrCodeLoginWrongPswd {
|
|
login, _ := resultList[1].(*dbstruct.Login)
|
|
if err := _DefaultLogin.OpHandleWrongPswd(ctx, login); err != nil {
|
|
logger.Error("OpHandleWrongPswd failed, err : %v", err)
|
|
}
|
|
}
|
|
|
|
// 3.验证失败则返回
|
|
if ec != errcode.ErrCodeLoginSrvOk {
|
|
logger.Error("ApiLoginByPswd business validation failed!")
|
|
return
|
|
}
|
|
|
|
// 4.获取业务数据
|
|
login, _ = resultList[1].(*dbstruct.Login)
|
|
account, _ = resultList[2].(*dbstruct.Account)
|
|
return
|
|
}
|
|
|
|
// 验证码登录
|
|
func (s *Service) ApiLoginByVeriCodeBusinessValidate(ctx *gin.Context, req *loginproto.ApiLoginByVeriCodeReq) (login *dbstruct.Login, account *dbstruct.Account, vericode *dbstruct.VeriCode, ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
req.CalcPhoneHash() //计算手机号哈希
|
|
resultList := businessvalidator.NewLoginBusinessValidator(ctx, req).
|
|
QueryVeriCode(_DefaultVeriCode.OpListByPhoneHash).
|
|
EnsureVeriCodeExist().
|
|
EnsureVeriCodeIsCorrect().
|
|
EnsureVeriCodeIsValid().
|
|
QueryLogin(_DefaultLogin.OpListByPhoneHash).
|
|
EnsureLoginExist().
|
|
//EnsureLoginAcctNotLocked(). //验证码登录不校验是否爆破登录
|
|
EnsureLoginAcctNotBanned().
|
|
QueryAccount(_DefaultAccount.OpListByMid).
|
|
EnsureAccountExist().
|
|
Validate().
|
|
Collect()
|
|
ec, _ = resultList[0].(errcode.ErrCode)
|
|
|
|
// 2.如果错误码是登录信息不存在,则判断为首次登录,业务逻辑将创建用户信息
|
|
if ec == errcode.ErrCodeLoginNotExist {
|
|
vericode, _ = resultList[3].(*dbstruct.VeriCode)
|
|
return
|
|
} else if ec == errcode.ErrCodeLoginSrvOk {
|
|
login, _ = resultList[1].(*dbstruct.Login)
|
|
account, _ = resultList[2].(*dbstruct.Account)
|
|
vericode, _ = resultList[3].(*dbstruct.VeriCode)
|
|
} else {
|
|
logger.Error("ApiLoginByVeriCode business validation failed!")
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
// 登录后第一次设置密码
|
|
func (s *Service) ApiSetPasswordBusinessValidate(ctx *gin.Context, req *loginproto.ApiSetPswdReq) (login *dbstruct.Login, account *dbstruct.Account, ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
req.CalcPhoneHash() //计算手机号哈希
|
|
resultList := businessvalidator.NewLoginBusinessValidator(ctx, req).
|
|
QueryLogin(_DefaultLogin.OpListByPhoneHash).
|
|
EnsureLoginExist().
|
|
EnsureLoginAcctNotLocked().
|
|
EnsureLoginAcctNotBanned().
|
|
QueryAccount(_DefaultAccount.OpListByMid).
|
|
EnsureAccountExist().
|
|
Validate().
|
|
Collect()
|
|
|
|
// 2.校验结果
|
|
ec, _ = resultList[0].(errcode.ErrCode)
|
|
if ec != errcode.ErrCodeLoginSrvOk {
|
|
logger.Error("ApiSetPassword business validation failed")
|
|
return
|
|
}
|
|
|
|
login, _ = resultList[1].(*dbstruct.Login)
|
|
account, _ = resultList[2].(*dbstruct.Account)
|
|
return
|
|
}
|
|
|
|
// 重置密码
|
|
func (s *Service) ApiResetPasswordBusinessValidate(ctx *gin.Context, req *loginproto.ApiResetPswdReq) (login *dbstruct.Login, account *dbstruct.Account, vericode *dbstruct.VeriCode, ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
req.CalcPhoneHash() //计算手机号哈希
|
|
resultList := businessvalidator.NewLoginBusinessValidator(ctx, req).
|
|
QueryVeriCode(_DefaultVeriCode.OpListByPhoneHash).
|
|
EnsureVeriCodeExist().
|
|
EnsureVeriCodeIsCorrect().
|
|
EnsureVeriCodeIsValid().
|
|
QueryLogin(_DefaultLogin.OpListByPhoneHash).
|
|
EnsureLoginExist().
|
|
EnsureLoginAcctEnabled().
|
|
EnsureLoginAcctNotBanned().
|
|
EnsureNewPasswordIsChanged().
|
|
QueryAccount(_DefaultAccount.OpListByMid).
|
|
EnsureAccountExist().
|
|
Validate().
|
|
Collect()
|
|
|
|
// 2.校验结果
|
|
ec, _ = resultList[0].(errcode.ErrCode)
|
|
if ec != errcode.ErrCodeLoginSrvOk {
|
|
logger.Error("ApiResetPassword business validation failed")
|
|
return
|
|
}
|
|
|
|
login, _ = resultList[1].(*dbstruct.Login)
|
|
account, _ = resultList[2].(*dbstruct.Account)
|
|
vericode, _ = resultList[3].(*dbstruct.VeriCode)
|
|
return
|
|
}
|
|
|
|
// 更新密码
|
|
func (s *Service) ApiUpdatePasswordBusinessValidate(ctx *gin.Context, req *loginproto.ApiUpdatePswdReq) (login *dbstruct.Login, account *dbstruct.Account, vericode *dbstruct.VeriCode, ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
req.CalcPhoneHash() //计算手机号哈希
|
|
resultList := businessvalidator.NewLoginBusinessValidator(ctx, req).
|
|
QueryVeriCode(_DefaultVeriCode.OpListByPhoneHash).
|
|
EnsureVeriCodeExist().
|
|
EnsureVeriCodeIsCorrect().
|
|
EnsureVeriCodeIsValid().
|
|
QueryLogin(_DefaultLogin.OpListByPhoneHash).
|
|
EnsureLoginExist().
|
|
EnsureLoginAcctEnabled().
|
|
EnsureLoginAcctNotLocked().
|
|
EnsureLoginAcctNotBanned().
|
|
EnsureOldPasswordIsCorrect().
|
|
EnsureNewPasswordIsChanged().
|
|
QueryAccount(_DefaultAccount.OpListByMid).
|
|
EnsureAccountExist().
|
|
Validate().
|
|
Collect()
|
|
|
|
// 2.校验结果
|
|
ec, _ = resultList[0].(errcode.ErrCode)
|
|
if ec != errcode.ErrCodeLoginSrvOk {
|
|
logger.Error("ApiUpdatePassword business validation failed")
|
|
return
|
|
}
|
|
|
|
login, _ = resultList[1].(*dbstruct.Login)
|
|
account, _ = resultList[2].(*dbstruct.Account)
|
|
vericode, _ = resultList[3].(*dbstruct.VeriCode)
|
|
return
|
|
}
|
|
|
|
// Account
|
|
func (s *Service) ApiUpdateAccountBusinessValidate(ctx *gin.Context, req *accountproto.ApiUpdateReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureMediaIsSuccessfullyUploaded(req.Account.Avatar).
|
|
EnsureIsOperatingHisOwn(util.DerefInt64(req.Account.Mid)).
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiUpdateAccount business validation failed")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiGetAccountListByMidBusinessValidate(ctx *gin.Context, req *accountproto.ApiListByMidReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureIsOperatingHisOwn(util.DerefInt64(req.Mid)).
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiGetAccountListByMid business validation failed")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiAccountExpIncBusinessValidate(ctx *gin.Context, req *accountproto.ApiExpIncReq) (account *dbstruct.Account, ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureIsOperatingHisOwn(util.DerefInt64(req.Mid)).
|
|
QueryAccount(_DefaultAccount.OpListByMid).
|
|
EnsureAccountExist().
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiAccountExpInc business validation failed")
|
|
return
|
|
}
|
|
|
|
account, _ = result[1].(*dbstruct.Account)
|
|
|
|
return
|
|
}
|
|
|
|
// AccountRelation
|
|
func (s *Service) ApiCreateAccountRelationBusinessValidate(ctx *gin.Context, req *accountrelationproto.ApiCreateReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
validator := businessvalidator.NewAuthBusinessValidator(ctx, req)
|
|
result := validator.
|
|
ForAccountRelations(req.AccountRelations,
|
|
validator.EnsureAccountRelationsAreOperatedByHisOwn, //对己操作
|
|
validator.EnsureAccountRelationsAreNotReflexive, //非自反
|
|
validator.EnsureAccountRelationsAreCorrectlyMapped). //数组对能够映射
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiCreateAccountRelation business validation failed")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiDeleteAccountRelationBusinessValidate(ctx *gin.Context, req *accountrelationproto.ApiDeleteReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
validator := businessvalidator.NewAuthBusinessValidator(ctx, req)
|
|
result := validator.
|
|
ForAccountRelations(req.Sentences,
|
|
validator.EnsureAccountRelationsAreOperatedByHisOwn, //对己操作
|
|
validator.EnsureAccountRelationsAreCorrectlyMapped). //数组对能够映射
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiDeleteAccountRelation business validation failed")
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiGetFollowAccountRelationListBusinessValidate(ctx *gin.Context, req *accountrelationproto.ApiListReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureIsOperatingHisOwn(util.DerefInt64(req.Mid)).
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiGetFollowAccountRelationList business validation failed")
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiGetIsFollowedAccountRelationListBusinessValidate(ctx *gin.Context, req *accountrelationproto.ApiListReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureIsOperatingHisOwn(util.DerefInt64(req.Mid)).
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiGetIsFollowedAccountRelationList business validation failed")
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiGetFriendAccountRelationListBusinessValidate(ctx *gin.Context, req *accountrelationproto.ApiListReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureIsOperatingHisOwn(util.DerefInt64(req.Mid)).
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiGetFriendAccountRelationList business validation failed")
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiGetIgnoreAccountRelationListBusinessValidate(ctx *gin.Context, req *accountrelationproto.ApiListReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureIsOperatingHisOwn(util.DerefInt64(req.Mid)).
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiGetIgnoreAccountRelationList business validation failed")
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiGetAbleToAccessWeixinOfAccountRelationListBusinessValidate(ctx *gin.Context, req *accountrelationproto.ApiListReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureIsOperatingHisOwn(util.DerefInt64(req.Mid)).
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiGetAbleToAccessWeixinOfAccountRelationList business validation failed")
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiGetAccountRelationCountBusinessValidate(ctx *gin.Context, req *accountrelationproto.ApiCountReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureIsOperatingHisOwn(util.DerefInt64(req.Mid)).
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiGetAccountRelationCount business validation failed")
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiGetAccountRelationBySentenceBusinessValidate(ctx *gin.Context, req *accountrelationproto.ApiListBySentenceReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.业务校验
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureIsOperatingHisOwn(util.DerefInt64(req.SubMid)).
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiGetAccountRelationCount business validation failed")
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiCreateStreamerAuthApprovalBusinessValidate(ctx *gin.Context, req *streamerauthapprovalproto.ApiCreateReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeStreamerAuthApprovalSrvOk
|
|
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
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 {
|
|
logger.Error("ApiGetAccountRelationCount business validation failed")
|
|
return
|
|
}
|
|
|
|
inviters := util.DerefInt64Slice(req.Inviters)
|
|
if len(inviters) > 0 {
|
|
account, _ := _DefaultAccount.OpListByUserId(ctx, &accountproto.OpListByUserIdReq{
|
|
UserId: goproto.Int64(inviters[0]),
|
|
})
|
|
if account == nil {
|
|
return errcode.ErrCodeStreamerAuthApprovalInviterNotExist
|
|
}
|
|
if util.DerefInt64(account.Role) != consts.Streamer {
|
|
return errcode.ErrCodeStreamerAuthApprovalInviterIsNotAStreamer
|
|
}
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiDeleteStreamerAuthApprovalBusinessValidate(ctx *gin.Context, req *streamerauthapprovalproto.ApiDeleteReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeStreamerAuthApprovalSrvOk
|
|
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureIsOperatingHisOwn(util.DerefInt64(req.Mid)).
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiGetAccountRelationCount business validation failed")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiGetStreamerAuthApprovalListBusinessValidate(ctx *gin.Context, req *streamerauthapprovalproto.ApiListReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeStreamerAuthApprovalSrvOk
|
|
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureIsOperatingHisOwn(util.DerefInt64(req.Mid)).
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiGetAccountRelationCount business validation failed")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiCreateStreamerAuthApprovalBasicBusinessValidate(ctx *gin.Context, req *streamerauthapprovalbasicproto.ApiCreateReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeStreamerAuthApprovalSrvOk
|
|
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
QueryAccount(_DefaultAccount.OpListByMid).
|
|
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 {
|
|
logger.Error("ApiGetAccountRelationCount business validation failed")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiCreateStreamerAuthApprovalDetailsBusinessValidate(ctx *gin.Context, req *streamerauthapprovaldetailsproto.ApiCreateReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeStreamerAuthApprovalSrvOk
|
|
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
QueryAccount(_DefaultAccount.OpListByMid).
|
|
EnsureIsNotThisRole(consts.Streamer).
|
|
EnsureMediaIsSuccessfullyUploaded(req.StreamerAuthApprovalDetails.Cover).
|
|
EnsureMediaIsSuccessfullyUploaded(req.StreamerAuthApprovalDetails.Shorts).
|
|
EnsureMediaIsSuccessfullyUploaded(req.StreamerAuthApprovalDetails.Album).
|
|
EnsureStreamerAuthApprovalBasicCreated(func(ctx *gin.Context, i int64) (*dbstruct.StreamerAuthApprovalBasic, error) {
|
|
return _DefaultStreamerAuthApprovalBasic.OpListByMid(ctx, &streamerauthapprovalbasicproto.OpListByMidReq{
|
|
BaseRequest: req.BaseRequest,
|
|
Uid: goproto.Int64(req.BaseRequest.Mid),
|
|
})
|
|
}, req.BaseRequest.Mid).
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiGetAccountRelationCount business validation failed")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiUpdateStreamerBusinessValidate(ctx *gin.Context, req *streamerproto.ApiUpdateReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeStreamerSrvOk
|
|
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureMediaIsSuccessfullyUploaded(req.Streamer.Album).
|
|
EnsureMediaIsSuccessfullyUploaded(req.Streamer.Shorts).
|
|
EnsureIsOperatingHisOwn(util.DerefInt64(req.Streamer.Mid)).
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiGetAccountRelationCount business validation failed")
|
|
return
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
func (s *Service) ApiGetStreamerListByMidBusinessValidate(ctx *gin.Context, req *streamerproto.ApiListByMidReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeStreamerSrvOk
|
|
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureIsOperatingHisOwn(util.DerefInt64(req.Mid)).
|
|
Validate().
|
|
Collect()
|
|
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiGetAccountRelationCount business validation failed")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiGetStreamerWxIdBusinessValidate(ctx *gin.Context, req *streamerproto.ApiListStreamerWxIdReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeStreamerSrvOk
|
|
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
QueryAccountRelation(consts.AbleToAccessWeixinOf, util.DerefInt64(req.Mid), _DefaultAccountRelation.OpListBySentence).
|
|
EnsureAccountRelationExist().
|
|
Validate().
|
|
Collect()
|
|
ec = result[0].(errcode.ErrCode)
|
|
if ec == errcode.ErrCodeAccountRelationNotExist {
|
|
logger.Error("Insufficient authority: %v has not acquired the privilege to access %v's weixin", req.BaseRequest.Mid, util.DerefInt64(req.Mid))
|
|
return errcode.ErrCodeAccountRelationSubMidUnableToAccessWxIdOfObjMid
|
|
}
|
|
if ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiGetAccountRelationCount business validation failed")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiCreateMomentBusinessValidate(ctx *gin.Context, req *momentproto.ApiCreateReq) (ec errcode.ErrCode, accountpunishment *dbstruct.AccountPunishment, maxDailyMomentCreateTimes int) {
|
|
ec = errcode.ErrCodeMomentSrvOk
|
|
|
|
resultList := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
QueryAccount(_DefaultAccount.OpListByMid).
|
|
EnsureAccountExist().
|
|
EnsureIsThisRole(consts.Streamer).
|
|
EnsureVideoIsUnique(req.Moment.MediaComp).
|
|
EnsureMediaIsSuccessfullyUploaded(req.Moment.MediaComp).
|
|
EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, consts.AccountPunishment_BlockFromCreatingMoment, _DefaultAccountPunishment.OpListByMidAndType).
|
|
QueryMomentCreateTimes(_DefaultMomentCreateTimes.OpGetAndUpdate, req.GetBaseRequest().Mid).
|
|
EnsureMomentCreateTimesNotReachedDailyUpperbound().
|
|
Validate().
|
|
Collect()
|
|
ec, _ = resultList[0].(errcode.ErrCode)
|
|
accountpunishment, _ = resultList[3].(*dbstruct.AccountPunishment)
|
|
maxDailyMomentCreateTimes, _ = resultList[4].(int)
|
|
if ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiCreateMomentBusinessValidate business validation failed!")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiUpdateMomentBusinessValidate(ctx *gin.Context, req *momentproto.ApiUpdateReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeMomentSrvOk
|
|
|
|
resultList := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
QueryAccount(_DefaultAccount.OpListByMid).
|
|
EnsureAccountExist().
|
|
EnsureIsThisRole(consts.Streamer).
|
|
EnsureVideoIsUnique(req.Moment.MediaComp).
|
|
EnsureMediaIsSuccessfullyUploaded(req.Moment.MediaComp).
|
|
Validate().
|
|
Collect()
|
|
ec, _ = resultList[0].(errcode.ErrCode)
|
|
if ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiUpdateMomentBusinessValidate business validation failed!")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiCreateZoneMomentBusinessValidate(ctx *gin.Context, req *zonemomentproto.ApiCreateReq) (ec errcode.ErrCode, accountpunishment *dbstruct.AccountPunishment, maxZoneMomentCreateTimes int) {
|
|
ec = errcode.ErrCodeMomentSrvOk
|
|
|
|
pType := int64(0)
|
|
mediaVisibleRange := int64(0)
|
|
switch req.ZoneMoment.GetCType() {
|
|
case consts.ZoneMomentCType_Free:
|
|
pType = consts.AccountPunishment_BlockFromCreatingFreeZoneMoment
|
|
case consts.ZoneMomentCType_Paid:
|
|
pType = consts.AccountPunishment_BlockFromCreatingPaidZoneMoment
|
|
mediaVisibleRange = req.ZoneMoment.GetMediaVisibleRange()
|
|
}
|
|
|
|
resultList := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
QueryAccount(_DefaultAccount.OpListByMid).
|
|
EnsureAccountExist().
|
|
EnsureIsThisRole(consts.Streamer).
|
|
EnsureVideoIsUnique(req.ZoneMoment.MediaComp).
|
|
EnsureMediaIsSuccessfullyUploaded(req.ZoneMoment.MediaComp).
|
|
EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, consts.AccountPunishment_BlockFromCreatingZoneMoment, _DefaultAccountPunishment.OpListByMidAndType).
|
|
EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, pType, _DefaultAccountPunishment.OpListByMidAndType).
|
|
EnsureZoneMomentImagesEnoughForEncryption(req.ZoneMoment.GetMType(), req.ZoneMoment.MediaComp, mediaVisibleRange).
|
|
EnsureAmongZoneMomentsPaidItemsLessThanFreeItems(_DefaultZoneMoment.OpCountByMidAndCType, req.GetBaseRequest().Mid, req.ZoneMoment.GetCType()).
|
|
EnsureZoneMomentCreateTimesNotReachedDailyUpperbound(_DefaultZoneMomentCreateTimes.OpGetAndUpdate, req.GetBaseRequest().Mid, req.ZoneMoment.GetCType()).
|
|
Validate().
|
|
Collect()
|
|
ec, _ = resultList[0].(errcode.ErrCode)
|
|
accountpunishment, _ = resultList[3].(*dbstruct.AccountPunishment)
|
|
maxZoneMomentCreateTimes, _ = resultList[5].(int)
|
|
if ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiCreateZoneMomentBusinessValidate business validation failed!")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiUpdateZoneMomentBusinessValidate(ctx *gin.Context, req *zonemomentproto.ApiUpdateReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeMomentSrvOk
|
|
|
|
mediaVisibleRange := int64(0)
|
|
switch req.ZoneMoment.GetCType() {
|
|
case consts.ZoneMomentCType_Paid:
|
|
mediaVisibleRange = req.ZoneMoment.GetMediaVisibleRange()
|
|
}
|
|
|
|
resultList := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
QueryAccount(_DefaultAccount.OpListByMid).
|
|
EnsureAccountExist().
|
|
EnsureIsThisRole(consts.Streamer).
|
|
EnsureVideoIsUnique(req.ZoneMoment.MediaComp).
|
|
EnsureMediaIsSuccessfullyUploaded(req.ZoneMoment.MediaComp).
|
|
EnsureZoneMomentImagesEnoughForEncryption(req.ZoneMoment.GetMType(), req.ZoneMoment.MediaComp, mediaVisibleRange).
|
|
Validate().
|
|
Collect()
|
|
ec, _ = resultList[0].(errcode.ErrCode)
|
|
if ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiUpdateZoneMomentBusinessValidate business validation failed!")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 代运营创建验证码
|
|
func (s *Service) ApiCreateZoneThirdPartnerBusinessValidate(ctx *gin.Context, req *zone_third_partner_proto.ApiCreateReq) (vericode *dbstruct.VeriCode, ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeLoginSrvOk
|
|
|
|
// 1.登录业务校验
|
|
req.CalcPhoneHash() //计算手机号哈希
|
|
resultList := businessvalidator.NewLoginBusinessValidator(ctx, req).
|
|
QueryVeriCode(_DefaultVeriCode.OpListByPhoneHash).
|
|
EnsureVeriCodeExist().
|
|
EnsureVeriCodeIsCorrect().
|
|
EnsureVeriCodeIsValid().
|
|
Validate().
|
|
Collect()
|
|
ec, _ = resultList[0].(errcode.ErrCode)
|
|
vericode, _ = resultList[3].(*dbstruct.VeriCode)
|
|
|
|
// 2.错误信息
|
|
if ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiCreateZoneThirdPartner business validation failed!")
|
|
return
|
|
}
|
|
|
|
// 3.鉴权校验
|
|
resultList = businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureIsNotOperatingHisOwn(util.DerefInt64(req.ThirdPartnerMid)).
|
|
EnsureZoneThirdPartnerSharingRatioIsNotTooLarge(req.ZoneThirdPartner.GetSharingRatio()).
|
|
Validate().
|
|
Collect()
|
|
ec, _ = resultList[0].(errcode.ErrCode)
|
|
// 4.错误信息
|
|
if ec == errcode.ErrCodeOperationToSelfIsNotPermitted {
|
|
ec = errcode.ErrCodeZoneThirdPartnerWrongThirdPartner
|
|
}
|
|
if ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiCreateZoneThirdPartner business validation failed!")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiCreateZoneCollaboratorBusinessValidate(ctx *gin.Context, req *zone_collaborator_proto.ApiCreateReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeZoneCollaboratorSrvOk
|
|
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
QueryZoneThirdPartnerByZid(_DefaultZoneThirdPartner.GetZoneThirdPartnerByZid, util.DerefInt64(req.Zid)).
|
|
EnsureZoneThirdPartnerExist().
|
|
EnsureZoneCollaboratorCreaterIsZoneThirdPartner(req.GetBaseRequest().Mid).
|
|
EnsureIsNotOperatingHisOwn(util.DerefInt64(req.CollaboratorMid)).
|
|
EnsureZoneCollaboratorIsNotZoneOwner(_DefaultZone.GetByMid, util.DerefInt64(req.CollaboratorMid)).
|
|
EnsureZtpSharingRatioIsEnoughAfterAddingACollab(_DefaultZoneThirdPartner.GetZoneThirdPartnerByZid, func(ctx *gin.Context, zid int64) ([]*dbstruct.ZoneCollaborator, error) {
|
|
return _DefaultZoneCollaborator.OpList(ctx, &zone_collaborator_proto.OpListReq{
|
|
Zid: goproto.Int64(zid),
|
|
})
|
|
}, req.ZoneCollaborator.GetZid(), req.ZoneCollaborator.GetSharingRatio()).
|
|
Validate().
|
|
Collect()
|
|
ec = result[0].(errcode.ErrCode)
|
|
if ec == errcode.ErrCodeOperationToSelfIsNotPermitted {
|
|
ec = errcode.ErrCodeZoneCollaboratorWrongCollaborator
|
|
}
|
|
if ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiCreateZoneCollaborator business validation failed")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiUpdateZoneCollaboratorBusinessValidate(ctx *gin.Context, req *zone_collaborator_proto.ApiUpdateReq) (ec errcode.ErrCode) {
|
|
ec = errcode.ErrCodeZoneCollaboratorSrvOk
|
|
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
QueryZoneThirdPartnerByZid(_DefaultZoneThirdPartner.GetZoneThirdPartnerByZid, util.DerefInt64(req.Zid)).
|
|
EnsureZoneThirdPartnerExist().
|
|
EnsureZoneCollaboratorCreaterIsZoneThirdPartner(req.GetBaseRequest().Mid).
|
|
EnsureIsNotOperatingHisOwn(util.DerefInt64(req.CollaboratorMid)).
|
|
EnsureZoneCollaboratorIsNotZoneOwner(_DefaultZone.GetByMid, util.DerefInt64(req.CollaboratorMid)).
|
|
EnsureZtpSharingRatioIsEnoughAfterUpdatingACollab(_DefaultZoneThirdPartner.GetZoneThirdPartnerByZid, func(ctx *gin.Context, zid int64) ([]*dbstruct.ZoneCollaborator, error) {
|
|
return _DefaultZoneCollaborator.OpList(ctx, &zone_collaborator_proto.OpListReq{
|
|
Zid: goproto.Int64(zid),
|
|
})
|
|
}, req.ZoneCollaborator.GetZid(), req.ZoneCollaborator.GetId(), req.ZoneCollaborator.GetSharingRatio()).
|
|
Validate().
|
|
Collect()
|
|
ec = result[0].(errcode.ErrCode)
|
|
if ec == errcode.ErrCodeOperationToSelfIsNotPermitted {
|
|
ec = errcode.ErrCodeZoneCollaboratorWrongCollaborator
|
|
}
|
|
if ec != errcode.ErrCodeOk {
|
|
logger.Error("ApiCreateZoneCollaborator business validation failed")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (s *Service) ApiCreateOrderBusinessValidate(ctx *gin.Context, req *vasproto.CreateOrderReq) (err error) {
|
|
|
|
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
|
|
EnsureSuchAccountPunishmentNotExist(req.BaseRequest.Mid, consts.AccountPunishment_BlockFromPaying, _DefaultAccountPunishment.OpListByMidAndType).
|
|
Validate().
|
|
Collect()
|
|
ec := result[0].(errcode.ErrCode)
|
|
if ec == errcode.ErrCodeAccountPunishmentExist {
|
|
return fmt.Errorf("账号已受限,解限请联系客服")
|
|
}
|
|
return nil
|
|
}
|