forked from all_user/stat_center
100 lines
2.6 KiB
Go
100 lines
2.6 KiB
Go
package withdrawGameOrdermod
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"stat/common/log"
|
|
"stat/common/mongos"
|
|
"time"
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
)
|
|
|
|
// 初始化model
|
|
func Init() {
|
|
// 获取数据库表
|
|
db = mongos.New(mongos.MgoManager, CollGameWithdrawOrder)
|
|
|
|
indexes := []mongo.IndexModel{
|
|
{
|
|
Keys: bson.D{{Key: "appId", Value: 1}, {Key: "uid", Value: 1}},
|
|
},
|
|
}
|
|
|
|
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
|
|
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollGameWithdrawOrder, err))
|
|
}
|
|
}
|
|
|
|
// 获取用户详情(集团)
|
|
func GetBlocGameWithdrawOrderList(ctx context.Context, appId *int32, start, end *time.Time, skip, limit int64) (count int64, data []GameWithdrawOrder, err error) {
|
|
filter := bson.M{}
|
|
|
|
if appId != nil {
|
|
filter["appId"] = appId
|
|
}
|
|
if start != nil && end != nil {
|
|
filter["successAt"] = bson.M{"$gte": start, "$lt": end}
|
|
} else if start != nil {
|
|
filter["successAt"] = bson.M{"$gte": start}
|
|
} else if end != nil {
|
|
filter["successAt"] = bson.M{"$lt": end}
|
|
}
|
|
|
|
sort := bson.D{{Key: "successAt", Value: -1}}
|
|
|
|
opts := options.Find().SetSort(sort).SetSkip(skip).SetLimit(limit)
|
|
|
|
if err = db.Find(ctx, &data, filter, opts); err != nil {
|
|
log.Error("register GetBlocGameWithdrawOrderList Find err", log.E(err))
|
|
return
|
|
}
|
|
|
|
if count, err = db.Count(ctx, filter); err != nil {
|
|
log.Error("register GetBlocGameWithdrawOrderList Count err", log.E(err))
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// AddWithdrawOrder 添加提现请求
|
|
func AddWithdrawOrder(ctx context.Context, doc *GameWithdrawOrder) (id string, err error) {
|
|
ret, err := db.InsertOne(ctx, doc)
|
|
if err != nil {
|
|
log.Error("withdraw AddWithdraw InsertOne err", log.E(err))
|
|
return
|
|
}
|
|
|
|
return ret, err
|
|
}
|
|
|
|
// 获取用户详情(集团)
|
|
func GetGameWithdrawOrder(ctx context.Context, appId int32, start, end time.Time) (data []GameWithdrawOrder, err error) {
|
|
filter := bson.M{"appId": appId, "successAt": bson.M{"$gte": start, "$lt": end}}
|
|
|
|
sort := bson.D{{Key: "successAt", Value: -1}}
|
|
|
|
opts := options.Find().SetSort(sort)
|
|
|
|
if err = db.Find(ctx, &data, filter, opts); err != nil {
|
|
log.Error("register GetBlocGameWithdrawOrderList Find err", log.E(err))
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
//FindManyRechargeInfo 查找一批信息数据
|
|
func FindManyGameWithdrawOrder(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (data []GameWithdrawOrder, err error) {
|
|
data = make([]GameWithdrawOrder, 0)
|
|
if err := db.Find(ctx, &data, filter, opts...); err != nil {
|
|
log.Warn("FindManyRechargeInfo dbChannel.Find failed", log.E(err), log.Any("filter", filter))
|
|
return nil, err
|
|
}
|
|
return data, nil
|
|
}
|