Parcourir la source

注销

master
huangjiajun il y a 1 semaine
Parent
révision
785e91eadf
3 fichiers modifiés avec 95 ajouts et 33 suppressions
  1. +17
    -9
      app/utils/string.go
  2. +2
    -1
      consume/md/mq_com.go
  3. +76
    -23
      consume/user_delete_consume.go

+ 17
- 9
app/utils/string.go Voir le fichier

@@ -16,7 +16,7 @@ func Implode(glue string, args ...interface{}) string {
return strings.Join(data, glue)
}

//字符串是否在数组里
// 字符串是否在数组里
func InArr(target string, str_array []string) bool {
for _, element := range str_array {
if target == element {
@@ -25,8 +25,16 @@ func InArr(target string, str_array []string) bool {
}
return false
}
func InArrInt64(target int64, str_array []int64) bool {
for _, element := range str_array {
if target == element {
return true
}
}
return false
}

//把数组的值放到key里
// 把数组的值放到key里
func ArrayColumn(array interface{}, key string) (result map[string]interface{}, err error) {
result = make(map[string]interface{})
t := reflect.TypeOf(array)
@@ -55,7 +63,7 @@ func ArrayColumn(array interface{}, key string) (result map[string]interface{},
return result, err
}

//转string
// 转string
func InterfaceToString(v interface{}) (result string, err error) {
switch reflect.TypeOf(v).Kind() {
case reflect.Int64, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32:
@@ -114,12 +122,12 @@ func GetQueryParam(uri string) map[string]string {
return query
}

//JoinStringsInASCII 按照规则,参数名ASCII码从小到大排序后拼接
//data 待拼接的数据
//sep 连接符
//onlyValues 是否只包含参数值,true则不包含参数名,否则参数名和参数值均有
//includeEmpty 是否包含空值,true则包含空值,否则不包含,注意此参数不影响参数名的存在
//exceptKeys 被排除的参数名,不参与排序及拼接
// JoinStringsInASCII 按照规则,参数名ASCII码从小到大排序后拼接
// data 待拼接的数据
// sep 连接符
// onlyValues 是否只包含参数值,true则不包含参数名,否则参数名和参数值均有
// includeEmpty 是否包含空值,true则包含空值,否则不包含,注意此参数不影响参数名的存在
// exceptKeys 被排除的参数名,不参与排序及拼接
func JoinStringsInASCII(data map[string]string, sep string, onlyValues, includeEmpty bool, exceptKeys ...string) string {
var list []string
var keyList []string


+ 2
- 1
consume/md/mq_com.go Voir le fichier

@@ -1,5 +1,6 @@
package md

type CommUserId struct {
Uid string `json:"uid"`
Uid string `json:"uid"`
ParentUid string `json:"parent_uid"`
}

+ 76
- 23
consume/user_delete_consume.go Voir le fichier

@@ -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)


Chargement…
Annuler
Enregistrer