用户列表
()
| 24 | |
| 25 | //用户列表 |
| 26 | func (this *UserController) List() { |
| 27 | var ( |
| 28 | condition []string |
| 29 | listRows = 10 |
| 30 | id = 0 |
| 31 | p = 1 |
| 32 | username string |
| 33 | ) |
| 34 | //path中的参数 |
| 35 | params := conv.Path2Map(this.GetString(":splat")) |
| 36 | |
| 37 | //页码处理 |
| 38 | if _, ok := params["p"]; ok { |
| 39 | p = helper.Interface2Int(params["p"]) |
| 40 | } else { |
| 41 | p, _ = this.GetInt("p") |
| 42 | } |
| 43 | p = helper.NumberRange(p, 1, 1000000) |
| 44 | |
| 45 | //搜索的用户id处理 |
| 46 | if _, ok := params["id"]; ok { |
| 47 | id = helper.Interface2Int(params["id"]) |
| 48 | } else { |
| 49 | id, _ = this.GetInt("id") |
| 50 | } |
| 51 | if id > 0 { |
| 52 | condition = append(condition, fmt.Sprintf("i.Id=%v", id)) |
| 53 | this.Data["Id"] = id |
| 54 | } |
| 55 | |
| 56 | //搜索的用户名处理 |
| 57 | if _, ok := params["username"]; ok { |
| 58 | username = params["username"] |
| 59 | } else { |
| 60 | username = this.GetString("username") |
| 61 | } |
| 62 | if len(username) > 0 { |
| 63 | condition = append(condition, fmt.Sprintf(`u.Username like "%v"`, "%"+username+"%")) |
| 64 | this.Data["Username"] = username |
| 65 | } |
| 66 | |
| 67 | data, totalRows, err := models.NewUser().UserList(p, listRows, "", "*", strings.Join(condition, " and ")) |
| 68 | if err != nil { |
| 69 | this.Ctx.WriteString(err.Error()) |
| 70 | return |
| 71 | } |
| 72 | |
| 73 | this.Data["Page"] = helper.Paginations(6, totalRows, listRows, p, "/admin/user/", "id", id, "username", username) |
| 74 | this.Data["Users"] = data |
| 75 | this.Data["ListRows"] = listRows |
| 76 | this.Data["TotalRows"] = totalRows |
| 77 | this.TplName = "list.html" |
| 78 | } |