forked from all_user/stat_center
Initial commit
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
"time"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
// DistrictInfo 渠道原始信息
|
||||
type DistrictInfo struct {
|
||||
Code string `bson:"code"` //商区码
|
||||
Name string `bson:"name"` //账号
|
||||
Mobile string `bson:"mobile"` //手机号
|
||||
Parent string `bson:"parent"` //parent
|
||||
Password string `bson:"password"` //密码
|
||||
DiscType int `bson:"discType"` //商区类型/结算类型
|
||||
DividendRatio float64 `bson:"dividendRatio"` //分红比例 参与结算
|
||||
DisSettlement bool `bson:"disSettlement"` //禁止结算
|
||||
UserUnitCent float64 `bson:"userUnitCent"` //用户单价 单位:分
|
||||
NUDeductionRatio float64 `bson:"nuDeductionRatio"` //新增用户扣量比例
|
||||
NUDedLowerOutset int64 `bson:"nuDedLowerOutset"` //新增用户扣量起点
|
||||
NUDedAt time.Time `bson:"nuDedAt"` //新增用户扣量时间
|
||||
RechgDeductionRatio float64 `bson:"rechgDeductionRatio"` //充值扣量比例
|
||||
RechgDedLowerOutset int64 `bson:"rechgDedLowerOutset"` //充值扣量起点
|
||||
RechgDedAt time.Time `bson:"rechgDedAt"` //充值扣量时间
|
||||
ChildMax int `bson:"childMax"` //最大孩子数
|
||||
Disable bool `bson:"disable"` //禁用
|
||||
Lock bool `bson:"lock"` //禁止登陆
|
||||
DisTrans bool `bson:"disTrans"` //禁止交易
|
||||
DisAd bool `bson:"disAd"` //禁止广告
|
||||
DisMulDivi bool `bson:"disMulDivi"` //禁止多级分成(目前针对CPS)
|
||||
PayPassword string `bson:"payPassword"` //支付密码
|
||||
BalanceCent decimal.Decimal `bson:"balance"` //余额 单位:分
|
||||
Remark string `bson:"remark"` //备注
|
||||
CreatedAt time.Time `bson:"createdAt"` //文档创建时间
|
||||
UpdatedAt time.Time `bson:"updatedAt"` //文档更新时间
|
||||
}
|
||||
|
||||
// YhDistrictCodeInfo 渠道码信息
|
||||
type YhDistrictCodeInfo struct {
|
||||
DiscCode string `bson:"discCode"` //商圈码
|
||||
PromSeq string `bson:"promSeq"` //推广序列
|
||||
Remark string `bson:"remark"` //备注
|
||||
PromCode string `bson:"promCode"` //备注
|
||||
CreatedAt time.Time `bson:"createdAt"`
|
||||
DeletedAt time.Time `bson:"deletedAt,omitempty"` //删除时间
|
||||
}
|
||||
|
||||
const CollDistrict = "district"
|
||||
const CollDistrictCode = "disc_prom_seqe"
|
||||
|
||||
var dbDistrict *mongos.MongoTool
|
||||
var dbDistrictcode *mongos.MongoTool
|
||||
|
||||
func DistrictInit() {
|
||||
dbDistrict = mongos.New(ManagerYh, CollDistrict)
|
||||
dbDistrictcode = mongos.New(ManagerYh, CollDistrictCode)
|
||||
}
|
||||
|
||||
// FindYhDistrictInfo 查询所有渠道
|
||||
func FindSQDistrictInfo(ctx context.Context) ([]DistrictInfo, error) {
|
||||
list := make([]DistrictInfo, 0)
|
||||
query := bson.M{}
|
||||
|
||||
if err := dbDistrict.Find(ctx, &list, query); err != nil {
|
||||
log.Error(fmt.Sprintf("model %s FindYhDistrictInfo Find error", CollDistrict), log.E(err))
|
||||
return list, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// FindSQDistrictCodeInfo 查询渠道的渠道码
|
||||
func FindSQDistrictCodeInfo(ctx context.Context, discCode string) ([]YhDistrictCodeInfo, error) {
|
||||
list := make([]YhDistrictCodeInfo, 0)
|
||||
query := bson.M{"discCode": discCode}
|
||||
|
||||
if err := dbDistrictcode.Find(ctx, &list, query); err != nil {
|
||||
log.Error(fmt.Sprintf("model %s FindYhDistrictInfo Find error", CollDistrict), log.E(err))
|
||||
return list, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
"stat/models"
|
||||
)
|
||||
|
||||
var (
|
||||
ManagerYh *mongos.Manager
|
||||
ManagerStat *mongos.Manager
|
||||
)
|
||||
|
||||
// InitMongoDB 初始化同步数据库
|
||||
func InitMongoDB() error {
|
||||
yhDB := mongos.NewManager("mongodb://read:6zwcDUpPy7dMkLTeWwHX@172.104.42.200:47017,139.162.18.46:47017,139.162.35.214:47017/sz?direct=game&maxPoolSize=200&connectTimeout=30&authSource=admin")
|
||||
if err := yhDB.Connect(); err != nil {
|
||||
log.Error("mgoDB connect err", log.E(err))
|
||||
return err
|
||||
}
|
||||
ManagerYh = yhDB
|
||||
|
||||
// 初始化表链接
|
||||
DistrictInit()
|
||||
UserInit()
|
||||
|
||||
statDB := mongos.NewManager("mongodb://bill:E4OSVEd6zuWibxJo@118.107.44.79:47017/statcentre?direct=game&maxPoolSize=200&connectTimeout=30&authSource=statcentre")
|
||||
if err := statDB.Connect(); err != nil {
|
||||
log.Error("mgoDB connect err", log.E(err))
|
||||
return err
|
||||
}
|
||||
mongos.MgoManager = statDB
|
||||
fmt.Println(statDB)
|
||||
// 初始化数据库索引
|
||||
models.InitIndex()
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user