...
|
...
|
@@ -184,6 +184,7 @@ func AddCompanyData(data ModuleCompanytData) error { |
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
//处理用户数据
|
|
|
log.Info("添加user表数据")
|
|
|
newUser, err = AddAdminUser(&data, o)
|
|
|
if err != nil {
|
|
|
o.Rollback()
|
...
|
...
|
@@ -259,11 +260,18 @@ func AddCompanyData(data ModuleCompanytData) error { |
|
|
|
|
|
func AddAdminUser(centerCompany *ModuleCompanytData, o orm.Ormer) (*models.User, error) {
|
|
|
var (
|
|
|
err error
|
|
|
err error
|
|
|
newUser = &models.User{}
|
|
|
)
|
|
|
companyAdminData := centerCompany.User
|
|
|
err = o.QueryTable(&models.User{}).
|
|
|
Filter("phone", companyAdminData.Phone).
|
|
|
One(newUser)
|
|
|
if err == nil {
|
|
|
return newUser, nil
|
|
|
}
|
|
|
//添加用户
|
|
|
newUser := &models.User{
|
|
|
newUser = &models.User{
|
|
|
Id: companyAdminData.Id,
|
|
|
Phone: companyAdminData.Phone,
|
|
|
NickName: companyAdminData.Name,
|
...
|
...
|
@@ -274,6 +282,7 @@ func AddAdminUser(centerCompany *ModuleCompanytData, o orm.Ormer) (*models.User, |
|
|
log.Error("添加用户数据失败:%s", err)
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
return newUser, nil
|
|
|
}
|
|
|
|
...
|
...
|
@@ -294,15 +303,24 @@ func AddCompanyBase(centerCompany *ModuleCompanytData, admininfo *models.User, o |
|
|
log.Error("添加公司数据失败:%s", err)
|
|
|
return nil, err
|
|
|
}
|
|
|
return nil, nil
|
|
|
return newCompany, nil
|
|
|
}
|
|
|
|
|
|
func AddUserCompanyData(centerCompany *ModuleCompanytData, newcompany *models.Company, newuser *models.User, o orm.Ormer) (*models.UserCompany, error) {
|
|
|
var (
|
|
|
err error
|
|
|
uc = &models.UserCompany{}
|
|
|
)
|
|
|
adminUserData := centerCompany.User
|
|
|
uc := &models.UserCompany{
|
|
|
err = o.QueryTable(&models.UserCompany{}).
|
|
|
Filter("company_id", newcompany.Id).
|
|
|
Filter("user_id", newuser.Id).
|
|
|
Filter("delete_at", 0).
|
|
|
One(uc)
|
|
|
if err == nil {
|
|
|
return uc, nil
|
|
|
}
|
|
|
uc = &models.UserCompany{
|
|
|
UserId: newuser.Id,
|
|
|
CompanyId: newcompany.Id,
|
|
|
Enable: models.USERCOMPANY_ENABLE_YES,
|
...
|
...
|
|