Browse Source

注销

master
huangjiajun 1 week ago
parent
commit
e8982c7c27
1 changed files with 45 additions and 69 deletions
  1. +45
    -69
      consume/user_delete_consume.go

+ 45
- 69
consume/user_delete_consume.go View File

@@ -95,83 +95,59 @@ func handleUserDeleteConsume(backEg *xorm.Engine, ch *rabbit.Channel, msgData []
}
}
//2.用户关系链
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)
//查出所有下级
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)
}
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 ids = make([]int64, 0)
for _, v := range relate {
ids = append(ids, v.Uid)
}
//读出所有下级重新处理
var allRelate []model.UserRelate
err = eg.In("uid", ids).Desc("level").Find(&allRelate)
for _, v := range allRelate {
if utils2.InArrInt64(v.ParentUid, parentIds) {
eg.Where("id=?", v.Id).Delete(&model.UserRelate{})
continue
}
//读出所有下级重新处理
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) && utils2.StrToInt64(msg.ParentUid) > 0 { //如果相等
level := v.Level
level++
var tmp = model.UserRelate{
ParentUid: utils2.StrToInt64(msg.ParentUid),
Uid: v.Uid,
Level: level,
InviteTime: v.InviteTime,
}
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.Insert(&tmp)
for _, v1 := range relateParent1 {
level++
var tmp1 = model.UserRelate{
ParentUid: v1.ParentUid,
Uid: v.Uid,
Level: level,
InviteTime: v.InviteTime,
}
eg.Insert(&tmp1)
}
}
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})
}
eg.Where("parent_uid=?", msg.Uid).Cols("parent_uid").Update(&model.User{ParentUid: utils2.StrToInt64(msg.ParentUid)})
_, err = eg.Where("parent_uid=?", msg.Uid).Delete(&model.UserRelate{})
_, err = eg.Where("uid=?", msg.Uid).Delete(&model.UserRelate{})



Loading…
Cancel
Save