作者 tangxvhui

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev

@@ -819,8 +819,29 @@ func RankRangeMove(fromId int64, toId int64, relationId []int64, companyid int64 @@ -819,8 +819,29 @@ func RankRangeMove(fromId int64, toId int64, relationId []int64, companyid int64
819 o.Rollback() 819 o.Rollback()
820 return protocol.NewErrWithMessage("1") 820 return protocol.NewErrWithMessage("1")
821 } 821 }
  822 + if err = removeRanks(o, companyid, fromRankRange.RankTypeId, fromRankRange.Id, relationId); err != nil {
  823 + log.Error("更新rank数据失败:%s", err)
  824 + o.Rollback()
  825 + return protocol.NewErrWithMessage("1")
  826 + }
822 o.Commit() 827 o.Commit()
823 return nil 828 return nil
824 } 829 }
825 830
826 // func SetAutoCreateRank 831 // func SetAutoCreateRank
  832 +//排行榜批量转移用户时 ,把当前进行的排行榜分数置为无效
  833 +func removeRanks(o orm.Ormer, companyId, rankTypeId, rankRangeId int64, relationIds []int64) (err error) {
  834 + var sqlRemoveRanks = fmt.Sprintf(`
  835 + update rank set enable_status=0,update_at=NOW()
  836 +where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id in
  837 +(
  838 + select id from rank_period where company_id=? and rank_type_id=? and status=1
  839 +) and relation_id in (%v)
  840 +`, utils.JoinInt64s(relationIds, ","))
  841 + if _, err = o.Raw(sqlRemoveRanks, companyId, rankTypeId, rankRangeId,
  842 + companyId, rankTypeId,
  843 + ).Exec(); err != nil {
  844 + return
  845 + }
  846 + return
  847 +}
1 package utils 1 package utils
2 2
3 import ( 3 import (
  4 + "fmt"
4 "strings" 5 "strings"
5 ) 6 )
6 7
@@ -54,3 +55,11 @@ func ArrayStringIn(arr1 []string, s string) bool { @@ -54,3 +55,11 @@ func ArrayStringIn(arr1 []string, s string) bool {
54 } 55 }
55 return false 56 return false
56 } 57 }
  58 +
  59 +func JoinInt64s(ids []int64, spilt string) string {
  60 + var idStrings []string = make([]string, len(ids))
  61 + for i := 0; i < len(ids); i++ {
  62 + idStrings[i] = fmt.Sprintf("%v", ids[i])
  63 + }
  64 + return strings.Join(idStrings, spilt)
  65 +}