作者 yangfu

榜单范围修改

@@ -383,6 +383,11 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in @@ -383,6 +383,11 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in
383 log.Error("添加rank_range_data记录失败;%s", err) 383 log.Error("添加rank_range_data记录失败;%s", err)
384 return protocol.NewErrWithMessage("1") 384 return protocol.NewErrWithMessage("1")
385 } 385 }
  386 + if err = removeAllRanks(o, companyid, rankTypeId, newRelationId); err != nil {
  387 + log.Error("更新rank数据失败:%s", err)
  388 + o.Rollback()
  389 + return protocol.NewErrWithMessage("1")
  390 + }
386 } 391 }
387 o.Commit() 392 o.Commit()
388 return nil 393 return nil
@@ -949,3 +954,25 @@ where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in @@ -949,3 +954,25 @@ where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in
949 } 954 }
950 return 955 return
951 } 956 }
  957 +
  958 +//移除已存在的榜单记录(榜单周期内)
  959 +//同时只会存在在一个排行榜单里面
  960 +func removeAllRanks(o orm.Ormer, companyId, rankTypeId int64, relationIds []int64) (err error) {
  961 + if len(relationIds) == 0 {
  962 + return nil
  963 + }
  964 + var sqlRemoveRanks = fmt.Sprintf(`
  965 + update rank set enable_status=0,update_at=NOW()
  966 +where company_id=? and rank_type_id=? and enable_status =1 and rank_period_id in
  967 +(
  968 + select id from rank_period where company_id=? and rank_type_id=? and status=1
  969 +)
  970 +`)
  971 + if len(relationIds) > 0 {
  972 + sqlRemoveRanks += fmt.Sprintf(" and relation_id in (%v)", utils.JoinInt64s(relationIds, ","))
  973 + }
  974 + if err = utils.ExecuteSQLWithOrmer(o, sqlRemoveRanks, companyId, rankTypeId, companyId, rankTypeId); err != nil {
  975 + return
  976 + }
  977 + return
  978 +}