by Robin at 20240427

This commit is contained in:
Leufolium 2024-04-27 00:27:53 +08:00
parent 7cb60f01b6
commit 9fed951998
6 changed files with 31 additions and 72 deletions

View File

@ -4750,13 +4750,11 @@ func (m *Mongo) GetZoneMomentCreateTimes(ctx *gin.Context, mid int64) (momentCre
return momentCreateTimes, err
}
func (m *Mongo) GetAndUpdateZoneMomentCreateTimes(ctx *gin.Context, mid, totalIncr, freeIncr, paidIncr int64) (momentCreateTimes *dbstruct.ZoneMomentCreateTimes, err error) {
func (m *Mongo) GetAndUpdateZoneMomentCreateTimes(ctx *gin.Context, mid, totalIncr int64) (momentCreateTimes *dbstruct.ZoneMomentCreateTimes, err error) {
col := m.getColZoneMomentCreateTimes()
incClause := qmgo.M{
"create_times": totalIncr,
"free_create_times": freeIncr,
"paid_create_times": paidIncr,
"create_times": totalIncr,
}
change := qmgo.Change{

View File

@ -2646,15 +2646,13 @@ func (s *Service) ApiDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.Api
}
// 回退每日发帖次数
totalIncr, freeIncr, paidIncr := int64(-1), int64(0), int64(0)
if zonemoment.GetCType() == consts.ZoneMomentCType_Free {
freeIncr = -1
} else if zonemoment.GetCType() == consts.ZoneMomentCType_Paid {
paidIncr = -1
totalIncr := int64(-1)
_, err = _DefaultZoneMomentCreateTimes.OpGetAndUpdate(ctx, zone.GetMid(), totalIncr)
if err != nil {
logger.Error("OpGetAndUpdate fail, err: %v", err)
ec = errcode.ErrCodeZoneMomentSrvFail
}
_, err = _DefaultZoneMomentCreateTimes.OpGetAndUpdate(ctx, zone.GetMid(), totalIncr, freeIncr, paidIncr)
logger.Error("OpGetAndUpdate fail, err: %v", err)
ec = errcode.ErrCodeZoneMomentSrvFail
return
}
@ -2843,31 +2841,6 @@ func (s *Service) ApiHeadZoneMoment(ctx *gin.Context, req *zonemomentproto.ApiHe
func (s *Service) ApiGetZoneMomentStatisticsByCreaterMid(ctx *gin.Context, req *zonemomentproto.ApiListStatisticsByCreaterMidReq) (result *zonemomentproto.ApiListStatisticsByCreaterMidData, ec errcode.ErrCode) {
ec = errcode.ErrCodeZoneMomentSrvOk
// 读取每日发送上限
maxDailyZoneMomentCreateTimes, err := apollo.GetIntValue(consts.MaxDailyZoneMomentCreateTimesKey, apollo.ApolloOpts().SetNamespace("application"))
if err != nil {
logger.Error("Apollo read failed : %v", err)
ec = errcode.ErrCodeApolloReadFail
return
}
// 今日发帖次数统计
zoneMomentCreateTimes, err := _DefaultZoneMomentCreateTimes.OpGetOne(ctx, req.BaseRequest.Mid)
if err != nil {
logger.Error("_DefaultZoneMomentCreateTimes OpGetOne fail, req: %v, err: %v", util.ToJson(req), err)
ec = errcode.ErrCodeZoneMomentCreateTimesSrvFail
return
}
// 免费贴个数
freeCount := int64(0)
// 付费贴个数
paidCount := int64(0)
if zoneMomentCreateTimes != nil {
freeCount = zoneMomentCreateTimes.FreeCreateTimes
paidCount = zoneMomentCreateTimes.PaidCreateTimes
}
// 审核未通过个数
rejectedCount, err := _DefaultZoneMoment.OpCountByMidAndStatus(ctx, req.BaseRequest.Mid, consts.ZoneMoment_Private)
if err != nil {
@ -2876,14 +2849,6 @@ func (s *Service) ApiGetZoneMomentStatisticsByCreaterMid(ctx *gin.Context, req *
return
}
// 付费贴限额
diff := freeCount - paidCount // 免费贴付费贴差额
dailyLimit := int64(maxDailyZoneMomentCreateTimes) - freeCount - paidCount // 每日发帖剩余限额
paidLimit := diff // 取两者最小值
if dailyLimit < diff {
paidLimit = dailyLimit
}
// 总发帖次数统计
totalFreeCount, err := _DefaultZoneMoment.OpCountByMidAndCType(ctx, req.BaseRequest.Mid, consts.ZoneMomentCType_Free)
if err != nil {
@ -2899,11 +2864,14 @@ func (s *Service) ApiGetZoneMomentStatisticsByCreaterMid(ctx *gin.Context, req *
return
}
// 付费贴限额
diff := totalFreeCount - totalPaidCount // 免费贴付费贴差额
result = &zonemomentproto.ApiListStatisticsByCreaterMidData{
FreeCount: totalFreeCount,
PaidCount: totalPaidCount,
RejectedCount: rejectedCount,
PaidLimit: paidLimit,
PaidLimit: diff,
}
return

View File

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

View File

@ -345,28 +345,28 @@ func (l *AuthBusinessValidator) EnsureMomentCreateTimesNotReachedDailyUpperbound
return l
}
func (l *AuthBusinessValidator) EnsureAmongZoneMomentsPaidItemsLessThanFreeItems(fun func(*gin.Context, int64) (*dbstruct.ZoneMomentCreateTimes, error), mid int64, cType int64) *AuthBusinessValidator {
func (l *AuthBusinessValidator) EnsureAmongZoneMomentsPaidItemsLessThanFreeItems(fun func(*gin.Context, int64, int64) (int64, error), mid int64, cType int64) *AuthBusinessValidator {
l.oplist = append(l.oplist, func() {
if cType == consts.ZoneMomentCType_Free {
return
}
// 查询动态数
zoneMomentCreateTimes, err := fun(l.ctx, mid)
totalFreeCount, err := fun(l.ctx, mid, consts.ZoneMomentCType_Free)
if err != nil {
logger.Error("Query zone moment create times failed, err: %v", err)
l.ec = errcode.ErrCodeZoneMomentCreateTimesSrvFail
logger.Error("_DefaultZoneMoment OpCountByMidAndCType fail, err: %v", err)
l.ec = errcode.ErrCodeZoneMomentSrvFail
return
}
// 免费动态数
freeCount := zoneMomentCreateTimes.FreeCreateTimes
totalPaidCount, err := fun(l.ctx, mid, consts.ZoneMomentCType_Paid)
if err != nil {
logger.Error("_DefaultZoneMoment OpCountByMidAndCType fail, err: %v", err)
l.ec = errcode.ErrCodeZoneMomentSrvFail
return
}
// 付费动态数
paidCount := zoneMomentCreateTimes.PaidCreateTimes
if paidCount >= freeCount {
if totalPaidCount >= totalFreeCount {
logger.Error("the paid zone moment create times of this mid has reached its upperbound")
l.ec = errcode.ErrCodePaidZoneMomentCreateTimesReachedUpperbound
return
@ -460,7 +460,7 @@ func (l *AuthBusinessValidator) EnsureSuchAccountPunishmentNotExist(uid int64, t
return l
}
func (l *AuthBusinessValidator) EnsureZoneMomentCreateTimesNotReachedDailyUpperbound(fun func(*gin.Context, int64, int64, int64, int64) (*dbstruct.ZoneMomentCreateTimes, error), mid int64, cType 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() {
// 读取每日发送上限
@ -471,14 +471,9 @@ func (l *AuthBusinessValidator) EnsureZoneMomentCreateTimesNotReachedDailyUpperb
return
}
totalIncr, freeIncr, paidIncr := int64(1), int64(0), int64(0)
if cType == consts.ZoneMomentCType_Free {
freeIncr = 1
} else if cType == consts.ZoneMomentCType_Paid {
paidIncr = 1
}
totalIncr := int64(1)
zoneMomentCreateTimes, err := fun(l.ctx, mid, totalIncr, freeIncr, paidIncr)
zoneMomentCreateTimes, err := fun(l.ctx, mid, totalIncr)
if err != nil {
l.ec = errcode.ErrCodeZoneMomentCreateTimesSrvFail
return

View File

@ -30,9 +30,9 @@ func (p *ZoneMomentCreateTimes) OpGetOne(ctx *gin.Context, mid int64) (*dbstruct
return zoneMomentCreateTimes, nil
}
func (p *ZoneMomentCreateTimes) OpGetAndUpdate(ctx *gin.Context, mid, totalIncr, freeIncr, paidIncr int64) (*dbstruct.ZoneMomentCreateTimes, error) {
func (p *ZoneMomentCreateTimes) OpGetAndUpdate(ctx *gin.Context, mid, totalIncr int64) (*dbstruct.ZoneMomentCreateTimes, error) {
zoneMomentCreateTimes, err := p.store.GetAndUpdateZoneMomentCreateTimes(ctx, mid, totalIncr, freeIncr, paidIncr)
zoneMomentCreateTimes, err := p.store.GetAndUpdateZoneMomentCreateTimes(ctx, mid, totalIncr)
if err != nil {
logger.Error("GetAndUpdateZoneMomentCreateTimes fail, err: %v", err)
return nil, err

View File

@ -1,8 +1,6 @@
package dbstruct
type ZoneMomentCreateTimes struct {
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"` //付费贴发帖次数
Id int64 `json:"id" bson:"_id"` //id,主播的mid
CreateTimes int64 `json:"create_times" bson:"create_times"` //发帖次数
}