作者 tangxvhui

bug 修复

... ... @@ -52,14 +52,17 @@ func (c PlatformController) CompanyAdminChance() {
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
e := fmt.Errorf("json 解析失败 err:%s", err)
log.Error(e.Error())
msg.Errno = "0"
msg.Errmsg = e.Error()
return
}
err := platform.AdminChance(param.CompanyId, param.Phone)
if err != nil {
log.Error("总后台调用CompanyAdminChance发生错误;%s", err)
msg.Errno = "-1"
msg.Errmsg = err.Error()
}
msg.Errno = "0"
c.Data["json"] = msg
c.ServeJSON()
return
... ...
package platform
import (
"errors"
"fmt"
"oppmg/common/log"
"oppmg/models"
... ... @@ -17,6 +18,7 @@ func AdminChance(companyid int64, phone string) error {
err error
newCharge *models.UserCompany
oldCharge *models.UserCompany
defaultRole *models.Role
)
companyData, err = models.GetCompanyByUCenter(companyid)
if err != nil {
... ... @@ -30,6 +32,12 @@ func AdminChance(companyid int64, phone string) error {
log.Error(err.Error())
return e
}
defaultRole, err = models.GetCompanyDefaultRole(companyid)
if err != nil {
e := fmt.Errorf("变更主管理员角色失败:err:%s", err)
log.Error(e.Error())
return errors.New("变更主管理员角色失败")
}
newCharge, err = models.GetUserCompanyBy(userData.Id, companyData.Id)
if err != nil {
e := fmt.Errorf("获取用户和公司的对应关系数据失败,user_id:%d,company_id:%d", userData.Id, companyData.Id)
... ... @@ -52,8 +60,8 @@ func AdminChance(companyid int64, phone string) error {
log.Error(e.Error())
return e
}
newCharge.ChargeStatus = models.USERCOMPANY_CHARGE_YES
oldCharge.ChargeStatus = models.USERCOMPANY_CHARGE_NO
newCharge.AdminType = models.USERCOMPANY_ADMIN_MAIN
oldCharge.AdminType = models.USERCOMPANY_ADMIN_SUBSET
err = models.UpdateUserCompanyById(newCharge, []string{"ChargeStatus"}, o)
if err != nil {
o.Rollback()
... ... @@ -68,6 +76,20 @@ func AdminChance(companyid int64, phone string) error {
log.Error(e.Error())
return e
}
//更新主管理员角色
_, err = o.QueryTable(&models.UserRole{}).
Filter("role_id", defaultRole.Id).
Filter("company_id", companyid).
Filter("user_company_id", oldCharge.Id).
Filter("enable_status", models.USER_ROLE_ENABLE_YES).
Update(orm.Params{
"user_company_id": newCharge.Id,
})
if err != nil {
e := fmt.Errorf("变更主管理员角色失败:%s", err)
log.Error(e.Error())
return errors.New("变更主管理员角色失败")
}
o.Commit()
return nil
}
... ...
... ... @@ -118,6 +118,7 @@ func UpdateCompanyData(data ModuleCompanytData) error {
companyData *models.Company
err error
topDepartment *models.Department
defaultRole *models.Role
)
newCompanyData := data.Company
companyData, err = models.GetCompanyByUCenter(newCompanyData.AdminCompanyId)
... ... @@ -142,11 +143,17 @@ func UpdateCompanyData(data ModuleCompanytData) error {
log.Error("获取公司一级数据失败,company_id=%d,err:%s", companyData.Id, err)
return errors.New("获取公司一级数据失败")
}
defaultRole, err = models.GetCompanyDefaultRole(companyData.Id)
if err != nil {
e := fmt.Errorf("变更主管理员角色失败:err:%s", err)
log.Error(e.Error())
return errors.New("变更主管理员角色失败")
}
o := orm.NewOrm()
o.Begin()
if data.User.Id != oldAdminData.Id {
//更新公司主管理员
oldAdminData.ChargeStatus = models.USERCOMPANY_CHARGE_NO
oldAdminData.AdminType = models.USERCOMPANY_ADMIN_SUBSET
err = models.UpdateUserCompanyById(oldAdminData, []string{"ChargeStatus"}, o)
if err != nil {
o.Rollback()
... ... @@ -160,7 +167,7 @@ func UpdateCompanyData(data ModuleCompanytData) error {
log.Error("获取新的主管理员失败,user_company_id=%d,err:%s", data.User.Id, err)
return errors.New("获取新的主管理员")
}
newAdminData.ChargeStatus = models.USERCOMPANY_CHARGE_YES
newAdminData.AdminType = models.USERCOMPANY_ADMIN_MAIN
err = models.UpdateUserCompanyById(newAdminData, []string{"ChargeStatus"}, o)
if err != nil {
o.Rollback()
... ... @@ -168,6 +175,20 @@ func UpdateCompanyData(data ModuleCompanytData) error {
return errors.New("变更主管理员失败")
}
companyData.AdminId = newAdminData.UserId
//更新主管理员角色
_, err = o.QueryTable(&models.UserRole{}).
Filter("role_id", defaultRole.Id).
Filter("company_id", companyData.Id).
Filter("user_company_id", oldAdminData.Id).
Filter("enable_status", models.USER_ROLE_ENABLE_YES).
Update(orm.Params{
"user_company_id": newAdminData.Id,
})
if err != nil {
e := fmt.Errorf("变更主管理员角色失败:%s", err)
log.Error(e.Error())
return errors.New("变更主管理员角色失败")
}
}
companyData.Logo = newCompanyData.Logo
companyData.Name = newCompanyData.Name
... ... @@ -185,6 +206,7 @@ func UpdateCompanyData(data ModuleCompanytData) error {
log.Error("更新公司一级部门数据失败:%s", err)
return errors.New("更新公司一级部门数据失败")
}
o.Commit()
return nil
}
... ...