|
@@ -370,9 +370,16 @@ func validUserCompany(userCompanyid int64, companyid int64) (*models.UserCompany |
|
@@ -370,9 +370,16 @@ func validUserCompany(userCompanyid int64, companyid int64) (*models.UserCompany |
370
|
|
370
|
|
371
|
func UserEdit(param protocol.RequestUserEdit) error {
|
371
|
func UserEdit(param protocol.RequestUserEdit) error {
|
372
|
var (
|
372
|
var (
|
373
|
- err error
|
|
|
374
|
- ucompany *models.UserCompany
|
373
|
+ err error
|
|
|
374
|
+ ucompany *models.UserCompany
|
|
|
375
|
+ companyInfo *models.Company
|
375
|
)
|
376
|
)
|
|
|
377
|
+ companyInfo, err = models.GetCompanyById(param.CompanyId)
|
|
|
378
|
+ if err != nil {
|
|
|
379
|
+ log.Error("GetCompanyById(%d):%s", param.CompanyId, err)
|
|
|
380
|
+ return protocol.NewErrWithMessage("1")
|
|
|
381
|
+ }
|
|
|
382
|
+
|
376
|
//校验公司和用户的关联
|
383
|
//校验公司和用户的关联
|
377
|
ucompany, err = validUserCompany(param.UserCompanyID, param.CompanyId)
|
384
|
ucompany, err = validUserCompany(param.UserCompanyID, param.CompanyId)
|
378
|
if err != nil {
|
385
|
if err != nil {
|
|
@@ -403,27 +410,14 @@ func UserEdit(param protocol.RequestUserEdit) error { |
|
@@ -403,27 +410,14 @@ func UserEdit(param protocol.RequestUserEdit) error { |
403
|
}
|
410
|
}
|
404
|
o := orm.NewOrm()
|
411
|
o := orm.NewOrm()
|
405
|
o.Begin()
|
412
|
o.Begin()
|
406
|
- //检查用户手机号是否生变更
|
|
|
407
|
- // var (
|
|
|
408
|
- // usrData *models.User
|
|
|
409
|
- // )
|
|
|
410
|
- // if usrData.Phone != param.Phone {
|
|
|
411
|
- // //手机号变更
|
|
|
412
|
- // uid, err := addNewUser(param.Name, param.Phone, o)
|
|
|
413
|
- // if err != nil {
|
|
|
414
|
- // o.Rollback()
|
|
|
415
|
- // log.Error("手机号变更,新增用户失败;%s", err)
|
|
|
416
|
- // return protocol.NewErrWithMessage("1")
|
|
|
417
|
- // }
|
|
|
418
|
- // ucompany.UserId = uid
|
|
|
419
|
- // }
|
|
|
420
|
- //用户数据更新
|
|
|
421
|
- // err = editUserCompany(param.UserCompanyID, ucompany.UserId, param.Name, o)
|
|
|
422
|
- // if err != nil {
|
|
|
423
|
- // o.Rollback()
|
|
|
424
|
- // log.Error("editUserCompany err:%s", err)
|
|
|
425
|
- // return protocol.NewErrWithMessage("1")
|
|
|
426
|
- // }
|
413
|
+ if ucompany.UserId == companyInfo.AdminId {
|
|
|
414
|
+ defaultRole, err := models.GetCompanyDefaultRole(param.CompanyId)
|
|
|
415
|
+ if err != nil {
|
|
|
416
|
+ log.Error("获取公司默认角色失败")
|
|
|
417
|
+ return protocol.NewErrWithMessage("1")
|
|
|
418
|
+ }
|
|
|
419
|
+ param.Roles = append(param.Roles, defaultRole.Id)
|
|
|
420
|
+ }
|
427
|
//添加角色
|
421
|
//添加角色
|
428
|
err = editUserRole(param.UserCompanyID, ucompany.UserId, param.CompanyId, param.Roles, o)
|
422
|
err = editUserRole(param.UserCompanyID, ucompany.UserId, param.CompanyId, param.Roles, o)
|
429
|
if err != nil {
|
423
|
if err != nil {
|
|
@@ -454,9 +448,14 @@ func UserDelete(userCompanyids []int64, companyid int64) error { |
|
@@ -454,9 +448,14 @@ func UserDelete(userCompanyids []int64, companyid int64) error { |
454
|
return nil
|
448
|
return nil
|
455
|
}
|
449
|
}
|
456
|
var (
|
450
|
var (
|
457
|
- updateIds []models.UserCompany
|
|
|
458
|
- err error
|
451
|
+ updateIds []models.UserCompany
|
|
|
452
|
+ err error
|
|
|
453
|
+ companyInfo *models.Company
|
459
|
)
|
454
|
)
|
|
|
455
|
+ companyInfo, err = models.GetCompanyById(companyid)
|
|
|
456
|
+ if err != nil {
|
|
|
457
|
+ log.Error("GetCompanyById(%d)获取公司数据失败:%s", companyid, err)
|
|
|
458
|
+ }
|
460
|
o := orm.NewOrm()
|
459
|
o := orm.NewOrm()
|
461
|
_, err = o.QueryTable(&models.UserCompany{}).
|
460
|
_, err = o.QueryTable(&models.UserCompany{}).
|
462
|
Filter("id__in", userCompanyids).
|
461
|
Filter("id__in", userCompanyids).
|
|
@@ -466,10 +465,14 @@ func UserDelete(userCompanyids []int64, companyid int64) error { |
|
@@ -466,10 +465,14 @@ func UserDelete(userCompanyids []int64, companyid int64) error { |
466
|
log.Error("获取用户数据失败:%s", err)
|
465
|
log.Error("获取用户数据失败:%s", err)
|
467
|
return protocol.NewErrWithMessage("1")
|
466
|
return protocol.NewErrWithMessage("1")
|
468
|
}
|
467
|
}
|
|
|
468
|
+
|
469
|
var (
|
469
|
var (
|
470
|
ids []int64
|
470
|
ids []int64
|
471
|
)
|
471
|
)
|
472
|
for _, v := range updateIds {
|
472
|
for _, v := range updateIds {
|
|
|
473
|
+ if v.Id == companyInfo.AdminId {
|
|
|
474
|
+ return protocol.NewErrWithMessage("10071")
|
|
|
475
|
+ }
|
473
|
ids = append(ids, v.Id)
|
476
|
ids = append(ids, v.Id)
|
474
|
}
|
477
|
}
|
475
|
_, err = o.QueryTable(&models.UserCompany{}).
|
478
|
_, err = o.QueryTable(&models.UserCompany{}).
|
|
@@ -635,9 +638,14 @@ func UserForbid(userCompanyids []int64, companyid int64) error { |
|
@@ -635,9 +638,14 @@ func UserForbid(userCompanyids []int64, companyid int64) error { |
635
|
return nil
|
638
|
return nil
|
636
|
}
|
639
|
}
|
637
|
var (
|
640
|
var (
|
638
|
- updateIds []models.UserCompany
|
|
|
639
|
- err error
|
641
|
+ updateIds []models.UserCompany
|
|
|
642
|
+ err error
|
|
|
643
|
+ companyInfo *models.Company
|
640
|
)
|
644
|
)
|
|
|
645
|
+ companyInfo, err = models.GetCompanyById(companyid)
|
|
|
646
|
+ if err != nil {
|
|
|
647
|
+ log.Error("GetCompanyById(%d) err:%s", companyid, err)
|
|
|
648
|
+ }
|
641
|
o := orm.NewOrm()
|
649
|
o := orm.NewOrm()
|
642
|
_, err = o.QueryTable(&models.UserCompany{}).
|
650
|
_, err = o.QueryTable(&models.UserCompany{}).
|
643
|
Filter("id__in", userCompanyids).
|
651
|
Filter("id__in", userCompanyids).
|
|
@@ -651,6 +659,9 @@ func UserForbid(userCompanyids []int64, companyid int64) error { |
|
@@ -651,6 +659,9 @@ func UserForbid(userCompanyids []int64, companyid int64) error { |
651
|
ids []int64
|
659
|
ids []int64
|
652
|
)
|
660
|
)
|
653
|
for _, v := range updateIds {
|
661
|
for _, v := range updateIds {
|
|
|
662
|
+ if v.Id == companyInfo.AdminId {
|
|
|
663
|
+ return protocol.NewErrWithMessage("10072")
|
|
|
664
|
+ }
|
654
|
ids = append(ids, v.Id)
|
665
|
ids = append(ids, v.Id)
|
655
|
}
|
666
|
}
|
656
|
num, err := o.QueryTable(&models.UserCompany{}).
|
667
|
num, err := o.QueryTable(&models.UserCompany{}).
|