service/app/mix/service/service.go

2491 lines
78 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 (
"errors"
"fmt"
"service/api/base"
"service/api/consts"
"service/api/errcode"
"service/api/errs"
accountproto "service/api/proto/account/proto"
accountrelationproto "service/api/proto/accountrelation/proto"
bannerproto "service/api/proto/banner/proto"
callhistoryproto "service/api/proto/callhistory/proto"
catalogproto "service/api/proto/catalog/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"
footprintproto "service/api/proto/footprint/proto"
imageauditproto "service/api/proto/imageaudit/proto"
imageaudittaskproto "service/api/proto/imageaudittask/proto"
loginproto "service/api/proto/login/proto"
mediaproto "service/api/proto/media/proto"
momentproto "service/api/proto/moment/proto"
productproto "service/api/proto/product/proto"
realname_authenticationproto "service/api/proto/realname_authentication/proto"
resourceproto "service/api/proto/resource/proto"
streamerproto "service/api/proto/streamer/proto"
streamerauthapprovalproto "service/api/proto/streamerauthapproval/proto"
streamerlinkproto "service/api/proto/streamerlink/proto"
textauditproto "service/api/proto/textaudit/proto"
textaudittaskproto "service/api/proto/textaudittask/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"
"service/app/mix/conf"
"service/app/mix/dao"
"service/app/mix/service/logic"
"service/bizcommon/util"
"service/dbstruct"
"service/library/apollo"
"service/library/contentaudit/imageaudit"
"service/library/contentaudit/textaudit"
"service/library/logger"
"service/library/melody"
"service/library/mycrypto"
"service/library/payclients/alipaycli"
"service/library/redis"
"go.mongodb.org/mongo-driver/mongo"
goproto "google.golang.org/protobuf/proto"
//"service/library/melody"
"github.com/gin-gonic/gin"
"github.com/qiniu/qmgo"
)
var (
DefaultService *Service
)
var (
_DefaultToken *logic.Token
_DefaultVeriCode *logic.VeriCode
_DefaultAccount *logic.Account
_DefaultProduct *logic.Product
_DefaultCatalog *logic.Catalog
_DefaultVas *logic.Vas
_DefaultResource *logic.Resource
_DefaultBanner *logic.Banner
_DefaultLogin *logic.Login
_DefaultMoment *logic.Moment
_DefaultFootPrint *logic.FootPrint
_DefaultThumbsUp *logic.ThumbsUp
_DefaultAccountRelation *logic.AccountRelation
_DefaultStreamerAuthApproval *logic.StreamerAuthApproval
_DefaultStreamer *logic.Streamer
_DefaultMedia *logic.Media
_DefaultFeedback *logic.Feedback
_DefaultCallHistory *logic.CallHistory
_DefaultStreamerLink *logic.StreamerLink
_DefaultUserWxAddCheck *logic.UserWxAddCheck
_DefaultUserId *logic.UserIdSeq
_DefaultRealNameAuthentication *logic.RealNameAuthentication
_DefaultContactCustomerService *logic.ContactCustomerService
_DefaultImageAudit *logic.ImageAudit
_DefaultImageAuditTask *logic.ImageAuditTask
_DefaultTextAudit *logic.TextAudit
_DefaultTextAuditTask *logic.TextAuditTask
_DefaultContactCustomerServiceSession *logic.ContactCustomerServiceSession
)
type Service struct {
defaultMelody *melody.Melody
}
func NewService() *Service {
return new(Service)
}
func (s *Service) Init(c any) (err error) {
cfg, ok := c.(*conf.ConfigSt)
if !ok {
err = errors.New("cfg struct type not expected")
logger.Error("service init, err: %v", err)
return
}
store, err := dao.NewStore(cfg)
if err != nil {
logger.Error("NewStore fail, cfg: %v, err: %v", util.ToJson(cfg), err)
return
}
if err = mycrypto.CryptoServiceInstance().Init(cfg.Crypto); err != nil {
logger.Error("cryptoService init, err: %v", err)
}
s.defaultMelody = melody.New()
err = alipaycli.Init(cfg.Alipay)
if err != nil {
logger.Error("alipaycli.Init fail, cfg: %v, err: %v", util.ToJson(cfg), err)
return
}
_DefaultToken = logic.NewToken(store, cfg.Crypto)
_DefaultVeriCode = logic.NewVeriCode(store, cfg.Dysmsapi)
_DefaultAccount = logic.NewAccount(store)
_DefaultProduct = logic.NewProduct(store)
_DefaultCatalog = logic.NewCatalog(store)
_DefaultVas = logic.NewVas(store)
_DefaultResource = logic.NewResource(store)
_DefaultBanner = logic.NewBanner(store)
_DefaultLogin = logic.NewLogin(store)
_DefaultMoment = logic.NewMoment(store)
_DefaultFootPrint = logic.NewFootPrint(store)
_DefaultThumbsUp = logic.NewThumbsUp(store)
_DefaultAccountRelation = logic.NewAccountRelation(store)
_DefaultStreamerAuthApproval = logic.NewStreamerAuthApproval(store)
_DefaultStreamer = logic.NewStreamer(store)
_DefaultMedia = logic.NewMedia(store, cfg.Media)
_DefaultFeedback = logic.NewFeedback(store)
_DefaultCallHistory = logic.NewCallHistory(store)
_DefaultStreamerLink = logic.NewStreamerLink(store)
_DefaultUserWxAddCheck = logic.NewUserWxAddCheck(store)
_DefaultRealNameAuthentication = logic.NewRealNameAuthentication(store)
_DefaultContactCustomerService = logic.NewContactCustomerService(store)
_DefaultUserId = logic.NewUserIdSeq(store)
_DefaultImageAudit = logic.NewImageAudit(store)
_DefaultImageAuditTask = logic.NewImageAuditTask(store)
_DefaultTextAudit = logic.NewTextAudit(store)
_DefaultTextAuditTask = logic.NewTextAuditTask(store)
_DefaultContactCustomerServiceSession = logic.NewContactCustomerServiceSession(store)
return
}
func (s *Service) GetDefaultMelody() *melody.Melody {
return s.defaultMelody
}
func (s *Service) Run() {
go s.defaultMelody.HandleMessage(func(session *melody.Session, msg []byte) {
logger.Info("recv msg: %s", string(msg))
s.defaultMelody.Broadcast(msg)
})
}
func (s *Service) Stop() {
}
// 图像审核接口
func (s *Service) ConnectToImageAudit() {
imageaudit.ConnectToImageAuditService(_DefaultImageAudit)
imageaudit.ConnectToImageAuditTaskService(_DefaultImageAuditTask)
textaudit.ConnectToTextAuditService(_DefaultTextAudit)
textaudit.ConnectToTextAuditTaskService(_DefaultTextAuditTask)
}
// Product
func (s *Service) OpCreateProduct(ctx *gin.Context, req *productproto.OpCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeProductSrvOk
err := _DefaultProduct.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeProductSrvFail
return
}
return
}
func (s *Service) OpUpdateProduct(ctx *gin.Context, req *productproto.OpUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeProductSrvOk
err := _DefaultProduct.OpUpdate(ctx, req)
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeProductNotExist
err = nil
return
}
if err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeProductSrvFail
return
}
return
}
func (s *Service) OpDeleteProduct(ctx *gin.Context, id int64) (ec errcode.ErrCode) {
ec = errcode.ErrCodeProductSrvOk
err := _DefaultProduct.OpDelete(ctx, id)
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", id, err)
ec = errcode.ErrCodeProductSrvFail
return
}
return
}
func (s *Service) OpGetProductList(ctx *gin.Context, req *productproto.OpListReq) (list []*dbstruct.Product, ec errcode.ErrCode) {
ec = errcode.ErrCodeProductSrvOk
list, err := _DefaultProduct.OpList(ctx, req)
if err != nil {
logger.Error("OpDelete fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeProductSrvFail
return
}
return
}
// Catalog
func (s *Service) OpCreateCatalog(ctx *gin.Context, req *catalogproto.OpCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeCatalogSrvOk
err := _DefaultCatalog.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeCatalogSrvFail
return
}
return
}
func (s *Service) OpUpdateCatalog(ctx *gin.Context, req *catalogproto.OpUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeCatalogSrvOk
err := _DefaultCatalog.OpUpdate(ctx, req)
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeCatalogNotExist
err = nil
return
}
if err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeCatalogSrvFail
return
}
return
}
func (s *Service) OpDeleteCatalog(ctx *gin.Context, id int64) (ec errcode.ErrCode) {
ec = errcode.ErrCodeCatalogSrvOk
err := _DefaultCatalog.OpDelete(ctx, id)
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", id, err)
ec = errcode.ErrCodeCatalogSrvFail
return
}
return
}
func (s *Service) OpGetCatalogList(ctx *gin.Context, req *catalogproto.OpListReq) (list []*dbstruct.Catalog, ec errcode.ErrCode) {
ec = errcode.ErrCodeCatalogSrvOk
list, err := _DefaultCatalog.OpList(ctx, req)
if err != nil {
logger.Error("OpDelete fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeCatalogSrvFail
return
}
return
}
// banner
func (s *Service) OpCreateBanner(ctx *gin.Context, req *bannerproto.OpCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeBannerSrvOk
err := _DefaultBanner.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeBannerSrvFail
return
}
return
}
func (s *Service) OpUpdateBanner(ctx *gin.Context, req *bannerproto.OpUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeBannerSrvOk
err := _DefaultBanner.OpUpdate(ctx, req)
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeProductNotExist
err = nil
return
}
if err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeBannerSrvFail
return
}
return
}
func (s *Service) OpDeleteBanner(ctx *gin.Context, id int64) (ec errcode.ErrCode) {
ec = errcode.ErrCodeBannerSrvOk
err := _DefaultBanner.OpDelete(ctx, id)
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", id, err)
ec = errcode.ErrCodeBannerSrvFail
return
}
return
}
func (s *Service) OpGetBannerList(ctx *gin.Context, req *bannerproto.OpListReq) (list []*dbstruct.Banner, ec errcode.ErrCode) {
ec = errcode.ErrCodeBannerSrvOk
list, err := _DefaultBanner.OpList(ctx, req)
if err != nil {
logger.Error("OpDelete fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeBannerSrvFail
return
}
return
}
// resource
func (s *Service) OpSetL2CatalogIndex(ctx *gin.Context, req *resourceproto.OpSetL2CatalogIndexReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeResourceSrvOk
err := _DefaultResource.OpSetL2CatalogIndex(ctx, req.List)
if err != nil {
logger.Error("OpSetL2CatalogIndex fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeResourceSrvFail
return
}
return
}
func (s *Service) OpGetL2CatalogIndexByL1Id(ctx *gin.Context, l1Id int64) (list []*dbstruct.L2CatalogIndex, ec errcode.ErrCode) {
ec = errcode.ErrCodeResourceSrvOk
list, err := _DefaultResource.OpGetL2CatalogIndexByL1Id(ctx, l1Id)
if err != nil {
logger.Error("OpGetL2CatalogIndexByL1Id fail, err: %v", err)
ec = errcode.ErrCodeResourceSrvFail
return
}
return
}
func (s *Service) GetL2CatalogListByL1Id(ctx *gin.Context, l1Id int64) (list []*dbstruct.Catalog, ec errcode.ErrCode) {
list = make([]*dbstruct.Catalog, 0)
ec = errcode.ErrCodeResourceSrvOk
// 获取l2分类顺序
indexList, err := _DefaultResource.OpGetL2CatalogIndexByL1Id(ctx, l1Id)
if err != nil {
logger.Error("OpGetL2CatalogIndexByL1Id fail, l1Id: %v, err: %v", l1Id, err)
ec = errcode.ErrCodeResourceSrvFail
return
}
// 获取l2分类内容
l2Ids := make([]int64, len(indexList))
for i := 0; i < len(indexList); i++ {
l2Ids[i] = indexList[i].L2Id
}
catalogList, err := _DefaultCatalog.GetListByIds(ctx, l2Ids)
catalogMap := make(map[int64]*dbstruct.Catalog)
for _, catalog := range catalogList {
catalogMap[catalog.Id] = catalog
}
for _, l2Id := range l2Ids {
if catalog, ok := catalogMap[l2Id]; ok {
list = append(list, catalog)
}
}
return
}
func (s *Service) OpSetBannerIndex(ctx *gin.Context, req *resourceproto.OpSetBannerIndexReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeResourceSrvOk
err := _DefaultResource.OpSetBannerIndex(ctx, req.List)
if err != nil {
logger.Error("OpSetBannerIndex fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeResourceSrvFail
return
}
return
}
func (s *Service) OpGetBannerIndex(ctx *gin.Context) (list []*dbstruct.BannerIndex, ec errcode.ErrCode) {
ec = errcode.ErrCodeResourceSrvOk
list, err := _DefaultResource.OpGetBannerIndex(ctx)
if err != nil {
logger.Error("OpGetBannerIndex fail, err: %v", err)
ec = errcode.ErrCodeResourceSrvFail
return
}
return
}
func (s *Service) GetBannerList(ctx *gin.Context) (list []*dbstruct.Banner, ec errcode.ErrCode) {
list = make([]*dbstruct.Banner, 0)
ec = errcode.ErrCodeResourceSrvOk
// 获取banner顺序
indexList, err := _DefaultResource.OpGetBannerIndex(ctx)
if err != nil {
logger.Error("OpGetBannerIndex fail, err: %v", err)
ec = errcode.ErrCodeResourceSrvFail
return
}
// 获取banner内容
ids := make([]int64, len(indexList))
for i := 0; i < len(indexList); i++ {
ids[i] = indexList[i].Id
}
bannerList, err := _DefaultBanner.GetListByIds(ctx, ids)
bannerMap := make(map[int64]*dbstruct.Banner)
for _, banner := range bannerList {
bannerMap[banner.Id] = banner
}
for _, id := range ids {
if banner, ok := bannerMap[id]; ok {
list = append(list, banner)
}
}
return
}
// 发送验证码
func (s *Service) OpSendVeriCode(ctx *gin.Context, req *vericodeproto.OpSendReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeResourceSrvOk
err := _DefaultVeriCode.OpSendVeriCode(ctx, req)
if err != nil {
logger.Error("OpSendVeriCode fail, err: %v", err)
ec = errcode.ErrCodeLoginSrvFail
return
}
return
}
// 密码登录
func (s *Service) OpLoginByPswd(ctx *gin.Context, req *loginproto.OpLoginByPswdReq) (isEnabled int64, token string, accountVO *accountproto.OpListVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeLoginSrvOk
// 1.业务校验
login, account, ec := s.OpLoginByPswdBusinessValidate(ctx, req)
if ec != errcode.ErrCodeLoginSrvOk {
return
}
// 2.让已登录的用户强制下线
if util.DerefInt64(login.IsLogined) == 1 {
if _, ec = s.OpLogout(ctx, &loginproto.OpLogoutReq{
Mid: account.Mid,
}); ec != errcode.ErrCodeLoginSrvOk {
logger.Error("OpLogout 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("OpGenerate 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("OpUpdate failed, err: %v", err)
return
}
// 5.组装返回信息
accountVO = &accountproto.OpListVO{}
accountVO.CopyAccount(account)
return
}
func (s *Service) OpLoginByVeriCode(ctx *gin.Context, req *loginproto.OpLoginByVeriCodeReq) (isEnabled int64, token string, accountVO *accountproto.OpListVO, 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.OpLoginByVeriCodeBusinessValidate(ctx, req)
// 2.如果错误码是登录信息不存在,则判断为首次登录,将创建用户信息
if ec == errcode.ErrCodeLoginNotExist {
login, account, ec = s.utilRegisterUser(ctx, &req.MobilePhoneInfoComponent)
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 OpDelete failed, err: %v", err)
ec = errcode.ErrCodeLoginSrvFail
return
}
// 4.让已登录的用户强制下线
if util.DerefInt64(login.IsLogined) == 1 {
if _, ec = s.OpLogout(ctx, &loginproto.OpLogoutReq{
Mid: account.Mid,
}); ec != errcode.ErrCodeLoginSrvOk {
logger.Error("OpLogout 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("OpGenerate 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("OpUpdate failed, err: %v", err)
return
}
// 7.组装返回信息
isEnabled = util.DerefInt64(login.IsEnabled)
accountVO = &accountproto.OpListVO{}
accountVO.CopyAccount(account)
return
}
func (s *Service) OpLogout(ctx *gin.Context, req *loginproto.OpLogoutReq) (logoutData *loginproto.OpLogoutData, ec errcode.ErrCode) {
ec = errcode.ErrCodeLoginSrvOk
if err := _DefaultToken.OpDeleteByMid(ctx, util.DerefInt64(req.Mid)); err != nil {
logger.Error("OpDeleteByMid 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("OpUpdateByMid failed, err: %v", err)
return
}
logoutData = &loginproto.OpLogoutData{
OpResult: true,
}
return
}
// 登录后第一次设置密码
func (s *Service) OpSetPassword(ctx *gin.Context, req *loginproto.OpSetPswdReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeLoginSrvOk
// 1.业务校验
login, _, ec := s.OpSetPasswordBusinessValidate(ctx, req)
if ec != errcode.ErrCodeLoginSrvOk {
return
}
// 2.更新密码,置为启用
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("OpUpdate failed : %v", err)
ec = errcode.ErrCodeLoginSrvFail
return
}
return
}
// 重置密码
func (s *Service) OpResetPassword(ctx *gin.Context, req *loginproto.OpResetPswdReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeLoginSrvOk
// 1.业务校验
login, _, vericode, ec := s.OpResetPasswordBusinessValidate(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("OpUpdate failed : %v", err)
ec = errcode.ErrCodeLoginSrvFail
return
}
return
}
func (s *Service) OpUpdatePassword(ctx *gin.Context, req *loginproto.OpUpdatePswdReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeLoginSrvOk
// 1.业务校验
login, _, vericode, ec := s.OpUpdatePasswordBusinessValidate(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("OpUpdate failed : %v", err)
ec = errcode.ErrCodeLoginSrvFail
return
}
return
}
// Account
func (s *Service) OpUpdateAccount(ctx *gin.Context, req *accountproto.OpUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
// 业务鉴权
if ec = s.OpUpdateAccountBusinessValidate(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
}
// 创建审核任务
textaudittask := s.CreateUpdateAccountTextAudit(ctx, oldAccount, req.Account)
// 运营只可操作用户的昵称
err = _DefaultAccount.OpUpdate(ctx, &accountproto.OpUpdateReq{
Account: &dbstruct.Account{
Mid: req.Account.Mid,
Name: req.Account.Name,
},
})
if err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountSrvFail
return
}
// 审核任务加入队列
if textaudittask != nil {
textaudit.AddTask(textaudittask)
}
return
}
func (s *Service) OpGetAccountListByMid(ctx *gin.Context, req *accountproto.OpListByMidReq) (vo *accountproto.OpListVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
account, err := _DefaultAccount.OpListByMid(ctx, req)
if err != nil {
logger.Error("OpListByMid fail, err: %v", err)
ec = errcode.ErrCodeAccountSrvFail
return
}
vo = &accountproto.OpListVO{}
vo.CopyAccount(account)
return
}
func (s *Service) OpGetAccountListByMids(ctx *gin.Context, req *accountproto.OpListByMidsReq) (volist []*accountproto.OpListVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
list, err := _DefaultAccount.OpListByMids(ctx, req)
if err != nil {
logger.Error("OpListByMids fail, err: %v", err)
ec = errcode.ErrCodeAccountSrvFail
return
}
volist = make([]*accountproto.OpListVO, len(list))
for i, account := range list {
volist[i] = &accountproto.OpListVO{}
volist[i].CopyAccount(account)
}
return
}
func (s *Service) OpGetAccountListByUserId(ctx *gin.Context, req *accountproto.OpListByUserIdReq) (vo *accountproto.OpListVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
// 业务鉴权
if ec = s.OpGetAccountListByUserIdBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountSrvOk {
return
}
account, err := _DefaultAccount.OpListByUserId(ctx, req)
if err != nil {
logger.Error("OpListByUserId fail, err: %v", err)
ec = errcode.ErrCodeAccountSrvFail
return
}
vo = &accountproto.OpListVO{}
vo.CopyAccount(account)
return
}
func (s *Service) OpGetAccountListFuzzilyByUserId(ctx *gin.Context, req *accountproto.OpListFuzzilyByUserIdReq) (volist []*accountproto.OpListVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
// 业务鉴权
if ec = s.OpGetAccountListFuzzilyByUserIdBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountSrvOk {
return
}
list, err := _DefaultAccount.OpListFuzzilyByUserId(ctx, req)
if err != nil {
logger.Error("OpListFuzzilyByUserId fail, err: %v", err)
ec = errcode.ErrCodeAccountSrvFail
return
}
volist = make([]*accountproto.OpListVO, len(list))
for i, account := range list {
volist[i] = &accountproto.OpListVO{}
volist[i].CopyAccount(account)
}
return
}
func (s *Service) OpGetAccountListFuzzilyByName(ctx *gin.Context, req *accountproto.OpListFuzzilyByNameReq) (volist []*accountproto.OpListVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
// 业务鉴权
if ec = s.OpGetAccountListFuzzilyByNameBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountSrvOk {
return
}
list, err := _DefaultAccount.OpListFuzzilyByName(ctx, req)
if err != nil {
logger.Error("OpListFuzzilyByName fail, err: %v", err)
ec = errcode.ErrCodeAccountSrvFail
return
}
volist = make([]*accountproto.OpListVO, len(list))
for i, account := range list {
volist[i] = &accountproto.OpListVO{}
volist[i].CopyAccount(account)
}
return
}
func (s *Service) OpGetAccountListForOthersByMid(ctx *gin.Context, req *accountproto.OpListOthersByMidReq) (vo *accountproto.OpListOthersVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
if ec = s.OpGetAccountListForOthersByMiBusinessValidated(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.OpListOthersVO{}
vo.CopyAccount(account)
return
}
func (s *Service) OpGetAccountListForOthersByMids(ctx *gin.Context, req *accountproto.OpListOthersByMidsReq) (volist []*accountproto.OpListOthersVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountSrvOk
if ec = s.OpGetAccountListForOthersByMidsBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountSrvOk {
return
}
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.OpListOthersVO, len(list))
for i, account := range list {
volist[i] = &accountproto.OpListOthersVO{}
volist[i].CopyAccount(account)
}
return
}
// Token
func (s *Service) OpVerifyToken(ctx *gin.Context, token string) (err error) {
if err = _DefaultToken.OpVerify(ctx, token); err != nil {
logger.Error("OpVerifyToken fail, err :%v", err)
return
}
return
}
// Vas
func (s *Service) GetCoinsProductList(ctx *gin.Context, req *vasproto.GetCoinsProductListReq) (data *vasproto.GetCoinsProductListData, ec errcode.ErrCode) {
ec = errcode.ErrCodeVasSrvOk
ok := false
listH5alipay, err := _DefaultVas.GetCoinsProductList(ctx, req)
if err != nil {
logger.Error("CreateOrder fail, err: %v", err)
ec, ok = errs.ErrEcMap[err]
if ok {
return
}
ec = errcode.ErrCodeVasSrvFail
return
}
data = &vasproto.GetCoinsProductListData{
ListAlipayH5: listH5alipay,
}
return
}
func (s *Service) CreateOrder(ctx *gin.Context, req *vasproto.CreateOrderReq) (data *vasproto.CreateOrderData, ec errcode.ErrCode) {
data, err := _DefaultVas.CreateOrder(ctx, req)
ec, err = errs.DealVasErr(err)
if err != nil {
logger.Error("CreateOrder fail, err: %v", err)
return
}
return
}
func (s *Service) OpCreateOrder(ctx *gin.Context, req *vasproto.OpCreateOrderReq) (ec errcode.ErrCode) {
err := _DefaultVas.OpCreateOrder(ctx, req)
ec, err = errs.DealVasErr(err)
if err != nil {
logger.Error("OpCreateOrder fail, err: %v", err)
return
}
return
}
// Moment
func (s *Service) OpCreateMoment(ctx *gin.Context, req *momentproto.OpCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeMomentSrvOk
err := _DefaultMoment.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMomentSrvFail
return
}
return
}
func (s *Service) OpUpdateMoment(ctx *gin.Context, req *momentproto.OpUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeMomentSrvOk
err := _DefaultMoment.OpUpdate(ctx, req)
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeMomentNotExist
err = nil
return
}
if err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMomentSrvFail
return
}
return
}
func (s *Service) OpDeleteMoment(ctx *gin.Context, id int64) (ec errcode.ErrCode) {
ec = errcode.ErrCodeMomentSrvOk
err := _DefaultMoment.OpDelete(ctx, id)
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", id, err)
ec = errcode.ErrCodeMomentSrvFail
return
}
return
}
func (s *Service) OpGetMomentList(ctx *gin.Context, req *momentproto.OpListReq) (list []*dbstruct.Moment, ec errcode.ErrCode) {
ec = errcode.ErrCodeMomentSrvOk
list, err := _DefaultMoment.OpList(ctx, req)
if err != nil {
logger.Error("OpGetMomentList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMomentSrvFail
return
}
return
}
func (s *Service) OpThumbsUpMoment(ctx *gin.Context, req *momentproto.OpThumbsUpReq) (moment *dbstruct.Moment, ec errcode.ErrCode) {
ec = errcode.ErrCodeMomentSrvOk
moment, err := _DefaultMoment.OpThumbsUp(ctx, req)
if err != nil {
logger.Error("OpThumbsUp fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMomentSrvFail
return
}
return
}
// FootPrint
func (s *Service) OpCreateFootPrint(ctx *gin.Context, req *footprintproto.OpCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeFootPrintSrvOk
err := _DefaultFootPrint.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeFootPrintSrvFail
return
}
return
}
func (s *Service) OpDeleteFootPrint(ctx *gin.Context, req *footprintproto.OpDeleteReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeFootPrintSrvOk
err := _DefaultFootPrint.OpDelete(ctx, req)
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeFootPrintSrvFail
return
}
return
}
func (s *Service) OpGetViewFootPrintList(ctx *gin.Context, req *footprintproto.OpListReq) (list []*dbstruct.FootPrint, ec errcode.ErrCode) {
ec = errcode.ErrCodeFootPrintSrvOk
list, err := _DefaultFootPrint.OpListView(ctx, req)
if err != nil {
logger.Error("OpListView fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeFootPrintSrvFail
return
}
return
}
func (s *Service) OpGetIsViewedFootPrintList(ctx *gin.Context, req *footprintproto.OpListReq) (list []*dbstruct.FootPrint, ec errcode.ErrCode) {
ec = errcode.ErrCodeFootPrintSrvOk
list, err := _DefaultFootPrint.OpListIsViewed(ctx, req)
if err != nil {
logger.Error("OpListIsViewed fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeFootPrintSrvFail
return
}
return
}
func (s *Service) OpGetFootPrintCount(ctx *gin.Context, req *footprintproto.OpCountReq) (countMap map[int64]int64, ec errcode.ErrCode) {
ec = errcode.ErrCodeFootPrintSrvOk
countMap, err := _DefaultFootPrint.OpCount(ctx, req)
if err != nil {
logger.Error("OpCount fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeFootPrintSrvFail
return
}
return
}
// ThumbsUp
func (s *Service) OpCreateThumbsUp(ctx *gin.Context, req *thumbsupproto.OpCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeThumbsUpSrvOk
err := _DefaultThumbsUp.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeThumbsUpSrvFail
return
}
return
}
func (s *Service) OpDeleteThumbsUp(ctx *gin.Context, req *thumbsupproto.OpDeleteReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeThumbsUpSrvOk
err := _DefaultThumbsUp.OpDelete(ctx, req)
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeThumbsUpSrvFail
return
}
return
}
func (s *Service) OpGetThumbsUpList(ctx *gin.Context, req *thumbsupproto.OpListReq) (list []*dbstruct.ThumbsUp, ec errcode.ErrCode) {
ec = errcode.ErrCodeThumbsUpSrvOk
list, err := _DefaultThumbsUp.OpList(ctx, req)
if err != nil {
logger.Error("OpGetThumbsUpList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeThumbsUpSrvFail
return
}
return
}
// AccountRelation
func (s *Service) OpGetFollowAccountRelationList(ctx *gin.Context, req *accountrelationproto.OpListReq) (list []*dbstruct.AccountRelation, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
//业务校验
if ec = s.OpGetFollowAccountRelationListBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
list, err := _DefaultAccountRelation.OpListBySubMidAndPredicate(ctx, &accountrelationproto.OpListBySubMidAndPredicateReq{
SubMid: req.Mid,
Predicate: goproto.Int64(consts.Follow),
})
if err != nil {
logger.Error("OpListBySubMidAndPredicate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
func (s *Service) OpGetIsFollowedAccountRelationList(ctx *gin.Context, req *accountrelationproto.OpListReq) (list []*dbstruct.AccountRelation, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
//业务校验
if ec = s.OpGetIsFollowedAccountRelationListBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
list, err := _DefaultAccountRelation.OpListBySubMidAndPredicate(ctx, &accountrelationproto.OpListBySubMidAndPredicateReq{
SubMid: req.Mid,
Predicate: goproto.Int64(consts.IsFollowed),
})
if err != nil {
logger.Error("OpListBySubMidAndPredicate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
func (s *Service) OpGetFriendAccountRelationList(ctx *gin.Context, req *accountrelationproto.OpListReq) (list []*dbstruct.AccountRelation, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
if ec = s.OpGetFriendAccountRelationListBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
list, err := _DefaultAccountRelation.OpListFriend(ctx, req)
if err != nil {
logger.Error("OpListFriend fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
func (s *Service) OpGetIgnoreAccountRelationList(ctx *gin.Context, req *accountrelationproto.OpListReq) (list []*dbstruct.AccountRelation, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
if ec = s.OpGetIgnoreAccountRelationListBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
list, err := _DefaultAccountRelation.OpListBySubMidAndPredicate(ctx, &accountrelationproto.OpListBySubMidAndPredicateReq{
SubMid: req.Mid,
Predicate: goproto.Int64(consts.Ignore),
})
if err != nil {
logger.Error("OpListBySubMidAndPredicate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
func (s *Service) OpGetAbleToAccessWeixinOfAccountRelationList(ctx *gin.Context, req *accountrelationproto.OpListReq) (list []*dbstruct.AccountRelation, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
if ec = s.OpGetAbleToAccessWeixinOfAccountRelationListBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
list, err := _DefaultAccountRelation.OpListBySubMidAndPredicate(ctx, &accountrelationproto.OpListBySubMidAndPredicateReq{
SubMid: req.Mid,
Predicate: goproto.Int64(consts.AbleToAccessWeixinOf),
})
if err != nil {
logger.Error("OpListBySubMidAndPredicate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
func (s *Service) OpGetAccountRelationCount(ctx *gin.Context, req *accountrelationproto.OpCountReq) (countMap map[int64]int64, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
if ec = s.OpGetAccountRelationCountBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
countMap, err := _DefaultAccountRelation.OpCount(ctx, req)
if err != nil {
logger.Error("OpCount fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
return
}
func (s *Service) OpGetIsFollowedAccountRelationCount(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) OpGetAccountRelationBySentence(ctx *gin.Context, req *accountrelationproto.OpListBySentenceReq) (accountrelation *dbstruct.AccountRelation, ec errcode.ErrCode) {
ec = errcode.ErrCodeAccountRelationSrvOk
if ec = s.OpGetAccountRelationBySentenceBusinessValidate(ctx, req); ec != errcode.ErrCodeAccountRelationSrvOk {
return
}
accountrelation, err := _DefaultAccountRelation.OpListBySentence(ctx, req)
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
}
// StreamerAuthApproval
// func (s *Service) OpCreateStreamerAuthApproval(ctx *gin.Context, req *streamerauthapprovalproto.OpCreateReq) (ec errcode.ErrCode) {
// ec = errcode.ErrCodeStreamerAuthApprovalSrvOk
// err := _DefaultStreamerAuthApproval.OpCreate(ctx, req)
// if mongo.IsDuplicateKeyError(err) {
// logger.Error("OpCreate 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) OpUpdateStreamerAuthApproval(ctx *gin.Context, req *streamerauthapprovalproto.OpUpdateReq) (ec errcode.ErrCode) {
// ec = errcode.ErrCodeStreamerAuthApprovalSrvOk
// err := _DefaultStreamerAuthApproval.OpUpdate(ctx, req)
// if err == qmgo.ErrNoSuchDocuments {
// ec = errcode.ErrCodeStreamerAuthApprovalNotExist
// err = nil
// return
// }
// if err != nil {
// logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
// ec = errcode.ErrCodeStreamerAuthApprovalSrvFail
// return
// }
// return
// }
// func (s *Service) OpDeleteBatchStreamerAuthApproval(ctx *gin.Context, ids []int64) (ec errcode.ErrCode) {
// ec = errcode.ErrCodeStreamerAuthApprovalSrvOk
// err := _DefaultStreamerAuthApproval.OpDeleteBatch(ctx, ids)
// if err != nil {
// logger.Error("OpDeleteBatch fail, ids: %v, err: %v", ids, err)
// ec = errcode.ErrCodeStreamerAuthApprovalSrvFail
// return
// }
// return
// }
func (s *Service) OpGetStreamerAuthApprovalList(ctx *gin.Context, req *streamerauthapprovalproto.OpListReq) (list []*dbstruct.StreamerAuthApproval, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerAuthApprovalSrvOk
if ec = s.OpGetStreamerAuthApprovalListBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerAuthApprovalSrvOk {
return
}
list, err := _DefaultStreamerAuthApproval.OpList(ctx, req)
if err != nil {
logger.Error("OpGetStreamerAuthApprovalList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerAuthApprovalSrvFail
return
}
return
}
func (s *Service) OpApproveStreamerAuthApproval(ctx *gin.Context, req *streamerauthapprovalproto.OpApproveReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerAuthApprovalSrvOk
if ec = s.OpApproveStreamerAuthApprovalBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerAuthApprovalSrvOk {
return
}
//1.更新状态
err := _DefaultStreamerAuthApproval.OpUpdateStreamerAuthApprovalByIds(ctx, &streamerauthapprovalproto.OpUpdateByIdsReq{
BaseRequest: req.BaseRequest,
StreamerAuthApproval: &dbstruct.StreamerAuthApproval{
Status: req.ApproveStatus,
Remarks: req.Remarks,
},
Ids: req.Ids,
})
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeStreamerAuthApprovalNotExist
err = nil
return
}
if err != nil {
logger.Error("OpUpdateStreamerAuthApprovalByIds fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerAuthApprovalSrvFail
return
}
//2.若是审批失败,则更新之后直接删除,审批失败的信息将流转到历史表里保存
if util.DerefInt64(req.ApproveStatus) == consts.Rejected {
err := _DefaultStreamerAuthApproval.OpDeleteBatch(ctx, req.Ids)
if err != nil {
logger.Error("OpDeleteBatch fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerAuthApprovalSrvFail
return
}
return
}
//3.查询获取这些认证申请
list, err := _DefaultStreamerAuthApproval.GetStreamerAuthApprovalListByIds(ctx, req.Ids)
if err != nil {
logger.Error("GetStreamerAuthApprovalListByIds fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerAuthApprovalSrvFail
return
}
//4.若是审批通过将审批表的信息合并进主播表创建信息并更新account表里的角色信息为主播
if util.DerefInt64(req.ApproveStatus) == consts.Approved {
// 构建streamer信息
streamerList := make([]*dbstruct.Streamer, len(list))
midList := make([]int64, len(list))
for i, streamerAuthApproval := range list {
mid := util.DerefInt64(streamerAuthApproval.Mid)
midList[i] = mid
streamerList[i] = &dbstruct.Streamer{
Mid: streamerAuthApproval.Mid,
Gender: streamerAuthApproval.Gender,
Bio: streamerAuthApproval.Bio,
Cover: streamerAuthApproval.Cover,
Shorts: streamerAuthApproval.Shorts,
Album: streamerAuthApproval.Album,
Age: streamerAuthApproval.Age,
Height: streamerAuthApproval.Height,
Weight: streamerAuthApproval.Weight,
Constellation: streamerAuthApproval.Constellation,
City: streamerAuthApproval.City,
Tag: streamerAuthApproval.Tag,
Fans: streamerAuthApproval.Fans,
AutoResponseMessage: streamerAuthApproval.AutoResponseMessage,
}
// 更新user_vas
err = _DefaultVas.UpdateWechat(ctx, &vasproto.UpdateWechatReq{
BaseRequest: base.BaseRequest{
Mid: mid,
},
WechatLockType: int32(util.DerefInt64(streamerAuthApproval.WechatLockType)),
WechatContact: util.DerefString(streamerAuthApproval.WechatContact),
WechatCoinPrice: util.DerefInt64(streamerAuthApproval.WechatCoinPrice),
})
if err != nil {
logger.Error("UpdateWechat fail, mid: %v, err: %v", err)
return
}
}
err = _DefaultStreamer.OpCreateBatch(ctx, &streamerproto.OpCreateBatchReq{
BaseRequest: req.BaseRequest,
Streamers: streamerList,
})
if mongo.IsDuplicateKeyError(err) {
logger.Error("OpCreateBatch duplicate key found, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerDuplicateKey
return
}
if err != nil {
logger.Error("OpCreateBatch fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerAuthApprovalSrvFail
return
}
// 更新account表里的角色信息为主播
err = _DefaultAccount.OpUpdateByIds(ctx, &accountproto.OpUpdateByIdsReq{
BaseRequest: req.BaseRequest,
Account: &dbstruct.Account{
Role: goproto.Int64(consts.Streamer),
},
Ids: midList,
})
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeAccountNotExist
err = nil
return
}
if err != nil {
logger.Error("Account OpUpdateByIds fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountSrvFail
return
}
}
return
}
// Streamer
func (s *Service) OpCreateStreamer(ctx *gin.Context, req *streamerproto.OpCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
if ec = s.OpCreateStreamerBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerSrvOk {
return
}
err := _DefaultStreamer.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerSrvFail
return
}
return
}
func (s *Service) OpUpdateStreamer(ctx *gin.Context, req *streamerproto.OpUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
if ec = s.OpUpdateStreamerBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerSrvOk {
return
}
err := _DefaultStreamer.OpUpdate(ctx, req)
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeStreamerNotExist
err = nil
return
}
if err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerSrvFail
return
}
return
}
func (s *Service) OpDeleteStreamer(ctx *gin.Context, id int64) (ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
err := _DefaultStreamer.OpDelete(ctx, id)
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", id, err)
ec = errcode.ErrCodeStreamerSrvFail
return
}
return
}
func (s *Service) OpGetStreamerList(ctx *gin.Context, req *streamerproto.OpListReq) (list []*dbstruct.Streamer, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
list, err := _DefaultStreamer.OpList(ctx, req)
if err != nil {
logger.Error("OpList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerSrvFail
return
}
return
}
func (s *Service) OpGetStreamerListByMid(ctx *gin.Context, req *streamerproto.OpListByMidReq) (streamer *dbstruct.Streamer, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
//业务校验
if ec = s.OpGetStreamerListByMidBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerSrvOk {
return
}
streamer, err := _DefaultStreamer.OpListByMid(ctx, req)
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) OpGetStreamerExtListByMid(ctx *gin.Context, req *streamerproto.OpListExtByMidReq) (vo *streamerproto.OpListExtVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
if ec = s.OpGetStreamerExtListByMidBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerSrvOk {
return
}
//1.从用户表中查询主播信息
account, err := _DefaultAccount.OpListByMid(ctx, &accountproto.OpListByMidReq{
Mid: req.Mid,
})
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.OpListExtVO{}
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
}
return
}
func (s *Service) OpGetStreamerExtListByMids(ctx *gin.Context, req *streamerproto.OpListExtByMidsReq) (list []*streamerproto.OpListExtVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
if ec = s.OpGetStreamerExtListByMidsBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerSrvOk {
return
}
//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.OpListExtVO, len(streamerExts))
for i, streamerExt := range streamerExts {
vo, _ := streamerExt.(*streamerproto.OpListExtVO)
list[i] = vo
}
return
}
func (s *Service) OpGetStreamerExtListByUserId(ctx *gin.Context, req *streamerproto.OpListExtByUserIdReq) (vo *streamerproto.OpListExtVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
if ec = s.OpGetStreamerExtListByUserIdBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerSrvOk {
return
}
//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.OpListExtVO{}
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
}
return
}
func (s *Service) OpGetStreamerExtListFuzzilyByUserId(ctx *gin.Context, req *streamerproto.OpListExtFuzzilyByUserIdReq) (list []*streamerproto.OpListExtVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
if ec = s.OpGetStreamerExtListFuzzilyByUserIdBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerSrvOk {
return
}
//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.OpListExtVO, len(streamerExts))
for i, streamerExt := range streamerExts {
vo, _ := streamerExt.(*streamerproto.OpListExtVO)
list[i] = vo
}
return
}
func (s *Service) OpGetStreamerExtListFuzzilyByName(ctx *gin.Context, req *streamerproto.OpListExtFuzzilyByNameReq) (list []*streamerproto.OpListExtVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
if ec = s.OpGetStreamerExtListFuzzilyByNameBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerSrvOk {
return
}
//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.OpListExtVO, len(streamerExts))
for i, streamerExt := range streamerExts {
vo, _ := streamerExt.(*streamerproto.OpListExtVO)
list[i] = vo
}
return
}
func (s *Service) OpGetStreamerWxId(ctx *gin.Context, req *streamerproto.OpListStreamerWxIdReq) (streamerWxIdVO *streamerproto.OpListWxIdVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
//业务校验-如果登录用户和被查找用户不一致,则查找用户关系表中查找,条件为(登录用户-sub_mid被查找用户-obj_mid6-主语可从宾语处查看微信-predicate
if req.BaseRequest.Mid != util.DerefInt64(req.Mid) {
accountrelation, err := _DefaultAccountRelation.OpListBySentence(ctx, &accountrelationproto.OpListBySentenceReq{
AccountRelation: &dbstruct.AccountRelation{
SubMid: goproto.Int64(req.BaseRequest.Mid),
ObjMid: req.Mid,
Predicate: goproto.Int64(consts.AbleToAccessWeixinOf),
},
})
if err != nil {
logger.Error("OpListBySentence fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountRelationSrvFail
return
}
if accountrelation == nil {
logger.Error("Insufficient authority: %v has not acquired the privilege to access %v's weixin", req.BaseRequest.Mid, util.DerefInt64(req.Mid))
return nil, errcode.ErrCodeAccountRelationSubMidUnableToAccessWxIdOfObjMid
}
}
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.OpListWxIdVO{}
streamerWxIdVO.CopyStreamer(streamer)
return
}
// 推荐
func (s *Service) OpGetStreamerRecommList(ctx *gin.Context, req *streamerproto.OpRecommListReq) (recommlist []int64, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerSrvOk
//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)
}
}
}
return
}
// Feedback
func (s *Service) OpCreateFeedback(ctx *gin.Context, req *feedbackproto.OpCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeFeedbackSrvOk
if ec = s.OpCreateFeedbackBusinessValidate(ctx, req); ec != errcode.ErrCodeFeedbackSrvOk {
return
}
err := _DefaultFeedback.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeFeedbackSrvFail
return
}
return
}
func (s *Service) OpUpdateFeedback(ctx *gin.Context, req *feedbackproto.OpUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeFeedbackSrvOk
if ec = s.OpUpdateFeedbackBusinessValidate(ctx, req); ec != errcode.ErrCodeFeedbackSrvOk {
return
}
err := _DefaultFeedback.OpUpdate(ctx, req)
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeFeedbackNotExist
err = nil
return
}
if err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeFeedbackSrvFail
return
}
return
}
func (s *Service) OpDeleteFeedback(ctx *gin.Context, id int64) (ec errcode.ErrCode) {
ec = errcode.ErrCodeFeedbackSrvOk
err := _DefaultFeedback.OpDelete(ctx, id)
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", id, err)
ec = errcode.ErrCodeFeedbackSrvFail
return
}
return
}
func (s *Service) OpGetFeedbackList(ctx *gin.Context, req *feedbackproto.OpListReq) (list []*dbstruct.Feedback, ec errcode.ErrCode) {
ec = errcode.ErrCodeFeedbackSrvOk
if ec = s.OpGetFeedbackListBusinessValidate(ctx, req); ec != errcode.ErrCodeFeedbackSrvOk {
return
}
list, err := _DefaultFeedback.OpList(ctx, req)
if err != nil {
logger.Error("OpGetFeedbackList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeFeedbackSrvFail
return
}
return
}
// CallHistory
func (s *Service) OpCreateCallHistory(ctx *gin.Context, req *callhistoryproto.OpCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeCallHistorySrvOk
if ec = s.OpCreateCallHistoryBusinessValidate(ctx, req); ec != errcode.ErrCodeCallHistorySrvOk {
return
}
err := _DefaultCallHistory.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeCallHistorySrvFail
return
}
return
}
func (s *Service) OpUpdateCallHistory(ctx *gin.Context, req *callhistoryproto.OpUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeCallHistorySrvOk
if ec = s.OpUpdateCallHistoryBusinessValidate(ctx, req); ec != errcode.ErrCodeCallHistorySrvOk {
return
}
err := _DefaultCallHistory.OpUpdate(ctx, req)
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeCallHistoryNotExist
err = nil
return
}
if err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeCallHistorySrvFail
return
}
return
}
func (s *Service) OpDeleteCallHistory(ctx *gin.Context, id int64) (ec errcode.ErrCode) {
ec = errcode.ErrCodeCallHistorySrvOk
err := _DefaultCallHistory.OpDelete(ctx, id)
if err != nil {
logger.Error("OpDelete fail, id: %v, err: %v", id, err)
ec = errcode.ErrCodeCallHistorySrvFail
return
}
return
}
func (s *Service) OpGetCallHistoryList(ctx *gin.Context, req *callhistoryproto.OpListReq) (list []*dbstruct.CallHistory, ec errcode.ErrCode) {
ec = errcode.ErrCodeCallHistorySrvOk
if ec = s.OpGetCallHistoryListBusinessValidate(ctx, req); ec != errcode.ErrCodeCallHistorySrvOk {
return
}
list, err := _DefaultCallHistory.OpList(ctx, req)
if err != nil {
logger.Error("OpGetCallHistoryList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeCallHistorySrvFail
return
}
return
}
func (s *Service) OpGetCallHistoryCount(ctx *gin.Context, req *callhistoryproto.OpCountReq) (countMap map[int64]int64, ec errcode.ErrCode) {
ec = errcode.ErrCodeCallHistorySrvOk
if ec = s.OpGetCallHistoryCountBusinessValidate(ctx, req); ec != errcode.ErrCodeCallHistorySrvOk {
return
}
countMap, err := _DefaultCallHistory.OpCount(ctx, req)
if err != nil {
logger.Error("OpCount fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeCallHistorySrvFail
return
}
return
}
func (s *Service) OpGetCallEvaluationList(ctx *gin.Context, req *callhistoryproto.OpCallEvaluationListReq) (list []*callhistoryproto.OpListCallEvaluationVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeCallHistorySrvOk
if ec = s.OpGetCallEvaluationListBusinessValidate(ctx, req); ec != errcode.ErrCodeCallHistorySrvOk {
return
}
//1.查出该主播的通话记录侧数据
callHistoryList, err := _DefaultCallHistory.OpList(ctx, &callhistoryproto.OpListReq{
Mid: req.Mid,
Offset: req.Offset,
Limit: req.Limit,
})
if err != nil {
logger.Error("OpList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeCallHistorySrvOk
return
}
//2.取出用户mid用以查询用户侧数据
//todo:每次查询数量较少,故遍历性能损耗不高
midList := make([]int64, 0)
midExistList := make(map[int64]bool, 0)
for _, callhistory := range callHistoryList {
subMid := util.DerefInt64(callhistory.SubMid)
if !midExistList[subMid] {
midList = append(midList, util.DerefInt64(callhistory.SubMid))
midExistList[subMid] = true
}
}
//3.查询得到用户侧数据
accountList, err := _DefaultAccount.OpListByMids(ctx, &accountproto.OpListByMidsReq{
Mids: midList,
})
if err != nil {
logger.Error("OpList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeAccountSrvFail
return
}
//4.用户侧数据转为map
accountMap := make(map[int64]*dbstruct.Account, 0)
for _, account := range accountList {
accountMap[util.DerefInt64(account.Mid)] = account
}
//5.组装返回数据
list = make([]*callhistoryproto.OpListCallEvaluationVO, len(callHistoryList))
for i, callhistory := range callHistoryList {
account := accountMap[util.DerefInt64(callhistory.SubMid)]
if account == nil {
logger.Error("Find illegal account in call history, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeCallHistorySrvFail
return
}
list[i] = &callhistoryproto.OpListCallEvaluationVO{}
list[i].CopyAccount(account).CopyHistory(callhistory)
}
return
}
// StreamerLink
func (s *Service) OpGetStreamerLinkListByMid(ctx *gin.Context, req *streamerlinkproto.OpListByMidReq) (list []*dbstruct.StreamerLink, ec errcode.ErrCode) {
ec = errcode.ErrCodeStreamerLinkSrvOk
if ec = s.OpGetStreamerLinkListByMidBusinessValidate(ctx, req); ec != errcode.ErrCodeStreamerLinkSrvOk {
return
}
list, err := _DefaultStreamerLink.OpListByMid(ctx, req)
if err != nil {
logger.Error("OpListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeStreamerLinkSrvFail
return
}
return
}
// UserWxAddCheck
func (s *Service) OpCreateUserWxAddCheck(ctx *gin.Context, req *userwxaddcheckproto.OpCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeUserWxAddCheckSrvOk
if ec = s.OpCreateUserWxAddCheckBusinessValidate(ctx, req); ec != errcode.ErrCodeUserWxAddCheckSrvOk {
return
}
err := _DefaultUserWxAddCheck.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeUserWxAddCheckSrvFail
return
}
return
}
func (s *Service) OpUpdateUserWxAddCheck(ctx *gin.Context, req *userwxaddcheckproto.OpUpdateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeUserWxAddCheckSrvOk
if ec = s.OpUpdateUserWxAddCheckBusinessValidate(ctx, req); ec != errcode.ErrCodeUserWxAddCheckSrvOk {
return
}
err := _DefaultUserWxAddCheck.OpUpdate(ctx, req)
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) OpDeleteUserWxAddCheck(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) OpGetUserWxAddCheckList(ctx *gin.Context, req *userwxaddcheckproto.OpListReq) (list []*dbstruct.UserWxAddCheck, ec errcode.ErrCode) {
ec = errcode.ErrCodeUserWxAddCheckSrvOk
if ec = s.OpGetUserWxAddCheckListBusinessValidate(ctx, req); ec != errcode.ErrCodeUserWxAddCheckSrvOk {
return
}
list, err := _DefaultUserWxAddCheck.OpList(ctx, req)
if err != nil {
logger.Error("OpGetUserWxAddCheckList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeUserWxAddCheckSrvFail
return
}
return
}
func (s *Service) MediaAuth(ctx *gin.Context, req *mediaproto.MediaAuthReq) (policyToken *mediaproto.PolicyToken, ec errcode.ErrCode) {
ec = errcode.ErrCodeMediaSrvOk
policyToken, err := _DefaultMedia.GetPolicyToken(req.Mtype)
if err != nil {
logger.Error("GetPolicyToken fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMediaSrvFail
return
}
return
}
func (s *Service) CUpload(ctx *gin.Context, req *mediaproto.CUploadReq) (ret interface{}, ec errcode.ErrCode) {
ec = errcode.ErrCodeMediaSrvOk
ret, err := _DefaultMedia.Upload(ctx, req.Mtype, req.Item)
if err != nil {
logger.Error("Upload fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMediaUploadFail
return
}
return
}
// 媒体
func (s *Service) GetImageByIds(ctx *gin.Context, req *mediaproto.ImageListReq) (list []*dbstruct.Image, ec errcode.ErrCode) {
ec = errcode.ErrCodeMediaSrvOk
list, err := _DefaultMedia.GetImageByIds(ctx, req.Ids)
if err != nil {
logger.Error("GetImageByIds fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMediaSrvFail
return
}
return
}
func (s *Service) GetVideoByIds(ctx *gin.Context, req *mediaproto.VideoListReq) (list []*dbstruct.Video, ec errcode.ErrCode) {
ec = errcode.ErrCodeMediaSrvOk
list, err := _DefaultMedia.GetVideoByIds(ctx, req.Ids)
if err != nil {
logger.Error("GetVideoByIds fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeMediaSrvFail
return
}
return
}
func (s *Service) OpGetPlatformListByIds(ctx *gin.Context, ids []int64) (list []*apollostruct.PlatformCfg, ec errcode.ErrCode) {
ec = errcode.ErrCodeOk
list = make([]*apollostruct.PlatformCfg, len(ids))
for i, id := range ids {
cfg := &apollostruct.PlatformCfg{}
err := apollo.GetJson(fmt.Sprintf("%d", id), cfg, apollo.ApolloOpts().SetNamespace("platform"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
return nil, errcode.ErrCodeApolloReadFail
}
list[i] = cfg
}
return
}
// RealNameAuthentication
func (s *Service) OpGetRealNameAuthenticationList(ctx *gin.Context, req *realname_authenticationproto.OpListReq) (list []*dbstruct.RealNameAuthentication, ec errcode.ErrCode) {
ec = errcode.ErrCodeRealNameAuthenticationSrvOk
// 1.业务校验,鉴权
if ec = s.OpGetRealNameAuthenticationListBusinessValidate(ctx, req); ec != errcode.ErrCodeRealNameAuthenticationSrvOk {
return
}
list, err := _DefaultRealNameAuthentication.OpList(ctx, req)
if err != nil {
logger.Error("OpGetRealNameAuthenticationList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeRealNameAuthenticationSrvFail
return
}
return
}
func (s *Service) OpApproveRealNameAuthentication(ctx *gin.Context, req *realname_authenticationproto.OpApproveReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeRealNameAuthenticationSrvOk
// 1.业务校验,鉴权
if ec = s.OpApproveRealNameAuthenticationBusinessValidate(ctx, req); ec != errcode.ErrCodeRealNameAuthenticationSrvOk {
return
}
//1.更新状态
err := _DefaultRealNameAuthentication.OpUpdateRealNameAuthenticationByIds(ctx, &realname_authenticationproto.OpUpdateByIdsReq{
BaseRequest: req.BaseRequest,
RealNameAuthentication: &dbstruct.RealNameAuthentication{
Status: req.ApproveStatus,
Remarks: req.Remarks,
},
Ids: req.Ids,
})
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeRealNameAuthenticationNotExist
err = nil
return
}
if err != nil {
logger.Error("OpUpdateRealNameAuthenticationByIds fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeRealNameAuthenticationSrvFail
return
}
//2.若是审批失败,则更新之后直接删除,审批失败的信息将流转到历史表里保存
if util.DerefInt64(req.ApproveStatus) == consts.RealNameAuthentication_Rejected {
err := _DefaultRealNameAuthentication.OpDeleteBatch(ctx, req.Ids)
if err != nil {
logger.Error("OpDeleteBatch fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeRealNameAuthenticationSrvFail
return
}
return
}
return
}
// ContactCustomerService
func (s *Service) OpCreateContactCustomerService(ctx *gin.Context, req *contact_customer_service_proto.OpCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeContactCustomerServiceSrvOk
if ec = s.OpCreateContactCustomerServiceBusinessValidate(ctx, req); ec != errcode.ErrCodeContactCustomerServiceSrvOk {
return
}
if err := _DefaultContactCustomerService.OpCreate(ctx, req); 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) OpUpdateContactCustomerServiceByIds(ctx *gin.Context, req *contact_customer_service_proto.OpUpdateByIdsReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeContactCustomerServiceSrvOk
if ec = s.OpUpdateContactCustomerServiceByIdsBusinessValidate(ctx, req); ec != errcode.ErrCodeContactCustomerServiceSrvOk {
return
}
err := _DefaultContactCustomerService.OpUpdateByIds(ctx, req)
if err == qmgo.ErrNoSuchDocuments {
ec = errcode.ErrCodeContactCustomerServiceNotExist
err = nil
return
}
if err != nil {
logger.Error("OpUpdate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeContactCustomerServiceSrvFail
return
}
return
}
func (s *Service) OpGetContactCustomerServiceListBySessionId(ctx *gin.Context, req *contact_customer_service_proto.OpListBySessionIdReq) (list []*dbstruct.ContactCustomerService, ec errcode.ErrCode) {
ec = errcode.ErrCodeContactCustomerServiceSrvOk
if ec = s.OpGetContactCustomerServiceListBySessionIdBusinessValidate(ctx, req); ec != errcode.ErrCodeContactCustomerServiceSrvOk {
return
}
list, err := _DefaultContactCustomerService.OpListBySessionId(ctx, req)
if err != nil {
logger.Error("OpGetContactCustomerServiceListBySessionId fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeContactCustomerServiceSrvFail
return
}
return
}
func (s *Service) OpGetContactCustomerServiceListUnreadGroupByMid(ctx *gin.Context, req *contact_customer_service_proto.OpListUnreadReq) (volist []*contact_customer_service_proto.ContactCustomerServiceOpUnreadVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeContactCustomerServiceSrvOk
if ec = s.OpGetContactCustomerServiceListUnreadGroupByMidBusinessValidate(ctx, req); ec != errcode.ErrCodeContactCustomerServiceSrvOk {
return
}
list, err := _DefaultContactCustomerService.OpListUnread(ctx, req)
if err != nil {
logger.Error("OpGetContactCustomerServiceListUnread fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeContactCustomerServiceSrvFail
return
}
_map := make(map[int64][]*dbstruct.ContactCustomerService)
for _, contact_customer_service := range list {
sessionId := util.DerefInt64(contact_customer_service.SessionId)
contents := _map[sessionId]
_map[sessionId] = append(contents, contact_customer_service)
}
index := 0
volist = make([]*contact_customer_service_proto.ContactCustomerServiceOpUnreadVO, len(_map))
for sessionId, contents := range _map {
volist[index] = &contact_customer_service_proto.ContactCustomerServiceOpUnreadVO{
SessionId: sessionId,
List: contents,
}
index++
}
return
}
func (s *Service) OpGetImageAuditTaskVOList(ctx *gin.Context, req *imageaudittaskproto.OpListReq) (volist []*imageaudittaskproto.ImageAuditTaskVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeImageAuditTaskSrvOk
if ec = s.OpGetImageAuditTaskVOListBusinessValidate(ctx, req); ec != errcode.ErrCodeImageAuditTaskSrvOk {
return
}
list, err := _DefaultImageAuditTask.OpList(ctx, req)
if err != nil {
logger.Error("OpGetImageAuditTaskListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeImageAuditTaskSrvFail
return
}
volist = make([]*imageaudittaskproto.ImageAuditTaskVO, len(list))
for i, task := range list {
volist[i] = &imageaudittaskproto.ImageAuditTaskVO{
ImageAuditTask: task,
}
if util.DerefInt64(task.IsFragmented) == 1 {
imageaudits, err := _DefaultImageAudit.GetListByIds(ctx, util.DerefStringSlice(task.ImageAuditFragmentIds))
if err != nil {
logger.Error("GetListByIds fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeImageAuditSrvFail
return
}
volist[i].CopyImageAudits(imageaudits)
} else {
imageaudit, err := _DefaultImageAudit.OpList(ctx, &imageauditproto.OpListReq{
Id: task.ImageAuditId,
})
if err != nil {
logger.Error("OpList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeImageAuditSrvFail
return
}
volist[i].CopyImageAudits([]*dbstruct.ImageAudit{imageaudit})
}
}
return
}
func (s *Service) OpPassImageAuditTaskBatch(ctx *gin.Context, req *imageaudittaskproto.OpPassBatchReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeImageAuditTaskSrvOk
if ec = s.OpPassImageAuditTaskBatchBusinessValidate(ctx, req); ec != errcode.ErrCodeImageAuditTaskSrvOk {
return
}
ids := make([]string, 0)
for i, task := range req.ImageAuditTasks {
if err := s.GetUpdateImageFunc(ctx, task)(); err != nil {
logger.Error("Execution of update function of %dth task fail: %v", i, err)
ec = errcode.ErrCodeImageAuditTaskManuallyPassFail
break
}
ids = append(ids, util.DerefString(task.Id))
}
if err := _DefaultImageAuditTask.OpUpdateByIds(ctx, &imageaudittaskproto.OpUpdateByIdsReq{
ImageAuditTask: &dbstruct.ImageAuditTask{
Status: goproto.Int64(consts.ImageAudit_ManuallyPassed),
},
Ids: ids,
}); err != nil {
logger.Error("OpUpdateByIds fail, req: %v, err: %v", util.ToJson(req), err)
return errcode.ErrCodeImageAuditSrvFail
}
return
}
func (s *Service) OpGetTextAuditTaskVOList(ctx *gin.Context, req *textaudittaskproto.OpListReq) (volist []*textaudittaskproto.TextAuditTaskVO, ec errcode.ErrCode) {
ec = errcode.ErrCodeTextAuditTaskSrvOk
if ec = s.OpGetTextAuditTaskVOListBusinessValidate(ctx, req); ec != errcode.ErrCodeTextAuditTaskSrvOk {
return
}
list, err := _DefaultTextAuditTask.OpList(ctx, req)
if err != nil {
logger.Error("OpGetTextAuditTaskListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeTextAuditTaskSrvFail
return
}
volist = make([]*textaudittaskproto.TextAuditTaskVO, len(list))
for i, task := range list {
volist[i] = &textaudittaskproto.TextAuditTaskVO{
TextAuditTask: task,
}
textaudit, err := _DefaultTextAudit.OpList(ctx, &textauditproto.OpListReq{
Id: task.TextAuditId,
})
if err != nil {
logger.Error("OpList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeTextAuditSrvFail
return
}
volist[i].CopyTextAudit(textaudit)
}
return
}
func (s *Service) OpPassTextAuditTaskBatch(ctx *gin.Context, req *textaudittaskproto.OpPassBatchReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeTextAuditTaskSrvOk
if ec = s.OpPassTextAuditTaskBatchBusinessValidate(ctx, req); ec != errcode.ErrCodeTextAuditTaskSrvOk {
return
}
ids := make([]string, 0)
for i, task := range req.TextAuditTasks {
if err := s.GetUpdateTextFunc(ctx, task)(); err != nil {
logger.Error("Execution of update function of %dth task fail: %v", i, err)
ec = errcode.ErrCodeTextAuditTaskManuallyPassFail
break
}
ids = append(ids, util.DerefString(task.Id))
}
if err := _DefaultTextAuditTask.OpUpdateByIds(ctx, &textaudittaskproto.OpUpdateByIdsReq{
TextAuditTask: &dbstruct.TextAuditTask{
Status: goproto.Int64(consts.TextAudit_ManuallyPassed),
},
Ids: ids,
}); err != nil {
logger.Error("OpUpdateByIds fail, req: %v, err: %v", util.ToJson(req), err)
return errcode.ErrCodeTextAuditSrvFail
}
return
}
// ContactCustomerServiceSession
func (s *Service) OpCreateContactCustomerServiceSession(ctx *gin.Context, req *contact_customer_service_sessionproto.OpCreateReq) (ec errcode.ErrCode) {
ec = errcode.ErrCodeContactCustomerServiceSessionSrvOk
if ec = s.OpCreateContactCustomerServiceSessionBusinessValidate(ctx, req); ec != errcode.ErrCodeContactCustomerServiceSessionSrvOk {
return
}
err := _DefaultContactCustomerServiceSession.OpCreate(ctx, req)
if err != nil {
logger.Error("OpCreate fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeContactCustomerServiceSessionSrvFail
return
}
return
}
func (s *Service) OpGetContactCustomerServiceSessionListByMid(ctx *gin.Context, req *contact_customer_service_sessionproto.OpListByMidReq) (session *dbstruct.ContactCustomerServiceSession, ec errcode.ErrCode) {
ec = errcode.ErrCodeContactCustomerServiceSessionSrvOk
if ec = s.OpGetContactCustomerServiceSessionListByMidBusinessValidate(ctx, req); ec != errcode.ErrCodeContactCustomerServiceSessionSrvOk {
return
}
session, err := _DefaultContactCustomerServiceSession.OpListByMid(ctx, req)
if err != nil {
logger.Error("OpListByMid fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeContactCustomerServiceSessionSrvFail
return
}
return
}
func (s *Service) OpGetContactCustomerServiceSessionListBySessionId(ctx *gin.Context, req *contact_customer_service_sessionproto.OpListBySessionIdReq) (session *dbstruct.ContactCustomerServiceSession, ec errcode.ErrCode) {
ec = errcode.ErrCodeContactCustomerServiceSessionSrvOk
if ec = s.OpGetContactCustomerServiceSessionListBySessionIdBusinessValidate(ctx, req); ec != errcode.ErrCodeContactCustomerServiceSessionSrvOk {
return
}
session, err := _DefaultContactCustomerServiceSession.OpListBySessionId(ctx, req)
if err != nil {
logger.Error("OpListBySessionId fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeContactCustomerServiceSessionSrvFail
return
}
return
}
func (s *Service) OpGetContactCustomerServiceSessionList(ctx *gin.Context, req *contact_customer_service_sessionproto.OpListReq) (list []*dbstruct.ContactCustomerServiceSession, ec errcode.ErrCode) {
ec = errcode.ErrCodeContactCustomerServiceSessionSrvOk
if ec = s.OpGetContactCustomerServiceSessionListBusinessValidate(ctx, req); ec != errcode.ErrCodeContactCustomerServiceSessionSrvOk {
return
}
list, err := _DefaultContactCustomerServiceSession.OpList(ctx, req)
if err != nil {
logger.Error("OpList fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeContactCustomerServiceSessionSrvFail
return
}
return
}