|
|
@@ -95,33 +95,86 @@ func handleUserDeleteConsume(backEg *xorm.Engine, ch *rabbit.Channel, msgData [] |
|
|
|
} |
|
|
|
} |
|
|
|
//2.用户关系链 |
|
|
|
//查出所有下级 |
|
|
|
var relate []model.UserRelate |
|
|
|
err = eg.Where("parent_uid=?", msg.Uid).Find(&relate) |
|
|
|
if len(relate) > 0 { |
|
|
|
backEg.Insert(&relate) |
|
|
|
} |
|
|
|
var ids = make([]int64, 0) |
|
|
|
for _, v := range relate { |
|
|
|
ids = append(ids, v.Uid) |
|
|
|
} |
|
|
|
//读出所有下级重新处理 |
|
|
|
var allRelate []model.UserRelate |
|
|
|
err = eg.In("uid", ids).Asc("level").Find(&allRelate) |
|
|
|
var relateMap = make(map[int64]int) |
|
|
|
for _, v := range allRelate { |
|
|
|
if v.ParentUid != utils2.StrToInt64(msg.Uid) { //如果相等就删掉 |
|
|
|
relateMap[v.Uid]++ |
|
|
|
eg.Where("id=?", v.Id).Cols("level").Update(&model.UserRelate{Level: relateMap[v.Uid]}) |
|
|
|
if utils2.StrToInt(msg.ParentUid) > 0 { |
|
|
|
//查出所有下级 |
|
|
|
var relate []model.UserRelate |
|
|
|
err = eg.Where("parent_uid=?", msg.Uid).Find(&relate) |
|
|
|
if len(relate) > 0 { |
|
|
|
backEg.Insert(&relate) |
|
|
|
} |
|
|
|
var relateParent []model.UserRelate |
|
|
|
err = eg.Where("uid=?", msg.Uid).Find(&relateParent) |
|
|
|
var relateParent1 []model.UserRelate |
|
|
|
err = eg.Where("uid=?", msg.ParentUid).Find(&relateParent1) |
|
|
|
var parentIds = make([]int64, 0) |
|
|
|
|
|
|
|
if len(relateParent) > 0 { |
|
|
|
backEg.Insert(&relateParent) |
|
|
|
for _, v := range relateParent { |
|
|
|
parentIds = append(parentIds, v.ParentUid) |
|
|
|
} |
|
|
|
} |
|
|
|
var ids = make([]int64, 0) |
|
|
|
for _, v := range relate { |
|
|
|
ids = append(ids, v.Uid) |
|
|
|
} |
|
|
|
//读出所有下级重新处理 |
|
|
|
var allRelate []model.UserRelate |
|
|
|
err = eg.In("uid", ids).Asc("level").Find(&allRelate) |
|
|
|
for _, v := range allRelate { |
|
|
|
if utils2.InArrInt64(v.ParentUid, parentIds) { |
|
|
|
eg.Where("id=?", v.Id).Delete(&model.UserRelate{}) |
|
|
|
continue |
|
|
|
} |
|
|
|
if v.ParentUid == utils2.StrToInt64(msg.Uid) { //如果相等 |
|
|
|
eg.Where("id=?", v.Id).Cols("parent_uid").Update(&model.UserRelate{ParentUid: utils2.StrToInt64(msg.ParentUid)}) |
|
|
|
level := v.Level |
|
|
|
for _, v1 := range relateParent1 { |
|
|
|
level++ |
|
|
|
var tmp = model.UserRelate{ |
|
|
|
ParentUid: v1.ParentUid, |
|
|
|
Uid: v1.Uid, |
|
|
|
Level: level, |
|
|
|
InviteTime: v.InviteTime, |
|
|
|
} |
|
|
|
eg.Insert(&tmp) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
eg.Where("parent_uid=?", msg.Uid).Cols("parent_uid").Update(&model.User{ParentUid: utils2.StrToInt64(msg.ParentUid)}) |
|
|
|
} else { |
|
|
|
//查出所有下级 |
|
|
|
var relate []model.UserRelate |
|
|
|
err = eg.Where("parent_uid=?", msg.Uid).Find(&relate) |
|
|
|
if len(relate) > 0 { |
|
|
|
backEg.Insert(&relate) |
|
|
|
} |
|
|
|
var ids = make([]int64, 0) |
|
|
|
for _, v := range relate { |
|
|
|
ids = append(ids, v.Uid) |
|
|
|
} |
|
|
|
var relateParent []model.UserRelate |
|
|
|
err = eg.Where("uid=?", msg.Uid).Find(&relateParent) |
|
|
|
if len(relateParent) > 0 { |
|
|
|
backEg.Insert(&relateParent) |
|
|
|
} |
|
|
|
//读出所有下级重新处理 |
|
|
|
var allRelate []model.UserRelate |
|
|
|
err = eg.In("uid", ids).Asc("level").Find(&allRelate) |
|
|
|
var relateMap = make(map[int64]int) |
|
|
|
for _, v := range allRelate { |
|
|
|
if v.ParentUid == utils2.StrToInt64(msg.Uid) { //如果相等就删掉 |
|
|
|
eg.Where("id=?", v.Id).Delete(&model.UserRelate{}) |
|
|
|
} else { |
|
|
|
relateMap[v.Uid]++ |
|
|
|
eg.Where("id=?", v.Id).Cols("level").Update(&model.UserRelate{Level: relateMap[v.Uid]}) |
|
|
|
} |
|
|
|
} |
|
|
|
eg.Where("parent_uid=?", msg.Uid).Cols("parent_uid").Update(&model.User{ParentUid: user.ParentUid}) |
|
|
|
} |
|
|
|
_, err = eg.Where("parent_uid=?", msg.Uid).Delete(&model.UserRelate{}) |
|
|
|
var relateParent []model.UserRelate |
|
|
|
err = eg.Where("uid=?", msg.Uid).Find(&relateParent) |
|
|
|
if len(relateParent) > 0 { |
|
|
|
backEg.Insert(&relateParent) |
|
|
|
} |
|
|
|
_, err = eg.Where("uid=?", msg.Uid).Delete(&model.UserRelate{}) |
|
|
|
|
|
|
|
//3.公排位置 |
|
|
|
var publicPlatoonUserRelation model.PublicPlatoonUserRelation |
|
|
|
exist, err = eg.Where("uid=?", msg.Uid).Get(&publicPlatoonUserRelation) |
|
|
|