...
|
...
|
@@ -4,16 +4,19 @@ import ( |
|
|
"fmt"
|
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
|
|
|
"github.com/astaxie/beego/orm"
|
|
|
)
|
|
|
|
|
|
// AdminChance
|
|
|
// AdminChance g更换公司主管
|
|
|
//companyid 总管理后台的公司id
|
|
|
func AdminChance(companyid int64, phone string) error {
|
|
|
var (
|
|
|
companyData *models.Company
|
|
|
userData *models.User
|
|
|
// userCompanyData *models.UserCompany
|
|
|
err error
|
|
|
err error
|
|
|
newCharge *models.UserCompany
|
|
|
oldCharge *models.UserCompany
|
|
|
)
|
|
|
companyData, err = models.GetCompanyByUCenter(companyid)
|
|
|
if err != nil {
|
...
|
...
|
@@ -27,18 +30,44 @@ func AdminChance(companyid int64, phone string) error { |
|
|
log.Error(err.Error())
|
|
|
return e
|
|
|
}
|
|
|
_, err = models.GetUserCompanyBy(userData.Id, companyData.Id)
|
|
|
newCharge, err = models.GetUserCompanyBy(userData.Id, companyData.Id)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("获取用户和公司的对应关系数据失败,user_id:%d,company_id:%d", userData.Id, companyData.Id)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
}
|
|
|
oldCharge, err = models.GetUserCompanyBy(companyData.AdminId, companyData.Id)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("获取公司原来的主管对应数据失败,user_id:%d,company_id:%d", companyData.AdminId, companyData.Id)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
companyData.AdminId = userData.Id
|
|
|
err = models.UpdateCompanyById(companyData, []string{"AdminId"})
|
|
|
err = models.UpdateCompanyById(companyData, []string{"AdminId"}, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
e := fmt.Errorf("更新公司数据失败,err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
}
|
|
|
newCharge.ChargeStatus = models.USERCOMPANY_CHARGE_YES
|
|
|
oldCharge.ChargeStatus = models.USERCOMPANY_CHARGE_NO
|
|
|
err = models.UpdateUserCompanyById(newCharge, []string{"ChargeStatus"}, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
e := fmt.Errorf("更新原公司主管理员数据失败,user_company_id=%d,err:%s", oldCharge.Id, err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
}
|
|
|
err = models.UpdateUserCompanyById(oldCharge, []string{"ChargeStatus"}, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
|
|
e := fmt.Errorf("更新新公司主管理员数据失败,user_company_id=%d , err:%s", newCharge.Id, err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
}
|
|
|
o.Commit()
|
|
|
return nil
|
|
|
} |
...
|
...
|
|