...
|
...
|
@@ -116,20 +116,57 @@ func UpdateCompanyData(data ModuleCompanytData) error { |
|
|
companyData *models.Company
|
|
|
err error
|
|
|
)
|
|
|
companyBaseData := data.Company
|
|
|
companyData, err = models.GetCompanyByUCenter(companyBaseData.AdminCompanyId)
|
|
|
newCompanyData := data.Company
|
|
|
companyData, err = models.GetCompanyByUCenter(newCompanyData.AdminCompanyId)
|
|
|
if err != nil {
|
|
|
log.Error("获取企业数据失败,user_center_id:%d ,err:%s", companyBaseData.AdminCompanyId, err)
|
|
|
log.Error("获取企业数据失败,user_center_id:%d ,err:%s", newCompanyData.AdminCompanyId, err)
|
|
|
return errors.New("获取企业数据失败")
|
|
|
}
|
|
|
companyData.Logo = companyBaseData.Logo
|
|
|
companyData.Name = companyBaseData.Name
|
|
|
companyData.Remark = companyBaseData.Remarks
|
|
|
err = models.UpdateCompanyById(companyData, []string{"Logo", "Name"})
|
|
|
var (
|
|
|
oldAdminData *models.UserCompany
|
|
|
)
|
|
|
oldAdminData, err = models.GetUserCompanyBy(companyData.AdminId, companyData.Id)
|
|
|
if err != nil {
|
|
|
log.Error("获取公司主管理员user_company数据失败,company_id=%d,user_id=%d,err:%s", companyData.Id, companyData.AdminId, err)
|
|
|
return errors.New("获取公司主管理员数据失败")
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
if data.User.Id != oldAdminData.Id {
|
|
|
//更新公司主管理员
|
|
|
oldAdminData.ChargeStatus = models.USERCOMPANY_CHARGE_NO
|
|
|
err = models.UpdateUserCompanyById(oldAdminData, []string{"ChargeStatus"}, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Error("去除旧的主管理员失败:user_company_id=%d,err:%s", oldAdminData.Id, err)
|
|
|
return errors.New("去除旧的更主管理员失败")
|
|
|
}
|
|
|
var newAdminData *models.UserCompany
|
|
|
newAdminData, err = models.GetUserCompanyById(data.User.Id)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Error("获取新的主管理员失败,user_company_id=%d,err:%s", data.User.Id, err)
|
|
|
return errors.New("获取新的主管理员")
|
|
|
}
|
|
|
newAdminData.ChargeStatus = models.USERCOMPANY_CHARGE_YES
|
|
|
err = models.UpdateUserCompanyById(newAdminData, []string{"ChargeStatus"}, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Error("变更更主管理员失败:user_company_id=%d,err:%s", newAdminData.Id, err)
|
|
|
return errors.New("变更主管理员失败")
|
|
|
}
|
|
|
companyData.AdminId = newAdminData.UserId
|
|
|
}
|
|
|
companyData.Logo = newCompanyData.Logo
|
|
|
companyData.Name = newCompanyData.Name
|
|
|
companyData.Remark = newCompanyData.Remarks
|
|
|
err = models.UpdateCompanyById(companyData, []string{"Logo", "Name", "AdminId"}, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
log.Error("更新公司数据失败:%s", err)
|
|
|
return errors.New("更新公司数据失败")
|
|
|
}
|
|
|
o.Commit()
|
|
|
return nil
|
|
|
}
|
|
|
|
...
|
...
|
|