70 lines
2.1 KiB
Go
70 lines
2.1 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 DspUser struct {
|
|
UID uint64 `json:"uid" bson:"uid"` //用户id
|
|
SysType string `json:"sysType" bson:"sysType"` //系统类型
|
|
DevType string `json:"devType" bson:"devType"` //设备类型
|
|
Mobile string `json:"mobile" bson:"mobile"` //手机号
|
|
Name string `json:"name" bson:"name"` //名字
|
|
DistrictCode string `json:"districtCode" bson:"districtCode"` //商区码
|
|
PromCode string `json:"promotionCode" bson:"promotionCode"` //推广码
|
|
IsDirect bool `json:"isDirect" bson:"isDirect"` //true:是直推用户
|
|
CreatedAt time.Time `bson:"createdAt"` //文档创建时间
|
|
}
|
|
|
|
const CollUser = "user"
|
|
|
|
var dbUser *mongos.MongoTool
|
|
|
|
func UserInit() {
|
|
dbUser = mongos.New(ManagerDsp, CollUser)
|
|
}
|
|
|
|
// FindDspUserInfo 查询用户
|
|
func FindDspUserInfo(ctx context.Context, skip int64, limit int64) ([]DspUser, error) {
|
|
list := make([]DspUser, 0)
|
|
query := bson.M{}
|
|
sort := bson.D{{Key: "_id", Value: 1}}
|
|
opts := options.Find().SetSkip(skip).SetLimit(limit).SetSort(sort)
|
|
|
|
if err := dbUser.Find(ctx, &list, query, opts); err != nil {
|
|
log.Error(fmt.Sprintf("model %s FindDspUserInfo Find error", CollDistrict), log.E(err))
|
|
return list, err
|
|
}
|
|
|
|
return list, nil
|
|
}
|
|
|
|
func FindOneUserInfo(ctx context.Context, uid uint64) (user DspUser, err error) {
|
|
query := bson.M{"uid": uid}
|
|
|
|
if err := dbUser.FindOne(ctx, &user, query); err != nil {
|
|
log.Error(fmt.Sprintf("model %s FindDspUserInfo Find error", CollDistrict), log.E(err))
|
|
return user, err
|
|
}
|
|
|
|
return user, nil
|
|
}
|
|
|
|
func FindManyUserInfo(ctx context.Context, uid []uint64) (user []DspUser, err error) {
|
|
query := bson.M{"uid": bson.M{"$in": uid}}
|
|
|
|
if err := dbUser.Find(ctx, &user, query); err != nil {
|
|
log.Error(fmt.Sprintf("model %s FindDspUserInfo Find error", CollDistrict), log.E(err))
|
|
return user, err
|
|
}
|
|
|
|
return user, nil
|
|
}
|