packagegroupPower_mimport("fmt""git.hilo.cn/hilo-common/domain""git.hilo.cn/hilo-common/resource/mysql")typeGroupPowerExpRankstruct{GroupPowerIdmysql.IDExpmysql.NumRankint}// 获取家族经验排行榜// param limit: 排行榜人数funcGetGroupPowerExpRank(model*domain.Model,beginDate,endDatestring,limitint)([]GroupPowerExpRank,error){varres[]GroupPowerExpRankiferr:=model.DB().Table("group_power_day_exp p").Joins(",(SELECT @curRank := 0) p").Where("date BETWEEN ? AND ?",beginDate,endDate).Select("group_power_id,SUM(exp) as exp,@curRank := @curRank + 1 `rank`").Group("group_power_id").Order("exp DESC").Limit(limit).Find(&res).Error;err!=nil{model.Log.Errorf("GetGroupPowerExpRank fail:%v",err)returnres,err}returnres,nil}// 获取我的家族排行funcGetGroupPowerExpMyRank(model*domain.Model,beginDate,endDatestring,groupPowerIdmysql.ID)(GroupPowerExpRank,error){table:=fmt.Sprintf("(select group_power_id,SUM(exp) as exp,@curRank := @curRank + 1 `rank` from group_power_day_exp p,(SELECT @curRank := 0) tmp"+" WHERE `date` BETWEEN '%s' AND '%s' group BY group_power_id ORDER BY exp DESC ) t",beginDate,endDate)varresGroupPowerExpRankiferr:=model.DB().Table(table).Select("t.group_power_id,t.exp,t.`rank`").Where("t.group_power_id = ?",groupPowerId).Scan(&res).Error;err!=nil{returnres,err}returnres,nil}