作者 tangxvhui

bug 修复

@@ -5,7 +5,6 @@ import ( @@ -5,7 +5,6 @@ import (
5 "oppmg/common/log" 5 "oppmg/common/log"
6 "oppmg/protocol" 6 "oppmg/protocol"
7 servecompany "oppmg/services/company" 7 servecompany "oppmg/services/company"
8 - "oppmg/utils"  
9 "strings" 8 "strings"
10 ) 9 )
11 10
@@ -249,44 +248,44 @@ func (c *CompanyController) PositionList() { @@ -249,44 +248,44 @@ func (c *CompanyController) PositionList() {
249 248
250 //UserAdd 添加用户 249 //UserAdd 添加用户
251 //@Router /user/add [post] 250 //@Router /user/add [post]
252 -func (c *CompanyController) UserAdd() {  
253 - var msg *protocol.ResponseMessage  
254 - defer func() {  
255 - c.ResposeJson(msg)  
256 - }()  
257 - var param protocol.RequestUserAdd  
258 - if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {  
259 - log.Error("json 解析失败 err:%s", err)  
260 - msg = protocol.BadRequestParam("1")  
261 - return  
262 - }  
263 - name := []rune(strings.TrimSpace(param.Name))  
264 - if len(name) == 0 {  
265 - msg = protocol.BadRequestParam("10035")  
266 - return  
267 - }  
268 - if len(name) > 10 {  
269 - msg = protocol.BadRequestParam("10034")  
270 - return  
271 - }  
272 - ok := utils.PhoneMatch.MatchString(param.Phone)  
273 - if !ok {  
274 - msg = protocol.BadRequestParam("10036")  
275 - return  
276 - }  
277 - if len(param.Departments) == 0 {  
278 - msg = protocol.BadRequestParam("10037")  
279 - return  
280 - }  
281 - if len(param.Roles) == 0 {  
282 - msg = protocol.BadRequestParam("10038")  
283 - return  
284 - }  
285 - param.CompanyId = c.GetCompanyId()  
286 - err := servecompany.UserAdd(param)  
287 - msg = protocol.NewReturnResponse(nil, err)  
288 - return  
289 -} 251 +// func (c *CompanyController) UserAdd() {
  252 +// var msg *protocol.ResponseMessage
  253 +// defer func() {
  254 +// c.ResposeJson(msg)
  255 +// }()
  256 +// var param protocol.RequestUserAdd
  257 +// if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  258 +// log.Error("json 解析失败 err:%s", err)
  259 +// msg = protocol.BadRequestParam("1")
  260 +// return
  261 +// }
  262 +// name := []rune(strings.TrimSpace(param.Name))
  263 +// if len(name) == 0 {
  264 +// msg = protocol.BadRequestParam("10035")
  265 +// return
  266 +// }
  267 +// if len(name) > 10 {
  268 +// msg = protocol.BadRequestParam("10034")
  269 +// return
  270 +// }
  271 +// ok := utils.PhoneMatch.MatchString(param.Phone)
  272 +// if !ok {
  273 +// msg = protocol.BadRequestParam("10036")
  274 +// return
  275 +// }
  276 +// if len(param.Departments) == 0 {
  277 +// msg = protocol.BadRequestParam("10037")
  278 +// return
  279 +// }
  280 +// if len(param.Roles) == 0 {
  281 +// msg = protocol.BadRequestParam("10038")
  282 +// return
  283 +// }
  284 +// param.CompanyId = c.GetCompanyId()
  285 +// err := servecompany.UserAdd(param)
  286 +// msg = protocol.NewReturnResponse(nil, err)
  287 +// return
  288 +// }
290 289
291 //UserEdit 编辑用户 290 //UserEdit 编辑用户
292 //@Router /user/edit [post] 291 //@Router /user/edit [post]
@@ -301,20 +300,20 @@ func (c *CompanyController) UserEdit() { @@ -301,20 +300,20 @@ func (c *CompanyController) UserEdit() {
301 msg = protocol.BadRequestParam("1") 300 msg = protocol.BadRequestParam("1")
302 return 301 return
303 } 302 }
304 - name := []rune(strings.TrimSpace(param.Name))  
305 - if len(name) == 0 {  
306 - msg = protocol.BadRequestParam("10035")  
307 - return  
308 - }  
309 - if len(name) > 10 {  
310 - msg = protocol.BadRequestParam("10034")  
311 - return  
312 - } 303 + // name := []rune(strings.TrimSpace(param.Name))
  304 + // if len(name) == 0 {
  305 + // msg = protocol.BadRequestParam("10035")
  306 + // return
  307 + // }
  308 + // if len(name) > 10 {
  309 + // msg = protocol.BadRequestParam("10034")
  310 + // return
  311 + // }
313 312
314 - if len(param.Departments) == 0 {  
315 - msg = protocol.BadRequestParam("10037")  
316 - return  
317 - } 313 + // if len(param.Departments) == 0 {
  314 + // msg = protocol.BadRequestParam("10037")
  315 + // return
  316 + // }
318 if len(param.Roles) == 0 { 317 if len(param.Roles) == 0 {
319 msg = protocol.BadRequestParam("10038") 318 msg = protocol.BadRequestParam("10038")
320 return 319 return
@@ -87,12 +87,12 @@ type RequestPositionDelete struct { @@ -87,12 +87,12 @@ type RequestPositionDelete struct {
87 87
88 //RequestUserAdd 添加用户 88 //RequestUserAdd 添加用户
89 type RequestUserAdd struct { 89 type RequestUserAdd struct {
90 - Name string `json:"name"`  
91 - CompanyId int64 `json:"company_id"`  
92 - Phone string `json:"phone"`  
93 - Departments []int64 `json:"departments"`  
94 - Positions []int64 `json:"positions"`  
95 - Roles []int64 `json:"roles"` 90 + //Name string `json:"name"`
  91 + CompanyId int64 `json:"company_id"`
  92 + // Phone string `json:"phone"`
  93 + // Departments []int64 `json:"departments"`
  94 + // Positions []int64 `json:"positions"`
  95 + Roles []int64 `json:"roles"`
96 } 96 }
97 97
98 //RequestUserEdit 编辑用户 98 //RequestUserEdit 编辑用户
@@ -48,7 +48,7 @@ func init() { @@ -48,7 +48,7 @@ func init() {
48 beego.NSNamespace("/user", 48 beego.NSNamespace("/user",
49 beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"), 49 beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"),
50 // beego.NSRouter("/add", &controllers.CompanyController{}, "post:UserAdd"), 50 // beego.NSRouter("/add", &controllers.CompanyController{}, "post:UserAdd"),
51 - // beego.NSRouter("/edit", &controllers.CompanyController{}, "post:UserEdit"), 51 + beego.NSRouter("/edit", &controllers.CompanyController{}, "post:UserEdit"),
52 // beego.NSRouter("/delete", &controllers.CompanyController{}, "post:UserDelete"), 52 // beego.NSRouter("/delete", &controllers.CompanyController{}, "post:UserDelete"),
53 // beego.NSRouter("/allow_forbid", &controllers.CompanyController{}, "post:UserAllowForbid"), 53 // beego.NSRouter("/allow_forbid", &controllers.CompanyController{}, "post:UserAllowForbid"),
54 beego.NSRouter("/info", &controllers.CompanyController{}, "post:UserDetail"), 54 beego.NSRouter("/info", &controllers.CompanyController{}, "post:UserDetail"),
@@ -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 }