作者 yangfu

榜单编辑修改

@@ -464,12 +464,12 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co @@ -464,12 +464,12 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co
464 var ( 464 var (
465 addRangeData []models.RankRangeData 465 addRangeData []models.RankRangeData
466 ) 466 )
467 - newRelationId := getDataForRankRnageRelation(companyid, rangetype, relationId)  
468 - for i := range newRelationId { 467 + newRelationIds := getDataForRankRnageRelation(companyid, rangetype, relationId)
  468 + for i := range newRelationIds {
469 m := models.RankRangeData{ 469 m := models.RankRangeData{
470 RankRangeId: rankRange.Id, 470 RankRangeId: rankRange.Id,
471 RangeType: rangetype, 471 RangeType: rangetype,
472 - RelationId: newRelationId[i], 472 + RelationId: newRelationIds[i],
473 RankTypeId: rankRange.RankTypeId, 473 RankTypeId: rankRange.RankTypeId,
474 } 474 }
475 addRangeData = append(addRangeData, m) 475 addRangeData = append(addRangeData, m)
@@ -493,9 +493,9 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co @@ -493,9 +493,9 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co
493 return protocol.NewErrWithMessage("1") 493 return protocol.NewErrWithMessage("1")
494 } 494 }
495 } 495 }
496 - if len(newRelationId) > 0 { 496 + if len(newRelationIds) > 0 {
497 //TODO 去除其他分组的重复项 497 //TODO 去除其他分组的重复项
498 - err = deleteRankRangeDataByRelation(rankRange.RankTypeId, rangetype, newRelationId, o) 498 + err = deleteRankRangeDataByRelation(rankRange.RankTypeId, rangetype, newRelationIds, o)
499 if err != nil { 499 if err != nil {
500 log.Error(err.Error()) 500 log.Error(err.Error())
501 o.Rollback() 501 o.Rollback()
@@ -508,6 +508,13 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co @@ -508,6 +508,13 @@ 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 + }
  517 + }
511 o.Commit() 518 o.Commit()
512 return nil 519 return nil
513 } 520 }
@@ -918,3 +925,18 @@ where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in @@ -918,3 +925,18 @@ where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in
918 } 925 }
919 return 926 return
920 } 927 }
  928 +func removeRanksNotIn(o orm.Ormer, companyId, rankTypeId, rankRangeId int64, relationIds []int64) (err error) {
  929 + var sqlRemoveRanks = fmt.Sprintf(`
  930 + update rank set enable_status=0,update_at=NOW()
  931 +where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in
  932 +(
  933 + 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, ","))
  936 + if _, err = o.Raw(sqlRemoveRanks, companyId, rankTypeId, rankRangeId,
  937 + companyId, rankTypeId,
  938 + ).Exec(); err != nil {
  939 + return
  940 + }
  941 + return
  942 +}