49 lines
1.8 KiB
Go
49 lines
1.8 KiB
Go
package model
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"stat/common/log"
|
|
"stat/common/mongos"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
type YhUser struct {
|
|
UID uint64 `json:"id" bson:"id"` //用户id
|
|
SysType string `json:"sysType" bson:"sysType"` //系统类型
|
|
DevType string `json:"deviceType" bson:"deviceType"` //设备类型
|
|
Mobile string `json:"mobile" bson:"mobile"` //手机号
|
|
Name string `json:"nickName" bson:"nickName"` //名字
|
|
DistrictCode string `json:"agentInviteCode" bson:"agentInviteCode"` //商区码
|
|
PromSeqe string `json:"promSeqe" bson:"promSeqe"` //推广序列
|
|
PromCode string `json:"inviteCode" bson:"inviteCode"` //邀请码
|
|
IsDirect bool `json:"isDirect" bson:"isDirect"` //true:是直推用户
|
|
CreatedAt time.Time `bson:"createdAt"` //文档创建时间
|
|
}
|
|
|
|
const CollUser = "server_user"
|
|
|
|
var dbUser *mongos.MongoTool
|
|
|
|
func UserInit() {
|
|
dbUser = mongos.New(ManagerYh, CollUser)
|
|
}
|
|
|
|
// FindSQUserInfo 查询用户
|
|
func FindSQUserInfo(ctx context.Context, skip int64, limit int64) ([]YhUser, error) {
|
|
list := make([]YhUser, 0)
|
|
query := bson.M{}
|
|
sort := bson.D{{Key: "_id", Value: 1}}
|
|
opts := options.Find().SetSkip(skip).SetLimit(limit).SetSort(sort).SetProjection(bson.M{"id": 1, "sysType": 1, "deviceType": 1, "mobile": 1, "nickName": 1, "agentInviteCode": 1, "inviteCode": 1, "isDirect": 1, "createdAt": 1})
|
|
|
|
if err := dbUser.Find(ctx, &list, query, opts); err != nil {
|
|
log.Error(fmt.Sprintf("model %s FindYhUserInfo Find error", CollDistrict), log.E(err))
|
|
return list, err
|
|
}
|
|
|
|
return list, nil
|
|
}
|