blog_backend_api/model/model.go

49 lines
1.3 KiB
Go
Raw Normal View History

2019-01-25 09:11:15 +00:00
package model
2019-02-23 06:19:29 +00:00
import (
"fmt"
"qiniupkg.com/x/log.v7"
"user/db"
"user/logs"
)
2019-01-25 09:11:15 +00:00
type Users struct {
ID int64 `sql:"id" json:"id"`
2019-02-23 06:19:29 +00:00
UserName string `sql:"user_name" json:"user_name"`
UserPwd string `sql:"user_pwd" json:"-"`
CreatedDate string `sql:"created_date" json:"created_date"`
UpdatedDate string `sql:"updated_date" json:"updated_date"`
DisplayName string `sql:"display_name" json:"display_name"`
EmailAddress string `sql:"email_address" json:"email_address"`
2019-01-25 09:11:15 +00:00
Tel string `sql:"tel" json:"tel"`
2019-02-23 06:19:29 +00:00
Avatar string `sql:"avatar" json:"avatar"`
}
func GetUsers(limit int32,offsetPage int32,name string) ([]Users,int32){
users := []Users{}
var query string
if name != ""{
log.Println(name)
query = fmt.Sprintf("select * from users where user_name like '%s' limit %d offset %d","%%" + name + "%%",limit,offsetPage*limit)
log.Printf(query)
}else {
query = fmt.Sprintf("select * from users limit %d offset %d",limit,offsetPage*limit)
}
err := db.GetMysqlClient().Query2(query,&users)
if nil != err{
logs.Error(err.Error())
}
type Count struct {
Count int32 `sql:"count"`
}
cnts := []Count{}
query = fmt.Sprintf("select count(*) as count from users")
err = db.GetMysqlClient().Query2(query,&cnts)
if nil != err{
logs.Error(err.Error())
}
return users,cnts[0].Count
2019-01-25 09:11:15 +00:00
}
2019-02-23 06:19:29 +00:00