|
@@ -280,7 +280,7 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in |
|
@@ -280,7 +280,7 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in |
280
|
log.Error("添加rank_range记录失败:%s", err)
|
280
|
log.Error("添加rank_range记录失败:%s", err)
|
281
|
return protocol.NewErrWithMessage("1")
|
281
|
return protocol.NewErrWithMessage("1")
|
282
|
}
|
282
|
}
|
283
|
- //TODO 去除其他分组的重复项
|
283
|
+
|
284
|
for i := range relationId {
|
284
|
for i := range relationId {
|
285
|
m := models.RankRangeData{
|
285
|
m := models.RankRangeData{
|
286
|
RankRangeId: rankRange.Id,
|
286
|
RankRangeId: rankRange.Id,
|
|
@@ -291,6 +291,13 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in |
|
@@ -291,6 +291,13 @@ func AddRankRange(rankTypeId int64, name string, rangetype int8, relationId []in |
291
|
rankRangeDatas = append(rankRangeDatas, m)
|
291
|
rankRangeDatas = append(rankRangeDatas, m)
|
292
|
}
|
292
|
}
|
293
|
if len(rankRangeDatas) > 0 {
|
293
|
if len(rankRangeDatas) > 0 {
|
|
|
294
|
+ //TODO 去除其他分组的重复项
|
|
|
295
|
+ err = deleteRankRangeDataByRelation(rankTypeId, rangetype, relationId, o)
|
|
|
296
|
+ if err != nil {
|
|
|
297
|
+ log.Error(err.Error())
|
|
|
298
|
+ o.Rollback()
|
|
|
299
|
+ return protocol.NewErrWithMessage("1")
|
|
|
300
|
+ }
|
294
|
_, err = models.AddRankRangeDataMulti(rankRangeDatas, o)
|
301
|
_, err = models.AddRankRangeDataMulti(rankRangeDatas, o)
|
295
|
if err != nil {
|
302
|
if err != nil {
|
296
|
o.Rollback()
|
303
|
o.Rollback()
|
|
@@ -324,28 +331,18 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co |
|
@@ -324,28 +331,18 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co |
324
|
}
|
331
|
}
|
325
|
var (
|
332
|
var (
|
326
|
oldids []int64
|
333
|
oldids []int64
|
327
|
- delids []int64
|
|
|
328
|
- addids []int64
|
|
|
329
|
)
|
334
|
)
|
330
|
- if rankRange.Type != rangetype {
|
|
|
331
|
- //当rangeType不同时
|
|
|
332
|
- delids = oldids
|
|
|
333
|
- addids = relationId
|
|
|
334
|
- } else {
|
|
|
335
|
- for i := range rankRangeDatas {
|
|
|
336
|
- oldids = append(oldids, rankRangeDatas[i].RelationId)
|
|
|
337
|
- }
|
|
|
338
|
- delids = utils.ArrayInt64Diff(oldids, relationId)
|
|
|
339
|
- addids = utils.ArrayInt64Diff(relationId, oldids)
|
335
|
+ for i := range rankRangeDatas {
|
|
|
336
|
+ oldids = append(oldids, rankRangeDatas[i].RelationId)
|
340
|
}
|
337
|
}
|
341
|
var (
|
338
|
var (
|
342
|
addRangeData []models.RankRangeData
|
339
|
addRangeData []models.RankRangeData
|
343
|
)
|
340
|
)
|
344
|
- for i := range addids {
|
341
|
+ for i := range relationId {
|
345
|
r := models.RankRangeData{
|
342
|
r := models.RankRangeData{
|
346
|
RankRangeId: id,
|
343
|
RankRangeId: id,
|
347
|
RangeType: rangetype,
|
344
|
RangeType: rangetype,
|
348
|
- RelationId: addids[i],
|
345
|
+ RelationId: relationId[i],
|
349
|
}
|
346
|
}
|
350
|
addRangeData = append(addRangeData, r)
|
347
|
addRangeData = append(addRangeData, r)
|
351
|
}
|
348
|
}
|
|
@@ -353,22 +350,30 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co |
|
@@ -353,22 +350,30 @@ func EditRankRange(id int64, name string, rangetype int8, relationId []int64, co |
353
|
rankRange.Type = rangetype
|
350
|
rankRange.Type = rangetype
|
354
|
o := orm.NewOrm()
|
351
|
o := orm.NewOrm()
|
355
|
o.Begin()
|
352
|
o.Begin()
|
356
|
- //TODO 去除其他分组的重复项
|
353
|
+
|
357
|
err = models.UpdateRankRangeById(rankRange, []string{"Name", "Type"}, o)
|
354
|
err = models.UpdateRankRangeById(rankRange, []string{"Name", "Type"}, o)
|
358
|
if err != nil {
|
355
|
if err != nil {
|
359
|
o.Rollback()
|
356
|
o.Rollback()
|
360
|
log.Error("添加rank_range数据失败:%s", err)
|
357
|
log.Error("添加rank_range数据失败:%s", err)
|
361
|
return protocol.NewErrWithMessage("1")
|
358
|
return protocol.NewErrWithMessage("1")
|
362
|
}
|
359
|
}
|
363
|
- if len(delids) > 0 {
|
|
|
364
|
- err = models.DeleteRankRangeData(delids, o)
|
360
|
+
|
|
|
361
|
+ if len(oldids) > 0 {
|
|
|
362
|
+ err = models.DeleteRankRangeData(oldids, o)
|
365
|
if err != nil {
|
363
|
if err != nil {
|
366
|
o.Rollback()
|
364
|
o.Rollback()
|
367
|
log.Error("删除rank_range_data数据失败:%s", err)
|
365
|
log.Error("删除rank_range_data数据失败:%s", err)
|
368
|
return protocol.NewErrWithMessage("1")
|
366
|
return protocol.NewErrWithMessage("1")
|
369
|
}
|
367
|
}
|
370
|
}
|
368
|
}
|
371
|
- if len(addids) > 0 {
|
369
|
+ if len(relationId) > 0 {
|
|
|
370
|
+ //TODO 去除其他分组的重复项
|
|
|
371
|
+ err = deleteRankRangeDataByRelation(rankRange.RankTypeId, rangetype, relationId, o)
|
|
|
372
|
+ if err != nil {
|
|
|
373
|
+ log.Error(err.Error())
|
|
|
374
|
+ o.Rollback()
|
|
|
375
|
+ return protocol.NewErrWithMessage("1")
|
|
|
376
|
+ }
|
372
|
_, err = models.AddRankRangeDataMulti(addRangeData, o)
|
377
|
_, err = models.AddRankRangeDataMulti(addRangeData, o)
|
373
|
if err != nil {
|
378
|
if err != nil {
|
374
|
o.Rollback()
|
379
|
o.Rollback()
|