Initial commit
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
package blocDailystatmod
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/mongos"
|
||||
"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, CollBlocDailyStat)
|
||||
|
||||
indexes := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.D{{Key: "sumDate", Value: 1}},
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
|
||||
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollBlocDailyStat, err))
|
||||
}
|
||||
}
|
||||
|
||||
// UpsertDailyStat 更新或插入一条统计记录
|
||||
func UpsertBlocDailyStat(ctx context.Context, sumDate time.Time, appId int32, doc BlocDailyStatDoc) (err error) {
|
||||
var filter = bson.M{
|
||||
"sumDate": sumDate,
|
||||
"appId": appId,
|
||||
}
|
||||
var update = mongos.ToBsonM(doc)
|
||||
|
||||
exists, err := db.Exists(ctx, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if exists {
|
||||
_, err = db.UpdateOne(ctx, filter, bson.M{"$set": update})
|
||||
} else {
|
||||
insertDoc := update
|
||||
insertDoc["sumDate"] = sumDate
|
||||
insertDoc["appId"] = appId
|
||||
|
||||
_, err = db.InsertOne(ctx, insertDoc)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 获取日常统计列表
|
||||
func GetBlocDailyStatList(ctx context.Context, appId *int32, start, end *time.Time, skip, limit int64) (count int64, data []BlocDailyStatMod, err error) {
|
||||
filter := bson.M{}
|
||||
if appId != nil {
|
||||
filter["appId"] = appId
|
||||
}
|
||||
if start != nil && end != nil {
|
||||
filter["sumDate"] = bson.M{"$gte": start, "$lt": end}
|
||||
} else if start != nil {
|
||||
filter["sumDate"] = bson.M{"$gte": start}
|
||||
} else if end != nil {
|
||||
filter["sumDate"] = bson.M{"$lt": end}
|
||||
}
|
||||
|
||||
sort := bson.D{{Key: "sumDate", Value: -1}}
|
||||
|
||||
opts := options.Find().SetSort(sort).SetSkip(skip).SetLimit(limit)
|
||||
|
||||
if err = db.Find(ctx, &data, filter, opts); err != nil {
|
||||
log.Error("channel GetDailyStatList Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
if count, err = db.Count(ctx, filter); err != nil {
|
||||
log.Error("channel GetDailyStatList Count err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// 获取日常统计列表
|
||||
func GetBlocDailyStatListTotal(ctx context.Context, appId *int32, start, end *time.Time) (data []BlocDailyStatMod, err error) {
|
||||
filter := bson.M{}
|
||||
if appId != nil {
|
||||
filter["appId"] = appId
|
||||
}
|
||||
if start != nil && end != nil {
|
||||
filter["sumDate"] = bson.M{"$gte": start, "$lt": end}
|
||||
} else if start != nil {
|
||||
filter["sumDate"] = bson.M{"$gte": start}
|
||||
} else if end != nil {
|
||||
filter["sumDate"] = bson.M{"$lt": end}
|
||||
}
|
||||
|
||||
sort := bson.D{{Key: "sumDate", Value: -1}}
|
||||
|
||||
opts := options.Find().SetSort(sort)
|
||||
|
||||
if err = db.Find(ctx, &data, filter, opts); err != nil {
|
||||
log.Error("channel GetDailyStatList Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func GetBlocDailyStatTotalList(ctx context.Context, start, end *time.Time) (data []BlocDailyStatMod, err error) {
|
||||
|
||||
match := bson.M{}
|
||||
if start != nil && end != nil {
|
||||
match["sumDate"] = bson.M{"$gte": start, "$lt": end}
|
||||
}
|
||||
|
||||
pipelines := []bson.M{
|
||||
{"$match": match},
|
||||
{"$group": bson.M{"_id": "$sumDate",
|
||||
"sumDate": bson.M{"$first": "$sumDate"},
|
||||
"newDirectCount": bson.M{"$sum": "$newDirectCount"},
|
||||
"newFissionCount": bson.M{"$sum": "$newFissionCount"},
|
||||
"directVisitCount": bson.M{"$sum": "$directVisitCount"},
|
||||
"fissionVisitCount": bson.M{"$sum": "$fissionVisitCount"},
|
||||
"directAmount": bson.M{"$sum": "$directAmount"},
|
||||
"fissionAmount": bson.M{"$sum": "$fissionAmount"},
|
||||
"directAmountcount": bson.M{"$sum": "$directAmountcount"},
|
||||
"fissionAmountcount": bson.M{"$sum": "$fissionAmountcount"},
|
||||
"deductionAmountCount": bson.M{"$sum": "$deductionAmountCount"},
|
||||
"newRechargeCount": bson.M{"$sum": "$newRechargeCount"},
|
||||
"newRechargeAmount": bson.M{"$sum": "$newRechargeAmount"},
|
||||
"daichongAmout": bson.M{"$sum": "$daichongAmout"},
|
||||
"onlineAmount": bson.M{"$sum": "$onlineAmount"},
|
||||
"userWithDrawAmount": bson.M{"$sum": "$userWithDrawAmount"},
|
||||
"userWithDrawPaymoneyAmount": bson.M{"$sum": "$userWithDrawPaymoneyAmount"},
|
||||
"gameRechageAmount": bson.M{"$sum": "$gameRechageAmount"},
|
||||
"gameWithdrawAmount": bson.M{"$sum": "$gameWithdrawAmount"},
|
||||
}},
|
||||
{"$sort": bson.D{{Key: "sumDate", Value: -1}}},
|
||||
}
|
||||
if err = db.Aggregate(ctx, &data, pipelines); err != nil {
|
||||
log.Error("channel GetDailyStatList Find err", log.E(err))
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package blocDailystatmod
|
||||
|
||||
import (
|
||||
"stat/common/mongos"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 表名
|
||||
const CollBlocDailyStat = "bloc_daily_stat"
|
||||
|
||||
var db *mongos.MongoTool
|
||||
|
||||
// BlocDailyStatMod 集团日常统计
|
||||
type BlocDailyStatMod struct {
|
||||
SumDate time.Time `bson:"sumDate"` // 记录时间 按天对齐
|
||||
AppId int32 `bson:"appId"` // appId
|
||||
NewDirectCount int64 `bson:"newDirectCount,omitempty"` // 新增直推
|
||||
NewFissionCount int64 `bson:"newFissionCount,omitempty"` // 新增裂变
|
||||
DirectVisitCount int64 `bson:"directVisitCount,omitempty"` // 直推访问数
|
||||
FissionVisitCount int64 `bson:"fissionVisitCount,omitempty"` // 裂变访问数
|
||||
Day1RetainRate float64 `bson:"day1RetainRate,omitempty"` // 次日留存率
|
||||
Day3RetainRate float64 `bson:"day3RetainRate,omitempty"` // 3日留存率
|
||||
Day7RetainRate float64 `bson:"day7RetainRate,omitempty"` // 7日留存率
|
||||
DirectAmount int64 `bson:"directAmount,omitempty"` // 直推充值金额
|
||||
FissionAmount int64 `bson:"fissionAmount,omitempty"` // 裂变充值金额
|
||||
DirectAmountCount int64 `bson:"directAmountcount,omitempty"` // 直推充值订单
|
||||
FissionAmountCount int64 `bson:"fissionAmountcount,omitempty"` // 裂变充值订单
|
||||
DeductionAmountCount int64 `bson:"deductionAmountCount,omitempty"` // 扣量充值订单
|
||||
NewRechargeCount int64 `bson:"newRechargeCount,omitempty"` // 新增充值数
|
||||
TotalRechargeCount int64 `bson:"totalRechargeCount,omitempty"` // 总充值人数
|
||||
NewRechargeAmount int64 `bson:"newRechargeAmount,omitempty"` // 新增充值金额
|
||||
DaichongAmout int64 `bson:"daichongAmout,omitempty"` // 代充充值金额
|
||||
OnlineAmount int64 `bson:"onlineAmount,omitempty"` // 在线充值金额
|
||||
UserWithDrawAmount int64 `bson:"userWithDrawAmount,omitempty"` // 用户提现金额
|
||||
UserWithDrawPaymoneyAmount int64 `bson:"userWithDrawPaymoneyAmount,omitempty"` // 用户提现金额(实际到账)
|
||||
GameRechageAmount int64 `bson:"gameRechageAmount,omitempty"` // 游戏充值
|
||||
GameWithdrawAmount int64 `bson:"gameWithdrawAmount,omitempty"` // 游戏提现
|
||||
LandpageAndroidClick int64 `bson:"landpageAndroidClick,omitempty"` // 落地页android访问次数
|
||||
LandpageIosAppstoreClick int64 `bson:"landpageIosAppstoreClick,omitempty"` // 落地页iOS商店包访问次数
|
||||
LandpageIosAthorClick int64 `bson:"landpageIosAthorClick,omitempty"` // 落地页iOS其他包访问次数
|
||||
UpdatedAt time.Time `bson:"updatedAt,omitempty"` // 更新时间
|
||||
}
|
||||
|
||||
type BlocDailyStatDoc struct {
|
||||
NewDirectCount *int64 `bson:"newDirectCount,omitempty"` // 新增直推
|
||||
NewFissionCount *int64 `bson:"newFissionCount,omitempty"` // 新增裂变
|
||||
DirectVisitCount *int64 `bson:"directVisitCount,omitempty"` // 直推访问数
|
||||
FissionVisitCount *int64 `bson:"fissionVisitCount,omitempty"` // 裂变访问数
|
||||
Day1RetainRate *float64 `bson:"day1RetainRate,omitempty"` // 次日留存率
|
||||
Day3RetainRate *float64 `bson:"day3RetainRate,omitempty"` // 3日留存率
|
||||
Day7RetainRate *float64 `bson:"day7RetainRate,omitempty"` // 7日留存率
|
||||
DirectAmount *int64 `bson:"directAmount,omitempty"` // 直推充值金额
|
||||
FissionAmount *int64 `bson:"fissionAmount,omitempty"` // 裂变充值金额
|
||||
DirectAmountCount *int64 `bson:"directAmountcount,omitempty"` // 直推充值订单
|
||||
FissionAmountCount *int64 `bson:"fissionAmountcount,omitempty"` // 裂变充值订单
|
||||
DeductionAmountCount *int64 `bson:"deductionAmountCount,omitempty"` // 扣量充值订单
|
||||
NewRechargeCount *int64 `bson:"newRechargeCount,omitempty"` // 新增充值数
|
||||
TotalRechargeCount *int64 `bson:"totalRechargeCount,omitempty"` // 总充值人数
|
||||
NewRechargeAmount *int64 `bson:"newRechargeAmount,omitempty"` // 新增充值金额
|
||||
DaichongAmout *int64 `bson:"daichongAmout,omitempty"` // 代充充值金额
|
||||
OnlineAmount *int64 `bson:"onlineAmount,omitempty"` // 在线充值金额
|
||||
UserWithDrawAmount *int64 `bson:"userWithDrawAmount,omitempty"` // 用户提现金额
|
||||
UserWithDrawPaymoneyAmount *int64 `bson:"userWithDrawPaymoneyAmount,omitempty"` // 用户提现金额(实际到账)
|
||||
GameRechageAmount *int64 `bson:"gameRechageAmount,omitempty"` // 游戏充值
|
||||
GameWithdrawAmount *int64 `bson:"gameWithdrawAmount,omitempty"` // 游戏提现
|
||||
LandpageAndroidClick *int64 `bson:"landpageAndroidClick,omitempty"` // 落地页android访问次数
|
||||
LandpageIosAppstoreClick *int64 `bson:"landpageIosAppstoreClick,omitempty"` // 落地页iOS商店包访问次数
|
||||
LandpageIosAthorClick *int64 `bson:"landpageIosAthorClick,omitempty"` // 落地页iOS其他包访问次数
|
||||
}
|
||||
Reference in New Issue
Block a user