diff --git a/api/consts/status.go b/api/consts/status.go index 45c70698..0c1a5f81 100644 --- a/api/consts/status.go +++ b/api/consts/status.go @@ -380,12 +380,16 @@ const ( // 热榜状态 const ( - ActivityHotStatus_Normal = 0 // 已生效 - ActivityHotStatus_Paused = 1 // 已暂停 + ActivityHotStatus_Normal = 0 // 已生效 + ActivityHotStatus_Paused = 1 // 已暂停 + ActivityHotStatus_Expired = 2 // 已失效(外层封装逻辑) + ActivityHotStatus_Waiting = 3 // 待开始(外层封装逻辑) ) // 活动Banner状态 const ( - ActivityBannerStatus_Normal = 0 // 已生效 - ActivityBannerStatus_Paused = 1 // 已暂停 + ActivityBannerStatus_Normal = 0 // 已生效 + ActivityBannerStatus_Paused = 1 // 已暂停 + ActivityBannerStatus_Expired = 2 // 已失效(外层封装逻辑) + ActivityBannerStatus_Waiting = 3 // 待开始(外层封装逻辑) ) diff --git a/api/proto/activity_banner/proto/activity_banner_op.go b/api/proto/activity_banner/proto/activity_banner_op.go index f0d1db1b..293e40cd 100644 --- a/api/proto/activity_banner/proto/activity_banner_op.go +++ b/api/proto/activity_banner/proto/activity_banner_op.go @@ -52,7 +52,6 @@ type OpListReq struct { base.BaseRequest DeviceType *int64 `json:"device_type"` Status *int64 `json:"status"` - IsValid bool `json:"is_valid"` Offset int `json:"offset"` Limit int `json:"limit"` } diff --git a/api/proto/activity_hot/proto/activity_hot_api_vo.go b/api/proto/activity_hot/proto/activity_hot_api_vo.go index b86a054c..6649c143 100644 --- a/api/proto/activity_hot/proto/activity_hot_api_vo.go +++ b/api/proto/activity_hot/proto/activity_hot_api_vo.go @@ -6,6 +6,7 @@ import ( type ActivityHotApiVO struct { Mid int64 `json:"mid" bson:"mid"` // 主播mid + UserId int64 `json:"user_id" bson:"user_id"` // 主播user_id Image *dbstruct.MediaComponent `json:"image" bson:"image"` // 主图 Title string `json:"title" bson:"title"` // 标题 Text string `json:"text" bson:"text"` // 文字内容 diff --git a/api/proto/activity_hot/proto/activity_hot_op.go b/api/proto/activity_hot/proto/activity_hot_op.go index f966fec9..128d5f0c 100644 --- a/api/proto/activity_hot/proto/activity_hot_op.go +++ b/api/proto/activity_hot/proto/activity_hot_op.go @@ -50,11 +50,10 @@ type OpUpdateResp struct { // op 列表 type OpListReq struct { base.BaseRequest - Uid *int64 `json:"mid"` - Status *int64 `json:"status"` - IsValid bool `json:"is_valid"` - Offset int `json:"offset"` - Limit int `json:"limit"` + Uid *int64 `json:"mid"` + Status *int64 `json:"status"` + Offset int `json:"offset"` + Limit int `json:"limit"` } type OpListData struct { diff --git a/api/proto/activity_hot/proto/activity_hot_op_vo.go b/api/proto/activity_hot/proto/activity_hot_op_vo.go new file mode 100644 index 00000000..36cbae44 --- /dev/null +++ b/api/proto/activity_hot/proto/activity_hot_op_vo.go @@ -0,0 +1,43 @@ +package proto + +import ( + "service/api/consts" + "service/dbstruct" + + goproto "google.golang.org/protobuf/proto" +) + +type ActivityHotOpVO struct { + *dbstruct.ActivityHot + UserId int64 `json:"user_id" bson:"user_id"` // 主播user_id +} + +func NewActivityHotOpVO() *ActivityHotOpVO { + return &ActivityHotOpVO{} +} + +func (vo *ActivityHotOpVO) CopyActivityHot(activityHot *dbstruct.ActivityHot) *ActivityHotOpVO { + if activityHot == nil { + return vo + } + vo.ActivityHot = activityHot + return vo +} + +func (vo *ActivityHotOpVO) CopyAccount(account *dbstruct.Account) *ActivityHotOpVO { + if account == nil { + return vo + } + vo.UserId = account.GetUserId() + return vo +} + +// 设置状态 +func (vo *ActivityHotOpVO) SetStatus(nt int64) *ActivityHotOpVO { + if vo.ActivityHot.GetSt() > nt { // 开始时间晚于当前时间,则为未开始 + vo.ActivityHot.Status = goproto.Int64(consts.ActivityHotStatus_Waiting) + } else if vo.ActivityHot.GetEt() < nt { // 结束时间早于当前时间,则为已过期 + vo.ActivityHot.Status = goproto.Int64(consts.ActivityHotStatus_Expired) + } + return vo +} diff --git a/app/mix/dao/mongo.go b/app/mix/dao/mongo.go index 4e20f467..2bbbc4af 100644 --- a/app/mix/dao/mongo.go +++ b/app/mix/dao/mongo.go @@ -7238,21 +7238,33 @@ func (m *Mongo) GetActivityHotList(ctx *gin.Context, req *activity_hot_proto.OpL "del_flag": 0, } + nt := time.Now().Unix() + if req.Uid != nil { query["mid"] = util.DerefInt64(req.Uid) } if req.Status != nil { - query["status"] = util.DerefInt64(req.Status) - } - - if req.IsValid { - nt := time.Now().Unix() - query["st"] = qmgo.M{ - "$lte": nt, - } - query["et"] = qmgo.M{ - "$gte": nt, + switch util.DerefInt64(req.Status) { + // 正常或暂停 + case consts.ActivityHotStatus_Normal, consts.ActivityHotStatus_Paused: + query["status"] = util.DerefInt64(req.Status) + query["st"] = qmgo.M{ + "$lte": nt, + } + query["et"] = qmgo.M{ + "$gte": nt, + } + // 未开始,开始时间必须大于现在的时间(即晚于) + case consts.ActivityHotStatus_Waiting: + query["st"] = qmgo.M{ + "$gt": nt, + } + // 已失效,结束时间必须小于现在的时间(即早于) + case consts.ActivityHotStatus_Expired: + query["et"] = qmgo.M{ + "$lt": nt, + } } } @@ -7332,21 +7344,33 @@ func (m *Mongo) GetActivityBannerList(ctx *gin.Context, req *activity_banner_pro "del_flag": 0, } + nt := time.Now().Unix() + if req.Status != nil { - query["status"] = util.DerefInt64(req.Status) - } - - if req.IsValid { - nt := time.Now().Unix() - query["st"] = qmgo.M{ - "$lte": nt, - } - query["et"] = qmgo.M{ - "$gte": nt, + switch util.DerefInt64(req.Status) { + // 正常或暂停 + case consts.ActivityBannerStatus_Normal, consts.ActivityBannerStatus_Paused: + query["status"] = util.DerefInt64(req.Status) + query["st"] = qmgo.M{ + "$lte": nt, + } + query["et"] = qmgo.M{ + "$gte": nt, + } + // 未开始,开始时间必须大于现在的时间(即晚于) + case consts.ActivityBannerStatus_Waiting: + query["st"] = qmgo.M{ + "$gt": nt, + } + // 已失效,结束时间必须小于现在的时间(即早于) + case consts.ActivityBannerStatus_Expired: + query["et"] = qmgo.M{ + "$lt": nt, + } } } - err := col.Find(ctx, query).Sort("-ct").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) + err := col.Find(ctx, query).Sort("-priority").Skip(int64(req.Offset)).Limit(int64(req.Limit)).All(&list) if err == qmgo.ErrNoSuchDocuments { err = nil return list, err diff --git a/app/mix/service/apiservice.go b/app/mix/service/apiservice.go index 0f51978f..6b0615e6 100644 --- a/app/mix/service/apiservice.go +++ b/app/mix/service/apiservice.go @@ -4888,7 +4888,7 @@ func (s *Service) ApiGetActivityHotList(ctx *gin.Context, req *activity_hot_prot // 填充信息 if len(list) > 0 { - vl, err := s.utilFillActivityHotVO(ctx, activityHotMp, mids) + vl, err := s.utilFillActivityHotApiVO(ctx, activityHotMp, mids) if err != nil { logger.Error("utilFillActivityHotVO fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeActivityHotSrvFail diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 2b44090a..b883d8f1 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -5554,14 +5554,25 @@ func (s *Service) OpDeleteActivityHot(ctx *gin.Context, id int64) (ec errcode.Er return } -func (s *Service) OpGetActivityHotList(ctx *gin.Context, req *activity_hot_proto.OpListReq) (list []*dbstruct.ActivityHot, ec errcode.ErrCode) { +func (s *Service) OpGetActivityHotList(ctx *gin.Context, req *activity_hot_proto.OpListReq) (volist []*activity_hot_proto.ActivityHotOpVO, ec errcode.ErrCode) { ec = errcode.ErrCodeActivityHotSrvOk + + volist = make([]*activity_hot_proto.ActivityHotOpVO, 0) + list, err := _DefaultActivityHot.OpList(ctx, req) if err != nil { logger.Error("OpGetActivityHotList fail, req: %v, err: %v", util.ToJson(req), err) ec = errcode.ErrCodeActivityHotSrvFail return } + + volist, err = s.utilFillActivityHotOpVO(ctx, list) + if err != nil { + logger.Error("utilFillActivityHotOpVO fail, req: %v, err: %v", util.ToJson(req), err) + ec = errcode.ErrCodeActivityHotSrvFail + return + } + return } @@ -5615,5 +5626,16 @@ func (s *Service) OpGetActivityBannerList(ctx *gin.Context, req *activity_banner ec = errcode.ErrCodeActivityBannerSrvFail return } + + // 当前时间 + nt := time.Now().Unix() + + for _, v := range list { + if v.GetSt() > nt { // 开始时间晚于当前时间,则为未开始 + v.Status = goproto.Int64(consts.ActivityHotStatus_Waiting) + } else if v.GetEt() < nt { // 结束时间早于当前时间,则为已过期 + v.Status = goproto.Int64(consts.ActivityHotStatus_Expired) + } + } return } diff --git a/app/mix/service/utilservice.go b/app/mix/service/utilservice.go index 3a4de801..d088d827 100644 --- a/app/mix/service/utilservice.go +++ b/app/mix/service/utilservice.go @@ -2423,7 +2423,7 @@ func (s *Service) utilGetRecentReceiveNotif(ctx *gin.Context, mid, nType int64) return notif, nil } -func (s *Service) utilFillActivityHotVO(ctx *gin.Context, activityHotMp map[int64]*dbstruct.ActivityHot, mids []int64) ([]*activity_hot_proto.ActivityHotApiVO, error) { +func (s *Service) utilFillActivityHotApiVO(ctx *gin.Context, activityHotMp map[int64]*dbstruct.ActivityHot, mids []int64) ([]*activity_hot_proto.ActivityHotApiVO, error) { volist := make([]*activity_hot_proto.ActivityHotApiVO, 0) acctMp, err := _DefaultAccount.GetAccountMapByMids(ctx, mids) @@ -2463,6 +2463,35 @@ func (s *Service) utilFillActivityHotVO(ctx *gin.Context, activityHotMp map[int6 return volist, nil } +func (s *Service) utilFillActivityHotOpVO(ctx *gin.Context, list []*dbstruct.ActivityHot) ([]*activity_hot_proto.ActivityHotOpVO, error) { + volist := make([]*activity_hot_proto.ActivityHotOpVO, 0) + + mids := make([]int64, 0) + midMp := make(map[int64]*dbstruct.Account) + for _, v := range list { + if midMp[v.GetMid()] == nil { + midMp[v.GetMid()] = &dbstruct.Account{} + mids = append(mids, v.GetMid()) + } + } + + // 补足account表信息 + acctMp, err := _DefaultAccount.GetAccountMapByMids(ctx, mids) + if err != nil { + logger.Error("GetAccountMapByMids failed, err: %v", err) + return make([]*activity_hot_proto.ActivityHotOpVO, 0), err + } + + // 当前时间 + nt := time.Now().Unix() + + for _, v := range list { + vo := activity_hot_proto.NewActivityHotOpVO().CopyActivityHot(v).CopyAccount(acctMp[v.GetMid()]).SetStatus(nt) + volist = append(volist, vo) + } + return volist, nil +} + func (s *Service) utilCompleteActivityHotList(ctx *gin.Context, existedMp map[int64]*dbstruct.ActivityHot, remLength int) ([]*activity_hot_proto.ActivityHotApiVO, error) { volist := make([]*activity_hot_proto.ActivityHotApiVO, 0) diff --git a/dbstruct/activity_banner.go b/dbstruct/activity_banner.go index d8d715a9..f4919702 100644 --- a/dbstruct/activity_banner.go +++ b/dbstruct/activity_banner.go @@ -8,6 +8,7 @@ type ActivityBanner struct { St *int64 `json:"st" bson:"st"` // 开始时间 Et *int64 `json:"et" bson:"et"` // 结束时间 DeviceType *int64 `json:"device_type" bson:"device_type"` // 支持的设备类型 + Priority *int64 `json:"priority" bson:"priority"` // 优先级 Status *int64 `json:"status" bson:"status"` // 状态 0-已生效,1-已暂停 Ct *int64 `json:"ct" bson:"ct"` // 创建时间 Ut *int64 `json:"ut" bson:"ut"` // 更新时间 diff --git a/dbstruct/activity_hot.go b/dbstruct/activity_hot.go index 892cce33..dde34d19 100644 --- a/dbstruct/activity_hot.go +++ b/dbstruct/activity_hot.go @@ -50,3 +50,10 @@ func (p *ActivityHot) GetEt() int64 { } return *p.Et } + +func (p *ActivityHot) GetStatus() int64 { + if p == nil || p.Status == nil { + return -1 + } + return *p.Status +}