|
@@ -5,7 +5,6 @@ import ( |
|
@@ -5,7 +5,6 @@ import ( |
5
|
"oppmg/common/log"
|
5
|
"oppmg/common/log"
|
6
|
"oppmg/models"
|
6
|
"oppmg/models"
|
7
|
"oppmg/protocol"
|
7
|
"oppmg/protocol"
|
8
|
- "oppmg/services/ucenter"
|
|
|
9
|
"oppmg/storage/redisdata"
|
8
|
"oppmg/storage/redisdata"
|
10
|
"oppmg/utils"
|
9
|
"oppmg/utils"
|
11
|
"strings"
|
10
|
"strings"
|
|
@@ -14,82 +13,82 @@ import ( |
|
@@ -14,82 +13,82 @@ import ( |
14
|
"github.com/astaxie/beego/orm"
|
13
|
"github.com/astaxie/beego/orm"
|
15
|
)
|
14
|
)
|
16
|
|
15
|
|
17
|
-func UserAdd(param protocol.RequestUserAdd) error {
|
|
|
18
|
- var (
|
|
|
19
|
- err error
|
|
|
20
|
- )
|
|
|
21
|
- //校验用户是否存在
|
|
|
22
|
- err = existCompanyUser(param.CompanyId, param.Phone)
|
|
|
23
|
- if err != nil {
|
|
|
24
|
- return err
|
|
|
25
|
- }
|
|
|
26
|
- //校验角色
|
|
|
27
|
- err = validCompanyRole(param.CompanyId, param.Roles)
|
|
|
28
|
- if err != nil {
|
|
|
29
|
- log.Error(err.Error())
|
|
|
30
|
- return err
|
|
|
31
|
- }
|
|
|
32
|
- //校验部门
|
|
|
33
|
- err = validCompanyDepart(param.CompanyId, param.Departments)
|
|
|
34
|
- if err != nil {
|
|
|
35
|
- log.Error(err.Error())
|
|
|
36
|
- return err
|
|
|
37
|
- }
|
|
|
38
|
- //校验职位
|
|
|
39
|
- err = validCompanyPosition(param.CompanyId, param.Positions)
|
|
|
40
|
- if err != nil {
|
|
|
41
|
- log.Error(err.Error())
|
|
|
42
|
- return err
|
|
|
43
|
- }
|
|
|
44
|
- var (
|
|
|
45
|
- userId int64
|
|
|
46
|
- userCompanyid int64
|
|
|
47
|
- )
|
|
|
48
|
- resp, err := ucenter.RequestUCenterAddUser(param.Phone, param.Name, "")
|
|
|
49
|
- if err != nil {
|
|
|
50
|
- log.Error("用户数据提交用户中心失败:%s", err)
|
|
|
51
|
- return protocol.NewErrWithMessage("1")
|
|
|
52
|
- }
|
|
|
53
|
- o := orm.NewOrm()
|
|
|
54
|
- o.Begin()
|
|
|
55
|
- //添加用户
|
|
|
56
|
- userId, err = addNewUser(resp.Data.Nickname, resp.Data.Phone,
|
|
|
57
|
- resp.Data.Id, resp.Data.Avatar, resp.Data.Accid, resp.Data.CustomerAccount, o)
|
|
|
58
|
- if err != nil {
|
|
|
59
|
- o.Rollback()
|
|
|
60
|
- log.Error("addNewUser err:%s", err)
|
|
|
61
|
- return protocol.NewErrWithMessage("1")
|
|
|
62
|
- }
|
|
|
63
|
- //添加用户公司关系
|
|
|
64
|
- userCompanyid, err = addUserCompany(userId, param.CompanyId, param.Name, o)
|
|
|
65
|
- if err != nil {
|
|
|
66
|
- log.Error("addUserCompany err:%s", err)
|
|
|
67
|
- return protocol.NewErrWithMessage("1")
|
|
|
68
|
- }
|
|
|
69
|
- //添加角色
|
|
|
70
|
- err = editUserRole(userCompanyid, userId, param.CompanyId, param.Roles, o)
|
|
|
71
|
- if err != nil {
|
|
|
72
|
- o.Rollback()
|
|
|
73
|
- log.Error("editUserRole err:%s", err)
|
|
|
74
|
- return protocol.NewErrWithMessage("1")
|
|
|
75
|
- }
|
|
|
76
|
- //添加部门
|
|
|
77
|
- err = editUserDepart(userCompanyid, userId, param.CompanyId, param.Departments, o)
|
|
|
78
|
- if err != nil {
|
|
|
79
|
- o.Rollback()
|
|
|
80
|
- log.Error("editUserDepart err:%s", err)
|
|
|
81
|
- return protocol.NewErrWithMessage("1")
|
|
|
82
|
- }
|
|
|
83
|
- //添加职位
|
|
|
84
|
- err = editUserPosition(userCompanyid, userId, param.CompanyId, param.Positions, o)
|
|
|
85
|
- if err != nil {
|
|
|
86
|
- o.Rollback()
|
|
|
87
|
- log.Error("editUserDepart err:%s", err)
|
|
|
88
|
- return protocol.NewErrWithMessage("1")
|
|
|
89
|
- }
|
|
|
90
|
- o.Commit()
|
|
|
91
|
- return nil
|
|
|
92
|
-}
|
16
|
+// func UserAdd(param protocol.RequestUserAdd) error {
|
|
|
17
|
+// var (
|
|
|
18
|
+// err error
|
|
|
19
|
+// )
|
|
|
20
|
+// //校验用户是否存在
|
|
|
21
|
+// err = existCompanyUser(param.CompanyId, param.Phone)
|
|
|
22
|
+// if err != nil {
|
|
|
23
|
+// return err
|
|
|
24
|
+// }
|
|
|
25
|
+// //校验角色
|
|
|
26
|
+// err = validCompanyRole(param.CompanyId, param.Roles)
|
|
|
27
|
+// if err != nil {
|
|
|
28
|
+// log.Error(err.Error())
|
|
|
29
|
+// return err
|
|
|
30
|
+// }
|
|
|
31
|
+// //校验部门
|
|
|
32
|
+// err = validCompanyDepart(param.CompanyId, param.Departments)
|
|
|
33
|
+// if err != nil {
|
|
|
34
|
+// log.Error(err.Error())
|
|
|
35
|
+// return err
|
|
|
36
|
+// }
|
|
|
37
|
+// //校验职位
|
|
|
38
|
+// err = validCompanyPosition(param.CompanyId, param.Positions)
|
|
|
39
|
+// if err != nil {
|
|
|
40
|
+// log.Error(err.Error())
|
|
|
41
|
+// return err
|
|
|
42
|
+// }
|
|
|
43
|
+// var (
|
|
|
44
|
+// userId int64
|
|
|
45
|
+// userCompanyid int64
|
|
|
46
|
+// )
|
|
|
47
|
+// resp, err := ucenter.RequestUCenterAddUser(param.Phone, param.Name, "")
|
|
|
48
|
+// if err != nil {
|
|
|
49
|
+// log.Error("用户数据提交用户中心失败:%s", err)
|
|
|
50
|
+// return protocol.NewErrWithMessage("1")
|
|
|
51
|
+// }
|
|
|
52
|
+// o := orm.NewOrm()
|
|
|
53
|
+// o.Begin()
|
|
|
54
|
+// //添加用户
|
|
|
55
|
+// userId, err = addNewUser(resp.Data.Nickname, resp.Data.Phone,
|
|
|
56
|
+// resp.Data.Id, resp.Data.Avatar, resp.Data.Accid, resp.Data.CustomerAccount, o)
|
|
|
57
|
+// if err != nil {
|
|
|
58
|
+// o.Rollback()
|
|
|
59
|
+// log.Error("addNewUser err:%s", err)
|
|
|
60
|
+// return protocol.NewErrWithMessage("1")
|
|
|
61
|
+// }
|
|
|
62
|
+// //添加用户公司关系
|
|
|
63
|
+// userCompanyid, err = addUserCompany(userId, param.CompanyId, param.Name, o)
|
|
|
64
|
+// if err != nil {
|
|
|
65
|
+// log.Error("addUserCompany err:%s", err)
|
|
|
66
|
+// return protocol.NewErrWithMessage("1")
|
|
|
67
|
+// }
|
|
|
68
|
+// //添加角色
|
|
|
69
|
+// err = editUserRole(userCompanyid, userId, param.CompanyId, param.Roles, o)
|
|
|
70
|
+// if err != nil {
|
|
|
71
|
+// o.Rollback()
|
|
|
72
|
+// log.Error("editUserRole err:%s", err)
|
|
|
73
|
+// return protocol.NewErrWithMessage("1")
|
|
|
74
|
+// }
|
|
|
75
|
+// //添加部门
|
|
|
76
|
+// err = editUserDepart(userCompanyid, userId, param.CompanyId, param.Departments, o)
|
|
|
77
|
+// if err != nil {
|
|
|
78
|
+// o.Rollback()
|
|
|
79
|
+// log.Error("editUserDepart err:%s", err)
|
|
|
80
|
+// return protocol.NewErrWithMessage("1")
|
|
|
81
|
+// }
|
|
|
82
|
+// //添加职位
|
|
|
83
|
+// err = editUserPosition(userCompanyid, userId, param.CompanyId, param.Positions, o)
|
|
|
84
|
+// if err != nil {
|
|
|
85
|
+// o.Rollback()
|
|
|
86
|
+// log.Error("editUserDepart err:%s", err)
|
|
|
87
|
+// return protocol.NewErrWithMessage("1")
|
|
|
88
|
+// }
|
|
|
89
|
+// o.Commit()
|
|
|
90
|
+// return nil
|
|
|
91
|
+// }
|
93
|
func validCompanyRole(companyid int64, roleid []int64) error {
|
92
|
func validCompanyRole(companyid int64, roleid []int64) error {
|
94
|
var (
|
93
|
var (
|
95
|
err error
|
94
|
err error
|
|
@@ -392,17 +391,17 @@ func UserEdit(param protocol.RequestUserEdit) error { |
|
@@ -392,17 +391,17 @@ func UserEdit(param protocol.RequestUserEdit) error { |
392
|
return err
|
391
|
return err
|
393
|
}
|
392
|
}
|
394
|
//校验部门
|
393
|
//校验部门
|
395
|
- err = validCompanyDepart(param.CompanyId, param.Departments)
|
|
|
396
|
- if err != nil {
|
|
|
397
|
- log.Error(err.Error())
|
|
|
398
|
- return err
|
|
|
399
|
- }
|
394
|
+ // err = validCompanyDepart(param.CompanyId, param.Departments)
|
|
|
395
|
+ // if err != nil {
|
|
|
396
|
+ // log.Error(err.Error())
|
|
|
397
|
+ // return err
|
|
|
398
|
+ // }
|
400
|
//校验职位
|
399
|
//校验职位
|
401
|
- err = validCompanyPosition(param.CompanyId, param.Positions)
|
|
|
402
|
- if err != nil {
|
|
|
403
|
- log.Error(err.Error())
|
|
|
404
|
- return err
|
|
|
405
|
- }
|
400
|
+ // err = validCompanyPosition(param.CompanyId, param.Positions)
|
|
|
401
|
+ // if err != nil {
|
|
|
402
|
+ // log.Error(err.Error())
|
|
|
403
|
+ // return err
|
|
|
404
|
+ // }
|
406
|
_, err = models.GetUserById(ucompany.UserId)
|
405
|
_, err = models.GetUserById(ucompany.UserId)
|
407
|
if err != nil {
|
406
|
if err != nil {
|
408
|
log.Error("获取用户数据失败:%s", err)
|
407
|
log.Error("获取用户数据失败:%s", err)
|
|
@@ -426,19 +425,19 @@ func UserEdit(param protocol.RequestUserEdit) error { |
|
@@ -426,19 +425,19 @@ func UserEdit(param protocol.RequestUserEdit) error { |
426
|
return protocol.NewErrWithMessage("1")
|
425
|
return protocol.NewErrWithMessage("1")
|
427
|
}
|
426
|
}
|
428
|
//添加部门
|
427
|
//添加部门
|
429
|
- err = editUserDepart(param.UserCompanyID, ucompany.UserId, param.CompanyId, param.Departments, o)
|
|
|
430
|
- if err != nil {
|
|
|
431
|
- o.Rollback()
|
|
|
432
|
- log.Error("editUserDepart err:%s", err)
|
|
|
433
|
- return protocol.NewErrWithMessage("1")
|
|
|
434
|
- }
|
428
|
+ // err = editUserDepart(param.UserCompanyID, ucompany.UserId, param.CompanyId, param.Departments, o)
|
|
|
429
|
+ // if err != nil {
|
|
|
430
|
+ // o.Rollback()
|
|
|
431
|
+ // log.Error("editUserDepart err:%s", err)
|
|
|
432
|
+ // return protocol.NewErrWithMessage("1")
|
|
|
433
|
+ // }
|
435
|
//添加职位
|
434
|
//添加职位
|
436
|
- err = editUserPosition(param.UserCompanyID, ucompany.UserId, param.CompanyId, param.Positions, o)
|
|
|
437
|
- if err != nil {
|
|
|
438
|
- o.Rollback()
|
|
|
439
|
- log.Error("editUserDepart err:%s", err)
|
|
|
440
|
- return protocol.NewErrWithMessage("1")
|
|
|
441
|
- }
|
435
|
+ // err = editUserPosition(param.UserCompanyID, ucompany.UserId, param.CompanyId, param.Positions, o)
|
|
|
436
|
+ // if err != nil {
|
|
|
437
|
+ // o.Rollback()
|
|
|
438
|
+ // log.Error("editUserDepart err:%s", err)
|
|
|
439
|
+ // return protocol.NewErrWithMessage("1")
|
|
|
440
|
+ // }
|
442
|
o.Commit()
|
441
|
o.Commit()
|
443
|
return nil
|
442
|
return nil
|
444
|
}
|
443
|
}
|