by Robin at 20240424
This commit is contained in:
parent
1966a42d28
commit
5d7220246e
|
@ -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()
|
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{
|
change := qmgo.Change{
|
||||||
Update: qmgo.M{"$inc": qmgo.M{"create_times": 1}},
|
Update: qmgo.M{"$inc": incClause},
|
||||||
Upsert: true,
|
Upsert: true,
|
||||||
ReturnNew: false,
|
ReturnNew: false,
|
||||||
}
|
}
|
||||||
|
|
|
@ -2780,6 +2780,7 @@ func (s *Service) ApiGetZoneMomentListByCreaterMid(ctx *gin.Context, req *zonemo
|
||||||
vo := &zonemomentproto.ApiZoneMomentVO{
|
vo := &zonemomentproto.ApiZoneMomentVO{
|
||||||
ZoneMoment: zonemoment,
|
ZoneMoment: zonemoment,
|
||||||
}
|
}
|
||||||
|
vo.IsZoneMomentUnlocked = consts.IsZoneMomentUnlocked_Yes
|
||||||
// 主播信息
|
// 主播信息
|
||||||
vo.CopyStreamerExt(streamerExt)
|
vo.CopyStreamerExt(streamerExt)
|
||||||
volist = append(volist, vo)
|
volist = append(volist, vo)
|
||||||
|
@ -2813,21 +2814,19 @@ func (s *Service) ApiGetZoneMomentStatisticsByCreaterMid(ctx *gin.Context, req *
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 免费贴个数
|
// 今日发帖次数统计
|
||||||
freeCount, err := _DefaultZoneMoment.OpCountByMidAndCType(ctx, req.BaseRequest.Mid, consts.ZoneMomentCType_Free)
|
zoneMomentCreateTimes, err := _DefaultZoneMomentCreateTimes.OpGetOne(ctx, req.BaseRequest.Mid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("_DefaultZoneMoment OpCountByMidAndCType fail, req: %v, err: %v", util.ToJson(req), err)
|
logger.Error("_DefaultZoneMomentCreateTimes OpGetOne fail, req: %v, err: %v", util.ToJson(req), err)
|
||||||
ec = errcode.ErrCodeZoneMomentSrvFail
|
ec = errcode.ErrCodeZoneMomentCreateTimesSrvFail
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 免费贴个数
|
||||||
|
freeCount := zoneMomentCreateTimes.FreeCreateTimes
|
||||||
|
|
||||||
// 付费贴个数
|
// 付费贴个数
|
||||||
paidCount, err := _DefaultZoneMoment.OpCountByMidAndCType(ctx, req.BaseRequest.Mid, consts.ZoneMomentCType_Paid)
|
paidCount := zoneMomentCreateTimes.PaidCreateTimes
|
||||||
if err != nil {
|
|
||||||
logger.Error("_DefaultZoneMoment OpCountByMidAndCType fail, req: %v, err: %v", util.ToJson(req), err)
|
|
||||||
ec = errcode.ErrCodeZoneMomentSrvFail
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 审核未通过个数
|
// 审核未通过个数
|
||||||
rejectedCount, err := _DefaultZoneMoment.OpCountByMidAndStatus(ctx, req.BaseRequest.Mid, consts.ZoneMoment_Private)
|
rejectedCount, err := _DefaultZoneMoment.OpCountByMidAndStatus(ctx, req.BaseRequest.Mid, consts.ZoneMoment_Private)
|
||||||
|
|
|
@ -565,8 +565,8 @@ func (s *Service) ApiCreateZoneMomentBusinessValidate(ctx *gin.Context, req *zon
|
||||||
EnsureIsThisRole(consts.Streamer).
|
EnsureIsThisRole(consts.Streamer).
|
||||||
EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, consts.AccountPunishment_BlockFromCreatingZoneMoment, _DefaultAccountPunishment.OpListByMidAndType).
|
EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, consts.AccountPunishment_BlockFromCreatingZoneMoment, _DefaultAccountPunishment.OpListByMidAndType).
|
||||||
EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, pType, _DefaultAccountPunishment.OpListByMidAndType).
|
EnsureSuchAccountPunishmentNotExist(req.GetBaseRequest().Mid, pType, _DefaultAccountPunishment.OpListByMidAndType).
|
||||||
EnsureZoneMomentCreateTimesNotReachedDailyUpperbound(_DefaultZoneMomentCreateTimes.OpGetAndUpdate, req.GetBaseRequest().Mid).
|
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()).
|
||||||
EnsureZoneMomentImagesEnoughForEncryption(req.ZoneMoment.GetMType(), req.ZoneMoment.MediaComp, mediaVisibleRange).
|
EnsureZoneMomentImagesEnoughForEncryption(req.ZoneMoment.GetMType(), req.ZoneMoment.MediaComp, mediaVisibleRange).
|
||||||
Validate().
|
Validate().
|
||||||
Collect()
|
Collect()
|
||||||
|
|
|
@ -345,28 +345,26 @@ func (l *AuthBusinessValidator) EnsureMomentCreateTimesNotReachedDailyUpperbound
|
||||||
return l
|
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() {
|
l.oplist = append(l.oplist, func() {
|
||||||
|
|
||||||
if cType == consts.ZoneMomentCType_Free {
|
if cType == consts.ZoneMomentCType_Free {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 免费动态数
|
// 查询动态数
|
||||||
freeCount, err1 := fun(l.ctx, mid, consts.ZoneMomentCType_Free)
|
zoneMomentCreateTimes, err := fun(l.ctx, mid)
|
||||||
if err1 != nil {
|
if err != nil {
|
||||||
logger.Error("Query free zone moment count failed, err: %v", err1)
|
logger.Error("Query zone moment create times failed, err: %v", err)
|
||||||
l.ec = errcode.ErrCodeZoneMomentSrvFail
|
l.ec = errcode.ErrCodeZoneMomentCreateTimesSrvFail
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 免费动态数
|
||||||
|
freeCount := zoneMomentCreateTimes.FreeCreateTimes
|
||||||
|
|
||||||
// 付费动态数
|
// 付费动态数
|
||||||
paidCount, err2 := fun(l.ctx, mid, consts.ZoneMomentCType_Paid)
|
paidCount := zoneMomentCreateTimes.PaidCreateTimes
|
||||||
if err2 != nil {
|
|
||||||
logger.Error("Query paid zone moment count failed, err: %v", err2)
|
|
||||||
l.ec = errcode.ErrCodeZoneMomentSrvFail
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if paidCount >= freeCount {
|
if paidCount >= freeCount {
|
||||||
logger.Error("the paid zone moment create times of this mid has reached its upperbound")
|
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
|
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() {
|
l.oplist = append(l.oplist, func() {
|
||||||
|
|
||||||
// 读取每日发送上限
|
// 读取每日发送上限
|
||||||
|
@ -468,7 +466,7 @@ func (l *AuthBusinessValidator) EnsureZoneMomentCreateTimesNotReachedDailyUpperb
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
zoneMomentCreateTimes, err := fun(l.ctx, mid)
|
zoneMomentCreateTimes, err := fun(l.ctx, mid, cType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.ec = errcode.ErrCodeZoneMomentCreateTimesSrvFail
|
l.ec = errcode.ErrCodeZoneMomentCreateTimesSrvFail
|
||||||
return
|
return
|
||||||
|
|
|
@ -19,15 +19,26 @@ func NewZoneMomentCreateTimes(store *dao.Store) (a *ZoneMomentCreateTimes) {
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
logger.Error("GetAndUpdateZoneMomentCreateTimes fail, err: %v", err)
|
logger.Error("GetAndUpdateZoneMomentCreateTimes fail, err: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return vericodeSendTimes, nil
|
return zoneMomentCreateTimes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ZoneMomentCreateTimes) OpClear(ctx *gin.Context) error {
|
func (p *ZoneMomentCreateTimes) OpClear(ctx *gin.Context) error {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package dbstruct
|
package dbstruct
|
||||||
|
|
||||||
type ZoneMomentCreateTimes struct {
|
type ZoneMomentCreateTimes struct {
|
||||||
Id int64 `json:"id" bson:"_id"` //id,主播的mid
|
Id int64 `json:"id" bson:"_id"` //id,主播的mid
|
||||||
CreateTimes int64 `json:"create_times" bson:"create_times"` //发送次数
|
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"` //付费贴发帖次数
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue