1.修复系统用户编辑后密码无法登录的缺陷;
2.修复系统用户编辑时错误提示;
This commit is contained in:
parent
b50abd884b
commit
16c6f1671c
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user