|
@@ -184,6 +184,7 @@ func AddCompanyData(data ModuleCompanytData) error { |
|
@@ -184,6 +184,7 @@ func AddCompanyData(data ModuleCompanytData) error { |
184
|
o := orm.NewOrm()
|
184
|
o := orm.NewOrm()
|
185
|
o.Begin()
|
185
|
o.Begin()
|
186
|
//处理用户数据
|
186
|
//处理用户数据
|
|
|
187
|
+ log.Info("添加user表数据")
|
187
|
newUser, err = AddAdminUser(&data, o)
|
188
|
newUser, err = AddAdminUser(&data, o)
|
188
|
if err != nil {
|
189
|
if err != nil {
|
189
|
o.Rollback()
|
190
|
o.Rollback()
|
|
@@ -259,11 +260,18 @@ func AddCompanyData(data ModuleCompanytData) error { |
|
@@ -259,11 +260,18 @@ func AddCompanyData(data ModuleCompanytData) error { |
259
|
|
260
|
|
260
|
func AddAdminUser(centerCompany *ModuleCompanytData, o orm.Ormer) (*models.User, error) {
|
261
|
func AddAdminUser(centerCompany *ModuleCompanytData, o orm.Ormer) (*models.User, error) {
|
261
|
var (
|
262
|
var (
|
262
|
- err error
|
263
|
+ err error
|
|
|
264
|
+ newUser = &models.User{}
|
263
|
)
|
265
|
)
|
264
|
companyAdminData := centerCompany.User
|
266
|
companyAdminData := centerCompany.User
|
|
|
267
|
+ err = o.QueryTable(&models.User{}).
|
|
|
268
|
+ Filter("phone", companyAdminData.Phone).
|
|
|
269
|
+ One(newUser)
|
|
|
270
|
+ if err == nil {
|
|
|
271
|
+ return newUser, nil
|
|
|
272
|
+ }
|
265
|
//添加用户
|
273
|
//添加用户
|
266
|
- newUser := &models.User{
|
274
|
+ newUser = &models.User{
|
267
|
Id: companyAdminData.Id,
|
275
|
Id: companyAdminData.Id,
|
268
|
Phone: companyAdminData.Phone,
|
276
|
Phone: companyAdminData.Phone,
|
269
|
NickName: companyAdminData.Name,
|
277
|
NickName: companyAdminData.Name,
|
|
@@ -274,6 +282,7 @@ func AddAdminUser(centerCompany *ModuleCompanytData, o orm.Ormer) (*models.User, |
|
@@ -274,6 +282,7 @@ func AddAdminUser(centerCompany *ModuleCompanytData, o orm.Ormer) (*models.User, |
274
|
log.Error("添加用户数据失败:%s", err)
|
282
|
log.Error("添加用户数据失败:%s", err)
|
275
|
return nil, err
|
283
|
return nil, err
|
276
|
}
|
284
|
}
|
|
|
285
|
+
|
277
|
return newUser, nil
|
286
|
return newUser, nil
|
278
|
}
|
287
|
}
|
279
|
|
288
|
|
|
@@ -294,15 +303,24 @@ func AddCompanyBase(centerCompany *ModuleCompanytData, admininfo *models.User, o |
|
@@ -294,15 +303,24 @@ func AddCompanyBase(centerCompany *ModuleCompanytData, admininfo *models.User, o |
294
|
log.Error("添加公司数据失败:%s", err)
|
303
|
log.Error("添加公司数据失败:%s", err)
|
295
|
return nil, err
|
304
|
return nil, err
|
296
|
}
|
305
|
}
|
297
|
- return nil, nil
|
306
|
+ return newCompany, nil
|
298
|
}
|
307
|
}
|
299
|
|
308
|
|
300
|
func AddUserCompanyData(centerCompany *ModuleCompanytData, newcompany *models.Company, newuser *models.User, o orm.Ormer) (*models.UserCompany, error) {
|
309
|
func AddUserCompanyData(centerCompany *ModuleCompanytData, newcompany *models.Company, newuser *models.User, o orm.Ormer) (*models.UserCompany, error) {
|
301
|
var (
|
310
|
var (
|
302
|
err error
|
311
|
err error
|
|
|
312
|
+ uc = &models.UserCompany{}
|
303
|
)
|
313
|
)
|
304
|
adminUserData := centerCompany.User
|
314
|
adminUserData := centerCompany.User
|
305
|
- uc := &models.UserCompany{
|
315
|
+ err = o.QueryTable(&models.UserCompany{}).
|
|
|
316
|
+ Filter("company_id", newcompany.Id).
|
|
|
317
|
+ Filter("user_id", newuser.Id).
|
|
|
318
|
+ Filter("delete_at", 0).
|
|
|
319
|
+ One(uc)
|
|
|
320
|
+ if err == nil {
|
|
|
321
|
+ return uc, nil
|
|
|
322
|
+ }
|
|
|
323
|
+ uc = &models.UserCompany{
|
306
|
UserId: newuser.Id,
|
324
|
UserId: newuser.Id,
|
307
|
CompanyId: newcompany.Id,
|
325
|
CompanyId: newcompany.Id,
|
308
|
Enable: models.USERCOMPANY_ENABLE_YES,
|
326
|
Enable: models.USERCOMPANY_ENABLE_YES,
|