|
|
package platform
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
)
|
|
|
|
|
|
// AdminChance
|
|
|
//companyid 总管理后台的公司id
|
|
|
func AdminChance(companyid int64, phone string) error {
|
|
|
var (
|
|
|
companyData *models.Company
|
|
|
userData *models.User
|
|
|
// userCompanyData *models.UserCompany
|
|
|
err error
|
|
|
)
|
|
|
companyData, err = models.GetCompanyByUCenter(companyid)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("获取公司数据失败,总后台company_id:%d", companyid)
|
|
|
log.Error(err.Error())
|
|
|
return e
|
|
|
}
|
|
|
userData, err = models.GetUserByPhone(phone)
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("获取用户数据失败,phone:%s", phone)
|
|
|
log.Error(err.Error())
|
|
|
return e
|
|
|
}
|
|
|
_, 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
|
|
|
}
|
|
|
companyData.AdminId = userData.Id
|
|
|
err = models.UpdateCompanyById(companyData, []string{"AdminId"})
|
|
|
if err != nil {
|
|
|
e := fmt.Errorf("更新公司数据失败,err:%s", err)
|
|
|
log.Error(e.Error())
|
|
|
return e
|
|
|
}
|
|
|
return nil
|
|
|
} |
...
|
...
|
|