From 3076813dfbccaaed027537115b6f4b0fd455989e Mon Sep 17 00:00:00 2001 From: Leufolium Date: Fri, 26 Apr 2024 10:48:57 +0800 Subject: [PATCH 1/2] by Robin at 20240426; rollback create times of deleted zone moment --- app/mix/dao/mongo.go | 11 ++++------- app/mix/service/apiservice.go | 12 ++++++++++++ app/mix/service/business_validator/auth.go | 11 +++++++++-- app/mix/service/logic/zone_moment_create_times.go | 4 ++-- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index b41fd720..4b88d8f8 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -4714,16 +4714,13 @@ func (m *Mongo) GetZoneMomentCreateTimes(ctx *gin.Context, mid int64) (momentCre return momentCreateTimes, err } -func (m *Mongo) GetAndUpdateZoneMomentCreateTimes(ctx *gin.Context, mid int64, cType int64) (momentCreateTimes *dbstruct.ZoneMomentCreateTimes, err error) { +func (m *Mongo) GetAndUpdateZoneMomentCreateTimes(ctx *gin.Context, mid, totalIncr, freeIncr, paidIncr 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 + "create_times": totalIncr, + "free_create_times": freeIncr, + "paid_create_times": paidIncr, } change := qmgo.Change{ diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index c06365da..5c432795 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -2618,6 +2618,18 @@ 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 + } + _, err = _DefaultZoneMomentCreateTimes.OpGetAndUpdate(ctx, zone.GetMid(), totalIncr, freeIncr, paidIncr) + logger.Error("OpGetAndUpdate fail, err: %v", err) + ec = errcode.ErrCodeZoneMomentSrvFail + return + return } diff --git a/app/mix/service/business_validator/auth.go b/app/mix/service/business_validator/auth.go index 5e03db14..c1d4ec97 100644 --- a/app/mix/service/business_validator/auth.go +++ b/app/mix/service/business_validator/auth.go @@ -460,7 +460,7 @@ func (l *AuthBusinessValidator) EnsureSuchAccountPunishmentNotExist(uid int64, t return l } -func (l *AuthBusinessValidator) EnsureZoneMomentCreateTimesNotReachedDailyUpperbound(fun func(*gin.Context, int64, int64) (*dbstruct.ZoneMomentCreateTimes, error), mid int64, cType int64) *AuthBusinessValidator { +func (l *AuthBusinessValidator) EnsureZoneMomentCreateTimesNotReachedDailyUpperbound(fun func(*gin.Context, int64, int64, int64, int64) (*dbstruct.ZoneMomentCreateTimes, error), mid int64, cType int64) *AuthBusinessValidator { l.oplist = append(l.oplist, func() { // 读取每日发送上限 @@ -471,7 +471,14 @@ func (l *AuthBusinessValidator) EnsureZoneMomentCreateTimesNotReachedDailyUpperb return } - zoneMomentCreateTimes, err := fun(l.ctx, mid, cType) + totalIncr, freeIncr, paidIncr := int64(1), int64(0), int64(0) + if cType == consts.ZoneMomentCType_Free { + freeIncr = 1 + } else if cType == consts.ZoneMomentCType_Paid { + paidIncr = 1 + } + + zoneMomentCreateTimes, err := fun(l.ctx, mid, totalIncr, freeIncr, paidIncr) if err != nil { l.ec = errcode.ErrCodeZoneMomentCreateTimesSrvFail return diff --git a/app/mix/service/logic/zone_moment_create_times.go b/app/mix/service/logic/zone_moment_create_times.go index 57a08ebf..0e17b874 100644 --- a/app/mix/service/logic/zone_moment_create_times.go +++ b/app/mix/service/logic/zone_moment_create_times.go @@ -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 int64, cType int64) (*dbstruct.ZoneMomentCreateTimes, error) { +func (p *ZoneMomentCreateTimes) OpGetAndUpdate(ctx *gin.Context, mid, totalIncr, freeIncr, paidIncr int64) (*dbstruct.ZoneMomentCreateTimes, error) { - zoneMomentCreateTimes, err := p.store.GetAndUpdateZoneMomentCreateTimes(ctx, mid, cType) + zoneMomentCreateTimes, err := p.store.GetAndUpdateZoneMomentCreateTimes(ctx, mid, totalIncr, freeIncr, paidIncr) if err != nil { logger.Error("GetAndUpdateZoneMomentCreateTimes fail, err: %v", err) return nil, err From 4137710945611cf319eff28e7bccc31aa0875723 Mon Sep 17 00:00:00 2001 From: Leufolium Date: Fri, 26 Apr 2024 11:13:49 +0800 Subject: [PATCH 2/2] by Robin at 20240426 --- api/consts/consts.go | 1 + apollostruct/referential_zone_moment.go | 10 +++++++++ app/mix/service/apiservice.go | 27 +++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 apollostruct/referential_zone_moment.go diff --git a/api/consts/consts.go b/api/consts/consts.go index fdfb0f99..0ff7b398 100644 --- a/api/consts/consts.go +++ b/api/consts/consts.go @@ -50,6 +50,7 @@ const ( MaxDailyMomentCreateTimesKey = "max_daily_moment_create_times" DefaultMomentTextKey = "default_moment_text" MaxDailyZoneMomentCreateTimesKey = "max_daily_zone_moment_create_times" + ZoneKey = "zone" ) // del_flag diff --git a/apollostruct/referential_zone_moment.go b/apollostruct/referential_zone_moment.go new file mode 100644 index 00000000..f0e57e86 --- /dev/null +++ b/apollostruct/referential_zone_moment.go @@ -0,0 +1,10 @@ +package apollostruct + +import "service/dbstruct" + +type ReferentialZoneMoment struct { + Text *string `json:"text"` // 动态文字内容 + MediaComp *dbstruct.MediaComponent `json:"media_component"` // 动态媒体内容 + MType *int64 `json:"m_type"` // 媒体类型,见: MediaType* + Status *int64 `json:"status"` // 审批状态 +} diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 5c432795..66116068 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -2147,6 +2147,31 @@ func (s *Service) ApiCreateZone(ctx *gin.Context, req *zoneproto.ApiCreateReq) ( return } + // 创建默认动态 + cfg := apollostruct.ReferentialZoneMoment{} + err = apollo.GetJson(consts.ZoneKey, &cfg, apollo.ApolloOpts().SetNamespace("referential_zone_moment")) + if err != nil { + logger.Error("Apollo read failed : %v", err) + return errcode.ErrCodeApolloReadFail + } + + _, err = _DefaultZoneMoment.OpCreate(ctx, &zonemomentproto.OpCreateReq{ + ZoneMoment: &dbstruct.ZoneMoment{ + Mid: req.Zone.Mid, + Zid: goproto.Int64(zid), + CType: goproto.Int64(consts.ZoneMomentCType_Free), + Text: cfg.Text, + MediaComp: cfg.MediaComp, + MType: cfg.MType, + Status: cfg.Status, + }, + }) + if err != nil { + logger.Error("_DefaultZoneMoment OpCreate fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeZoneSrvFail + return + } + return } @@ -2629,8 +2654,6 @@ func (s *Service) ApiDeleteZoneMoment(ctx *gin.Context, req *zonemomentproto.Api logger.Error("OpGetAndUpdate fail, err: %v", err) ec = errcode.ErrCodeZoneMomentSrvFail return - - return } func (s *Service) ApiGetZoneMomentListByVisitorMid(ctx *gin.Context, req *zonemomentproto.ApiListByVisitorMidReq) (volist []*zonemomentproto.ApiZoneMomentVO, ec errcode.ErrCode) {