|
|
package rank
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
|
|
"oppmg/utils"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
//GetRankList 获取榜单类型列表
|
|
|
func GetRankList(companyid int64) []protocol.ResponseRankType {
|
|
|
var (
|
|
|
rspData = make([]protocol.ResponseRankType, 0)
|
|
|
err error
|
|
|
)
|
|
|
sqlString := `SELECT id,name,status,rank_type FROM rank WHERE company_id=?`
|
|
|
err = utils.ExecuteQueryAll(&rspData, sqlString, companyid)
|
|
|
if err != nil {
|
|
|
log.Error("获取榜单列表失败,err%s", err)
|
|
|
return rspData
|
|
|
}
|
|
|
if len(rspData) >= 2 {
|
|
|
return rspData
|
|
|
}
|
|
|
if len(rspData) < 2 {
|
|
|
AddDefaultRankType(companyid)
|
|
|
}
|
|
|
err = utils.ExecuteQueryAll(&rspData, sqlString, companyid)
|
|
|
if err != nil {
|
|
|
log.Error("获取榜单列表失败,err%s", err)
|
|
|
return rspData
|
|
|
}
|
|
|
return rspData
|
|
|
}
|
|
|
|
|
|
func AddDefaultRankType(companyid int64) []*models.RankType {
|
|
|
var (
|
|
|
rankA *models.RankType
|
|
|
rankB *models.RankType
|
|
|
err error
|
|
|
)
|
|
|
rankA = &models.RankType{
|
|
|
CompanyId: companyid,
|
|
|
Name: "季赛榜",
|
|
|
Type: models.RANK_TYPE_SEASON,
|
|
|
EnableStatus: models.RANK_STATUS_YES,
|
|
|
}
|
|
|
rankB = &models.RankType{
|
|
|
CompanyId: companyid,
|
|
|
Name: "年榜",
|
|
|
Type: models.RANK_TYPE_YEAR,
|
|
|
EnableStatus: models.RANK_STATUS_YES,
|
|
|
}
|
|
|
_, err = models.AddRank(rankA)
|
|
|
if err != nil {
|
|
|
log.Error("添加榜单失败:AddRank,err:%s", err)
|
|
|
}
|
|
|
_, err = models.AddRank(rankB)
|
|
|
if err != nil {
|
|
|
log.Error("添加榜单失败:AddRank,err:%s", err)
|
|
|
}
|
|
|
ranks := []*models.RankType{
|
|
|
rankA, rankB,
|
|
|
}
|
|
|
return ranks
|
|
|
}
|
|
|
|
|
|
func UpdateRankType(id int64, name string, companyid int64) error {
|
|
|
var (
|
|
|
err error
|
|
|
ranktype *models.RankType
|
|
|
)
|
|
|
ranktype, err = models.GetRankById(id)
|
|
|
if err != nil {
|
|
|
log.Error("获取榜单类型数据失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if ranktype.CompanyId != companyid {
|
|
|
log.Error("数据无法与公司id对应")
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
ranktype.Name = name
|
|
|
err = models.UpdateRankById(ranktype, []string{"Name"})
|
|
|
if err != nil {
|
|
|
log.Error("更新榜单数据失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//ForbidRank 禁用榜单
|
|
|
func ForbidRank(id int64, companyid int64) error {
|
|
|
var (
|
|
|
err error
|
|
|
ranktype *models.RankType
|
|
|
)
|
|
|
ranktype, err = models.GetRankById(id)
|
|
|
if err != nil {
|
|
|
log.Error("获取榜单类型数据失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if ranktype.CompanyId != companyid {
|
|
|
log.Error("数据无法与公司id对应")
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
ranktype.EnableStatus = models.RANK_STATUS_NO
|
|
|
err = models.UpdateRankById(ranktype, []string{"EnableStatus"})
|
|
|
if err != nil {
|
|
|
log.Error("更新榜单数据失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
//AllowRank 启用榜单
|
|
|
func AllowRank(id int64, companyid int64) error {
|
|
|
var (
|
|
|
err error
|
|
|
ranktype *models.RankType
|
|
|
)
|
|
|
ranktype, err = models.GetRankById(id)
|
|
|
if err != nil {
|
|
|
log.Error("获取榜单类型数据失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if ranktype.CompanyId != companyid {
|
|
|
log.Error("数据无法与公司id对应")
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
ranktype.EnableStatus = models.RANK_STATUS_YES
|
|
|
err = models.UpdateRankById(ranktype, []string{"EnableStatus"})
|
|
|
if err != nil {
|
|
|
log.Error("更新榜单数据失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
//RankSeasonList ..获取赛季列表
|
|
|
func RankSeasonList(pageindex int, pagesize int, companyid int64) (protocol.ResponseRankSeasonList, error) {
|
|
|
var (
|
|
|
err error
|
|
|
listdata []protocol.RankSeasonItem
|
|
|
cnt int64
|
|
|
)
|
|
|
rspData := protocol.ResponseRankSeasonList{
|
|
|
ResponsePageInfo: protocol.ResponsePageInfo{
|
|
|
TotalPage: 0, CurrentPage: pageindex,
|
|
|
},
|
|
|
List: make([]protocol.RankSeasonItem, 0),
|
|
|
}
|
|
|
pageStart := (pageindex - 1) * pagesize
|
|
|
datasql := `SELECT id,season_name,begin_time,end_time,status FROM rank_period WHERE company_id = ?`
|
|
|
datasql = fmt.Sprintf("%s ORDER BY begin_time DESC limit %d,%d", datasql, pageStart, pagesize)
|
|
|
countsql := `SELECT COUNT(*) FROM rank_period WHERE company_id = ?`
|
|
|
err = utils.ExecuteQueryOne(&cnt, countsql, companyid)
|
|
|
if err != nil {
|
|
|
log.Error("EXCUTE SQL ERR:%s", err)
|
|
|
return rspData, nil
|
|
|
}
|
|
|
if cnt <= 0 {
|
|
|
return rspData, nil
|
|
|
}
|
|
|
err = utils.ExecuteQueryAll(&listdata, datasql, companyid)
|
|
|
if err != nil {
|
|
|
log.Error("EXCUTE SQL ERR:%s", err)
|
|
|
return rspData, nil
|
|
|
}
|
|
|
return rspData, err
|
|
|
}
|
|
|
|
|
|
func AddRankSeason(beginTime int64, endTime int64, name string, companyid int64) error {
|
|
|
var (
|
|
|
err error
|
|
|
)
|
|
|
m := &models.RankPeriod{
|
|
|
CompanyId: companyid,
|
|
|
SeasonName: name,
|
|
|
BeginTime: time.Unix(beginTime, 0),
|
|
|
EndTime: time.Unix(endTime, 0),
|
|
|
Status: 0,
|
|
|
}
|
|
|
_, err = models.AddRankPeriod(m)
|
|
|
if err != nil {
|
|
|
log.Error("添加赛季失败;%s", err)
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
func EditRankSeason(id int64, beginTime int64, endTime int64, name string, companyid int64) error {
|
|
|
var (
|
|
|
err error
|
|
|
m *models.RankPeriod
|
|
|
)
|
|
|
m, err = models.GetRankPeriodById(id)
|
|
|
if err != nil {
|
|
|
log.Error("获取赛季失败;%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if m.CompanyId != companyid {
|
|
|
log.Error("公司不匹配")
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
m.SeasonName = name
|
|
|
m.BeginTime = time.Unix(beginTime, 0)
|
|
|
m.EndTime = time.Unix(endTime, 0)
|
|
|
err = models.UpdateRankPeriodById(m)
|
|
|
if err != nil {
|
|
|
log.Error("更新赛季失败;%s", err)
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//获取赛季参与人列表
|
|
|
func GetRankRangeList() {
|
|
|
|
|
|
} |
...
|
...
|
|