...
|
...
|
@@ -6,6 +6,7 @@ import ( |
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
|
|
"oppmg/utils"
|
|
|
"sort"
|
|
|
"time"
|
|
|
|
|
|
"github.com/astaxie/beego/orm"
|
...
|
...
|
@@ -398,5 +399,142 @@ func GetRankRangeInfo(id int64) protocol.ResponseRankRangeInfo { |
|
|
}
|
|
|
}
|
|
|
return rspdata
|
|
|
}
|
|
|
|
|
|
func RankRangeSort(ids []int64) error {
|
|
|
var updateData []*models.RankRange
|
|
|
for i := range ids {
|
|
|
m := &models.RankRange{
|
|
|
Id: ids[i],
|
|
|
SortNum: i,
|
|
|
}
|
|
|
updateData = append(updateData, m)
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
for i := range updateData {
|
|
|
err := models.UpdateRankRangeById(updateData[i], []string{"SortNum"}, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Error("更新rank_range数据失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
}
|
|
|
o.Commit()
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
var AllRankItem = []protocol.RankItemInfo{
|
|
|
protocol.RankItemInfo{
|
|
|
ItemName: "总分",
|
|
|
ItemKey: "zongfen",
|
|
|
},
|
|
|
protocol.RankItemInfo{
|
|
|
ItemName: "发现",
|
|
|
ItemKey: "faxian",
|
|
|
},
|
|
|
protocol.RankItemInfo{
|
|
|
ItemName: "把握",
|
|
|
ItemKey: "bawo",
|
|
|
},
|
|
|
protocol.RankItemInfo{
|
|
|
ItemName: "发现数量",
|
|
|
ItemKey: "faxianshuliang",
|
|
|
},
|
|
|
protocol.RankItemInfo{
|
|
|
ItemName: "评论数量",
|
|
|
ItemKey: "pinglunshuliang",
|
|
|
},
|
|
|
}
|
|
|
|
|
|
func GetRankItemList(companyid int64, rankTypeId int64) []protocol.RankItemInfo {
|
|
|
var (
|
|
|
rankitemData []models.RankItem
|
|
|
err error
|
|
|
)
|
|
|
rspData := make([]protocol.RankItemInfo, 0)
|
|
|
rankitemData, err = models.GetRankItemByCompanyid(companyid, rankTypeId)
|
|
|
if err != nil {
|
|
|
log.Error("获取rank_item数据失败:%s", err)
|
|
|
return rspData
|
|
|
}
|
|
|
for i := range rankitemData {
|
|
|
for ii := range AllRankItem {
|
|
|
if rankitemData[i].ItemKey == AllRankItem[ii].ItemKey {
|
|
|
m := protocol.RankItemInfo{
|
|
|
ItemKey: rankitemData[i].ItemKey,
|
|
|
ItemName: rankitemData[i].ItemName,
|
|
|
SortNum: rankitemData[i].SortNum,
|
|
|
}
|
|
|
rspData = append(rspData, m)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
sort.Sort(protocol.RankItemAll(rspData))
|
|
|
return rspData
|
|
|
}
|
|
|
|
|
|
func GetRankItemEdit(companyid int64, rankTypeid int64, itemKey []string) error {
|
|
|
var (
|
|
|
rankitemData []models.RankItem
|
|
|
err error
|
|
|
)
|
|
|
rankitemData, err = models.GetRankItemByCompanyid(companyid, rankTypeid)
|
|
|
if err != nil {
|
|
|
log.Error("获取rank_item数据失败:%s", err)
|
|
|
return nil
|
|
|
}
|
|
|
var (
|
|
|
newItems []models.RankItem
|
|
|
)
|
|
|
for i := range itemKey {
|
|
|
for ii := range AllRankItem {
|
|
|
if AllRankItem[ii].ItemKey == itemKey[i] {
|
|
|
m := models.RankItem{
|
|
|
CompanyId: companyid,
|
|
|
RankTypeId: rankTypeid,
|
|
|
ItemName: AllRankItem[ii].ItemName,
|
|
|
SortNum: i,
|
|
|
}
|
|
|
newItems = append(newItems, m)
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
var (
|
|
|
delIds []int64
|
|
|
addItems []models.RankItem
|
|
|
updateItems []models.RankItem
|
|
|
)
|
|
|
|
|
|
for i := range rankitemData {
|
|
|
var has bool = false
|
|
|
for ii := range newItems {
|
|
|
if rankitemData[i].ItemKey == newItems[ii].ItemKey {
|
|
|
has = true
|
|
|
newItems[ii].Id = rankitemData[i].Id
|
|
|
updateItems = append(updateItems, newItems[ii])
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
if !has {
|
|
|
delIds = append(delIds, rankitemData[i].Id)
|
|
|
}
|
|
|
}
|
|
|
for i := range newItems {
|
|
|
var has bool = false
|
|
|
for ii := range rankitemData {
|
|
|
if rankitemData[i].ItemKey == newItems[ii].ItemKey {
|
|
|
has = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
if !has {
|
|
|
addItems = append(addItems, newItems[i])
|
|
|
}
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
o.Commit()
|
|
|
return nil
|
|
|
} |
...
|
...
|
|