package bahe_service import ( "fmt" "hudongzhuanjia/models" "hudongzhuanjia/utils/define" "github.com/ouxuanserver/osmanthuswine/src/core" ) type CountMembersResult struct { Number int `json:"number,omitempty"` TeamId int64 `json:"team_id,omitempty"` Color string `json:"color,omitempty"` } func CountMembers(baheId int64) ([]*CountMembersResult, error) { result := make([]*CountMembersResult, 0) err := core.GetXormAuto().Table(new(models.BaheTeam)).Alias("t"). Select("count(m.id) as number, t.id as team_id, t.bahe_team_name as color"). Join("left", "ox_bahe_team_member as m", "m.team_id=t.id and m.is_delete=0"). Where("t.is_delete=0 and t.bahe_activity_id = ?", baheId).Desc("color"). GroupBy("t.id").Find(&result) return result, err } func GetMember(bid, rid, uid int64) (*models.BaheTeamMember, bool, error) { member := new(models.BaheTeamMember) exist, err := core.GetXormAuto().Where("is_delete=0 and rehearsal_id=? and "+ "bahe_activity_id=? and member_id=?", rid, bid, uid).Get(member) return member, exist, err } func GetCurrentTugWar(aid, uid, rid int64) (map[string]interface{}, error) { bahe := new(models.TugOfWar) exist, err := bahe.GetCurrent(aid) if err != nil { return nil, err } if !exist { return nil, fmt.Errorf("轮次尚未开启") } member := new(models.BaheTeamMember) exist, err = member.GetMemberByBaheIdAndUserId(uid, bahe.Id, rid) if err != nil { return nil, err } if exist { return map[string]interface{}{ "member": member, }, nil } if bahe.Model == define.TUGWAR_MODEL_RANDOM { return map[string]interface{}{ "model": bahe.Model, "bahe_activity_id": bahe.Id, }, nil } res, err := CountMembers(bahe.Id) if err != nil { return nil, err } return map[string]interface{}{ "list": res, "model": bahe.Model, "bahe_activity_id": bahe.Id, "limit": bahe.Number, }, nil }