Ai
423 Star 2K Fork 719

进击的皇虫/DocHub

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
UserController.go 1.66 KB
一键复制 编辑 原始数据 按行查看 历史
TruthHun 提交于 2018-08-10 19:37 +08:00 . 代码优化
package AdminControllers
import (
"fmt"
"github.com/TruthHun/DocHub/helper"
"strings"
"github.com/TruthHun/DocHub/helper/conv"
"github.com/TruthHun/DocHub/models"
)
//IT文库注册会员管理
type UserController struct {
BaseController
}
func (this *UserController) Prepare() {
this.BaseController.Prepare()
this.Data["IsUser"] = true
}
//用户列表
func (this *UserController) List() {
var (
condition []string
listRows = 10
id = 0
p = 1
username string
)
//path中的参数
params := conv.Path2Map(this.GetString(":splat"))
//页码处理
if _, ok := params["p"]; ok {
p = helper.Interface2Int(params["p"])
} else {
p, _ = this.GetInt("p")
}
p = helper.NumberRange(p, 1, 1000000)
//搜索的用户id处理
if _, ok := params["id"]; ok {
id = helper.Interface2Int(params["id"])
} else {
id, _ = this.GetInt("id")
}
if id > 0 {
condition = append(condition, fmt.Sprintf("i.Id=%v", id))
this.Data["Id"] = id
}
//搜索的用户名处理
if _, ok := params["username"]; ok {
username = params["username"]
} else {
username = this.GetString("username")
}
if len(username) > 0 {
condition = append(condition, fmt.Sprintf(`u.Username like "%v"`, "%"+username+"%"))
this.Data["Username"] = username
}
data, totalRows, err := models.NewUser().UserList(p, listRows, "", "*", strings.Join(condition, " and "))
if err != nil {
this.Ctx.WriteString(err.Error())
return
}
this.Data["Page"] = helper.Paginations(6, totalRows, listRows, p, "/admin/user/", "id", id, "username", username)
this.Data["Users"] = data
this.Data["ListRows"] = listRows
this.Data["TotalRows"] = totalRows
this.TplName = "list.html"
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/truthhun/DocHub.git
git@gitee.com:truthhun/DocHub.git
truthhun
DocHub
DocHub
01033d1926ec

搜索帮助