by Robin at 20240424

This commit is contained in:
Leufolium 2024-04-24 20:16:22 +08:00
parent 1966a42d28
commit 5d7220246e
6 changed files with 63 additions and 33 deletions

View File

@ -4686,11 +4686,31 @@ func (m *Mongo) CreateZoneThirdPartnerHis(ctx *gin.Context, zone_third_partner *
}
// 动态创建频次
func (m *Mongo) GetAndUpdateZoneMomentCreateTimes(ctx *gin.Context, mid int64) (momentCreateTimes *dbstruct.ZoneMomentCreateTimes, err error) {
func (m *Mongo) GetZoneMomentCreateTimes(ctx *gin.Context, mid int64) (momentCreateTimes *dbstruct.ZoneMomentCreateTimes, err error) {
col := m.getColZoneMomentCreateTimes()
momentCreateTimesInstance := dbstruct.ZoneMomentCreateTimes{}
err = col.Find(ctx, qmgo.M{"_id": mid}).One(&momentCreateTimes)
if err == qmgo.ErrNoSuchDocuments {
err = nil
return nil, err
}
return &momentCreateTimesInstance, err
}
func (m *Mongo) GetAndUpdateZoneMomentCreateTimes(ctx *gin.Context, mid int64, cType int64) (momentCreateTimes *dbstruct.ZoneMomentCreateTimes, err error) {
col := m.getColZoneMomentCreateTimes()
incClause := qmgo.M{
"create_times": 1,
}
if cType == consts.ZoneMomentCType_Free {
incClause["free_create_times"] = 1
} else if cType == consts.ZoneMomentCType_Paid {
incClause["paid_create_times"] = 1
}
change := qmgo.Change{
Update: qmgo.M{"$inc": qmgo.M{"create_times": 1}},
Update: qmgo.M{"$inc": incClause},
Upsert: true,
ReturnNew: false,
}

View File

@ -2780,6 +2780,7 @@ func (s *Service) ApiGetZoneMomentListByCreaterMid(ctx *gin.Context, req *zonemo
vo := &zonemomentproto.ApiZoneMomentVO{
ZoneMoment: zonemoment,
}
vo.IsZoneMomentUnlocked = consts.IsZoneMomentUnlocked_Yes
// 主播信息
vo.CopyStreamerExt(streamerExt)
volist = append(volist, vo)
@ -2813,21 +2814,19 @@ func (s *Service) ApiGetZoneMomentStatisticsByCreaterMid(ctx *gin.Context, req *
return
}
// 免费贴个数
freeCount, err := _DefaultZoneMoment.OpCountByMidAndCType(ctx, req.BaseRequest.Mid, consts.ZoneMomentCType_Free)
// 今日发帖次数统计
zoneMomentCreateTimes, err := _DefaultZoneMomentCreateTimes.OpGetOne(ctx, req.BaseRequest.Mid)
if err != nil {
logger.Error("_DefaultZoneMoment OpCountByMidAndCType fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeZoneMomentSrvFail
logger.Error("_DefaultZoneMomentCreateTimes OpGetOne fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeZoneMomentCreateTimesSrvFail
return
}
// 免费贴个数
freeCount := zoneMomentCreateTimes.FreeCreateTimes
// 付费贴个数
paidCount, err := _DefaultZoneMoment.OpCountByMidAndCType(ctx, req.BaseRequest.Mid, consts.ZoneMomentCType_Paid)
if err != nil {
logger.Error("_DefaultZoneMoment OpCountByMidAndCType fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeZoneMomentSrvFail
return
}
paidCount := zoneMomentCreateTimes.PaidCreateTimes
// 审核未通过个数
rejectedCount, err := _DefaultZoneMoment.OpCountByMidAndStatus(ctx, req.BaseRequest.Mid, consts.ZoneMoment_Private)

View File

@ -565,8 +565,8 @@ func (s *Service) ApiCreateZoneMomentBusinessValidate(ctx *gin.Context, req *zon
EnsureIsThisRole(consts.Streamer).
EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, consts.AccountPunishment_BlockFromCreatingZoneMoment, _DefaultAccountPunishment.OpListByMidAndType).
EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, pType, _DefaultAccountPunishment.OpListByMidAndType).
EnsureZoneMomentCreateTimesNotReachedDailyUpperbound(_DefaultZoneMomentCreateTimes.OpGetAndUpdate, req.GetBaseRequest().Mid).
EnsureAmongZoneMomentsPaidItemsLessThanFreeItems(_DefaultZoneMoment.OpCountByMidAndCType, req.GetBaseRequest().Mid, req.ZoneMoment.GetCType()).
EnsureAmongZoneMomentsPaidItemsLessThanFreeItems(_DefaultZoneMomentCreateTimes.OpGetOne, req.GetBaseRequest().Mid, req.ZoneMoment.GetCType()).
EnsureZoneMomentCreateTimesNotReachedDailyUpperbound(_DefaultZoneMomentCreateTimes.OpGetAndUpdate, req.GetBaseRequest().Mid, req.ZoneMoment.GetCType()).
EnsureZoneMomentImagesEnoughForEncryption(req.ZoneMoment.GetMType(), req.ZoneMoment.MediaComp, mediaVisibleRange).
Validate().
Collect()

View File

@ -345,28 +345,26 @@ func (l *AuthBusinessValidator) EnsureMomentCreateTimesNotReachedDailyUpperbound
return l
}
func (l *AuthBusinessValidator) EnsureAmongZoneMomentsPaidItemsLessThanFreeItems(fun func(*gin.Context, int64, int64) (int64, error), mid int64, cType int64) *AuthBusinessValidator {
func (l *AuthBusinessValidator) EnsureAmongZoneMomentsPaidItemsLessThanFreeItems(fun func(*gin.Context, int64) (*dbstruct.ZoneMomentCreateTimes, error), mid int64, cType int64) *AuthBusinessValidator {
l.oplist = append(l.oplist, func() {
if cType == consts.ZoneMomentCType_Free {
return
}
// 免费动态数
freeCount, err1 := fun(l.ctx, mid, consts.ZoneMomentCType_Free)
if err1 != nil {
logger.Error("Query free zone moment count failed, err: %v", err1)
l.ec = errcode.ErrCodeZoneMomentSrvFail
// 查询动态数
zoneMomentCreateTimes, err := fun(l.ctx, mid)
if err != nil {
logger.Error("Query zone moment create times failed, err: %v", err)
l.ec = errcode.ErrCodeZoneMomentCreateTimesSrvFail
return
}
// 免费动态数
freeCount := zoneMomentCreateTimes.FreeCreateTimes
// 付费动态数
paidCount, err2 := fun(l.ctx, mid, consts.ZoneMomentCType_Paid)
if err2 != nil {
logger.Error("Query paid zone moment count failed, err: %v", err2)
l.ec = errcode.ErrCodeZoneMomentSrvFail
return
}
paidCount := zoneMomentCreateTimes.PaidCreateTimes
if paidCount >= freeCount {
logger.Error("the paid zone moment create times of this mid has reached its upperbound")
@ -457,7 +455,7 @@ func (l *AuthBusinessValidator) EnsureSuchAccountPunishmentNotExist(uid int64, t
return l
}
func (l *AuthBusinessValidator) EnsureZoneMomentCreateTimesNotReachedDailyUpperbound(fun func(*gin.Context, int64) (*dbstruct.ZoneMomentCreateTimes, error), mid int64) *AuthBusinessValidator {
func (l *AuthBusinessValidator) EnsureZoneMomentCreateTimesNotReachedDailyUpperbound(fun func(*gin.Context, int64, int64) (*dbstruct.ZoneMomentCreateTimes, error), mid int64, cType int64) *AuthBusinessValidator {
l.oplist = append(l.oplist, func() {
// 读取每日发送上限
@ -468,7 +466,7 @@ func (l *AuthBusinessValidator) EnsureZoneMomentCreateTimesNotReachedDailyUpperb
return
}
zoneMomentCreateTimes, err := fun(l.ctx, mid)
zoneMomentCreateTimes, err := fun(l.ctx, mid, cType)
if err != nil {
l.ec = errcode.ErrCodeZoneMomentCreateTimesSrvFail
return

View File

@ -19,15 +19,26 @@ func NewZoneMomentCreateTimes(store *dao.Store) (a *ZoneMomentCreateTimes) {
return
}
func (p *ZoneMomentCreateTimes) OpGetAndUpdate(ctx *gin.Context, mid int64) (*dbstruct.ZoneMomentCreateTimes, error) {
func (p *ZoneMomentCreateTimes) OpGetOne(ctx *gin.Context, mid int64) (*dbstruct.ZoneMomentCreateTimes, error) {
vericodeSendTimes, err := p.store.GetAndUpdateZoneMomentCreateTimes(ctx, mid)
zoneMomentCreateTimes, err := p.store.GetZoneMomentCreateTimes(ctx, mid)
if err != nil {
logger.Error("GetZoneMomentCreateTimes fail, err: %v", err)
return nil, err
}
return zoneMomentCreateTimes, nil
}
func (p *ZoneMomentCreateTimes) OpGetAndUpdate(ctx *gin.Context, mid int64, cType int64) (*dbstruct.ZoneMomentCreateTimes, error) {
zoneMomentCreateTimes, err := p.store.GetAndUpdateZoneMomentCreateTimes(ctx, mid, cType)
if err != nil {
logger.Error("GetAndUpdateZoneMomentCreateTimes fail, err: %v", err)
return nil, err
}
return vericodeSendTimes, nil
return zoneMomentCreateTimes, nil
}
func (p *ZoneMomentCreateTimes) OpClear(ctx *gin.Context) error {

View File

@ -1,6 +1,8 @@
package dbstruct
type ZoneMomentCreateTimes struct {
Id int64 `json:"id" bson:"_id"` //id,主播的mid
CreateTimes int64 `json:"create_times" bson:"create_times"` //发送次数
Id int64 `json:"id" bson:"_id"` //id,主播的mid
CreateTimes int64 `json:"create_times" bson:"create_times"` //发帖次数
FreeCreateTimes int64 `json:"free_create_times" bson:"free_create_times"` //免费贴发帖次数
PaidCreateTimes int64 `json:"paid_create_times" bson:"paid_create_times"` //付费贴发帖次数
}