diff --git a/app/md/member_center/md_user_management.go b/app/md/member_center/md_user_management.go index b5e98d6..deb1ef3 100644 --- a/app/md/member_center/md_user_management.go +++ b/app/md/member_center/md_user_management.go @@ -95,7 +95,7 @@ type UserManagementUpdateUserInfoReq struct { type TagNode struct { TagID int `json:"tag_id"` // 标签 ID - TagName string `json:"tag_name"` // 标签 名称 + TagName string `json:"tag_name"` // 标签名称 } type BasicInfoNode struct { @@ -179,3 +179,14 @@ type UserManagementGetVirtualCoinDetailResp struct { List []VirtualCoinDetailNode `json:"list"` Paginate Paginate `json:"paginate"` } + +type UserManagementAddTagReq struct { + Uid int64 `json:"uid"` // 用户 ID + TagId string `json:"tag_id"` // 标签 ID + Memo string `json:"memo"` // 标签备注 +} + +type UserManagementDelTagReq struct { + Uid int64 `json:"uid"` // 用户 ID + TagId string `json:"tag_id"` // 标签 ID +} diff --git a/app/svc/member_center/svc_user_management.go b/app/svc/member_center/svc_user_management.go index aa5ed5b..e8976f7 100644 --- a/app/svc/member_center/svc_user_management.go +++ b/app/svc/member_center/svc_user_management.go @@ -133,16 +133,19 @@ func UserManagementUpdateUserInfo(engine *xorm.Engine, req *md.UserManagementUpd if err != nil { return 0, err } - if records != nil { - recordIds := make([]int, 0) - for _, record := range *records { - recordIds = append(recordIds, record.Id) - } - - // 删除所有用户的所有标签记录 + oldRecordIds := make([]string, 0) + for _, record := range *records { + oldRecordIds = append(oldRecordIds, utils.IntToStr(record.Id)) + } + newRecordIds := strings.Split(req.Tag, ",") + // 需要删除的标签 + delTags := utils.DiffArray(oldRecordIds, newRecordIds) + addTags := utils.DiffArray(newRecordIds, oldRecordIds) + if delTags != nil { + // 删除不需要的标签记录 _, err := recordsDb.UserTagRecordsDeleteBySession(session, map[string]interface{}{ "key": "id", - "value": recordIds, + "value": delTags, }) if err != nil { return 0, err @@ -153,8 +156,7 @@ func UserManagementUpdateUserInfo(engine *xorm.Engine, req *md.UserManagementUpd if req.Tag != "" { newRecords := make([]*model.UserTagRecords, 0) now := time.Now() - tags := strings.Split(req.Tag, ",") - for _, tag := range tags { + for _, tag := range addTags { newRecord := &model.UserTagRecords{ TagId: utils.StrToInt(tag), Uid: req.UID, diff --git a/go.mod b/go.mod index 59e8bd1..96d220c 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( ) require ( - code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241206115326-8cbc93c7c64d + code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241207021144-5eb7d8513c6a code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241205075006-9c0bf995c788 code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5