Initial commit
This commit is contained in:
@@ -0,0 +1,214 @@
|
||||
package rechargegamemod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
"stat/common/utils"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// 初始化model
|
||||
func Init() {
|
||||
// 获取数据库表
|
||||
db = mongos.New(mongos.MgoManager, CollGameRechargeLog)
|
||||
|
||||
// 初始化索引
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{{Key: "userId", Value: 1}, {Key: "appId", Value: 1}},
|
||||
}, {
|
||||
Keys: bson.D{{Key: "appId", Value: 1}, {Key: "orderId", Value: 1}},
|
||||
Options: options.Index().SetUnique(true),
|
||||
}, {
|
||||
Keys: bson.D{{Key: "appId", Value: 1}, {Key: "successAt", Value: 1}},
|
||||
}, {
|
||||
Keys: bson.D{{Key: "appId", Value: 1}, {Key: "successAt", Value: 1}, {Key: "isDeduction", Value: 1}, {Key: "blocDeduction", Value: 1}},
|
||||
},
|
||||
}
|
||||
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
|
||||
panic(fmt.Sprintf("%s model set index err ==>[%+v]", CollGameRechargeLog, err))
|
||||
}
|
||||
}
|
||||
|
||||
// 新增用户充值记录
|
||||
func AddRechargeLog(ctx context.Context, doc *GameRechargeMod) (err error) {
|
||||
if _, err = db.InsertOne(ctx, doc); err != nil {
|
||||
log.Error("admin AddActionLog InsertOne err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 获取充值详情(集团)
|
||||
func GetBlocRechargeDetailsList(ctx context.Context, appId *int32, start, end *time.Time, skip, limit int64) (count int64, data []GameRechargeMod, 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("recharge GetBlocRechargeDetailsList Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
if count, err = db.Count(ctx, filter); err != nil {
|
||||
log.Error("recharge GetBlocRechargeDetailsList Count err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 获取充值详情
|
||||
func GetBlocRechargeDetailsListTool(ctx context.Context, appId int32, skip, limit int64) (data []GameRechargeMod, err error) {
|
||||
filter := bson.M{"appId": appId}
|
||||
|
||||
sort := bson.D{{Key: "_id", Value: 1}}
|
||||
|
||||
opts := options.Find().SetSort(sort).SetSkip(skip).SetLimit(limit)
|
||||
|
||||
if err = db.Find(ctx, &data, filter, opts); err != nil {
|
||||
log.Error("recharge GetBlocRechargeDetailsList Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateRechargeInfo 批量更新
|
||||
func UpdateRechargeInfo(ctx context.Context, mods []mongo.WriteModel) error {
|
||||
if _, err := db.BulkWrite(ctx, mods); err != nil {
|
||||
log.Error("UpdateRechargeInfo failed", log.Any("err", err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddManyRecharge 新增多条注册记录
|
||||
func AddManyRecharge(ctx context.Context, docs *[]*GameRechargeMod) (err error) {
|
||||
if _, err = db.InsertMany(ctx, docs); err != nil {
|
||||
log.Error("channelCode AddManyRecharge InsertMany err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FindDspDistrictRecharge
|
||||
func FindDistrictRecharge(ctx context.Context, appId int32, district string) ([]GameRechargeMod, error) {
|
||||
list := make([]GameRechargeMod, 0)
|
||||
|
||||
beginTimeStr := "2020-10-01T00:00:00-08:00"
|
||||
|
||||
beginTime := utils.StrTimeToTime(beginTimeStr)
|
||||
query := bson.M{"successAt": bson.M{"$gt": beginTime}, "districtCode": district, "appId": appId}
|
||||
|
||||
if err := db.Find(ctx, &list, query); err != nil {
|
||||
log.Error("FindDspDistrictRecharge Find error", log.E(err))
|
||||
return list, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func FindBlocDistrictRecharge(ctx context.Context, appId int32, blocDeduction bool) ([]GameRechargeMod, error) {
|
||||
list := make([]GameRechargeMod, 0)
|
||||
|
||||
beginTimeStr := "2020-10-01T00:00:00-08:00"
|
||||
|
||||
beginTime := utils.StrTimeToTime(beginTimeStr)
|
||||
query := bson.M{"successAt": bson.M{"$gt": beginTime}, "appId": appId, "blocDeduction": blocDeduction}
|
||||
|
||||
if err := db.Find(ctx, &list, query); err != nil {
|
||||
log.Error("FindDspDistrictRecharge Find error", log.E(err))
|
||||
return list, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func FindBlocDistrictRechargeTotal(ctx context.Context, appId int32) ([]GameRechargeMod, error) {
|
||||
list := make([]GameRechargeMod, 0)
|
||||
|
||||
beginTimeStr := "2020-10-01T00:00:00-08:00"
|
||||
|
||||
beginTime := utils.StrTimeToTime(beginTimeStr)
|
||||
query := bson.M{"successAt": bson.M{"$gt": beginTime}, "appId": appId}
|
||||
|
||||
if err := db.Find(ctx, &list, query); err != nil {
|
||||
log.Error("FindDspDistrictRecharge Find error", log.E(err))
|
||||
return list, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func FindDistrictRechargeAll(ctx context.Context, appId int32) ([]GameRechargeMod, error) {
|
||||
list := make([]GameRechargeMod, 0)
|
||||
|
||||
beginTimeStr := "2020-10-01T00:00:00-08:00"
|
||||
|
||||
beginTime := utils.StrTimeToTime(beginTimeStr)
|
||||
query := bson.M{"successAt": bson.M{"$gt": beginTime}, "appId": appId, "districtCode": bson.M{"$gt": ""}}
|
||||
|
||||
if err := db.Find(ctx, &list, query); err != nil {
|
||||
log.Error("FindDspDistrictRecharge Find error", log.E(err))
|
||||
return list, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// FindRechargeByOrder
|
||||
func FindRechargeByOrder(ctx context.Context, appId int32, OrderId string) (data GameRechargeMod, err error) {
|
||||
|
||||
query := bson.M{"orderId": OrderId, "appId": appId}
|
||||
|
||||
if err = db.FindOne(ctx, &data, query); err != nil {
|
||||
log.Error("FindRechargeByOrder Find error", log.E(err))
|
||||
return data, err
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func FindRechargeByUser(ctx context.Context, appId int32, userid int64) (data GameRechargeMod, err error) {
|
||||
|
||||
query := bson.M{"userId": userid, "appId": appId}
|
||||
|
||||
if err = db.FindOne(ctx, &data, query); err != nil {
|
||||
log.Error("FindRechargeByOrder Find error", log.E(err))
|
||||
return data, err
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
//UpdateManyRecharge 更新注册用户信息
|
||||
func UpdateManyRecharge(ctx context.Context, filter bson.M, update bson.M) error {
|
||||
_, err := db.UpdateMany(ctx, filter, update)
|
||||
if err != nil {
|
||||
log.Warn("user:UpdateManyRecharge db.UpdateMany failed",
|
||||
log.E(err), log.Any("filter", filter))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
package rechargegamemod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"stat/common/log"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
// DirectRechargeAmount 获取直推充值金额
|
||||
func DirectRechargeAmount(ctx context.Context, appid int32, start, end time.Time) (count int64, money int64, err error) {
|
||||
|
||||
query := bson.M{"appId": appid, "successAt": bson.M{"$gte": start, "$lt": end}, "isDirect": true, "status": 3}
|
||||
result := make([]GameRechargeMod, 0)
|
||||
|
||||
err = db.Find(ctx, &result, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count = int64(len(result))
|
||||
for _, v := range result {
|
||||
money += v.PayMoney
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FissionRechargeAmount 获取裂变充值金额
|
||||
func FissionRechargeAmount(ctx context.Context, appid int32, start, end time.Time) (count int64, money int64, err error) {
|
||||
|
||||
query := bson.M{"appId": appid, "successAt": bson.M{"$gte": start, "$lt": end}, "isDirect": false, "status": 3}
|
||||
result := make([]GameRechargeMod, 0)
|
||||
|
||||
err = db.Find(ctx, &result, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count = int64(len(result))
|
||||
for _, v := range result {
|
||||
money += v.PayMoney
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DeductionRechargeAmount 获取扣量值金额
|
||||
func DeductionRechargeAmount(ctx context.Context, appid int32, start, end time.Time) (count int64, money int64, err error) {
|
||||
|
||||
query := bson.M{"appId": appid, "successAt": bson.M{"$gte": start, "$lt": end}, "status": 3}
|
||||
result := make([]GameRechargeMod, 0)
|
||||
|
||||
err = db.Find(ctx, &result, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count = int64(len(result))
|
||||
for _, v := range result {
|
||||
money += v.PayMoney
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// TotalRechargeAmount 获取总充值金额
|
||||
func TotalRechargeAmount(ctx context.Context, appid int32, start, end time.Time) (count int64, money int64, err error) {
|
||||
|
||||
query := bson.M{"appId": appid, "successAt": bson.M{"$gte": start, "$lt": end}, "status": 3}
|
||||
result := make([]GameRechargeMod, 0)
|
||||
|
||||
err = db.Find(ctx, &result, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count = int64(len(result))
|
||||
for _, v := range result {
|
||||
money += v.PayMoney
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// TotalDistricRechargeAmount 获取渠道总充值金额
|
||||
func TotalDistricRechargeAmount(ctx context.Context, appid int32, start, end time.Time) (result []GameRechargeMod, err error) {
|
||||
|
||||
query := bson.M{"appId": appid, "successAt": bson.M{"$gte": start, "$lt": end}, "status": 3}
|
||||
result = make([]GameRechargeMod, 0)
|
||||
|
||||
err = db.Find(ctx, &result, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// TotalDistricRechargeAmountV1 获取渠道总充值金额
|
||||
func TotalDistricRechargeAmountV1(ctx context.Context, appid int32, start, end time.Time) (result []GameRechargeMod, err error) {
|
||||
|
||||
query := bson.M{"appId": appid, "successAt": bson.M{"$gte": start, "$lt": end}, "status": 3}
|
||||
result = make([]GameRechargeMod, 0)
|
||||
|
||||
err = db.Find(ctx, &result, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// BlocTotalDistricRechargeAmount 获取渠道总充值金额
|
||||
func BlocTotalDistricRechargeAmount(ctx context.Context, appid int32, start, end time.Time) (result []GameRechargeMod, err error) {
|
||||
|
||||
query := bson.M{"appId": appid, "blocDeduction": false, "successAt": bson.M{"$gte": start, "$lt": end}, "status": 3}
|
||||
result = make([]GameRechargeMod, 0)
|
||||
|
||||
err = db.Find(ctx, &result, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetDaichongAmout 获取直推充值金额
|
||||
func GetDaichongAmout(ctx context.Context, appid int32, start, end time.Time) (count int64, money int64, err error) {
|
||||
|
||||
query := bson.M{"appId": appid, "successAt": bson.M{"$gte": start, "$lt": end}, "channelName": "daichong"}
|
||||
result := make([]GameRechargeMod, 0)
|
||||
|
||||
err = db.Find(ctx, &result, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count = int64(len(result))
|
||||
for _, v := range result {
|
||||
money += v.PayMoney
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetDaichongAmout 获取直推充值金额
|
||||
func BlocGetDaichongAmout(ctx context.Context, appid int32, start, end time.Time) (count int64, money int64, err error) {
|
||||
|
||||
query := bson.M{"appId": appid, "successAt": bson.M{"$gte": start, "$lt": end}, "blocDeduction": false, "channelName": "daichong"}
|
||||
result := make([]GameRechargeMod, 0)
|
||||
|
||||
err = db.Find(ctx, &result, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count = int64(len(result))
|
||||
for _, v := range result {
|
||||
money += v.PayMoney
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetOnlineAmount 获取直推充值金额
|
||||
func GetOnlineAmount(ctx context.Context, appid int32, start, end time.Time) (count int64, money int64, err error) {
|
||||
|
||||
query := bson.M{"appId": appid, "successAt": bson.M{"$gte": start, "$lt": end}}
|
||||
result := make([]GameRechargeMod, 0)
|
||||
|
||||
err = db.Find(ctx, &result, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count = int64(len(result))
|
||||
for _, v := range result {
|
||||
money += v.PayMoney
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// BlocGetOnlineAmount 获取直推充值金额
|
||||
func BlocGetOnlineAmount(ctx context.Context, appid int32, start, end time.Time) (count int64, money int64, err error) {
|
||||
|
||||
query := bson.M{"appId": appid, "successAt": bson.M{"$gte": start, "$lt": end}, "blocDeduction": false, "channelName": bson.M{"$ne": "daichong"}}
|
||||
result := make([]GameRechargeMod, 0)
|
||||
|
||||
err = db.Find(ctx, &result, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count = int64(len(result))
|
||||
for _, v := range result {
|
||||
money += v.PayMoney
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// BlocDirectRechargeAmount 获取直推充值金额
|
||||
func BlocDirectRechargeAmount(ctx context.Context, appid int32, start, end time.Time) (count int64, money int64, err error) {
|
||||
|
||||
query := bson.M{"appId": appid, "blocDeduction": false, "successAt": bson.M{"$gte": start, "$lt": end}, "isDirect": true, "status": 3}
|
||||
result := make([]GameRechargeMod, 0)
|
||||
|
||||
err = db.Find(ctx, &result, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count = int64(len(result))
|
||||
for _, v := range result {
|
||||
money += v.PayMoney
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// BlocFissionRechargeAmount 获取裂变充值金额
|
||||
func BlocFissionRechargeAmount(ctx context.Context, appid int32, start, end time.Time) (count int64, money int64, err error) {
|
||||
|
||||
query := bson.M{"appId": appid, "blocDeduction": false, "successAt": bson.M{"$gte": start, "$lt": end}, "isDirect": false, "status": 3}
|
||||
result := make([]GameRechargeMod, 0)
|
||||
|
||||
err = db.Find(ctx, &result, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count = int64(len(result))
|
||||
for _, v := range result {
|
||||
money += v.PayMoney
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// FissionRechargeAmount 获取裂变充值金额
|
||||
func FissionRechargeList(ctx context.Context, appid int32, start, end time.Time) (data []GameRechargeMod, err error) {
|
||||
|
||||
query := bson.M{"appId": appid, "successAt": bson.M{"$gte": start, "$lt": end}, "isDirect": false, "status": 3}
|
||||
|
||||
err = db.Find(ctx, &data, query)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//FindManyRechargeInfo 查找一批信息数据
|
||||
func FindManyRechargeInfo(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (GameRechargeInfoList, error) {
|
||||
data := make(GameRechargeInfoList, 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
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package rechargegamemod
|
||||
|
||||
import (
|
||||
"stat/common/mongos"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// 表名
|
||||
const CollGameRechargeLog = "log_recharge_game"
|
||||
|
||||
var db *mongos.MongoTool
|
||||
|
||||
// GameRechargeMod 充值成功订单信息
|
||||
type GameRechargeMod struct {
|
||||
ID primitive.ObjectID `bson:"_id,omitempty"` // 订单
|
||||
PlatformId string `json:"platformId" bson:"platformId"` // 原始平台订单Id
|
||||
UserId uint64 `json:"userId" bson:"userId"` // 用户ID
|
||||
AppId int32 `json:"appId" bson:"appId"` // appID
|
||||
SysType string `json:"sysType" bson:"sysType"` // 操作系统类型 安卓 IOS
|
||||
DevType string `json:"devType" bson:"devType"` // 设备类型
|
||||
ChannelName string `json:"channelName" bson:"channelName"` // 支付渠道名字
|
||||
CID string `json:"cid" bson:"cid"` // 渠道id
|
||||
Type string `bson:"type" json:"type"` // 充值方式
|
||||
OrderId string `json:"orderId" bson:"orderId"` // 流水id
|
||||
Money int64 `json:"money" bson:"money"` // 充值金额 订单金额
|
||||
PayMoney int64 `json:"payMoney" bson:"payMoney"` // 实际到账金额 用户实际支付金额
|
||||
Status int `json:"status" bson:"status"` // 2付款失败 3付款成功
|
||||
FailureAt time.Time `json:"failureAt,omitempty" bson:"failureAt,omitempty"` // 失败时间
|
||||
SuccessAt time.Time `json:"successAt,omitempty" bson:"successAt,omitempty"` // 成功时间
|
||||
OrderCreatedAt time.Time `json:"orderCreatedAt,omitempty" bson:"orderCreatedAt,omitempty"` // 创建时间
|
||||
BlocDeduction bool `json:"blocDeduction" bson:"blocDeduction"` // 集团扣量(特定渠道扣量)
|
||||
PromCode string `json:"promCode,omitempty" bson:"promCode"` // 用户推广序列
|
||||
RegisterTime time.Time `json:"registerTime,omitempty" bson:"registerTime"` // 操作时间
|
||||
IsDirect bool `json:"isDirect" bson:"isDirect"` // true:是直推用户
|
||||
IsFormalUser bool `json:"isFormalUser" bson:"isFormalUser"` // 是否正式用户
|
||||
DistrictCode string `json:"districtCode" bson:"districtCode"` // 渠道码
|
||||
Repeat bool `bson:"repeat" json:"repeat"` // 复冲: true 重复充值 false 第一次
|
||||
Rate string `json:"rate" bson:"rate"` // 渠道费率
|
||||
SyncStatus int64 `json:"syncStatus" bson:"syncStatus"` // 同步大白鲨:0 需要同步 1:不需要同步
|
||||
CreatedAt time.Time `bson:"createdAt"` // 创建时间
|
||||
}
|
||||
|
||||
type GameRechargeInfoList []*GameRechargeMod
|
||||
Reference in New Issue
Block a user