作者 yangfu

榜单编辑修改

... ... @@ -464,12 +464,12 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co
var (
addRangeData []models.RankRangeData
)
newRelationId := getDataForRankRnageRelation(companyid, rangetype, relationId)
for i := range newRelationId {
newRelationIds := getDataForRankRnageRelation(companyid, rangetype, relationId)
for i := range newRelationIds {
m := models.RankRangeData{
RankRangeId: rankRange.Id,
RangeType: rangetype,
RelationId: newRelationId[i],
RelationId: newRelationIds[i],
RankTypeId: rankRange.RankTypeId,
}
addRangeData = append(addRangeData, m)
... ... @@ -493,9 +493,9 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co
return protocol.NewErrWithMessage("1")
}
}
if len(newRelationId) > 0 {
if len(newRelationIds) > 0 {
//TODO 去除其他分组的重复项
err = deleteRankRangeDataByRelation(rankRange.RankTypeId, rangetype, newRelationId, o)
err = deleteRankRangeDataByRelation(rankRange.RankTypeId, rangetype, newRelationIds, o)
if err != nil {
log.Error(err.Error())
o.Rollback()
... ... @@ -508,6 +508,13 @@ 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")
}
}
o.Commit()
return nil
}
... ... @@ -918,3 +925,18 @@ where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in
}
return
}
func removeRanksNotIn(o orm.Ormer, companyId, rankTypeId, rankRangeId int64, relationIds []int64) (err error) {
var sqlRemoveRanks = fmt.Sprintf(`
update rank set enable_status=0,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 not in (%v)
`, utils.JoinInt64s(relationIds, ","))
if _, err = o.Raw(sqlRemoveRanks, companyId, rankTypeId, rankRangeId,
companyId, rankTypeId,
).Exec(); err != nil {
return
}
return
}
... ...