...
|
...
|
@@ -370,9 +370,16 @@ func validUserCompany(userCompanyid int64, companyid int64) (*models.UserCompany |
|
|
|
|
|
func UserEdit(param protocol.RequestUserEdit) error {
|
|
|
var (
|
|
|
err error
|
|
|
ucompany *models.UserCompany
|
|
|
err error
|
|
|
ucompany *models.UserCompany
|
|
|
companyInfo *models.Company
|
|
|
)
|
|
|
companyInfo, err = models.GetCompanyById(param.CompanyId)
|
|
|
if err != nil {
|
|
|
log.Error("GetCompanyById(%d):%s", param.CompanyId, err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
|
|
|
//校验公司和用户的关联
|
|
|
ucompany, err = validUserCompany(param.UserCompanyID, param.CompanyId)
|
|
|
if err != nil {
|
...
|
...
|
@@ -403,27 +410,14 @@ func UserEdit(param protocol.RequestUserEdit) error { |
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
//检查用户手机号是否生变更
|
|
|
// var (
|
|
|
// usrData *models.User
|
|
|
// )
|
|
|
// if usrData.Phone != param.Phone {
|
|
|
// //手机号变更
|
|
|
// uid, err := addNewUser(param.Name, param.Phone, o)
|
|
|
// if err != nil {
|
|
|
// o.Rollback()
|
|
|
// log.Error("手机号变更,新增用户失败;%s", err)
|
|
|
// return protocol.NewErrWithMessage("1")
|
|
|
// }
|
|
|
// ucompany.UserId = uid
|
|
|
// }
|
|
|
//用户数据更新
|
|
|
// err = editUserCompany(param.UserCompanyID, ucompany.UserId, param.Name, o)
|
|
|
// if err != nil {
|
|
|
// o.Rollback()
|
|
|
// log.Error("editUserCompany err:%s", err)
|
|
|
// return protocol.NewErrWithMessage("1")
|
|
|
// }
|
|
|
if ucompany.UserId == companyInfo.AdminId {
|
|
|
defaultRole, err := models.GetCompanyDefaultRole(param.CompanyId)
|
|
|
if err != nil {
|
|
|
log.Error("获取公司默认角色失败")
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
param.Roles = append(param.Roles, defaultRole.Id)
|
|
|
}
|
|
|
//添加角色
|
|
|
err = editUserRole(param.UserCompanyID, ucompany.UserId, param.CompanyId, param.Roles, o)
|
|
|
if err != nil {
|
...
|
...
|
@@ -454,9 +448,14 @@ func UserDelete(userCompanyids []int64, companyid int64) error { |
|
|
return nil
|
|
|
}
|
|
|
var (
|
|
|
updateIds []models.UserCompany
|
|
|
err error
|
|
|
updateIds []models.UserCompany
|
|
|
err error
|
|
|
companyInfo *models.Company
|
|
|
)
|
|
|
companyInfo, err = models.GetCompanyById(companyid)
|
|
|
if err != nil {
|
|
|
log.Error("GetCompanyById(%d)获取公司数据失败:%s", companyid, err)
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
_, err = o.QueryTable(&models.UserCompany{}).
|
|
|
Filter("id__in", userCompanyids).
|
...
|
...
|
@@ -466,10 +465,14 @@ func UserDelete(userCompanyids []int64, companyid int64) error { |
|
|
log.Error("获取用户数据失败:%s", err)
|
|
|
return protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
|
|
|
var (
|
|
|
ids []int64
|
|
|
)
|
|
|
for _, v := range updateIds {
|
|
|
if v.Id == companyInfo.AdminId {
|
|
|
return protocol.NewErrWithMessage("10071")
|
|
|
}
|
|
|
ids = append(ids, v.Id)
|
|
|
}
|
|
|
_, err = o.QueryTable(&models.UserCompany{}).
|
...
|
...
|
@@ -635,9 +638,14 @@ func UserForbid(userCompanyids []int64, companyid int64) error { |
|
|
return nil
|
|
|
}
|
|
|
var (
|
|
|
updateIds []models.UserCompany
|
|
|
err error
|
|
|
updateIds []models.UserCompany
|
|
|
err error
|
|
|
companyInfo *models.Company
|
|
|
)
|
|
|
companyInfo, err = models.GetCompanyById(companyid)
|
|
|
if err != nil {
|
|
|
log.Error("GetCompanyById(%d) err:%s", companyid, err)
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
_, err = o.QueryTable(&models.UserCompany{}).
|
|
|
Filter("id__in", userCompanyids).
|
...
|
...
|
@@ -651,6 +659,9 @@ func UserForbid(userCompanyids []int64, companyid int64) error { |
|
|
ids []int64
|
|
|
)
|
|
|
for _, v := range updateIds {
|
|
|
if v.Id == companyInfo.AdminId {
|
|
|
return protocol.NewErrWithMessage("10072")
|
|
|
}
|
|
|
ids = append(ids, v.Id)
|
|
|
}
|
|
|
num, err := o.QueryTable(&models.UserCompany{}).
|
...
|
...
|
|