...
|
...
|
@@ -508,13 +508,19 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co |
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
}
|
|
|
if len(newRelationIds) > 0 {
|
|
|
if err = removeRanksNotIn(o, companyid, rankRange.RankTypeId, rankRange.Id, newRelationIds); err != nil {
|
|
|
log.Error("更新rank数据失败:%s", err)
|
|
|
o.Rollback()
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
|
|
|
if err = removeRanksNotIn(o, companyid, rankRange.RankTypeId, rankRange.Id, relationId); err != nil {
|
|
|
log.Error("更新rank数据失败:%s", err)
|
|
|
o.Rollback()
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
//if len(relationId)>0{
|
|
|
// if err = updateRanks(o, companyid, rankRange.RankTypeId, rankRange.Id, relationId,1); err != nil {
|
|
|
// log.Error("更新rank数据失败:%s", err)
|
|
|
// o.Rollback()
|
|
|
// return protocol.NewErrWithMessage("1")
|
|
|
// }
|
|
|
//}
|
|
|
o.Commit()
|
|
|
return nil
|
|
|
}
|
...
|
...
|
@@ -899,7 +905,7 @@ func RankRangeMove(fromId int64, toId int64, relationId []int64, companyid int64 |
|
|
o.Rollback()
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if err = removeRanks(o, companyid, fromRankRange.RankTypeId, fromRankRange.Id, relationId); err != nil {
|
|
|
if err = updateRanks(o, companyid, fromRankRange.RankTypeId, fromRankRange.Id, relationId, 0); err != nil {
|
|
|
log.Error("更新rank数据失败:%s", err)
|
|
|
o.Rollback()
|
|
|
return protocol.NewErrWithMessage("1")
|
...
|
...
|
@@ -910,15 +916,15 @@ func RankRangeMove(fromId int64, toId int64, relationId []int64, companyid int64 |
|
|
|
|
|
// func SetAutoCreateRank
|
|
|
//排行榜批量转移用户时 ,把当前进行的排行榜分数置为无效
|
|
|
func removeRanks(o orm.Ormer, companyId, rankTypeId, rankRangeId int64, relationIds []int64) (err error) {
|
|
|
func updateRanks(o orm.Ormer, companyId, rankTypeId, rankRangeId int64, relationIds []int64, status int) (err error) {
|
|
|
var sqlRemoveRanks = fmt.Sprintf(`
|
|
|
update rank set enable_status=0,update_at=NOW()
|
|
|
update rank set enable_status=?,update_at=NOW()
|
|
|
where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in
|
|
|
(
|
|
|
select id from rank_period where company_id=? and rank_type_id=? and status=1
|
|
|
) and relation_id in (%v)
|
|
|
`, utils.JoinInt64s(relationIds, ","))
|
|
|
if _, err = o.Raw(sqlRemoveRanks, companyId, rankTypeId, rankRangeId,
|
|
|
if _, err = o.Raw(sqlRemoveRanks, status, companyId, rankTypeId, rankRangeId,
|
|
|
companyId, rankTypeId,
|
|
|
).Exec(); err != nil {
|
|
|
return
|
...
|
...
|
@@ -931,8 +937,11 @@ func removeRanksNotIn(o orm.Ormer, companyId, rankTypeId, rankRangeId int64, rel |
|
|
where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in
|
|
|
(
|
|
|
select id from rank_period where company_id=? and rank_type_id=? and status=1
|
|
|
) and relation_id not in (%v)
|
|
|
`, utils.JoinInt64s(relationIds, ","))
|
|
|
)
|
|
|
`)
|
|
|
if len(relationIds) > 0 {
|
|
|
sqlRemoveRanks += fmt.Sprintf(" and relation_id not in (%v)", utils.JoinInt64s(relationIds, ","))
|
|
|
}
|
|
|
if _, err = o.Raw(sqlRemoveRanks, companyId, rankTypeId, rankRangeId,
|
|
|
companyId, rankTypeId,
|
|
|
).Exec(); err != nil {
|
...
|
...
|
|