by Robin at 20240626

This commit is contained in:
Leufolium 2024-06-26 17:37:00 +08:00
parent 01bd876048
commit 1124d413fa
4 changed files with 77 additions and 1 deletions

View File

@ -574,3 +574,19 @@ func (m *Mysql) GetLastHourZoneAdmissionInfo(ctx *gin.Context, tx *sqlx.Tx, st,
}
return
}
// 统计空间总人数
func (m *Mysql) GetZoneMemberCountGroupByZoneMemberType(ctx *gin.Context, tx *sqlx.Tx, zids []int64) (list []*dbstruct.ZoneMemberCount, err error) {
sql := fmt.Sprintf("select count(1), zid , member_type from %s where zid in (%s) group by member_type, zid", TableVasZoneMember, util.Convert2SqlArr(zids))
list = make([]*dbstruct.ZoneMemberCount, 0)
if tx != nil {
err = tx.SelectContext(ctx, &list, sql)
} else {
db := m.getDBVas()
err = db.SelectContext(ctx, &list, sql)
}
if err != nil {
return
}
return
}

View File

@ -1238,3 +1238,26 @@ func (v *Vas) GetLastHourZoneProfit(ctx *gin.Context, st, et int64) ([]*dbstruct
func (v *Vas) GetLastHourZoneAdmissionInfo(ctx *gin.Context, tx *sqlx.Tx, st, et int64) ([]*dbstruct.ZoneAdmissionInfo, error) {
return v.store.GetLastHourZoneAdmissionInfo(ctx, tx, st, et)
}
// 统计空间总人数
func (v *Vas) GetZoneMemberCountGroupByZoneMemberType(ctx *gin.Context, zids []int64) (map[int64]map[int64]int64, error) {
countMp := make(map[int64]map[int64]int64, 0)
list, err := v.store.GetZoneMemberCountGroupByZoneMemberType(ctx, nil, zids)
if err != nil {
logger.Error("GetZoneMemberCountGroupByZoneMemberType fail err: %v", err)
return make(map[int64]map[int64]int64), nil
}
for _, zonemembercount := range list {
mp, ok := countMp[zonemembercount.GetZid()]
if ok {
mp[zonemembercount.GetMemberType()] = zonemembercount.GetNum()
} else {
mp = make(map[int64]int64)
mp[zonemembercount.GetMemberType()] = zonemembercount.GetNum()
countMp[zonemembercount.GetZid()] = mp
}
}
return countMp, nil
}

View File

@ -1970,7 +1970,10 @@ func (s *Service) utilFillZonesWithOpVOInfo(ctx *gin.Context, list []*dbstruct.Z
// 8.获取空间付费信息
zvMap, _ := _DefaultVas.GetZoneVasByIds(ctx, zids)
// 9.填充信息
// 9.获取空间人数信息
zmcountMap, _ := _DefaultVas.GetZoneMemberCountGroupByZoneMemberType(ctx, zids)
// 10.填充信息
for _, vo := range volist {
zid := vo.Zone.GetId()
@ -2003,6 +2006,12 @@ func (s *Service) utilFillZonesWithOpVOInfo(ctx *gin.Context, list []*dbstruct.Z
if zv, ok := zvMap[zid]; ok {
vo.CopyZoneVas(zv)
}
// 填充空间总人数
zmcount := zmcountMap[zid]
vo.IronfanNum = zmcount[int64(dbstruct.ZoneMemberTypeIronfan)]
vo.SuperfanNum = zmcount[int64(dbstruct.ZoneMemberTypeSuperfan)]
vo.EntrantNum = zmcount[int64(dbstruct.ZoneMemberTypeNormal)] + vo.IronfanNum + vo.SuperfanNum
}
return

View File

@ -1483,3 +1483,31 @@ func (p *RefundRate) GetRefundRate() float64 {
}
return 0
}
// 空间总人数统计
type ZoneMemberCount struct {
Zid *int64 `json:"zid" db:"zid"`
MemberType *int64 `json:"member_type" db:"member_type"`
Num *int64 `json:"num" db:"num"`
}
func (p *ZoneMemberCount) GetZid() int64 {
if p != nil && p.Zid != nil {
return *p.Zid
}
return 0
}
func (p *ZoneMemberCount) GetMemberType() int64 {
if p != nil && p.MemberType != nil {
return *p.MemberType
}
return 0
}
func (p *ZoneMemberCount) GetNum() int64 {
if p != nil && p.Num != nil {
return *p.Num
}
return 0
}