MCPcopy Index your code
hub / github.com/TruthHun/DocHub / UserList

Method UserList

models/UserModel.go:57–82  ·  view source on GitHub ↗

根据条件查询用户信息,比如用户登录、用户列表等的获取也可以使用这个函数 @param p int 页码 @param listRows int 每页显示记录数 @param orderby string 排序,如"id desc" @param fields []string 需要查询的字段 @param cond string 查询条件 @param

(p, listRows int, orderby, fields, cond string, args ...interface{})

Source from the content-addressed store, hash-verified

55//@param cond string 查询条件
56//@param args ...interface{} 查询条件参数
57func (u *User) UserList(p, listRows int, orderby, fields, cond string, args ...interface{}) (params []orm.Params, totalRows int, err error) {
58 o := orm.NewOrm()
59 if len(orderby) == 0 || orderby == "" {
60 orderby = "i.Id desc"
61 }
62 if len(fields) == 0 {
63 fields = "*"
64 }
65 if len(cond) > 0 {
66 cond = "where " + cond
67 }
68
69 sqlCount := fmt.Sprintf("select count(i.Id) cnt from %v u left join %v i on u.Id=i.Id %v limit 1",
70 GetTableUser(), GetTableUserInfo(), cond,
71 )
72 var one []orm.Params
73 if rows, err := o.Raw(sqlCount, args...).Values(&one); err == nil && rows > 0 {
74 totalRows = helper.Interface2Int(one[0]["cnt"])
75 }
76
77 sql := fmt.Sprintf("select %v from %v u left join %v i on u.Id=i.Id %v order by %v limit %v offset %v",
78 fields, GetTableUser(), GetTableUserInfo(), cond, orderby, listRows, (p-1)*listRows,
79 )
80 _, err = o.Raw(sql, args...).Values(&params)
81 return params, totalRows, err
82}
83
84//获取User表的字段
85func (u *User) Fields() map[string]string {

Callers 7

LoginMethod · 0.95
GetMethod · 0.80
CoinMethod · 0.80
CollectMethod · 0.80
DocEditMethod · 0.80
GetMethod · 0.80
ListMethod · 0.80

Calls 2

GetTableUserFunction · 0.85
GetTableUserInfoFunction · 0.85

Tested by

no test coverage detected