PaymentCenter/app/services/user_service.go

56 lines
1.3 KiB
Go

package services
import (
"fmt"
"github.com/ahmetb/go-linq/v3"
"qteam/app/http/entities/backend"
"qteam/app/models/userinfomodel"
"xorm.io/builder"
)
func GetListByMobile(mobile string, page int, limit int) (userlist []*userinfomodel.UserInfo, err error) {
limitStart := GetLimitStart(limit, page)
userlist, err = userinfomodel.GetInstance().GetListByMobile(mobile, limitStart...)
return
}
func GetListByWhere(where map[string]interface{}, page int, limit int) (count int64, UserList []backend.UserListResponse, err error) {
conn := builder.NewCond()
UserListInfo := []userinfomodel.UserInfo{}
for k, v := range where {
if v != "" {
conn = conn.And(builder.Like{k, fmt.Sprint(v)})
}
}
session := userinfomodel.GetInstance().GetDb().Where(conn)
if page != 0 && limit != 0 {
session = session.Limit(page, (page-1)*limit)
}
count, err = session.FindAndCount(&UserListInfo)
linq.From(UserListInfo).SelectT(func(in userinfomodel.UserInfo) (d backend.UserListResponse) {
d = in.ToDomain()
return d
}).ToSlice(&UserList)
if err != nil {
return
}
return
}
func GetLimitStart(limit int, page int) (arr []int) {
arr = make([]int, 2)
if limit <= 0 {
limit = 20
}
arr[0] = limit
if page > 0 {
arr[1] = (page - 1) * limit
} else {
arr[1] = 0
}
return
}