From 16c6f1671c97849f484338e901b4961e97b11b78 Mon Sep 17 00:00:00 2001 From: chenlin Date: Wed, 24 Jul 2024 16:27:38 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E7=B3=BB=E7=BB=9F=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=BC=96=E8=BE=91=E5=90=8E=E5=AF=86=E7=A0=81=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E7=99=BB=E5=BD=95=E7=9A=84=E7=BC=BA=E9=99=B7=EF=BC=9B?= =?UTF-8?q?=202.=E4=BF=AE=E5=A4=8D=E7=B3=BB=E7=BB=9F=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E6=97=B6=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/apis/system/sysuser.go | 55 +++++++++++++++++--------------- app/admin/models/sysuser.go | 15 +++++---- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/app/admin/apis/system/sysuser.go b/app/admin/apis/system/sysuser.go index 7287bbb..24bddc1 100644 --- a/app/admin/apis/system/sysuser.go +++ b/app/admin/apis/system/sysuser.go @@ -333,13 +333,13 @@ func UpdateSysUser(c *gin.Context) { if req.ShopperCode != "" { if len(req.ShopperCode) != 6 { logger.Error("兑换码不是6位") - app.Error(c, http.StatusInternalServerError, err, "兑换码长度不符合要求[6位]") + app.Error(c, http.StatusInternalServerError, err, "店员识别码长度不符合要求[6位]") return } if req.Uid == 0 { logger.Error("uid为0") - app.Error(c, http.StatusInternalServerError, err, "配置店员兑换码需填写小程序账号ID") + app.Error(c, http.StatusInternalServerError, err, "配置店员识别码需填写小程序账号ID") return } } @@ -403,12 +403,10 @@ func UpdateSysUser(c *gin.Context) { Uid: req.Uid, }, } - if req.LoginM.UserName.Username == "" { - data.LoginM.UserName = sysInfo.LoginM.UserName - } - if req.LoginM.PassWord.Password == "" { - data.LoginM.PassWord = sysInfo.LoginM.PassWord + // 重置密码时uid赋值为原有的uid + if req.Phone == "" && req.LoginM.PassWord.Password != "" && req.Uid == 0 { + data.Uid = sysInfo.Uid } if len(req.StoreList) != 0 { @@ -425,30 +423,35 @@ func UpdateSysUser(c *gin.Context) { begin := orm.Eloquent.Begin() data.UpdateBy = tools.GetUserIdStr(c) result, err := data.Update(begin, data.UserId) + if err != nil { + begin.Rollback() + } tools.HasError(err, "修改失败", 500) // 判断是否修改了uid - if sysInfo.Uid == 0 && req.Uid != 0 { // 新增uid,直接更新为2即可 - err = models.UpdateUserType(begin, req.Uid, models.UserTypeShopAssistant, uint32(req.RoleId)) - } else if sysInfo.Uid != 0 { - if sysInfo.Uid != req.Uid { - // 原uid的状态更新为1 - err = models.UpdateUserType(begin, sysInfo.Uid, models.UserTypeConsumer, 0) - if err == nil { - if req.Uid != 0 { - // 新uid状态更新为2 - err = models.UpdateUserType(begin, req.Uid, models.UserTypeShopAssistant, uint32(req.RoleId)) + if req.Phone != "" { // 手机号目前是必填项,不能为空,否则可能是重置密码 + if sysInfo.Uid == 0 && req.Uid != 0 { // 新增uid,直接更新为2即可 + err = models.UpdateUserType(begin, req.Uid, models.UserTypeShopAssistant, uint32(req.RoleId)) + } else if sysInfo.Uid != 0 { + if sysInfo.Uid != req.Uid { + // 原uid的状态更新为1 + err = models.UpdateUserType(begin, sysInfo.Uid, models.UserTypeConsumer, 0) + if err == nil { + if req.Uid != 0 { + // 新uid状态更新为2 + err = models.UpdateUserType(begin, req.Uid, models.UserTypeShopAssistant, uint32(req.RoleId)) + } } + } else if sysInfo.Uid == req.Uid && sysInfo.RoleId != req.RoleId { // 更改了用户角色 + err = models.UpdateUserType(begin, sysInfo.Uid, models.UserTypeShopAssistant, uint32(req.RoleId)) } - } else if sysInfo.Uid == req.Uid && sysInfo.RoleId != req.RoleId { // 更改了用户角色 - err = models.UpdateUserType(begin, sysInfo.Uid, models.UserTypeShopAssistant, uint32(req.RoleId)) } - } - if err != nil { - begin.Rollback() - logger.Error("UpdateUserType err:", logger.Field("err", err)) - app.Error(c, http.StatusInternalServerError, err, "修改失败") - return + if err != nil { + begin.Rollback() + logger.Error("UpdateUserType err:", logger.Field("err", err)) + app.Error(c, http.StatusInternalServerError, err, "修改失败") + return + } } if req.ShopperCode != "" { // 添加店员兑换码:删除原兑换码,添加新兑换码 @@ -456,7 +459,7 @@ func UpdateSysUser(c *gin.Context) { if err != nil { begin.Rollback() logger.Error("UpdateShopperCode err:", logger.Field("err", err)) - app.Error(c, http.StatusInternalServerError, err, "修改失败") + app.Error(c, http.StatusInternalServerError, err, err.Error()) return } } diff --git a/app/admin/models/sysuser.go b/app/admin/models/sysuser.go index 5c69dd9..7a05ec9 100644 --- a/app/admin/models/sysuser.go +++ b/app/admin/models/sysuser.go @@ -597,15 +597,16 @@ func (e *SysUser) Update(begin *gorm.DB, id int) (update SysUser, err error) { //参数1:是要修改的数据 //参数2:是修改的数据 - if e.Password != "" { // 更新密码时其他信息为空,需要update - if err = begin.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil { - return - } - } else { - if err = begin.Table(e.TableName()).Model(&update).Save(&e).Error; err != nil { + if err = begin.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil { + return + } + + if e.Uid == 0 { + if err = begin.Table(e.TableName()).Model(&update).UpdateColumn("uid", 0).Error; err != nil { return } } + return } @@ -833,7 +834,7 @@ func UpdateShopperCode(req InsertSysUserReq, begin *gorm.DB, sysInfo *SysUser) e orm.Eloquent.Debug().Model(&ShopperPromotionCode{}). Where("code = ? and state = ?", req.ShopperCode, 2).Find(&oldShopperCode) if oldShopperCode.ID != 0 && oldShopperCode.Uid != sysInfo.Uid { - return errors.New(fmt.Sprintf("兑换码[%s]重复,请更换", req.ShopperCode)) + return errors.New(fmt.Sprintf("[%s]与已有店员识别码重复", req.ShopperCode)) } // 获取有效门店id