AddMember 参加参与用户.
()
| 15 | |
| 16 | // AddMember 参加参与用户. |
| 17 | func (this *BookMemberController) AddMember() { |
| 18 | identify := this.GetString("identify") |
| 19 | account := this.GetString("account") |
| 20 | roleId, _ := this.GetInt("role_id", 3) |
| 21 | |
| 22 | if identify == "" || account == "" { |
| 23 | this.JsonResult(6001, "参数错误") |
| 24 | } |
| 25 | book, err := this.IsPermission() |
| 26 | |
| 27 | if err != nil { |
| 28 | this.JsonResult(6001, err.Error()) |
| 29 | } |
| 30 | |
| 31 | member := models.NewMember() |
| 32 | |
| 33 | if _, err := member.FindByAccount(account); err != nil { |
| 34 | this.JsonResult(404, "用户不存在") |
| 35 | } |
| 36 | if member.Status == 1 { |
| 37 | this.JsonResult(6003, "用户已被禁用") |
| 38 | } |
| 39 | |
| 40 | if _, err := models.NewRelationship().FindForRoleId(book.BookId, member.MemberId); err == nil { |
| 41 | this.JsonResult(6003, "用户已存在该书籍中") |
| 42 | } |
| 43 | |
| 44 | relationship := models.NewRelationship() |
| 45 | relationship.BookId = book.BookId |
| 46 | relationship.MemberId = member.MemberId |
| 47 | relationship.RoleId = roleId |
| 48 | |
| 49 | if err := relationship.Insert(); err != nil { |
| 50 | this.JsonResult(500, err.Error()) |
| 51 | } |
| 52 | |
| 53 | result := models.NewMemberRelationshipResult().FromMember(member) |
| 54 | result.RoleId = roleId |
| 55 | result.RelationshipId = relationship.RelationshipId |
| 56 | result.BookId = book.BookId |
| 57 | result.ResolveRoleName() |
| 58 | this.JsonResult(0, "ok", result) |
| 59 | } |
| 60 | |
| 61 | // 变更指定用户在指定书籍中的权限 |
| 62 | func (this *BookMemberController) ChangeRole() { |
nothing calls this directly
no test coverage detected