作者 yangfu

榜单范围修改

... ... @@ -383,6 +383,11 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in
log.Error("添加rank_range_data记录失败;%s", err)
return protocol.NewErrWithMessage("1")
}
if err = removeAllRanks(o, companyid, rankTypeId, newRelationId); err != nil {
log.Error("更新rank数据失败:%s", err)
o.Rollback()
return protocol.NewErrWithMessage("1")
}
}
o.Commit()
return nil
... ... @@ -949,3 +954,25 @@ where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in
}
return
}
//移除已存在的榜单记录(榜单周期内)
//同时只会存在在一个排行榜单里面
func removeAllRanks(o orm.Ormer, companyId, rankTypeId int64, relationIds []int64) (err error) {
if len(relationIds) == 0 {
return nil
}
var sqlRemoveRanks = fmt.Sprintf(`
update rank set enable_status=0,update_at=NOW()
where company_id=? and rank_type_id=? and enable_status =1 and rank_period_id in
(
select id from rank_period where company_id=? and rank_type_id=? and status=1
)
`)
if len(relationIds) > 0 {
sqlRemoveRanks += fmt.Sprintf(" and relation_id in (%v)", utils.JoinInt64s(relationIds, ","))
}
if err = utils.ExecuteSQLWithOrmer(o, sqlRemoveRanks, companyId, rankTypeId, companyId, rankTypeId); err != nil {
return
}
return
}
... ...