作者 yangfu

榜单编辑修改

@@ -508,13 +508,19 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co @@ -508,13 +508,19 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co
508 return protocol.NewErrWithMessage("1") 508 return protocol.NewErrWithMessage("1")
509 } 509 }
510 } 510 }
511 - if len(newRelationIds) > 0 {  
512 - if err = removeRanksNotIn(o, companyid, rankRange.RankTypeId, rankRange.Id, newRelationIds); err != nil {  
513 - log.Error("更新rank数据失败:%s", err)  
514 - o.Rollback()  
515 - return protocol.NewErrWithMessage("1")  
516 - } 511 +
  512 + if err = removeRanksNotIn(o, companyid, rankRange.RankTypeId, rankRange.Id, relationId); err != nil {
  513 + log.Error("更新rank数据失败:%s", err)
  514 + o.Rollback()
  515 + return protocol.NewErrWithMessage("1")
517 } 516 }
  517 + //if len(relationId)>0{
  518 + // if err = updateRanks(o, companyid, rankRange.RankTypeId, rankRange.Id, relationId,1); err != nil {
  519 + // log.Error("更新rank数据失败:%s", err)
  520 + // o.Rollback()
  521 + // return protocol.NewErrWithMessage("1")
  522 + // }
  523 + //}
518 o.Commit() 524 o.Commit()
519 return nil 525 return nil
520 } 526 }
@@ -899,7 +905,7 @@ func RankRangeMove(fromId int64, toId int64, relationId []int64, companyid int64 @@ -899,7 +905,7 @@ func RankRangeMove(fromId int64, toId int64, relationId []int64, companyid int64
899 o.Rollback() 905 o.Rollback()
900 return protocol.NewErrWithMessage("1") 906 return protocol.NewErrWithMessage("1")
901 } 907 }
902 - if err = removeRanks(o, companyid, fromRankRange.RankTypeId, fromRankRange.Id, relationId); err != nil { 908 + if err = updateRanks(o, companyid, fromRankRange.RankTypeId, fromRankRange.Id, relationId, 0); err != nil {
903 log.Error("更新rank数据失败:%s", err) 909 log.Error("更新rank数据失败:%s", err)
904 o.Rollback() 910 o.Rollback()
905 return protocol.NewErrWithMessage("1") 911 return protocol.NewErrWithMessage("1")
@@ -910,15 +916,15 @@ func RankRangeMove(fromId int64, toId int64, relationId []int64, companyid int64 @@ -910,15 +916,15 @@ func RankRangeMove(fromId int64, toId int64, relationId []int64, companyid int64
910 916
911 // func SetAutoCreateRank 917 // func SetAutoCreateRank
912 //排行榜批量转移用户时 ,把当前进行的排行榜分数置为无效 918 //排行榜批量转移用户时 ,把当前进行的排行榜分数置为无效
913 -func removeRanks(o orm.Ormer, companyId, rankTypeId, rankRangeId int64, relationIds []int64) (err error) { 919 +func updateRanks(o orm.Ormer, companyId, rankTypeId, rankRangeId int64, relationIds []int64, status int) (err error) {
914 var sqlRemoveRanks = fmt.Sprintf(` 920 var sqlRemoveRanks = fmt.Sprintf(`
915 - update rank set enable_status=0,update_at=NOW() 921 + update rank set enable_status=?,update_at=NOW()
916 where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in 922 where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in
917 ( 923 (
918 select id from rank_period where company_id=? and rank_type_id=? and status=1 924 select id from rank_period where company_id=? and rank_type_id=? and status=1
919 ) and relation_id in (%v) 925 ) and relation_id in (%v)
920 `, utils.JoinInt64s(relationIds, ",")) 926 `, utils.JoinInt64s(relationIds, ","))
921 - if _, err = o.Raw(sqlRemoveRanks, companyId, rankTypeId, rankRangeId, 927 + if _, err = o.Raw(sqlRemoveRanks, status, companyId, rankTypeId, rankRangeId,
922 companyId, rankTypeId, 928 companyId, rankTypeId,
923 ).Exec(); err != nil { 929 ).Exec(); err != nil {
924 return 930 return
@@ -931,8 +937,11 @@ func removeRanksNotIn(o orm.Ormer, companyId, rankTypeId, rankRangeId int64, rel @@ -931,8 +937,11 @@ func removeRanksNotIn(o orm.Ormer, companyId, rankTypeId, rankRangeId int64, rel
931 where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in 937 where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in
932 ( 938 (
933 select id from rank_period where company_id=? and rank_type_id=? and status=1 939 select id from rank_period where company_id=? and rank_type_id=? and status=1
934 -) and relation_id not in (%v)  
935 -`, utils.JoinInt64s(relationIds, ",")) 940 +)
  941 +`)
  942 + if len(relationIds) > 0 {
  943 + sqlRemoveRanks += fmt.Sprintf(" and relation_id not in (%v)", utils.JoinInt64s(relationIds, ","))
  944 + }
936 if _, err = o.Raw(sqlRemoveRanks, companyId, rankTypeId, rankRangeId, 945 if _, err = o.Raw(sqlRemoveRanks, companyId, rankTypeId, rankRangeId,
937 companyId, rankTypeId, 946 companyId, rankTypeId,
938 ).Exec(); err != nil { 947 ).Exec(); err != nil {