service/app/mix/service/apiservice.go

1855 lines
57 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"service/api/base"
"service/api/consts"
"service/api/errcode"
accountproto "service/api/proto/account/proto"
accountrelationproto "service/api/proto/accountrelation/proto"
appconfigproto "service/api/proto/app_config/proto"
contact_customer_service_proto "service/api/proto/contact_customer_service/proto"
contact_customer_service_sessionproto "service/api/proto/contact_customer_service_session/proto"
feedbackproto "service/api/proto/feedback/proto"
loginproto "service/api/proto/login/proto"
momentproto "service/api/proto/moment/proto"
realname_authenticationproto "service/api/proto/realname_authentication/proto"
streamerproto "service/api/proto/streamer/proto"
streamerauthapprovalproto "service/api/proto/streamerauthapproval/proto"
streamerlinkproto "service/api/proto/streamerlink/proto"
thumbsupproto "service/api/proto/thumbsup/proto"
tokenproto "service/api/proto/token/proto"
userwxaddcheckproto "service/api/proto/userwxaddcheck/proto"
vasproto "service/api/proto/vas/proto"
vericodeproto "service/api/proto/vericode/proto"
"service/apollostruct"
businessvalidator "service/app/mix/service/business_validator"
"service/bizcommon/util"
"service/dbstruct"
"service/library/apollo"
"service/library/contentaudit/imageaudit"
"service/library/contentaudit/textaudit"
"service/library/logger"
"service/library/redis"
"go.mongodb.org/mongo-driver/mongo"
goproto "google.golang.org/protobuf/proto"
"github.com/gin-gonic/gin"
"github.com/qiniu/qmgo"
)
// 发送验证码
func (s *Service) ApiSendVeriCode(ctx *gin.Context, req *vericodeproto.ApiSendReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeLoginSrvOk
ec = s.ApiSendVeriCodeBusinessValidate(ctx, req)
if ec != errcode.ErrCodeLoginSrvOk {
return
}
err := _DefaultVeriCode.OpSendVeriCode(ctx, &vericodeproto.OpSendReq{
MobilePhone: req.MobilePhone,
RegionCode: req.RegionCode,
Trigger: req.Trigger,
})
if err != nil {
logger.Error("OpSendVeriCode fail, err: %v", err)
ec = errcode.ErrCodeLoginSrvFail
return
}
return
}
// 密码登录
func (s *Service) ApiLoginByPswd(ctx *gin.Context, req *loginproto.ApiLoginByPswdReq) (isEnabled int64, token string, accountVO *accountproto.ApiListVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeLoginSrvOk
// 1.业务校验
login, account, ec := s.ApiLoginByPswdBusinessValidate(ctx, req)
if ec != errcode.ErrCodeLoginSrvOk {
return
}
// 2.让已登录的用户强制下线
if util.DerefInt64(login.IsLogined) == 1 {
if _, ec = s.ApiLogout(ctx, &loginproto.ApiLogoutReq{
Mid: account.Mid,
}); ec != errcode.ErrCodeLoginSrvOk {
logger.Error("ApiLogout failed!")
return
}
}
// 3.生成token
token, err := _DefaultToken.OpGenerate(ctx, &tokenproto.OpCreateReq{
Token: &dbstruct.Token{
Mid: util.DerefInt64(login.Mid),
},
})
if err != nil {
ec = errcode.ErrCodeLoginSrvFail
logger.Error("ApiGenerate failed, err: %v", err)
return
}
// 4.更新登录状态
if err = _DefaultLogin.OpUpdate(ctx, &loginproto.OpUpdateReq{
Login: &dbstruct.Login{
Id: goproto.Int64(util.DerefInt64(login.Id)),
IsLogined: goproto.Int64(1),
},
}); err != nil {
ec = errcode.ErrCodeLoginSrvFail
logger.Error("ApiUpdate failed, err: %v", err)
return
}
// 5.组装返回信息
accountVO = &accountproto.ApiListVO{}
accountVO.CopyAccount(account)
return
}
func (s *Service) ApiLoginByVeriCode(ctx *gin.Context, req *loginproto.ApiLoginByVeriCodeReq) (isEnabled int64, token string, accountVO *accountproto.ApiListVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeLoginSrvOk
var login *dbstruct.Login
var account *dbstruct.Account
var vericode *dbstruct.VeriCode
var err error
// 1.业务校验
login, account, vericode, ec = s.ApiLoginByVeriCodeBusinessValidate(ctx, req)
// 2.如果错误码是登录信息不存在,则判断为首次登录,将创建用户信息
if ec == errcode.ErrCodeLoginNotExist {
login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent, req.Inviter, req.BaseRequest.DevType)
if ec != errcode.ErrCodeLoginSrvOk {
logger.Error("utilRegisterUser failed")
ec = errcode.ErrCodeLoginRegisterUserFail
return
}
} else if ec != errcode.ErrCodeLoginSrvOk {
return
}
// 3.验证码校验已通过,立即删除该验证码
if err := _DefaultVeriCode.OpDelete(ctx, vericode.Id); err != nil {
logger.Error("VeriCode ApiDelete failed, err: %v", err)
ec = errcode.ErrCodeLoginSrvFail
return
}
// 4.让已登录的用户强制下线
if util.DerefInt64(login.IsLogined) == 1 {
if _, ec = s.ApiLogout(ctx, &loginproto.ApiLogoutReq{
Mid: account.Mid,
}); ec != errcode.ErrCodeLoginSrvOk {
logger.Error("ApiLogout failed!")
return
}
}
// 5.生成token
token, err = _DefaultToken.OpGenerate(ctx, &tokenproto.OpCreateReq{
Token: &dbstruct.Token{
Mid: util.DerefInt64(login.Mid),
},
})
if err != nil {
ec = errcode.ErrCodeLoginSrvFail
logger.Error("ApiGenerate failed, err: %v", err)
return
}
// 6.更新登录状态
if err = _DefaultLogin.OpUpdate(ctx, &loginproto.OpUpdateReq{
Login: &dbstruct.Login{
Id: goproto.Int64(util.DerefInt64(login.Id)),
IsLogined: goproto.Int64(1),
},
}); err != nil {
ec = errcode.ErrCodeLoginSrvFail
logger.Error("ApiUpdate failed, err: %v", err)
return
}
// 7.组装返回信息
isEnabled = util.DerefInt64(login.IsEnabled)
accountVO = &accountproto.ApiListVO{}
accountVO.CopyAccount(account)
return
}
func (s *Service) ApiLogout(ctx *gin.Context, req *loginproto.ApiLogoutReq) (logoutData *loginproto.OpLogoutData, ec errcode.ErrCode) {
ec = errcode.ErrCodeLoginSrvOk
if err := _DefaultToken.OpDeleteByMid(ctx, util.DerefInt64(req.Mid)); err != nil {
logger.Error("ApiDeleteByMid failed, err: %v", err)
logoutData = &loginproto.OpLogoutData{
OpResult: false,
}
ec = errcode.ErrCodeLoginSrvFail
return
}
// 更新登录状态
if err := _DefaultLogin.OpUpdateByMid(ctx, &loginproto.OpUpdateByMidReq{
Login: &dbstruct.Login{
IsLogined: goproto.Int64(0),
},
Mid: req.Mid,
}); err != nil {
ec = errcode.ErrCodeLoginSrvFail
logger.Error("ApiUpdateByMid failed, err: %v", err)
return
}
logoutData = &loginproto.OpLogoutData{
OpResult: true,
}
return
}
// 登录后第一次设置密码
func (s *Service) ApiSetPassword(ctx *gin.Context, req *loginproto.ApiSetPswdReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeLoginSrvOk
// 1.业务校验
login, _, ec := s.ApiSetPasswordBusinessValidate(ctx, req)
if ec != errcode.ErrCodeLoginSrvOk {
return
}
// 3.更新密码,置为启用
if err := _DefaultLogin.OpUpdate(ctx, &loginproto.OpUpdateReq{
Login: &dbstruct.Login{
Id: goproto.Int64(util.DerefInt64(login.Id)),
Password: goproto.String(req.NewPassword),
IsEnabled: goproto.Int64(1),
},
}); err != nil {
logger.Error("ApiUpdate failed : %v", err)
ec = errcode.ErrCodeLoginSrvFail
return
}
return
}
// 重置密码
func (s *Service) ApiResetPassword(ctx *gin.Context, req *loginproto.ApiResetPswdReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeLoginSrvOk
// 1.业务校验
login, _, vericode, ec := s.ApiResetPasswordBusinessValidate(ctx, req)
if ec != errcode.ErrCodeLoginSrvOk {
return
}
// 2.消费验证码
if err := _DefaultVeriCode.OpDelete(ctx, vericode.Id); err != nil {
logger.Error("VeriCode OpDelete failed, err: %v", err)
ec = errcode.ErrCodeLoginSrvFail
return
}
// 3.更新密码,置为未锁定,重置密码错误次数
if err := _DefaultLogin.OpUpdate(ctx, &loginproto.OpUpdateReq{
Login: &dbstruct.Login{
Id: goproto.Int64(util.DerefInt64(login.Id)),
Password: goproto.String(req.NewPassword),
IsLocked: goproto.Int64(0),
WrongPswdTimes: goproto.Int64(0),
},
}); err != nil {
logger.Error("ApiUpdate failed : %v", err)
ec = errcode.ErrCodeLoginSrvFail
return
}
return
}
func (s *Service) ApiUpdatePassword(ctx *gin.Context, req *loginproto.ApiUpdatePswdReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeLoginSrvOk
// 1.业务校验
login, _, vericode, ec := s.ApiUpdatePasswordBusinessValidate(ctx, req)
if ec != errcode.ErrCodeLoginSrvOk {
return
}
// 2.消费验证码
if err := _DefaultVeriCode.OpDelete(ctx, vericode.Id); err != nil {
logger.Error("VeriCode OpDelete failed, err: %v", err)
ec = errcode.ErrCodeLoginSrvFail
return
}
// 3.更新密码
if err := _DefaultLogin.OpUpdate(ctx, &loginproto.OpUpdateReq{
Login: &dbstruct.Login{
Id: goproto.Int64(util.DerefInt64(login.Id)),
Password: goproto.String(req.NewPassword),
WrongPswdTimes: goproto.Int64(0),
},
}); err != nil {
logger.Error("ApiUpdate failed : %v", err)
ec = errcode.ErrCodeLoginSrvFail
return
}
return
}
// Account
func (s *Service) ApiUpdateAccount(ctx *gin.Context, req *accountproto.ApiUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
// 业务鉴权
if ec = s.ApiUpdateAccountBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountSrvOk {
return
}
// 查询旧账户
oldAccount, err := _DefaultAccount.OpListByMid(ctx, &accountproto.OpListByMidReq{
Mid: req.Account.Mid,
})
if oldAccount == nil {
ec = errcode.ErrCodeAccountNotExist
return
}
if err != nil {
logger.Error("OpListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountSrvFail
return
}
// 创建审核任务
imageaudittask := s.CreateUpdateAccountImageAudit(ctx, oldAccount, req.Account)
textaudittask := s.CreateUpdateAccountTextAudit(ctx, oldAccount, req.Account)
// 用户只允许修改昵称和头像
if err := _DefaultAccount.OpUpdate(ctx, &accountproto.OpUpdateReq{
Account: &dbstruct.Account{
Mid: req.Account.Mid,
Name: req.Account.Name,
Avatar: req.Account.Avatar,
},
}); err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountSrvFail
return
}
// 审核任务加入队列
if imageaudittask != nil {
imageaudit.AddTask(imageaudittask)
}
if textaudittask != nil {
textaudit.AddTask(textaudittask)
}
return
}
func (s *Service) ApiGetAccountListByMid(ctx *gin.Context, req *accountproto.ApiListByMidReq) (vo *accountproto.ApiListVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
// 业务鉴权
if ec = s.ApiGetAccountListByMidBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountSrvOk {
return
}
account, err := _DefaultAccount.OpListByMid(ctx, &accountproto.OpListByMidReq{
Mid: req.Mid,
})
if err != nil {
logger.Error("OpListByMid fail, err: %v", err)
ec = errcode.ErrCodeAccountSrvFail
return
}
vo = &accountproto.ApiListVO{}
vo.CopyAccount(account)
wallet, _ := _DefaultVas.CheckWalletExist(ctx, util.DerefInt64(req.Mid))
vo.CopyWallet(wallet)
return
}
func (s *Service) ApiGetAccountListByMids(ctx *gin.Context, req *accountproto.ApiListByMidsReq) (volist []*accountproto.ApiListVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
list, err := _DefaultAccount.OpListByMids(ctx, &accountproto.OpListByMidsReq{
Mids: req.Mids,
Offset: req.Offset,
Limit: req.Limit,
Sort: req.Sort,
})
if err != nil {
logger.Error("OpListByMids fail, err: %v", err)
ec = errcode.ErrCodeAccountSrvFail
return
}
volist = make([]*accountproto.ApiListVO, len(list))
for i, account := range list {
volist[i] = &accountproto.ApiListVO{}
volist[i].CopyAccount(account)
}
return
}
func (s *Service) ApiGetAccountListByUserId(ctx *gin.Context, req *accountproto.ApiListByUserIdReq) (vo *accountproto.ApiListVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
account, err := _DefaultAccount.OpListByUserId(ctx, &accountproto.OpListByUserIdReq{
UserId: req.UserId,
})
if err != nil {
logger.Error("OpListByUserId fail, err: %v", err)
ec = errcode.ErrCodeAccountSrvFail
return
}
vo = &accountproto.ApiListVO{}
vo.CopyAccount(account)
return
}
func (s *Service) ApiGetAccountListFuzzilyByUserId(ctx *gin.Context, req *accountproto.ApiListFuzzilyByUserIdReq) (volist []*accountproto.ApiListVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
list, err := _DefaultAccount.OpListFuzzilyByUserId(ctx, &accountproto.OpListFuzzilyByUserIdReq{
UserId: req.UserId,
Role: req.Role,
Offset: req.Offset,
Limit: req.Limit,
Sort: req.Sort,
})
if err != nil {
logger.Error("OpListFuzzilyByUserId fail, err: %v", err)
ec = errcode.ErrCodeAccountSrvFail
return
}
volist = make([]*accountproto.ApiListVO, len(list))
for i, account := range list {
volist[i] = &accountproto.ApiListVO{}
volist[i].CopyAccount(account)
}
return
}
func (s *Service) ApiGetAccountListFuzzilyByName(ctx *gin.Context, req *accountproto.ApiListFuzzilyByNameReq) (volist []*accountproto.ApiListVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
list, err := _DefaultAccount.OpListFuzzilyByName(ctx, &accountproto.OpListFuzzilyByNameReq{
Name: req.Name,
Role: req.Role,
Offset: req.Offset,
Limit: req.Limit,
Sort: req.Sort,
})
if err != nil {
logger.Error("OpListFuzzilyByName fail, err: %v", err)
ec = errcode.ErrCodeAccountSrvFail
return
}
volist = make([]*accountproto.ApiListVO, len(list))
for i, account := range list {
volist[i] = &accountproto.ApiListVO{}
volist[i].CopyAccount(account)
}
return
}
func (s *Service) ApiGetAccountListForOthersByMid(ctx *gin.Context, req *accountproto.ApiListOthersByMidReq) (vo *accountproto.ApiListOthersVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
account, err := _DefaultAccount.OpListByMid(ctx, &accountproto.OpListByMidReq{
Mid: req.Mid,
})
if err != nil {
logger.Error("OpListByMid fail, err: %v", err)
ec = errcode.ErrCodeAccountSrvFail
return
}
vo = &accountproto.ApiListOthersVO{}
vo.CopyAccount(account)
return
}
func (s *Service) ApiGetAccountListForOthersByMids(ctx *gin.Context, req *accountproto.ApiListOthersByMidsReq) (volist []*accountproto.ApiListOthersVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
list, err := _DefaultAccount.OpListByMids(ctx, &accountproto.OpListByMidsReq{
Mids: req.Mids,
Offset: req.Offset,
Limit: req.Limit,
})
if err != nil {
logger.Error("OpListByMids fail, err: %v", err)
ec = errcode.ErrCodeAccountSrvFail
return
}
volist = make([]*accountproto.ApiListOthersVO, len(list))
for i, account := range list {
volist[i] = &accountproto.ApiListOthersVO{}
volist[i].CopyAccount(account)
}
return
}
func (s *Service) ApiAccountExpInc(ctx *gin.Context, req *accountproto.ApiExpIncReq) (result *accountproto.ApiExpIncData, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
// 业务鉴权
account, ec := s.ApiAccountExpIncBusinessValidate(ctx, req)
if ec != errcode.ErrCodeAccountSrvOk {
return
}
cfg := apollostruct.AccountInitCfg{}
err := apollo.GetJson(consts.AccountInitKey, &cfg, apollo.ApolloOpts().SetNamespace("account_init"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
return nil, errcode.ErrCodeApolloReadFail
}
//拼合所有经验向量
expVector := make([]int64, 0)
expVector = append(expVector, cfg.LevelUpExpVector1...)
expVector = append(expVector, cfg.LevelUpExpVector2...)
expVector = append(expVector, cfg.LevelUpExpVector3...)
expVector = append(expVector, cfg.LevelUpExpVector4...)
expVector = append(expVector, cfg.LevelUpExpVector5...)
expVector = append(expVector, cfg.LevelUpExpVector6...)
expVector = append(expVector, cfg.LevelUpExpVector7...)
expVector = append(expVector, cfg.LevelUpExpVector8...)
expVector = append(expVector, cfg.LevelUpExpVector9...)
expVector = append(expVector, cfg.LevelUpExpVector10...)
level := util.DerefInt64(account.Level)
expPool := util.DerefInt64(account.CurrentExp) + util.DerefInt64(req.ExpIncrement) // 当前经验池
currentLevelExp := util.DerefInt64(account.CurrentLevelExp) // 当前等级总经验
isLevelledUp := 0
if expPool >= expVector[level] {
isLevelledUp = 1
//循环升级
for expPool >= expVector[level] {
expPool -= expVector[level]
level++
//如果等级触顶,则直接跳出
if level == cfg.LevelUpperBound {
currentLevelExp = 0
break
} else {
currentLevelExp = expVector[level]
}
}
}
//更新升级后的信息
err = _DefaultAccount.OpUpdate(ctx, &accountproto.OpUpdateReq{
Account: &dbstruct.Account{
Mid: req.Mid,
Level: goproto.Int64(level),
CurrentExp: goproto.Int64(expPool),
CurrentLevelExp: goproto.Int64(currentLevelExp),
},
})
if err != nil {
logger.Error("ApiUpdate fail, err: %v", err)
return nil, errcode.ErrCodeAccountSrvFail
}
result = &accountproto.ApiExpIncData{
IsLevelledUp: int64(isLevelledUp),
Level: level,
CurrentExp: expPool,
CurrentLevelExp: currentLevelExp,
}
return
}
// AccountRelation
func (s *Service) ApiCreateAccountRelation(ctx *gin.Context, req *accountrelationproto.ApiCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
//业务校验
if ec = s.ApiCreateAccountRelationBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
err := _DefaultAccountRelation.OpCreate(ctx, &accountrelationproto.OpCreateReq{
AccountRelations: req.AccountRelations,
})
if mongo.IsDuplicateKeyError(err) {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationDuplicateKey
return
}
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
func (s *Service) ApiUpdateAccountRelation(ctx *gin.Context, req *accountrelationproto.ApiUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
err := _DefaultAccountRelation.OpUpdate(ctx, &accountrelationproto.OpUpdateReq{
AccountRelation: req.AccountRelation,
Sentence: req.Sentence,
})
if err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
func (s *Service) ApiDeleteAccountRelation(ctx *gin.Context, req *accountrelationproto.ApiDeleteReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
//业务校验
if ec = s.ApiDeleteAccountRelationBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
err := _DefaultAccountRelation.OpDelete(ctx, &accountrelationproto.OpDeleteReq{
Sentences: req.Sentences,
})
if err == qmgo.ErrNoSuchDocuments {
logger.Error("OpDelete fail, id: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationNotExist
return
}
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
// 查询关注列表
func (s *Service) ApiGetFollowAccountRelationList(ctx *gin.Context, req *accountrelationproto.ApiListReq) (list []*dbstruct.AccountRelation, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
//业务校验
if ec = s.ApiGetFollowAccountRelationListBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
list, err := _DefaultAccountRelation.OpListBySubMidAndPredicate(ctx, &accountrelationproto.OpListBySubMidAndPredicateReq{
SubMid: req.Mid,
Predicate: goproto.Int64(consts.Follow),
Offset: req.Offset,
Limit: req.Limit,
})
if err != nil {
logger.Error("OpListBySubMidAndPredicate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
// 查询被关注列表
func (s *Service) ApiGetIsFollowedAccountRelationList(ctx *gin.Context, req *accountrelationproto.ApiListReq) (list []*dbstruct.AccountRelation, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
//业务校验
if ec = s.ApiGetIsFollowedAccountRelationListBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
list, err := _DefaultAccountRelation.OpListBySubMidAndPredicate(ctx, &accountrelationproto.OpListBySubMidAndPredicateReq{
SubMid: req.Mid,
Predicate: goproto.Int64(consts.IsFollowed),
Offset: req.Offset,
Limit: req.Limit,
})
if err != nil {
logger.Error("OpListBySubMidAndPredicate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
// 查询好友列表
func (s *Service) ApiGetFriendAccountRelationList(ctx *gin.Context, req *accountrelationproto.ApiListReq) (list []*dbstruct.AccountRelation, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
if ec = s.ApiGetFriendAccountRelationListBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
list, err := _DefaultAccountRelation.OpListFriend(ctx, &accountrelationproto.OpListReq{
Mid: req.Mid,
Offset: req.Offset,
Limit: req.Limit,
})
if err != nil {
logger.Error("OpListFriend fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
// 查询黑名单列表
func (s *Service) ApiGetIgnoreAccountRelationList(ctx *gin.Context, req *accountrelationproto.ApiListReq) (list []*dbstruct.AccountRelation, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
if ec = s.ApiGetIgnoreAccountRelationListBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
list, err := _DefaultAccountRelation.OpListBySubMidAndPredicate(ctx, &accountrelationproto.OpListBySubMidAndPredicateReq{
SubMid: req.Mid,
Predicate: goproto.Int64(consts.Ignore),
Offset: req.Offset,
Limit: req.Limit,
})
if err != nil {
logger.Error("OpListBySubMidAndPredicate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
// 查询解锁微信列表
func (s *Service) ApiGetAbleToAccessWeixinOfAccountRelationList(ctx *gin.Context, req *accountrelationproto.ApiListReq) (list []*dbstruct.AccountRelation, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
if ec = s.ApiGetAbleToAccessWeixinOfAccountRelationListBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
list, err := _DefaultAccountRelation.OpListBySubMidAndPredicate(ctx, &accountrelationproto.OpListBySubMidAndPredicateReq{
SubMid: req.Mid,
Predicate: goproto.Int64(consts.AbleToAccessWeixinOf),
Offset: req.Offset,
Limit: req.Limit,
})
if err != nil {
logger.Error("OpListBySubMidAndPredicate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
// 查询关注、被关注数量
func (s *Service) ApiGetAccountRelationCount(ctx *gin.Context, req *accountrelationproto.ApiCountReq) (countMap map[int64]int64, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
if ec = s.ApiGetAccountRelationCountBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
countMap, err := _DefaultAccountRelation.OpCount(ctx, &accountrelationproto.OpCountReq{
Mid: req.Mid,
})
if err != nil {
logger.Error("OpCount fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
func (s *Service) ApiGetIsFollowedAccountRelationCount(ctx *gin.Context) (midList []int64, countList []int64, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
midList, countList, err := _DefaultAccountRelation.OpIsFollowedCount(ctx)
if err != nil {
logger.Error("OpIsFollowedCount fail, err: %v", err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
// 查询是否存在某种关系
func (s *Service) ApiGetAccountRelationBySentence(ctx *gin.Context, req *accountrelationproto.ApiListBySentenceReq) (accountrelation *dbstruct.AccountRelation, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
if ec = s.ApiGetAccountRelationBySentenceBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
accountrelation, err := _DefaultAccountRelation.OpListBySentence(ctx, &accountrelationproto.OpListBySentenceReq{
AccountRelation: req.AccountRelation,
})
if err != nil {
logger.Error("OpListBySentence fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
if accountrelation == nil {
ec = errcode.ErrCodeAccountRelationNotExist
return
}
return
}
// 女神认证审核
func (s *Service) ApiCreateStreamerAuthApproval(ctx *gin.Context, req *streamerauthapprovalproto.ApiCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerAuthApprovalSrvOk
if ec = s.ApiCreateStreamerAuthApprovalBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerAuthApprovalSrvOk {
return
}
err := _DefaultStreamerAuthApproval.OpCreate(ctx, &streamerauthapprovalproto.OpCreateReq{
StreamerAuthApproval: req.StreamerAuthApproval,
})
if mongo.IsDuplicateKeyError(err) {
logger.Error("ApiCreate duplicate key found, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerAuthApprovalDuplicateKey
return
}
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerAuthApprovalSrvFail
return
}
return
}
func (s *Service) ApiDeleteStreamerAuthApproval(ctx *gin.Context, req *streamerauthapprovalproto.ApiDeleteReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerAuthApprovalSrvOk
if ec = s.ApiDeleteStreamerAuthApprovalBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerAuthApprovalSrvOk {
return
}
err := _DefaultStreamerAuthApproval.OpDelete(ctx, req)
if err != nil {
logger.Error("OpDelete fail, ids: %v, err: %v", req, err)
ec = errcode.ErrCodeStreamerAuthApprovalSrvFail
return
}
return
}
func (s *Service) ApiGetStreamerAuthApprovalList(ctx *gin.Context, req *streamerauthapprovalproto.ApiListReq) (vo *streamerauthapprovalproto.StreamerAuthApprovalApiVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerAuthApprovalSrvOk
if ec = s.ApiGetStreamerAuthApprovalListBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerAuthApprovalSrvOk {
return
}
streamerauthapproval, err := _DefaultStreamerAuthApproval.OpListByMid(ctx, &streamerauthapprovalproto.OpListByMidReq{
Mid: req.Mid,
})
if err != nil {
logger.Error("OpListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerAuthApprovalSrvFail
return
}
account, err := _DefaultAccount.OpListByMid(ctx, &accountproto.OpListByMidReq{
Mid: streamerauthapproval.Mid,
})
if err != nil {
logger.Error("OpListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountSrvFail
return
}
vo = &streamerauthapprovalproto.StreamerAuthApprovalApiVO{}
vo.CopyStreamerAuthApproval(streamerauthapproval)
vo.CopyAccount(account)
return
}
// Streamer
func (s *Service) ApiUpdateStreamer(ctx *gin.Context, req *streamerproto.ApiUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
if ec = s.ApiUpdateStreamerBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerSrvOk {
return
}
// 查询旧主播
oldStreamer, err := _DefaultStreamer.OpListByMid(ctx, &streamerproto.OpListByMidReq{
Mid: req.Streamer.Mid,
})
if oldStreamer == nil {
ec = errcode.ErrCodeStreamerNotExist
return
}
if err != nil {
logger.Error("OpListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerSrvFail
return
}
// 创建审核任务
imageaudittasks := s.CreateUpdateStreamerImageAudit(ctx, oldStreamer, req.Streamer)
textaudittasks := s.CreateUpdateStreamerTextAudit(ctx, oldStreamer, req.Streamer)
//执行更新
if err := _DefaultStreamer.OpUpdate(ctx, &streamerproto.OpUpdateReq{
Streamer: &dbstruct.Streamer{
Mid: req.Streamer.Mid,
Gender: req.Streamer.Gender,
Bio: req.Streamer.Bio,
Cover: req.Streamer.Cover,
Shorts: req.Streamer.Shorts,
Album: req.Streamer.Album,
Age: req.Streamer.Age,
Height: req.Streamer.Height,
Weight: req.Streamer.Weight,
Constellation: req.Streamer.Constellation,
City: req.Streamer.City,
Tag: req.Streamer.Tag,
Fans: req.Streamer.Fans,
AutoResponseMessage: req.Streamer.AutoResponseMessage,
},
}); err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerSrvFail
return
}
// 更新user_vas
err = _DefaultVas.UpdateWechat(ctx, &vasproto.UpdateWechatReq{
BaseRequest: base.BaseRequest{
Mid: util.DerefInt64(req.Streamer.Mid),
},
WechatLockType: util.DerefInt32(req.Streamer.WechatLockType),
WechatContact: util.DerefString(req.Streamer.WechatContact),
WechatCoinPrice: util.DerefInt64(req.Streamer.WechatCoinPrice),
})
if err != nil {
logger.Error("UpdateWechat fail, mid: %v, err: %v", err)
return
}
// 审核任务加入队列
for i := range imageaudittasks {
if imageaudittasks[i] != nil {
imageaudit.AddTask(imageaudittasks[i])
}
}
for i := range textaudittasks {
if textaudittasks[i] != nil {
textaudit.AddTask(textaudittasks[i])
}
}
return
}
func (s *Service) ApiGetStreamerList(ctx *gin.Context, req *streamerproto.ApiListReq) (list []*dbstruct.Streamer, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
list, err := _DefaultStreamer.OpList(ctx, &streamerproto.OpListReq{
Offset: req.Offset,
Limit: req.Limit,
Sort: req.Sort,
})
if err != nil {
logger.Error("OpList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerSrvFail
return
}
return
}
func (s *Service) ApiGetStreamerListByMid(ctx *gin.Context, req *streamerproto.ApiListByMidReq) (streamer *dbstruct.Streamer, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
if ec = s.ApiGetStreamerListByMidBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerSrvOk {
return
}
streamer, err := _DefaultStreamer.OpListByMid(ctx, &streamerproto.OpListByMidReq{
Mid: req.Mid,
})
if err != nil {
logger.Error("OpListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerSrvFail
return
}
userVas, err := _DefaultVas.GetUserVasInfo(ctx, util.DerefInt64(streamer.Mid))
if err != nil {
logger.Error("GetUserVasInfo fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerSrvFail
return
}
streamer.WechatLockType = goproto.Int32(userVas.WechatLockType)
streamer.WechatContact = goproto.String(userVas.WechatContact)
streamer.WechatCoinPrice = goproto.Int64(userVas.WechatCoinPrice)
return
}
// StreamerExt
func (s *Service) ApiGetStreamerExtListByMid(ctx *gin.Context, req *streamerproto.ApiListExtByMidReq) (data *streamerproto.ApiListExtByMidData, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
//1.从用户表中查询主播信息
account, err := _DefaultAccount.OpListByMid(ctx, &accountproto.OpListByMidReq{
Mid: req.Uid,
})
if err != nil || account == nil {
logger.Error("Account OpListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountSrvFail
return
}
//2.将account扩张为StreamerExt
vo := &streamerproto.ApiListExtVO{}
ec = s.utilExtendAccountIntoStreamerExt(ctx, account, vo)
if ec != errcode.ErrCodeStreamerSrvOk {
logger.Error("Extend account into streamer_ext fail, req: %v, err: %v", util.ToJson(req), err)
return
}
data = &streamerproto.ApiListExtByMidData{
StreamerExt: vo,
}
// 主播的微信上锁类型
uVasInfo, _ := _DefaultVas.GetUserVasInfo(ctx, util.DerefInt64(req.Uid))
if uVasInfo != nil {
data.WechatLockType = uVasInfo.WechatLockType
}
// 是否解锁微信
unlockInfo, _ := _DefaultVas.GetUserWechatUnlock(ctx, req.Mid, util.DerefInt64(req.Uid))
if unlockInfo != nil {
data.IsUnlockWechat = 1
}
return
}
func (s *Service) ApiGetStreamerExtListByMids(ctx *gin.Context, req *streamerproto.ApiListExtByMidsReq) (list []*streamerproto.ApiListExtVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
//1.从用户表中查询所有主播信息的用户侧数据按mid正序排序
accountList, err := _DefaultAccount.OpListByMids(ctx, &accountproto.OpListByMidsReq{
Mids: req.Mids,
Offset: req.Offset,
Limit: req.Limit,
Sort: []string{"_id"},
})
if err != nil {
logger.Error("Account OpListByMids fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountSrvFail
return
}
//2.将accountlist扩张为StreamerExts
streamerExts := make([]streamerproto.StreamerExtVO, len(accountList))
for i := range streamerExts {
streamerExts[i] = &streamerproto.ApiListExtVO{}
}
ec = s.utilExtendAccountsIntoStreamerExts(ctx, accountList, streamerExts)
if ec != errcode.ErrCodeStreamerSrvOk {
logger.Error("Extend accountlist into streamer_exts fail, req: %v, err: %v", util.ToJson(req), err)
return
}
list = make([]*streamerproto.ApiListExtVO, len(streamerExts))
for i, streamerExt := range streamerExts {
vo, _ := streamerExt.(*streamerproto.ApiListExtVO)
list[i] = vo
}
return
}
func (s *Service) ApiGetStreamerExtListByUserId(ctx *gin.Context, req *streamerproto.ApiListExtByUserIdReq) (data *streamerproto.ApiListExtByUserIdData, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
//1.从用户表中查询主播信息
account, err := _DefaultAccount.OpListByUserId(ctx, &accountproto.OpListByUserIdReq{
UserId: req.UserId,
})
if err != nil || account == nil {
logger.Error("Account OpListByUserId fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountSrvFail
return
}
//2.将account扩张为StreamerExt
vo := &streamerproto.ApiListExtVO{}
ec = s.utilExtendAccountIntoStreamerExt(ctx, account, vo)
if ec != errcode.ErrCodeStreamerSrvOk {
logger.Error("Extend account into streamer_ext fail, req: %v, err: %v", util.ToJson(req), err)
return
}
data = &streamerproto.ApiListExtByUserIdData{
StreamerExt: vo,
}
// 主播的微信上锁类型
uVasInfo, _ := _DefaultVas.GetUserVasInfo(ctx, util.DerefInt64(account.Mid))
if uVasInfo != nil {
data.WechatLockType = uVasInfo.WechatLockType
}
// 是否解锁微信
unlockInfo, _ := _DefaultVas.GetUserWechatUnlock(ctx, req.Mid, util.DerefInt64(account.Mid))
if unlockInfo != nil {
data.IsUnlockWechat = 1
}
return
}
func (s *Service) ApiGetStreamerExtListFuzzilyByUserId(ctx *gin.Context, req *streamerproto.ApiListExtFuzzilyByUserIdReq) (list []*streamerproto.ApiListExtVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
//1.从用户表中模糊匹配所有主播信息的用户侧数据按mid正序排序
accountList, err := _DefaultAccount.OpListFuzzilyByUserId(ctx, &accountproto.OpListFuzzilyByUserIdReq{
UserId: req.UserId,
Role: goproto.Int64(consts.Streamer),
Offset: req.Offset,
Limit: req.Limit,
Sort: []string{"_id"},
})
if err != nil {
logger.Error("Account OpListFuzzilyByUserId fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountSrvFail
return
}
//2.将accountlist扩张为StreamerExts
streamerExts := make([]streamerproto.StreamerExtVO, len(accountList))
for i := range streamerExts {
streamerExts[i] = &streamerproto.ApiListExtVO{}
}
ec = s.utilExtendAccountsIntoStreamerExts(ctx, accountList, streamerExts)
if ec != errcode.ErrCodeStreamerSrvOk {
logger.Error("Extend accountlist into streamer_exts fail, req: %v, err: %v", util.ToJson(req), err)
return
}
list = make([]*streamerproto.ApiListExtVO, len(streamerExts))
for i, streamerExt := range streamerExts {
vo, _ := streamerExt.(*streamerproto.ApiListExtVO)
list[i] = vo
}
return
}
func (s *Service) ApiGetStreamerExtListFuzzilyByName(ctx *gin.Context, req *streamerproto.ApiListExtFuzzilyByNameReq) (list []*streamerproto.ApiListExtVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
//1.从用户表中模糊匹配所有主播信息的用户侧数据按mid正序排序
accountList, err := _DefaultAccount.OpListFuzzilyByName(ctx, &accountproto.OpListFuzzilyByNameReq{
Name: req.Name,
Role: goproto.Int64(consts.Streamer),
Offset: req.Offset,
Limit: req.Limit,
Sort: []string{"_id"},
})
if err != nil {
logger.Error("Account OpListFuzzilyByName fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountSrvFail
return
}
//2.将accountlist扩张为StreamerExts
streamerExts := make([]streamerproto.StreamerExtVO, len(accountList))
for i := range streamerExts {
streamerExts[i] = &streamerproto.ApiListExtVO{}
}
ec = s.utilExtendAccountsIntoStreamerExts(ctx, accountList, streamerExts)
if ec != errcode.ErrCodeStreamerSrvOk {
logger.Error("Extend accountlist into streamer_exts fail, req: %v, err: %v", util.ToJson(req), err)
return
}
list = make([]*streamerproto.ApiListExtVO, len(streamerExts))
for i, streamerExt := range streamerExts {
vo, _ := streamerExt.(*streamerproto.ApiListExtVO)
list[i] = vo
}
return
}
func (s *Service) ApiGetStreamerWxId(ctx *gin.Context, req *streamerproto.ApiListStreamerWxIdReq) (streamerWxIdVO *streamerproto.ApiListWxIdVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
//业务校验-如果登录用户和被查找用户不一致,则查找用户关系表中查找,条件为(登录用户-sub_mid被查找用户-obj_mid6-主语可从宾语处查看微信-predicate
if ec = s.ApiGetStreamerWxIdBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerSrvOk {
return
}
streamer, err := _DefaultStreamer.OpListByMid(ctx, &streamerproto.OpListByMidReq{
Mid: req.Mid,
})
if err != nil {
logger.Error("OpListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerSrvFail
return
}
streamerWxIdVO = &streamerproto.ApiListWxIdVO{}
streamerWxIdVO.CopyStreamer(streamer)
return
}
// 推荐
func (s *Service) ApiGetStreamerRecommList(ctx *gin.Context, req *streamerproto.ApiRecommListReq) (recommlist []int64, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
// 取apollo配置
cfg := &apollostruct.RestrictedVisitorCfg{}
err := apollo.GetJson(consts.RestrictedVisitorKey, &cfg, apollo.ApolloOpts().SetNamespace("application"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
return nil, errcode.ErrCodeApolloReadFail
}
//1.从redis中获取数据
err = redis.GetRedisClient().GetObject(consts.RedisStreamerPrefix+"recomm_list", &recommlist)
if err != nil {
logger.Error("Redis read failed : %v", err)
ec = errcode.ErrCodeStreamerRecommListRedisCacheInvalid
return
}
//2.若redis命中失败再从数据库查
if len(recommlist) == 0 {
logger.Error("Redis hit failed, reading recommendation list from mongo...")
// recommlist, _, err = _DefaultAccountRelation.OpIsFollowedCount(ctx)
// if err != nil {
// logger.Error("OpIsFollowedCount fail, err: %v", err)
// ec = errcode.ErrCodeAccountRelationSrvFail
// return
// }
list, err := _DefaultStreamer.OpList(ctx, &streamerproto.OpListReq{
Sort: "-fans",
})
if err != nil {
logger.Error("OpList fail, err: %v", err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
recommlist = make([]int64, len(list))
for i, streamer := range list {
recommlist[i] = util.DerefInt64(streamer.Mid)
}
//若数据库命中成功则立即加载进redis
if len(recommlist) != 0 {
err := redis.GetRedisClient().Set(consts.RedisStreamerPrefix+"recomm_list", recommlist, 0)
if err != nil {
logger.Error("Redis cache fail, err: %v", err)
}
}
}
visitorMid := req.BaseRequest.Mid
for _, restricted_visitor_mid := range cfg.RestrictedVisitorMids {
if restricted_visitor_mid == visitorMid { // 是限制访问的访客
recommMap := make(map[int64]int64)
for _, recommMid := range recommlist {
recommMap[recommMid] = 1
}
restrictedRecommList := make([]int64, 0)
for _, restrictedVisitorVisibleMid := range cfg.RestrictedVisitorVisibleMids {
if recommMap[restrictedVisitorVisibleMid] == 1 {
restrictedRecommList = append(restrictedRecommList, restrictedVisitorVisibleMid)
}
}
recommlist = restrictedRecommList
break
}
}
return
}
// Feedback
func (s *Service) ApiCreateFeedback(ctx *gin.Context, req *feedbackproto.ApiCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeFeedbackSrvOk
err := _DefaultFeedback.OpCreate(ctx, &feedbackproto.OpCreateReq{
Feedback: req.Feedback,
})
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeFeedbackSrvFail
return
}
return
}
// StreamerLink
func (s *Service) ApiCreateStreamerLink(ctx *gin.Context, req *streamerlinkproto.ApiCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerLinkSrvOk
err := _DefaultStreamerLink.OpCreate(ctx, &streamerlinkproto.OpCreateReq{
StreamerLink: req.StreamerLink,
})
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerLinkSrvFail
return
}
return
}
func (s *Service) ApiUpdateStreamerLink(ctx *gin.Context, req *streamerlinkproto.ApiUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerLinkSrvOk
err := _DefaultStreamerLink.OpUpdate(ctx, &streamerlinkproto.OpUpdateReq{
StreamerLink: req.StreamerLink,
})
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeStreamerLinkNotExist
err = nil
return
}
if err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerLinkSrvFail
return
}
return
}
func (s *Service) ApiDeleteStreamerLink(ctx *gin.Context, id int64) (ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerLinkSrvOk
err := _DefaultStreamerLink.OpDelete(ctx, id)
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", id, err)
ec = errcode.ErrCodeStreamerLinkSrvFail
return
}
return
}
func (s *Service) ApiGetStreamerLinkListByMid(ctx *gin.Context, req *streamerlinkproto.ApiListByMidReq) (list []*dbstruct.StreamerLink, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerLinkSrvOk
list, err := _DefaultStreamerLink.OpListByMid(ctx, &streamerlinkproto.OpListByMidReq{
Mid: req.Mid,
Offset: req.Offset,
Limit: req.Limit,
Sort: req.Sort,
})
if err != nil {
logger.Error("OpListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerLinkSrvFail
return
}
return
}
func (s *Service) ApiCreateBatchStreamerLink(ctx *gin.Context, req *streamerlinkproto.ApiCreateBatchReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerLinkSrvOk
err := _DefaultStreamerLink.OpCreateBatch(ctx, &streamerlinkproto.OpCreateBatchReq{
StreamerLinks: req.StreamerLinks,
})
if err != nil {
logger.Error("OpCreateBatch fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerLinkSrvFail
return
}
return
}
func (s *Service) ApiDeleteBatchStreamerLink(ctx *gin.Context, req *streamerlinkproto.ApiDeleteBatchReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerLinkSrvOk
err := _DefaultStreamerLink.OpDeleteBatch(ctx, &streamerlinkproto.OpDeleteBatchReq{
Ids: req.Ids,
})
if err != nil {
logger.Error("OpDeleteBatch fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerLinkSrvFail
return
}
return
}
// UserWxAddCheck
func (s *Service) ApiCreateUserWxAddCheck(ctx *gin.Context, req *userwxaddcheckproto.ApiCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeUserWxAddCheckSrvOk
err := _DefaultUserWxAddCheck.OpCreate(ctx, &userwxaddcheckproto.OpCreateReq{
UserWxAddCheck: req.UserWxAddCheck,
})
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeUserWxAddCheckSrvFail
return
}
return
}
func (s *Service) ApiUpdateUserWxAddCheck(ctx *gin.Context, req *userwxaddcheckproto.ApiUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeUserWxAddCheckSrvOk
err := _DefaultUserWxAddCheck.OpUpdate(ctx, &userwxaddcheckproto.OpUpdateReq{
UserWxAddCheck: req.UserWxAddCheck,
})
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeUserWxAddCheckNotExist
err = nil
return
}
if err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeUserWxAddCheckSrvFail
return
}
return
}
func (s *Service) ApiDeleteUserWxAddCheck(ctx *gin.Context, id int64) (ec errcode.ErrCode) {
ec = errcode.ErrCodeUserWxAddCheckSrvOk
err := _DefaultUserWxAddCheck.OpDelete(ctx, id)
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", id, err)
ec = errcode.ErrCodeUserWxAddCheckSrvFail
return
}
return
}
func (s *Service) ApiGetUserWxAddCheckList(ctx *gin.Context, req *userwxaddcheckproto.ApiListReq) (list []*dbstruct.UserWxAddCheck, ec errcode.ErrCode) {
ec = errcode.ErrCodeUserWxAddCheckSrvOk
list, err := _DefaultUserWxAddCheck.OpList(ctx, &userwxaddcheckproto.OpListReq{
Offset: req.Offset,
Limit: req.Limit,
})
if err != nil {
logger.Error("OpGetUserWxAddCheckList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeUserWxAddCheckSrvFail
return
}
return
}
func (s *Service) ApiCreateRealNameAuthentication(ctx *gin.Context, req *realname_authenticationproto.ApiCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeRealNameAuthenticationSrvOk
// 1.业务校验,鉴权
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
EnsureIsOperatingHisOwn(util.DerefInt64(req.RealNameAuthentication.Mid)).
QueryAccount(_DefaultAccount.OpListByMid).
EnsureAccountExist().
EnsureIsThisRole(consts.Streamer).
Validate().
Collect()
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
logger.Error("ApiCreateRealNameAuthentication business validation failed")
return
}
err := _DefaultRealNameAuthentication.OpCreate(ctx, &realname_authenticationproto.OpCreateReq{
RealNameAuthentication: req.RealNameAuthentication,
})
if mongo.IsDuplicateKeyError(err) {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeRealNameAuthenticationDuplicateKey
return
}
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeRealNameAuthenticationSrvFail
return
}
return
}
func (s *Service) ApiGetRealNameAuthenticationListByMid(ctx *gin.Context, req *realname_authenticationproto.ApiListReq) (vo *realname_authenticationproto.RealNameAuthenticationApiVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeRealNameAuthenticationSrvOk
// 1.业务校验,鉴权
result := businessvalidator.NewAuthBusinessValidator(ctx, req).
EnsureIsOperatingHisOwn(util.DerefInt64(req.Mid)).
QueryAccount(_DefaultAccount.OpListByMid).
EnsureAccountExist().
EnsureIsThisRole(consts.Streamer).
Validate().
Collect()
if ec = result[0].(errcode.ErrCode); ec != errcode.ErrCodeOk {
logger.Error("OpCreateRealNameAuthentication business validation failed")
return
}
realname_authentication, err := _DefaultRealNameAuthentication.OpListByMid(ctx, &realname_authenticationproto.OpListByMidReq{
Mid: req.Mid,
})
if realname_authentication == nil {
logger.Error("No realname authentication entity found, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeRealNameAuthenticationNotExist
return
}
if err != nil {
logger.Error("OpListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeRealNameAuthenticationSrvFail
return
}
vo = &realname_authenticationproto.RealNameAuthenticationApiVO{}
vo.CopyRealNameAuthentication(realname_authentication)
return
}
// ContactCustomerService
func (s *Service) ApiCreateContactCustomerService(ctx *gin.Context, req *contact_customer_service_proto.ApiCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeContactCustomerServiceSrvOk
err := _DefaultContactCustomerService.OpCreate(ctx, &contact_customer_service_proto.OpCreateReq{
ContactCustomerService: req.ContactCustomerService,
})
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeContactCustomerServiceSrvFail
return
}
//更新session表的内容
if err := _DefaultContactCustomerServiceSession.OpUpdate(ctx, &contact_customer_service_sessionproto.OpUpdateReq{
ContactCustomerServiceSession: &dbstruct.ContactCustomerServiceSession{
Id: req.SessionId,
RecentMessage: req.Message,
},
}); err != nil {
logger.Error("Update session fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeContactCustomerServiceSessionSrvFail
return
}
return
}
func (s *Service) ApiGetContactCustomerServiceListBySessionId(ctx *gin.Context, req *contact_customer_service_proto.ApiListBySessionIdReq) (list []*dbstruct.ContactCustomerService, ec errcode.ErrCode) {
ec = errcode.ErrCodeContactCustomerServiceSrvOk
list, err := _DefaultContactCustomerService.OpListBySessionId(ctx, &contact_customer_service_proto.OpListBySessionIdReq{
SessionId: req.SessionId,
Offset: req.Offset,
Limit: req.Limit,
})
if err != nil {
logger.Error("OpGetContactCustomerServiceListBySessionId fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeContactCustomerServiceSrvFail
return
}
return
}
// ContactCustomerServiceSession
func (s *Service) ApiCreateContactCustomerServiceSession(ctx *gin.Context, req *contact_customer_service_sessionproto.ApiCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeContactCustomerServiceSessionSrvOk
err := _DefaultContactCustomerServiceSession.OpCreate(ctx, &contact_customer_service_sessionproto.OpCreateReq{
ContactCustomerServiceSession: req.ContactCustomerServiceSession,
})
if err != nil {
logger.Error("ApiCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeContactCustomerServiceSessionSrvFail
return
}
return
}
func (s *Service) ApiGetContactCustomerServiceSessionListByMid(ctx *gin.Context, req *contact_customer_service_sessionproto.ApiListByMidReq) (session *dbstruct.ContactCustomerServiceSession, ec errcode.ErrCode) {
ec = errcode.ErrCodeContactCustomerServiceSessionSrvOk
session, err := _DefaultContactCustomerServiceSession.OpListByMid(ctx, &contact_customer_service_sessionproto.OpListByMidReq{
Mid: req.Mid,
})
if err != nil {
logger.Error("OpListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeContactCustomerServiceSessionSrvFail
return
}
return
}
// Moment
func (s *Service) ApiCreateMoment(ctx *gin.Context, req *momentproto.ApiCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeMomentSrvOk
req.Moment.Mid = goproto.Int64(req.BaseRequest.Mid)
if ec = s.ApiCreateMomentBusinessValidate(ctx, req); ec != errcode.ErrCodeMomentSrvOk {
return
}
err := _DefaultMoment.OpCreate(ctx, &momentproto.OpCreateReq{
Moment: req.Moment,
})
if err != nil {
logger.Error("ApiCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMomentSrvFail
return
}
return
}
func (s *Service) ApiUpdateMoment(ctx *gin.Context, req *momentproto.ApiUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeMomentSrvOk
req.Moment.Mid = goproto.Int64(req.BaseRequest.Mid)
err := _DefaultMoment.OpUpdate(ctx, &momentproto.OpUpdateReq{
Moment: &dbstruct.Moment{
Status: req.Status,
Text: req.Text,
MediaComp: req.MediaComp,
},
})
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeMomentNotExist
err = nil
return
}
if err != nil {
logger.Error("ApiUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMomentSrvFail
return
}
return
}
func (s *Service) ApiDeleteMoment(ctx *gin.Context, id int64) (ec errcode.ErrCode) {
ec = errcode.ErrCodeMomentSrvOk
err := _DefaultMoment.OpDelete(ctx, id)
if err != nil {
logger.Error("ApiDelete fail, id: %v, err: %v", id, err)
ec = errcode.ErrCodeMomentSrvFail
return
}
return
}
func (s *Service) ApiGetMomentList(ctx *gin.Context, req *momentproto.ApiListReq) (voList []*momentproto.ApiMomentVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeMomentSrvOk
list, err := _DefaultMoment.OpList(ctx, &momentproto.OpListReq{
CtUpperBound: req.CtUpperBound,
CtLowerBound: req.CtLowerBound,
Offset: req.Offset,
Limit: req.Limit,
})
if err != nil {
logger.Error("ApiGetMomentList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMomentSrvFail
return
}
// 获取访问者的关注列表
visitorMid := req.GetBaseRequest().Mid
followMap, err := s.utilGetFollowMap(ctx, visitorMid)
if err != nil {
logger.Error("utilGetFollowMap fail")
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
// 填充主播信息
vos, ec := s.utilFillMomentsStreamerInfo(ctx, list, consts.InterfaceType_Api)
if ec != errcode.ErrCodeMomentSrvOk {
logger.Error("utilFillMomentsStreamerInfo fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMomentSrvFail
return
}
voList = make([]*momentproto.ApiMomentVO, 0)
for _, vo := range vos {
apiVO, _ := vo.(*momentproto.ApiMomentVO)
// 填充是否关注
s.utilFillIsFollowedFillable(ctx, followMap, apiVO)
// 填充是否点赞
if err := s.utilFillIsThumbedUpFillable(ctx, visitorMid, apiVO); err != nil {
logger.Error("utilFillIsThumbedUpFillable fail")
ec = errcode.ErrCodeThumbsUpSrvFail
return
}
voList = append(voList, apiVO)
}
return
}
func (s *Service) ApiGetMomentListByMid(ctx *gin.Context, req *momentproto.ApiListByMidReq) (voList []*momentproto.ApiMomentVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeMomentSrvOk
if req.Mid == nil {
req.Mid = goproto.Int64(req.BaseRequest.Mid)
}
list, err := _DefaultMoment.OpListByMid(ctx, &momentproto.OpListByMidReq{
Mid: req.Mid,
CtUpperBound: req.CtUpperBound,
CtLowerBound: req.CtLowerBound,
Offset: req.Offset,
Limit: req.Limit,
})
if err != nil {
logger.Error("ApiGetMomentListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMomentSrvFail
return
}
// 填充主播信息
vos, ec := s.utilFillMomentsStreamerInfo(ctx, list, consts.InterfaceType_Api)
if ec != errcode.ErrCodeMomentSrvOk {
logger.Error("utilFillMomentsStreamerInfo fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMomentSrvFail
return
}
voList = make([]*momentproto.ApiMomentVO, 0)
for _, vo := range vos {
apiVO, _ := vo.(*momentproto.ApiMomentVO)
voList = append(voList, apiVO)
}
return
}
func (s *Service) ApiGetMomentListByMids(ctx *gin.Context, req *momentproto.ApiListByMidsReq) (voList []*momentproto.ApiMomentVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeMomentSrvOk
list, err := _DefaultMoment.OpListByMids(ctx, &momentproto.OpListByMidsReq{
Mids: req.Mids,
CtUpperBound: req.CtUpperBound,
CtLowerBound: req.CtLowerBound,
Offset: req.Offset,
Limit: req.Limit,
})
if err != nil {
logger.Error("ApiGetMomentListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMomentSrvFail
return
}
// 获取访问者的关注列表
visitorMid := req.GetBaseRequest().Mid
followMap, err := s.utilGetFollowMap(ctx, visitorMid)
if err != nil {
logger.Error("utilGetFollowMap fail")
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
// 填充主播信息
vos, ec := s.utilFillMomentsStreamerInfo(ctx, list, consts.InterfaceType_Api)
if ec != errcode.ErrCodeMomentSrvOk {
logger.Error("utilFillMomentsStreamerInfo fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMomentSrvFail
return
}
voList = make([]*momentproto.ApiMomentVO, 0)
for _, vo := range vos {
apiVO, _ := vo.(*momentproto.ApiMomentVO)
// 填充是否关注
s.utilFillIsFollowedFillable(ctx, followMap, apiVO)
// 填充是否点赞
if err := s.utilFillIsThumbedUpFillable(ctx, visitorMid, apiVO); err != nil {
logger.Error("utilFillIsThumbedUpFillable fail")
ec = errcode.ErrCodeThumbsUpSrvFail
return
}
voList = append(voList, apiVO)
}
return
}
func (s *Service) ApiGetMomentListByIds(ctx *gin.Context, req *momentproto.ApiListByIdsReq) (voList []*momentproto.ApiMomentVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeMomentSrvOk
list, err := _DefaultMoment.OpListByIds(ctx, &momentproto.OpListByIdsReq{
Ids: req.Ids,
})
if err != nil {
logger.Error("ApiGetMomentListByIds fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMomentSrvFail
return
}
// 填充主播信息
vos, ec := s.utilFillMomentsStreamerInfo(ctx, list, consts.InterfaceType_Api)
if ec != errcode.ErrCodeMomentSrvOk {
logger.Error("utilFillMomentsStreamerInfo fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMomentSrvFail
return
}
voList = make([]*momentproto.ApiMomentVO, 0)
for _, vo := range vos {
opVO, _ := vo.(*momentproto.ApiMomentVO)
voList = append(voList, opVO)
}
return
}
func (s *Service) ApiThumbsUpMoment(ctx *gin.Context, req *momentproto.ApiThumbsUpReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeMomentSrvOk
req.Mid = goproto.Int64(req.BaseRequest.Mid)
times := util.DerefInt64(req.Times)
if times != 1 && times == -1 {
ec = errcode.ErrCodeMomentSrvFail
}
//点赞
if times == 1 {
ec = s.utilThumbsUpMoment(ctx, &momentproto.OpThumbsUpReq{
MomentId: req.MomentId,
Mid: req.Mid,
Times: req.Times,
})
} else if times == -1 { //取消点赞
ec = s.utilUnThumbsUpMoment(ctx, &momentproto.OpThumbsUpReq{
MomentId: req.MomentId,
Mid: req.Mid,
Times: req.Times,
})
}
return
}
func (s *Service) ApiGetThumbsUpList(ctx *gin.Context, req *thumbsupproto.ApiListReq) (list []*dbstruct.ThumbsUp, ec errcode.ErrCode) {
ec = errcode.ErrCodeThumbsUpSrvOk
list, err := _DefaultThumbsUp.OpList(ctx, &thumbsupproto.OpListReq{
MomentId: req.MomentId,
Offset: req.Offset,
Limit: req.Limit,
})
if err != nil {
logger.Error("ApiGetThumbsUpList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeThumbsUpSrvFail
return
}
return
}
func (s *Service) ApiGetAppConfigListByKey(ctx *gin.Context, req *appconfigproto.ApiListByKeyReq) (appconfig *dbstruct.AppConfig, ec errcode.ErrCode) {
ec = errcode.ErrCodeAppConfigSrvOk
appconfig, err := _DefaultAppConfig.OpListByKey(ctx, &appconfigproto.OpListByKeyReq{
ConfigKey: req.ConfigKey,
})
if err != nil {
logger.Error("OpGetAppConfigListByKey fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAppConfigSrvFail
return
}
return
}