给你看一下我后台的一个接口
```
func ApiAdminUserUpdate(c *gin.Context) {
var err error = func() error {
user, err := service.GinGetUser(c)
if err != nil {
return err
}
err = service.CheckUserRoleError(user, enum_data.UserRoleListPlat...)
if err != nil {
return err
}
d, err := utils.GinRequestD(c)
if err != nil {
return err
}
local_id, err := lerror.GinDGet(d, "local_id")
if err != nil {
return err
}
update_at, err := lerror.GinDGet(d, "update_at")
if err != nil {
return err
}
targetUser, err := service.UserFindByLocalId(local_id)
if err != nil {
return err
}
err = service.UserCheckUpdatAtStr(targetUser, update_at)
if err != nil {
return err
}
var fnSendOk = func() {
lerror.HandlerResponseOk(c)
}
var createEvent = func(event, detail string) error {
LocalId, err := model.RedisIntKey()
if err != nil {
return err
}
var actionLog = model.MActionLog{
LocalId: LocalId,
UserId: user.LocalId,
Business: enum_data.ActionBusinessUser,
Event: event,
Detail: detail,
Ip: utils.GinRequestIp(c),
UserAgent: c.Request.UserAgent(),
RefId: user.LocalId,
RefTable: "m_user",
}
err = model.Db.Create(&actionLog).Error
return err
}
status, flag := d["status"]
var event string
var detail string
if flag {
// 禁用|启用 用户
statusI, err := strconv.ParseInt(status, 10, 64)
if err != nil {
return err
}
event = enum_data.ActionEventUnActive
detail = enum_data.ActionUserUnactiveFormat(user, targetUser)
if statusI == int64(1) {
event = enum_data.ActionEventActive
detail = enum_data.ActionUserActiveFormat(user, targetUser)
}
err = service.UserUpdate(targetUser, gin.H{
"status": statusI,
"update_at": time.Now().Unix(),
})
if err != nil {
return err
}
err = createEvent(event, detail)
if err != nil {
return err
}
fnSendOk()
return nil
}
ms_auth_status, flag := d["ms_auth_status"]
if flag {
ms_auth_status_i, err := strconv.ParseInt(ms_auth_status, 10, 64)
if err != nil {
return err
}
event = enum_data.ActionEventMsUnActive
detail = enum_data.ActionUserMsAuthUnActiveFormat(user, targetUser)
if ms_auth_status_i == int64(1) {
event = enum_data.ActionEventMsActive
detail = enum_data.ActionUserMsAuthActiveFormat(user, targetUser)
}
err = service.UserUpdate(targetUser, gin.H{
"ms_auth_status": ms_auth_status_i,
"update_at": time.Now().Unix(),
})
if err != nil {
return err
}
err = createEvent(event, detail)
if err != nil {
return err
}
fnSendOk()
return nil
}
name, err := lerror.GinDGet(d, "name")
if err != nil {
return err
}
nameCount, err := service.UserCount(utils.NewSqlCnd().Eq("name", name).NotEq("local_id", targetUser))
if err != nil {
return err
}
if nameCount > 1 {
return lerror.NewMsgError(fmt.Sprintf("用户账号重复 [%s]", name))
}
// 更新用户
nick, err := lerror.GinDGet(d, "nick")
if err != nil {
return err
}
count, err := service.UserCount(utils.NewSqlCnd().Eq("nick", nick).NotEq("local_id", targetUser))
if err != nil {
return err
}
if count > 0 {
return lerror.NewMsgError(fmt.Sprintf("昵称重复 [%s]", nick))
}
ms_auth_secret, err := lerror.GinDGet(d, "ms_auth_secret")
if err != nil {
return err
}
secret, err := lerror.GinDGet(d, "secret")
if err != nil {
return err
}
update_d := gin.H{
"nick": nick,
"ms_auth_secret": ms_auth_secret,
"secret": secret,
"update_at": time.Now().Unix(),
}
err = service.UserUpdate(targetUser, update_d)
if err != nil {
return err
}
return nil
}()
if err != nil {
logging.Info("err:%s", err)
lerror.HandlerResponseError(c, err)
return
}
}
```