forked from all_user/stat_center
90 lines
2.3 KiB
Go
90 lines
2.3 KiB
Go
package withdrawUserOrdermod
|
|
|
|
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, CollUserWithDrawOrder)
|
|
|
|
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", CollUserWithDrawOrder, err))
|
|
}
|
|
}
|
|
|
|
// 获取用户详情(集团)
|
|
func GetBlocUserWithdrawOrderList(ctx context.Context, appId *int32, start, end *time.Time, skip, limit int64) (count int64, data []UserWithdrawOrder, err error) {
|
|
filter := bson.M{"blocDeduction": false}
|
|
|
|
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 GetBlocUserWithdrawOrderList Find err", log.E(err))
|
|
return
|
|
}
|
|
|
|
if count, err = db.Count(ctx, filter); err != nil {
|
|
log.Error("register GetBlocUserWithdrawOrderList Count err", log.E(err))
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// AddWithdrawOrder 添加提现请求
|
|
func AddWithdrawOrder(ctx context.Context, doc *UserWithdrawOrder) (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 GetBlocUserWithdrawOrder(ctx context.Context, appId int32, start, end time.Time) (data []UserWithdrawOrder, err error) {
|
|
filter := bson.M{"blocDeduction": false, "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 GetBlocUserWithdrawOrderList Find err", log.E(err))
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|