Initial commit

This commit is contained in:
2026-05-20 16:13:58 +08:00
commit ceffbe382e
500 changed files with 157469 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
package accessmod
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, CollAccessLog)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: "userId", Value: 1}, {Key: "appId", Value: 1}},
}, {
Keys: bson.D{{Key: "appId", Value: 1}, {Key: "visitAt", Value: 1}},
},
{
Keys: bson.D{{Key: "appId", Value: 1}, {Key: "userId", Value: 1}, {Key: "visitAt", Value: 1}},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{{Key: "appId", Value: 1}, {Key: "userId", Value: 1}, {Key: "visitAt", Value: 1}, {Key: "registerTime", Value: 1}},
},
{
Keys: bson.D{{Key: "createdAt", Value: 1}},
Options: options.Index().SetExpireAfterSeconds(5 * 24 * 60 * 60),
}, {
Keys: bson.D{{Key: "appId", Value: 1}, {Key: "userId", Value: 1}, {Key: "visitAt", Value: 1}, {Key: "isDirect", Value: 1}, {Key: "blocDeduction", Value: 1}},
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", CollAccessLog, err))
}
}
// 新增用户访问记录
func AddAccessLog(ctx context.Context, doc *AccessMod) (err error) {
doc.CreatedAt = time.Now()
if _, err = db.UpsertOne(ctx, bson.M{"visitAt": doc.VisitAt, "userId": doc.UserId, "appId": doc.AppId}, bson.M{"$setOnInsert": doc}); err != nil {
log.Error("admin AddAccessLog InsertOne err", log.E(err))
return
}
return
}
+221
View File
@@ -0,0 +1,221 @@
package accessmod
import (
"context"
"stat/common/log"
"stat/common/utils"
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
)
// 根据appId 获取appInfo
func GetAccessUserByTime(ctx context.Context, appid int32, start, end time.Time) ([]uint64, error) {
filter := bson.M{"appId": appid, "visitAt": bson.M{"$gte": start, "$lt": end}}
results := make([]AccessMod, 0)
if err := db.Find(ctx, &results, filter); err != nil {
log.Error("GetAccessUserByTime Find err", log.Any("start", start), log.Any("end", end), log.E(err))
return nil, err
}
uids := make([]uint64, 0, len(results))
for _, v := range results {
uids = append(uids, v.UserId)
}
return uids, nil
}
func GetAccessUserDistrictCount(ctx context.Context, appid int32, sysTypes []string, start, end time.Time) (int64, error) {
filter := bson.M{
"appId": appid,
"visitAt": bson.M{"$gte": start, "$lt": end},
"isDirect": true,
"$and": bson.A{
bson.M{"districtCode": bson.M{"$gt": ""}},
bson.M{"districtCode": bson.M{"$ne": "官方"}},
bson.M{"districtCode": bson.M{"$ne": "modelweb"}},
},
}
if len(sysTypes) > 0 {
filter["sysType"] = bson.M{"$in": sysTypes}
}
if count, err := db.Count(ctx, filter); err != nil {
log.Error("GetAccessUserDistrictCount Find err", log.Any("start", start), log.Any("end", end), log.E(err))
return 0, err
} else {
return count, nil
}
}
// 根据appId 获取appInfo
func GetAndroidAccessUserByTime(ctx context.Context, appid int32, start, end time.Time) ([]uint64, error) {
filter := bson.M{"appId": appid, "sysType": "android", "visitAt": bson.M{"$gte": start, "$lt": end}}
results := make([]AccessMod, 0)
if err := db.Find(ctx, &results, filter); err != nil {
log.Error("GetAccessUserByTime FindOne err", log.Any("start", start), log.Any("end", end), log.E(err))
return nil, err
}
uids := make([]uint64, 0, len(results))
for _, v := range results {
uids = append(uids, v.UserId)
}
return uids, nil
}
// 根据appId 获取appInfo
func GetIosAccessUserByTime(ctx context.Context, appid int32, start, end time.Time) ([]uint64, error) {
filter := bson.M{"appId": appid, "sysType": "ios", "visitAt": bson.M{"$gte": start, "$lt": end}}
results := make([]AccessMod, 0)
if err := db.Find(ctx, &results, filter); err != nil {
log.Error("GetAccessUserByTime FindOne err", log.Any("start", start), log.Any("end", end), log.E(err))
return nil, err
}
uids := make([]uint64, 0, len(results))
for _, v := range results {
uids = append(uids, v.UserId)
}
return uids, nil
}
// BlocDailyStatCount 集团日活
func BlocDailyStatCount(ctx context.Context, appid int32, isDirect *bool, blocDeduction *bool, start, end time.Time) (int64, error) {
filter := bson.M{"appId": appid, "visitAt": bson.M{"$gte": start, "$lt": end}}
if isDirect != nil {
filter["isDirect"] = *isDirect
}
if blocDeduction != nil {
filter["blocDeduction"] = *blocDeduction
}
count, err := db.Count(ctx, filter)
if err != nil {
log.Error("GetAccessUserByTime Find err", log.Any("start", start), log.Any("end", end), log.E(err))
return 0, err
}
return count, nil
}
// BlocDailyVisitStatCount H5日活
func BlocDailyVisitStatCount(ctx context.Context, appid int32, sysTypes []string, blocDeduction *bool, start, end time.Time) (int64, error) {
filter := bson.M{
"appId": appid,
"sysType": bson.M{"$in": sysTypes},
"visitAt": bson.M{"$gte": start, "$lt": end}}
if blocDeduction != nil {
filter["blocDeduction"] = *blocDeduction
}
count, err := db.Count(ctx, filter)
if err != nil {
log.Error("BlocDailyVisitStatCount Find err", log.Any("start", start), log.Any("end", end), log.E(err))
return 0, err
}
return count, nil
}
// DailyUserCount 用户访问量
func DailyUserVisitCountByRegister(ctx context.Context, appid int32, start, end, registerStart, registerEnd time.Time) (int64, error) {
filter := bson.M{"appId": appid, "visitAt": bson.M{"$gte": start, "$lt": end}, "registerTime": bson.M{"$gte": registerStart, "$lt": registerEnd}}
count, err := db.Count(ctx, filter)
if err != nil {
log.Error("DailyUserCount Find err", log.Any("start", start), log.Any("end", end), log.E(err))
return 0, err
}
return count, nil
}
// VisitInfoByTime 访问信息
func VisitInfoByTime(ctx context.Context, appid int32, start, end time.Time, blocDeduction *bool) ([]*AccessMod, error) {
filter := bson.M{"appId": appid, "visitAt": bson.M{"$gte": start, "$lt": end}}
results := make([]*AccessMod, 0)
if err := db.Find(ctx, &results, filter); err != nil {
log.Error("GetAccessUserByTime Find err", log.Any("start", start), log.Any("end", end), log.E(err))
return nil, err
}
return results, nil
}
type OnItem func(item *AccessMod)
// VisitInfoByTimeShard 访问信息
func VisitInfoByTimeShard(ctx context.Context, appid int32, start, end time.Time, step time.Duration, onItem OnItem) error {
segments := utils.CalcTimeSegments(start, end, step)
for _, segment := range segments {
results := make([]*AccessMod, 0)
filter := bson.M{"appId": appid, "visitAt": bson.M{"$gte": segment.Begin, "$lt": segment.End}}
if err := db.Find(ctx, &results, filter); err != nil {
log.Error("GetAccessUserByTime Find err", log.Any("start", start), log.Any("end", end), log.E(err))
return err
}
for _, item := range results {
onItem(item)
}
results = nil
}
return nil
}
// VisitInfoByTime 访问信息
func VisitInfoByTimeV1(ctx context.Context, appid int32, start, end time.Time, blocDeduction *bool) ([]AccessMod, error) {
filter := bson.M{"appId": appid, "isDeduction": false, "visitAt": bson.M{"$gte": start, "$lt": end}}
results := make([]AccessMod, 0)
if err := db.Find(ctx, &results, filter); err != nil {
log.Error("GetAccessUserByTime Find err", log.Any("start", start), log.Any("end", end), log.E(err))
return nil, err
}
return results, nil
}
// DailyUserVisitCountByInfoShard 用户访问量
func DailyUserVisitCountByInfoShard(ctx context.Context, appid int32, start, end time.Time, shard time.Duration, registerStart, registerEnd time.Time, onItem OnItem) error {
segments := utils.CalcTimeSegments(start, end, shard)
for _, segment := range segments {
filter := bson.M{"appId": appid, "visitAt": bson.M{"$gte": segment.Begin, "$lt": segment.End}, "registerTime": bson.M{"$gte": registerStart, "$lt": registerEnd}}
results := make([]*AccessMod, 0)
err := db.Find(ctx, &results, filter)
if err != nil {
log.Error("DailyUserVisitCountByInfo Find err", log.Any("start", start), log.Any("end", end), log.E(err))
return err
}
for _, item := range results {
onItem(item)
}
results = nil
}
return nil
}
// DailyUserCount 用户访问量
func DailyUserVisitCountByInfo(ctx context.Context, appid int32, start, end, registerStart, registerEnd time.Time) ([]AccessMod, error) {
filter := bson.M{"appId": appid, "visitAt": bson.M{"$gte": start, "$lt": end}, "registerTime": bson.M{"$gte": registerStart, "$lt": registerEnd}}
results := make([]AccessMod, 0)
err := db.Find(ctx, &results, filter)
if err != nil {
log.Error("DailyUserVisitCountByInfo Find err", log.Any("start", start), log.Any("end", end), log.E(err))
return nil, err
}
return results, nil
}
// FindManyVisitInfo 查找一批渠道信息数据
func FindManyVisitInfo(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (VisitInfoList, error) {
data := make(VisitInfoList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("FindManyVisitInfo dbChannel.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
+32
View File
@@ -0,0 +1,32 @@
package accessmod
import (
"stat/common/mongos"
"time"
)
// 表名
const CollAccessLog = "log_access"
var db *mongos.MongoTool
// AccessMod 用户访问记录
type AccessMod struct {
UserId uint64 `json:"userId" bson:"userId"` // 用户ID
AppId int32 `json:"appId" bson:"appId"` // appID
SysType string `json:"sysType" bson:"sysType"` // 操作系统类型 android ios
DevType string `json:"devType,omitempty" bson:"devType"` // 设备型号
IP string `json:"ip,omitempty" bson:"ip"` // IP
Version string `json:"version,omitempty" bson:"version"` // APP版本号
DevID string `json:"devID,omitempty" bson:"devID"` // 设备ID
IsDirect bool `json:"isDirect" bson:"isDirect"` // true:是直推用户
DistrictCode string `json:"districtCode" bson:"districtCode"` // 渠道码
RegisterTime time.Time `json:"registerTime,omitempty" bson:"registerTime"` // 操作时间
IsDeduction bool `json:"isDeduction" bson:"isDeduction"` // true:CPA扣量用户
IsFormalUser bool `json:"isFormalUser" bson:"isFormalUser"` // 是否正式用户
BlocDeduction bool `json:"blocDeduction" bson:"blocDeduction"` // 集团扣量(特定渠道扣量)
VisitAt time.Time `json:"visitAt,omitempty" bson:"visitAt"` // 访问时间
CreatedAt time.Time `bson:"createdAt"` // 创建时间
}
type VisitInfoList []*AccessMod
+96
View File
@@ -0,0 +1,96 @@
package activityVisit
import (
"context"
"fmt"
"time"
"stat/common/log"
"stat/common/mongos"
"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, CollActivityVisit)
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: "appId", Value: 1}},
},
{
Keys: bson.D{{Key: "activityId", Value: 1}},
},
{
Keys: bson.D{{Key: "createdAt", Value: -1}},
},
{
Keys: bson.D{{Key: "ch", Value: 1}},
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollActivityVisit, err))
}
}
// 插入InsertActivityVisit 活动访问次数
func InsertActivityVisit(ctx context.Context, model *ActivityVisit) (err error) {
_, err = db.InsertOne(ctx, model)
return
}
// 插入InsertManyActivityVisit 活动访问次数
func InsertManyActivityVisit(ctx context.Context, docs []interface{}) (err error) {
_, err = db.GetCollection().InsertMany(ctx, docs)
return
}
// FindManyActivityList 查找一批
func FindManyActivityList(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (ActivityVisitList, error) {
data := make(ActivityVisitList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("FindManyActivityList db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
// 根据appId 获取activityVisit
func GetActivityVisitByTime(ctx context.Context, appid int32, start, end time.Time) (ActivityVisitList, error) {
filter := bson.M{"appId": appid, "createdAt": bson.M{"$gte": start, "$lt": end}}
results := make(ActivityVisitList, 0)
if err := db.Find(ctx, &results, filter); err != nil {
log.Error("GetActivityVisitByTime FindOne err", log.Any("start", start), log.Any("end", end), log.E(err))
return nil, err
}
return results, nil
}
// 根据ch 获取activityVisit
func GetActivityVisitByCh(ctx context.Context, ch string, start, end time.Time) (ActivityVisitList, error) {
filter := bson.M{"ch": ch, "createdAt": bson.M{"$gte": start, "$lt": end}}
results := make(ActivityVisitList, 0)
if err := db.Find(ctx, &results, filter); err != nil {
log.Error("GetActivityVisitByTime FindOne err", log.Any("start", start), log.Any("end", end), log.E(err))
return nil, err
}
return results, nil
}
// CountActivityVisit 统计活动访问数量
func CountActivityVisit(ctx context.Context, filter bson.M) (int64, error) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("CountActivityVisit db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
+28
View File
@@ -0,0 +1,28 @@
package activityVisit
import (
"stat/common/mongos"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// 表名
const CollActivityVisit = "activity_visit"
var db *mongos.MongoTool
type ActivityVisit struct {
AppId int32 `json:"appId" bson:"appId"` // appId
CH string `json:"ch" bson:"ch"` // 渠道号
IP string `json:"ip" bson:"ip"` // 用户IP
DevType string `json:"devType" bson:"devType"` // 设备类型
SysType string `json:"sysType" bson:"sysType"` // 系统类型
PeerIP string `json:"peerIP" bson:"peerIP"` // 网站IP
ActivityId primitive.ObjectID `json:"activityId" bson:"activityId"` // 活动Id
ActivityName string `json:"activityName" bson:"activityName"` // 活动名字
CreatedAt time.Time `bson:"createdAt"` // 创建时间
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
}
type ActivityVisitList []*ActivityVisit
+462
View File
@@ -0,0 +1,462 @@
package activitymod
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var dbAct *mongos.MongoTool
var dbLotCodeInfo *mongos.MongoTool
var dbLotGift *mongos.MongoTool
var dbLotGetGift *mongos.MongoTool
func Init() {
ctx := context.Background()
InitAct(ctx)
InitLotCodeInfo(ctx)
InitLotGift(ctx)
InitLotGiftCode(ctx)
}
func InitAct(ctx context.Context) {
// 获取数据库表
dbAct = mongos.New(mongos.MgoManager, TN.ActivityInfo)
// 初始化
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: FN.ActivityInfo.Name, Value: 1}},
},
{
Keys: bson.D{{Key: FN.ActivityInfo.Enable, Value: 1}},
},
{
Keys: bson.D{{Key: FN.ActivityInfo.SortCode, Value: -1}},
},
{
Keys: bson.D{
{Key: FN.ActivityInfo.StartTime, Value: -1},
{Key: FN.ActivityInfo.EndTime, Value: -1},
},
},
}
if _, err := dbAct.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", TN.ActivityInfo, err))
}
}
func InitLotCodeInfo(ctx context.Context) {
// 获取数据库表
dbLotCodeInfo = mongos.New(mongos.MgoManager, TN.LottertyCodeInfo)
// 初始化
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: FN.LottertyCodeInfo.LotteryCode, Value: 1}},
},
{
Keys: bson.D{{Key: FN.LottertyCodeInfo.ActId, Value: 1}},
},
{
Keys: bson.D{{Key: FN.LottertyCodeInfo.UserIp, Value: 1}},
},
{
Keys: bson.D{{Key: FN.LottertyCodeInfo.IsUsed, Value: 1}},
},
}
if _, err := dbLotCodeInfo.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", TN.LottertyCodeInfo, err))
}
}
func InitLotGift(ctx context.Context) {
// 获取数据库表
dbLotGift = mongos.New(mongos.MgoManager, TN.LotteryGift)
// 初始化
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: FN.LotteryGift.ActId, Value: 1}},
},
{
Keys: bson.D{{Key: FN.LotteryGift.GiftName, Value: 1}},
},
}
if _, err := dbLotGift.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", TN.LotteryGift, err))
}
}
func InitLotGiftCode(ctx context.Context) {
// 获取数据库表
dbLotGetGift = mongos.New(mongos.MgoManager, TN.LotteryGetGift)
// 初始化
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: FN.LotteryGetGift.GiftCode, Value: 1}},
},
{
Keys: bson.D{{Key: FN.LotteryGetGift.AppName, Value: 1}},
},
{
Keys: bson.D{{Key: FN.LotteryGetGift.ActId, Value: 1}},
},
{
Keys: bson.D{{Key: FN.LotteryGetGift.GiftId, Value: 1}},
},
}
if _, err := dbLotGetGift.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", TN.LotteryGetGift, err))
}
}
//InsertOneActivityInfo 插入一个活动信息
func InsertOneActivityInfo(ctx context.Context, data *ActivityInfo) error {
if _, err := dbAct.InsertOne(ctx, data); err != nil {
log.Warn("activitymod:InsertOneActivityInfo db.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneActivityInfo 查找一个活动信息
func FindOneActivityInfo(ctx context.Context, filter bson.M) (*ActivityInfo, error) {
var data ActivityInfo
if err := dbAct.FindOneEx(ctx, &data, filter); err != nil {
log.Warn("activitymod:FindOneActivityInfo db.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &data, nil
}
//DelOneActivityInfo 删除一个活动信息
func DelOneActivityInfo(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbAct.DeleteOne(ctx, filter)
if err != nil {
log.Warn("activitymod:DelOneActivityInfo db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateOneActivityInfo 更新一个活动信息
func UpdateOneActivityInfo(ctx context.Context, filter bson.M, update bson.M) error {
result, err := dbAct.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("activitymod:UpdateOneActivityInfo activitymod:UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
if result.MatchedCount == 0 {
return mongo.ErrNoDocuments
}
return nil
}
//CountActivityInfos 统计活动信息数量
func CountActivityInfos(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbAct.Count(ctx, filter)
if err != nil {
log.Warn("activitymod:CountActivityInfos db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateManyActivityInfo 更新满足条件的活动信息
func UpdateManyActivityInfo(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbAct.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyActivityInfo db.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//FindManyActivityInfo 查找一批活动信息数据
func FindManyActivityInfo(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (ActivityInfoList, error) {
data := make(ActivityInfoList, 0)
if err := dbAct.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("activitymod:FindManyActivityInfo db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
//FindManyActivityInfoWithBind 用自己定义结构查找一批活动信息数据
func FindManyActivityInfoWithBind(ctx context.Context, bind interface{}, filter bson.M, opts ...*options.FindOptions) error {
if err := dbAct.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("activitymod:FindManyActivityInfoWithBind db.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//InsertOneLottertyCodeInfo 插入一个抽奖码信息
func InsertOneLottertyCodeInfo(ctx context.Context, data *LottertyCodeInfo) error {
if _, err := dbLotCodeInfo.InsertOne(ctx, data); err != nil {
log.Warn("activitymod:InsertOneLottertyCodeInfo db.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneLottertyCodeInfo 查找一个抽奖码信息
func FindOneLottertyCodeInfo(ctx context.Context, filter bson.M) (*LottertyCodeInfo, error) {
var data LottertyCodeInfo
if err := dbLotCodeInfo.FindOneEx(ctx, &data, filter); err != nil {
log.Warn("LottertyCodeInfo:FindOneLottertyCodeInfo activitymod:FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &data, nil
}
//DelOneLottertyCodeInfo 删除一个抽奖码信息
func DelOneLottertyCodeInfo(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbLotCodeInfo.DeleteOne(ctx, filter)
if err != nil {
log.Warn("LottertyCodeInfo:DelOneLottertyCodeInfo activitymod:DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateOneLottertyCodeInfo 更新一个抽奖码信息
func UpdateOneLottertyCodeInfo(ctx context.Context, filter bson.M, update bson.M) error {
result, err := dbLotCodeInfo.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("UpdateOneLottertyCodeInfo activitymod:UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
if result.MatchedCount == 0 {
return mongo.ErrNoDocuments
}
return nil
}
//CountLottertyCodeInfos 统计抽奖码信息数量
func CountLottertyCodeInfos(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbLotCodeInfo.Count(ctx, filter)
if err != nil {
log.Warn("LottertyCodeInfo:CountLottertyCodeInfos activitymod:Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateManyLottertyCodeInfo 更新满足条件的抽奖码信息
func UpdateManyLottertyCodeInfo(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbLotCodeInfo.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyLottertyCodeInfo activitymod:UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//FindManyLottertyCodeInfo 查找一批抽奖码信息数据
func FindManyLottertyCodeInfo(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (LottertyCodeInfoList, error) {
data := make(LottertyCodeInfoList, 0)
if err := dbLotCodeInfo.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("LottertyCodeInfo:FindManyLottertyCodeInfo activitymod:Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
//FindManyLottertyCodeInfoWithBind 用自己定义结构查找一批抽奖码信息数据
func FindManyLottertyCodeInfoWithBind(ctx context.Context, bind interface{}, filter bson.M, opts ...*options.FindOptions) error {
if err := dbLotCodeInfo.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("LottertyCodeInfo:FindManyLottertyCodeInfoWithBind activitymod:Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//InsertOneLotteryGift 插入一个奖品信息
func InsertOneLotteryGift(ctx context.Context, data *LotteryGift) error {
if _, err := dbLotGift.InsertOne(ctx, data); err != nil {
log.Warn("activitymod:InsertOneLotteryGift db.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneLotteryGift 查找一个奖品信息
func FindOneLotteryGift(ctx context.Context, filter bson.M) (*LotteryGift, error) {
var data LotteryGift
if err := dbLotGift.FindOneEx(ctx, &data, filter); err != nil {
log.Warn("LotteryGift:FindOneLotteryGift dbLotGift.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &data, nil
}
//DelOneLotteryGift 删除一个奖品信息
func DelOneLotteryGift(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbLotGift.DeleteOne(ctx, filter)
if err != nil {
log.Warn("LotteryGift:DelOneLotteryGift dbLotGift.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateOneLotteryGift 更新一个奖品信息
func UpdateOneLotteryGift(ctx context.Context, filter bson.M, update bson.M) error {
result, err := dbLotGift.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("UpdateOneLotteryGift dbLotGift.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
if result.MatchedCount == 0 {
return mongo.ErrNoDocuments
}
return nil
}
//CountLotteryGifts 统计奖品信息数量
func CountLotteryGifts(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbLotGift.Count(ctx, filter)
if err != nil {
log.Warn("LotteryGift:CountLotteryGifts dbLotGift.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateManyLotteryGift 更新满足条件的奖品信息
func UpdateManyLotteryGift(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbLotGift.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyLotteryGift dbLotGift.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//FindManyLotteryGift 查找一批奖品信息数据
func FindManyLotteryGift(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (LotteryGiftList, error) {
data := make(LotteryGiftList, 0)
if err := dbLotGift.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("LotteryGift:FindManyLotteryGift dbLotGift.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
//FindManyLotteryGiftWithBind 用自己定义结构查找一批奖品信息数据
func FindManyLotteryGiftWithBind(ctx context.Context, bind interface{}, filter bson.M, opts ...*options.FindOptions) error {
if err := dbLotGift.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("LotteryGift:FindManyLotteryGiftWithBind dbLotGift.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//InsertOneLotteryGetGift 插入一个中奖兑换相关信息
func InsertOneLotteryGetGift(ctx context.Context, media *LotteryGetGift) error {
if _, err := dbLotGetGift.InsertOne(ctx, media); err != nil {
log.Warn("activitymod:InsertOneLotteryGetGift dbLotGetGift.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneLotteryGetGift 查找一个中奖兑换相关信息
func FindOneLotteryGetGift(ctx context.Context, filter bson.M) (*LotteryGetGift, error) {
var data LotteryGetGift
if err := dbLotGetGift.FindOneEx(ctx, &data, filter); err != nil {
log.Warn("LotteryGetGift:FindOneLotteryGetGift dbLotGetGift.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &data, nil
}
//DelOneLotteryGetGift 删除一个中奖兑换相关信息
func DelOneLotteryGetGift(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbLotGetGift.DeleteOne(ctx, filter)
if err != nil {
log.Warn("LotteryGetGift:DelOneLotteryGetGift dbLotGetGift.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateOneLotteryGetGift 更新一个中奖兑换相关信息
func UpdateOneLotteryGetGift(ctx context.Context, filter bson.M, update bson.M) error {
result, err := dbLotGetGift.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("UpdateOneLotteryGetGift dbLotGetGift.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
if result.MatchedCount == 0 {
return mongo.ErrNoDocuments
}
return nil
}
//CountLotteryGetGifts 统计中奖兑换相关信息数量
func CountLotteryGetGifts(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbLotGetGift.Count(ctx, filter)
if err != nil {
log.Warn("LotteryGetGift:CountLotteryGetGifts dbLotGetGift.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateManyLotteryGetGift 更新满足条件的中奖兑换相关信息
func UpdateManyLotteryGetGift(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbLotGetGift.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyLotteryGetGift dbLotGetGift.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//FindManyLotteryGetGift 查找一批渠道中奖兑换相关信息
func FindManyLotteryGetGift(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (LotteryGetGiftList, error) {
data := make(LotteryGetGiftList, 0)
if err := dbLotGetGift.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("LotteryGetGift:FindManyLotteryGetGift dbLotGetGift.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
//FindManyLotteryGetGiftWithBind 用自己定义结构查找一批渠道中奖兑换相关信息
func FindManyLotteryGetGiftWithBind(ctx context.Context, bind interface{}, filter bson.M, opts ...*options.FindOptions) error {
if err := dbLotGetGift.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("LotteryGetGift:FindManyLotteryGetGiftWithBind dbLotGetGift.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
+127
View File
@@ -0,0 +1,127 @@
package activitymod
type TagLotteryGift struct {
ActId string
ActName string
CreatedAt string
GiftDesc string
GiftName string
Id string
Rate string
Sort string
UpdatedAt string
}
type TagLotteryGetGift struct {
ActId string
ActName string
AppName string
CreatedAt string
GetGiftAt string
GiftCode string
GiftId string
GiftName string
Id string
IsGaveOut string
IsUsed string
LotteryCode string
Remark string
UpdatedAt string
UserId string
}
type TagActivityInfo struct {
Background string
Banner string
CreatedAt string
Desc string
Enable string
EndTime string
GiftDesc string
H5Domain string
Id string
Name string
SortCode string
StartTime string
UpdatedAt string
}
type TagLottertyCodeInfo struct {
ActId string
ActName string
CreatedAt string
GiftCode string
Id string
IsUsed string
LotteryAt string
LotteryCode string
Remark string
UpdatedAt string
UserIp string
}
var FN struct {
LotteryGift TagLotteryGift
LotteryGetGift TagLotteryGetGift
ActivityInfo TagActivityInfo
LottertyCodeInfo TagLottertyCodeInfo
}
var TN struct {
LotteryGift string
LotteryGetGift string
ActivityInfo string
LottertyCodeInfo string
}
func init() {
FN.LotteryGift.ActId = "actId"
FN.LotteryGift.ActName = "actName"
FN.LotteryGift.CreatedAt = "createdAt"
FN.LotteryGift.GiftDesc = "giftDesc"
FN.LotteryGift.GiftName = "giftName"
FN.LotteryGift.Id = "_id"
FN.LotteryGift.Rate = "rate"
FN.LotteryGift.Sort = "sort"
FN.LotteryGift.UpdatedAt = "updatedAt"
FN.LotteryGetGift.ActId = "actId"
FN.LotteryGetGift.ActName = "actName"
FN.LotteryGetGift.AppName = "appName"
FN.LotteryGetGift.CreatedAt = "createdAt"
FN.LotteryGetGift.GetGiftAt = "getGiftAt"
FN.LotteryGetGift.GiftCode = "giftCode"
FN.LotteryGetGift.GiftId = "giftId"
FN.LotteryGetGift.GiftName = "giftName"
FN.LotteryGetGift.Id = "_id"
FN.LotteryGetGift.IsGaveOut = "isGaveOut"
FN.LotteryGetGift.IsUsed = "isUsed"
FN.LotteryGetGift.LotteryCode = "lotteryCode"
FN.LotteryGetGift.Remark = "remark"
FN.LotteryGetGift.UpdatedAt = "updatedAt"
FN.LotteryGetGift.UserId = "userId"
FN.ActivityInfo.Background = "background"
FN.ActivityInfo.Banner = "banner"
FN.ActivityInfo.CreatedAt = "createdAt"
FN.ActivityInfo.Desc = "desc"
FN.ActivityInfo.Enable = "enable"
FN.ActivityInfo.EndTime = "endTime"
FN.ActivityInfo.GiftDesc = "giftDesc"
FN.ActivityInfo.H5Domain = "h5Domain"
FN.ActivityInfo.Id = "_id"
FN.ActivityInfo.Name = "name"
FN.ActivityInfo.SortCode = "sortCode"
FN.ActivityInfo.StartTime = "startTime"
FN.ActivityInfo.UpdatedAt = "updatedAt"
FN.LottertyCodeInfo.ActId = "actId"
FN.LottertyCodeInfo.ActName = "actName"
FN.LottertyCodeInfo.CreatedAt = "createdAt"
FN.LottertyCodeInfo.GiftCode = "giftCode"
FN.LottertyCodeInfo.Id = "_id"
FN.LottertyCodeInfo.IsUsed = "isUsed"
FN.LottertyCodeInfo.LotteryAt = "lotteryAt"
FN.LottertyCodeInfo.LotteryCode = "lotteryCode"
FN.LottertyCodeInfo.Remark = "remark"
FN.LottertyCodeInfo.UpdatedAt = "updatedAt"
FN.LottertyCodeInfo.UserIp = "userIp"
TN.LotteryGetGift = "lottery_get_gift"
TN.ActivityInfo = "activity_info"
TN.LottertyCodeInfo = "lotterty_code_info"
TN.LotteryGift = "lottery_gift"
}
+88
View File
@@ -0,0 +1,88 @@
package activitymod
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// 活动信息
// @table:activity_info
type ActivityInfo struct {
Id primitive.ObjectID `json:"id" bson:"_id"` // 唯一ID
Name string `json:"name" bson:"name"` // 活动名称
Desc string `json:"desc" bson:"desc"` // 活动说明
SortCode int32 `json:"sortCode" bson:"sortCode"` // 排序号
H5Domain string `json:"h5Domain" bson:"h5Domain"` // 活动H5地址
GiftDesc string `json:"giftDesc" bson:"giftDesc"` // 奖励说明
Enable bool `json:"enable" bson:"enable"` // 活动开关
Background string `json:"background" bson:"background"` // 背景图
StartTime time.Time `json:"startTime" bson:"startTime"` // 活动开始时间
EndTime time.Time `json:"endTime" bson:"endTime"` // 活动结束时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
Banner []BannerInfo `json:"banner" bson:"banner"` // banner列表
}
type BannerInfo struct {
Img string `json:"bannerImg" bson:"bannerImg"` // banner图片
Url string `json:"bannerUrl" bson:"bannerUrl"` // banner跳转地址
}
type ActivityInfoList []*ActivityInfo
// 抽奖码相关信息
// @table:lotterty_code_info
type LottertyCodeInfo struct {
Id primitive.ObjectID `json:"id" bson:"_id"` // 唯一ID
LotteryCode string `json:"lotteryCode" bson:"lotteryCode"` // 抽奖码
ActId string `json:"actId" bson:"actId"` // 所属活动的ID
ActName string `json:"actName" bson:"actName"` // 活动名称
UserIp string `json:"userIp" bson:"userIp"` // 抽奖者IP
Remark string `json:"remark" bson:"remark"` // 备注
IsUsed bool `json:"isUsed" bson:"isUsed"` // 抽奖码是否已使用
GiftCode string `json:"giftCode" bson:"giftCode"` // 奖品兑换码
LotteryAt time.Time `json:"lotteryAt" bson:"lotteryAt"` // 抽奖时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
}
type LottertyCodeInfoList []*LottertyCodeInfo
// 奖品信息
// @table:lottery_gift
type LotteryGift struct {
Id primitive.ObjectID `json:"id" bson:"_id"` // 唯一ID
ActId string `json:"actId" bson:"actId"` // 所属活动的ID
ActName string `json:"actName" bson:"actName"` // 所属活动的名称
GiftName string `json:"giftName" bson:"giftName"` // 奖品名称
GiftDesc string `json:"giftDesc" bson:"giftDesc"` // 奖品描述
Rate int32 `json:"rate" bson:"rate"` // 备注
Sort int32 `json:"sort" bson:"sort"` // 排序
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
}
type LotteryGiftList []*LotteryGift
// 中奖兑换相关信息
// @table:lottery_get_gift
type LotteryGetGift struct {
Id primitive.ObjectID `json:"id" bson:"_id"` // 唯一ID
LotteryCode string `json:"lotteryCode" bson:"lotteryCode"` // 抽奖码
ActId string `json:"actId" bson:"actId"` // 所属活动的ID
ActName string `json:"actName" bson:"actName"` // 所属活动的名称
GiftId string `json:"giftId" bson:"giftId"` // 所属活动奖品的ID
GiftName string `json:"giftName" bson:"giftName"` // 奖品名称
UserId string `json:"userId" bson:"userId"` // 兑换者Id
AppName string `json:"appName" bson:"appName"` // 所属app的名字
Remark string `json:"remark" bson:"remark"` // 备注
IsGaveOut bool `json:"isGaveOut" bson:"isGaveOut"` // 兑换码是否已发放
IsUsed bool `json:"isUsed" bson:"isUsed"` // 奖品兑换码是否已使用
GiftCode string `json:"giftCode" bson:"giftCode"` // 奖品兑换码
GetGiftAt time.Time `json:"getGiftAt" bson:"getGiftAt"` // 兑换奖品的时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
}
type LotteryGetGiftList []*LotteryGetGift
+152
View File
@@ -0,0 +1,152 @@
package adminMod
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"stat/common/utils"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func Init() {
// 获取数据库表
db = mongos.New(mongos.MgoManager, CollAdmin)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: "account", Value: 1}},
Options: options.Index().SetUnique(true),
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollAdmin, err))
}
}
// 根据账号获取管理员信息
func FindOneByAccount(ctx context.Context, account string) (data Admin, err error) {
filter := bson.M{"account": account}
if err = db.FindOne(ctx, &data, filter); err != nil {
log.Error("admin FindOneByAccount err", log.Any("account", account), log.E(err))
return
}
return
}
// FindOnedmin 查找一个渠道信息
func FindOnedmin(ctx context.Context, filter bson.M) (*Admin, error) {
var Admin Admin
if err := db.FindOne(ctx, &Admin, filter); err != nil {
log.Warn("admin:FindOnedmin.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &Admin, nil
}
// 获取管理员列表
func FindAdminList(ctx context.Context, blocRole *int, skip int64, limit int64) (count int64, data []Admin, err error) {
filter := bson.M{}
if blocRole != nil {
filter["blocRole"] = blocRole
}
opts := options.Find().SetSkip(skip).SetLimit(limit)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("admin FindAdminList Find err", log.E(err))
return
}
if count, err = db.Count(ctx, filter); err != nil {
log.Error("admin FindAdminList Count err", log.E(err))
return
}
return
}
// 新增管理员
func AddAdmin(ctx context.Context, doc *Admin) (err error) {
if _, err = db.InsertOne(ctx, doc); err != nil {
log.Error("admin AddAdmin InsertOne err", log.E(err))
return
}
return
}
// 更新管理员
func UpdateAdmin(ctx context.Context, account string, doc UpdateDoc) (err error) {
filter := bson.M{"account": account}
update, _ := utils.ToBsonM(doc)
if _, err = db.UpdateOne(ctx, filter, bson.M{"$set": update}); err != nil {
log.Error("admin UpdateAdmin UpdateOne err", log.E(err))
return
}
return
}
// 删除管理员
func DelAdmin(ctx context.Context, account string) (err error) {
filter := bson.M{"account": account}
if _, err = db.DeleteOne(ctx, filter); err != nil {
log.Error("admin DelAdmin DeleteOne err", log.E(err))
return
}
return
}
// 验证token
func CheckToken(ctx context.Context, token string) (ok bool, err error) {
booToken := Admin{}
if err = db.FindOne(ctx, &booToken, bson.M{"token": token}); err != nil {
log.Error("admin CheckToken FindOne err", log.E(err))
return false, err
}
if booToken.Account == "" {
return false, nil
}
return true, nil
}
// 刷新token
func RefreshToken(ctx context.Context, account string, newToken string) (err error) {
filter := bson.M{"account": account}
update := bson.M{"token": newToken}
if _, err = db.UpdateOne(ctx, filter, bson.M{"$set": update}); err != nil {
log.Error("admin RefreshToken UpdateOne err", log.E(err))
return
}
return
}
// 绑定两步验证
func TwoStepBind(ctx context.Context, account string) (err error) {
filter := bson.M{"account": account}
update := bson.M{"$set": bson.M{"hasBind": true}}
_, err = db.UpdateOne(ctx, filter, update)
return
}
// 设置两步验证密钥
func TwoStepSecretSet(ctx context.Context, account string, secret string) (err error) {
filter := bson.M{"account": account}
update := bson.M{"$set": bson.M{"secret": secret}}
_, err = db.UpdateOne(ctx, filter, update)
return
}
+37
View File
@@ -0,0 +1,37 @@
package adminMod
import (
"stat/common/mongos"
"time"
)
const CollAdmin = "admin"
var db *mongos.MongoTool
type Admin struct {
Account string `bson:"account"` // 用户名
Password string `bson:"password"` // 密码
Name string `bson:"name"` // 名称
RoleId int64 `bson:"roleId"` // 角色id
Token string `bson:"token"` // token
Status int64 `bson:"status"` // 状态
Secret string `bson:"secret"` // 两步验证密钥
HasBind bool `bson:"hasBind"` // 已绑定 true,曾成功登录,反之false
MerchantId string `bson:"MerchantId"` // 商人id
BlocRole int `bson:"blocRole"` // 集团账号
CreatedAt time.Time `bson:"createdAt"` // 创建时间
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
LastTime time.Time `bson:"lastTime"` // 登录时间
}
type UpdateDoc struct {
Account *string `bson:"account,omitempty"` // 用户名
Password *string `bson:"password,omitempty"` // 密码
Name *string `bson:"name,omitempty"` // 名称
RoleId *int64 `bson:"roleId,omitempty"` // 角色
Status *int64 `bson:"status,omitempty"` // 状态
MerchantId *string `bson:"MerchantId,omitempty"` // 商人id
BlocRole *int `bson:"blocRole,omitempty"` // 集团账号
UpdatedAt *time.Time `bson:"updatedAt,omitempty"` // 更新时间
}
+135
View File
@@ -0,0 +1,135 @@
package advertiseLocMod
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"stat/common/utils"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func Init() {
// 获取数据库表
db = mongos.New(mongos.MgoManager, CollAdvertiseLocation)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: "appId", Value: 1}, {Key: "locId", Value: 1}},
Options: options.Index().SetUnique(true),
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollAdvertiseLocation, err))
}
}
// 新增广告位置信息
func AddAdvertiseLocation(ctx context.Context, doc *AdvertiseLocation) (err error) {
if _, err = db.InsertOne(ctx, doc); err != nil {
log.Error("advertise location AddAdvertiseLocation InsertOne err", log.E(err))
return
}
return
}
// 修改广告位置信息就
func UpdateAdvertiseLocation(ctx context.Context, id int64, doc UpdateAdsLoc) (err error) {
filter := bson.M{"_id": id}
update, _ := utils.ToBsonM(doc)
if _, err = db.UpdateOne(ctx, filter, bson.M{"$set": update}); err != nil {
log.Error("advertise location UpdateAdvertiseLocation UpdateOne err", log.E(err))
return
}
return
}
// 删除广告位置信息就
func DelAdvertiseLocation(ctx context.Context, id int64) (err error) {
filter := bson.M{"_id": id}
if _, err = db.DeleteOne(ctx, filter); err != nil {
log.Error("advertise location DelAdvertiseLocation UpdateOne err", log.E(err))
return
}
return
}
// 删除广告位置信息就
func FindAdvertiseLocationList(ctx context.Context, appId *int32, skip, limit int64) (count int64, data []AdvertiseLocation, err error) {
filter := bson.M{}
if appId != nil {
filter["appId"] = appId
}
sort := bson.D{{Key: "createdAt", Value: -1}}
opts := options.Find().SetSort(sort).SetSkip(skip).SetLimit(limit)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("advertise location FindAdvertiseLocationList Find err", log.E(err))
return
}
if count, err = db.Count(ctx, filter); err != nil {
log.Error("advertise location FindAdvertiseLocationList Count err", log.E(err))
return
}
return
}
// 根据应用id和位置id获取广告位置
func FindLocationByAppIdAndLocId(ctx context.Context, appId, locId int32) (data AdvertiseLocation, err error) {
filter := bson.M{"appId": appId, "locId": locId}
if err = db.FindOne(ctx, &data, filter); err != nil {
log.Error("advertise location FindLocationByAppIdAndLocId FindOne err", log.E(err))
return
}
return
}
// 根据id获取广告位置
func FindLocationById(ctx context.Context, id int64) (data AdvertiseLocation, err error) {
filter := bson.M{"_id": id}
if err = db.FindOne(ctx, &data, filter); err != nil {
log.Error("advertise location FindLocationById FindOne err", log.E(err))
return
}
return
}
// GetAllAdvertiseLocationMap 获取 map[appId]map[locId]*AdvertiseLocation
func GetAllAdvertiseLocationMap(ctx context.Context, filter bson.M) (map[int32]map[int32]*AdvertiseLocation, error) {
dict := make(map[int32]map[int32]*AdvertiseLocation)
list := make([]*AdvertiseLocation, 0)
if err := db.Find(ctx, &list, filter); err != nil {
log.Error("AdvertiseLocation GetAllAdvertiseMap Find err", log.E(err))
return dict, err
}
for _, loc := range list {
m := dict[loc.AppId]
if m == nil {
m = make(map[int32]*AdvertiseLocation)
m[loc.LocId] = loc
dict[loc.AppId] = m
} else {
m[loc.LocId] = loc
}
}
return dict, nil
}
+30
View File
@@ -0,0 +1,30 @@
package advertiseLocMod
import (
"stat/common/mongos"
"time"
)
const CollAdvertiseLocation = "advertise_location"
var db *mongos.MongoTool
type AdvertiseLocation struct {
Id int64 `bson:"_id"` // 唯一id
AppId int32 `bson:"appId"` // 应用id
LocId int32 `bson:"locId"` // 位置id,外部使用的id,方便app配置
Name string `bson:"name"` // 位置名称
ImgSizeDesc string `bson:"imgSizeDesc"` // 该位置图片描述
Remark string `bson:"remark"` // 备注
CreatedAt time.Time `bson:"createAt"` // 创建时间
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
}
type UpdateAdsLoc struct {
AppId *int32 `bson:"appId,omitempty"` // 应用id
LocId *int32 `bson:"locId,omitempty"` // 位置id,外部使用的id,方便app配置
Name *string `bson:"name,omitempty"` // 位置名称
ImgSizeDesc *string `bson:"imgSizeDesc,omitempty"` // 该位置图片描述
Remark *string `bson:"remark,omitempty"` // 备注
UpdatedAt *time.Time `bson:"updatedAt,omitempty"` // 更新时间
}
+220
View File
@@ -0,0 +1,220 @@
package advertiseMod
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"stat/common/stdLog"
"stat/common/utils"
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func Init() {
// 获取数据库表
db = mongos.New(mongos.MgoManager, CollAdvertise)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: "appId", Value: 1}},
},
{
Keys: bson.D{{Key: "appId", Value: 1}, {Key: "isActive", Value: 1}, {Key: "startTime", Value: 1}, {Key: "endTime", Value: 1}},
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollAdvertise, err))
}
}
// 新增广告
func AddAdvertise(ctx context.Context, doc *Advertise) (err error) {
if _, err = db.InsertOne(ctx, doc); err != nil {
log.Error("advertise AddAdvertise InsertOne err", log.E(err))
return
}
return
}
// 修改广告
func UpdateAdvertise(ctx context.Context, id int64, doc UpdateAds) (err error) {
filter := bson.M{"_id": id}
update, _ := utils.ToBsonM(doc)
if _, err = db.UpdateOne(ctx, filter, bson.M{"$set": update}); err != nil {
log.Error("advertise UpdateAdvertise UpdateOne err", log.E(err))
return
}
return
}
// 删除广告
func DelAdvertise(ctx context.Context, id int64) (err error) {
filter := bson.M{"_id": id}
if _, err = db.DeleteOne(ctx, filter); err != nil {
log.Error("advertise DelAdvertise DeleteOne err", log.E(err))
return
}
return
}
func FindAdvertiseList(ctx context.Context, appId *int32, isActive *bool, locId *int32, skip, limit int64,
link, title, daoLiangTitle *string) (count int64, data []Advertise, err error) {
filter := bson.M{}
if appId != nil {
filter["appId"] = appId
}
if isActive != nil {
filter["isActive"] = isActive
}
if locId != nil {
filter["locId"] = *locId
}
if link != nil {
filter["links"] = bson.M{"$elemMatch": bson.M{"link": *link}}
}
if title != nil {
filter["title"] = bson.M{"$regex": *title}
}
if daoLiangTitle != nil {
filter["daoLiangTitle"] = bson.M{"$regex": *daoLiangTitle}
}
sort := bson.D{{Key: "sort", Value: 1}}
opts := options.Find().SetSort(sort).SetSkip(skip).SetLimit(limit)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("advertise FindAdvertiseList Find err", log.E(err))
return
}
if count, err = db.Count(ctx, filter); err != nil {
log.Error("advertise FindAdvertiseList Count err", log.E(err))
return
}
return
}
// 根据appId和locId更新位置id
func UpdateLocInfo(ctx context.Context, appId, oldLocId, newLocID int32) (err error) {
filter := bson.M{"appId": appId, "locId": oldLocId}
update := bson.M{"$set": bson.M{"locId": newLocID}}
if _, err = db.UpdateMany(ctx, filter, update); err != nil {
log.Error("advertise UpdateLocInfo UpdateMany err", log.E(err))
return
}
return
}
// 根据app和位置获取广告
func FindAdsByAppAndLocation(ctx context.Context, appId int32, locId *int32) (data []Advertise, err error) {
now := time.Now()
filter := bson.M{"appId": appId, "isActive": true, "startTime": bson.M{"$lt": now}, "endTime": bson.M{"$gte": now}}
if locId != nil {
filter["locId"] = locId
}
sort := bson.D{{Key: "sort", Value: 1}}
opts := options.Find().SetSort(sort)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("advertise FindAdsByAppAndLocation Find err", log.E(err))
return
}
return
}
// 根据app和位置获取广告
func FindAdsById(ctx context.Context, id int64) (data Advertise, err error) {
filter := bson.M{"_id": id}
if err = db.FindOne(ctx, &data, filter); err != nil {
log.Error("advertise FindAdsById FindOne err", log.E(err))
return
}
return
}
// 增加广告点击量
func IncAdsClickCount(ctx context.Context, id int64) (err error) {
filter := bson.M{"_id": id}
update := bson.M{"$inc": bson.M{"clickCount": 1}}
if _, err = db.UpdateOne(ctx, filter, update); err != nil {
log.Error("advertise IncAdsClickCount UpdateOne err", log.E(err))
return
}
return
}
// FindAds 根据app和位置获取广告
func FindAds(ctx context.Context) (data []Advertise, err error) {
filter := bson.M{}
sort := bson.D{{Key: "sort", Value: 1}}
opts := options.Find().SetSort(sort)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("advertise FindAdsByAppAndLocation Find err", log.E(err))
return
}
return
}
// FindOneAdvertise 查找一个应用
func FindOneAdvertise(ctx context.Context, filter bson.M) (
*Advertise, error) {
var advertise Advertise
if err := db.FindOneEx(ctx, &advertise, filter); err != nil {
return nil, err
}
return &advertise, nil
}
// GetAllAdvertiseMap 获取ads id map
func GetAllAdvertiseMap(ctx context.Context, filter bson.M) (map[int64]*Advertise, error) {
dict := make(map[int64]*Advertise)
list := make([]*Advertise, 0)
if err := db.Find(ctx, &list, filter); err != nil {
log.Error("Advertise GetAllAdvertiseMap Find err", log.E(err))
return dict, err
}
for _, ads := range list {
dict[ads.Id] = ads
}
return dict, nil
}
// FindAds 根据app和位置获取广告
func FindAdvertiselist(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (data []Advertise, serr *stdLog.SrvErr) {
if err := db.Find(ctx, &data, filter, opts...); err != nil {
if err != mongo.ErrNoDocuments {
log.Error("advertise FindAdvertiselist err", log.E(err))
return nil, stdLog.New(stdLog.DataEmpty, "", err.Error())
}
log.Error("advertise FindAdvertiselist Find err", log.E(err))
return nil, stdLog.New(stdLog.QueryDataError, "", err.Error())
}
return
}
+67
View File
@@ -0,0 +1,67 @@
package advertiseMod
import (
"stat/common/mongos"
"time"
)
const CollAdvertise = "advertise"
var db *mongos.MongoTool
type JumpType = int64
const (
JumpTypeOutsideBrowser JumpType = iota // 0:外部浏览器跳转
JumpTypeInsideBrowser // 1:内部浏览器跳转
JumpTypeInsideApp // 2:app内部跳转
)
type LinkInfo struct {
Link string `bson:"link"` // 链接地址
Foreign bool `bson:"foreign"` // true 国外用户
Weight int `bson:"weight"` // 权重
}
type Advertise struct {
Id int64 `bson:"_id"` // 广告id
AppId int32 `bson:"appId"` // 应用id
LocId int32 `bson:"locId"` // 位置id
Title string `bson:"title"` // 广告标题
DaoLiangTitle string `bson:"daoLiangTitle"` // 广告导量标题
Tags string `bson:"tags"` // 广告标签
CoverImg string `bson:"coverImg"` // 封面
VisibleChannels []string `bson:"visibleChannels"` // 可见的渠道
JumpType JumpType `bson:"jumpType"` // 跳转方式
Link string `bson:"link"` // 链接
Links []LinkInfo `bson:"links"` // 链接地址
Sort int64 `bson:"sort"` // 排序值--优先级
IsActive bool `bson:"isActive"` // 是否激活
StartTime time.Time `bson:"startTime"` // 开始时间
EndTime time.Time `bson:"endTime"` // 结束时间
Remark string `bson:"remark"` // 备注
ClickCount int64 `bson:"clickCount"` // 点击次数
AmbientColor string `bson:"ambientColor"` // 氛围色(逼哩漫画)
CreatedAt time.Time `bson:"createAt"` // 创建时间
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
}
type UpdateAds struct {
AppId *int32 `bson:"appId,omitempty"` // 应用id
LocId *int32 `bson:"locId,omitempty"` // 位置id
Title *string `bson:"title,omitempty"` // 广告标题
DaoLiangTitle *string `bson:"daoLiangTitle,omitempty"` // 广告导量标题
Tags *string `bson:"tags,omitempty"` // 广告标签
CoverImg *string `bson:"coverImg,omitempty"` // 封面
VisibleChannels *[]string `bson:"visibleChannels,omitempty"` // 可见的渠道
Location *int64 `bson:"location,omitempty"` // 位置
JumpType *JumpType `bson:"jumpType,omitempty"` // 跳转方式
Links *[]LinkInfo `bson:"links,omitempty"` // 链接地址
Sort *int64 `bson:"sort,omitempty"` // 排序值--优先级
IsActive *bool `bson:"isActive,omitempty"` // 是否激活
StartTime *time.Time `bson:"startTime,omitempty"` // 开始时间
EndTime *time.Time `bson:"endTime,omitempty"` // 结束时间
Remark *string `bson:"remark,omitempty"` // 备注
AmbientColor *string `bson:"ambientColor"` // 氛围色(逼哩漫画)
UpdatedAt *time.Time `bson:"updatedAt,omitempty"` // 更新时间
}
+149
View File
@@ -0,0 +1,149 @@
package advertisestat
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"stat/common/stdLog"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
// 表名
var db *mongos.MongoTool
func Init() {
// 获取数据库表
db = mongos.New(mongos.MgoManager, TN.AdvertiseStat)
// 获取数据库表
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.AdvertiseStat.AdsId, Value: 1},
{Key: FN.AdvertiseStat.SumData, Value: -1},
},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{
{Key: FN.AdvertiseStat.Id, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.AdvertiseStat.AppId, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.AdvertiseStat.SumData, Value: -1},
},
},
{
Keys: bson.D{
{Key: FN.AdvertiseStat.Total, Value: -1},
},
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("(media:initAdvertiseStatIndex) Create AdvertiseStat Index failed! err:%+v:", err))
}
}
// InsertOneAdvertiseStat 插入一个广告统计
func InsertOneAdvertiseStat(ctx context.Context, applicationStat *AdvertiseStat) error {
if _, err := db.InsertOne(ctx, applicationStat); err != nil {
log.Warn("media:InsertOneAdvertiseStat db.InsertOne failed", log.E(err))
return err
}
return nil
}
// DelOneAdvertiseStat 删除一个广告统计tag
func DelOneAdvertiseStat(ctx context.Context, filter bson.M) (int64, error) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("media:DelOneAdvertiseStat db.DeleteOne failed", log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// FindOneAdvertiseStat 查找一个广告统计
func FindOneAdvertiseStat(ctx context.Context, filter bson.M) (*AdvertiseStat, error) {
var applicationStat AdvertiseStat
if err := db.FindOneEx(ctx, &applicationStat, filter); err != nil { //mongo.ErrNoDocuments
return nil, err
}
return &applicationStat, nil
}
// CountAdvertiseStats 统计广告统计数量
func CountAdvertiseStats(ctx context.Context, filter bson.M) (int64, error) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("media:CountAdvertiseStats db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateOneAdvertiseStat 更新一个广告统计
func UpdateOneAdvertiseStat(ctx context.Context, filter bson.M, update bson.M) error {
result, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("media:UpdateOneAdvertiseStat db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
if result.MatchedCount != 1 {
log.Warn("media:UpdateOneAdvertiseStat db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return mongo.ErrNoDocuments
}
return nil
}
// UpdateManyAdvertiseStat 更新一批广告统计
func UpdateManyAdvertiseStat(ctx context.Context, filter bson.M, update bson.M) error {
result, err := db.UpdateMMany(ctx, filter, update)
if err != nil {
log.Warn("media:UpdateManyAdvertiseStat db.UpdateMMany failed",
log.E(err), log.Any("filter", filter))
return err
}
if result.MatchedCount <= 0 {
log.Warn("media:UpdateManyAdvertiseStat db.UpdateMMany failed",
log.E(err), log.Any("filter", filter))
//return srvdef.New(srvdef.ErrApplicationNotExsit, "", "")
}
return nil
}
// AggregateTopicInfos 聚合查找一批用户信息
func AggregateAdvertiseStat(ctx context.Context,
bind interface{}, pipeline []bson.M) *stdLog.SrvErr {
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("feedback:AggregateAdvertiseStat db.Aggregate failed",
log.E(err), log.Any("pipeline", pipeline))
return stdLog.New(stdLog.QueryDataError, "", err.Error())
}
return nil
}
// FindManyAdvertiseStat 查找一批广告统计
func FindManyAdvertiseStat(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (AdvertiseStatList, error) {
data := make(AdvertiseStatList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("media:FindManyAdvertiseStat db.Find failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
+32
View File
@@ -0,0 +1,32 @@
package advertisestat
type TagAdvertiseStat struct {
Id string
AdsId string
AppId string
SumData string
Total string
HourData string
CreatedAt string
UpdatedAt string
}
var FN struct {
AdvertiseStat TagAdvertiseStat
}
var TN struct {
AdvertiseStat string
}
func init() {
FN.AdvertiseStat.Id = "_id"
FN.AdvertiseStat.AdsId = "adsId"
FN.AdvertiseStat.AppId = "appId"
FN.AdvertiseStat.SumData = "sumDate"
FN.AdvertiseStat.Total = "total"
FN.AdvertiseStat.HourData = "hourData"
FN.AdvertiseStat.CreatedAt = "createdAt"
FN.AdvertiseStat.UpdatedAt = "updatedAt"
TN.AdvertiseStat = "advertisestat"
}
+40
View File
@@ -0,0 +1,40 @@
package advertisestat
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
const ColladvertiseStat = "advertisestat"
type THourStat map[int]int64
func (m THourStat) Total() int64 {
var sum int64
for _, v := range m {
sum += v
}
return sum
}
type Update struct {
Total *int64 `json:"total" bson:"total,omitempty"` //今日点击
HourData *THourStat `json:"hourData" bson:"hourData,omitempty"` //小时数据
UpdatedAt *time.Time `json:"updatedAt" bson:"updatedAt,omitempty"` //更新时间
}
// 应用统计
// @table:advertisejob
type AdvertiseStat struct {
Id primitive.ObjectID `json:"id" bson:"_id,omitempty"`
AdsId int64 `json:"adsId" bson:"adsId"` //广告ID
AppId int32 `json:"appId" bson:"appId"` //应用ID
SumDate time.Time `json:"sumDate" bson:"sumDate"` //记录时间
Total int64 `json:"total" bson:"total"` //今日点击
HourData THourStat `json:"hourData" bson:"hourData"` //小时数据
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` //创建时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` //更新时间
}
type AdvertiseStatList []*AdvertiseStat
+121
View File
@@ -0,0 +1,121 @@
package announInfoMod
import (
"context"
"fmt"
"go.mongodb.org/mongo-driver/bson/primitive"
"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"
)
func Init() {
// 获取数据库表
db = mongos.New(mongos.MgoManager, CollAnnounInfo)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: "appId", Value: 1}},
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollAnnounInfo, err))
}
}
// 获取公告列表
func FindAnnounceList(ctx context.Context, appId *int32, skip int64, limit int64) (count int64, data []AnnounInfo, err error) {
filter := bson.M{}
if appId != nil {
filter["appId"] = appId
}
opts := options.Find().SetSkip(skip).SetLimit(limit)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("announce FindAnnounceList Find err", log.E(err))
return
}
if count, err = db.Count(ctx, filter); err != nil {
log.Error("announce FindAnnounceList Count err", log.E(err))
return
}
return
}
// 新增管理员
func AddAnnounce(ctx context.Context, doc *AnnounInfo) (err error) {
if _, err = db.InsertOne(ctx, doc); err != nil {
log.Error("announce AddAnnounce InsertOne err", log.E(err))
return
}
return
}
// 更新管理员
func UpdateAnnounce(ctx context.Context, id string, doc UpdateDoc) (err error) {
if id == "" {
return
}
objId, err := primitive.ObjectIDFromHex(id)
if err != nil {
log.Error("announce UpdateAnnounce ObjectIDFromHex err", log.E(err))
return
}
filter := bson.M{"_id": objId}
update, _ := utils.ToBsonM(doc)
if _, err = db.UpdateOne(ctx, filter, bson.M{"$set": update}); err != nil {
log.Error("announce UpdateAdmin UpdateOne err", log.E(err))
return
}
return
}
// 删除管理员
func DelAnnounce(ctx context.Context, id string) (err error) {
if id == "" {
return
}
objId, err := primitive.ObjectIDFromHex(id)
if err != nil {
log.Error("announce DelAnnounce ObjectIDFromHex err", log.E(err))
return
}
filter := bson.M{"_id": objId}
if _, err = db.DeleteOne(ctx, filter); err != nil {
log.Error("announce DelAnnounce DeleteOne err", log.E(err))
return
}
return
}
// 根据appId获取公告
func FindAnnounceByAppId(ctx context.Context, appId int32) (data []AnnounInfo, err error) {
now := time.Now()
filer := bson.M{"appId": appId, "startTime": bson.M{"$lt": now}, "endTime": bson.M{"$gt": now}}
if err = db.Find(ctx, &data, filer); err != nil {
log.Error("announce DelAnnounce DeleteOne err", log.E(err))
return
}
return
}
+36
View File
@@ -0,0 +1,36 @@
package announInfoMod
import (
"go.mongodb.org/mongo-driver/bson/primitive"
"stat/common/mongos"
"time"
)
const CollAnnounInfo = "announ_info"
var db *mongos.MongoTool
type AnnounInfo struct {
ID primitive.ObjectID `bson:"_id,omitempty"` // 公告id
AppId int32 `bson:"appId"` // 应用id
Title string `bson:"title"` // 公告标题
Content string `bson:"content"` // 公告内容
Cover string `bson:"cover"` // 公告封面图
Href string `bson:"href"` // 公告跳转地址
Type int `bson:"type"` // 公告类型 0,外部连接;1,直接安装app
Active bool `bson:"active"` // 是否激活
StartTime time.Time `bson:"startTime"` // 开始时间
EndTime time.Time `bson:"endTime"` // 结束时间
}
type UpdateDoc struct {
AppId *int32 `bson:"appId,omitempty"` // 应用id
Title *string `bson:"title,omitempty"` // 公告标题
Content *string `bson:"content,omitempty"` // 公告内容
Cover *string `bson:"cover,omitempty"` // 公告封面图
Href *string `bson:"href,omitempty"` // 公告跳转地址
Type *int `bson:"type,omitempty"` // 公告类型 0,外部连接;1,直接安装app
Active *bool `bson:"active,omitempty"` // 是否激活
StartTime *time.Time `bson:"startTime,omitempty"` // 开始时间
EndTime *time.Time `bson:"endTime,omitempty"` // 结束时间
}
+219
View File
@@ -0,0 +1,219 @@
package appInfoMod
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"stat/common/stdLog"
"stat/common/utils"
"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, CollAppInfo)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: "appId", Value: 1}},
Options: options.Index().SetUnique(true),
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", CollAppInfo, err))
}
}
// 添加渠道
func AddAppInfo(ctx context.Context, doc *AppInfo) (err error) {
if _, err = db.InsertOne(ctx, doc); err != nil {
log.Error("appInfo AddAppInfo InsertOne err", log.E(err))
return
}
return
}
// 修改app信息
func UpdateAppInfo(ctx context.Context, appId int32, doc AppInfoUpdate) (err error) {
filter := bson.M{"appId": appId}
update, _ := utils.ToBsonM(doc)
if _, err = db.UpdateOne(ctx, filter, bson.M{"$set": update}); err != nil {
log.Error("appInfo UpdateAppInfo UpdateOne err", log.Any("appId", appId), log.E(err))
return
}
return
}
// 删除app信息
func DelAppInfo(ctx context.Context, appId int32) (err error) {
filter := bson.M{"appId": appId}
if _, err = db.DeleteOne(ctx, filter); err != nil {
log.Error("appInfo DelAppInfo DeleteOne err", log.Any("appId", appId), log.E(err))
return
}
return
}
// 根据appId 获取appInfo
func GetAppInfoById(ctx context.Context, appId int32) (data AppInfo, err error) {
filter := bson.M{"appId": appId}
if err = db.FindOne(ctx, &data, filter); err != nil {
log.Error("appInfo GetAppInfoById FindOne err", log.Any("appId", appId), log.E(err))
return
}
return
}
// 根据appId 获取appInfo
func GetAppInfoByIdEx(ctx context.Context, appId int32) (*AppInfo, error) {
var err error
app := AppInfo{}
if err = db.FindOneEx(ctx, &app, bson.M{"appId": appId}); err != nil {
log.Error("appInfo GetAppInfoByIdEx FindOneEx err", log.Any("appId", appId), log.E(err))
return nil, err
}
return &app, nil
}
// 获取app列表
func GetAppInfoList(ctx context.Context, appName *string, used *bool, skip, limit int64) (count int64, data []AppInfo, err error) {
filter := bson.M{}
/*if used == nil {
filter["used"] = true
}
*/
if appName != nil {
filter["name"] = bson.M{"$regex": fmt.Sprintf("^%s", *appName)}
}
opts := options.Find().SetSkip(skip).SetLimit(limit)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("appInfo GetAppInfoList Find err", log.E(err))
return
}
if count, err = db.Count(ctx, filter); err != nil {
log.Error("appInfo GetAppInfoList Count err", log.E(err))
return
}
return
}
// 获取app根据appIds
func GetAppInfosByAppIds(ctx context.Context, appIds []int32) (data []AppInfo, err error) {
if len(appIds) == 0 {
return
}
filter := bson.M{"appId": bson.M{"$in": appIds}}
if err = db.Find(ctx, &data, filter); err != nil {
log.Error("appInfo GetAppInfosByAppIds Find err", log.Any("appIds", appIds), log.E(err))
return
}
return
}
// 获取app ID列表
func GetAppIds(ctx context.Context) (ids []int32, err error) {
filter := bson.M{
"used": true,
}
data := make([]AppInfo, 0)
if err = db.Find(ctx, &data, filter); err != nil {
log.Error("appInfo GetAppIds Find err", log.E(err))
return
}
ids = make([]int32, 0)
for _, v := range data {
ids = append(ids, v.AppId)
}
return
}
// 获取app ID列表
func GetAllAppInfo(ctx context.Context) (data []AppInfo, err error) {
filter := bson.M{}
if err = db.Find(ctx, &data, filter); err != nil {
log.Error("appInfo GetAppIds Find err", log.E(err))
return
}
return
}
// 获取app ID列表
func GetAllAppInfoEx(ctx context.Context) (data []*AppInfo, err error) {
filter := bson.M{}
if err = db.Find(ctx, &data, filter); err != nil {
log.Error("appInfo GetAppIds Find err", log.E(err))
return
}
return
}
// 获取app ID列表
func GetAllAppIdMap(ctx context.Context, filter bson.M) (map[int32]*AppInfo, error) {
dict := make(map[int32]*AppInfo)
apps := make([]*AppInfo, 0)
if err := db.Find(ctx, &apps, filter); err != nil {
log.Error("appInfo GetAppIds Find err", log.E(err))
return dict, err
}
for _, app := range apps {
dict[app.AppId] = app
}
return dict, nil
}
// FindOneApplication 查找一个应用
func FindOneApplication(ctx context.Context, filter bson.M) (
*AppInfo, *stdLog.SrvErr) {
var Application AppInfo
if err := db.FindOneEx(
ctx, &Application, filter); err != nil {
if err != mongo.ErrNoDocuments {
log.Info("appinfo:FindOneApplication db.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, stdLog.New(stdLog.QueryDataError, "", "")
}
return nil, stdLog.New(stdLog.ErrApplicationNotExist, "", "")
}
return &Application, nil
}
// 获取app ID-Name列表
func GetAllAppIdNameMap(ctx context.Context) (map[int32]string, error) {
filter := bson.M{}
dict := make(map[int32]string)
apps := make([]*AppInfo, 0)
if err := db.Find(ctx, &apps, filter); err != nil {
log.Error("appInfo GetAppIds Find err", log.E(err))
return dict, err
}
for _, app := range apps {
dict[app.AppId] = app.Name
}
return dict, nil
}
+5
View File
@@ -0,0 +1,5 @@
package appInfoMod
//type DateMonitor struct {
// NewAdd
//}
+34
View File
@@ -0,0 +1,34 @@
package appInfoMod
type TagAppInfo struct {
AppId string
Name string
LandPages string
IconImg string
Used string
AdvertiseNum string
AdvertiseNewNum string
CreatedAt string
UpdatedAt string
}
var FN struct {
AppInfo TagAppInfo
}
var TN struct {
AppInfo string
}
func init() {
FN.AppInfo.AppId = "appId"
FN.AppInfo.Name = "name"
FN.AppInfo.LandPages = "landPages"
FN.AppInfo.IconImg = "iconImg"
FN.AppInfo.Used = "used"
FN.AppInfo.AdvertiseNum = "advertiseNum"
FN.AppInfo.AdvertiseNewNum = "advertiseNewNum"
FN.AppInfo.CreatedAt = "createdAt"
FN.AppInfo.UpdatedAt = "updatedAt"
TN.AppInfo = CollAppInfo
}
+34
View File
@@ -0,0 +1,34 @@
package appInfoMod
import (
"stat/common/mongos"
"time"
)
// 表名
const CollAppInfo = "app_info"
var db *mongos.MongoTool
type AppInfo struct {
AppId int32 `bson:"appId"` // appId,唯一id
Name string `bson:"name"` // app名称
LandPages []string `bson:"landPages"` // 落地页列表
IconImg string `bson:"iconImg"` // 图标
Used bool `bson:"used"` // 是否正在使用
AdvertiseNum int64 `bson:"advertiseNum"` // 广告系数
AdvertiseNewNum int64 `bson:"advertiseNewNum"` // 广告新增系数
CreatedAt time.Time `bson:"createdAt"` // 创建时间
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
}
type AppInfoList []*AppInfo
type AppInfoUpdate struct {
Name *string `bson:"name,omitempty"` // app名称
IconImg *string `bson:"iconImg,omitempty"` // 图标
LandPages *[]string `bson:"landPages,omitempty"` // 落地页列表
AdvertiseNum *int64 `bson:"advertiseNum,omitempty"` // 广告系数
AdvertiseNewNum *int64 `bson:"advertiseNewNum,omitempty"` // 广告新增系数
UpdatedAt *time.Time `bson:"updatedAt,omitempty"` // 更新时间
}
+141
View File
@@ -0,0 +1,141 @@
package appcategory
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"stat/common/stdLog"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
// 表名
const Collappcategory = "appcategory"
var db *mongos.MongoTool
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.New(mongos.MgoManager, Collappcategory)
// 获取数据库表
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: "parentAppId", Value: 1},
},
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(media:initCategoryIndex) Create AppCategory Index failed! err:%+v:", err))
}
}
// InsertOneAppCategory 插入一个应用
func InsertOneAppCategory(ctx context.Context, Category *AppCategory) *stdLog.SrvErr {
if _, err := db.InsertOne(ctx, Category); err != nil {
log.Warn("media:InsertOneAppCategory db.InsertOne failed", log.E(err))
return stdLog.New(stdLog.InsertDataError, "", "")
}
return nil
}
// DelOneAppCategory 删除一个应用tag
func DelOneAppCategory(ctx context.Context, filter bson.M) (
int64, *stdLog.SrvErr) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("media:DelOneAppCategory db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, stdLog.New(stdLog.DelDataError, "", "")
}
return count, nil
}
// FindOneAppCategory 查找一个应用
func FindOneAppCategory(ctx context.Context, filter bson.M) (
*AppCategory, *stdLog.SrvErr) {
var Category AppCategory
if err := db.FindOneEx(
ctx, &Category, filter); err != nil {
if err != mongo.ErrNoDocuments {
log.Info("media:FindOneAppCategory db.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, stdLog.New(stdLog.QueryDataError, "", "")
}
return nil, stdLog.New(stdLog.DataNotExist, "", "")
}
return &Category, nil
}
// CountAppCategories 统计应用数量
func CountAppCategories(ctx context.Context, filter bson.M) (
int64, *stdLog.SrvErr) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("media:CountAppCategories db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, stdLog.New(stdLog.QueryDataError, "", "")
}
return count, nil
}
// UpdateOneAppCategory 更新一个应用
func UpdateOneAppCategory(ctx context.Context, filter bson.M, update bson.M) *stdLog.SrvErr {
result, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("media:UpdateOneAppCategory db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return stdLog.New(stdLog.UpdateDataError, "", "")
}
if result.MatchedCount != 1 {
log.Warn("media:UpdateOneAppCategory db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return stdLog.New(stdLog.DataNotExist, "", "")
}
return nil
}
// UpdateManyAppCategory 更新一批应用
func UpdateManyAppCategory(ctx context.Context, filter bson.M, update bson.M) *stdLog.SrvErr {
result, err := db.UpdateMMany(ctx, filter, update)
if err != nil {
log.Warn("media:UpdateManyAppCategory db.UpdateMMany failed",
log.E(err), log.Any("filter", filter))
return stdLog.New(stdLog.UpdateDataError, "", "")
}
if result.MatchedCount <= 0 {
log.Warn("media:UpdateManyAppCategory db.UpdateMMany failed",
log.E(err), log.Any("filter", filter))
//return srvdef.New(srvdef.ErrCategoryNotExsit, "", "")
}
return nil
}
// FindManyAppCategory 查找一批应用
func FindManyAppCategory(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (AppCategoryList, *stdLog.SrvErr) {
data := make(AppCategoryList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("media:FindManyAppCategory db.Find failed",
log.E(err), log.Any("filter", filter))
return nil, stdLog.New(stdLog.QueryDataError, "", "")
}
return data, nil
}
// GetAppCategoryIdNameMap 查找一批应用
func GetAppCategoryIdNameMap(ctx context.Context) (map[int64]*AppCategory, *stdLog.SrvErr) {
list := make(AppCategoryList, 0)
if err := db.Find(ctx, &list, bson.M{}); err != nil {
log.Warn("media:GetAppCategoryIdNameMap db.Find failed", log.E(err))
return nil, stdLog.New(stdLog.QueryDataError, "", "")
}
dict := make(map[int64]*AppCategory)
for _, item := range list {
dict[item.Id] = item
}
return dict, nil
}
+21
View File
@@ -0,0 +1,21 @@
package appcategory
import (
"time"
)
// 应用中心
// @table:appcategory
type AppCategory struct {
Id int64 `json:"id" bson:"_id,omitempty"`
ParentAppId int64 `json:"parentAppId" bson:"parentAppId"` // parentAppId
Name string `json:"name" bson:"name"` // 名称
Desc string `json:"desc" bson:"desc"` // 描述
Status bool `json:"status" bson:"status"` // 状态
Rank int64 `json:"rank" bson:"rank"` // 应用排序
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
ImgType int64 `json:"imgType" bson:"imgType"` // 图片展示类型 0:应用图标 1.小图标 2.大图标
}
type AppCategoryList []*AppCategory
+163
View File
@@ -0,0 +1,163 @@
package applicationLocMod
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"stat/common/stdLog"
"stat/common/utils"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.New(mongos.MgoManager, CollApplicationLocation)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: "appId", Value: 1}, {Key: "locId", Value: 1}},
Options: options.Index().SetUnique(true),
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollApplicationLocation, err))
}
}
// 新增广告位置信息
func AddApplicationLocation(ctx context.Context, doc *ApplicationLocation) (err error) {
if _, err = db.InsertOne(ctx, doc); err != nil {
log.Error("application location AddApplicationLocation InsertOne err", log.E(err))
return
}
return
}
// 修改广告位置信息就
func UpdateApplicationLocation(ctx context.Context, id int64, doc UpdateAppLoc) (err error) {
filter := bson.M{"_id": id}
update, _ := utils.ToBsonM(doc)
if _, err = db.UpdateOne(ctx, filter, bson.M{"$set": update}); err != nil {
log.Error("application location UpdateApplicationLocation UpdateOne err", log.E(err))
return
}
return
}
// 删除广告位置信息就
func DelApplicationLocation(ctx context.Context, id int64) (err error) {
filter := bson.M{"_id": id}
if _, err = db.DeleteOne(ctx, filter); err != nil {
log.Error("application location DelApplicationLocation UpdateOne err", log.E(err))
return
}
return
}
// 删除广告位置信息就
func FindApplicationLocationList(ctx context.Context, appId *int32, skip, limit int64) (count int64, data []ApplicationLocation, err error) {
filter := bson.M{}
if appId != nil {
filter["appId"] = appId
}
sort := bson.D{{Key: "createdAt", Value: -1}}
opts := options.Find().SetSort(sort).SetSkip(skip).SetLimit(limit)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("application location FindApplicationLocationList Find err", log.E(err))
return
}
if count, err = db.Count(ctx, filter); err != nil {
log.Error("application location FindApplicationLocationList Count err", log.E(err))
return
}
return
}
// 根据应用id和位置id获取广告位置
func FindLocationByAppIdAndLocId(ctx context.Context, appId, locId int32) (data ApplicationLocation, err error) {
filter := bson.M{"appId": appId, "locId": locId}
if err = db.FindOne(ctx, &data, filter); err != nil {
log.Error("application location FindLocationByAppIdAndLocId FindOne err", log.E(err))
return
}
return
}
// 根据id获取广告位置
func FindLocationById(ctx context.Context, id int64) (data ApplicationLocation, err error) {
filter := bson.M{"_id": id}
if err = db.FindOne(ctx, &data, filter); err != nil {
log.Error("application location FindLocationById FindOne err", log.E(err))
return
}
return
}
// GetAllApplicationLocationMap 获取 map[appId]map[locId]*ApplicationLocation
func GetAllApplicationLocationMap(ctx context.Context, filter bson.M) (map[int32]map[int32]*ApplicationLocation, error) {
dict := make(map[int32]map[int32]*ApplicationLocation)
list := make([]*ApplicationLocation, 0)
if err := db.Find(ctx, &list, filter); err != nil {
log.Error("ApplicationLocation GetAllApplicationMap Find err", log.E(err))
return dict, err
}
for _, loc := range list {
m := dict[loc.AppId]
if m == nil {
m = make(map[int32]*ApplicationLocation)
m[loc.LocId] = loc
dict[loc.AppId] = m
} else {
m[loc.LocId] = loc
}
}
return dict, nil
}
func GetAppLocIdNameMap(ctx context.Context) (map[int64]ApplicationLocation, *stdLog.SrvErr) {
list := make([]ApplicationLocation, 0)
if err := db.Find(ctx, &list, bson.M{}); err != nil {
log.Warn("media:GetAppLocIdNameMap db.Find failed", log.E(err))
return nil, stdLog.New(stdLog.QueryDataError, "", "")
}
dict := make(map[int64]ApplicationLocation)
for _, item := range list {
dict[int64(item.LocId)] = item
}
return dict, nil
}
func FindApplicationLocationDict(ctx context.Context, appId int64) map[int64]ApplicationLocation {
resp := make(map[int64]ApplicationLocation)
list := make([]ApplicationLocation, 0)
if err := db.Find(ctx, &list, bson.M{
"appId": appId,
}); err != nil {
return resp
}
for _, item := range list {
resp[int64(item.LocId)] = item
}
return resp
}
+30
View File
@@ -0,0 +1,30 @@
package applicationLocMod
import (
"stat/common/mongos"
"time"
)
const CollApplicationLocation = "application_location"
var db *mongos.MongoTool
type ApplicationLocation struct {
Id int64 `bson:"_id"` // 唯一id
AppId int32 `bson:"appId"` // 应用id
LocId int32 `bson:"locId"` // 位置id,外部使用的id,方便app配置
Name string `bson:"name"` // 位置名称
ImgSizeDesc string `bson:"imgSizeDesc"` // 该位置图片描述
Remark string `bson:"remark"` // 备注
CreatedAt time.Time `bson:"createAt"` // 创建时间
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
}
type UpdateAppLoc struct {
AppId *int32 `bson:"appId,omitempty"` // 应用id
LocId *int32 `bson:"locId,omitempty"` // 位置id,外部使用的id,方便app配置
Name *string `bson:"name,omitempty"` // 位置名称
ImgSizeDesc *string `bson:"imgSizeDesc,omitempty"` // 该位置图片描述
Remark *string `bson:"remark,omitempty"` // 备注
UpdatedAt *time.Time `bson:"updatedAt,omitempty"` // 更新时间
}
+184
View File
@@ -0,0 +1,184 @@
package applicationmod
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"stat/common/stdLog"
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.New(mongos.MgoManager, Collapplication)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: "parentAppId", Value: 1}},
},
{
Keys: bson.D{{Key: "rank", Value: -1}},
},
{
Keys: bson.D{{Key: "locId", Value: -1}},
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", Collapplication, err))
}
}
// InsertOneApplication 插入一个应用
func InsertOneApplication(ctx context.Context, Application *Application) *stdLog.SrvErr {
if _, err := db.InsertOne(ctx, Application); err != nil {
log.Warn("media:InsertOneApplication db.InsertOne failed", log.E(err))
return stdLog.New(stdLog.InsertDataError, "", "")
}
return nil
}
// DelOneApplication 删除一个应用tag
func DelOneApplication(ctx context.Context, filter bson.M) (
int64, *stdLog.SrvErr) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("application:DelOneApplication db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, stdLog.New(stdLog.DelDataError, "", "")
}
return count, nil
}
// UpdateOneApplication 更新一个应用
func UpdateOneApplication(ctx context.Context, filter bson.M, update bson.M) *stdLog.SrvErr {
result, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("application:UpdateOneApplication db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return stdLog.New(stdLog.UpdateDataError, "", "")
}
if result.MatchedCount != 1 {
log.Warn("application:UpdateOneApplication db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return stdLog.New(stdLog.ErrApplicationNotExist, "", "")
}
return nil
}
// CountApplications 统计应用数量
func CountApplications(ctx context.Context, filter bson.M) (
int64, *stdLog.SrvErr) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("media:CountApplications db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, stdLog.New(stdLog.QueryDataError, "", "")
}
return count, nil
}
// FindOneApplication 查找一个应用
func FindOneApplication(ctx context.Context, filter bson.M) (
*Application, *stdLog.SrvErr) {
var Application Application
if err := db.FindOneEx(
ctx, &Application, filter); err != nil {
if err != mongo.ErrNoDocuments {
log.Info("media:FindOneApplication db.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, stdLog.New(stdLog.QueryDataError, "", "")
}
return nil, stdLog.New(stdLog.ErrApplicationNotExist, "", "")
}
return &Application, nil
}
// FindManyApplication 查找一批应用
func FindManyApplication(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (ApplicationList, *stdLog.SrvErr) {
data := make(ApplicationList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("application:FindManyApplication db.Find failed",
log.E(err), log.Any("filter", filter))
return nil, stdLog.New(stdLog.QueryDataError, "", "")
}
return data, nil
}
// 根据appId获取配置的app
func FindAppByAppId(ctx context.Context, appId int64) (data []Application, err error) {
now := time.Now().Local()
filter := bson.M{"parentAppId": appId, "status": true,
"startTime": bson.M{"$lt": now}, "endTime": bson.M{"$gte": now}}
sort := bson.D{{Key: "rank", Value: -1}}
opts := options.Find().SetSort(sort)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("application FindAdsByAppId Find err", log.E(err))
return
}
return
}
// 增加广告点击量
func IncAppClickCount(ctx context.Context, id int64) (err error) {
filter := bson.M{"_id": id}
update := bson.M{"$inc": bson.M{"clickCount": 1}}
if _, err = db.UpdateOne(ctx, filter, update); err != nil {
log.Error("advertise IncAdsClickCount UpdateOne err", log.E(err))
return
}
return
}
// GetAllAdvertiseMap 获取ads id map
func GetAllAdvertiseMap(ctx context.Context) (map[primitive.ObjectID]*Application, error) {
filter := bson.M{}
dict := make(map[primitive.ObjectID]*Application)
list := make([]*Application, 0)
if err := db.Find(ctx, &list, filter); err != nil {
log.Error("Advertise GetAllAdvertiseMap Find err", log.E(err))
return dict, err
}
for _, ads := range list {
dict[ads.Id] = ads
}
return dict, nil
}
// 根据appId和locId更新位置id
func UpdateLocInfo(ctx context.Context, appId, oldLocId, newLocID int32) (err error) {
filter := bson.M{"appId": appId, "locId": oldLocId}
update := bson.M{"$set": bson.M{"locId": newLocID}}
if _, err = db.UpdateMany(ctx, filter, update); err != nil {
log.Error("advertise UpdateLocInfo UpdateMany err", log.E(err))
return
}
return
}
// UpdateManyApplication 更新满足条件的应用
func UpdateManyApplication(ctx context.Context, filter bson.M, update bson.M) *stdLog.SrvErr {
_, err := db.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("application:UpdateManyApplication db.UpdateMany failed",
log.E(err), log.Any("filter", filter), log.Any("update", update))
return stdLog.New(stdLog.UpdateDataError, "", "")
}
return nil
}
+80
View File
@@ -0,0 +1,80 @@
package applicationmod
type TagApplication struct {
AndroidUrl string
AppId string
Avatar string
BigImg string
Categories string
CreatedAt string
CreatedId string
Desc string
DownloadUrl string
EndTime string
HighQualityType string
HomeShow string
Id string
Internal string
IosUrl string
IsGame string
IsHighQuality string
IsRecommend string
LocIds string
LocNames string
Name string
NineShow string
ParentAppId string
Rank string
RecreationShow string
SmallImg string
StartTime string
Status string
Tag string
Total string
UpdatedAt string
UpdatedId string
}
var FN struct {
Application TagApplication
}
var TN struct {
Application string
}
func init() {
FN.Application.AndroidUrl = "androidUrl"
FN.Application.AppId = "appId"
FN.Application.Avatar = "avatar"
FN.Application.BigImg = "bigImg"
FN.Application.Categories = "categories"
FN.Application.CreatedAt = "createdAt"
FN.Application.CreatedId = "created_id"
FN.Application.Desc = "desc"
FN.Application.DownloadUrl = "download_url"
FN.Application.EndTime = "endTime"
FN.Application.HighQualityType = "highQualityType"
FN.Application.HomeShow = "homeShow"
FN.Application.Id = "_id"
FN.Application.Internal = "internal"
FN.Application.IosUrl = "iosUrl"
FN.Application.IsGame = "isGame"
FN.Application.IsHighQuality = "isHighQuality"
FN.Application.IsRecommend = "isRecommend"
FN.Application.LocIds = "locIds"
FN.Application.LocNames = "-"
FN.Application.Name = "name"
FN.Application.NineShow = "nineShow"
FN.Application.ParentAppId = "parentAppId"
FN.Application.Rank = "rank"
FN.Application.RecreationShow = "recreationShow"
FN.Application.SmallImg = "smallImg"
FN.Application.StartTime = "startTime"
FN.Application.Status = "status"
FN.Application.Tag = "tag"
FN.Application.Total = "total"
FN.Application.UpdatedAt = "updatedAt"
FN.Application.UpdatedId = "updated_id"
TN.Application = "application"
}
+91
View File
@@ -0,0 +1,91 @@
package applicationmod
import (
"stat/common"
"stat/common/mongos"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
const Collapplication = "application"
var db *mongos.MongoTool
// 应用中心
// @table:application
type Application struct {
Id primitive.ObjectID `json:"id" bson:"_id"`
AppId int64 `json:"appId" bson:"appId"` //appId
ParentAppId int64 `json:"parentAppId" bson:"parentAppId"` //所属appId
Name string `json:"name" bson:"name"` //应用名
DaoLiangTitle string `json:"daoLiangTitle" bson:"daoLiangTitle"` //广告导量标题
Tag int32 `json:"tag" bson:"tag"` //标签
Internal bool `json:"internal" bson:"internal"` //是否内部应用
Categories []*common.CategoryRank `json:"categories" bson:"categories"` //分类排序
Desc string `json:"desc" bson:"desc"` //描述
DownloadUrl string `json:"download_url" bson:"download_url"` //下载地址
IosUrl string `json:"iosUrl" bson:"iosUrl"` //ios链接
AndroidUrl string `json:"androidUrl" bson:"androidUrl"` //安卓链接
Avatar string `json:"avatar" bson:"avatar"` //头像图片
Status bool `json:"status" bson:"status"` //状态
Rank int64 `json:"rank" bson:"rank"` //默认排序
Total int64 `json:"total" bson:"total"` //总点击
CreatedId int64 `json:"created_id" bson:"created_id"` //创建人
UpdatedId int64 `json:"updated_id" bson:"updated_id"` //最后更新人
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` //创建时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` //更新时间
NineShow bool `json:"nineShow" bson:"nineShow"` //是否九宫格
RecreationShow bool `json:"recreationShow" bson:"recreationShow"` //是否娱乐中心显示
IsRecommend bool `json:"isRecommend" bson:"isRecommend"` //是否推荐
IsGame bool `json:"isGame" bson:"isGame"` //是否游戏
HomeShow bool `json:"homeShow" bson:"homeShow"` //是否首页展示
LocIds []int64 `json:"locIds" bson:"locIds"` //位置id
LocNames []string `json:"locNames" bson:"-"` //位置映射
SmallImg string `json:"smallImg" bson:"smallImg"` // 小图标(比例:360*200)
BigImg string `json:"bigImg" bson:"bigImg"` // 大图标(比例:686*330)
IsHighQuality bool `json:"isHighQuality" bson:"isHighQuality"` // 是否是优质APP推荐
HighQualityType int64 `json:"highQualityType" bson:"highQualityType"` // 优质APP推荐展示方式 0:应用图标 1:展示描述文字
StartTime time.Time `json:"startTime" bson:"startTime"` // 开始时间
EndTime time.Time `json:"endTime" bson:"endTime"` // 结束时间
}
type ApplicationList []*Application
type AppUpdate struct {
Id string `json:"id" bson:"id"`
Param AppUpdateInfo `json:"param" bson:"param"`
}
type AppUpdateInfo struct {
AppId int64 `json:"appId" bson:"appId"` //appId
ParentAppId int64 `json:"parentAppId" bson:"parentAppId"` //所属appId
Name string `json:"name" bson:"name"` //应用名
DaoLiangTitle string `json:"daoLiangTitle" bson:"daoLiangTitle"` //广告导量标题
//Tag common.AppReqType `json:"tag" bson:"tag"` //标签
Internal bool `json:"internal" bson:"internal"` //是否内部应用
Categories []*common.CategoryRank `json:"categories" bson:"categories"` //分类排序
Desc string `json:"desc" bson:"desc"` //描述
DownloadUrl string `json:"download_url" bson:"download_url"` //下载地址
IosUrl string `json:"iosUrl" bson:"iosUrl"` //ios链接
AndroidUrl string `json:"androidUrl" bson:"androidUrl"` //安卓链接
Avatar string `json:"avatar" bson:"avatar"` //头像图片
Status bool `json:"status" bson:"status"` //状态
Rank int64 `json:"rank" bson:"rank"` //默认排序
Total int64 `json:"total" bson:"total"` //总点击
CreatedId int64 `json:"created_id" bson:"created_id"` //创建人
UpdatedId int64 `json:"updated_id" bson:"updated_id"` //最后更新人
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` //更新时间
NineShow bool `json:"nineShow" bson:"nineShow"` //是否九宫格
RecreationShow bool `json:"recreationShow" bson:"recreationShow"` //是否娱乐中心显示
IsRecommend bool `json:"isRecommend" bson:"isRecommend"` //是否推荐
IsGame bool `json:"isGame" bson:"isGame"` //是否游戏
HomeShow bool `json:"homeShow" bson:"homeShow"` //是否首页展示
LocIds []int32 `json:"locIds" bson:"locIds"` //位置id
SmallImg string `json:"smallImg" bson:"smallImg"` // 小图标
BigImg string `json:"bigImg" bson:"bigImg"` // 大图标
IsHighQuality bool `json:"isHighQuality" bson:"isHighQuality"` // 是否是优质APP推荐
HighQualityType int64 `json:"highQualityType" bson:"highQualityType"` // 优质APP推荐展示方式 0:应用图标 1:展示描述文字
StartTime time.Time `bson:"startTime" json:"startTime"` // 开始时间
EndTime time.Time `bson:"endTime" json:"endTime"` // 结束时间
}
+139
View File
@@ -0,0 +1,139 @@
package applicationstat
import (
"context"
"fmt"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"stat/common/log"
"stat/common/mongos"
"stat/common/stdLog"
)
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.New(mongos.MgoManager, Collapplicationstat)
// 获取数据库表
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: "applicationDbId", Value: 1},
{Key: FN.ApplicationStat.SumData, Value: -1},
},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{
{Key: FN.ApplicationStat.Id, Value: 1},
},
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(applicationstat:initApplicationStatIndex) Create ApplicationStat Index failed! err:%+v:", err))
}
}
// InsertOneApplicationStat 插入一个应用
func InsertOneApplicationStat(ctx context.Context, applicationStat *ApplicationStat) *stdLog.SrvErr {
if _, err := db.InsertOne(ctx, applicationStat); err != nil {
log.Warn("applicationstat:InsertOneApplicationStat db.InsertOne failed", log.E(err))
return stdLog.New(stdLog.InsertDataError, "", "")
}
return nil
}
// DelOneApplicationStat 删除一个应用tag
func DelOneApplicationStat(ctx context.Context, filter bson.M) (
int64, *stdLog.SrvErr) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("applicationstat:DelOneApplicationStat db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, stdLog.New(stdLog.DelDataError, "", "")
}
return count, nil
}
// FindOneApplicationStat 查找一个应用
func FindOneApplicationStat(ctx context.Context, filter bson.M) (
*ApplicationStat, *stdLog.SrvErr) {
var applicationStat ApplicationStat
if err := db.FindOneEx(
ctx, &applicationStat, filter); err != nil {
if err != mongo.ErrNoDocuments {
log.Info("applicationstat:FindOneApplicationStat db.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, stdLog.New(stdLog.QueryDataError, "", "")
}
return nil, stdLog.New(stdLog.DataNotExist, "", "")
}
return &applicationStat, nil
}
// CountApplicationStats 统计应用数量
func CountApplicationStats(ctx context.Context, filter bson.M) (
int64, *stdLog.SrvErr) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("applicationstat:CountApplicationStats db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, stdLog.New(stdLog.QueryDataError, "", "")
}
return count, nil
}
// UpdateOneApplicationStat 更新一个应用
func UpdateOneApplicationStat(ctx context.Context, filter bson.M, update bson.M) *stdLog.SrvErr {
result, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("applicationstat:UpdateOneApplicationStat db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return stdLog.New(stdLog.UpdateDataError, "", "")
}
if result.MatchedCount != 1 {
log.Warn("applicationstat:UpdateOneApplicationStat db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return stdLog.New(stdLog.DataNotExist, "", "")
}
return nil
}
// UpdateManyApplicationStat 更新一批应用
func UpdateManyApplicationStat(ctx context.Context, filter bson.M, update bson.M) *stdLog.SrvErr {
result, err := db.UpdateMMany(ctx, filter, update)
if err != nil {
log.Warn("applicationstat:UpdateManyApplicationStat db.UpdateMMany failed",
log.E(err), log.Any("filter", filter))
return stdLog.New(stdLog.UpdateDataError, "", "")
}
if result.MatchedCount <= 0 {
log.Warn("applicationstat:UpdateManyApplicationStat db.UpdateMMany failed",
log.E(err), log.Any("filter", filter))
//return srvdef.New(srvdef.ErrApplicationNotExsit, "", "")
}
return nil
}
// AggregateTopicInfos 聚合查找一批用户信息
func AggregateApplicationStat(ctx context.Context,
bind interface{}, pipeline []bson.M) *stdLog.SrvErr {
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("feedback:AggregateApplicationStat db.Aggregate failed",
log.E(err), log.Any("pipeline", pipeline))
return stdLog.New(stdLog.QueryDataError, "", err.Error())
}
return nil
}
// FindManyApplicationStat 查找一批应用
func FindManyApplicationStat(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (ApplicationStatList, *stdLog.SrvErr) {
data := make(ApplicationStatList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("applicationstat:FindManyApplicationStat db.Find failed",
log.E(err), log.Any("filter", filter))
return nil, stdLog.New(stdLog.QueryDataError, "", "")
}
return data, nil
}
+30
View File
@@ -0,0 +1,30 @@
package applicationstat
type TagApplicationStat struct {
Id string
//AppId string
SumData string
Total string
HourData string
CreatedAt string
UpdatedAt string
}
var FN struct {
ApplicationStat TagApplicationStat
}
var TN struct {
ApplicationStat string
}
func init() {
FN.ApplicationStat.Id = "_id"
//FN.ApplicationStat.AppId = "appId"
FN.ApplicationStat.SumData = "sumDate"
FN.ApplicationStat.Total = "total"
FN.ApplicationStat.HourData = "hourData"
FN.ApplicationStat.CreatedAt = "createdAt"
FN.ApplicationStat.UpdatedAt = "updatedAt"
TN.ApplicationStat = "applicationstat"
}
+44
View File
@@ -0,0 +1,44 @@
package applicationstat
import (
"stat/common/mongos"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
const Collapplicationstat = "applicationstat"
var db *mongos.MongoTool
type THourStat map[int]int64
func (m THourStat) Total() int64 {
var sum int64
for _, v := range m {
sum += v
}
return sum
}
type Update struct {
Total *int64 `json:"total" bson:"total,omitempty"` //今日点击
HourData *THourStat `json:"hourData" bson:"hourData,omitempty"` //小时数据
UpdatedAt *time.Time `json:"updatedAt" bson:"updatedAt,omitempty"` //更新时间
}
// 应用统计
// @table:applicationstat
type ApplicationStat struct {
Id primitive.ObjectID `json:"id" bson:"_id,omitempty"`
ApplicationDbId primitive.ObjectID `json:"applicationDbId" bson:"applicationDbId"`
//AppId int64 `json:"appId" bson:"appId"` //应用ID
//ParentAppId int64 `json:"parentAppId" bson:"parentAppId"` //所属应用ID
SumDate time.Time `json:"sumDate" bson:"sumDate"` //记录时间
Total int64 `json:"total" bson:"total"` //今日点击
HourData THourStat `json:"hourData" bson:"hourData"` //小时数据
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` //创建时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` //更新时间
}
type ApplicationStatList []*ApplicationStat
+137
View File
@@ -0,0 +1,137 @@
package authorityMod
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"stat/common/utils"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func Init() {
// 获取数据库表
db = mongos.New(mongos.MgoManager, CollAuthority)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{{"role", 1}},
Options: options.Index().SetUnique(true),
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollAuthority, err))
}
}
// 添加角色
func AddRole(ctx context.Context, doc *Authority) (err error) {
if _, err = db.InsertOne(ctx, doc); err != nil {
log.Error(fmt.Sprintf("model %s AddRole InsertOne error", CollAuthority), log.E(err))
return
}
return
}
// 更新角色
func UpdateRole(ctx context.Context, roleId int64, doc UpdateDoc) (err error) {
filter := bson.M{"_id": roleId}
update, _ := utils.ToBsonM(doc)
if _, err = db.UpdateOne(ctx, filter, bson.M{"$set": update}); err != nil {
log.Error(fmt.Sprintf("model %s UpdateRole UpdateOne error", CollAuthority), log.E(err))
return
}
return
}
// 删除角色
func DelRoleById(ctx context.Context, roleId int64) (err error) {
filter := bson.M{"_id": roleId}
if _, err = db.DeleteOne(ctx, filter); err != nil {
log.Error(fmt.Sprintf("model %s DelRole DeleteOne error", CollAuthority), log.E(err))
return
}
return
}
// 角色列表
func RoleList(ctx context.Context, skip int64, limit int64) (count int64, data []Authority, err error) {
filter := bson.M{}
opts := options.Find().SetSkip(skip).SetLimit(limit)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error(fmt.Sprintf("model %s RoleList Find error", CollAuthority), log.E(err))
return
}
if count, err = db.Count(ctx, filter); err != nil {
log.Error(fmt.Sprintf("model %s RoleList Count error", CollAuthority), log.E(err))
return
}
return
}
// 根据角色获取权限
func GetAuthorityByRole(ctx context.Context, role string) (data Authority, err error) {
query := bson.M{"role": role}
if err = db.FindOne(ctx, &data, query); err != nil {
log.Error(fmt.Sprintf("model %s GetAuthorityByRole FindOne error", CollAuthority), log.E(err))
return
}
return
}
// 根据id获取权限
func GetAuthorityById(ctx context.Context, id int64) (data Authority, err error) {
query := bson.M{"_id": id}
if err = db.FindOne(ctx, &data, query); err != nil {
log.Error(fmt.Sprintf("model %s GetAuthorityById FindOne error", CollAuthority), log.E(err))
return
}
return
}
// 根据ids获取权限列表
func GetAuthorityByIds(ctx context.Context, ids []int64) (data []Authority, err error) {
if len(ids) == 0 {
return
}
query := bson.M{"_id": bson.M{"$in": ids}}
if err = db.Find(ctx, &data, query); err != nil {
log.Error(fmt.Sprintf("model %s GetAuthorityByIds Find error", CollAuthority), log.E(err))
return
}
return
}
// 获取角色信息,排除当前角色
func GetRoleExcludeRole(ctx context.Context, roleId int64, role string) (data Authority, err error) {
filter := bson.M{"_id": bson.M{"$ne": roleId}, "role": role}
if err = db.FindOne(ctx, &data, filter); err != nil {
log.Error(fmt.Sprintf("model %s GetRoleExcludeRole FindOne error", CollAuthority),
log.Any("roleId", roleId),
log.Any("role", role),
log.E(err),
)
return
}
return
}
+24
View File
@@ -0,0 +1,24 @@
package authorityMod
import (
"stat/common/mongos"
"time"
)
const CollAuthority = "authority"
var db *mongos.MongoTool
type Authority struct {
Id int64 `bson:"_id"` // _id
Role string `bson:"role"` // 角色
AuthJson string `bson:"authJson"` // 权限json数据
CreatedAt time.Time `bson:"createdAt"` // 创建时间
UpdatedAt time.Time `bson:"updatedAt"` // 修改时间
}
type UpdateDoc struct {
Role *string `bson:"role,omitempty"` // 角色
AuthJson *string `bson:"authJson,omitempty"` // 权限json数据
UpdatedAt *time.Time `bson:"updatedAt,omitempty"` // 修改时间
}
+150
View File
@@ -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
}
+69
View File
@@ -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其他包访问次数
}
+699
View File
@@ -0,0 +1,699 @@
package botdailyhourstat
import (
"errors"
"fmt"
"stat/common/statutils"
)
func LineCount(iTemp string, iValue int64, permilValue int64) string {
if permilValue > 1000000 || permilValue < -1000000 {
s1 := fmt.Sprintf("%d", iValue)
str1 := fmt.Sprintf(iTemp, s1)
return str1 + "\n"
} else {
s1 := fmt.Sprintf("%d", iValue)
str1 := fmt.Sprintf(iTemp, s1)
v := float64(permilValue) / 10
str2 := ""
if v < 0 {
str2 = fmt.Sprintf("⬇%.2f%%", v)
} else if v > 0 {
str2 = fmt.Sprintf("⬆+️%.2f%%", v)
} else {
str2 = fmt.Sprintf(" %.2f%%", v)
}
return str1 + str2 + "\n"
}
}
func LineMoneyOne(iTemp string, iValue int64) string {
return LineCountOne(iTemp, iValue/100)
}
func LineCountOne(iTemp string, iValue int64) string {
s1 := fmt.Sprintf("%d", iValue)
str1 := fmt.Sprintf(iTemp, s1)
return str1 + "\n"
}
func LineMoney(iTemp string, iValue int64, permilValue int64) string {
return LineCount(iTemp, iValue/100, permilValue)
}
func (s *StatItem) Display(prefix string) string {
var text string
//text += fmt.Sprintf("%s%s\n", prefix+"┣", "充值总计:")
//text += s.Recharge.DisplayDayHourText(prefix+"┃", 100)
//text += fmt.Sprintf("%s%s\n", prefix+"┣", "老用户充值:")
//text += s.RechargeOldUser.DisplayDayHourText(prefix+"┃", 100)
//text += fmt.Sprintf("%s%s\n", prefix+"┣", "新用户充值:")
//text += s.RechargeNewUser.DisplayDayHourText(prefix+"┃", 100)
//text += fmt.Sprintf("%s%s\n", prefix+"┣", "[会员购买]:")
//text += s.RechargeVip.DisplayDayHourText(prefix+"┃", 100)
//text += fmt.Sprintf("%s%s\n", prefix+"┣", "[金币购买]:")
//text += s.RechargeGold.DisplayDayHourText(prefix+"┃", 100)
//text += fmt.Sprintf("%s%s\n", prefix+"┣", "[订单统计]:")
//text += s.Order.DisplayDayHourText(prefix+"┃", 1)
//text += fmt.Sprintf("%s%s\n", prefix+"┣", "[注册统计]:")
//text += s.Register.DisplayDayHourText(prefix+"┃", 1)
//text += fmt.Sprintf("%s%s\n", prefix+"┗", "[访问统计]:")
//text += s.Visit.DisplayDayHourText(prefix+" ", 1)
return text
}
func (s *BotHourStat) DisplayDayHourText(appName string, compare *BotHourStat) string {
calc := func(curr, hist *statutils.Stat) (*statutils.Stat, *statutils.Stat) {
diff := curr.Sub(hist)
rate := diff.Permil(hist)
return curr, rate
}
rate := func(currValue, histValue int64) int64 {
if histValue != 0 {
return (currValue - histValue) * 1000 / histValue
} else {
return 0
}
}
var text string
text += fmt.Sprintf("应用名称:【%s】\n", appName) //🆚
text += fmt.Sprintf("统计时间:%s\n", s.SumDate.Format("2006-01-02T15:04:05"))
if compare != nil {
func() {
reCurr, reRate := calc(&s.TodayStat.Recharge, &compare.TodayStat.Recharge)
text += "1️⃣当日充值:\n"
text += LineMoney("┣充值合计:%s", reCurr.Value(), reRate.Value())
text += LineMoney("┃┏安卓充值:%s", reCurr.Android.Value(), reRate.Android.Value())
text += LineMoney("┣╋苹果充值:%s", reCurr.Ios.Value(), reRate.Ios.Value())
text += LineMoney("┃┣轻量充值:%s", reCurr.Light.Value(), reRate.Light.Value())
text += LineMoney("┃┗H5充值 :%s", reCurr.H5.Value(), reRate.H5.Value())
text += LineMoney("┃┏渠道充值:%s", reCurr.Total.District.Value, reRate.Total.District.Value)
text += LineMoney("┣╋官网充值:%s", reCurr.Total.Web.Value, reRate.Total.Web.Value)
text += LineMoney("┃┣自来充值:%s", reCurr.Total.Normal.Value, reRate.Total.Normal.Value)
text += LineMoney("┃┗分享充值:%s", reCurr.Total.Share.Value, reRate.Total.Share.Value)
oldCurr, oldRate := calc(&s.TodayStat.RechargeOld, &compare.TodayStat.RechargeOld)
text += LineMoney("┃┏老用户充:%s", oldCurr.Value(), oldRate.Value())
newCurr, newRate := calc(&s.TodayStat.RechargeNew, &compare.TodayStat.RechargeNew)
text += LineMoney("┣╋新用户充:%s", newCurr.Value(), newRate.Value())
v0, v00 := calc(newCurr.Percentage(reCurr), compare.TodayStat.RechargeNew.Percentage(&compare.TodayStat.Recharge))
text += LineCount("┃┗新充占比:%s%%", v0.Value(), v00.Value())
memCurr, memRate := calc(&s.TodayStat.RechargeVip, &compare.TodayStat.RechargeVip)
text += LineMoney("┃┏会员充值:%s", memCurr.Value(), memRate.Value())
coinCurr, coinRate := calc(&s.TodayStat.RechargeGold, &compare.TodayStat.RechargeGold)
text += LineMoney("┣╋金币充值:%s", coinCurr.Value(), coinRate.Value())
v2, v22 := calc(memCurr.Percentage(reCurr), compare.TodayStat.RechargeVip.Percentage(&compare.TodayStat.Recharge))
text += LineCount("┃┗会员占比:%s%%", v2.Value(), v22.Value())
orderCurr, orderRate := calc(&s.TodayStat.Order, &compare.TodayStat.Order)
text += LineCount("┃┏订单拉起:%s", orderCurr.Count(), orderRate.Count())
succCurr, succRate := calc(&s.TodayStat.OrderSucc, &compare.TodayStat.OrderSucc)
text += LineCount("┣╋订单成功:%s", succCurr.Count(), succRate.Count())
v1, v11 := calc(succCurr.Percentage(orderCurr), compare.TodayStat.OrderSucc.Percentage(&compare.TodayStat.Order))
text += LineCount("┃┗成功比率:%s%%", v1.Count(), v11.Count())
text += "2️⃣当日新增:\n"
regCurr, regRate := calc(&s.TodayStat.Register, &compare.TodayStat.Register)
text += LineCount("┣新增用户:%s", regCurr.Count(), regRate.Count())
text += LineCount("┃┏安卓新增:%s", regCurr.Android.Count(), regRate.Android.Count())
text += LineCount("┣╋苹果新增:%s", regCurr.Ios.Count(), regRate.Ios.Count())
text += LineCount("┃┣轻量新增:%s", regCurr.Light.Count(), regRate.Light.Count())
text += LineCount("┃┗H5新增 :%s", regCurr.H5.Count(), regRate.H5.Count())
text += LineCount("┃┏渠道新增:%s", regCurr.Total.District.Count, regRate.Total.District.Count)
text += LineCount("┣╋有效新增:%s", regCurr.Total.Direct.Value()-regCurr.Total.Direct.Natural.Value,
regRate.Total.Direct.Value()-regRate.Total.Direct.Natural.Value)
text += LineCount("┣╋官网新增:%s", regCurr.Total.Web.Count, regRate.Total.Web.Count)
text += LineCount("┃┣自来新增:%s", regCurr.Total.Normal.Count, regRate.Total.Normal.Count)
text += LineCount("┃┗分享新增:%s", regCurr.Total.Share.Count, regRate.Total.Share.Count)
text += "3️⃣当日日活:\n"
visitCurr, visitRate := calc(&s.TodayStat.Visit, &compare.TodayStat.Visit)
text += LineCount("┣日活总数:%s", visitCurr.Count(), visitRate.Count())
text += LineCount("┃┏安卓日活:%s", visitCurr.Android.Count(), visitRate.Android.Count())
text += LineCount("┣╋苹果日活:%s", visitCurr.Ios.Count(), visitRate.Ios.Count())
text += LineCount("┃┣轻量日活:%s", visitCurr.Light.Count(), visitRate.Light.Count())
text += LineCount("┃┗H5日活 :%s", visitCurr.H5.Count(), visitRate.H5.Count())
text += LineCount("┃┏渠道日活:%s", visitCurr.Total.District.Count, visitRate.Total.District.Count)
text += LineCount("┣╋官网日活:%s", visitCurr.Total.Web.Count, visitRate.Total.Web.Count)
text += LineCount("┃┣自来日活:%s", visitCurr.Total.Normal.Count, visitRate.Total.Normal.Count)
text += LineCount("┃┗分享日活:%s", visitCurr.Total.Share.Count, visitRate.Total.Share.Count)
text += "4️⃣落地页点击:\n"
text += LineCount("┣总数:%s", s.TodayLandPage.LandPageTotalClick, rate(s.TodayLandPage.LandPageTotalClick, compare.TodayLandPage.LandPageTotalClick))
text += LineCount("┃┏安卓:%s", s.TodayLandPage.LandPageAndroidClick, rate(s.TodayLandPage.LandPageAndroidClick, compare.TodayLandPage.LandPageAndroidClick))
text += LineCount("┣╋商店:%s", s.TodayLandPage.LandPageIosAppstoreClick, rate(s.TodayLandPage.LandPageIosAppstoreClick, compare.TodayLandPage.LandPageIosAppstoreClick))
text += LineCount("┃┣企业:%s", s.TodayLandPage.LandPageIosFirmClick, rate(s.TodayLandPage.LandPageIosFirmClick, compare.TodayLandPage.LandPageIosFirmClick))
text += LineCount("┃┗轻量:%s", s.TodayLandPage.LandPageIosLightClick, rate(s.TodayLandPage.LandPageIosLightClick, compare.TodayLandPage.LandPageIosLightClick))
}()
func() {
reCurr, reRate := calc(&s.HourStat.Recharge, &compare.HourStat.Recharge)
text += "5️⃣小时充值:\n"
text += LineMoney("┣充值合计:%s", reCurr.Value(), reRate.Value())
text += LineMoney("┃┏安卓充值:%s", reCurr.Android.Value(), reRate.Android.Value())
text += LineMoney("┣╋苹果充值:%s", reCurr.Ios.Value(), reRate.Ios.Value())
text += LineMoney("┃┣轻量充值:%s", reCurr.Light.Value(), reRate.Light.Value())
text += LineMoney("┃┗H5充值 :%s", reCurr.H5.Value(), reRate.H5.Value())
text += LineMoney("┃┏渠道充值:%s", reCurr.Total.District.Value, reRate.Total.District.Value)
text += LineMoney("┣╋官网充值:%s", reCurr.Total.Web.Value, reRate.Total.Web.Value)
text += LineMoney("┃┣自来充值:%s", reCurr.Total.Normal.Value, reRate.Total.Normal.Value)
text += LineMoney("┃┗分享充值:%s", reCurr.Total.Share.Value, reRate.Total.Share.Value)
oldCurr, oldRate := calc(&s.HourStat.RechargeOld, &compare.HourStat.RechargeOld)
text += LineMoney("┃┏老用户充:%s", oldCurr.Value(), oldRate.Value())
newCurr, newRate := calc(&s.HourStat.RechargeNew, &compare.HourStat.RechargeNew)
text += LineMoney("┣╋新用户充:%s", newCurr.Value(), newRate.Value())
v0, v00 := calc(newCurr.Percentage(reCurr), compare.HourStat.RechargeNew.Percentage(&compare.HourStat.Recharge))
text += LineCount("┃┗新充占比:%s%%", v0.Value(), v00.Value())
memCurr, memRate := calc(&s.HourStat.RechargeVip, &compare.HourStat.RechargeVip)
text += LineMoney("┃┏会员充值:%s", memCurr.Value(), memRate.Value())
coinCurr, coinRate := calc(&s.HourStat.RechargeGold, &compare.HourStat.RechargeGold)
text += LineMoney("┣╋金币充值:%s", coinCurr.Value(), coinRate.Value())
v2, v22 := calc(memCurr.Percentage(reCurr), compare.HourStat.RechargeVip.Percentage(&compare.HourStat.Recharge))
text += LineCount("┃┗会员占比:%s%%", v2.Value(), v22.Value())
orderCurr, orderRate := calc(&s.HourStat.Order, &compare.HourStat.Order)
text += LineCount("┃┏订单拉起:%s", orderCurr.Count(), orderRate.Count())
succCurr, succRate := calc(&s.HourStat.OrderSucc, &compare.HourStat.OrderSucc)
text += LineCount("┣╋订单成功:%s", succCurr.Count(), succRate.Count())
v1, v11 := calc(succCurr.Percentage(orderCurr), compare.HourStat.OrderSucc.Percentage(&compare.HourStat.Order))
text += LineCount("┃┗订单成功率:%s%%", v1.Count(), v11.Count())
text += "6️⃣小时新增:\n"
regCurr, regRate := calc(&s.HourStat.Register, &compare.HourStat.Register)
text += LineCount("┣新增用户:%s", regCurr.Count(), regRate.Count())
text += LineCount("┃┏安卓新增:%s", regCurr.Android.Count(), regRate.Android.Count())
text += LineCount("┣╋苹果新增:%s", regCurr.Ios.Count(), regRate.Ios.Count())
text += LineCount("┃┣轻量新增:%s", regCurr.Light.Count(), regRate.Light.Count())
text += LineCount("┃┗H5新增 :%s", regCurr.H5.Count(), regRate.H5.Count())
text += LineCount("┃┏渠道新增:%s", regCurr.Total.District.Count, regRate.Total.District.Count)
text += LineCount("┣╋有效新增:%s", regCurr.Total.Direct.Value()-regCurr.Total.Direct.Natural.Value,
regRate.Total.Direct.Value()-regRate.Total.Direct.Natural.Value)
text += LineCount("┣╋官网新增:%s", regCurr.Total.Web.Count, regRate.Total.Web.Count)
text += LineCount("┃┣自来新增:%s", regCurr.Total.Normal.Count, regRate.Total.Normal.Count)
text += LineCount("┃┗分享新增:%s", regCurr.Total.Share.Count, regRate.Total.Share.Count)
text += "7️⃣小时落地页点击:\n"
text += LineCount("┣总数:%s", s.HourLandPage.LandPageTotalClick, rate(s.HourLandPage.LandPageTotalClick, compare.HourLandPage.LandPageTotalClick))
text += LineCount("┃┏安卓:%s", s.HourLandPage.LandPageAndroidClick, rate(s.HourLandPage.LandPageAndroidClick, compare.HourLandPage.LandPageAndroidClick))
text += LineCount("┣╋商店:%s", s.HourLandPage.LandPageIosAppstoreClick, rate(s.HourLandPage.LandPageIosAppstoreClick, compare.HourLandPage.LandPageIosAppstoreClick))
text += LineCount("┃┣企业:%s", s.HourLandPage.LandPageIosFirmClick, rate(s.HourLandPage.LandPageIosFirmClick, compare.HourLandPage.LandPageIosFirmClick))
text += LineCount("┃┗轻量:%s", s.HourLandPage.LandPageIosLightClick, rate(s.HourLandPage.LandPageIosLightClick, compare.HourLandPage.LandPageIosLightClick))
}()
func() {
if s.TodayGame != nil {
text += "8️⃣游戏数据:\n"
text += fmt.Sprintf("┣游戏充值: %d\n", s.TodayGame.RchgAmount)
text += fmt.Sprintf("┣代充充值: %d\n", s.TodayGame.DcRchgAmount)
text += fmt.Sprintf("┣有效投注: %d\n", s.TodayGame.ValidBet)
text += fmt.Sprintf("┣系统盈利: %d\n", s.TodayGame.Profit)
text += fmt.Sprintf("┣提现金额: %d\n", s.TodayGame.WtdrRealAmount)
text += fmt.Sprintf("┣游戏上分: %d\n", s.TodayGame.IncAmount)
text += fmt.Sprintf("┗游戏下分: %d\n", s.TodayGame.DecAmount)
}
}()
text += fmt.Sprintf("🆚%s同比数据:当日的昨天%d点\n", appName, compare.SumDate.Hour())
} else {
func() {
reCurr := &s.TodayStat.Recharge
text += "1️⃣当日充值:\n"
text += LineMoneyOne("┣充值合计: %s", reCurr.Value())
text += LineMoneyOne("┃┏安卓充值: %s", reCurr.Android.Value())
text += LineMoneyOne("┣╋苹果充值: %s", reCurr.Ios.Value())
text += LineMoneyOne("┃┣轻量充值: %s", reCurr.Light.Value())
text += LineMoneyOne("┃┗H5充值: %s", reCurr.H5.Value())
text += LineMoneyOne("┃┏渠道充值: %s", reCurr.Total.District.Value)
text += LineMoneyOne("┣╋官网充值: %s", reCurr.Total.Web.Value)
text += LineMoneyOne("┃┣自来充值: %s", reCurr.Total.Normal.Value)
text += LineMoneyOne("┃┗分享充值: %s", reCurr.Total.Share.Value)
oldCurr := &s.TodayStat.RechargeOld
text += LineMoneyOne("┃┏老用户充: %s", oldCurr.Value())
newCurr := &s.TodayStat.RechargeNew
text += LineMoneyOne("┣╋新用户充: %s", newCurr.Value())
v0 := newCurr.Percentage(reCurr)
text += LineCountOne("┃┗新充占比: %s%%", v0.Value())
memCurr := &s.TodayStat.RechargeVip
text += LineMoneyOne("┃┏会员充值: %s", memCurr.Value())
coinCurr := &s.TodayStat.RechargeGold
text += LineMoneyOne("┣╋金币充值: %s", coinCurr.Value())
v1 := memCurr.Percentage(reCurr)
text += LineCountOne("┃┗会员占比: %s%%", v1.Value())
orderCurr := &s.TodayStat.Order
text += LineCountOne("┃┏订单拉起: %s", orderCurr.Count())
succCurr := &s.TodayStat.OrderSucc
text += LineCountOne("┣╋订单成功: %s", succCurr.Count())
v2 := succCurr.Percentage(orderCurr)
text += LineCountOne("┃┗成功占比: %s%%", v2.Count())
text += "2️⃣当日新增:\n"
regCurr := &s.TodayStat.Register
text += LineCountOne("┣新增用户: %s", regCurr.Count())
text += LineCountOne("┃┏安卓新增: %s", regCurr.Android.Count())
text += LineCountOne("┣╋苹果新增: %s", regCurr.Ios.Count())
text += LineCountOne("┃┣轻量新增: %s", regCurr.Light.Count())
text += LineCountOne("┃┗H5新增: %s", regCurr.H5.Count())
text += LineCountOne("┃┏渠道新增: %s", regCurr.Total.District.Count)
text += LineCountOne("┣╋官网新增: %s", regCurr.Total.Web.Count)
text += LineCountOne("┃┣自来新增: %s", regCurr.Total.Normal.Count)
text += LineCountOne("┃┗分享新增: %s", regCurr.Total.Share.Count)
text += "3️⃣当日日活:\n"
visitCurr := &s.TodayStat.Visit
text += LineCountOne("┣日活总数: %s", visitCurr.Count())
text += LineCountOne("┃┏安卓日活: %s", visitCurr.Android.Count())
text += LineCountOne("┣╋苹果日活: %s", visitCurr.Ios.Count())
text += LineCountOne("┃┣轻量日活: %s", visitCurr.Light.Count())
text += LineCountOne("┃┗H5日活: %s", visitCurr.H5.Count())
text += LineCountOne("┃┏渠道日活: %s", visitCurr.Total.District.Count)
text += LineCountOne("┣╋官网日活: %s", visitCurr.Total.Web.Count)
text += LineCountOne("┃┣自来日活: %s", visitCurr.Total.Normal.Count)
text += LineCountOne("┃┗分享日活: %s", visitCurr.Total.Share.Count)
}()
func() {
reCurr := &s.HourStat.Recharge
text += "4️⃣小时充值:\n"
text += LineMoneyOne(" ┣充值合计: %s", reCurr.Value())
text += LineMoneyOne(" ┣安卓充值: %s", reCurr.Android.Value())
text += LineMoneyOne(" ┣苹果充值: %s", reCurr.Ios.Value())
text += LineMoneyOne(" ┣轻量充值: %s", reCurr.Light.Value())
text += LineMoneyOne(" ┣H5充值: %s", reCurr.H5.Value())
text += LineMoneyOne(" ┣渠道充值: %s", reCurr.Total.District.Value)
text += LineMoneyOne(" ┣官网充值: %s", reCurr.Total.Web.Value)
text += LineMoneyOne(" ┣自来充值: %s", reCurr.Total.Normal.Value)
oldCurr := &s.HourStat.RechargeOld
text += LineMoneyOne(" ┣老用户充: %s", oldCurr.Value())
newCurr := &s.HourStat.RechargeNew
text += LineMoneyOne(" ┣新用户充: %s", newCurr.Value())
memCurr := &s.HourStat.RechargeVip
text += LineMoneyOne(" ┣会员充值: %s", memCurr.Value())
coinCurr := &s.HourStat.RechargeGold
text += LineMoneyOne(" ┣金币充值: %s", coinCurr.Value())
orderCurr := &s.HourStat.Order
text += LineCountOne(" ┣订单拉起: %s", orderCurr.Count())
succCurr := &s.HourStat.OrderSucc
text += LineCountOne(" ┣订单成功: %s", succCurr.Count())
v1 := succCurr.Percentage(orderCurr)
text += LineCountOne(" ┗订单成功率: %s%%", v1.Count())
text += "5️⃣小时新增:\n"
regCurr := &s.HourStat.Register
text += LineCountOne(" ┣新增用户: %s", regCurr.Count())
text += LineCountOne(" ┣安卓新增: %s", regCurr.Android.Count())
text += LineCountOne(" ┣苹果新增: %s", regCurr.Ios.Count())
text += LineCountOne(" ┣轻量新增: %s", regCurr.Light.Count())
text += LineCountOne(" ┣H5新增: %s", regCurr.H5.Count())
text += LineCountOne(" ┣渠道新增: %s", regCurr.Total.District.Count)
text += LineCountOne(" ┣官网新增: %s", regCurr.Total.Web.Count)
text += LineCountOne(" ┗自来新增: %s", regCurr.Total.Normal.Count)
}()
func() {
if s.TodayGame != nil {
text += "5️⃣游戏数据:\n"
text += fmt.Sprintf(" ┣游戏充值: %d\n", s.TodayGame.RchgAmount)
text += fmt.Sprintf(" ┣代充充值: %d\n", s.TodayGame.DcRchgAmount)
text += fmt.Sprintf(" ┣有效投注: %d\n", s.TodayGame.ValidBet)
text += fmt.Sprintf(" ┣系统盈利: %d\n", s.TodayGame.Profit)
text += fmt.Sprintf(" ┣提现金额: %d\n", s.TodayGame.WtdrRealAmount)
text += fmt.Sprintf(" ┣游戏上分: %d\n", s.TodayGame.IncAmount)
text += fmt.Sprintf(" ┗游戏下分: %d\n", s.TodayGame.DecAmount)
}
}()
text += fmt.Sprintf("🆚【%s】同比数据未找到\n", appName)
}
return text
}
func (s *BotHourStat) DisplaySummaryText(title string) string {
var text string
text += fmt.Sprintf("统计标题:%s\n", title) //
func() {
reCurr := &s.TodayStat.Recharge
text += "1️⃣充值合计:\n"
text += LineMoneyOne("┣充值合计: %s元", reCurr.Value())
text += LineMoneyOne("┃┏安卓充值: %s元", reCurr.Android.Value())
text += LineMoneyOne("┣╋苹果充值: %s元", reCurr.Ios.Value())
text += LineMoneyOne("┃┣轻量充值: %s元", reCurr.Light.Value())
text += LineMoneyOne("┃┗H5充值: %s元", reCurr.H5.Value())
text += LineMoneyOne("┃┏渠道充值: %s元", reCurr.Total.District.Value)
text += LineMoneyOne("┣╋官网充值: %s元", reCurr.Total.Web.Value)
text += LineMoneyOne("┃┣自来充值: %s元", reCurr.Total.Normal.Value)
text += LineMoneyOne("┃┗分享充值: %s元", reCurr.Total.Share.Value)
oldCurr := &s.TodayStat.RechargeOld
text += LineMoneyOne("┃┏老用户充: %s元", oldCurr.Value())
newCurr := &s.TodayStat.RechargeNew
text += LineMoneyOne("┣╋新用户充: %s元", newCurr.Value())
v0 := newCurr.Percentage(reCurr)
text += LineCountOne("┃┗新充占比: %s%%", v0.Value())
memCurr := &s.TodayStat.RechargeVip
text += LineMoneyOne("┃┏会员充值: %s元", memCurr.Value())
coinCurr := &s.TodayStat.RechargeGold
text += LineMoneyOne("┣╋金币充值: %s元", coinCurr.Value())
v1 := memCurr.Percentage(reCurr)
text += LineCountOne("┃┗会员占比: %s%%", v1.Value())
orderCurr := &s.TodayStat.Order
text += LineCountOne("┃┏订单拉起: %s", orderCurr.Count())
succCurr := &s.TodayStat.OrderSucc
text += LineCountOne("┣╋订单成功: %s", succCurr.Count())
v2 := succCurr.Percentage(orderCurr)
text += LineCountOne("┃┗成功占比: %s%%", v2.Count())
text += "2️⃣新增合计:\n"
regCurr := &s.TodayStat.Register
text += LineCountOne("┣新增用户: %s", regCurr.Count())
text += LineCountOne("┃┏安卓新增: %s", regCurr.Android.Count())
text += LineCountOne("┣╋苹果新增: %s", regCurr.Ios.Count())
text += LineCountOne("┃┣轻量新增: %s", regCurr.Light.Count())
text += LineCountOne("┃┗H5新增: %s", regCurr.H5.Count())
text += LineCountOne("┃┏渠道新增: %s", regCurr.Total.District.Count)
text += LineCountOne("┣╋官网新增: %s", regCurr.Total.Web.Count)
text += LineCountOne("┃┣自来新增: %s", regCurr.Total.Normal.Count)
text += LineCountOne("┃┗分享新增: %s", regCurr.Total.Share.Count)
text += "3️⃣日活合计:\n"
visitCurr := &s.TodayStat.Visit
text += LineCountOne("┣日活总数: %s", visitCurr.Count())
text += LineCountOne("┃┏安卓日活: %s", visitCurr.Android.Count())
text += LineCountOne("┣╋苹果日活: %s", visitCurr.Ios.Count())
text += LineCountOne("┃┣轻量日活: %s", visitCurr.Light.Count())
text += LineCountOne("┃┗H5日活: %s", visitCurr.H5.Count())
text += LineCountOne("┃┏渠道日活: %s", visitCurr.Total.District.Count)
text += LineCountOne("┣╋官网日活: %s", visitCurr.Total.Web.Count)
text += LineCountOne("┃┣自来日活: %s", visitCurr.Total.Normal.Count)
text += LineCountOne("┃┗分享日活: %s", visitCurr.Total.Share.Count)
}()
func() {
if s.AppId == 888 && s.TodayGame != nil {
text += "5️⃣游戏合计:\n"
text += fmt.Sprintf("┃┏游戏充值: %d\n", s.TodayGame.RchgAmount)
text += fmt.Sprintf("┃┣代充充值: %d\n", s.TodayGame.DcRchgAmount)
text += fmt.Sprintf("┃┣有效投注: %d\n", s.TodayGame.ValidBet)
text += fmt.Sprintf("┣╋系统盈利: %d\n", s.TodayGame.Profit)
text += fmt.Sprintf("┃┣提现金额: %d\n", s.TodayGame.WtdrRealAmount)
text += fmt.Sprintf("┃┣游戏上分: %d\n", s.TodayGame.IncAmount)
text += fmt.Sprintf("┃┗游戏下分: %d\n", s.TodayGame.DecAmount)
}
}()
return text
}
func (s *BotHourStat) GenerateTodayTable(title string, statName string, filepath string, compare *BotHourStat) (string, error) {
var text string
text += fmt.Sprintf("报告时间:%s\n", s.SumDate.Format("2006-01-02T15:04:05"))
if _, exists := statutils.StatProjectNameDict[statName]; exists {
if compare != nil {
switch statName {
case statutils.StatProjectRecharge:
return text, s.TodayStat.Recharge.Table(title, 100, &compare.TodayStat.Recharge, filepath)
case statutils.StatProjectRechargeOld:
return text, s.TodayStat.RechargeOld.Table(title, 100, &compare.TodayStat.RechargeOld, filepath)
case statutils.StatProjectRechargeNew:
return text, s.TodayStat.RechargeNew.Table(title, 100, &compare.TodayStat.RechargeNew, filepath)
case statutils.StatProjectRechargeGold:
return text, s.TodayStat.RechargeGold.Table(title, 100, &compare.TodayStat.RechargeGold, filepath)
case statutils.StatProjectRechargeVip:
return text, s.TodayStat.RechargeVip.Table(title, 100, &compare.TodayStat.RechargeVip, filepath)
case statutils.StatProjectOrder:
return text, s.TodayStat.Order.Table(title, 1, &compare.TodayStat.Order, filepath)
case statutils.StatProjectRegister:
return text, s.TodayStat.Register.Table(title, 1, &compare.TodayStat.Register, filepath)
case statutils.StatProjectVisit:
return text, s.TodayStat.Visit.Table(title, 1, &compare.TodayStat.Visit, filepath)
default:
return "", errors.New("没有指定统计项目")
}
} else {
switch statName {
case statutils.StatProjectRecharge:
return text, s.TodayStat.Recharge.Table(title, 100, nil, filepath)
case statutils.StatProjectRechargeOld:
return text, s.TodayStat.RechargeOld.Table(title, 100, nil, filepath)
case statutils.StatProjectRechargeNew:
return text, s.TodayStat.RechargeNew.Table(title, 100, nil, filepath)
case statutils.StatProjectRechargeGold:
return text, s.TodayStat.RechargeGold.Table(title, 100, nil, filepath)
case statutils.StatProjectRechargeVip:
return text, s.TodayStat.RechargeVip.Table(title, 100, nil, filepath)
case statutils.StatProjectOrder:
return text, s.TodayStat.Order.Table(title, 1, nil, filepath)
case statutils.StatProjectRegister:
return text, s.TodayStat.Register.Table(title, 1, nil, filepath)
case statutils.StatProjectVisit:
return text, s.TodayStat.Visit.Table(title, 1, nil, filepath)
default:
return "", errors.New("没有指定统计项目")
}
}
} else {
return "", errors.New("没有指定统计项目")
}
}
func (s *BotHourStat) DisplayDayHourTextWithTitle(appName string, compare *BotHourStat) (text string, title string, descript string) {
calc := func(curr, hist *statutils.Stat) (*statutils.Stat, *statutils.Stat) {
diff := curr.Sub(hist)
rate := diff.Permil(hist)
return curr, rate
}
rate := func(currValue, histValue int64) int64 {
if histValue != 0 {
return (currValue - histValue) * 1000 / histValue
} else {
return 0
}
}
title = fmt.Sprintf("%s", appName)
descript = fmt.Sprintf("统计时间: %s\n", s.SumDate.Format("2006-01-02T15"))
if compare != nil {
func() {
reCurr, reRate := calc(&s.TodayStat.Recharge, &compare.TodayStat.Recharge)
text += "1️⃣当日充值:\n"
text += LineMoney("┣充值合计:%s", reCurr.Value(), reRate.Value())
descript += LineMoney(" 今日充值:%s", reCurr.Value(), reRate.Value())
text += LineMoney("┃┏安卓充值:%s", reCurr.Android.Value(), reRate.Android.Value())
text += LineMoney("┣╋苹果充值:%s", reCurr.Ios.Value(), reRate.Ios.Value())
text += LineMoney("┃┣轻量充值:%s", reCurr.Light.Value(), reRate.Light.Value())
text += LineMoney("┃┗H5充值 :%s", reCurr.H5.Value(), reRate.H5.Value())
text += LineMoney("┃┏渠道充值:%s", reCurr.Total.District.Value, reRate.Total.District.Value)
text += LineMoney("┣╋官网充值:%s", reCurr.Total.Web.Value, reRate.Total.Web.Value)
text += LineMoney("┃┣自来充值:%s", reCurr.Total.Normal.Value, reRate.Total.Normal.Value)
text += LineMoney("┃┗分享充值:%s", reCurr.Total.Share.Value, reRate.Total.Share.Value)
oldCurr, oldRate := calc(&s.TodayStat.RechargeOld, &compare.TodayStat.RechargeOld)
text += LineMoney("┃┏老用户充:%s", oldCurr.Value(), oldRate.Value())
newCurr, newRate := calc(&s.TodayStat.RechargeNew, &compare.TodayStat.RechargeNew)
text += LineMoney("┣╋新用户充:%s", newCurr.Value(), newRate.Value())
v0, v00 := calc(newCurr.Percentage(reCurr), compare.TodayStat.RechargeNew.Percentage(&compare.TodayStat.Recharge))
text += LineCount("┃┗新充占比:%s%%", v0.Value(), v00.Value())
memCurr, memRate := calc(&s.TodayStat.RechargeVip, &compare.TodayStat.RechargeVip)
text += LineMoney("┃┏会员充值:%s", memCurr.Value(), memRate.Value())
coinCurr, coinRate := calc(&s.TodayStat.RechargeGold, &compare.TodayStat.RechargeGold)
text += LineMoney("┣╋金币充值:%s", coinCurr.Value(), coinRate.Value())
v2, v22 := calc(memCurr.Percentage(reCurr), compare.TodayStat.RechargeVip.Percentage(&compare.TodayStat.Recharge))
text += LineCount("┃┗会员占比:%s%%", v2.Value(), v22.Value())
orderCurr, orderRate := calc(&s.TodayStat.Order, &compare.TodayStat.Order)
text += LineCount("┃┏订单拉起:%s", orderCurr.Count(), orderRate.Count())
succCurr, succRate := calc(&s.TodayStat.OrderSucc, &compare.TodayStat.OrderSucc)
text += LineCount("┣╋订单成功:%s", succCurr.Count(), succRate.Count())
v1, v11 := calc(succCurr.Percentage(orderCurr), compare.TodayStat.OrderSucc.Percentage(&compare.TodayStat.Order))
text += LineCount("┃┗成功比率:%s%%", v1.Count(), v11.Count())
text += "2️⃣当日新增:\n"
regCurr, regRate := calc(&s.TodayStat.Register, &compare.TodayStat.Register)
text += LineCount("┣新增用户:%s", regCurr.Count(), regRate.Count())
descript += LineCount(" 今日新增:%s", regCurr.Count(), regRate.Count())
text += LineCount("┃┏安卓新增:%s", regCurr.Android.Count(), regRate.Android.Count())
text += LineCount("┣╋苹果新增:%s", regCurr.Ios.Count(), regRate.Ios.Count())
text += LineCount("┃┣轻量新增:%s", regCurr.Light.Count(), regRate.Light.Count())
text += LineCount("┃┗H5新增 :%s", regCurr.H5.Count(), regRate.H5.Count())
text += LineCount("┃┏渠道新增:%s", regCurr.Total.District.Count, regRate.Total.District.Count)
text += LineCount("┣╋有效新增:%s", regCurr.Total.Direct.Value()-regCurr.Total.Direct.Natural.Value,
regRate.Total.Direct.Value()-regRate.Total.Direct.Natural.Value)
text += LineCount("┣╋官网新增:%s", regCurr.Total.Web.Count, regRate.Total.Web.Count)
text += LineCount("┃┣自来新增:%s", regCurr.Total.Normal.Count, regRate.Total.Normal.Count)
text += LineCount("┃┗分享新增:%s", regCurr.Total.Share.Count, regRate.Total.Share.Count)
text += "3️⃣当日日活:\n"
visitCurr, visitRate := calc(&s.TodayStat.Visit, &compare.TodayStat.Visit)
text += LineCount("┣日活总数:%s", visitCurr.Count(), visitRate.Count())
text += LineCount("┃┏安卓日活:%s", visitCurr.Android.Count(), visitRate.Android.Count())
text += LineCount("┣╋苹果日活:%s", visitCurr.Ios.Count(), visitRate.Ios.Count())
text += LineCount("┃┣轻量日活:%s", visitCurr.Light.Count(), visitRate.Light.Count())
text += LineCount("┃┗H5日活 :%s", visitCurr.H5.Count(), visitRate.H5.Count())
text += LineCount("┃┏渠道日活:%s", visitCurr.Total.District.Count, visitRate.Total.District.Count)
text += LineCount("┣╋官网日活:%s", visitCurr.Total.Web.Count, visitRate.Total.Web.Count)
text += LineCount("┃┣自来日活:%s", visitCurr.Total.Normal.Count, visitRate.Total.Normal.Count)
text += LineCount("┃┗分享日活:%s", visitCurr.Total.Share.Count, visitRate.Total.Share.Count)
text += "4️⃣落地页点击:\n"
text += LineCount("┣总数:%s", s.TodayLandPage.LandPageTotalClick, rate(s.TodayLandPage.LandPageTotalClick, compare.TodayLandPage.LandPageTotalClick))
text += LineCount("┃┏安卓:%s", s.TodayLandPage.LandPageAndroidClick, rate(s.TodayLandPage.LandPageAndroidClick, compare.TodayLandPage.LandPageAndroidClick))
text += LineCount("┣╋商店:%s", s.TodayLandPage.LandPageIosAppstoreClick, rate(s.TodayLandPage.LandPageIosAppstoreClick, compare.TodayLandPage.LandPageIosAppstoreClick))
text += LineCount("┃┣企业:%s", s.TodayLandPage.LandPageIosFirmClick, rate(s.TodayLandPage.LandPageIosFirmClick, compare.TodayLandPage.LandPageIosFirmClick))
text += LineCount("┃┗轻量:%s", s.TodayLandPage.LandPageIosLightClick, rate(s.TodayLandPage.LandPageIosLightClick, compare.TodayLandPage.LandPageIosLightClick))
}()
func() {
reCurr, reRate := calc(&s.HourStat.Recharge, &compare.HourStat.Recharge)
text += "5️⃣小时充值:\n"
text += LineMoney("┣充值合计:%s", reCurr.Value(), reRate.Value())
descript += LineMoney(" 小时充值:%s", reCurr.Value(), reRate.Value())
text += LineMoney("┃┏安卓充值:%s", reCurr.Android.Value(), reRate.Android.Value())
text += LineMoney("┣╋苹果充值:%s", reCurr.Ios.Value(), reRate.Ios.Value())
text += LineMoney("┃┣轻量充值:%s", reCurr.Light.Value(), reRate.Light.Value())
text += LineMoney("┃┗H5充值 :%s", reCurr.H5.Value(), reRate.H5.Value())
text += LineMoney("┃┏渠道充值:%s", reCurr.Total.District.Value, reRate.Total.District.Value)
text += LineMoney("┣╋官网充值:%s", reCurr.Total.Web.Value, reRate.Total.Web.Value)
text += LineMoney("┃┣自来充值:%s", reCurr.Total.Normal.Value, reRate.Total.Normal.Value)
text += LineMoney("┃┗分享充值:%s", reCurr.Total.Share.Value, reRate.Total.Share.Value)
oldCurr, oldRate := calc(&s.HourStat.RechargeOld, &compare.HourStat.RechargeOld)
text += LineMoney("┃┏老用户充:%s", oldCurr.Value(), oldRate.Value())
newCurr, newRate := calc(&s.HourStat.RechargeNew, &compare.HourStat.RechargeNew)
text += LineMoney("┣╋新用户充:%s", newCurr.Value(), newRate.Value())
v0, v00 := calc(newCurr.Percentage(reCurr), compare.HourStat.RechargeNew.Percentage(&compare.HourStat.Recharge))
text += LineCount("┃┗新充占比:%s%%", v0.Value(), v00.Value())
memCurr, memRate := calc(&s.HourStat.RechargeVip, &compare.HourStat.RechargeVip)
text += LineMoney("┃┏会员充值:%s", memCurr.Value(), memRate.Value())
coinCurr, coinRate := calc(&s.HourStat.RechargeGold, &compare.HourStat.RechargeGold)
text += LineMoney("┣╋金币充值:%s", coinCurr.Value(), coinRate.Value())
v2, v22 := calc(memCurr.Percentage(reCurr), compare.HourStat.RechargeVip.Percentage(&compare.HourStat.Recharge))
text += LineCount("┃┗会员占比:%s%%", v2.Value(), v22.Value())
orderCurr, orderRate := calc(&s.HourStat.Order, &compare.HourStat.Order)
text += LineCount("┃┏订单拉起:%s", orderCurr.Count(), orderRate.Count())
succCurr, succRate := calc(&s.HourStat.OrderSucc, &compare.HourStat.OrderSucc)
text += LineCount("┣╋订单成功:%s", succCurr.Count(), succRate.Count())
v1, v11 := calc(succCurr.Percentage(orderCurr), compare.HourStat.OrderSucc.Percentage(&compare.HourStat.Order))
text += LineCount("┃┗订单成功率:%s%%", v1.Count(), v11.Count())
text += "6️⃣小时新增:\n"
regCurr, regRate := calc(&s.HourStat.Register, &compare.HourStat.Register)
text += LineCount("┣新增用户:%s", regCurr.Count(), regRate.Count())
descript += LineCount(" 小时新增:%s", regCurr.Count(), regRate.Count())
text += LineCount("┃┏安卓新增:%s", regCurr.Android.Count(), regRate.Android.Count())
text += LineCount("┣╋苹果新增:%s", regCurr.Ios.Count(), regRate.Ios.Count())
text += LineCount("┃┣轻量新增:%s", regCurr.Light.Count(), regRate.Light.Count())
text += LineCount("┃┗H5新增 :%s", regCurr.H5.Count(), regRate.H5.Count())
text += LineCount("┃┏渠道新增:%s", regCurr.Total.District.Count, regRate.Total.District.Count)
text += LineCount("┣╋有效新增:%s", regCurr.Total.Direct.Value()-regCurr.Total.Direct.Natural.Value,
regRate.Total.Direct.Value()-regRate.Total.Direct.Natural.Value)
text += LineCount("┣╋官网新增:%s", regCurr.Total.Web.Count, regRate.Total.Web.Count)
text += LineCount("┃┣自来新增:%s", regCurr.Total.Normal.Count, regRate.Total.Normal.Count)
text += LineCount("┃┗分享新增:%s", regCurr.Total.Share.Count, regRate.Total.Share.Count)
text += "7️⃣小时落地页点击:\n"
text += LineCount("┣总数:%s", s.HourLandPage.LandPageTotalClick, rate(s.HourLandPage.LandPageTotalClick, compare.HourLandPage.LandPageTotalClick))
text += LineCount("┃┏安卓:%s", s.HourLandPage.LandPageAndroidClick, rate(s.HourLandPage.LandPageAndroidClick, compare.HourLandPage.LandPageAndroidClick))
text += LineCount("┣╋商店:%s", s.HourLandPage.LandPageIosAppstoreClick, rate(s.HourLandPage.LandPageIosAppstoreClick, compare.HourLandPage.LandPageIosAppstoreClick))
text += LineCount("┃┣企业:%s", s.HourLandPage.LandPageIosFirmClick, rate(s.HourLandPage.LandPageIosFirmClick, compare.HourLandPage.LandPageIosFirmClick))
text += LineCount("┃┗轻量:%s", s.HourLandPage.LandPageIosLightClick, rate(s.HourLandPage.LandPageIosLightClick, compare.HourLandPage.LandPageIosLightClick))
}()
func() {
if s.TodayGame != nil {
text += "8️⃣游戏数据:\n"
text += fmt.Sprintf("┣游戏充值: %d\n", s.TodayGame.RchgAmount)
text += fmt.Sprintf("┣代充充值: %d\n", s.TodayGame.DcRchgAmount)
text += fmt.Sprintf("┣有效投注: %d\n", s.TodayGame.ValidBet)
text += fmt.Sprintf("┣系统盈利: %d\n", s.TodayGame.Profit)
text += fmt.Sprintf("┣提现金额: %d\n", s.TodayGame.WtdrRealAmount)
text += fmt.Sprintf("┣游戏上分: %d\n", s.TodayGame.IncAmount)
text += fmt.Sprintf("┗游戏下分: %d\n", s.TodayGame.DecAmount)
}
}()
text += fmt.Sprintf("🆚%s同比数据:当日的昨天%d点\n", appName, compare.SumDate.Hour())
} else {
func() {
reCurr := &s.TodayStat.Recharge
text += "1️⃣当日充值:\n"
text += LineMoneyOne("┣充值合计: %s", reCurr.Value())
text += LineMoneyOne("┃┏安卓充值: %s", reCurr.Android.Value())
text += LineMoneyOne("┣╋苹果充值: %s", reCurr.Ios.Value())
text += LineMoneyOne("┃┣轻量充值: %s", reCurr.Light.Value())
text += LineMoneyOne("┃┗H5充值: %s", reCurr.H5.Value())
text += LineMoneyOne("┃┏渠道充值: %s", reCurr.Total.District.Value)
text += LineMoneyOne("┣╋官网充值: %s", reCurr.Total.Web.Value)
text += LineMoneyOne("┃┣自来充值: %s", reCurr.Total.Normal.Value)
text += LineMoneyOne("┃┗分享充值: %s", reCurr.Total.Share.Value)
oldCurr := &s.TodayStat.RechargeOld
text += LineMoneyOne("┃┏老用户充: %s", oldCurr.Value())
newCurr := &s.TodayStat.RechargeNew
text += LineMoneyOne("┣╋新用户充: %s", newCurr.Value())
v0 := newCurr.Percentage(reCurr)
text += LineCountOne("┃┗新充占比: %s%%", v0.Value())
memCurr := &s.TodayStat.RechargeVip
text += LineMoneyOne("┃┏会员充值: %s", memCurr.Value())
coinCurr := &s.TodayStat.RechargeGold
text += LineMoneyOne("┣╋金币充值: %s", coinCurr.Value())
v1 := memCurr.Percentage(reCurr)
text += LineCountOne("┃┗会员占比: %s%%", v1.Value())
orderCurr := &s.TodayStat.Order
text += LineCountOne("┃┏订单拉起: %s", orderCurr.Count())
succCurr := &s.TodayStat.OrderSucc
text += LineCountOne("┣╋订单成功: %s", succCurr.Count())
v2 := succCurr.Percentage(orderCurr)
text += LineCountOne("┃┗成功占比: %s%%", v2.Count())
text += "2️⃣当日新增:\n"
regCurr := &s.TodayStat.Register
text += LineCountOne("┣新增用户: %s", regCurr.Count())
text += LineCountOne("┃┏安卓新增: %s", regCurr.Android.Count())
text += LineCountOne("┣╋苹果新增: %s", regCurr.Ios.Count())
text += LineCountOne("┃┣轻量新增: %s", regCurr.Light.Count())
text += LineCountOne("┃┗H5新增: %s", regCurr.H5.Count())
text += LineCountOne("┃┏渠道新增: %s", regCurr.Total.District.Count)
text += LineCountOne("┣╋官网新增: %s", regCurr.Total.Web.Count)
text += LineCountOne("┃┣自来新增: %s", regCurr.Total.Normal.Count)
text += LineCountOne("┃┗分享新增: %s", regCurr.Total.Share.Count)
text += "3️⃣当日日活:\n"
visitCurr := &s.TodayStat.Visit
text += LineCountOne("┣日活总数: %s", visitCurr.Count())
text += LineCountOne("┃┏安卓日活: %s", visitCurr.Android.Count())
text += LineCountOne("┣╋苹果日活: %s", visitCurr.Ios.Count())
text += LineCountOne("┃┣轻量日活: %s", visitCurr.Light.Count())
text += LineCountOne("┃┗H5日活: %s", visitCurr.H5.Count())
text += LineCountOne("┃┏渠道日活: %s", visitCurr.Total.District.Count)
text += LineCountOne("┣╋官网日活: %s", visitCurr.Total.Web.Count)
text += LineCountOne("┃┣自来日活: %s", visitCurr.Total.Normal.Count)
text += LineCountOne("┃┗分享日活: %s", visitCurr.Total.Share.Count)
}()
func() {
reCurr := &s.HourStat.Recharge
text += "4️⃣小时充值:\n"
text += LineMoneyOne(" ┣充值合计: %s", reCurr.Value())
text += LineMoneyOne(" ┣安卓充值: %s", reCurr.Android.Value())
text += LineMoneyOne(" ┣苹果充值: %s", reCurr.Ios.Value())
text += LineMoneyOne(" ┣轻量充值: %s", reCurr.Light.Value())
text += LineMoneyOne(" ┣H5充值: %s", reCurr.H5.Value())
text += LineMoneyOne(" ┣渠道充值: %s", reCurr.Total.District.Value)
text += LineMoneyOne(" ┣官网充值: %s", reCurr.Total.Web.Value)
text += LineMoneyOne(" ┣自来充值: %s", reCurr.Total.Normal.Value)
oldCurr := &s.HourStat.RechargeOld
text += LineMoneyOne(" ┣老用户充: %s", oldCurr.Value())
newCurr := &s.HourStat.RechargeNew
text += LineMoneyOne(" ┣新用户充: %s", newCurr.Value())
memCurr := &s.HourStat.RechargeVip
text += LineMoneyOne(" ┣会员充值: %s", memCurr.Value())
coinCurr := &s.HourStat.RechargeGold
text += LineMoneyOne(" ┣金币充值: %s", coinCurr.Value())
orderCurr := &s.HourStat.Order
text += LineCountOne(" ┣订单拉起: %s", orderCurr.Count())
succCurr := &s.HourStat.OrderSucc
text += LineCountOne(" ┣订单成功: %s", succCurr.Count())
v1 := succCurr.Percentage(orderCurr)
text += LineCountOne(" ┗订单成功率: %s%%", v1.Count())
text += "5️⃣小时新增:\n"
regCurr := &s.HourStat.Register
text += LineCountOne(" ┣新增用户: %s", regCurr.Count())
text += LineCountOne(" ┣安卓新增: %s", regCurr.Android.Count())
text += LineCountOne(" ┣苹果新增: %s", regCurr.Ios.Count())
text += LineCountOne(" ┣轻量新增: %s", regCurr.Light.Count())
text += LineCountOne(" ┣H5新增: %s", regCurr.H5.Count())
text += LineCountOne(" ┣渠道新增: %s", regCurr.Total.District.Count)
text += LineCountOne(" ┣官网新增: %s", regCurr.Total.Web.Count)
text += LineCountOne(" ┗自来新增: %s", regCurr.Total.Normal.Count)
}()
func() {
if s.TodayGame != nil {
text += "5️⃣游戏数据:\n"
text += fmt.Sprintf(" ┣游戏充值: %d\n", s.TodayGame.RchgAmount)
text += fmt.Sprintf(" ┣代充充值: %d\n", s.TodayGame.DcRchgAmount)
text += fmt.Sprintf(" ┣有效投注: %d\n", s.TodayGame.ValidBet)
text += fmt.Sprintf(" ┣系统盈利: %d\n", s.TodayGame.Profit)
text += fmt.Sprintf(" ┣提现金额: %d\n", s.TodayGame.WtdrRealAmount)
text += fmt.Sprintf(" ┣游戏上分: %d\n", s.TodayGame.IncAmount)
text += fmt.Sprintf(" ┗游戏下分: %d\n", s.TodayGame.DecAmount)
}
}()
text += fmt.Sprintf("🆚【%s】同比数据未找到\n", appName)
}
return text, title, descript
}
+146
View File
@@ -0,0 +1,146 @@
package botdailyhourstat
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var db *mongos.MongoTool
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.New(mongos.MgoManager, CollName)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: "appId", Value: 1},
{Key: "sumDate", Value: 1},
},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{
{Key: "appId", Value: 1},
},
},
{
Keys: bson.D{
{Key: "sumDate", Value: 1},
},
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(BotHourStat:Init) Create BotHourStat Index failed! err:%+v:", err))
}
}
// InsertOneBotHourStat 插入一个机器人小时统计
func InsertOneBotHourStat(ctx context.Context, botHourStat *BotHourStat) error {
if _, err := db.InsertOne(ctx, botHourStat); err != nil {
log.Warn("botHourStat:InsertOneBotHourStat db.InsertOne failed", log.E(err))
return err
}
return nil
}
// FindOneBotHourStat 查找一个机器人小时统计
func FindOneBotHourStat(ctx context.Context, filter bson.M) (*BotHourStat, error) {
var botHourStat BotHourStat
if err := db.FindOne(ctx, &botHourStat, filter); err != nil {
return nil, err
}
return &botHourStat, nil
}
// FindOneBotHourStatEx 查找一个机器人小时统计
func FindOneBotHourStatEx(ctx context.Context, filter bson.M) (*BotHourStat, error) {
var botHourStat BotHourStat
if err := db.FindOneEx(ctx, &botHourStat, filter); err != nil {
return nil, err
}
return &botHourStat, nil
}
// DelOneBotHourStat 删除一个机器人小时统计
func DelOneBotHourStat(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("BotHourStat:DelOneBotHourStat db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateOneBotHourStat 更新一个机器人小时统计
func UpdateOneBotHourStat(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateOneBotHourStat db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// CountBotHourStats 统计机器人小时统计数量
func CountBotHourStats(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("BotHourStat:CountBotHourStats db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateManyBotHourStat 更新满足条件的机器人小时统计
func UpdateManyBotHourStat(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyBotHourStat db.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// FindManyBotHourStat 查找一批机器人小时统计数据
func FindManyBotHourStat(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (BotHourStatList, error) {
data := make(BotHourStatList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("BotHourStat:FindManyBotHourStat db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
// FindManyBotHourStatWithBind 用自己定义结构查找一批机器人小时统计数据
func FindManyBotHourStatWithBind(ctx context.Context, bind interface{}, filter bson.M,
opts ...*options.FindOptions) error {
if err := db.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("BotHourStat:FindManyBotHourStatWithBind db.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// AggregateBotHourStats 聚合查找一批机器人小时统计信息
func AggregateBotHourStats(ctx context.Context, bind interface{}, pipeline []bson.M) error {
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("feedback:AggregateBotHourStats db.Aggregate failed",
log.E(err), log.Any("pipeline", pipeline))
return err
}
return nil
}
+105
View File
@@ -0,0 +1,105 @@
package botdailyhourstat
import (
"stat/common/statutils"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
const CollName = "bot_daily_hour_stat"
type GameItem struct {
RchgAmount int64 `json:"rchgAmount" bson:"rchg_amount"` //充值总金额
DcRchgAmount int64 `json:"dcRchgAmount" bson:"dcRchgAmount"` //代充总金额
WtdrAmount int64 `json:"wtdrAmount" bson:"wtdrAmount"` //游戏提现总金额
WtdrRealAmount int64 `json:"wtdrRealAmount" bson:"wtdrRealAmount"` //游戏实际提现总金额
IncAmount int64 `json:"incAmount" bson:"incAmount"` //游戏上分总金额
DecAmount int64 `json:"decAmount" bson:"decAmount"` //游戏下分总金额
ValidBet int64 `json:"validBet" bson:"validBet"` //有效投注金额
Profit int64 `json:"profit" bson:"profit"` //系统盈利
}
func (g *GameItem) ACC(d *GameItem) {
if g == nil || d == nil {
return
}
g.RchgAmount += d.RchgAmount
g.DcRchgAmount += d.DcRchgAmount
g.WtdrAmount += d.WtdrAmount
g.WtdrRealAmount += d.WtdrRealAmount
g.IncAmount += d.IncAmount
g.DecAmount += d.DecAmount
g.ValidBet += d.ValidBet
g.Profit += d.Profit
}
type LandPage struct {
LandPageTotalClick int64 `bson:"landPageTotalClick,omitempty" json:"landPageTotalClick"` // 落地页访问总次数
LandPageAndroidClick int64 `bson:"landPageAndroidClick,omitempty" json:"landPageAndroidClick"` // 落地页android访问次数
LandPageIosAppstoreClick int64 `bson:"landPageIosAppstoreClick,omitempty" json:"landPageIosAppstoreClick"` // 落地页iOS商店包访问次数
LandPageIosFirmClick int64 `bson:"landPageIosFirmClick,omitempty" json:"landPageIosFirmClick"` // 落地页iOS企业包访问次数
LandPageIosLightClick int64 `bson:"landPageIosLightClick,omitempty" json:"landPageIosLightClick"` // 落地页iOS轻量版访问次数
}
func (s *LandPage) ACC(d *LandPage) {
s.LandPageTotalClick += d.LandPageTotalClick
s.LandPageAndroidClick += d.LandPageAndroidClick
s.LandPageIosAppstoreClick += d.LandPageIosAppstoreClick
s.LandPageIosFirmClick += d.LandPageIosFirmClick
s.LandPageIosLightClick += d.LandPageIosLightClick
}
type StatItem struct {
// 充值
Recharge statutils.Stat `json:"recharge" bson:"recharge"` // 充值
RechargeOld statutils.Stat `json:"rechargeOld" bson:"rechargeOld"` // 老用户充值
RechargeNew statutils.Stat `json:"rechargeNew" bson:"rechargeNew"` // 新用户充值
RechargeGold statutils.Stat `json:"rechargeGold" bson:"rechargeGold"` // 金币充值
RechargeVip statutils.Stat `json:"rechargeVip" bson:"rechargeVip"` // 会员充值
// 订单
Order statutils.Stat `json:"order" bson:"order"` // 所有订单
OrderSucc statutils.Stat `json:"orderSucc" bson:"orderSucc"` // 成功订单
// 注册
Register statutils.Stat `json:"register" bson:"register"` // 注册
// 访问
Visit statutils.Stat `json:"visit" bson:"visit"` // 访问
}
func (s *StatItem) ACC(d *StatItem) {
s.Recharge.ACC(&d.Recharge)
s.RechargeOld.ACC(&d.RechargeOld)
s.RechargeNew.ACC(&d.RechargeNew)
s.RechargeGold.ACC(&d.RechargeGold)
s.RechargeVip.ACC(&d.RechargeVip)
s.Order.ACC(&d.Order)
s.OrderSucc.ACC(&d.OrderSucc)
s.Register.ACC(&d.Register)
s.Visit.ACC(&d.Visit)
}
// @table:bot_hour_stat
type BotHourStat struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // ID
AppId int32 `json:"appId" bson:"appId"` // appId,唯一id
Reported bool `json:"reported" bson:"reported"` // 是否已汇报
ReportTime time.Time `json:"reportTime" bson:"reportTime"` // 汇报时间
SumDate time.Time `json:"sumDate" bson:"sumDate"` // 记录时间 按小时对齐
TodayStat StatItem `json:"todayStat" bson:"todayStat"` // 今日
HourStat StatItem `json:"hourStat" bson:"hourStat"` // 小时
TodayGame *GameItem `json:"todayGame" bson:"todayGame,omitempty"` // 游戏
TodayLandPage LandPage `json:"todayLandPage" bson:"todayLandPage"` // 今日落地页
HourLandPage LandPage `json:"hourLandPage" bson:"hourLandPage"` // 小时落地页
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 修改时间
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
}
func (s *BotHourStat) ACC(d *BotHourStat) {
s.TodayStat.ACC(&d.TodayStat)
s.HourStat.ACC(&d.HourStat)
s.TodayGame.ACC(d.TodayGame)
s.TodayLandPage.ACC(&d.TodayLandPage)
s.HourLandPage.ACC(&d.HourLandPage)
}
type BotHourStatList []*BotHourStat
+127
View File
@@ -0,0 +1,127 @@
package botreport
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var db *mongos.MongoTool
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.New(mongos.MgoManager, TN.BotReport)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.BotReport.SumDate, Value: 1},
},
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(BotReport:initBotReportIndex) Create BotReport Index failed! err:%+v:", err))
}
}
//InsertOneBotReport 插入一个VIP购买记录
func InsertOneBotReport(ctx context.Context, BotReport *BotReport) error {
if _, err := db.InsertOne(ctx, BotReport); err != nil {
log.Warn("BotReport:InsertOneBotReport db.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneBotReport 查找一个VIP购买记录
func FindOneBotReport(ctx context.Context, filter bson.M) (
*BotReport, error) {
var BotReport BotReport
if err := db.FindOne(ctx, &BotReport, filter); err != nil {
return nil, err
}
return &BotReport, nil
}
//DelOneBotReport 删除一个VIP购买记录
func DelOneBotReport(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("BotReport:DelOneBotReport db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateOneBotReport 更新一个VIP购买记录
func UpdateOneBotReport(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateOneBotReport db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//CountBotReports 统计VIP购买记录数量
func CountBotReports(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("BotReport:CountBotReports db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateManyBotReport 更新满足条件的VIP购买记录
func UpdateManyBotReport(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyBotReport db.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//FindManyBotReport 查找一批VIP购买记录数据
func FindManyBotReport(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (BotReportList, error) {
data := make(BotReportList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("BotReport:FindManyBotReport db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
//FindManyBotReportWithBind 用自己定义结构查找一批VIP购买记录数据
func FindManyBotReportWithBind(ctx context.Context, bind interface{}, filter bson.M,
opts ...*options.FindOptions) error {
if err := db.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("BotReport:FindManyBotReportWithBind db.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//AggregateBotReports 聚合查找一批VIP购买记录信息
func AggregateBotReports(ctx context.Context,
bind interface{}, pipeline []bson.M) error {
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("feedback:AggregateBotReports db.Aggregate failed",
log.E(err), log.Any("pipeline", pipeline))
return err
}
return nil
}
+224
View File
@@ -0,0 +1,224 @@
package botreport
type TagBotReport struct {
AccessUser string
TodayAccessIos string
TodayAccessAndroid string
AppId string
CreatedAt string
GameDCRchgAmount string
GameDCRchgCount string
GameDecAmount string
GameDecCount string
GameFirstRchgAmount string
GameFirstRchgCount string
GameFirstRchgUsers string
GameGiftIncAmount string
GameGiftIncCount string
GameIncAmount string
GameInchCount string
GamePlayCount string
GameRchGiftIncAmount string
GameRchGiftIncCount string
GameRchgAmount string
GameRchgCount string
GameRchgUsers string
GameVipGiftIncAmount string
GameVipGiftIncCount string
GameWtdrAmount string
GameWtdrCount string
GameWtdrRealAmount string
HourAndroidNew string
HourAndroidNewRecharge string
HourAndroidRecharge string
HourDistrictRecharge string
HourDistrictVip string
HourH5New string
HourH5NewRecharge string
HourH5Recharge string
HourIosNew string
HourIosNewRecharge string
HourIosRecharge string
HourNew string
HourNewDistrict string
HourNewNormal string
HourNewRecharge string
HourNewWeb string
HourNormalRecharge string
HourNormalVip string
HourOldRecharge string
HourOrder string
HourRecharge string
HourSuccessOrder string
HourVipRecharge string
HourWebRecharge string
HourWebVip string
ID string
Profit string
Revenue string
SumDate string
TodayAccessH5 string
TodayAndroidNew string
TodayAndroidNewRecharge string
TodayAndroidRecharge string
TodayDistrictRecharge string
TodayDistrictVip string
TodayH5New string
TodayH5NewRecharge string
TodayH5Recharge string
TodayIosNew string
TodayIosNewRecharge string
TodayIosRecharge string
TodayNew string
TodayNewDistrict string
TodayNewNormal string
TodayNewRecharge string
TodayNewWeb string
TodayNormalRecharge string
TodayNormalVip string
TodayOldRecharge string
TodayOrder string
TodayRecharge string
TodaySuccessOrder string
TodayVipRecharge string
TodayWebRecharge string
TodayWebVip string
ValidBet string
TodayAccessH5Pc string
TodayAccessH5Ios string
TodayAccessH5Android string
TodayH5PcNew string
TodayH5IosNew string
TodayH5AndroidNew string
TodayH5PcRecharge string
TodayH5IosRecharge string
TodayH5AndroidRecharge string
TodayH5PcNewRecharge string
TodayH5IosNewRecharge string
TodayH5AndroidNewRecharge string
HourH5PcNew string
HourH5IosNew string
HourH5AndroidNew string
HourH5PcRecharge string
HourH5IosRecharge string
HourH5AndroidRecharge string
HourH5PcNewRecharge string
HourH5IosNewRecharge string
HourH5AndroidNewRecharge string
}
var FN struct {
BotReport TagBotReport
}
var TN struct {
BotReport string
}
func init() {
FN.BotReport.AccessUser = "accessUser"
FN.BotReport.AppId = "appId"
FN.BotReport.CreatedAt = "createdAt"
FN.BotReport.GameDCRchgAmount = "gameDCRchgAmount"
FN.BotReport.GameDCRchgCount = "gameDCRchgCount"
FN.BotReport.GameDecAmount = "gameDecAmount"
FN.BotReport.GameDecCount = "gameDecCount"
FN.BotReport.GameFirstRchgAmount = "gameFirstRchgAmount"
FN.BotReport.GameFirstRchgCount = "gameFirstRchgCount"
FN.BotReport.GameFirstRchgUsers = "gameFirstRchgUsers"
FN.BotReport.GameGiftIncAmount = "gameGiftIncAmount"
FN.BotReport.GameGiftIncCount = "gameGiftIncCount"
FN.BotReport.GameIncAmount = "gameIncAmount"
FN.BotReport.GameInchCount = "gameInchCount"
FN.BotReport.GamePlayCount = "gamePlayCount"
FN.BotReport.GameRchGiftIncAmount = "gameRchGiftIncAmount"
FN.BotReport.GameRchGiftIncCount = "gameRchGiftIncCount"
FN.BotReport.GameRchgAmount = "gameRchgAmount"
FN.BotReport.GameRchgCount = "gameRchgCount"
FN.BotReport.GameRchgUsers = "gameRchgUsers"
FN.BotReport.GameVipGiftIncAmount = "gameVipGiftIncAmount"
FN.BotReport.GameVipGiftIncCount = "gameVipGiftIncCount"
FN.BotReport.GameWtdrAmount = "gameWtdrAmount"
FN.BotReport.GameWtdrCount = "gameWtdrCount"
FN.BotReport.GameWtdrRealAmount = "gameWtdrRealAmount"
FN.BotReport.HourAndroidNew = "hourAndroidNew"
FN.BotReport.HourAndroidNewRecharge = "hourAndroidNewRecharge"
FN.BotReport.HourAndroidRecharge = "hourAndroidRecharge"
FN.BotReport.HourDistrictRecharge = "hourDistrictRecharge"
FN.BotReport.HourDistrictVip = "hourDistrictVip"
FN.BotReport.HourH5New = "hourH5New"
FN.BotReport.HourH5NewRecharge = "HourH5NewRecharge"
FN.BotReport.HourH5Recharge = "HourH5Recharge"
FN.BotReport.HourIosNew = "hourIosNew"
FN.BotReport.HourIosNewRecharge = "hourIosNewRecharge"
FN.BotReport.HourIosRecharge = "hourIosRecharge"
FN.BotReport.HourNew = "hourNew"
FN.BotReport.HourNewDistrict = "hourNewDistrict"
FN.BotReport.HourNewNormal = "hourNewNormal"
FN.BotReport.HourNewRecharge = "hourNewRecharge"
FN.BotReport.HourNewWeb = "hourNewWeb"
FN.BotReport.HourNormalRecharge = "hourNormalRecharge"
FN.BotReport.HourNormalVip = "hourNormalVip"
FN.BotReport.HourOldRecharge = "hourOldRecharge"
FN.BotReport.HourOrder = "hourOrder"
FN.BotReport.HourRecharge = "hourRecharge"
FN.BotReport.HourSuccessOrder = "hourSuccessOrder"
FN.BotReport.HourVipRecharge = "hourVipRecharge"
FN.BotReport.HourWebRecharge = "hourWebRecharge"
FN.BotReport.HourWebVip = "hourWeVip"
FN.BotReport.ID = "_id"
FN.BotReport.Profit = "profit"
FN.BotReport.Revenue = "revenue"
FN.BotReport.SumDate = "sumDate"
FN.BotReport.TodayAccessH5 = "todayAccessH5"
FN.BotReport.TodayAndroidNew = "todayAndroidNew"
FN.BotReport.TodayAndroidNewRecharge = "todayAndroidNewRecharge"
FN.BotReport.TodayAndroidRecharge = "todayAndroidRecharge"
FN.BotReport.TodayDistrictRecharge = "todayDistrictRecharge"
FN.BotReport.TodayDistrictVip = "todayDistrictVip"
FN.BotReport.TodayH5New = "todayH5New"
FN.BotReport.TodayH5NewRecharge = "todayH5NewRecharge"
FN.BotReport.TodayH5Recharge = "todayH5Recharge"
FN.BotReport.TodayIosNew = "todayIosNew"
FN.BotReport.TodayIosNewRecharge = "todayIosNewRecharge"
FN.BotReport.TodayIosRecharge = "todayIosRecharge"
FN.BotReport.TodayNew = "todayNew"
FN.BotReport.TodayNewDistrict = "todayNewDistrict"
FN.BotReport.TodayNewNormal = "todayNewNormal"
FN.BotReport.TodayNewRecharge = "todayNewRecharge"
FN.BotReport.TodayNewWeb = "todayNewWeb"
FN.BotReport.TodayNormalRecharge = "todayNormalRecharge"
FN.BotReport.TodayNormalVip = "todayNormalVip"
FN.BotReport.TodayOldRecharge = "todayOldRecharge"
FN.BotReport.TodayOrder = "todayOrder"
FN.BotReport.TodayRecharge = "todayRecharge"
FN.BotReport.TodaySuccessOrder = "todaySuccessOrder"
FN.BotReport.TodayVipRecharge = "todayVipRecharge"
FN.BotReport.TodayWebRecharge = "todayWebRecharge"
FN.BotReport.TodayWebVip = "todayWebVip"
FN.BotReport.ValidBet = "validBet"
FN.BotReport.TodayAccessH5Pc = "todayAccessH5Pc"
FN.BotReport.TodayAccessH5Ios = "todayAccessH5Ios"
FN.BotReport.TodayAccessH5Android = "todayAccessH5Android"
FN.BotReport.TodayH5PcNew = "todayH5PcNew"
FN.BotReport.TodayH5IosNew = "todayH5IosNew"
FN.BotReport.TodayH5AndroidNew = "todayH5AndroidNew"
FN.BotReport.TodayH5PcRecharge = "todayH5PcRecharge"
FN.BotReport.TodayH5IosRecharge = "todayH5IosRecharge"
FN.BotReport.TodayH5AndroidRecharge = "todayH5AndroidRecharge"
FN.BotReport.TodayH5PcNewRecharge = "todayH5PcNewRecharge"
FN.BotReport.TodayH5IosNewRecharge = "todayH5IosNewRecharge"
FN.BotReport.TodayH5AndroidNewRecharge = "todayH5AndroidNewRecharge"
FN.BotReport.HourH5PcNew = "hourH5PcNew"
FN.BotReport.HourH5IosNew = "hourH5IosNew"
FN.BotReport.HourH5AndroidNew = "hourH5AndroidNew"
FN.BotReport.HourH5PcRecharge = "hourH5PcRecharge"
FN.BotReport.HourH5IosRecharge = "hourH5IosRecharge"
FN.BotReport.HourH5AndroidRecharge = "hourH5AndroidRecharge"
FN.BotReport.HourH5PcNewRecharge = "hourH5PcNewRecharge"
FN.BotReport.HourH5IosNewRecharge = "hourH5IosNewRecharge"
FN.BotReport.HourH5AndroidNewRecharge = "hourH5AndroidNewRecharge"
FN.BotReport.TodayAccessIos = "todayAccessIos"
FN.BotReport.TodayAccessAndroid = "todayAccessAndroid"
TN.BotReport = "bot_report"
}
+145
View File
@@ -0,0 +1,145 @@
package botreport
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// @table:bot_report
type BotReport struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // ID
AppId int32 `json:"appId" bson:"appId"` // appId,唯一id
SumDate time.Time `json:"sumDate" bson:"sumDate"` // 记录时间 按天对齐
TodayRecharge int64 `json:"todayRecharge" bson:"todayRecharge"` // 当日累计充值
HourRecharge int64 `json:"hourRecharge" bson:"hourRecharge"` // 单小时充值
AccessUser int64 `json:"accessUser" bson:"accessUser"` // 当日日活
TodayAccessDistrict int64 `json:"todayAccessDistrict" bson:"todayAccessDistrict"` // +当日渠道日活
TodayAccessIos int64 `json:"todayAccessIos" bson:"todayAccessIos"` // *当日IOS日活
TodayAccessAndroid int64 `json:"todayAccessAndroid" bson:"todayAccessAndroid"` // *当日Android日活
TodayAccessH5 int64 `json:"todayAccessH5" bson:"todayAccessH5"` // *当日H5日活
TodayAccessH5Pc int64 `json:"todayAccessH5Pc" bson:"todayAccessH5Pc"` // *当日H5PC日活
TodayAccessH5Ios int64 `json:"todayAccessH5Ios" bson:"todayAccessH5Ios"` // *当日H5IOS日活
TodayAccessH5Android int64 `json:"todayAccessH5Android" bson:"todayAccessH5Android"` // *当日H5Android日活
TodayAccessH5District int64 `json:"todayAccessH5District" bson:"todayAccessH5District"` // +当日H5渠道日活
TodayOrder int64 `json:"todayOrder" bson:"todayOrder"` // 当日订单数
TodaySuccessOrder int64 `json:"todaySuccessOrder" bson:"todaySuccessOrder"` // 当日成功订单数
HourOrder int64 `json:"hourOrder" bson:"hourOrder"` // 单小时订单数
HourSuccessOrder int64 `json:"hourSuccessOrder" bson:"hourSuccessOrder"` // 单小时成功单数
TodayNewDistrict int64 `json:"todayNewDistrict" bson:"todayNewDistrict"` // 当日渠道新增
TodayNewWeb int64 `json:"todayNewWeb" bson:"todayNewWeb"` // 当日官网新增
TodayNewNormal int64 `json:"todayNewNormal" bson:"todayNewNormal"` // 当日自来量(分享和官方)
TodayNew int64 `json:"todayNew" bson:"todayNew"` // 当日新增
TodayAndroidNew int64 `json:"todayAndroidNew" bson:"todayAndroidNew"` // 当日android新增
TodayIosNew int64 `json:"todayIosNew" bson:"todayIosNew"` // 当日Ios新增
TodayH5New int64 `json:"todayH5New" bson:"todayH5New"` // 当日H5新增
TodayH5PcNew int64 `json:"todayH5PcNew" bson:"todayH5PcNew"` // *当日H5PC新增
TodayH5IosNew int64 `json:"todayH5IosNew" bson:"todayH5IosNew"` // *当日H5IOS新增
TodayH5AndroidNew int64 `json:"todayH5AndroidNew" bson:"todayH5AndroidNew"` // *当日H5Android新增
TodayH5DistrictNew int64 `json:"todayH5DistrictNew" bson:"todayH5DistrictNew"` // +当日H5渠道新增
TodayDistrictRecharge int64 `json:"todayDistrictRecharge" bson:"todayDistrictRecharge"` // 当日渠道充值新增
TodayWebRecharge int64 `json:"todayWebRecharge" bson:"todayWebRecharge"` // 当日官网充值新增
TodayNormalRecharge int64 `json:"todayNormalRecharge" bson:"todayNormalRecharge"` // 当日自来量充值新增
TodayVipRecharge int64 `json:"todayVipRecharge" bson:"todayVipRecharge"` // 当日渠道充值新增
TodayAndroidRecharge int64 `json:"todayAndroidRecharge" bson:"todayAndroidRecharge"` // 当日android充值
TodayIosRecharge int64 `json:"todayIosRecharge" bson:"todayIosRecharge"` // 当日Ios充值
TodayH5Recharge int64 `json:"todayH5Recharge" bson:"todayH5Recharge"` // 当日H5充值
TodayH5PcRecharge int64 `json:"todayH5PcRecharge" bson:"todayH5PcRecharge"` // *当日H5PC充值
TodayH5IosRecharge int64 `json:"todayH5IosRecharge" bson:"todayH5IosRecharge"` // *当日H5IOS充值
TodayH5AndroidRecharge int64 `json:"todayH5AndroidRecharge" bson:"todayH5AndroidRecharge"` // *当日H5Android充值
TodayH5DistrictRecharge int64 `json:"todayH5DistrictRecharge" bson:"todayH5DistrictRecharge"` // +当日H5渠道充值
TodayNewRecharge int64 `json:"todayNewRecharge" bson:"todayNewRecharge"` // 当日新增充值
TodayIosNewRecharge int64 `json:"todayIosNewRecharge" bson:"todayIosNewRecharge"` // 当日Ios新增充值
TodayH5NewRecharge int64 `json:"todayH5NewRecharge" bson:"todayH5NewRecharge"` // 当日H5新增充值
TodayH5PcNewRecharge int64 `json:"todayH5PcNewRecharge" bson:"todayH5PcNewRecharge"` // *当日H5Pc新增充值
TodayH5IosNewRecharge int64 `json:"todayH5IosNewRecharge" bson:"todayH5IosNewRecharge"` // *当日H5Ios新增充值
TodayH5AndroidNewRecharge int64 `json:"todayH5AndroidNewRecharge" bson:"todayH5AndroidNewRecharge"` // *当日H5Android新增充值
TodayH5DistrictNewRecharge int64 `json:"todayH5DistrictNewRecharge" bson:"todayH5DistrictNewRecharge"` // +当日H5渠道新增充值
TodayAndroidNewRecharge int64 `json:"todayAndroidNewRecharge" bson:"todayAndroidNewRecharge"` // 当日android新增充值
TodayOldRecharge int64 `json:"todayOldRecharge" bson:"todayOldRecharge"` // 当日老用户充值
TodayDistrictVip int64 `json:"todayDistrictVip" bson:"todayDistrictVip"` // 单小时渠道VIP充值
TodayWebVip int64 `json:"todayWebVip" bson:"todayWebVip"` // 单小时官网VIP充值
TodayNormalVip int64 `json:"todayNormalVip" bson:"todayNormalVip"` // 单小时自来量充值新增
HourNewDistrict int64 `json:"hourNewDistrict" bson:"hourNewDistrict"` // 单小时渠道新增
HourNewWeb int64 `json:"hourNewWeb" bson:"hourNewWeb"` // 单小时官网新增
HourNewNormal int64 `json:"hourNewNormal" bson:"hourNewNormal"` // 单小时自来量(分享和官方)
HourNew int64 `json:"hourNew" bson:"hourNew"` // 单小时新增
HourAndroidNew int64 `json:"hourAndroidNew" bson:"hourAndroidNew"` // 单小时android新增
HourIosNew int64 `json:"hourIosNew" bson:"hourIosNew"` // 单小时Ios新增
HourH5New int64 `json:"hourH5New" bson:"hourH5New"` // 单小时H5新增
HourH5PcNew int64 `json:"hourH5PcNew" bson:"hourH5PcNew"` // *单小时H5Pc新增
HourH5IosNew int64 `json:"hourH5IosNew" bson:"hourH5IosNew"` // *单小时H5Ios新增
HourH5AndroidNew int64 `json:"hourH5AndroidNew" bson:"hourH5AndroidNew"` // *单小时H5Android新增
HourH5DistrictNew int64 `json:"hourH5DistrictNew" bson:"hourH5DistrictNew"` // +单小时H5渠道新增
HourDistrictRecharge int64 `json:"hourDistrictRecharge" bson:"hourDistrictRecharge"` // 单小时渠道充值新增
HourWebRecharge int64 `json:"hourWebRecharge" bson:"hourWebRecharge"` // 单小时官网充值新增
HourNormalRecharge int64 `json:"hourNormalRecharge" bson:"hourNormalRecharge"` // 单小时自来量充值新增
HourVipRecharge int64 `json:"hourVipRecharge" bson:"hourVipRecharge"` // 单小时VIP充值
HourDistrictVip int64 `json:"hourDistrictVip" bson:"hourDistrictVip"` // 单小时渠道VIP充值
HourWebVip int64 `json:"hourWebVip" bson:"hourWeVip"` // 单小时官网VIP充值
HourAndroidRecharge int64 `json:"hourAndroidRecharge" bson:"hourAndroidRecharge"` // 单小时android充值
HourIosRecharge int64 `json:"hourIosRecharge" bson:"hourIosRecharge"` // 单小时Ios充值
HourH5Recharge int64 `json:"HourH5Recharge" bson:"HourH5Recharge"` // 单小时H5充值
HourH5PcRecharge int64 `json:"hourH5PcRecharge" bson:"hourH5PcRecharge"` // *单小时H5Pc充值
HourH5IosRecharge int64 `json:"hourH5IosRecharge" bson:"hourH5IosRecharge"` // *单小时H5Ios充值
HourH5AndroidRecharge int64 `json:"hourH5AndroidRecharge" bson:"hourH5AndroidRecharge"` // *单小时H5Android充值
HourH5DistrictRecharge int64 `json:"hourH5DistrictRecharge" bson:"hourH5DistrictRecharge"` // +单小时H5渠道充值
HourNormalVip int64 `json:"hourNormalVip" bson:"hourNormalVip"` // 单小时自来量充值新增
HourNewRecharge int64 `json:"hourNewRecharge" bson:"hourNewRecharge"` // 单小时新增充值
HourIosNewRecharge int64 `json:"hourIosNewRecharge" bson:"hourIosNewRecharge"` // 单小时Ios新增充值
HourH5NewRecharge int64 `json:"HourH5NewRecharge" bson:"HourH5NewRecharge"` // 单小时H5新增充值
HourH5PcNewRecharge int64 `json:"hourH5PcNewRecharge" bson:"hourH5PcNewRecharge"` // *单小时H5Pc新增充值
HourH5IosNewRecharge int64 `json:"hourH5IosNewRecharge" bson:"hourH5IosNewRecharge"` // *单小时H5Ios新增充值
HourH5AndroidNewRecharge int64 `json:"hourH5AndroidNewRecharge" bson:"hourH5AndroidNewRecharge"` // *单小时H5Android新增充值
HourH5DistrictNewRecharge int64 `json:"hourH5DistrictNewRecharge" bson:"hourH5DistrictNewRecharge"` // +单小时H5渠道新增充值
HourAndroidNewRecharge int64 `json:"hourAndroidNewRecharge" bson:"hourAndroidNewRecharge"` // 单小时android新增充值
HourOldRecharge int64 `json:"hourOldRecharge" bson:"hourOldRecharge"` // 单小时用户充值
GameRchgAmount int64 `json:"gameRchgAmount" bson:"gameRchgAmount"` //充值总金额
GameDCRchgAmount int64 `json:"gameDCRchgAmount" bson:"gameDCRchgAmount"` //代充总金额
GameWtdrAmount int64 `json:"gameWtdrAmount" bson:"gameWtdrAmount"` //游戏提现总金额
GameWtdrRealAmount int64 `json:"gameWtdrRealAmount" bson:"gameWtdrRealAmount"` //游戏实际提现总金额
GameIncAmount int64 `json:"gameIncAmount" bson:"gameIncAmount"` //游戏上分总金额
GameDecAmount int64 `json:"gameDecAmount" bson:"gameDecAmount"` //游戏下分总金额
ValidBet int64 `json:"validBet" bson:"validBet"` //有效投注金额
Profit int64 `json:"profit" bson:"profit"` //系统盈利
GameRchgCount int64 `json:"gameRchgCount" bson:"gameRchgCount"`
//活跃人数
GamePlayCount int64 `json:"gamePlayCount" bson:"gamePlayCount"`
//游戏成功充值人数
GameRchgUsers int64 `json:"gameRchgUsers" bson:"gameRchgUsers"`
//游戏首次充值总金额
GameFirstRchgAmount int64 `json:"gameFirstRchgAmount" bson:"gameFirstRchgAmount"`
//游戏首次成功充值次数
GameFirstRchgCount int64 `json:"gameFirstRchgCount" bson:"gameFirstRchgCount"`
//游戏首次成功充值人数
GameFirstRchgUsers int64 `json:"gameFirstRchgUsers" bson:"gameFirstRchgUsers"`
//游戏成功代充次数
GameDCRchgCount int64 `json:"gameDCRchgCount" bson:"gameDCRchgCount"`
//游戏成功提现次数
GameWtdrCount int64 `json:"gameWtdrCount" bson:"gameWtdrCount"`
//游戏上分次数
GameInchCount int64 `json:"gameInchCount" bson:"gameInchCount"`
//游戏下分次数
GameDecCount int64 `json:"gameDecCount" bson:"gameDecCount"`
//游戏6元赠送总金额
GameGiftIncAmount int64 `json:"gameGiftIncAmount" bson:"gameGiftIncAmount"`
//游戏6元赠送次数
GameGiftIncCount int64 `json:"gameGiftIncCount" bson:"gameGiftIncCount"`
//游戏充值赠送总金额
GameRchGiftIncAmount int64 `json:"gameRchGiftIncAmount" bson:"gameRchGiftIncAmount"`
//游戏充值赠送次数
GameRchGiftIncCount int64 `json:"gameRchGiftIncCount" bson:"gameRchGiftIncCount"`
//游戏VIP赠送总金额
GameVipGiftIncAmount int64 `json:"gameVipGiftIncAmount" bson:"gameVipGiftIncAmount"`
//游戏VIP赠送次数
GameVipGiftIncCount int64 `json:"gameVipGiftIncCount" bson:"gameVipGiftIncCount"`
// 游戏抽水
Revenue int64 `json:"revenue" bson:"revenue"`
CreatedAt time.Time `bson:"createdAt"` // 创建时间
}
type BotReportList []*BotReport
@@ -0,0 +1,445 @@
package channelCodeBlocStatMod
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"
)
func Init() {
db = mongos.New(mongos.MgoManager, CollChannelCodeBlocStat)
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: "channelCode", Value: 1}, {Key: "appId", Value: 1}, {Key: "sumDate", Value: 1}},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{{Key: "channel", Value: 1}},
},
{
Keys: bson.D{{Key: "appId", Value: 1}},
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollChannelCodeBlocStat, err))
}
}
// UpsertOneUserRegisterStat 更新或插入一条用户注册信息统计信息
func UpsertOneUserRegisterStat(ctx context.Context, code string, appId int32, sumDate time.Time, direct, fission, deduction int64) (err error) {
filter := bson.M{"channelCode": code, "appId": appId, "sumDate": sumDate}
update := bson.M{}
if direct > 0 {
update["newDirectCount"] = direct
}
if fission > 0 {
update["newFissionCount"] = fission
}
if deduction > 0 {
update["newDeductionCount"] = deduction
}
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
insertDoc["channelCode"] = code
_, err = db.InsertOne(ctx, insertDoc)
}
return err
}
// UpsertOneUserRechargeStat 更新或插入一条用户消费统计信息
func UpsertOneUserRechargeStat(ctx context.Context, code string, appId int32, sumDate time.Time, rechargeAmount, deductionAmount, fissionAmount, newRechargeAmount int64) (err error) {
filter := bson.M{"channelCode": code, "appId": appId, "sumDate": sumDate}
update := bson.M{}
if rechargeAmount > 0 {
update["directAmount"] = rechargeAmount
}
if deductionAmount > 0 {
update["deductionAmount"] = deductionAmount
}
if fissionAmount > 0 {
update["fissionAmount"] = fissionAmount
}
if newRechargeAmount > 0 {
update["newRechargeAmount"] = newRechargeAmount
}
exists, err := db.Exists(ctx, filter)
if err != nil {
return err
}
if exists {
_, err = db.UpdateOne(ctx, filter, bson.M{"$inc": update})
} else {
insertDoc := update
insertDoc["sumDate"] = sumDate
insertDoc["appId"] = appId
insertDoc["channelCode"] = code
_, err = db.InsertOne(ctx, insertDoc)
}
return err
}
// UpsertOneDistrictStat 更新渠道的留存
func UpsertOneDistrictStat(ctx context.Context, code string, appId int32, sumDate time.Time, day1Rate, day3Rate, day7Rate *float64) (err error) {
filter := bson.M{"channelCode": code, "appId": appId, "sumDate": sumDate}
update := bson.M{}
if day1Rate != nil {
update["day1RetainRate"] = *day1Rate
}
if day3Rate != nil {
update["day3RetainRate"] = *day3Rate
}
if day7Rate != nil {
update["day7RetainRate"] = *day7Rate
}
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
insertDoc["channelCode"] = code
_, err = db.InsertOne(ctx, insertDoc)
}
return err
}
// UpsertOneDistrictVisitStat 更新渠道的留存
func UpsertOneDistrictVisitStat(ctx context.Context, code string, appId int32, sumDate time.Time, directVisitCount, fissionVisitCount int64) (err error) {
filter := bson.M{"channelCode": code, "appId": appId, "sumDate": sumDate}
update := bson.M{"directVisitCount": directVisitCount, "fissionVisitCount": fissionVisitCount}
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
insertDoc["channelCode"] = code
_, err = db.InsertOne(ctx, insertDoc)
}
return err
}
// UpsertOneDistrictCpc 更新渠道的留存
func UpsertOneDistrictCpc(ctx context.Context, code string, appId int32, sumDate time.Time, visitCount int64) (err error) {
filter := bson.M{"channelCode": code, "appId": appId, "sumDate": sumDate}
update := bson.M{"landPageVisitCount": visitCount}
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
insertDoc["channelCode"] = code
_, err = db.InsertOne(ctx, insertDoc)
}
return err
}
// UpsertOneDistrictRechargeStat 更新渠道的新增充值
func UpsertOneDistrictRechargeStat(ctx context.Context, code string, appId int32, sumDate time.Time, directAmount, fissionAmount, deduction int64) (err error) {
filter := bson.M{"channelCode": code, "appId": appId, "sumDate": sumDate}
update := bson.M{"fissionAmount": fissionAmount, "directAmount": directAmount, "deductionAmount": deduction}
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
insertDoc["channelCode"] = code
_, err = db.InsertOne(ctx, insertDoc)
}
return err
}
// 后台获取统计信息
func GetChannelCodeBlocStatAgentList(ctx context.Context, channelCodes []string, appId int32, start, end *time.Time, skip, limit int64) (count int64, data ChannelCodeBlocStatList, err error) {
if len(channelCodes) == 0 {
return
}
filter := bson.M{"channelCode": bson.M{"$in": channelCodes}, "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}, {Key: "newDirectCount", Value: -1}}
opts := options.Find().SetSort(sort).SetSkip(skip).SetLimit(limit)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("ChannelCodeBlocStat GetChannelCodeBlocStatList Find err", log.E(err))
return
}
if count, err = db.Count(ctx, filter); err != nil {
log.Error("ChannelCodeBlocStat GetChannelCodeBlocStatList Count err", log.E(err))
return
}
return
}
// 后台获取统计信息
func GetChannelCodeBlocStatAgentListTotal(ctx context.Context, channelCodes []string, appId int32, start, end *time.Time) (data ChannelCodeBlocStatList, err error) {
if len(channelCodes) == 0 {
return
}
filter := bson.M{"channelCode": bson.M{"$in": channelCodes}, "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}, {Key: "newDirectCount", Value: -1}}
opts := options.Find().SetSort(sort)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("ChannelCodeBlocStat GetChannelCodeBlocStatList Find err", log.E(err))
return
}
return
}
// 后台获取统计信息总数
func GetBlocChannelCodeBlocStatListTotal(ctx context.Context, channel *string, appId *int32, start, end *time.Time) (data ChannelCodeBlocStatList, err error) {
filter := bson.M{}
if channel != nil {
filter["channelCode"] = channel
}
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}
}
if err = db.Find(ctx, &data, filter); err != nil {
log.Error("ChannelCodeBlocStat GetChannelCodeBlocStatList Find err", log.E(err))
return
}
return
}
// 后台获取统计信息
func GetChannelCodeBlocStatList(ctx context.Context, channelCodes []string, appId *int32, start, end *time.Time, skip, limit int64) (count int64, data ChannelCodeBlocStatList, err error) {
filter := bson.M{}
if len(channelCodes) > 0 {
filter["channelCode"] = bson.M{"$in": channelCodes}
}
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}, {Key: "newDirectCount", Value: -1}}
opts := options.Find().SetSort(sort).SetSkip(skip).SetLimit(limit)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("ChannelCodeBlocStat GetChannelCodeBlocStatList Find err", log.E(err))
return
}
if count, err = db.Count(ctx, filter); err != nil {
log.Error("ChannelCodeBlocStat GetChannelCodeBlocStatList Count err", log.E(err))
return
}
return
}
// 后台获取统计信息
func GetBlocChannelCodeBlocStatList(ctx context.Context, channel *string, appId *int32, start, end *time.Time, skip, limit int64) (count int64, data ChannelCodeBlocStatList, err error) {
filter := bson.M{}
if channel != nil {
filter["channelCode"] = channel
}
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}, {Key: "newDirectCount", Value: -1}}
opts := options.Find().SetSort(sort).SetSkip(skip).SetLimit(limit)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("ChannelCodeBlocStat GetChannelCodeBlocStatList Find err", log.E(err))
return
}
if count, err = db.Count(ctx, filter); err != nil {
log.Error("ChannelCodeBlocStat GetChannelCodeBlocStatList Count err", log.E(err))
return
}
return
}
// 后台获取统计信息
func GetBlocChannelCodeStatTotal(ctx context.Context, channels []string, appId *int32, start, end *time.Time) (count int64, data ChannelCodeBlocStatList, err error) {
filter := bson.M{}
if len(channels) > 0 {
filter["channelCode"] = bson.M{"$in": channels}
}
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}
}
if err = db.Find(ctx, &data, filter); err != nil {
log.Error("ChannelCodeBlocStat GetChannelCodeBlocStatList Find err", log.E(err))
return
}
if count, err = db.Count(ctx, filter); err != nil {
log.Error("ChannelCodeBlocStat GetChannelCodeBlocStatList Count err", log.E(err))
return
}
return
}
// GetAllChannelCodeBlocStatList 根据渠道码获取统计信息
func GetAllChannelCodeBlocStatList(ctx context.Context, appId int32, channelCode []string, sumDate time.Time) (data ChannelCodeBlocStatList, err error) {
filter := bson.M{"sumDate": sumDate, "appId": appId, "channelCode": bson.M{"$in": channelCode}}
if err = db.Find(ctx, &data, filter); err != nil {
log.Error("ChannelCodeBlocStat GetChannelCodeBlocStatList Find err", log.E(err))
return
}
return
}
// GetChannelCodeBlocStatListTool 根据渠道码获取统计信息
func GetChannelCodeBlocStatListTool(ctx context.Context, appId int32, channelCode string) (data ChannelCodeBlocStatList, err error) {
filter := bson.M{"appId": appId, "channelCode": channelCode}
if err = db.Find(ctx, &data, filter); err != nil {
log.Error("ChannelCodeBlocStat GetChannelCodeBlocStatList Find err", log.E(err))
return
}
return
}
// UpsertOneDistrictRechargeStat 更新渠道的新增充值
func UpsertOneDistrictFissionRechargeStat(ctx context.Context, code string, appId int32, sumDate time.Time, rechargeCount, rechargeAmount int64) (err error) {
filter := bson.M{"channelCode": code, "appId": appId, "sumDate": sumDate}
update := bson.M{"fissionAmount": rechargeAmount}
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
insertDoc["channelCode"] = code
_, err = db.InsertOne(ctx, insertDoc)
}
return err
}
+40
View File
@@ -0,0 +1,40 @@
package channelCodeBlocStatMod
import (
"stat/common/mongos"
"time"
)
const CollChannelCodeBlocStat = "channel_code_stat_bloc"
var db *mongos.MongoTool
// ChannelCodeStat 渠道码日常统计
type ChannelCodeBlocStat struct {
SumDate time.Time `bson:"sumDate"` // 记录时间 按天对齐
ChannelCode string `bson:"channelCode"` // 渠道码
AppId int32 `bson:"appId"` // appId
Channel string `bson:"channel"` // 该渠道码所属渠道渠道
NewDirectCount int64 `bson:"newDirectCount,omitempty"` // 新增直推
NewFissionCount int64 `bson:"newFissionCount,omitempty"` // 新增裂变
NewDeductionCount int64 `bson:"newDeductionCount,omitempty"` // 新增扣量(新增 = 新增直推+新增裂变+扣量)
DirectVisitCount int64 `bson:"directVisitCount,omitempty"` // 直推访问数
FissionVisitCount int64 `bson:"fissionVisitCount,omitempty"` // 裂变访问数
DeductionVisitCount int64 `bson:"deductionVisitCount,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"` // 裂变充值金额
DeductionAmount int64 `bson:"deductionAmount,omitempty"` // 扣量金额(总金额=充值金额+扣量金额+裂变充值金额)
NewRechargeCount int64 `bson:"newRechargeCount,omitempty"` // 新增充值数
NewRechargeAmount int64 `bson:"newRechargeAmount,omitempty"` // 新增充值金额
LandPageVisitCount int64 `bson:"landPageVisitCount,omitempty"` // 落地页访问次数
UpdatedAt time.Time `bson:"updatedAt,omitempty"` // 更新时间
}
type ChannelCodeBlocStatList []*ChannelCodeBlocStat
func (p ChannelCodeBlocStatList) Len() int { return len(p) }
func (p ChannelCodeBlocStatList) Less(i, j int) bool { return p[j].SumDate.Before(p[i].SumDate) }
func (p ChannelCodeBlocStatList) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
+710
View File
@@ -0,0 +1,710 @@
package channelmod
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var dbChannel *mongos.MongoTool
var dbRule *mongos.MongoTool
var dbStat *mongos.MongoTool
var dbSettlement *mongos.MongoTool
var dbChannelOwnerChange *mongos.MongoTool
var dbStatYestoday *mongos.MongoTool
func Init() {
ctx := context.Background()
InitChannel(ctx)
InitStat(ctx)
InitRule(ctx)
InitSettlement(ctx)
InitStatYestoday(ctx)
InitChannelOwnerChange(ctx)
}
func InitRule(ctx context.Context) {
// 获取数据库表
dbRule = mongos.New(mongos.MgoManager, TN.ChannelDeductionRule)
// 初始化
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: FN.ChannelDeductionRule.Channel, Value: 1}, {Key: FN.ChannelDeductionRule.AppId, Value: 1}},
Options: options.Index().SetUnique(true),
},
}
if _, err := dbRule.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", TN.ChannelDeductionRule, err))
}
}
func InitStat(ctx context.Context) {
// 获取数据库表
dbStat = mongos.New(mongos.MgoManager, TN.ChannelStat)
// 初始化
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: FN.ChannelStat.Channel, Value: 1}, {Key: FN.ChannelStat.AppId, Value: 1}, {Key: FN.ChannelStat.SumDate, Value: 1}},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{{Key: FN.ChannelStat.SumDate, Value: -1}, {Key: FN.ChannelStat.NewDirectCount, Value: -1}},
},
{
Keys: bson.D{{Key: FN.ChannelStat.CreatedAt, Value: -1}},
},
// {
// Keys: bson.D{{Key: FN.ChannelStat.NewDirectCount, Value: -1}},
// },
{
Keys: bson.D{
{Key: FN.ChannelStat.Channel, Value: 1},
{Key: FN.ChannelStat.ParentChannel, Value: 1},
{Key: FN.ChannelStat.AppId, Value: 1},
{Key: FN.ChannelStat.SumDate, Value: -1},
{Key: FN.ChannelStat.Type, Value: 1},
},
},
{
Keys: bson.D{{Key: FN.ChannelStat.Type, Value: 1}},
},
// {
// Keys: bson.D{{Key: FN.ChannelStat.IsPay, Value: 1}},
// },
// {
// Keys: bson.D{{Key: FN.ChannelStat.SumDate, Value: -1}},
// },
// {
// Keys: bson.D{{Key: FN.ChannelStat.AppId, Value: 1}},
// },
{
Keys: bson.D{
{Key: FN.ChannelStat.AppId, Value: 1},
{Key: FN.ChannelStat.SumDate, Value: -1},
},
},
}
if _, err := dbStat.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", TN.ChannelStat, err))
}
}
func InitStatYestoday(ctx context.Context) {
// 获取数据库表
dbStatYestoday = mongos.New(mongos.MgoManager, TN.ChannelStatYestoday)
// 初始化
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: FN.ChannelStatYestoday.Channel, Value: 1}, {Key: FN.ChannelStatYestoday.AppId, Value: 1}, {Key: FN.ChannelStatYestoday.SumDate, Value: 1}},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{{Key: FN.ChannelStatYestoday.SumDate, Value: -1}, {Key: FN.ChannelStatYestoday.NewCount, Value: -1}},
},
{
Keys: bson.D{
{Key: FN.ChannelStatYestoday.SumDate, Value: -1},
},
Options: options.Index().SetExpireAfterSeconds(3 * 24 * 60 * 60),
},
}
if _, err := dbStatYestoday.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", TN.ChannelStatYestoday, err))
}
}
func InitSettlement(ctx context.Context) {
// 获取数据库表
dbSettlement = mongos.New(mongos.MgoManager, TN.ChannelSettlement)
// 初始化
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: FN.ChannelSettlement.Channel, Value: 1}, {Key: FN.ChannelSettlement.AppId, Value: 1}, {Key: FN.ChannelSettlement.SumDate, Value: 1}},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{{Key: FN.ChannelSettlement.CreatedAt, Value: -1}},
Options: options.Index().SetExpireAfterSeconds(5 * 24 * 60 * 60),
},
}
if _, err := dbSettlement.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", TN.ChannelSettlement, err))
}
}
func InitChannel(ctx context.Context) {
// 获取数据库表
dbChannel = mongos.New(mongos.MgoManager, TN.ChannelInfo)
// 初始化
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: FN.ChannelInfo.Channel, Value: 1}},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{
{Key: FN.ChannelInfo.ParentAgent, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.ChannelInfo.ParentChannel, Value: 1},
},
},
}
if _, err := dbChannel.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", TN.ChannelInfo, err))
}
}
func InitChannelOwnerChange(ctx context.Context) {
// 获取数据库表
dbChannelOwnerChange = mongos.New(mongos.MgoManager, TN.ChannelOwnerChange)
// 初始化
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: FN.ChannelOwnerChange.Channel, Value: -1}},
},
{
Keys: bson.D{
{Key: FN.ChannelOwnerChange.NewUser, Value: -1},
{Key: FN.ChannelOwnerChange.OldUser, Value: -1},
},
},
}
if _, err := dbChannelOwnerChange.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", TN.ChannelOwnerChange, err))
}
}
// InsertOneChannelInfo 插入一个渠道信息
func InsertOneChannelInfo(ctx context.Context, media *ChannelInfo) error {
if _, err := dbChannel.InsertOne(ctx, media); err != nil {
log.Warn("media:InsertOneChannelInfo db.InsertOne failed", log.E(err))
return err
}
return nil
}
// FindOneChannelInfo 查找一个渠道信息
func FindOneChannelInfo(ctx context.Context, filter bson.M) (*ChannelInfo, error) {
var ChannelInfo ChannelInfo
if err := dbChannel.FindOne(ctx, &ChannelInfo, filter); err != nil {
log.Warn("ChannelInfo:FindOneChannelInfo dbChannel.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &ChannelInfo, nil
}
// FindOneChannelInfo 查找一个渠道信息
func FindOneChannelInfoEx(ctx context.Context, filter bson.M) (*ChannelInfo, error) {
var ChannelInfo ChannelInfo
if err := dbChannel.FindOneEx(ctx, &ChannelInfo, filter); err != nil {
log.Warn("ChannelInfo:FindOneChannelInfoEx dbChannel.FindOneEx failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &ChannelInfo, nil
}
// DelOneChannelInfo 删除一个渠道信息
func DelOneChannelInfo(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbChannel.DeleteOne(ctx, filter)
if err != nil {
log.Warn("ChannelInfo:DelOneChannelInfo dbChannel.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateOneChannelInfo 更新一个渠道信息
func UpdateOneChannelInfo(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbChannel.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateOneChannelInfo dbChannel.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// CountChannelInfos 统计渠道信息数量
func CountChannelInfos(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbChannel.Count(ctx, filter)
if err != nil {
log.Warn("ChannelInfo:CountChannelInfos dbChannel.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateManyChannelInfo 更新满足条件的渠道信息
func UpdateManyChannelInfo(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbChannel.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyChannelInfo dbChannel.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// FindManyChannelInfo 查找一批渠道信息数据
func FindManyChannelInfo(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (ChannelInfoList, error) {
data := make(ChannelInfoList, 0)
if err := dbChannel.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("ChannelInfo:FindManyChannelInfo dbChannel.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
// FindManyChannelInfoWithBind 用自己定义结构查找一批渠道信息数据
func FindManyChannelInfoWithBind(ctx context.Context, bind interface{}, filter bson.M, opts ...*options.FindOptions) error {
if err := dbChannel.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("ChannelInfo:FindManyChannelInfoWithBind dbChannel.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// InsertOneChannelDeductionRule 插入一个渠道扣量规则
func InsertOneChannelDeductionRule(ctx context.Context, media *ChannelDeductionRule) error {
if _, err := dbRule.InsertOne(ctx, media); err != nil {
log.Warn("media:InsertOneChannelDeductionRule db.InsertOne failed", log.E(err))
return err
}
return nil
}
// FindOneChannelDeductionRule 查找一个渠道扣量规则
func FindOneChannelDeductionRule(ctx context.Context, filter bson.M) (*ChannelDeductionRule, error) {
var ChannelDeductionRule ChannelDeductionRule
if err := dbRule.FindOne(ctx, &ChannelDeductionRule, filter); err != nil {
log.Warn("ChannelDeductionRule:FindOneChannelDeductionRule dbChannel.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &ChannelDeductionRule, nil
}
// FindOneChannelDeductionRuleEx 查找一个渠道扣量规则
func FindOneChannelDeductionRuleEx(ctx context.Context, filter bson.M) (*ChannelDeductionRule, error) {
var ChannelDeductionRule ChannelDeductionRule
if err := dbRule.FindOneEx(ctx, &ChannelDeductionRule, filter); err != nil {
log.Warn("ChannelDeductionRule:FindOneChannelDeductionRuleEx dbChannel.FindOneEx failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &ChannelDeductionRule, nil
}
// DelOneChannelDeductionRule 删除一个渠道扣量规则
func DelOneChannelDeductionRule(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbRule.DeleteOne(ctx, filter)
if err != nil {
log.Warn("ChannelDeductionRule:DelOneChannelDeductionRule dbChannel.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateOneChannelDeductionRule 更新一个渠道扣量规则
func UpdateOneChannelDeductionRule(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbRule.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("UpdateOneChannelDeductionRule dbChannel.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// CountChannelDeductionRules 统计渠道扣量规则数量
func CountChannelDeductionRules(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbRule.Count(ctx, filter)
if err != nil {
log.Warn("ChannelDeductionRule:CountChannelDeductionRules dbChannel.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateManyChannelDeductionRule 更新满足条件的渠道扣量规则
func UpdateManyChannelDeductionRule(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbRule.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyChannelDeductionRule dbChannel.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// FindManyChannelDeductionRule 查找一批渠道扣量规则数据
func FindManyChannelDeductionRule(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (ChannelDeductionRuleList, error) {
data := make(ChannelDeductionRuleList, 0)
if err := dbRule.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("ChannelDeductionRule:FindManyChannelDeductionRule dbChannel.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
// FindManyChannelDeductionRuleWithBind 用自己定义结构查找一批渠道扣量规则数据
func FindManyChannelDeductionRuleWithBind(ctx context.Context, bind interface{}, filter bson.M, opts ...*options.FindOptions) error {
if err := dbRule.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("ChannelDeductionRule:FindManyChannelDeductionRuleWithBind dbChannel.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// InsertOneChannelStat 插入一个渠道统计信息
func InsertOneChannelStat(ctx context.Context, media *ChannelStat) error {
if _, err := dbStat.InsertOne(ctx, media); err != nil {
log.Warn("media:InsertOneChannelStat db.InsertOne failed", log.E(err))
return err
}
return nil
}
// FindOneChannelStat 查找一个渠道日常统计
func FindOneChannelStat(ctx context.Context, filter bson.M) (*ChannelStat, error) {
var ChannelStat ChannelStat
if err := dbStat.FindOne(ctx, &ChannelStat, filter); err != nil {
log.Warn("ChannelStat:FindOneChannelStat dbStat.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &ChannelStat, nil
}
// DelOneChannelStat 删除一个渠道日常统计
func DelOneChannelStat(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbStat.DeleteOne(ctx, filter)
if err != nil {
log.Warn("ChannelStat:DelOneChannelStat dbStat.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateOneChannelStat 更新一个渠道日常统计
func UpdateOneChannelStat(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbStat.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("UpdateOneChannelStat dbStat.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// CountChannelStats 统计渠道日常统计数量
func CountChannelStats(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbStat.Count(ctx, filter)
if err != nil {
log.Warn("ChannelStat:CountChannelStats dbStat.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateManyChannelStat 更新满足条件的渠道日常统计
func UpdateManyChannelStat(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbStat.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyChannelStat dbStat.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// UpdateManyChannelStat 更新满足条件的渠道日常统计
func UpdateManyChannelStatWithResult(ctx context.Context, filter bson.M, update bson.M) (int64, error) {
result, err := dbStat.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyChannelStatWithResult dbStat.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return result.MatchedCount, nil
}
// FindManyChannelStat 查找一批渠道日常统计数据
func FindManyChannelStat(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (ChannelStatList, error) {
data := make(ChannelStatList, 0)
if err := dbStat.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("ChannelStat:FindManyChannelStat dbStat.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
type OnItem func(item *ChannelStat)
// FindManyChannelStatShard 查找一批渠道日常统计数据
func FindManyChannelStatShard(ctx context.Context, filter bson.M, shard int64, onItem OnItem) error {
num := int64(0)
for {
opt := &options.FindOptions{}
opt.SetSkip(num * shard)
opt.SetLimit(shard)
lst := make(ChannelStatList, 0)
if err := dbStat.Find(ctx, &lst, filter, opt); err != nil {
log.Warn("ChannelStat:FindManyChannelStatShard dbStat.Find failed", log.E(err), log.Any("filter", filter))
return err
}
for _, item := range lst {
onItem(item)
}
if int64(len(lst)) < shard {
break
}
lst = nil
num++
}
return nil
}
// FindManyChannelStatWithBind 用自己定义结构查找一批渠道日常统计数据
func FindManyChannelStatWithBind(ctx context.Context, bind interface{}, filter bson.M, opts ...*options.FindOptions) error {
if err := dbStat.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("ChannelStat:FindManyChannelStatWithBind dbStat.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// InsertOneChannelSettlement 插入一个渠道统计信息
func InsertOneChannelSettlement(ctx context.Context, media *ChannelSettlement) error {
if _, err := dbSettlement.InsertOne(ctx, media); err != nil {
log.Warn("media:InsertOneChannelSettlement dbSettlement.InsertOne failed", log.E(err))
return err
}
return nil
}
// FindOneChannelSettlement 查找一个15分钟结算
func FindOneChannelSettlement(ctx context.Context, filter bson.M) (*ChannelSettlement, error) {
var ChannelSettlement ChannelSettlement
if err := dbSettlement.FindOne(ctx, &ChannelSettlement, filter); err != nil {
log.Warn("ChannelSettlement:FindOneChannelSettlement dbSettlement.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &ChannelSettlement, nil
}
// DelOneChannelSettlement 删除一个15分钟结算
func DelOneChannelSettlement(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbSettlement.DeleteOne(ctx, filter)
if err != nil {
log.Warn("ChannelSettlement:DelOneChannelSettlement dbSettlement.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateOneChannelSettlement 更新一个15分钟结算
func UpdateOneChannelSettlement(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbSettlement.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("UpdateOneChannelSettlement dbSettlement.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// CountChannelSettlements 统计15分钟结算数量
func CountChannelSettlements(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbSettlement.Count(ctx, filter)
if err != nil {
log.Warn("ChannelSettlement:CountChannelSettlements dbSettlement.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateManyChannelSettlement 更新满足条件的15分钟结算
func UpdateManyChannelSettlement(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbSettlement.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyChannelSettlement dbSettlement.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// FindManyChannelSettlement 查找一批渠道15分钟结算
func FindManyChannelSettlement(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (ChannelSettlementList, error) {
data := make(ChannelSettlementList, 0)
if err := dbSettlement.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("ChannelSettlement:FindManyChannelSettlement dbSettlement.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
// FindManyChannelSettlementWithBind 用自己定义结构查找一批渠道15分钟结算
func FindManyChannelSettlementWithBind(ctx context.Context, bind interface{}, filter bson.M, opts ...*options.FindOptions) error {
if err := dbSettlement.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("ChannelSettlement:FindManyChannelSettlementWithBind dbSettlement.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// FindManyChannelStatYestoday 查找一批渠道日常统计数据
func FindManyChannelStatYestoday(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (ChannelStatYestodayList, error) {
data := make(ChannelStatYestodayList, 0)
if err := dbStatYestoday.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("ChannelStat:FindManyChannelStat dbStat.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
// InsertOneChannelStatYestoday 插入一个渠道统计信息
func InsertOneChannelStatYestoday(ctx context.Context, media *ChannelStatYesterday) error {
if _, err := dbStatYestoday.InsertOne(ctx, media); err != nil {
log.Warn("media:InsertOneChannelStat db.InsertOne failed", log.E(err))
return err
}
return nil
}
// CountChannelStatYestoday 统计渠道扣量规则数量
func CountChannelStatYestoday(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbStatYestoday.Count(ctx, filter)
if err != nil {
log.Warn("ChannelDeductionRule:CountChannelStatYestoday dbChannel.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// InsertOneChannelOwnerChange 插入一个渠道信息
func InsertOneChannelOwnerChange(ctx context.Context, media *ChannelOwnerChange) error {
if _, err := dbChannelOwnerChange.InsertOne(ctx, media); err != nil {
log.Warn("media:InsertOneChannelOwnerChange db.InsertOne failed", log.E(err))
return err
}
return nil
}
// FindOneChannelOwnerChange 查找一个渠道信息
func FindOneChannelOwnerChange(ctx context.Context, filter bson.M) (*ChannelOwnerChange, error) {
var ChannelOwnerChange ChannelOwnerChange
if err := dbChannelOwnerChange.FindOne(ctx, &ChannelOwnerChange, filter); err != nil {
log.Warn("ChannelOwnerChange:FindOneChannelOwnerChange dbChannelOwnerChange.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &ChannelOwnerChange, nil
}
// FindOneChannelOwnerChange 查找一个渠道信息
func FindOneChannelOwnerChangeEx(ctx context.Context, filter bson.M) (*ChannelOwnerChange, error) {
var ChannelOwnerChange ChannelOwnerChange
if err := dbChannelOwnerChange.FindOneEx(ctx, &ChannelOwnerChange, filter); err != nil {
log.Warn("ChannelOwnerChange:FindOneChannelOwnerChangeEx dbChannelOwnerChange.FindOneEx failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &ChannelOwnerChange, nil
}
// DelOneChannelOwnerChange 删除一个渠道信息
func DelOneChannelOwnerChange(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbChannelOwnerChange.DeleteOne(ctx, filter)
if err != nil {
log.Warn("ChannelOwnerChange:DelOneChannelOwnerChange dbChannelOwnerChange.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateOneChannelOwnerChange 更新一个渠道信息
func UpdateOneChannelOwnerChange(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbChannelOwnerChange.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateOneChannelOwnerChange dbChannelOwnerChange.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// CountChannelOwnerChanges 统计渠道信息数量
func CountChannelOwnerChanges(ctx context.Context, filter bson.M) (int64, error) {
count, err := dbChannelOwnerChange.Count(ctx, filter)
if err != nil {
log.Warn("ChannelOwnerChange:CountChannelOwnerChanges dbChannelOwnerChange.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateManyChannelOwnerChange 更新满足条件的渠道信息
func UpdateManyChannelOwnerChange(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbChannelOwnerChange.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyChannelOwnerChange dbChannelOwnerChange.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// FindManyChannelOwnerChanges 查找一批渠道信息数据
func FindManyChannelOwnerChanges(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (ChannelOwnerChangeList, error) {
data := make(ChannelOwnerChangeList, 0)
if err := dbChannelOwnerChange.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("ChannelOwnerChange:FindManyChannelOwnerChange dbChannelOwnerChange.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
// FindManyChannelOwnerChangeWithBind 用自己定义结构查找一批渠道信息数据
func FindManyChannelOwnerChangeWithBind(ctx context.Context, bind interface{}, filter bson.M, opts ...*options.FindOptions) error {
if err := dbChannelOwnerChange.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("ChannelOwnerChange:FindManyChannelOwnerChangeWithBind dbChannelOwnerChange.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
+810
View File
@@ -0,0 +1,810 @@
package channelmod
import (
"fmt"
"strconv"
)
type CalcIncomeRateMode int
const (
CalcIncomeRateModeDirect CalcIncomeRateMode = 0 // 直推模式:直推总额
CalcIncomeRateModeTotal CalcIncomeRateMode = 1 // 总量模式:充值总额
CalcIncomeRateModeMember CalcIncomeRateMode = 2 // 会员模式:会员总额
CalcIncomeRateModeCustom CalcIncomeRateMode = 3 // 定制模式:会员总额+(金币总额*占比)
)
type CalcIncomeRateConfig struct {
Mode CalcIncomeRateMode // 计算模式
CoinRatio float64 // 金币占比(最小为0,最大为1)
}
var configDefault = &CalcIncomeRateConfig{
Mode: CalcIncomeRateModeMember, // 默认收益率计算模式
CoinRatio: 0,
}
var configXcb = &CalcIncomeRateConfig{
Mode: CalcIncomeRateModeTotal, // 总充值
CoinRatio: 0,
}
func getConfig(appId int32) *CalcIncomeRateConfig {
if appId == 6666 {
return configXcb
} else {
return configDefault
}
}
// GetIncome 收益率计算公式
func (c *CalcIncomeRateConfig) GetIncome(stat *ChannelStat) int64 {
switch c.Mode {
case CalcIncomeRateModeDirect:
return stat.DirectAmount
case CalcIncomeRateModeTotal:
return stat.TotalAmount
case CalcIncomeRateModeMember:
return stat.VipPayMoney + stat.VipPayDeduction
case CalcIncomeRateModeCustom:
rate := c.CoinRatio
if rate > 1 {
rate = 1
}
if rate < 0 {
rate = 0
}
return (stat.VipPayMoney + stat.VipPayDeduction) + int64(float64(stat.VipPayCoin)*rate)
default:
return stat.VipPayMoney + stat.VipPayDeduction
}
}
func (t ChannelType) String() string {
switch t {
case ChannelTypeNone, ChannelTypeEnd:
return "无效"
case ChannelTypeParent:
return "一级"
case ChannelTypeSecond:
return "二级"
case ChannelTypeThird:
return "三级"
case ChannelTypeForth:
return "四级"
default:
if t > ChannelTypeNone && t < ChannelTypeEnd {
return fmt.Sprintf("【%d】级", t)
}
return "无效"
}
}
func (t ChannelType) IsTop() bool {
if t == ChannelTypeParent {
return true
}
return false
}
func (t ChannelType) IsSecond() bool {
if t == ChannelTypeSecond {
return true
}
return false
}
func (t ChannelType) IsChild() bool {
if t > ChannelTypeParent && t < ChannelTypeEnd {
return true
}
return false
}
func (t ChannelType) Child() ChannelType {
if t > ChannelTypeNone && t < ChannelTypeEnd {
return t + 1
} else {
return ChannelTypeEnd
}
}
func (t ChannelType) Parent() ChannelType {
if t > ChannelTypeNone && t < ChannelTypeEnd {
return t - 1
} else {
return ChannelTypeNone
}
}
func (t ChannelType) IsValid() bool {
if t > ChannelTypeNone && t < ChannelTypeEnd {
return true
} else {
return false
}
}
func (t ChannelType) IsNone() bool {
if t > ChannelTypeNone && t < ChannelTypeEnd {
return false
} else {
return true
}
}
func (a ChannelStatList) Len() int { return len(a) }
func (a ChannelStatList) Less(i, j int) bool { return a[i].SumDate.After(a[j].SumDate) }
func (a ChannelStatList) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (s *ChannelSettlement) AssignmentTo(d *ChannelStat) {
d.ValidDirectCount = s.ValidDirectCount
d.ValidDeductionCount = s.ValidDeductionCount
d.ValidPayMoney = s.ValidPayMoney
d.ValidPayCoin = s.ValidPayCoin
d.NewTotalIpCount = s.NewTotalIpCount
d.NewTotalCount = s.NewTotalCount
d.NewDirectCount = s.NewDirectCount
d.NewFissionCount = s.NewFissionCount
d.NewDeductionCount = s.NewDeductionCount
d.NewAndroidCount = s.NewAndroidCount
d.NewAndroidDirectCount = s.NewAndroidDirectCount
d.NewAndroidFissionCount = s.NewAndroidFissionCount
d.NewAndroidDeductionCount = s.NewAndroidDeductionCount
d.NewIosCount = s.NewIosCount
d.NewIosDirectCount = s.NewIosDirectCount
d.NewIosFissionCount = s.NewIosFissionCount
d.NewIosDeductionCount = s.NewIosDeductionCount
d.NewLightCount = s.NewLightCount
d.NewLightGuestCount = s.NewLightGuestCount
d.NewLightGuestDirectCount = s.NewLightGuestDirectCount
d.NewLightGuestFissionCount = s.NewLightGuestFissionCount
d.NewLightGuestDeductionCount = s.NewLightGuestDeductionCount
d.NewLightFormalCount = s.NewLightFormalCount
d.NewLightFormalDirectCount = s.NewLightFormalDirectCount
d.NewLightFormalFissionCount = s.NewLightFormalFissionCount
d.NewLightFormalDeductionCount = s.NewLightFormalDeductionCount
d.NewLightDirectCount = s.NewLightDirectCount
d.NewLightFissionCount = s.NewLightFissionCount
d.NewLightDeductionCount = s.NewLightDeductionCount
d.NewLightNaturalCount = s.NewLightNaturalCount
d.NewH5Count = s.NewH5Count
d.NewH5DirectCount = s.NewH5DirectCount
d.NewH5FissionCount = s.NewH5FissionCount
d.NewH5DeductionCount = s.NewH5DeductionCount
d.NewH5AndroidCount = s.NewH5AndroidCount
d.NewH5IosCount = s.NewH5IosCount
d.NewH5PcCount = s.NewH5PcCount
d.NewH5FormalCount = s.NewH5FormalCount
d.NewH5FormalDirectCount = s.NewH5FormalDirectCount
d.NewH5FormalFissionCount = s.NewH5FormalFissionCount
d.NewH5FormalDeductionCount = s.NewH5FormalDeductionCount
// 访问
d.TotalVisitCount = s.TotalVisitCount
d.DirectVisitCount = s.DirectVisitCount
d.FissionVisitCount = s.FissionVisitCount
d.AndroidVisitCount = s.AndroidVisitCount
d.IosVisitCount = s.IosVisitCount
d.LightVisitCount = s.LightVisitCount
d.LightVisitDirectCount = s.LightVisitDirectCount
d.LightVisitFissionCount = s.LightVisitFissionCount
d.LightVisitDeductionCount = s.LightVisitDeductionCount
d.LightVisitNaturalCount = s.LightVisitNaturalCount
d.H5VisitCount = s.H5VisitCount
d.H5AndroidVisitCount = s.H5AndroidVisitCount
d.H5IosVisitCount = s.H5IosVisitCount
d.H5PcVisitCount = s.H5PcVisitCount
// 充值
d.TotalAmount = s.TotalAmount
d.DirectAmount = s.DirectAmount
d.DirectAmountCount = s.DirectAmountCount
d.FissionAmount = s.FissionAmount
d.FissionAmountCount = s.FissionAmountCount
d.NaturalAmount = s.NaturalAmount
d.NaturalAmountCount = s.NaturalAmountCount
d.DeductionAmount = s.DeductionAmount
d.DeductionAmountCount = s.DeductionAmountCount
d.AndroidAmount = s.AndroidAmount
d.AndroidAmountCount = s.AndroidAmountCount
d.IosAmount = s.IosAmount
d.IosAmountCount = s.IosAmountCount
d.H5Amount = s.H5Amount
d.H5AmountCount = s.H5AmountCount
d.LightAmount = s.LightAmount
d.LightAmountCount = s.LightAmountCount
d.LightDirectAmount = s.LightDirectAmount
d.LightDirectAmountCount = s.LightDirectAmountCount
d.LightFissionAmount = s.LightFissionAmount
d.LightFissionAmountCount = s.LightFissionAmountCount
d.LightDeductionAmount = s.LightDeductionAmount
d.LightDeductionAmountCount = s.LightDeductionAmountCount
d.LightNaturalAmount = s.LightNaturalAmount
d.LightNaturalAmountCount = s.LightNaturalAmountCount
// 其他充值
d.NewRechargeAmount = s.NewRechargeAmount
d.VipPayMoney = s.VipPayMoney
d.VipPayCoin = s.VipPayCoin
d.VipPayDeduction = s.VipPayDeduction
d.GameRechageAmount = s.GameRechageAmount
d.GameWithdrawAmount = s.GameWithdrawAmount
// 落地页访问
d.LandPageVisitCount = s.LandPageVisitCount
d.LandpageAndroidClick = s.LandpageAndroidClick
d.LandpageIosAppstoreClick = s.LandpageIosAppstoreClick
d.LandpageIosAthorClick = s.LandpageIosAthorClick
d.LandpageIosH5Click = s.LandpageIosH5Click
}
func (s *ChannelSettlement) AccumulateTo(d *ChannelStat) {
d.ValidDirectCount += s.ValidDirectCount
d.ValidDeductionCount += s.ValidDeductionCount
d.ValidPayMoney += s.ValidPayMoney
d.ValidPayCoin += s.ValidPayCoin
d.NewTotalIpCount += s.NewTotalIpCount
d.NewTotalCount += s.NewTotalCount
d.NewDirectCount += s.NewDirectCount
d.NewFissionCount += s.NewFissionCount
d.NewDeductionCount += s.NewDeductionCount
d.NewAndroidCount += s.NewAndroidCount
d.NewAndroidDirectCount += s.NewAndroidDirectCount
d.NewAndroidFissionCount += s.NewAndroidFissionCount
d.NewAndroidDeductionCount += s.NewAndroidDeductionCount
d.NewIosCount += s.NewIosCount
d.NewIosDirectCount += s.NewIosDirectCount
d.NewIosFissionCount += s.NewIosFissionCount
d.NewIosDeductionCount += s.NewIosDeductionCount
d.NewLightCount += s.NewLightCount
d.NewLightGuestCount += s.NewLightGuestCount
d.NewLightGuestDirectCount += s.NewLightGuestDirectCount
d.NewLightGuestFissionCount += s.NewLightGuestFissionCount
d.NewLightGuestDeductionCount += s.NewLightGuestDeductionCount
d.NewLightFormalCount += s.NewLightFormalCount
d.NewLightFormalDirectCount += s.NewLightFormalDirectCount
d.NewLightFormalFissionCount += s.NewLightFormalFissionCount
d.NewLightFormalDeductionCount += s.NewLightFormalDeductionCount
d.NewLightDirectCount += s.NewLightDirectCount
d.NewLightFissionCount += s.NewLightFissionCount
d.NewLightDeductionCount += s.NewLightDeductionCount
d.NewLightNaturalCount += s.NewLightNaturalCount
d.NewH5Count += s.NewH5Count
d.NewH5DirectCount += s.NewH5DirectCount
d.NewH5FissionCount += s.NewH5FissionCount
d.NewH5DeductionCount += s.NewH5DeductionCount
d.NewH5AndroidCount += s.NewH5AndroidCount
d.NewH5IosCount += s.NewH5IosCount
d.NewH5PcCount += s.NewH5PcCount
d.NewH5FormalCount += s.NewH5FormalCount
d.NewH5FormalDirectCount += s.NewH5FormalDirectCount
d.NewH5FormalFissionCount += s.NewH5FormalFissionCount
d.NewH5FormalDeductionCount += s.NewH5FormalDeductionCount
// 访问
d.TotalVisitCount += s.TotalVisitCount
d.DirectVisitCount += s.DirectVisitCount
d.FissionVisitCount += s.FissionVisitCount
d.AndroidVisitCount += s.AndroidVisitCount
d.IosVisitCount += s.IosVisitCount
d.LightVisitCount += s.LightVisitCount
d.LightVisitDirectCount += s.LightVisitDirectCount
d.LightVisitFissionCount += s.LightVisitFissionCount
d.LightVisitDeductionCount += s.LightVisitDeductionCount
d.LightVisitNaturalCount += s.LightVisitNaturalCount
d.H5VisitCount += s.H5VisitCount
d.H5AndroidVisitCount += s.H5AndroidVisitCount
d.H5IosVisitCount += s.H5IosVisitCount
d.H5PcVisitCount += s.H5PcVisitCount
// 充值
d.TotalAmount += s.TotalAmount
d.DirectAmount += s.DirectAmount
d.DirectAmountCount += s.DirectAmountCount
d.FissionAmount += s.FissionAmount
d.FissionAmountCount += s.FissionAmountCount
d.NaturalAmount += s.NaturalAmount
d.NaturalAmountCount += s.NaturalAmountCount
d.DeductionAmount += s.DeductionAmount
d.DeductionAmountCount += s.DeductionAmountCount
d.AndroidAmount += s.AndroidAmount
d.AndroidAmountCount += s.AndroidAmountCount
d.IosAmount += s.IosAmount
d.IosAmountCount += s.IosAmountCount
d.H5Amount += s.H5Amount
d.H5AmountCount += s.H5AmountCount
d.LightAmount += s.LightAmount
d.LightAmountCount += s.LightAmountCount
d.LightDirectAmount += s.LightDirectAmount
d.LightDirectAmountCount += s.LightDirectAmountCount
d.LightFissionAmount += s.LightFissionAmount
d.LightFissionAmountCount += s.LightFissionAmountCount
d.LightDeductionAmount += s.LightDeductionAmount
d.LightDeductionAmountCount += s.LightDeductionAmountCount
d.LightNaturalAmount += s.LightNaturalAmount
d.LightNaturalAmountCount += s.LightNaturalAmountCount
// 其他充值
d.NewRechargeAmount += s.NewRechargeAmount
d.VipPayMoney += s.VipPayMoney
d.VipPayCoin += s.VipPayCoin
d.VipPayDeduction += s.VipPayDeduction
d.GameRechageAmount += s.GameRechageAmount
d.GameWithdrawAmount += s.GameWithdrawAmount
// 落地页访问
d.LandPageVisitCount += s.LandPageVisitCount
d.LandpageAndroidClick += s.LandpageAndroidClick
d.LandpageIosAppstoreClick += s.LandpageIosAppstoreClick
d.LandpageIosAthorClick += s.LandpageIosAthorClick
d.LandpageIosH5Click += s.LandpageIosH5Click
}
func (s *ChannelStat) AssignmentTo(d *ChannelSettlement) {
d.ValidDirectCount = s.ValidDirectCount
d.ValidDeductionCount = s.ValidDeductionCount
d.ValidPayMoney = s.ValidPayMoney
d.ValidPayCoin = s.ValidPayCoin
d.NewTotalIpCount = s.NewTotalIpCount
d.NewTotalCount = s.NewTotalCount
d.NewDirectCount = s.NewDirectCount
d.NewFissionCount = s.NewFissionCount
d.NewDeductionCount = s.NewDeductionCount
d.NewAndroidCount = s.NewAndroidCount
d.NewAndroidDirectCount = s.NewAndroidDirectCount
d.NewAndroidFissionCount = s.NewAndroidFissionCount
d.NewAndroidDeductionCount = s.NewAndroidDeductionCount
d.NewIosCount = s.NewIosCount
d.NewIosDirectCount = s.NewIosDirectCount
d.NewIosFissionCount = s.NewIosFissionCount
d.NewIosDeductionCount = s.NewIosDeductionCount
d.NewLightCount = s.NewLightCount
d.NewLightGuestCount = s.NewLightGuestCount
d.NewLightGuestDirectCount = s.NewLightGuestDirectCount
d.NewLightGuestFissionCount = s.NewLightGuestFissionCount
d.NewLightGuestDeductionCount = s.NewLightGuestDeductionCount
d.NewLightFormalCount = s.NewLightFormalCount
d.NewLightFormalDirectCount = s.NewLightFormalDirectCount
d.NewLightFormalFissionCount = s.NewLightFormalFissionCount
d.NewLightFormalDeductionCount = s.NewLightFormalDeductionCount
d.NewLightDirectCount = s.NewLightDirectCount
d.NewLightFissionCount = s.NewLightFissionCount
d.NewLightDeductionCount = s.NewLightDeductionCount
d.NewLightNaturalCount = s.NewLightNaturalCount
d.NewH5Count = s.NewH5Count
d.NewH5DirectCount = s.NewH5DirectCount
d.NewH5FissionCount = s.NewH5FissionCount
d.NewH5DeductionCount = s.NewH5DeductionCount
d.NewH5AndroidCount = s.NewH5AndroidCount
d.NewH5IosCount = s.NewH5IosCount
d.NewH5PcCount = s.NewH5PcCount
d.NewH5FormalCount = s.NewH5FormalCount
d.NewH5FormalDirectCount = s.NewH5FormalDirectCount
d.NewH5FormalFissionCount = s.NewH5FormalFissionCount
d.NewH5FormalDeductionCount = s.NewH5FormalDeductionCount
// 访问
d.TotalVisitCount = s.TotalVisitCount
d.DirectVisitCount = s.DirectVisitCount
d.FissionVisitCount = s.FissionVisitCount
d.AndroidVisitCount = s.AndroidVisitCount
d.IosVisitCount = s.IosVisitCount
d.LightVisitCount = s.LightVisitCount
d.LightVisitDirectCount = s.LightVisitDirectCount
d.LightVisitFissionCount = s.LightVisitFissionCount
d.LightVisitDeductionCount = s.LightVisitDeductionCount
d.LightVisitNaturalCount = s.LightVisitNaturalCount
d.H5VisitCount = s.H5VisitCount
d.H5AndroidVisitCount = s.H5AndroidVisitCount
d.H5IosVisitCount = s.H5IosVisitCount
d.H5PcVisitCount = s.H5PcVisitCount
// 充值
d.TotalAmount = s.TotalAmount
d.DirectAmount = s.DirectAmount
d.DirectAmountCount = s.DirectAmountCount
d.FissionAmount = s.FissionAmount
d.FissionAmountCount = s.FissionAmountCount
d.NaturalAmount = s.NaturalAmount
d.NaturalAmountCount = s.NaturalAmountCount
d.DeductionAmount = s.DeductionAmount
d.DeductionAmountCount = s.DeductionAmountCount
d.AndroidAmount = s.AndroidAmount
d.AndroidAmountCount = s.AndroidAmountCount
d.IosAmount = s.IosAmount
d.IosAmountCount = s.IosAmountCount
d.H5Amount = s.H5Amount
d.H5AmountCount = s.H5AmountCount
d.LightAmount = s.LightAmount
d.LightAmountCount = s.LightAmountCount
d.LightDirectAmount = s.LightDirectAmount
d.LightDirectAmountCount = s.LightDirectAmountCount
d.LightFissionAmount = s.LightFissionAmount
d.LightFissionAmountCount = s.LightFissionAmountCount
d.LightDeductionAmount = s.LightDeductionAmount
d.LightDeductionAmountCount = s.LightDeductionAmountCount
d.LightNaturalAmount = s.LightNaturalAmount
d.LightNaturalAmountCount = s.LightNaturalAmountCount
// 其他充值
d.NewRechargeAmount = s.NewRechargeAmount
d.VipPayMoney = s.VipPayMoney
d.VipPayCoin = s.VipPayCoin
d.VipPayDeduction = s.VipPayDeduction
d.GameRechageAmount = s.GameRechageAmount
d.GameWithdrawAmount = s.GameWithdrawAmount
// 落地页访问
d.LandPageVisitCount = s.LandPageVisitCount
d.LandpageAndroidClick = s.LandpageAndroidClick
d.LandpageIosAppstoreClick = s.LandpageIosAppstoreClick
d.LandpageIosAthorClick = s.LandpageIosAthorClick
d.LandpageIosH5Click = s.LandpageIosH5Click
}
func (s *ChannelStat) AccumulateTo(d *ChannelSettlement) {
d.ValidDirectCount += s.ValidDirectCount
d.ValidDeductionCount += s.ValidDeductionCount
d.ValidPayMoney += s.ValidPayMoney
d.ValidPayCoin += s.ValidPayCoin
d.NewTotalIpCount += s.NewTotalIpCount
d.NewTotalCount += s.NewTotalCount
d.NewDirectCount += s.NewDirectCount
d.NewFissionCount += s.NewFissionCount
d.NewDeductionCount += s.NewDeductionCount
d.NewAndroidCount += s.NewAndroidCount
d.NewAndroidDirectCount += s.NewAndroidDirectCount
d.NewAndroidFissionCount += s.NewAndroidFissionCount
d.NewAndroidDeductionCount += s.NewAndroidDeductionCount
d.NewIosCount += s.NewIosCount
d.NewIosDirectCount += s.NewIosDirectCount
d.NewIosFissionCount += s.NewIosFissionCount
d.NewIosDeductionCount += s.NewIosDeductionCount
d.NewLightCount += s.NewLightCount
d.NewLightGuestCount += s.NewLightGuestCount
d.NewLightGuestDirectCount += s.NewLightGuestDirectCount
d.NewLightGuestFissionCount += s.NewLightGuestFissionCount
d.NewLightGuestDeductionCount += s.NewLightGuestDeductionCount
d.NewLightFormalCount += s.NewLightFormalCount
d.NewLightFormalDirectCount += s.NewLightFormalDirectCount
d.NewLightFormalFissionCount += s.NewLightFormalFissionCount
d.NewLightFormalDeductionCount += s.NewLightFormalDeductionCount
d.NewLightDirectCount += s.NewLightDirectCount
d.NewLightFissionCount += s.NewLightFissionCount
d.NewLightDeductionCount += s.NewLightDeductionCount
d.NewLightNaturalCount += s.NewLightNaturalCount
d.NewH5Count += s.NewH5Count
d.NewH5DirectCount += s.NewH5DirectCount
d.NewH5FissionCount += s.NewH5FissionCount
d.NewH5DeductionCount += s.NewH5DeductionCount
d.NewH5AndroidCount += s.NewH5AndroidCount
d.NewH5IosCount += s.NewH5IosCount
d.NewH5PcCount += s.NewH5PcCount
d.NewH5FormalCount += s.NewH5FormalCount
d.NewH5FormalDirectCount += s.NewH5FormalDirectCount
d.NewH5FormalFissionCount += s.NewH5FormalFissionCount
d.NewH5FormalDeductionCount += s.NewH5FormalDeductionCount
// 访问
d.TotalVisitCount += s.TotalVisitCount
d.DirectVisitCount += s.DirectVisitCount
d.FissionVisitCount += s.FissionVisitCount
d.AndroidVisitCount += s.AndroidVisitCount
d.IosVisitCount += s.IosVisitCount
d.LightVisitCount += s.LightVisitCount
d.LightVisitDirectCount += s.LightVisitDirectCount
d.LightVisitFissionCount += s.LightVisitFissionCount
d.LightVisitDeductionCount += s.LightVisitDeductionCount
d.LightVisitNaturalCount += s.LightVisitNaturalCount
d.H5VisitCount += s.H5VisitCount
d.H5AndroidVisitCount += s.H5AndroidVisitCount
d.H5IosVisitCount += s.H5IosVisitCount
d.H5PcVisitCount += s.H5PcVisitCount
// 充值
d.TotalAmount += s.TotalAmount
d.DirectAmount += s.DirectAmount
d.DirectAmountCount += s.DirectAmountCount
d.FissionAmount += s.FissionAmount
d.FissionAmountCount += s.FissionAmountCount
d.NaturalAmount += s.NaturalAmount
d.NaturalAmountCount += s.NaturalAmountCount
d.DeductionAmount += s.DeductionAmount
d.DeductionAmountCount += s.DeductionAmountCount
d.AndroidAmount += s.AndroidAmount
d.AndroidAmountCount += s.AndroidAmountCount
d.IosAmount += s.IosAmount
d.IosAmountCount += s.IosAmountCount
d.LightAmount += s.LightAmount
d.LightAmountCount += s.LightAmountCount
d.LightDirectAmount += s.LightDirectAmount
d.LightDirectAmountCount += s.LightDirectAmountCount
d.LightFissionAmount += s.LightFissionAmount
d.LightFissionAmountCount += s.LightFissionAmountCount
d.LightDeductionAmount += s.LightDeductionAmount
d.LightDeductionAmountCount += s.LightDeductionAmountCount
d.LightNaturalAmount += s.LightNaturalAmount
d.LightNaturalAmountCount += s.LightNaturalAmountCount
// 其他充值
d.NewRechargeAmount += s.NewRechargeAmount
d.VipPayMoney += s.VipPayMoney
d.VipPayCoin += s.VipPayCoin
d.VipPayDeduction += s.VipPayDeduction
d.GameRechageAmount += s.GameRechageAmount
d.GameWithdrawAmount += s.GameWithdrawAmount
// 落地页访问
d.LandPageVisitCount += s.LandPageVisitCount
d.LandpageAndroidClick += s.LandpageAndroidClick
d.LandpageIosAppstoreClick += s.LandpageIosAppstoreClick
d.LandpageIosAthorClick += s.LandpageIosAthorClick
d.LandpageIosH5Click += s.LandpageIosH5Click
}
func (s *ChannelStat) CalcIncomeRate() *ChannelStat {
if s.Settlement == SettlementCPA && s.CPAPrice > 0 {
spendMoney := s.ValidDirectCount * s.CPAPrice
incomeMoney := getConfig(s.AppId).GetIncome(s) //s.DirectAmount
if spendMoney > 0 {
s.IncomeAmount = spendMoney
s.IncomeRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", float64(incomeMoney)/float64(spendMoney)), 64)
}
} else if s.Settlement == SettlementCPS && s.CPSRate > 0 {
spendMoney := s.ValidPayMoney * s.CPSRate / 100
incomeMoney := getConfig(s.AppId).GetIncome(s) // s.DirectAmount
if spendMoney > 0 {
s.IncomeAmount = spendMoney
s.IncomeRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", float64(incomeMoney)/float64(spendMoney)), 64)
}
}
return s
}
func (s *ChannelStat) CorrectValidData() *ChannelStat {
//if s.ValidDirectCount == 0 && s.ValidPayMoney == 0 {
s.ValidDirectCount, s.ValidPayMoney, s.ValidPayCoin, s.ValidDeductionCount = GetChannelStatValidData(s)
//}
if s.TotalVisitCount != s.DirectVisitCount+s.FissionVisitCount {
s.TotalVisitCount = s.DirectVisitCount + s.FissionVisitCount
}
if s.NewTotalCount != s.NewDirectCount+s.NewFissionCount+s.NewDeductionCount {
s.NewTotalCount = s.NewDirectCount + s.NewFissionCount + s.NewDeductionCount
}
if s.DirectAmount+s.FissionAmount+s.DeductionAmount != s.TotalAmount {
s.TotalAmount = s.DirectAmount + s.FissionAmount + s.DeductionAmount
}
if s.VipPayMoney+s.VipPayDeduction+s.VipPayCoin != s.TotalAmount {
s.VipPayCoin = s.TotalAmount - s.VipPayMoney - s.VipPayDeduction
}
return s
}
func (s *ChannelSettlement) CorrectValidData() *ChannelSettlement {
//if s.ValidDirectCount == 0 && s.ValidPayMoney == 0 {
s.ValidDirectCount, s.ValidPayMoney, s.ValidPayCoin, s.ValidDeductionCount = GetChannelSettlementValidData(s)
//}
if s.TotalVisitCount != s.DirectVisitCount+s.FissionVisitCount {
s.TotalVisitCount = s.DirectVisitCount + s.FissionVisitCount
}
if s.NewTotalCount != s.NewDirectCount+s.NewFissionCount+s.NewDeductionCount {
s.NewTotalCount = s.NewDirectCount + s.NewFissionCount + s.NewDeductionCount
}
if s.DirectAmount+s.FissionAmount+s.DeductionAmount != s.TotalAmount {
s.TotalAmount = s.DirectAmount + s.FissionAmount + s.DeductionAmount
}
if s.VipPayMoney+s.VipPayDeduction+s.VipPayCoin != s.TotalAmount {
s.VipPayCoin = s.TotalAmount - s.VipPayMoney - s.VipPayDeduction
}
return s
}
func GetChannelStatValidData(stat *ChannelStat) (count int64, amount int64, coin int64, deduction int64) {
switch stat.AppType {
case AppTypePkg:
count = stat.NewAndroidDirectCount + stat.NewIosDirectCount
deduction = stat.NewAndroidDeductionCount + stat.NewIosDeductionCount
amount = stat.VipPayMoney
coin = stat.ValidPayCoin
case AppTypeLight:
if stat.PromoteMode == PromoteModeRegister {
count = stat.NewLightFormalDirectCount
deduction = stat.NewLightFormalDeductionCount
} else {
count = stat.NewLightDirectCount
deduction = stat.NewLightDeductionCount
}
amount = stat.VipPayMoney
coin = stat.ValidPayCoin
case AppTypeH5:
if stat.PromoteMode == PromoteModeRegister {
count = stat.NewH5FormalDirectCount
deduction = stat.NewH5FormalDeductionCount
} else {
count = stat.NewH5DirectCount
deduction = stat.NewH5DeductionCount
}
amount = stat.VipPayMoney
coin = stat.ValidPayCoin
default:
count = stat.NewDirectCount
deduction = stat.NewDeductionCount
amount = stat.VipPayMoney
if stat.AppId == 6666 && amount == 0 { // 咻车宝按照充值金币计算
amount += stat.VipPayCoin
}
coin = stat.ValidPayCoin
}
return
}
func GetChannelSettlementValidData(stat *ChannelSettlement) (count int64, amount int64, coin int64, deduction int64) {
switch stat.AppType {
case AppTypePkg:
count = stat.NewAndroidDirectCount + stat.NewIosDirectCount
deduction = stat.NewAndroidDeductionCount + stat.NewIosDeductionCount
amount = stat.VipPayMoney
coin = stat.ValidPayCoin
case AppTypeLight:
if stat.PromoteMode == PromoteModeRegister {
count = stat.NewLightFormalDirectCount
deduction = stat.NewLightFormalDeductionCount
} else {
count = stat.NewLightDirectCount
deduction = stat.NewLightDeductionCount
}
amount = stat.VipPayMoney
coin = stat.ValidPayCoin
case AppTypeH5:
if stat.PromoteMode == PromoteModeRegister {
count = stat.NewH5FormalDirectCount
deduction = stat.NewH5FormalDeductionCount
} else {
count = stat.NewH5DirectCount
deduction = stat.NewH5DeductionCount
}
amount = stat.VipPayMoney
coin = stat.ValidPayCoin
default:
count = stat.NewDirectCount
deduction = stat.NewDeductionCount
amount = stat.VipPayMoney
coin = stat.ValidPayCoin
}
return
}
func ChannelStatSummation(base, value *ChannelStat) {
value.CorrectValidData()
base.ValidDirectCount += value.ValidDirectCount
base.ValidDeductionCount += value.ValidDeductionCount
base.ValidPayMoney += value.ValidPayMoney
base.ValidPayCoin += value.ValidPayCoin
base.NewTotalIpCount += value.NewTotalIpCount
base.NewTotalCount += value.NewTotalCount
base.NewDirectCount += value.NewDirectCount
base.NewFissionCount += value.NewFissionCount
base.NewDeductionCount += value.NewDeductionCount
base.NewAndroidCount += value.NewAndroidCount
base.NewAndroidDirectCount += value.NewAndroidDirectCount
base.NewAndroidFissionCount += value.NewAndroidFissionCount
base.NewAndroidDeductionCount += value.NewAndroidDeductionCount
base.NewIosCount += value.NewIosCount
base.NewIosDirectCount += value.NewIosDirectCount
base.NewIosFissionCount += value.NewIosFissionCount
base.NewIosDeductionCount += value.NewIosDeductionCount
base.NewLightCount += value.NewLightCount
base.NewLightGuestCount += value.NewLightGuestCount
base.NewLightGuestDirectCount += value.NewLightGuestDirectCount
base.NewLightGuestFissionCount += value.NewLightGuestFissionCount
base.NewLightGuestDeductionCount += value.NewLightGuestDeductionCount
base.NewLightFormalCount += value.NewLightFormalCount
base.NewLightFormalDirectCount += value.NewLightFormalDirectCount
base.NewLightFormalFissionCount += value.NewLightFormalFissionCount
base.NewLightFormalDeductionCount += value.NewLightFormalDeductionCount
base.NewLightDirectCount += value.NewLightDirectCount
base.NewLightFissionCount += value.NewLightFissionCount
base.NewLightDeductionCount += value.NewLightDeductionCount
base.NewLightNaturalCount += value.NewLightNaturalCount
base.NewH5Count += value.NewH5Count
base.NewH5DirectCount += value.NewH5DirectCount
base.NewH5FissionCount += value.NewH5FissionCount
base.NewH5DeductionCount += value.NewH5DeductionCount
base.NewH5AndroidCount += value.NewH5AndroidCount
base.NewH5IosCount += value.NewH5IosCount
base.NewH5PcCount += value.NewH5PcCount
base.NewH5FormalCount += value.NewH5FormalCount
base.NewH5FormalDirectCount += value.NewH5FormalDirectCount
base.NewH5FormalFissionCount += value.NewH5FormalFissionCount
base.NewH5FormalDeductionCount += value.NewH5FormalDeductionCount
// 访问
base.TotalVisitCount += value.TotalVisitCount
base.DirectVisitCount += value.DirectVisitCount
base.FissionVisitCount += value.FissionVisitCount
base.AndroidVisitCount += value.AndroidVisitCount
base.IosVisitCount += value.IosVisitCount
base.LightVisitCount += value.LightVisitCount
base.LightVisitDirectCount += value.LightVisitDirectCount
base.LightVisitFissionCount += value.LightVisitFissionCount
base.LightVisitDeductionCount += value.LightVisitDeductionCount
base.LightVisitNaturalCount += value.LightVisitNaturalCount
base.H5VisitCount += value.H5VisitCount
base.H5AndroidVisitCount += value.H5AndroidVisitCount
base.H5IosVisitCount += value.H5IosVisitCount
base.H5PcVisitCount += value.H5PcVisitCount
// 充值
base.TotalAmount += value.TotalAmount
base.DirectAmount += value.DirectAmount
base.DirectAmountCount += value.DirectAmountCount
base.FissionAmount += value.FissionAmount
base.FissionAmountCount += value.FissionAmountCount
base.NaturalAmount += value.NaturalAmount
base.NaturalAmountCount += value.NaturalAmountCount
base.DeductionAmount += value.DeductionAmount
base.DeductionAmountCount += value.DeductionAmountCount
base.AndroidAmount += value.AndroidAmount
base.AndroidAmountCount += value.AndroidAmountCount
base.IosAmount += value.IosAmount
base.IosAmountCount += value.IosAmountCount
base.H5Amount += value.H5Amount
base.H5AmountCount += value.H5AmountCount
base.LightAmount += value.LightAmount
base.LightAmountCount += value.LightAmountCount
base.LightDirectAmount += value.LightDirectAmount
base.LightDirectAmountCount += value.LightDirectAmountCount
base.LightFissionAmount += value.LightFissionAmount
base.LightFissionAmountCount += value.LightFissionAmountCount
base.LightDeductionAmount += value.LightDeductionAmount
base.LightDeductionAmountCount += value.LightDeductionAmountCount
base.LightNaturalAmount += value.LightNaturalAmount
base.LightNaturalAmountCount += value.LightNaturalAmountCount
// 其他充值
base.NewRechargeAmount += value.NewRechargeAmount
base.VipPayMoney += value.VipPayMoney
base.VipPayCoin += value.DirectAmount + value.FissionAmount - value.VipPayMoney - value.VipPayDeduction
base.VipPayDeduction += value.VipPayDeduction
base.GameRechageAmount += value.GameRechageAmount
base.GameWithdrawAmount += value.GameWithdrawAmount
// 落地页访问
base.LandPageVisitCount += value.LandPageVisitCount
base.LandpageAndroidClick += value.LandpageAndroidClick
base.LandpageIosAppstoreClick += value.LandpageIosAppstoreClick
base.LandpageIosAthorClick += value.LandpageIosAthorClick
base.LandpageIosH5Click += value.LandpageIosH5Click
}
func CalculateChannelIncome(stat *ChannelStat) (int64, string) {
var income int64
var desc string
if stat.Settlement == SettlementCPA {
income = stat.ValidDirectCount * stat.CPAPrice
desc = fmt.Sprintf("CPA:%d * %.2f", stat.ValidDirectCount, float64(stat.CPAPrice)/float64(100))
} else if stat.Settlement == SettlementCPS {
income += (stat.ValidPayMoney * stat.CPSRate) / 100
desc = fmt.Sprintf("CPS:%.2f * %.2f", float64(stat.ValidPayMoney)/float64(100), float64(stat.CPSRate)/float64(100))
} else {
income = 0
desc = fmt.Sprintf("【%s】结算方式,需要自己计算结算金额", stat.Settlement)
}
return income, desc
}
+649
View File
@@ -0,0 +1,649 @@
package channelmod
type TagChannelInfo struct {
AppIds string
AutoGenApk string
Channel string
CheckTokenTime string
ChildCount string
ChildShowDivideRate string
CreatedAt string
ID string
IP string
Lock string
Mobile string
ParentAgent string
ParentChannel string
Password string
Remark string
ShowMagic string
Status string
Token string
Type string
UpdatedAt string
UserName string
Wallet struct {
Addr1 string
Addr2 string
}
}
type TagChannelDeductionRule struct {
AppId string
AppName string
AppType string
AutoDeduction string
BeginTime string
CPAPrice string
CPSBegin string
CPSDeductionRate string
CPSRate string
Channel string
CreatedAt string
DivideRate string
Fifth string
First string
Fourth string
ID string
LandingPage string
LessIncomeRate string
PromoteMode string
ProxyDeduction string
Second string
Settlement string
SettlementTime string
Third string
TodayDeduction string
TodayTime string
UpdatedAt string
}
type TagChannelStat struct {
AndroidAmount string
AndroidAmountCount string
AndroidVisitCount string
AppId string
AppType string
CPAPrice string
CPSRate string
Channel string
CreatedAt string
Day1RetainRate string
Day3RetainRate string
Day7RetainRate string
DeductionAmount string
DeductionAmountCount string
DirectAmount string
DirectAmountCount string
DirectVisitCount string
FissionAmount string
FissionAmountCount string
FissionVisitCount string
GameRechageAmount string
GameWithdrawAmount string
H5Amount string
H5AmountCount string
H5AndroidVisitCount string
H5IosVisitCount string
H5PcVisitCount string
H5VisitCount string
ID string
IncomeAmount string
IncomeRate string
IosAmount string
IosAmountCount string
IosVisitCount string
IsPay string
LandPageVisitCount string
LandpageAndroidClick string
LandpageIosAppstoreClick string
LandpageIosAthorClick string
LandpageIosH5Click string
LightAmount string
LightAmountCount string
LightDeductionAmount string
LightDeductionAmountCount string
LightDirectAmount string
LightDirectAmountCount string
LightFissionAmount string
LightFissionAmountCount string
LightNaturalAmount string
LightNaturalAmountCount string
LightVisitCount string
LightVisitDeductionCount string
LightVisitDirectCount string
LightVisitFissionCount string
LightVisitNaturalCount string
NaturalAmount string
NaturalAmountCount string
NewAndroidCount string
NewAndroidDeductionCount string
NewAndroidDirectCount string
NewAndroidFissionCount string
NewDeductionCount string
NewDirectCount string
NewFissionCount string
NewH5AndroidCount string
NewH5Count string
NewH5DeductionCount string
NewH5DirectCount string
NewH5FissionCount string
NewH5FormalCount string
NewH5FormalDeductionCount string
NewH5FormalDirectCount string
NewH5FormalFissionCount string
NewH5IosCount string
NewH5PcCount string
NewIosCount string
NewIosDeductionCount string
NewIosDirectCount string
NewIosFissionCount string
NewLightCount string
NewLightDeductionCount string
NewLightDirectCount string
NewLightFissionCount string
NewLightFormalCount string
NewLightFormalDeductionCount string
NewLightFormalDirectCount string
NewLightFormalFissionCount string
NewLightGuestCount string
NewLightGuestDeductionCount string
NewLightGuestDirectCount string
NewLightGuestFissionCount string
NewLightNaturalCount string
NewRechargeAmount string
NewTotalCount string
NewTotalIpCount string
ParentChannel string
PromoteMode string
Settlement string
SumDate string
TotalAmount string
TotalVisitCount string
Type string
UpdatedAt string
UserName string
ValidDeductionCount string
ValidDirectCount string
ValidPayCoin string
ValidPayMoney string
VipPayCoin string
VipPayDeduction string
VipPayMoney string
}
type TagChannelSettlement struct {
AndroidAmount string
AndroidAmountCount string
AndroidVisitCount string
AppId string
AppType string
Channel string
CreatedAt string
DeductionAmount string
DeductionAmountCount string
DirectAmount string
DirectAmountCount string
DirectVisitCount string
FissionAmount string
FissionAmountCount string
FissionVisitCount string
GameRechageAmount string
GameWithdrawAmount string
H5Amount string
H5AmountCount string
H5AndroidVisitCount string
H5IosVisitCount string
H5PcVisitCount string
H5VisitCount string
ID string
IosAmount string
IosAmountCount string
IosVisitCount string
LandPageVisitCount string
LandpageAndroidClick string
LandpageIosAppstoreClick string
LandpageIosAthorClick string
LandpageIosH5Click string
LightAmount string
LightAmountCount string
LightDeductionAmount string
LightDeductionAmountCount string
LightDirectAmount string
LightDirectAmountCount string
LightFissionAmount string
LightFissionAmountCount string
LightNaturalAmount string
LightNaturalAmountCount string
LightVisitCount string
LightVisitDeductionCount string
LightVisitDirectCount string
LightVisitFissionCount string
LightVisitNaturalCount string
NaturalAmount string
NaturalAmountCount string
NewAndroidCount string
NewAndroidDeductionCount string
NewAndroidDirectCount string
NewAndroidFissionCount string
NewDeductionCount string
NewDirectCount string
NewFissionCount string
NewH5AndroidCount string
NewH5Count string
NewH5DeductionCount string
NewH5DirectCount string
NewH5FissionCount string
NewH5FormalCount string
NewH5FormalDeductionCount string
NewH5FormalDirectCount string
NewH5FormalFissionCount string
NewH5IosCount string
NewH5PcCount string
NewIosCount string
NewIosDeductionCount string
NewIosDirectCount string
NewIosFissionCount string
NewLightCount string
NewLightDeductionCount string
NewLightDirectCount string
NewLightFissionCount string
NewLightFormalCount string
NewLightFormalDeductionCount string
NewLightFormalDirectCount string
NewLightFormalFissionCount string
NewLightGuestCount string
NewLightGuestDeductionCount string
NewLightGuestDirectCount string
NewLightGuestFissionCount string
NewLightNaturalCount string
NewRechargeAmount string
NewTotalCount string
NewTotalIpCount string
ParentChannel string
PromoteMode string
SumDate string
TotalAmount string
TotalVisitCount string
Type string
UpdatedAt string
UserName string
ValidDeductionCount string
ValidDirectCount string
ValidPayCoin string
ValidPayMoney string
VipPayCoin string
VipPayDeduction string
VipPayMoney string
}
type TagChannelStatYestoday struct {
AndroidRechargeAmount string
AppId string
Channel string
CreatedAt string
DirectAmount string
FissionAmount string
H5RechargeAmount string
ID string
IosRechargeAmount string
LightRechargeAmount string
NewAndroidCount string
NewCount string
NewDirectCount string
NewFissionCount string
NewH5Count string
NewH5FormalCount string
NewIncreaseCount string
NewIncreaseRate string
NewIosCount string
NewLightFormalCount string
NewLightGuestCount string
ParentChannel string
RechargeAmount string
RechargeIncreaseAmount string
RechargeIncreaseRate string
Settlement string
SumDate string
UpdatedAt string
VipPayCoin string
VipPayDeduction string
VipPayMoney string
}
type TagChannelOwnerChange struct {
Account string
Channel string
CreatedAt string
ID string
Mark string
NewUser string
OldUser string
Operator string
UpdatedAt string
}
var FN struct {
ChannelInfo TagChannelInfo
ChannelDeductionRule TagChannelDeductionRule
ChannelStat TagChannelStat
ChannelSettlement TagChannelSettlement
ChannelStatYestoday TagChannelStatYestoday
ChannelOwnerChange TagChannelOwnerChange
}
var TN struct {
ChannelInfo string
ChannelDeductionRule string
ChannelStat string
ChannelSettlement string
ChannelStatYestoday string
ChannelOwnerChange string
}
func init() {
FN.ChannelInfo.AppIds = "appIds"
FN.ChannelInfo.AutoGenApk = "autoGenApk"
FN.ChannelInfo.Channel = "channel"
FN.ChannelInfo.CheckTokenTime = "checkTokenTime"
FN.ChannelInfo.ChildCount = "childCount"
FN.ChannelInfo.ChildShowDivideRate = "childShowDivideRate"
FN.ChannelInfo.CreatedAt = "createdAt"
FN.ChannelInfo.ID = "_id"
FN.ChannelInfo.IP = "ip"
FN.ChannelInfo.Lock = "lock"
FN.ChannelInfo.Mobile = "mobile"
FN.ChannelInfo.ParentAgent = "parentAgent"
FN.ChannelInfo.ParentChannel = "parentChannel"
FN.ChannelInfo.Password = "password"
FN.ChannelInfo.Remark = "remark"
FN.ChannelInfo.ShowMagic = "showMagic"
FN.ChannelInfo.Status = "status"
FN.ChannelInfo.Token = "token"
FN.ChannelInfo.Type = "type"
FN.ChannelInfo.UpdatedAt = "updatedAt"
FN.ChannelInfo.UserName = "userName"
FN.ChannelInfo.Wallet.Addr1 = "wallet.addr1"
FN.ChannelInfo.Wallet.Addr2 = "wallet.addr2"
FN.ChannelDeductionRule.AppId = "appId"
FN.ChannelDeductionRule.AppName = "appName"
FN.ChannelDeductionRule.AppType = "appType"
FN.ChannelDeductionRule.AutoDeduction = "autoDeduction"
FN.ChannelDeductionRule.BeginTime = "deductionAt"
FN.ChannelDeductionRule.CPAPrice = "cpaPrice"
FN.ChannelDeductionRule.CPSBegin = "cpsBegin"
FN.ChannelDeductionRule.CPSDeductionRate = "cpsDeductionRate"
FN.ChannelDeductionRule.CPSRate = "cpsRate"
FN.ChannelDeductionRule.Channel = "channel"
FN.ChannelDeductionRule.CreatedAt = "createdAt"
FN.ChannelDeductionRule.DivideRate = "divideRate"
FN.ChannelDeductionRule.Fifth = "fifth"
FN.ChannelDeductionRule.First = "first"
FN.ChannelDeductionRule.Fourth = "fourth"
FN.ChannelDeductionRule.ID = "_id"
FN.ChannelDeductionRule.LandingPage = "landingPage"
FN.ChannelDeductionRule.LessIncomeRate = "lessIncomeRate"
FN.ChannelDeductionRule.PromoteMode = "promoteMode"
FN.ChannelDeductionRule.ProxyDeduction = "proxyDeduction"
FN.ChannelDeductionRule.Second = "second"
FN.ChannelDeductionRule.Settlement = "settlement"
FN.ChannelDeductionRule.SettlementTime = "settlementTime"
FN.ChannelDeductionRule.Third = "third"
FN.ChannelDeductionRule.TodayDeduction = "todayDeduction"
FN.ChannelDeductionRule.TodayTime = "todayTime"
FN.ChannelDeductionRule.UpdatedAt = "updatedAt"
FN.ChannelStat.AndroidAmount = "androidAmount"
FN.ChannelStat.AndroidAmountCount = "androidAmountCount"
FN.ChannelStat.AndroidVisitCount = "androidVisitCount"
FN.ChannelStat.AppId = "appId"
FN.ChannelStat.AppType = "appType"
FN.ChannelStat.CPAPrice = "cpaPrice"
FN.ChannelStat.CPSRate = "cpsRate"
FN.ChannelStat.Channel = "channel"
FN.ChannelStat.CreatedAt = "createdAt"
FN.ChannelStat.Day1RetainRate = "day1RetainRate"
FN.ChannelStat.Day3RetainRate = "day3RetainRate"
FN.ChannelStat.Day7RetainRate = "day7RetainRate"
FN.ChannelStat.DeductionAmount = "deductionAmount"
FN.ChannelStat.DeductionAmountCount = "deductionAmountCount"
FN.ChannelStat.DirectAmount = "directAmount"
FN.ChannelStat.DirectAmountCount = "directAmountCount"
FN.ChannelStat.DirectVisitCount = "directVisitCount"
FN.ChannelStat.FissionAmount = "fissionAmount"
FN.ChannelStat.FissionAmountCount = "fissionAmountCount"
FN.ChannelStat.FissionVisitCount = "fissionVisitCount"
FN.ChannelStat.GameRechageAmount = "gameRechageAmount"
FN.ChannelStat.GameWithdrawAmount = "gameWithdrawAmount"
FN.ChannelStat.H5Amount = "h5Amount"
FN.ChannelStat.H5AmountCount = "h5AmountCount"
FN.ChannelStat.H5AndroidVisitCount = "h5AndroidVisitCount"
FN.ChannelStat.H5IosVisitCount = "h5IosVisitCount"
FN.ChannelStat.H5PcVisitCount = "h5PcVisitCount"
FN.ChannelStat.H5VisitCount = "h5VisitCount"
FN.ChannelStat.ID = "_id"
FN.ChannelStat.IncomeAmount = "IncomeAmount"
FN.ChannelStat.IncomeRate = "incomeRate"
FN.ChannelStat.IosAmount = "iosAmount"
FN.ChannelStat.IosAmountCount = "iosAmountCount"
FN.ChannelStat.IosVisitCount = "iosVisitCount"
FN.ChannelStat.IsPay = "isPay"
FN.ChannelStat.LandPageVisitCount = "landPageVisitCount"
FN.ChannelStat.LandpageAndroidClick = "landpageAndroidClick"
FN.ChannelStat.LandpageIosAppstoreClick = "landpageIosAppstoreClick"
FN.ChannelStat.LandpageIosAthorClick = "landpageIosAthorClick"
FN.ChannelStat.LandpageIosH5Click = "landpageIosH5Click"
FN.ChannelStat.LightAmount = "lightAmount"
FN.ChannelStat.LightAmountCount = "lightAmountCount"
FN.ChannelStat.LightDeductionAmount = "lightDeductionAmount"
FN.ChannelStat.LightDeductionAmountCount = "lightDeductionAmountCount"
FN.ChannelStat.LightDirectAmount = "lightDirectAmount"
FN.ChannelStat.LightDirectAmountCount = "lightDirectAmountCount"
FN.ChannelStat.LightFissionAmount = "lightFissionAmount"
FN.ChannelStat.LightFissionAmountCount = "lightFissionAmountCount"
FN.ChannelStat.LightNaturalAmount = "lightNaturalAmount"
FN.ChannelStat.LightNaturalAmountCount = "lightNaturalAmountCount"
FN.ChannelStat.LightVisitCount = "lightVisitCount"
FN.ChannelStat.LightVisitDeductionCount = "lightVisitDeductionCount"
FN.ChannelStat.LightVisitDirectCount = "lightVisitDirectCount"
FN.ChannelStat.LightVisitFissionCount = "lightVisitFissionCount"
FN.ChannelStat.LightVisitNaturalCount = "lightVisitNaturalCount"
FN.ChannelStat.NaturalAmount = "naturalAmount"
FN.ChannelStat.NaturalAmountCount = "naturalAmountCount"
FN.ChannelStat.NewAndroidCount = "newAndroidCount"
FN.ChannelStat.NewAndroidDeductionCount = "newAndroidDeductionCount"
FN.ChannelStat.NewAndroidDirectCount = "newAndroidDirectCount"
FN.ChannelStat.NewAndroidFissionCount = "newAndroidFissionCount"
FN.ChannelStat.NewDeductionCount = "newDeductionCount"
FN.ChannelStat.NewDirectCount = "newDirectCount"
FN.ChannelStat.NewFissionCount = "newFissionCount"
FN.ChannelStat.NewH5AndroidCount = "newH5AndroidCount"
FN.ChannelStat.NewH5Count = "newH5Count"
FN.ChannelStat.NewH5DeductionCount = "newH5DeductionCount"
FN.ChannelStat.NewH5DirectCount = "newH5DirectCount"
FN.ChannelStat.NewH5FissionCount = "newH5FissionCount"
FN.ChannelStat.NewH5FormalCount = "newH5FormalCount"
FN.ChannelStat.NewH5FormalDeductionCount = "newH5FormalDeductionCount"
FN.ChannelStat.NewH5FormalDirectCount = "newH5FormalDirectCount"
FN.ChannelStat.NewH5FormalFissionCount = "newH5FormalFissionCount"
FN.ChannelStat.NewH5IosCount = "newH5IosCount"
FN.ChannelStat.NewH5PcCount = "newH5PcCount"
FN.ChannelStat.NewIosCount = "newIosCount"
FN.ChannelStat.NewIosDeductionCount = "newIosDeductionCount"
FN.ChannelStat.NewIosDirectCount = "newIosDirectCount"
FN.ChannelStat.NewIosFissionCount = "newIosFissionCount"
FN.ChannelStat.NewLightCount = "newLightCount"
FN.ChannelStat.NewLightDeductionCount = "newLightDeductionCount"
FN.ChannelStat.NewLightDirectCount = "newLightDirectCount"
FN.ChannelStat.NewLightFissionCount = "newLightFissionCount"
FN.ChannelStat.NewLightFormalCount = "newLightFormalCount"
FN.ChannelStat.NewLightFormalDeductionCount = "newLightFormalDeductionCount"
FN.ChannelStat.NewLightFormalDirectCount = "newLightFormalDirectCount"
FN.ChannelStat.NewLightFormalFissionCount = "newLightFormalFissionCount"
FN.ChannelStat.NewLightGuestCount = "newLightGuestCount"
FN.ChannelStat.NewLightGuestDeductionCount = "newLightGuestDeductionCount"
FN.ChannelStat.NewLightGuestDirectCount = "newLightGuestDirectCount"
FN.ChannelStat.NewLightGuestFissionCount = "newLightGuestFissionCount"
FN.ChannelStat.NewLightNaturalCount = "newLightNaturalCount"
FN.ChannelStat.NewRechargeAmount = "newRechargeAmount"
FN.ChannelStat.NewTotalCount = "newTotalCount"
FN.ChannelStat.NewTotalIpCount = "newTotalIpCount"
FN.ChannelStat.ParentChannel = "parentChannel"
FN.ChannelStat.PromoteMode = "promoteMode"
FN.ChannelStat.Settlement = "settlement"
FN.ChannelStat.SumDate = "sumDate"
FN.ChannelStat.TotalAmount = "totalAmount"
FN.ChannelStat.TotalVisitCount = "totalVisitCount"
FN.ChannelStat.Type = "type"
FN.ChannelStat.UpdatedAt = "updatedAt"
FN.ChannelStat.UserName = "userName"
FN.ChannelStat.ValidDeductionCount = "validDeductionCount"
FN.ChannelStat.ValidDirectCount = "validDirectCount"
FN.ChannelStat.ValidPayCoin = "validPayCoin"
FN.ChannelStat.ValidPayMoney = "validPayMoney"
FN.ChannelStat.VipPayCoin = "vipPayCoin"
FN.ChannelStat.VipPayDeduction = "vipPayDeduction"
FN.ChannelStat.VipPayMoney = "vipPayMoney"
FN.ChannelSettlement.AndroidAmount = "androidAmount"
FN.ChannelSettlement.AndroidAmountCount = "androidAmountCount"
FN.ChannelSettlement.AndroidVisitCount = "androidVisitCount"
FN.ChannelSettlement.AppId = "appId"
FN.ChannelSettlement.AppType = "appType"
FN.ChannelSettlement.Channel = "channel"
FN.ChannelSettlement.CreatedAt = "createdAt"
FN.ChannelSettlement.DeductionAmount = "deductionAmount"
FN.ChannelSettlement.DeductionAmountCount = "deductionAmountCount"
FN.ChannelSettlement.DirectAmount = "directAmount"
FN.ChannelSettlement.DirectAmountCount = "directAmountCount"
FN.ChannelSettlement.DirectVisitCount = "directVisitCount"
FN.ChannelSettlement.FissionAmount = "fissionAmount"
FN.ChannelSettlement.FissionAmountCount = "fissionAmountCount"
FN.ChannelSettlement.FissionVisitCount = "fissionVisitCount"
FN.ChannelSettlement.GameRechageAmount = "gameRechageAmount"
FN.ChannelSettlement.GameWithdrawAmount = "gameWithdrawAmount"
FN.ChannelSettlement.H5Amount = "h5Amount"
FN.ChannelSettlement.H5AmountCount = "h5AmountCount"
FN.ChannelSettlement.H5AndroidVisitCount = "h5AndroidVisitCount"
FN.ChannelSettlement.H5IosVisitCount = "h5IosVisitCount"
FN.ChannelSettlement.H5PcVisitCount = "h5PcVisitCount"
FN.ChannelSettlement.H5VisitCount = "h5VisitCount"
FN.ChannelSettlement.ID = "_id"
FN.ChannelSettlement.IosAmount = "iosAmount"
FN.ChannelSettlement.IosAmountCount = "iosAmountCount"
FN.ChannelSettlement.IosVisitCount = "iosVisitCount"
FN.ChannelSettlement.LandPageVisitCount = "landPageVisitCount"
FN.ChannelSettlement.LandpageAndroidClick = "landpageAndroidClick"
FN.ChannelSettlement.LandpageIosAppstoreClick = "landpageIosAppstoreClick"
FN.ChannelSettlement.LandpageIosAthorClick = "landpageIosAthorClick"
FN.ChannelSettlement.LandpageIosH5Click = "landpageIosH5Click"
FN.ChannelSettlement.LightAmount = "lightAmount"
FN.ChannelSettlement.LightAmountCount = "lightAmountCount"
FN.ChannelSettlement.LightDeductionAmount = "lightDeductionAmount"
FN.ChannelSettlement.LightDeductionAmountCount = "lightDeductionAmountCount"
FN.ChannelSettlement.LightDirectAmount = "lightDirectAmount"
FN.ChannelSettlement.LightDirectAmountCount = "lightDirectAmountCount"
FN.ChannelSettlement.LightFissionAmount = "lightFissionAmount"
FN.ChannelSettlement.LightFissionAmountCount = "lightFissionAmountCount"
FN.ChannelSettlement.LightNaturalAmount = "lightNaturalAmount"
FN.ChannelSettlement.LightNaturalAmountCount = "lightNaturalAmountCount"
FN.ChannelSettlement.LightVisitCount = "lightVisitCount"
FN.ChannelSettlement.LightVisitDeductionCount = "lightVisitDeductionCount"
FN.ChannelSettlement.LightVisitDirectCount = "lightVisitDirectCount"
FN.ChannelSettlement.LightVisitFissionCount = "lightVisitFissionCount"
FN.ChannelSettlement.LightVisitNaturalCount = "lightVisitNaturalCount"
FN.ChannelSettlement.NaturalAmount = "naturalAmount"
FN.ChannelSettlement.NaturalAmountCount = "naturalAmountCount"
FN.ChannelSettlement.NewAndroidCount = "newAndroidCount"
FN.ChannelSettlement.NewAndroidDeductionCount = "newAndroidDeductionCount"
FN.ChannelSettlement.NewAndroidDirectCount = "newAndroidDirectCount"
FN.ChannelSettlement.NewAndroidFissionCount = "newAndroidFissionCount"
FN.ChannelSettlement.NewDeductionCount = "newDeductionCount"
FN.ChannelSettlement.NewDirectCount = "newDirectCount"
FN.ChannelSettlement.NewFissionCount = "newFissionCount"
FN.ChannelSettlement.NewH5AndroidCount = "newH5AndroidCount"
FN.ChannelSettlement.NewH5Count = "newH5Count"
FN.ChannelSettlement.NewH5DeductionCount = "newH5DeductionCount"
FN.ChannelSettlement.NewH5DirectCount = "newH5DirectCount"
FN.ChannelSettlement.NewH5FissionCount = "newH5FissionCount"
FN.ChannelSettlement.NewH5FormalCount = "newH5FormalCount"
FN.ChannelSettlement.NewH5FormalDeductionCount = "newH5FormalDeductionCount"
FN.ChannelSettlement.NewH5FormalDirectCount = "newH5FormalDirectCount"
FN.ChannelSettlement.NewH5FormalFissionCount = "newH5FormalFissionCount"
FN.ChannelSettlement.NewH5IosCount = "newH5IosCount"
FN.ChannelSettlement.NewH5PcCount = "newH5PcCount"
FN.ChannelSettlement.NewIosCount = "newIosCount"
FN.ChannelSettlement.NewIosDeductionCount = "newIosDeductionCount"
FN.ChannelSettlement.NewIosDirectCount = "newIosDirectCount"
FN.ChannelSettlement.NewIosFissionCount = "newIosFissionCount"
FN.ChannelSettlement.NewLightCount = "newLightCount"
FN.ChannelSettlement.NewLightDeductionCount = "newLightDeductionCount"
FN.ChannelSettlement.NewLightDirectCount = "newLightDirectCount"
FN.ChannelSettlement.NewLightFissionCount = "newLightFissionCount"
FN.ChannelSettlement.NewLightFormalCount = "newLightFormalCount"
FN.ChannelSettlement.NewLightFormalDeductionCount = "newLightFormalDeductionCount"
FN.ChannelSettlement.NewLightFormalDirectCount = "newLightFormalDirectCount"
FN.ChannelSettlement.NewLightFormalFissionCount = "newLightFormalFissionCount"
FN.ChannelSettlement.NewLightGuestCount = "newLightGuestCount"
FN.ChannelSettlement.NewLightGuestDeductionCount = "newLightGuestDeductionCount"
FN.ChannelSettlement.NewLightGuestDirectCount = "newLightGuestDirectCount"
FN.ChannelSettlement.NewLightGuestFissionCount = "newLightGuestFissionCount"
FN.ChannelSettlement.NewLightNaturalCount = "newLightNaturalCount"
FN.ChannelSettlement.NewRechargeAmount = "newRechargeAmount"
FN.ChannelSettlement.NewTotalCount = "newTotalCount"
FN.ChannelSettlement.NewTotalIpCount = "newTotalIpCount"
FN.ChannelSettlement.ParentChannel = "parentChannel"
FN.ChannelSettlement.PromoteMode = "promoteMode"
FN.ChannelSettlement.SumDate = "sumDate"
FN.ChannelSettlement.TotalAmount = "totalAmount"
FN.ChannelSettlement.TotalVisitCount = "totalVisitCount"
FN.ChannelSettlement.Type = "type"
FN.ChannelSettlement.UpdatedAt = "updatedAt"
FN.ChannelSettlement.UserName = "userName"
FN.ChannelSettlement.ValidDeductionCount = "validDeductionCount"
FN.ChannelSettlement.ValidDirectCount = "validDirectCount"
FN.ChannelSettlement.ValidPayCoin = "validPayCoin"
FN.ChannelSettlement.ValidPayMoney = "validPayMoney"
FN.ChannelSettlement.VipPayCoin = "vipPayCoin"
FN.ChannelSettlement.VipPayDeduction = "vipPayDeduction"
FN.ChannelSettlement.VipPayMoney = "vipPayMoney"
FN.ChannelStatYestoday.AndroidRechargeAmount = "androidRechargeAmount"
FN.ChannelStatYestoday.AppId = "appId"
FN.ChannelStatYestoday.Channel = "channel"
FN.ChannelStatYestoday.CreatedAt = "createdAt"
FN.ChannelStatYestoday.DirectAmount = "directAmount"
FN.ChannelStatYestoday.FissionAmount = "fissionAmount"
FN.ChannelStatYestoday.H5RechargeAmount = "h5RechargeAmount"
FN.ChannelStatYestoday.ID = "_id"
FN.ChannelStatYestoday.IosRechargeAmount = "iosRechargeAmount"
FN.ChannelStatYestoday.LightRechargeAmount = "lightRechargeAmount"
FN.ChannelStatYestoday.NewAndroidCount = "newAndroidCount"
FN.ChannelStatYestoday.NewCount = "newCount"
FN.ChannelStatYestoday.NewDirectCount = "newDirectCount"
FN.ChannelStatYestoday.NewFissionCount = "newFissionCount"
FN.ChannelStatYestoday.NewH5Count = "newH5Count"
FN.ChannelStatYestoday.NewH5FormalCount = "newH5FormalCount"
FN.ChannelStatYestoday.NewIncreaseCount = "newIncreaseCount"
FN.ChannelStatYestoday.NewIncreaseRate = "newIncreaseRate"
FN.ChannelStatYestoday.NewIosCount = "newIosCount"
FN.ChannelStatYestoday.NewLightFormalCount = "newLightFormalCount"
FN.ChannelStatYestoday.NewLightGuestCount = "newLightGuestCount"
FN.ChannelStatYestoday.ParentChannel = "parentChannel"
FN.ChannelStatYestoday.RechargeAmount = "rechargeAmount"
FN.ChannelStatYestoday.RechargeIncreaseAmount = "rechargeIncreaseAmount"
FN.ChannelStatYestoday.RechargeIncreaseRate = "rechargeIncreaseRate"
FN.ChannelStatYestoday.Settlement = "settlement"
FN.ChannelStatYestoday.SumDate = "sumDate"
FN.ChannelStatYestoday.UpdatedAt = "updatedAt"
FN.ChannelStatYestoday.VipPayCoin = "vipPayCoin"
FN.ChannelStatYestoday.VipPayDeduction = "vipPayDeduction"
FN.ChannelStatYestoday.VipPayMoney = "vipPayMoney"
FN.ChannelOwnerChange.Channel = "channel"
FN.ChannelOwnerChange.CreatedAt = "createdAt"
FN.ChannelOwnerChange.Account = "account"
FN.ChannelOwnerChange.ID = "_id"
FN.ChannelOwnerChange.Mark = "mark"
FN.ChannelOwnerChange.NewUser = "newUser"
FN.ChannelOwnerChange.OldUser = "oldUser"
FN.ChannelOwnerChange.Operator = "operator"
FN.ChannelOwnerChange.UpdatedAt = "updatedAt"
TN.ChannelInfo = "channel_info"
TN.ChannelDeductionRule = "channel_app_deduction"
TN.ChannelStat = "channel_stat"
TN.ChannelSettlement = "channel_settlement_bak"
TN.ChannelStatYestoday = "channel_stat_yestoday"
TN.ChannelOwnerChange = "channel_owner_change"
}
+596
View File
@@ -0,0 +1,596 @@
package channelmod
import (
"strings"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
const (
OfficialChannelName = "官方"
OfficialChannelDisplayName = "zilai"
)
var (
officialChannelNames = []string{OfficialChannelName, OfficialChannelDisplayName}
)
// 官方渠道
func IsOfficialChannelName(name string) bool {
for _, value := range officialChannelNames {
if value == name {
return true
}
}
return false
}
// 官方渠道 或 无渠道码
func IsOfficialChannelOrEmpty(name string) bool {
name = strings.TrimSpace(name)
if name == "" {
return true
}
for _, value := range officialChannelNames {
if value == name {
return true
}
}
return false
}
func ChannelDisplayName(name string) string {
if name == OfficialChannelName {
return OfficialChannelDisplayName
}
return name
}
// 结算方式
type SettlementWay string
const (
SettlementCPA SettlementWay = "cpa"
SettlementCPS SettlementWay = "cps"
SettlementCPT SettlementWay = "cpt"
SettlementCPC SettlementWay = "cpc"
SettlementHZ SettlementWay = "hz" //下载站
)
type ChannelType int32
const (
ChannelTypeNone ChannelType = 0 // 无
ChannelTypeParent ChannelType = 1 // 一级
ChannelTypeSecond ChannelType = 2 // 二级
ChannelTypeThird ChannelType = 3 // 三级
ChannelTypeForth ChannelType = 4 // 四级
ChannelTypeEnd ChannelType = 10 // End
)
type ChannelTypeList []ChannelType
type AppType int32
const (
AppTypeNone AppType = 0 // 所有
AppTypePkg AppType = 1 // 安装包
AppTypeLight AppType = 2 // 轻量版
AppTypeH5 AppType = 3 // H5网页
)
type PromoteMode int32
const (
PromoteModeNone PromoteMode = 0 // 所有
PromoteModeInstall PromoteMode = 1 // 安装
PromoteModeRegister PromoteMode = 2 // 注册
)
func GetChildChannelTypes() ChannelTypeList {
ret := make([]ChannelType, 0)
for i := ChannelTypeParent + 1; i < ChannelTypeEnd; i++ {
ret = append(ret, i)
}
return ret
}
func GetAllChannelTypes() ChannelTypeList {
ret := make([]ChannelType, 0)
for i := ChannelTypeParent; i < ChannelTypeEnd; i++ {
ret = append(ret, i)
}
return ret
}
func (l ChannelTypeList) Include(value ChannelType) bool {
for _, ct := range l {
if ct == value {
return true
}
}
return false
}
type Wallet struct {
Addr1 string `json:"addr1" bson:"addr1"` // 钱包地址1
Addr2 string `json:"addr2" bson:"addr2"` // 钱包地址2
}
// 渠道-代理商
// @table:channel_info
type ChannelInfo struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // ID
Channel string `bson:"channel" json:"channel"` // 渠道
AppIds []int32 `bson:"appIds" json:"appIds"` // 渠道对应的app
UserName string `bson:"userName" json:"userName"` // 所有者
ParentChannel string `bson:"parentChannel" json:"parentChannel"` // 父渠道 如果为空字符串,则为渠道,否则为代理
ParentAgent string `bson:"parentAgent" json:"parentAgent"` // 父代理 (从二级的子代理开始用ParentAgent描述父子关系)
ChildCount int64 `bson:"childCount" json:"childCount"` // 子渠道数量
Password string `bson:"password" json:"password"` // 代理商密码
IP string `bson:"ip" json:"ip"` // ip
Token string `bson:"token" json:"token"` // token
CheckTokenTime time.Time `bson:"checkTokenTime" json:"checkTokenTime"` // 检查Token的时间
Status bool `bson:"status" json:"status"` // 状态 开/关
Mobile string `bson:"mobile" json:"mobile"` // 手机号
Type ChannelType `bson:"type" json:"type"` // 渠道类型:1 一级 2:二级
Remark string `bson:"remark" json:"remark"` // 备注
Lock bool `bson:"lock" json:"lock"` // 禁止登陆
Wallet Wallet `bson:"wallet" json:"wallet"` // 钱包地址
AutoGenApk bool `bson:"autoGenApk" json:"autoGenApk"` // 自动生成渠道包
ShowMagic int32 `bson:"showMagic" json:"showMagic"` // 正常显示数据 n>0 展示空白数据
ChildShowDivideRate bool `bson:"childShowDivideRate" json:"childShowDivideRate"` // 下级是否显示分成比例
CreatedAt time.Time `bson:"createdAt" json:"createdAt"` // 创建时间
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` // 更新时间
}
type ChannelInfoList []*ChannelInfo
// @table:channel_app_deduction
type ChannelDeductionRule struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // ID
AppId int32 `bson:"appId" json:"appId"` // 应用ID
Channel string `bson:"channel" json:"channel"` // 渠道
AppName string `bson:"appName" json:"appName"` // 应用名称
AppType AppType `bson:"appType" json:"appType"` // 应用类型
PromoteMode PromoteMode `bson:"promoteMode" json:"promoteMode"` // 推广类型
Settlement SettlementWay `bson:"settlement" json:"settlement"` // 结算方式 cps/cpa/cpt/cpc
First int32 `bson:"first" json:"first"` // 一阶
Second int32 `bson:"second" json:"second"` // 二阶
Third int32 `bson:"third" json:"third"` // 三阶
Fourth int32 `bson:"fourth" json:"fourth"` // 四阶
Fifth int32 `bson:"fifth" json:"fifth"` // 5阶
CPAPrice int64 `bson:"cpaPrice" json:"cpaPrice"` // 单价
CPSRate int64 `bson:"cpsRate" json:"cpsRate"` // CPS 分成比列 0-100
CPSBegin int64 `bson:"cpsBegin" json:"cpsBegin"` // CPS 开始扣量金额
CPSDeductionRate int64 `bson:"cpsDeductionRate" json:"cpsDeductionRate"` // CPS 扣量比例
BeginTime time.Time `bson:"deductionAt" json:"deductionAt"` // 扣量开始时间
SettlementTime time.Time `bson:"settlementTime" json:"settlementTime"` // 扣量结算时间
TodayTime time.Time `bson:"todayTime" json:"todayTime"` // 当日时间
TodayDeduction int64 `bson:"todayDeduction" json:"todayDeduction"` // 当日扣量金额
LandingPage string `bson:"landingPage" json:"landingPage"` // 落地页
ProxyDeduction int64 `bson:"proxyDeduction" json:"proxyDeduction"` // 代理扣量比例
AutoDeduction bool `bson:"autoDeduction" json:"autoDeduction"` // 自动扣量开关
DivideRate int64 `bson:"divideRate" json:"divideRate"` // 代理分成比例
LessIncomeRate float64 `bson:"lessIncomeRate" json:"lessIncomeRate"` // 最低收益比 CPA低于该值开启扣量(0.1 - 3.0)
CreatedAt time.Time `bson:"createdAt" json:"createdAt"` // 创建时间
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` // 更新时间
}
type ChannelDeductionRuleList []*ChannelDeductionRule
// 渠道每日统计
// @table:channel_stat
type ChannelStat struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // ID
Channel string `bson:"channel" json:"channel"` // 渠道
SumDate time.Time `bson:"sumDate" json:"sumDate"` // 记录时间 15分钟对齐
AppId int32 `bson:"appId" json:"appId"` // appId
Type ChannelType `bson:"type" json:"type"` // 渠道类型:1 一级 2:二级
Settlement SettlementWay `bson:"settlement" json:"settlement"` // 结算方式 cps/cpa/cpt/cpc
CPAPrice int64 `bson:"cpaPrice" json:"cpaPrice"` // 单价
CPSRate int64 `bson:"cpsRate" json:"cpsRate"` // CPS 分成比列 0-100
AppType AppType `bson:"appType" json:"appType"` // 应用类型
PromoteMode PromoteMode `bson:"promoteMode" json:"promoteMode"` // 推广类型
UserName string `bson:"userName" json:"userName"` // 所有者
ParentChannel string `bson:"parentChannel" json:"parentChannel"` // 父渠道 如果为空字符串,则为渠道,否则为代理
// 收益及结算
ValidDirectCount int64 `bson:"validDirectCount,omitempty" json:"validDirectCount"` // 有效直推总数
ValidDeductionCount int64 `bson:"validDeductionCount,omitempty" json:"validDeductionCount"` // 有效扣量总数
ValidPayMoney int64 `bson:"validPayMoney,omitempty" json:"validPayMoney"` // 有效收益金额
ValidPayCoin int64 `bson:"validPayCoin,omitempty" json:"validPayCoin"` // 有效收益金币金额
IncomeAmount int64 `bson:"IncomeAmount,omitempty" json:"IncomeAmount"` // 收益估算
IncomeRate float64 `bson:"incomeRate,omitempty" json:"incomeRate"` // 收益比
IsPay bool `bson:"isPay,omitempty" json:"isPay"` // 是否已结算
// 注册
NewTotalIpCount int64 `bson:"newTotalIpCount,omitempty" json:"newTotalIpCount"` // 新增IP总量
NewTotalCount int64 `bson:"newTotalCount,omitempty" json:"newTotalCount"` // **新增总量
NewDirectCount int64 `bson:"newDirectCount,omitempty" json:"newDirectCount"` // 新增直推
NewFissionCount int64 `bson:"newFissionCount,omitempty" json:"newFissionCount"` // 新增裂变
NewDeductionCount int64 `bson:"newDeductionCount,omitempty" json:"newDeductionCount"` // 新增扣量
NewAndroidCount int64 `bson:"newAndroidCount,omitempty" json:"newAndroidCount"` // android新增
NewAndroidDirectCount int64 `bson:"newAndroidDirectCount,omitempty" json:"newAndroidDirectCount"` // 新增安卓直推
NewAndroidFissionCount int64 `bson:"newAndroidFissionCount,omitempty" json:"newAndroidFissionCount"` // 新增安卓裂变
NewAndroidDeductionCount int64 `bson:"newAndroidDeductionCount,omitempty" json:"newAndroidDeductionCount"` // 新增安卓扣量
NewIosCount int64 `bson:"newIosCount,omitempty" json:"newIosCount"` // ios新增
NewIosDirectCount int64 `bson:"newIosDirectCount,omitempty" json:"newIosDirectCount"` // 新增IOS直推
NewIosFissionCount int64 `bson:"newIosFissionCount,omitempty" json:"newIosFissionCount"` // 新增IOS裂变
NewIosDeductionCount int64 `bson:"newIosDeductionCount,omitempty" json:"newIosDeductionCount"` // 新增IOS扣量
NewLightCount int64 `bson:"newLightCount,omitempty" json:"newLightCount"` // light新增
NewLightGuestCount int64 `bson:"newLightGuestCount,omitempty" json:"newLightGuestCount"` // **轻量安装
NewLightGuestDirectCount int64 `bson:"newLightGuestDirectCount,omitempty" json:"newLightGuestDirectCount"` // 新增LightGuest直推
NewLightGuestFissionCount int64 `bson:"newLightGuestFissionCount,omitempty" json:"newLightGuestFissionCount"` // 新增LightGuest裂变
NewLightGuestDeductionCount int64 `bson:"newLightGuestDeductionCount,omitempty" json:"newLightGuestDeductionCount"` // 新增LightGuest扣量
NewLightFormalCount int64 `bson:"newLightFormalCount,omitempty" json:"newLightFormalCount"` // **轻量注册
NewLightFormalDirectCount int64 `bson:"newLightFormalDirectCount,omitempty" json:"newLightFormalDirectCount"` // 新增LightFormal直推
NewLightFormalFissionCount int64 `bson:"newLightFormalFissionCount,omitempty" json:"newLightFormalFissionCount"` // 新增LightFormal裂变
NewLightFormalDeductionCount int64 `bson:"newLightFormalDeductionCount,omitempty" json:"newLightFormalDeductionCount"` // 新增LightFormal扣量
NewLightDirectCount int64 `bson:"newLightDirectCount,omitempty" json:"newLightDirectCount"` // light新增直推
NewLightFissionCount int64 `bson:"newLightFissionCount,omitempty" json:"newLightFissionCount"` // light新增裂变
NewLightDeductionCount int64 `bson:"newLightDeductionCount,omitempty" json:"newLightDeductionCount"` // light新增扣量
NewLightNaturalCount int64 `bson:"newLightNaturalCount,omitempty" json:"newLightNaturalCount"` // light自然新增
NewH5Count int64 `bson:"newH5Count,omitempty" json:"newH5Count"` // h5新增
NewH5DirectCount int64 `bson:"newH5DirectCount,omitempty" json:"newH5DirectCount"` // 新增H5直推
NewH5FissionCount int64 `bson:"newH5FissionCount,omitempty" json:"newH5FissionCount"` // 新增H5裂变
NewH5DeductionCount int64 `bson:"newH5DeductionCount,omitempty" json:"newH5DeductionCount"` // 新增H5扣量
NewH5AndroidCount int64 `bson:"newH5AndroidCount,omitempty" json:"newH5AndroidCount"` // h5安卓新增
NewH5IosCount int64 `bson:"newH5IosCount,omitempty" json:"newH5IosCount"` // h5苹果新增
NewH5PcCount int64 `bson:"newH5PcCount,omitempty" json:"newH5PcCount"` // h5电脑新增
NewH5FormalCount int64 `bson:"newH5FormalCount,omitempty" json:"newH5FormalCount"` // h5注册新增
NewH5FormalDirectCount int64 `bson:"newH5FormalDirectCount,omitempty" json:"newH5FormalDirectCount"` // 新增H5正式直推
NewH5FormalFissionCount int64 `bson:"newH5FormalFissionCount,omitempty" json:"newH5FormalFissionCount"` // 新增H5正式裂变
NewH5FormalDeductionCount int64 `bson:"newH5FormalDeductionCount,omitempty" json:"newH5FormalDeductionCount"` // 新增H5正式扣量
// 访问
TotalVisitCount int64 `bson:"totalVisitCount,omitempty" json:"totalVisitCount"` // **总计访问数
DirectVisitCount int64 `bson:"directVisitCount,omitempty" json:"directVisitCount"` // 直推访问数
FissionVisitCount int64 `bson:"fissionVisitCount,omitempty" json:"fissionVisitCount"` // 裂变访问数
AndroidVisitCount int64 `bson:"androidVisitCount,omitempty" json:"androidVisitCount"` // android访问
IosVisitCount int64 `bson:"iosVisitCount,omitempty" json:"iosVisitCount"` // ios访问
LightVisitCount int64 `bson:"lightVisitCount,omitempty" json:"lightVisitCount"` // **轻量访问
LightVisitDirectCount int64 `bson:"lightVisitDirectCount,omitempty" json:"lightVisitDirectCount"` // light访问量直推
LightVisitFissionCount int64 `bson:"lightVisitFissionCount,omitempty" json:"lightVisitFissionCount"` // light访问量裂变
LightVisitDeductionCount int64 `bson:"lightVisitDeductionCount,omitempty" json:"lightVisitDeductionCount"` // light访问量扣量
LightVisitNaturalCount int64 `bson:"lightVisitNaturalCount,omitempty" json:"lightVisitNaturalCount"` // light访问量自然
H5VisitCount int64 `bson:"h5VisitCount,omitempty" json:"h5VisitCount"` // h5访问
H5AndroidVisitCount int64 `bson:"h5AndroidVisitCount,omitempty" json:"h5AndroidVisitCount"` // h5安卓访问
H5IosVisitCount int64 `bson:"h5IosVisitCount,omitempty" json:"h5IosVisitCount"` // h5苹果访问
H5PcVisitCount int64 `bson:"h5PcVisitCount,omitempty" json:"h5PcVisitCount"` // h5电脑访问
// 充值统计
TotalAmount int64 `bson:"totalAmount,omitempty" json:"totalAmount"` // **充值金额总量
DirectAmount int64 `bson:"directAmount,omitempty" json:"directAmount"` // 直推充值金额
DirectAmountCount int64 `bson:"directAmountCount,omitempty" json:"directAmountCount"` // 直推充值订单数
FissionAmount int64 `bson:"fissionAmount,omitempty" json:"fissionAmount"` // 裂变充值金额
FissionAmountCount int64 `bson:"fissionAmountCount,omitempty" json:"fissionAmountCount"` // 裂变充值订单数
NaturalAmount int64 `bson:"naturalAmount,omitempty" json:"naturalAmount"` // 自然充值
NaturalAmountCount int64 `bson:"naturalAmountCount,omitempty" json:"naturalAmountCount"` // 自然充值订单数
DeductionAmount int64 `bson:"deductionAmount,omitempty" json:"deductionAmount"` // 充值扣量
DeductionAmountCount int64 `bson:"deductionAmountCount,omitempty" json:"deductionAmountCount"` // 充值扣量次数
AndroidAmount int64 `bson:"androidAmount,omitempty" json:"androidAmount"` // +安卓充值金额
AndroidAmountCount int64 `bson:"androidAmountCount,omitempty" json:"androidAmountCount"` // +安卓充值次数
IosAmount int64 `bson:"iosAmount,omitempty" json:"iosAmount"` // +Ios充值金额
IosAmountCount int64 `bson:"iosAmountCount,omitempty" json:"iosAmountCount"` // +Ios充值次数
H5Amount int64 `bson:"h5Amount,omitempty" json:"h5Amount"` // +H5充值金额
H5AmountCount int64 `bson:"h5AmountCount,omitempty" json:"h5AmountCount"` // +H5充值次数
LightAmount int64 `bson:"lightAmount,omitempty" json:"lightAmount"` // light充值金额
LightAmountCount int64 `bson:"lightAmountCount,omitempty" json:"lightAmountCount"` // light充值次数
LightDirectAmount int64 `bson:"lightDirectAmount,omitempty" json:"lightDirectAmount"` // light充值金额直推
LightDirectAmountCount int64 `bson:"lightDirectAmountCount,omitempty" json:"lightDirectAmountCount"` // light充值次数直推
LightFissionAmount int64 `bson:"lightFissionAmount,omitempty" json:"lightFissionAmount"` // light充值金额裂变
LightFissionAmountCount int64 `bson:"lightFissionAmountCount,omitempty" json:"lightFissionAmountCount"` // light充值次数裂变
LightDeductionAmount int64 `bson:"lightDeductionAmount,omitempty" json:"lightDeductionAmount"` // light充值金额扣量
LightDeductionAmountCount int64 `bson:"lightDeductionAmountCount,omitempty" json:"lightDeductionAmountCount"` // light充值次数扣量
LightNaturalAmount int64 `bson:"lightNaturalAmount,omitempty" json:"lightNaturalAmount"` // light充值金额自然
LightNaturalAmountCount int64 `bson:"lightNaturalAmountCount,omitempty" json:"lightNaturalAmountCount"` // light充值次数自然
// 其他充值
NewRechargeAmount int64 `bson:"newRechargeAmount,omitempty" json:"newRechargeAmount"` // 新增充值金额
VipPayMoney int64 `bson:"vipPayMoney,omitempty" json:"vipPayMoney"` // 购买会员金额(CPS扣量后)
VipPayCoin int64 `bson:"vipPayCoin,omitempty" json:"vipPayCoin"` // 金币购买会员数量
VipPayDeduction int64 `bson:"vipPayDeduction,omitempty" json:"vipPayDeduction"` // 购买会员金额(CPS扣量)
GameRechageAmount int64 `bson:"gameRechageAmount,omitempty" json:"gameRechageAmount"` // 游戏充值
GameWithdrawAmount int64 `bson:"gameWithdrawAmount,omitempty" json:"gameWithdrawAmount"` // 游戏提现
// 落地页访问
LandPageVisitCount int64 `bson:"landPageVisitCount,omitempty" json:"landPageVisitCount"` // 落地页访问次数
LandpageAndroidClick int64 `bson:"landpageAndroidClick,omitempty" json:"landpageAndroidClick"` // 落地页android访问次数
LandpageIosAppstoreClick int64 `bson:"landpageIosAppstoreClick,omitempty" json:"landpageIosAppstoreClick"` // 落地页iOS商店包访问次数
LandpageIosAthorClick int64 `bson:"landpageIosAthorClick,omitempty" json:"landpageIosAthorClick"` // 落地页iOS其他包访问次数
LandpageIosH5Click int64 `bson:"landpageIosH5Click,omitempty" json:"landpageIosH5Click"` // 落地页H5访问次数
// 留存率
Day1RetainRate float64 `bson:"day1RetainRate,omitempty" json:"day1RetainRate"` // 次日留存率
Day3RetainRate float64 `bson:"day3RetainRate,omitempty" json:"day3RetainRate"` // 3日留存率
Day7RetainRate float64 `bson:"day7RetainRate,omitempty" json:"day7RetainRate"` // 7日留存率
// 时间
UpdatedAt time.Time `bson:"updatedAt,omitempty" json:"updatedAt"` // 更新时间
CreatedAt time.Time `bson:"createdAt" json:"createdAt"` // 创建时间
}
type ChannelStatList []*ChannelStat
type ChannelStatDoc struct {
// 收益及结算
ValidDirectCount *int64 `bson:"validDirectCount,omitempty" json:"validDirectCount"` // 有效直推总数
ValidDeductionCount *int64 `bson:"validDeductionCount,omitempty" json:"validDeductionCount"` // 有效扣量总数
ValidPayMoney *int64 `bson:"validPayMoney,omitempty" json:"validPayMoney"` // 有效收益会员金额
ValidPayCoin *int64 `bson:"validPayCoin,omitempty" json:"validPayCoin"` // 有效收益金币金额
IncomeAmount *int64 `bson:"IncomeAmount,omitempty" json:"IncomeAmount"` // 收益估算
IncomeRate *float64 `bson:"incomeRate,omitempty" json:"incomeRate"` // 收益比
IsPay *bool `bson:"isPay,omitempty" json:"isPay"` // 是否已结算
// 注册
NewTotalIpCount *int64 `bson:"newTotalIpCount,omitempty" json:"newTotalIpCount"` // 新增IP总量
NewTotalCount *int64 `bson:"newTotalCount,omitempty" json:"newTotalCount"` // **新增总量
NewDirectCount *int64 `bson:"newDirectCount,omitempty" json:"newDirectCount"` // 新增直推
NewFissionCount *int64 `bson:"newFissionCount,omitempty" json:"newFissionCount"` // 新增裂变
NewDeductionCount *int64 `bson:"newDeductionCount,omitempty" json:"newDeductionCount"` // 新增扣量
NewAndroidCount *int64 `bson:"newAndroidCount,omitempty" json:"newAndroidCount"` // android新增
NewAndroidDirectCount *int64 `bson:"newAndroidDirectCount,omitempty" json:"newAndroidDirectCount"` // 新增安卓直推
NewAndroidFissionCount *int64 `bson:"newAndroidFissionCount,omitempty" json:"newAndroidFissionCount"` // 新增安卓裂变
NewAndroidDeductionCount *int64 `bson:"newAndroidDeductionCount,omitempty" json:"newAndroidDeductionCount"` // 新增安卓扣量
NewIosCount *int64 `bson:"newIosCount,omitempty" json:"newIosCount"` // ios新增
NewIosDirectCount *int64 `bson:"newIosDirectCount,omitempty" json:"newIosDirectCount"` // 新增IOS直推
NewIosFissionCount *int64 `bson:"newIosFissionCount,omitempty" json:"newIosFissionCount"` // 新增IOS裂变
NewIosDeductionCount *int64 `bson:"newIosDeductionCount,omitempty" json:"newIosDeductionCount"` // 新增IOS扣量
NewLightCount *int64 `bson:"newLightCount,omitempty" json:"newLightCount"` // light新增
NewLightGuestCount *int64 `bson:"newLightGuestCount,omitempty" json:"newLightGuestCount"` // **轻量安装
NewLightGuestDirectCount *int64 `bson:"newLightGuestDirectCount,omitempty" json:"newLightGuestDirectCount"` // 新增LightGuest直推
NewLightGuestFissionCount *int64 `bson:"newLightGuestFissionCount,omitempty" json:"newLightGuestFissionCount"` // 新增LightGuest裂变
NewLightGuestDeductionCount *int64 `bson:"newLightGuestDeductionCount,omitempty" json:"newLightGuestDeductionCount"` // 新增LightGuest扣量
NewLightFormalCount *int64 `bson:"newLightFormalCount,omitempty" json:"newLightFormalCount"` // **轻量注册
NewLightFormalDirectCount *int64 `bson:"newLightFormalDirectCount,omitempty" json:"newLightFormalDirectCount"` // 新增LightFormal直推
NewLightFormalFissionCount *int64 `bson:"newLightFormalFissionCount,omitempty" json:"newLightFormalFissionCount"` // 新增LightFormal裂变
NewLightFormalDeductionCount *int64 `bson:"newLightFormalDeductionCount,omitempty" json:"newLightFormalDeductionCount"` // 新增LightFormal扣量
NewLightDirectCount *int64 `bson:"newLightDirectCount,omitempty" json:"newLightDirectCount"` // light新增直推
NewLightFissionCount *int64 `bson:"newLightFissionCount,omitempty" json:"newLightFissionCount"` // light新增裂变
NewLightDeductionCount *int64 `bson:"newLightDeductionCount,omitempty" json:"newLightDeductionCount"` // light新增扣量
NewLightNaturalCount *int64 `bson:"newLightNaturalCount,omitempty" json:"newLightNaturalCount"` // light自然新增
NewH5Count *int64 `bson:"newH5Count,omitempty" json:"newH5Count"` // h5新增
NewH5DirectCount *int64 `bson:"newH5DirectCount,omitempty" json:"newH5DirectCount"` // 新增H5直推
NewH5FissionCount *int64 `bson:"newH5FissionCount,omitempty" json:"newH5FissionCount"` // 新增H5裂变
NewH5DeductionCount *int64 `bson:"newH5DeductionCount,omitempty" json:"newH5DeductionCount"` // 新增H5扣量
NewH5AndroidCount *int64 `bson:"newH5AndroidCount,omitempty" json:"newH5AndroidCount"` // h5安卓新增
NewH5IosCount *int64 `bson:"newH5IosCount,omitempty" json:"newH5IosCount"` // h5苹果新增
NewH5PcCount *int64 `bson:"newH5PcCount,omitempty" json:"newH5PcCount"` // h5电脑新增
NewH5FormalCount *int64 `bson:"newH5FormalCount,omitempty" json:"newH5FormalCount"` // h5注册新增
NewH5FormalDirectCount *int64 `bson:"newH5FormalDirectCount,omitempty" json:"newH5FormalDirectCount"` // 新增H5正式直推
NewH5FormalFissionCount *int64 `bson:"newH5FormalFissionCount,omitempty" json:"newH5FormalFissionCount"` // 新增H5正式裂变
NewH5FormalDeductionCount *int64 `bson:"newH5FormalDeductionCount,omitempty" json:"newH5FormalDeductionCount"` // 新增H5正式扣量
// 访问
TotalVisitCount *int64 `bson:"totalVisitCount,omitempty" json:"totalVisitCount"` // **总计访问数
DirectVisitCount *int64 `bson:"directVisitCount,omitempty" json:"directVisitCount"` // 直推访问数
FissionVisitCount *int64 `bson:"fissionVisitCount,omitempty" json:"fissionVisitCount"` // 裂变访问数
AndroidVisitCount *int64 `bson:"androidVisitCount,omitempty" json:"androidVisitCount"` // android访问
IosVisitCount *int64 `bson:"iosVisitCount,omitempty" json:"iosVisitCount"` // ios访问
LightVisitCount *int64 `bson:"lightVisitCount,omitempty" json:"lightVisitCount"` // **轻量访问
LightVisitDirectCount *int64 `bson:"lightVisitDirectCount,omitempty" json:"lightVisitDirectCount"` // light访问量直推
LightVisitFissionCount *int64 `bson:"lightVisitFissionCount,omitempty" json:"lightVisitFissionCount"` // light访问量裂变
LightVisitDeductionCount *int64 `bson:"lightVisitDeductionCount,omitempty" json:"lightVisitDeductionCount"` // light访问量扣量
LightVisitNaturalCount *int64 `bson:"lightVisitNaturalCount,omitempty" json:"lightVisitNaturalCount"` // light访问量自然
H5VisitCount *int64 `bson:"h5VisitCount,omitempty" json:"h5VisitCount"` // h5访问
H5AndroidVisitCount *int64 `bson:"h5AndroidVisitCount,omitempty" json:"h5AndroidVisitCount"` // h5安卓访问
H5IosVisitCount *int64 `bson:"h5IosVisitCount,omitempty" json:"h5IosVisitCount"` // h5苹果访问
H5PcVisitCount *int64 `bson:"h5PcVisitCount,omitempty" json:"h5PcVisitCount"` // h5电脑访问
// 充值统计
TotalAmount *int64 `bson:"totalAmount,omitempty" json:"totalAmount"` // **充值金额总量
DirectAmount *int64 `bson:"directAmount,omitempty" json:"directAmount"` // 直推充值金额
DirectAmountCount *int64 `bson:"directAmountCount,omitempty" json:"directAmountCount"` // 直推充值订单数
FissionAmount *int64 `bson:"fissionAmount,omitempty" json:"fissionAmount"` // 裂变充值金额
FissionAmountCount *int64 `bson:"fissionAmountCount,omitempty" json:"fissionAmountCount"` // 裂变充值订单数
NaturalAmount *int64 `bson:"naturalAmount,omitempty" json:"naturalAmount"` // 自然充值
NaturalAmountCount *int64 `bson:"naturalAmountCount,omitempty" json:"naturalAmountCount"` // 自然充值订单数
DeductionAmount *int64 `bson:"deductionAmount,omitempty" json:"deductionAmount"` // 充值扣量
DeductionAmountCount *int64 `bson:"deductionAmountCount,omitempty" json:"deductionAmountCount"` // 充值扣量次数
AndroidAmount *int64 `bson:"androidAmount,omitempty" json:"androidAmount"` // +安卓充值金额
AndroidAmountCount *int64 `bson:"androidAmountCount,omitempty" json:"androidAmountCount"` // +安卓充值次数
IosAmount *int64 `bson:"iosAmount,omitempty" json:"iosAmount"` // +Ios充值金额
IosAmountCount *int64 `bson:"iosAmountCount,omitempty" json:"iosAmountCount"` // +Ios充值次数
H5Amount *int64 `bson:"h5Amount,omitempty" json:"h5Amount"` // +H5充值金额
H5AmountCount *int64 `bson:"h5AmountCount,omitempty" json:"h5AmountCount"` // +H5充值次数
LightAmount *int64 `bson:"lightAmount,omitempty" json:"lightAmount"` // light充值金额
LightAmountCount *int64 `bson:"lightAmountCount,omitempty" json:"lightAmountCount"` // light充值次数
LightDirectAmount *int64 `bson:"lightDirectAmount,omitempty" json:"lightDirectAmount"` // light充值金额直推
LightDirectAmountCount *int64 `bson:"lightDirectAmountCount,omitempty" json:"lightDirectAmountCount"` // light充值次数直推
LightFissionAmount *int64 `bson:"lightFissionAmount,omitempty" json:"lightFissionAmount"` // light充值金额裂变
LightFissionAmountCount *int64 `bson:"lightFissionAmountCount,omitempty" json:"lightFissionAmountCount"` // light充值次数裂变
LightDeductionAmount *int64 `bson:"lightDeductionAmount,omitempty" json:"lightDeductionAmount"` // light充值金额扣量
LightDeductionAmountCount *int64 `bson:"lightDeductionAmountCount,omitempty" json:"lightDeductionAmountCount"` // light充值次数扣量
LightNaturalAmount *int64 `bson:"lightNaturalAmount,omitempty" json:"lightNaturalAmount"` // light充值金额自然
LightNaturalAmountCount *int64 `bson:"lightNaturalAmountCount,omitempty" json:"lightNaturalAmountCount"` // light充值次数自然
// 其他充值
NewRechargeAmount *int64 `bson:"newRechargeAmount,omitempty" json:"newRechargeAmount"` // 新增充值金额
VipPayMoney *int64 `bson:"vipPayMoney,omitempty" json:"vipPayMoney"` // 购买会员金额(CPS扣量后)
VipPayCoin *int64 `bson:"vipPayCoin,omitempty" json:"vipPayCoin"` // 金币购买会员数量
VipPayDeduction *int64 `bson:"vipPayDeduction,omitempty" json:"vipPayDeduction"` // 购买会员金额(CPS扣量)
GameRechageAmount *int64 `bson:"gameRechageAmount,omitempty" json:"gameRechageAmount"` // 游戏充值
GameWithdrawAmount *int64 `bson:"gameWithdrawAmount,omitempty" json:"gameWithdrawAmount"` // 游戏提现
// 落地页访问
LandPageVisitCount *int64 `bson:"landPageVisitCount,omitempty" json:"landPageVisitCount"` // 落地页访问次数
LandpageAndroidClick *int64 `bson:"landpageAndroidClick,omitempty" json:"landpageAndroidClick"` // 落地页android访问次数
LandpageIosAppstoreClick *int64 `bson:"landpageIosAppstoreClick,omitempty" json:"landpageIosAppstoreClick"` // 落地页iOS商店包访问次数
LandpageIosAthorClick *int64 `bson:"landpageIosAthorClick,omitempty" json:"landpageIosAthorClick"` // 落地页iOS其他包访问次数
LandpageIosH5Click *int64 `bson:"landpageIosH5Click,omitempty" json:"landpageIosH5Click"` // 落地页H5访问次数
// 留存率
Day1RetainRate *float64 `bson:"day1RetainRate,omitempty" json:"day1RetainRate"` // 次日留存率
Day3RetainRate *float64 `bson:"day3RetainRate,omitempty" json:"day3RetainRate"` // 3日留存率
Day7RetainRate *float64 `bson:"day7RetainRate,omitempty" json:"day7RetainRate"` // 7日留存率
// 时间
UpdatedAt *time.Time `bson:"updatedAt,omitempty" json:"updatedAt"` // 更新时间
}
// 渠道结算---每15分钟根据扣量规则结算
// @table:channel_settlement_bak
type ChannelSettlement struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // ID
Channel string `bson:"channel" json:"channel"` // 渠道
SumDate time.Time `bson:"sumDate" json:"sumDate"` // 记录时间 15分钟对齐
AppId int32 `bson:"appId" json:"appId"` // appId
AppType AppType `bson:"appType" json:"appType"` // 应用类型
PromoteMode PromoteMode `bson:"promoteMode" json:"promoteMode"` // 推广类型
Type ChannelType `bson:"type" json:"type"` // 渠道类型:1 一级 2:二级
UserName string `bson:"userName" json:"userName"` // 所有者
ParentChannel string `bson:"parentChannel" json:"parentChannel"` // 父渠道 如果为空字符串,则为渠道,否则为代理
ValidDirectCount int64 `bson:"validDirectCount,omitempty" json:"validDirectCount"` // 有效直推总数
ValidDeductionCount int64 `bson:"validDeductionCount,omitempty" json:"validDeductionCount"` // 有效扣量总数
ValidPayMoney int64 `bson:"validPayMoney,omitempty" json:"validPayMoney"` // 有效收益会员金额
ValidPayCoin int64 `bson:"validPayCoin,omitempty" json:"validPayCoin"` // 有效收益金币金额
// 注册用户
NewTotalIpCount int64 `bson:"newTotalIpCount,omitempty" json:"newTotalIpCount"` // 新增IP总量
NewTotalCount int64 `bson:"newTotalCount,omitempty" json:"newTotalCount"` // 新增总量
NewDirectCount int64 `bson:"newDirectCount,omitempty" json:"newDirectCount"` // 新增直推
NewFissionCount int64 `bson:"newFissionCount,omitempty" json:"newFissionCount"` // 新增裂变
NewDeductionCount int64 `bson:"newDeductionCount,omitempty" json:"newDeductionCount"` // 新增扣量
NewAndroidCount int64 `bson:"newAndroidCount,omitempty" json:"newAndroidCount"` // android新增
NewAndroidDirectCount int64 `bson:"newAndroidDirectCount,omitempty" json:"newAndroidDirectCount"` // 新增安卓直推
NewAndroidFissionCount int64 `bson:"newAndroidFissionCount,omitempty" json:"newAndroidFissionCount"` // 新增安卓裂变
NewAndroidDeductionCount int64 `bson:"newAndroidDeductionCount,omitempty" json:"newAndroidDeductionCount"` // 新增安卓扣量
NewIosCount int64 `bson:"newIosCount,omitempty" json:"newIosCount"` // ios新增
NewIosDirectCount int64 `bson:"newIosDirectCount,omitempty" json:"newIosDirectCount"` // 新增IOS直推
NewIosFissionCount int64 `bson:"newIosFissionCount,omitempty" json:"newIosFissionCount"` // 新增IOS裂变
NewIosDeductionCount int64 `bson:"newIosDeductionCount,omitempty" json:"newIosDeductionCount"` // 新增IOS扣量
NewLightCount int64 `bson:"newLightCount,omitempty" json:"newLightCount"` // light新增
NewLightDirectCount int64 `bson:"newLightDirectCount,omitempty" json:"newLightDirectCount"` // light新增直推
NewLightFissionCount int64 `bson:"newLightFissionCount,omitempty" json:"newLightFissionCount"` // light新增裂变
NewLightDeductionCount int64 `bson:"newLightDeductionCount,omitempty" json:"newLightDeductionCount"` // light新增扣量
NewLightNaturalCount int64 `bson:"newLightNaturalCount,omitempty" json:"newLightNaturalCount"` // light自然新增
NewLightGuestCount int64 `bson:"newLightGuestCount,omitempty" json:"newLightGuestCount"` // **轻量安装
NewLightGuestDirectCount int64 `bson:"newLightGuestDirectCount,omitempty" json:"newLightGuestDirectCount"` // 新增LightGuest直推
NewLightGuestFissionCount int64 `bson:"newLightGuestFissionCount,omitempty" json:"newLightGuestFissionCount"` // 新增LightGuest裂变
NewLightGuestDeductionCount int64 `bson:"newLightGuestDeductionCount,omitempty" json:"newLightGuestDeductionCount"` // 新增LightGuest扣量
NewLightFormalCount int64 `bson:"newLightFormalCount,omitempty" json:"newLightFormalCount"` // **轻量注册
NewLightFormalDirectCount int64 `bson:"newLightFormalDirectCount,omitempty" json:"newLightFormalDirectCount"` // 新增LightFormal直推
NewLightFormalFissionCount int64 `bson:"newLightFormalFissionCount,omitempty" json:"newLightFormalFissionCount"` // 新增LightFormal裂变
NewLightFormalDeductionCount int64 `bson:"newLightFormalDeductionCount,omitempty" json:"newLightFormalDeductionCount"` // 新增LightFormal扣量
NewH5Count int64 `bson:"newH5Count,omitempty" json:"newH5Count"` // h5新增安装
NewH5DirectCount int64 `bson:"newH5DirectCount,omitempty" json:"newH5DirectCount"` // 新增H5直推
NewH5FissionCount int64 `bson:"newH5FissionCount,omitempty" json:"newH5FissionCount"` // 新增H5裂变
NewH5DeductionCount int64 `bson:"newH5DeductionCount,omitempty" json:"newH5DeductionCount"` // 新增H5扣量
NewH5AndroidCount int64 `bson:"newH5AndroidCount,omitempty" json:"newH5AndroidCount"` // h5安卓新增
NewH5IosCount int64 `bson:"newH5IosCount,omitempty" json:"newH5IosCount"` // h5苹果新增
NewH5PcCount int64 `bson:"newH5PcCount,omitempty" json:"newH5PcCount"` // h5电脑新增
NewH5FormalCount int64 `bson:"newH5FormalCount,omitempty" json:"newH5FormalCount"` // h5注册新增
NewH5FormalDirectCount int64 `bson:"newH5FormalDirectCount,omitempty" json:"newH5FormalDirectCount"` // 新增H5正式直推
NewH5FormalFissionCount int64 `bson:"newH5FormalFissionCount,omitempty" json:"newH5FormalFissionCount"` // 新增H5正式裂变
NewH5FormalDeductionCount int64 `bson:"newH5FormalDeductionCount,omitempty" json:"newH5FormalDeductionCount"` // 新增H5正式扣量
// 访问统计
TotalVisitCount int64 `bson:"totalVisitCount,omitempty" json:"totalVisitCount"` // **总计访问数
DirectVisitCount int64 `bson:"directVisitCount,omitempty" json:"directVisitCount"` // 直推访问数
FissionVisitCount int64 `bson:"fissionVisitCount,omitempty" json:"fissionVisitCount"` // 裂变访问数
AndroidVisitCount int64 `bson:"androidVisitCount,omitempty" json:"androidVisitCount"` // android访问
IosVisitCount int64 `bson:"iosVisitCount,omitempty" json:"iosVisitCount"` // ios访问
LightVisitCount int64 `bson:"lightVisitCount,omitempty" json:"lightVisitCount"` // **轻量访问
LightVisitDirectCount int64 `bson:"lightVisitDirectCount" json:"lightVisitDirectCount"` // light访问量直推
LightVisitFissionCount int64 `bson:"lightVisitFissionCount" json:"lightVisitFissionCount"` // light访问量裂变
LightVisitDeductionCount int64 `bson:"lightVisitDeductionCount" json:"lightVisitDeductionCount"` // light访问量扣量
LightVisitNaturalCount int64 `bson:"lightVisitNaturalCount" json:"lightVisitNaturalCount"` // light访问量自然
H5VisitCount int64 `bson:"h5VisitCount,omitempty" json:"h5VisitCount"` // h5访问
H5AndroidVisitCount int64 `bson:"h5AndroidVisitCount,omitempty" json:"h5AndroidVisitCount"` // h5安卓访问
H5IosVisitCount int64 `bson:"h5IosVisitCount,omitempty" json:"h5IosVisitCount"` // h5苹果访问
H5PcVisitCount int64 `bson:"h5PcVisitCount,omitempty" json:"h5PcVisitCount"` // h5电脑访问
// 充值统计
TotalAmount int64 `bson:"totalAmount,omitempty" json:"totalAmount"` // **充值金额总量
DirectAmount int64 `bson:"directAmount,omitempty" json:"directAmount"` // 直推充值金额
DirectAmountCount int64 `bson:"directAmountCount,omitempty" json:"directAmountCount"` // 直推充值订单数
FissionAmount int64 `bson:"fissionAmount,omitempty" json:"fissionAmount"` // 裂变充值金额
FissionAmountCount int64 `bson:"fissionAmountCount,omitempty" json:"fissionAmountCount"` // 裂变充值订单数
NaturalAmount int64 `bson:"naturalAmount,omitempty" json:"naturalAmount"` // 自然充值
NaturalAmountCount int64 `bson:"naturalAmountCount,omitempty" json:"naturalAmountCount"` // 自然充值订单数
DeductionAmount int64 `bson:"deductionAmount,omitempty" json:"deductionAmount"` // 充值扣量
DeductionAmountCount int64 `bson:"deductionAmountCount,omitempty" json:"deductionAmountCount"` // 充值扣量次数
AndroidAmount int64 `bson:"androidAmount,omitempty" json:"androidAmount"` // +安卓充值金额
AndroidAmountCount int64 `bson:"androidAmountCount,omitempty" json:"androidAmountCount"` // +安卓充值次数
IosAmount int64 `bson:"iosAmount,omitempty" json:"iosAmount"` // +Ios充值金额
IosAmountCount int64 `bson:"iosAmountCount,omitempty" json:"iosAmountCount"` // +Ios充值次数
H5Amount int64 `bson:"h5Amount,omitempty" json:"h5Amount"` // +H5充值金额
H5AmountCount int64 `bson:"h5AmountCount,omitempty" json:"h5AmountCount"` // +H5充值次数
LightAmount int64 `bson:"lightAmount,omitempty" json:"lightAmount"` // light充值金额
LightAmountCount int64 `bson:"lightAmountCount,omitempty" json:"lightAmountCount"` // light充值次数
LightDirectAmount int64 `bson:"lightDirectAmount,omitempty" json:"lightDirectAmount"` // light充值金额直推
LightDirectAmountCount int64 `bson:"lightDirectAmountCount,omitempty" json:"lightDirectAmountCount"` // light充值次数直推
LightFissionAmount int64 `bson:"lightFissionAmount,omitempty" json:"lightFissionAmount"` // light充值金额裂变
LightFissionAmountCount int64 `bson:"lightFissionAmountCount,omitempty" json:"lightFissionAmountCount"` // light充值次数裂变
LightDeductionAmount int64 `bson:"lightDeductionAmount,omitempty" json:"lightDeductionAmount"` // light充值金额扣量
LightDeductionAmountCount int64 `bson:"lightDeductionAmountCount,omitempty" json:"lightDeductionAmountCount"` // light充值次数扣量
LightNaturalAmount int64 `bson:"lightNaturalAmount,omitempty" json:"lightNaturalAmount"` // light充值金额自然
LightNaturalAmountCount int64 `bson:"lightNaturalAmountCount,omitempty" json:"lightNaturalAmountCount"` // light充值次数自然
// 其他充值统计
NewRechargeAmount int64 `bson:"newRechargeAmount,omitempty" json:"newRechargeAmount"` // 新增充值金额
VipPayMoney int64 `bson:"vipPayMoney,omitempty" json:"vipPayMoney"` // 购买会员金额(CPS扣量后)
VipPayCoin int64 `bson:"vipPayCoin,omitempty" json:"vipPayCoin"` // 金币购买会员数量
VipPayDeduction int64 `bson:"vipPayDeduction,omitempty" json:"vipPayDeduction"` // 购买会员金额(CPS扣量)
GameRechageAmount int64 `bson:"gameRechageAmount,omitempty" json:"gameRechageAmount"` // 游戏充值
GameWithdrawAmount int64 `bson:"gameWithdrawAmount,omitempty" json:"gameWithdrawAmount"` // 游戏提现
// 落地页访问
LandPageVisitCount int64 `bson:"landPageVisitCount,omitempty" json:"landPageVisitCount"` // 落地页访问次数
LandpageAndroidClick int64 `bson:"landpageAndroidClick,omitempty" json:"landpageAndroidClick"` // 落地页android访问次数
LandpageIosAppstoreClick int64 `bson:"landpageIosAppstoreClick,omitempty" json:"landpageIosAppstoreClick"` // 落地页iOS商店包访问次数
LandpageIosAthorClick int64 `bson:"landpageIosAthorClick,omitempty" json:"landpageIosAthorClick"` // 落地页iOS其他包访问次数
LandpageIosH5Click int64 `bson:"landpageIosH5Click,omitempty" json:"landpageIosH5Click"` // 落地页H5访问次数
// 时间
UpdatedAt time.Time `bson:"updatedAt,omitempty" json:"updatedAt"` // 更新时间
CreatedAt time.Time `bson:"createdAt,omitempty" json:"createdAt"` // 创建时间
}
type ChannelSettlementList []*ChannelSettlement
// 渠道每日统计
// @table:channel_stat_yestoday
type ChannelStatYesterday struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // ID
Channel string `bson:"channel" json:"channel"` // 渠道
SumDate time.Time `bson:"sumDate" json:"sumDate"` // 记录时间 15分钟对齐
AppId int32 `bson:"appId" json:"appId"` // appId
Settlement SettlementWay `bson:"settlement" json:"settlement"` // 结算方式 cps/cpa/cpt/cpc
ParentChannel string `bson:"parentChannel" json:"parentChannel"` // 父渠道 如果为空字符串,则为渠道,否则为代理
// 注册
NewCount int64 `bson:"newCount,omitempty" json:"newCount"` // 新增
NewDirectCount int64 `bson:"newDirectCount,omitempty" json:"newDirectCount"` // 新增直推
NewFissionCount int64 `bson:"newFissionCount,omitempty" json:"newFissionCount"` // 新增裂变
NewAndroidCount int64 `bson:"newAndroidCount,omitempty" json:"newAndroidCount"` // android新增
NewIosCount int64 `bson:"newIosCount,omitempty" json:"newIosCount"` // ios新增
NewH5Count int64 `bson:"newH5Count,omitempty" json:"newH5Count"` // h5新增(guest)
NewH5FormalCount int64 `bson:"newH5FormalCount,omitempty" json:"newH5FormalCount"` // h5注册新增
NewLightGuestCount int64 `bson:"newLightGuestCount,omitempty" json:"newLightGuestCount"` // 轻量安装
NewLightFormalCount int64 `bson:"newLightFormalCount,omitempty" json:"newLightFormalCount"` // 轻量注册
NewIncreaseCount int64 `bson:"newIncreaseCount,omitempty" json:"newIncreaseCount"` // 新增增长
NewIncreaseRate string `bson:"newIncreaseRate,omitempty" json:"newIncreaseRate"` // 新增增长比例 对比昨天同时段
// 充值
RechargeAmount int64 `bson:"rechargeAmount,omitempty" json:"rechargeAmount"` // **充值金额
DirectAmount int64 `bson:"directAmount,omitempty" json:"directAmount"` // 直推充值金额
FissionAmount int64 `bson:"fissionAmount,omitempty" json:"fissionAmount"` // 裂变充值金额
AndroidRechargeAmount int64 `bson:"androidRechargeAmount,omitempty" json:"androidRechargeAmount"` // android充值金额
IosRechargeAmount int64 `bson:"iosRechargeAmount,omitempty" json:"iosRechargeAmount"` // ios充值金额
H5RechargeAmount int64 `bson:"h5RechargeAmount,omitempty" json:"h5RechargeAmount"` // h5充值金额
LightRechargeAmount int64 `bson:"lightRechargeAmount,omitempty" json:"lightRechargeAmount"` // **light充值金额
RechargeIncreaseAmount int64 `bson:"rechargeIncreaseAmount,omitempty" json:"rechargeIncreaseAmount"` // 充值增长
RechargeIncreaseRate string `bson:"rechargeIncreaseRate,omitempty" json:"rechargeIncreaseRate"` // 充值增长比例 对比昨天同时段
// 其他充值
VipPayCoin int64 `bson:"vipPayCoin,omitempty" json:"vipPayCoin"` // 金币购买会员数量
VipPayMoney int64 `bson:"vipPayMoney,omitempty" json:"vipPayMoney"` // 购买会员金额(CPS扣量后)
VipPayDeduction int64 `bson:"vipPayDeduction,omitempty" json:"vipPayDeduction"` // 购买会员金额(CPS扣量)
//
UpdatedAt time.Time `bson:"updatedAt,omitempty" json:"updatedAt"` // 更新时间
CreatedAt time.Time `bson:"createdAt,omitempty" json:"createdAt"` // 创建时间
}
type ChannelStatYestodayList []*ChannelStatYesterday
// 渠道所有者变更记录
// @table:channel_owner_change
type ChannelOwnerChange struct {
ID primitive.ObjectID `json:"id" bson:"_id"` // ID
Channel string `json:"channel" bson:"channel"` // 渠道
OldUser string `json:"oldUser" bson:"oldUser"` // 变更前的所有者
NewUser string `json:"newUser" bson:"newUser"` // 变更后的所有者
Mark string `json:"mark" bson:"mark"` // 备注
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
Operator string `json:"operator" bson:"operator"` // 操作者
Account string `json:"account" bson:"account"` // 操作账号
}
type ChannelOwnerChangeList []*ChannelOwnerChange
+121
View File
@@ -0,0 +1,121 @@
package channelpackage
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"stat/common/stdLog"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.New(mongos.MgoManager, CollChannelPackage)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.ChannelPackage.AppId, Value: 1},
{Key: FN.ChannelPackage.Channel, Value: 1},
{Key: FN.ChannelPackage.Version, Value: 1},
{Key: FN.ChannelPackage.FileName, Value: 1},
},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{
{Key: FN.ChannelPackage.AppId, Value: 1},
{Key: FN.ChannelPackage.Channel, Value: 1},
{Key: FN.ChannelPackage.Version, Value: 1},
{Key: FN.ChannelPackage.FileName, Value: 1},
{Key: FN.ChannelPackage.Status, Value: 1},
},
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollChannelPackage, err))
}
}
// InsertOneChannelPackage 插入一个应用
func InsertOneChannelPackage(ctx context.Context, ChannelPackage *ChannelPackage) *stdLog.SrvErr {
if _, err := db.InsertOne(ctx, ChannelPackage); err != nil {
log.Warn("media:InsertOneChannelPackage db.InsertOne failed", log.E(err))
return stdLog.New(stdLog.InsertDataError, "", "")
}
return nil
}
// DelOneChannelPackage 删除一个应用tag
func DelOneChannelPackage(ctx context.Context, filter bson.M) (
int64, *stdLog.SrvErr) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("application:DelOneChannelPackage db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, stdLog.New(stdLog.DelDataError, "", "")
}
return count, nil
}
// UpdateOneChannelPackage 更新一个应用
func UpdateOneChannelPackage(ctx context.Context, filter bson.M, update bson.M) *stdLog.SrvErr {
result, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("application:UpdateOneChannelPackage db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return stdLog.New(stdLog.UpdateDataError, "", "")
}
if result.MatchedCount != 1 {
log.Warn("application:UpdateOneChannelPackage db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return stdLog.New(stdLog.DataNotExist, "", "")
}
return nil
}
// CountChannelPackages 统计应用数量
func CountChannelPackages(ctx context.Context, filter bson.M) (
int64, *stdLog.SrvErr) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("media:CountChannelPackages db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, stdLog.New(stdLog.QueryDataError, "", "")
}
return count, nil
}
// FindOneChannelPackage 查找一个应用
func FindOneChannelPackage(ctx context.Context, filter bson.M) (
*ChannelPackage, *stdLog.SrvErr) {
var ChannelPackage ChannelPackage
if err := db.FindOneEx(
ctx, &ChannelPackage, filter); err != nil {
if err != mongo.ErrNoDocuments {
log.Info("media:FindOneChannelPackage db.FindOne failed",
log.E(err), log.Any("filter", filter))
return nil, stdLog.New(stdLog.QueryDataError, "", "")
}
return nil, stdLog.New(stdLog.DataNotExist, "", "")
}
return &ChannelPackage, nil
}
// FindManyChannelPackage 查找一批应用
func FindManyChannelPackage(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (ChannelPackageList, *stdLog.SrvErr) {
data := make(ChannelPackageList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("application:FindManyChannelPackage db.Find failed",
log.E(err), log.Any("filter", filter))
return nil, stdLog.New(stdLog.QueryDataError, "", "")
}
return data, nil
}
+83
View File
@@ -0,0 +1,83 @@
package channelpackage
import (
"context"
"fmt"
"go.mongodb.org/mongo-driver/bson"
"math"
"math/rand"
"net/url"
"stat/common/stdLog"
"time"
)
func (c *ChannelPackage) IncDownCount(ctx context.Context) *stdLog.SrvErr {
update := bson.M{
"$inc": bson.M{
FN.ChannelPackage.DownCount: 1,
},
"$set": bson.M{
FN.ChannelPackage.DownLatest: time.Now(),
},
}
return UpdateOneChannelPackage(ctx, bson.M{FN.ChannelPackage.Id: c.Id}, update)
}
func (c *ChannelPackage) GetRandomLink(domains []string) string {
if len(domains) > 0 {
base := domains[rand.Intn(len(domains))]
link, _ := url.JoinPath(base, c.UrlPath)
return link
}
return ""
}
func (c *ChannelPackage) GetAllLink(domains []string) []string {
if len(domains) > 0 {
list := make([]string, 0)
for _, domain := range domains {
link, _ := url.JoinPath(domain, c.UrlPath)
list = append(list, link)
}
return list
}
return []string{}
}
func (c *ChannelPackage) CanMake(force bool) (bool, time.Duration, string) {
// 先判断锁定时间(强制生成不可破锁)
duration := ApkLockTimeDuration - time.Since(c.LockTime)
if duration > 0 {
return false, duration, fmt.Sprintf("记录锁定")
}
if force {
return true, 0, "强制生成"
}
if c.Status == ChanApkStatusSuccess {
// 已成功的记录
return false, duration, "已经生成成功过,无需重新生成"
} else if c.Status == ChanApkStatusMaking {
// 判断超时的记录
current := time.Now().Sub(c.GenTime)
diff := ApkNoResponseDuration - current
if diff <= 0 {
duration := time.Duration(math.Pow(3, float64(c.GenCount))) * time.Minute
if current > duration {
return true, -1, "可以生成"
} else {
return false, duration - current, "未达到可以再次生成的时间"
}
} else {
return false, diff, "正在生成中"
}
} else {
// 判断失败的记录
duration := time.Duration(math.Pow(3, float64(c.GenCount))) * time.Minute
current := time.Now().Sub(c.GenTime)
if current > duration {
return true, -1, "上次生成失败已超时,现在可以重新生成"
} else {
return false, duration - current, "上次生成失败,重新生成的时间未到"
}
}
}
+54
View File
@@ -0,0 +1,54 @@
package channelpackage
type TagChannelPackage struct {
AppId string
Channel string
CreatedAt string
Desc string
Reason string
FileName string
GenCount string
GenError string
GenTime string
Id string
Status string
UpdatedAt string
UrlPath string
Version string
LockCode string
LockTime string
DownCount string
DownLatest string
CheckLink string
}
var FN struct {
ChannelPackage TagChannelPackage
}
var TN struct {
ChannelPackage string
}
func init() {
FN.ChannelPackage.AppId = "appId"
FN.ChannelPackage.Channel = "channel"
FN.ChannelPackage.CreatedAt = "createdAt"
FN.ChannelPackage.Desc = "desc"
FN.ChannelPackage.Reason = "reason"
FN.ChannelPackage.FileName = "fileName"
FN.ChannelPackage.GenCount = "genCount"
FN.ChannelPackage.GenError = "genError"
FN.ChannelPackage.GenTime = "genTime"
FN.ChannelPackage.Id = "_id"
FN.ChannelPackage.Status = "status"
FN.ChannelPackage.UpdatedAt = "updatedAt"
FN.ChannelPackage.UrlPath = "urlPath"
FN.ChannelPackage.Version = "version"
FN.ChannelPackage.LockCode = "lockCode"
FN.ChannelPackage.LockTime = "lockTime"
FN.ChannelPackage.CheckLink = "checkLink"
FN.ChannelPackage.DownCount = "downCount"
FN.ChannelPackage.DownLatest = "downLatest"
TN.ChannelPackage = "channel_package"
}
+68
View File
@@ -0,0 +1,68 @@
package channelpackage
import (
"stat/common/mongos"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
const CollChannelPackage = "channel_package"
var db *mongos.MongoTool
type ChanApkStatus int64
const (
ChanApkStatusUnknown ChanApkStatus = iota
ChanApkStatusMaking // 正在生成
ChanApkStatusSuccess // 生成成功
ChanApkStatusFailure // 生成失败
)
const (
ApkLockTimeDuration = 30 * time.Minute // 记录锁定时间
ApkNoResponseDuration = 60 * time.Minute // 生成时无响应间隔
ApkCheckLinkDuration = 10 * time.Minute // 生成时无响应间隔
ApkGenerateParallelMax = int64(5) // 并行生成APK的最大任务数
)
// 渠道包
// @table:channel_package
type ChannelPackage struct {
Id primitive.ObjectID `json:"id" bson:"_id,omitempty"`
AppId int32 `json:"appId" bson:"appId"` // appId
Channel string `json:"channel" bson:"channel"` // 渠道
Version string `bson:"version" json:"version"` // 版本号
FileName string `json:"fileName" bson:"fileName"` // 包文件名
UrlPath string `json:"urlPath" bson:"urlPath"` // UrlPath
Status ChanApkStatus `json:"status" bson:"status"` // 状态
Desc string `bson:"desc" json:"desc"` // 版本描述
GenError string `bson:"genError" json:"genError"` // 生成错误
GenCount int64 `bson:"genCount" json:"genCount"` // 生成次数
GenTime time.Time `bson:"genTime" json:"genTime"` // 生成时间
Reason string `bson:"reason" json:"reason"` // 生成原因
LockCode int64 `bson:"lockCode" json:"lockCode"` // 更新锁码
LockTime time.Time `bson:"lockTime" json:"lockTime"` // 锁定时间
DownCount int64 `bson:"downCount" json:"downCount"` // 下载次数
DownLatest time.Time `bson:"downLatest" json:"downLatest"` // 最后下载时间
CheckLink time.Time `bson:"checkLink" json:"checkLink"` // 检查链接
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
}
type ChannelPackageList []*ChannelPackage
type ChannelPackageUpdate struct {
AppId *int32 `json:"appId" bson:"appId"` // appId
Channel *string `json:"channel" bson:"channel"` // 渠道
Version *string `bson:"version" json:"version"` // 版本号
FileName *string `json:"fileName" bson:"fileName"` // 包文件名
UrlPath *string `json:"urlPath" bson:"urlPath"` // UrlPath
Status *int64 `json:"status" bson:"status"` // 状态
Desc *string `bson:"desc" json:"desc"` // 版本描述
GenError *string `bson:"genError" json:"genError"` // 生成错误
GenCount *int64 `bson:"genCount" json:"genCount"` // 生成次数
GenTime *time.Time `bson:"genTime" json:"genTime"` // 生成时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
}
+215
View File
@@ -0,0 +1,215 @@
package channelsettlementrecord
import (
"context"
"fmt"
"go.mongodb.org/mongo-driver/mongo"
"stat/common/log"
"stat/common/mongos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
)
var (
dbRecord *mongos.MongoTool
dbDeleted *mongos.MongoTool
)
func Init(ctx context.Context) {
initDbRecord(ctx)
initDbDeleted(ctx)
}
func initDbRecord(ctx context.Context) {
// 获取数据库表
dbRecord = mongos.New(mongos.MgoManager, TN.ChannelSettlementRecord)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.ChannelSettlementRecord.Channel, Value: 1},
{Key: FN.ChannelSettlementRecord.AppId, Value: 1},
},
},
{
Keys: bson.D{{Key: FN.ChannelSettlementRecord.SettleIds, Value: 1}},
},
{
Keys: bson.D{{Key: FN.ChannelSettlementRecord.Applicant, Value: 1}},
},
}
if _, err := dbRecord.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(ChannelSettlementRecord:initChannelSettlementRecordIndex) Create ChannelSettlementRecord Index failed! err:%+v:", err))
}
}
func initDbDeleted(ctx context.Context) {
// 获取数据库表
dbDeleted = mongos.New(mongos.MgoManager, TN.ChannelSettlementDeleted)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.ChannelSettlementDeleted.Channel, Value: 1},
{Key: FN.ChannelSettlementDeleted.AppId, Value: 1},
},
},
{
Keys: bson.D{{Key: FN.ChannelSettlementDeleted.SettleIds, Value: 1}},
},
}
if _, err := dbDeleted.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(ChannelSettlementDeleted:initChannelSettlementDeletedIndex) Create ChannelSettlementDeleted Index failed! err:%+v:", err))
}
}
//InsertOneChannelSettlementRecord 插入一个结算记录
func InsertOneChannelSettlementRecord(ctx context.Context, ChannelSettlementRecord *ChannelSettlementRecord) error {
if _, err := dbRecord.InsertOne(ctx, ChannelSettlementRecord); err != nil {
log.Warn("ChannelSettlementRecord:InsertOneChannelSettlementRecord dbRecord.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneChannelSettlementRecord 查找一个结算记录
func FindOneChannelSettlementRecord(ctx context.Context, filter bson.M) (
*ChannelSettlementRecord, error) {
var ChannelSettlementRecord ChannelSettlementRecord
if err := dbRecord.FindOne(ctx, &ChannelSettlementRecord, filter); err != nil {
return nil, err
}
return &ChannelSettlementRecord, nil
}
//FindOneChannelSettlementRecordEx 查找一个结算记录
func FindOneChannelSettlementRecordEx(ctx context.Context, filter bson.M) (
*ChannelSettlementRecord, error) {
var ChannelSettlementRecord ChannelSettlementRecord
if err := dbRecord.FindOneEx(ctx, &ChannelSettlementRecord, filter); err != nil {
return nil, err
}
return &ChannelSettlementRecord, nil
}
//DelOneChannelSettlementRecord 删除一个结算记录
func DelOneChannelSettlementRecord(ctx context.Context, filter bson.M) (
int64, error) {
count, err := dbRecord.DeleteOne(ctx, filter)
if err != nil {
log.Warn("ChannelSettlementRecord:DelOneChannelSettlementRecord dbRecord.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateOneChannelSettlementRecord 更新一个结算记录
func UpdateOneChannelSettlementRecord(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbRecord.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateOneChannelSettlementRecord dbRecord.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//CountChannelSettlementRecords 统计结算记录数量
func CountChannelSettlementRecords(ctx context.Context, filter bson.M) (
int64, error) {
count, err := dbRecord.Count(ctx, filter)
if err != nil {
log.Warn("ChannelSettlementRecord:CountChannelSettlementRecords dbRecord.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateManyChannelSettlementRecord 更新满足条件的结算记录
func UpdateManyChannelSettlementRecord(ctx context.Context, filter bson.M, update bson.M) error {
_, err := dbRecord.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyChannelSettlementRecord dbRecord.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//FindManyChannelSettlementRecord 查找一批结算记录数据
func FindManyChannelSettlementRecord(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (ChannelSettlementRecordList, error) {
data := make(ChannelSettlementRecordList, 0)
if err := dbRecord.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("ChannelSettlementRecord:FindManyChannelSettlementRecord dbRecord.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
//FindManyChannelSettlementRecordWithBind 用自己定义结构查找一批结算记录数据
func FindManyChannelSettlementRecordWithBind(ctx context.Context, bind interface{}, filter bson.M,
opts ...*options.FindOptions) error {
if err := dbRecord.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("ChannelSettlementRecord:FindManyChannelSettlementRecordWithBind dbRecord.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//AggregateChannelSettlementRecords 聚合查找一批结算记录信息
func AggregateChannelSettlementRecords(ctx context.Context,
bind interface{}, pipeline []bson.M) error {
if err := dbRecord.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("feedback:AggregateChannelSettlementRecords dbRecord.Aggregate failed",
log.E(err), log.Any("pipeline", pipeline))
return err
}
return nil
}
// ----------------------------------------
//CountChannelSettlementRecords 统计结算记录数量
func CountChannelSettlementDeletes(ctx context.Context, filter bson.M) (
int64, error) {
count, err := dbDeleted.Count(ctx, filter)
if err != nil {
log.Warn("ChannelSettlementRecord:CountChannelSettlementDeletes dbDeleted.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//InsertOneChannelSettlementDeleted 插入一个结算删除记录
func InsertOneChannelSettlementDeleted(ctx context.Context, ChannelSettlementRecord *ChannelSettlementRecord) error {
if _, err := dbDeleted.InsertOne(ctx, ChannelSettlementRecord); err != nil {
log.Warn("ChannelSettlementRecord:InsertOneChannelSettlementDeleted dbDeleted.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneChannelSettlementDeletedEx 查找一个结算删除记录
func FindOneChannelSettlementDeletedEx(ctx context.Context, filter bson.M) (
*ChannelSettlementRecord, error) {
var ChannelSettlementRecord ChannelSettlementRecord
if err := dbDeleted.FindOneEx(ctx, &ChannelSettlementRecord, filter); err != nil {
return nil, err
}
return &ChannelSettlementRecord, nil
}
//FindManyChannelSettlementDeleted 查找一批结算记录数据
func FindManyChannelSettlementDeleted(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (ChannelSettlementRecordList, error) {
data := make(ChannelSettlementRecordList, 0)
if err := dbDeleted.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("ChannelSettlementRecord:FindManyChannelSettlementDeleted dbDeleted.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
+81
View File
@@ -0,0 +1,81 @@
package channelsettlementrecord
type TagChannelSettlementRecord struct {
AppId string
BeginTime string
CPAPrice string
CPSRate string
Channel string
CreatedAt string
UpdatedAt string
EndTime string
ID string
NewDeductionCount string
NewFissionCount string
NewDirectCount string
PayMoney string
RechargeAmount string
Remark string
Settlement string
Status string
TotalMoney string
SettleMoney string
Usdt string
VipPayMoney string
VipPayCoin string
VipPayDeduction string
SettleIds string
OperateHistory string
Applicant string
Wallet struct {
Addr1 string
Addr2 string
}
IncludeChild string
}
var FN struct {
ChannelSettlementRecord TagChannelSettlementRecord
ChannelSettlementDeleted TagChannelSettlementRecord
}
var TN struct {
ChannelSettlementRecord string
ChannelSettlementDeleted string
}
func init() {
FN.ChannelSettlementRecord.AppId = "appId"
FN.ChannelSettlementRecord.BeginTime = "beginTime"
FN.ChannelSettlementRecord.CPAPrice = "cpaPrice"
FN.ChannelSettlementRecord.CPSRate = "cpsRate"
FN.ChannelSettlementRecord.Channel = "channel"
FN.ChannelSettlementRecord.CreatedAt = "createdAt"
FN.ChannelSettlementRecord.UpdatedAt = "updatedAt"
FN.ChannelSettlementRecord.EndTime = "endTime"
FN.ChannelSettlementRecord.ID = "_id"
FN.ChannelSettlementRecord.NewDeductionCount = "newDeductionCount"
FN.ChannelSettlementRecord.NewFissionCount = "newFissionCount"
FN.ChannelSettlementRecord.NewDirectCount = "newDirectCount"
FN.ChannelSettlementRecord.PayMoney = "payMoney"
FN.ChannelSettlementRecord.RechargeAmount = "rechargeAmount"
FN.ChannelSettlementRecord.Remark = "remark"
FN.ChannelSettlementRecord.Settlement = "settlement"
FN.ChannelSettlementRecord.Status = "status"
FN.ChannelSettlementRecord.TotalMoney = "totalMoney"
FN.ChannelSettlementRecord.SettleMoney = "settleMoney"
FN.ChannelSettlementRecord.Usdt = "usdt"
FN.ChannelSettlementRecord.VipPayMoney = "vipPayMoney"
FN.ChannelSettlementRecord.VipPayCoin = "vipPayCoin"
FN.ChannelSettlementRecord.VipPayDeduction = "vipPayDeduction"
FN.ChannelSettlementRecord.SettleIds = "settleIds"
FN.ChannelSettlementRecord.OperateHistory = "operateHistory"
FN.ChannelSettlementRecord.Applicant = "applicant"
FN.ChannelSettlementRecord.Wallet.Addr1 = "wallet.addr1"
FN.ChannelSettlementRecord.Wallet.Addr2 = "wallet.addr2"
FN.ChannelSettlementRecord.IncludeChild = "includeChild"
FN.ChannelSettlementDeleted = FN.ChannelSettlementRecord
TN.ChannelSettlementRecord = "channel_settlement_record"
TN.ChannelSettlementDeleted = "channel_settlement_deleted"
}
+90
View File
@@ -0,0 +1,90 @@
package channelsettlementrecord
import (
"stat/middleware/define"
"stat/models/channelmod"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// 结算方式
type SettlementStatus int64
const (
SettlementInit SettlementStatus = 0 // 发起
SettlementSuccess SettlementStatus = 1 // 成功
SettlementFailed SettlementStatus = 2 // 失败
SettlementDeleted SettlementStatus = 3 // 已删除
)
func (status SettlementStatus) String() string {
return GetSettStatus(status)
}
func GetSettStatus(status SettlementStatus) string {
switch status {
case SettlementInit:
return "发起"
case SettlementSuccess:
return "成功"
case SettlementFailed:
return "失败"
case SettlementDeleted:
return "已删除"
default:
return "未知状态"
}
}
type SettlementOperateItem struct {
OperateTime time.Time `bson:"operateTime" json:"operateTime"` // 操作时间
BeforeStatus SettlementStatus `bson:"beforeStatus" json:"beforeStatus"` // 操作前状态
AfterStatus SettlementStatus `bson:"afterStatus" json:"afterStatus"` // 操作后状态
OperatorAccount string `bson:"operatorAccount" json:"operatorAccount"` // 操作者账号
OperatorAccountType define.ActType `bson:"operatorAccountType" json:"operatorAccountType"` // 操作者账号类型
OperatorAccountName string `bson:"operatorAccountName" json:"operatorAccountName"` // 操作者账号名字
Content string `bson:"content" json:"content"` // 操作的内容
Pictures []string `bson:"pictures" json:"pictures"` // 上传的图片
Remark string `bson:"remark" json:"remark"` // 操作备注
}
// 帖子模型,数据库中的
// @table:channel_settlement_record
type ChannelSettlementRecord struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // ID
Channel string `bson:"channel" json:"channel"` // 渠道
AppId int32 `bson:"appId" json:"appId"` // appId
AppType channelmod.AppType `bson:"appType" json:"appType"` // 应用类型
PromoteMode channelmod.PromoteMode `bson:"promoteMode" json:"promoteMode"` // 推广类型
BeginTime time.Time `bson:"beginTime" json:"beginTime"` // 开始时间
EndTime time.Time `bson:"endTime" json:"endTime"` // 结束时间
TotalMoney int64 `bson:"totalMoney" json:"totalMoney"` // 计算出的总金额
SettleMoney int64 `bson:"settleMoney" json:"settleMoney"` // 手动输入的要结算的真实金额()
Settlement channelmod.SettlementWay `bson:"settlement" json:"settlement"` // 结算方式 cps/cpa/cpt/cpc
CPAPrice int64 `bson:"cpaPrice" json:"cpaPrice"` // 单价
CPSRate int64 `bson:"cpsRate" json:"cpsRate"` // CPS 分成比列 0-100
NewDirectCount int64 `bson:"newDirectCount" json:"newDirectCount"` // 新增直推
NewFissionCount int64 `bson:"newFissionCount" json:"newFissionCount"` // 新增裂变
NewDeductionCount int64 `bson:"newDeductionCount" json:"newDeductionCount"` // 新增扣量
RechargeAmount int64 `bson:"rechargeAmount" json:"rechargeAmount"` // 充值金额
VipPayMoney int64 `bson:"vipPayMoney" json:"vipPayMoney"` // 购买会员金额(CPS扣量后)
VipPayCoin int64 `bson:"vipPayCoin,omitempty" json:"vipPayCoin"` // 购买会员金币
VipPayDeduction int64 `bson:"vipPayDeduction,omitempty" json:"vipPayDeduction"` // 购买会员金额(CPS扣量)
ValidDirectCount int64 `bson:"validDirectCount,omitempty" json:"validDirectCount"` // 有效直推总数
ValidDeductionCount int64 `bson:"validDeductionCount,omitempty" json:"validDeductionCount"` // 有效扣量总数
ValidPayMoney int64 `bson:"validPayMoney,omitempty" json:"validPayMoney"` // 有效收益会员金额
ValidPayCoin int64 `bson:"validPayCoin,omitempty" json:"validPayCoin"` // 有效收益金币金额
Wallet channelmod.Wallet `bson:"wallet" json:"wallet"` // 钱包地址
PayMoney int64 `bson:"payMoney" json:"payMoney"` // 打款金额
Usdt int64 `bson:"usdt" json:"usdt"` // 打款Usdt 还是分
Status SettlementStatus `bson:"status" json:"status"` // 状态
OperateHistory []SettlementOperateItem `bson:"operateHistory" json:"operateHistory"` // 操作历史[最后一项是当前操作记录]
Remark string `bson:"remark" json:"remark"` // 备注
UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt"` // 更新时间
CreatedAt time.Time `bson:"createdAt" json:"createdAt"` // 创建时间
SettleIds []primitive.ObjectID `bson:"settleIds" json:"settleIds"` // 本次结算的天统计记录id列表
Applicant string `bson:"applicant" json:"applicant"` // 结算申请人
IncludeChild bool `bson:"includeChild" json:"includeChild"` // 结算是否包含子渠道
}
type ChannelSettlementRecordList []*ChannelSettlementRecord
+24
View File
@@ -0,0 +1,24 @@
package dailyhourstatmod
import "time"
var (
fixTime time.Time
)
func init() {
time.Local, _ = time.LoadLocation("Asia/Shanghai")
fixTime, _ = time.ParseInLocation("2006-01-02", "2023-07-14", time.Local)
}
func (s *DailyHourStat) CorrectValidData() *DailyHourStat {
if s.SumDate.Before(fixTime) {
s.TotalAmount = s.DirectAmount + s.FissionAmount + s.DeductionAmount
s.NewTotalCount = s.NewDirectCount + s.NewFissionCount + s.NewDeductionCount
s.TotalVisitCount = s.DirectVisitCount + s.FissionVisitCount + s.DeductionVisitCount
s.NewLightCount = s.NewLightDirectCount + s.NewLightFissionCount + s.NewLightDeductionCount
s.LightAmount = s.LightDirectAmount + s.LightFissionAmount + s.LightDeductionAmount
s.LightAmountCount = s.LightDirectAmountCount + s.LightFissionAmountCount + s.LightDeductionAmountCount
}
return s
}
+155
View File
@@ -0,0 +1,155 @@
package dailyhourstatmod
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"
)
var db *mongos.MongoTool
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.New(mongos.MgoManager, TN.DailyHourStat)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.DailyHourStat.SumDate, Value: 1},
{Key: FN.DailyHourStat.AppId, Value: 1},
},
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(DailyHourStat:initDailyHourStatIndex) Create DailyHourStat Index failed! err:%+v:", err))
}
}
//InsertOneDailyHourStat 插入一个VIP购买记录
func InsertOneDailyHourStat(ctx context.Context, DailyHourStat *DailyHourStat) error {
if _, err := db.InsertOne(ctx, DailyHourStat); err != nil {
log.Warn("DailyHourStat:InsertOneDailyHourStat db.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneDailyHourStat 查找一个VIP购买记录
func FindOneDailyHourStat(ctx context.Context, filter bson.M) (
*DailyHourStat, error) {
var DailyHourStat DailyHourStat
if err := db.FindOne(ctx, &DailyHourStat, filter); err != nil {
return nil, err
}
return &DailyHourStat, nil
}
//DelOneDailyHourStat 删除一个VIP购买记录
func DelOneDailyHourStat(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("DailyHourStat:DelOneDailyHourStat db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateOneDailyHourStat 更新一个VIP购买记录
func UpdateOneDailyHourStat(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateOneDailyHourStat db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//CountDailyHourStats 统计VIP购买记录数量
func CountDailyHourStats(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("DailyHourStat:CountDailyHourStats db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateManyDailyHourStat 更新满足条件的VIP购买记录
func UpdateManyDailyHourStat(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyDailyHourStat db.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//FindManyDailyHourStat 查找一批每小时统计
func FindManyDailyHourStat(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (DailyHourStatList, error) {
data := make(DailyHourStatList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("DailyHourStat:FindManyDailyHourStat db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
//FindManyDailyHourStatWithBind 用自己定义结构查找一批每小时统计
func FindManyDailyHourStatWithBind(ctx context.Context, bind interface{}, filter bson.M,
opts ...*options.FindOptions) error {
if err := db.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("DailyHourStat:FindManyDailyHourStatWithBind db.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//AggregateDailyHourStats 聚合查找一批VIP购买记录信息
func AggregateDailyHourStats(ctx context.Context,
bind interface{}, pipeline []bson.M) error {
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("feedback:AggregateDailyHourStats db.Aggregate failed",
log.E(err), log.Any("pipeline", pipeline))
return err
}
return nil
}
// UpsertDailyStat 更新或插入一条统计记录
func UpsertDailyHourStat(ctx context.Context, sumDate time.Time, appId int32, doc DailyHourStatDoc) (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
}
+74
View File
@@ -0,0 +1,74 @@
package dailyhourstatmod
type TagDailyHourStat struct {
AppId string
DirectAmount string
DirectVisitCount string
FissionAmount string
FissionVisitCount string
GameRechageAmount string
GameWithdrawAmount string
ID string
LandpageAndroidClick string
LandpageIosAppstoreClick string
LandpageIosAthorClick string
NaturalAmount string
NewAndroidCount string
NewDeductionCount string
NewDirectCount string
NewFissionCount string
NewH5Count string
NewIosCount string
NewNaturalCount string
NewRechargeAmount string
RepeatAmount string
SuccessRechargeOrder string
SumDate string
SumHour string
TotalRechargeOrder string
UpdatedAt string
VipPayByAmount string
VipPayByMoney string
VipRepeatAmount string
}
var FN struct {
DailyHourStat TagDailyHourStat
}
var TN struct {
DailyHourStat string
}
func init() {
FN.DailyHourStat.AppId = "appId"
FN.DailyHourStat.DirectAmount = "directAmount"
FN.DailyHourStat.DirectVisitCount = "directVisitCount"
FN.DailyHourStat.FissionAmount = "fissionAmount"
FN.DailyHourStat.FissionVisitCount = "fissionVisitCount"
FN.DailyHourStat.GameRechageAmount = "gameRechageAmount"
FN.DailyHourStat.GameWithdrawAmount = "gameWithdrawAmount"
FN.DailyHourStat.ID = "_id"
FN.DailyHourStat.LandpageAndroidClick = "landpageAndroidClick"
FN.DailyHourStat.LandpageIosAppstoreClick = "landpageIosAppstoreClick"
FN.DailyHourStat.LandpageIosAthorClick = "landpageIosAthorClick"
FN.DailyHourStat.NaturalAmount = "naturalAmount"
FN.DailyHourStat.NewAndroidCount = "newAndroidCount"
FN.DailyHourStat.NewDeductionCount = "newDeductionCount"
FN.DailyHourStat.NewDirectCount = "newDirectCount"
FN.DailyHourStat.NewFissionCount = "newFissionCount"
FN.DailyHourStat.NewH5Count = "newH5Count"
FN.DailyHourStat.NewIosCount = "newIosCount"
FN.DailyHourStat.NewNaturalCount = "newNaturalCount"
FN.DailyHourStat.NewRechargeAmount = "newRechargeAmount"
FN.DailyHourStat.RepeatAmount = "repeatAmount"
FN.DailyHourStat.SuccessRechargeOrder = "successRechargeOrder"
FN.DailyHourStat.SumDate = "sumDate"
FN.DailyHourStat.SumHour = "sumHour"
FN.DailyHourStat.TotalRechargeOrder = "totalRechargeOrder"
FN.DailyHourStat.UpdatedAt = "updatedAt"
FN.DailyHourStat.VipPayByAmount = "vipPayByAmount"
FN.DailyHourStat.VipPayByMoney = "vipPayByMoney"
FN.DailyHourStat.VipRepeatAmount = "vipRepeatAmount"
TN.DailyHourStat = "daily_hour_stat"
}
+285
View File
@@ -0,0 +1,285 @@
package dailyhourstatmod
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// 帖子模型,数据库中的
// @table:daily_hour_stat
type DailyHourStat struct {
ID primitive.ObjectID `bson:"_id,omitempty"` // ID
SumDate time.Time `bson:"sumDate"` // 记录时间 按天对齐
AppId int32 `bson:"appId"` // appId
SumHour int `bson:"sumHour,omitempty"` // 小时数
// 注册用户
NewTotalCount int64 `bson:"newTotalCount,omitempty"` // **新增总量
// ------分类1
NewDirectCount int64 `bson:"newDirectCount,omitempty"` // 新增直推
NewFissionCount int64 `bson:"newFissionCount,omitempty"` // 新增裂变
NewDeductionCount int64 `bson:"newDeductionCount,omitempty"` // 新增扣量
NewNaturalCount int64 `bson:"newNaturalCount,omitempty"` // 自然新增
DeductionVisitCount int64 `bson:"deductionVisitCount,omitempty"` // 新增扣量
// ------分类2
NewAndroidCount int64 `bson:"newAndroidCount,omitempty"` // android新增
NewIosCount int64 `bson:"newIosCount,omitempty"` // ios新增
// ------分类3
NewLightCount int64 `bson:"newLightCount,omitempty"` // light新增
NewLightGuestCount int64 `bson:"newLightGuestCount,omitempty"` // light新增安装
NewLightFormalCount int64 `bson:"newLightFormalCount,omitempty"` // light新增注册
NewLightDirectCount int64 `bson:"newLightDirectCount,omitempty"` // light新增直推
NewLightFissionCount int64 `bson:"newLightFissionCount,omitempty"` // light新增裂变
NewLightDeductionCount int64 `bson:"newLightDeductionCount,omitempty"` // light新增扣量
NewLightNaturalCount int64 `bson:"newLightNaturalCount,omitempty"` // light自然新增
NewLightWebCount int64 `bson:"newLightWebCount,omitempty"` // light官网新增
NewLightNormalCount int64 `bson:"newLightNormalCount,omitempty"` // light自来新增
NewLightDistrictCount int64 `bson:"newLightDistrictCount,omitempty"` // light渠道新增
// ------分类4
NewH5Count int64 `bson:"newH5Count,omitempty"` // H5新增
NewH5FormalCount int64 `bson:"newH5FormalCount,omitempty"` // H5注册新增
NewH5PcCount int64 `bson:"newH5PcCount,omitempty"` // +H5PC新增
NewH5IosCount int64 `bson:"NewH5IosCount,omitempty"` // +H5IOS新增
NewH5AndroidCount int64 `bson:"newH5AndroidCount,omitempty"` // +H5Android新增
// ------分类4
NewWebCount int64 `bson:"newWebCount,omitempty"` // **官网新增
NewNormalCount int64 `bson:"newNormalCount,omitempty"` // **自来新增
NewDistrictCount int64 `bson:"newDistrictCount,omitempty"` // **渠道新增
// 访问统计
TotalVisitCount int64 `bson:"totalVisitCount,omitempty"` // **访问总量
// ------分类1
DirectVisitCount int64 `bson:"directVisitCount,omitempty"` // 直推访问数
FissionVisitCount int64 `bson:"fissionVisitCount,omitempty"` // 裂变访问数
NaturalVisitCount int64 `bson:"naturalVisitCount,omitempty"` // **自然访问数
// ------分类2
IosVisitCount int64 `bson:"iosVisitCount,omitempty"` // +Ios访问量
AndroidVisitCount int64 `bson:"androidVisitCount,omitempty"` // +Android访问量
// ------分类3
LightVisitCount int64 `bson:"lightVisitCount,omitempty"` // light访问量
LightVisitDirectCount int64 `bson:"lightVisitDirectCount,omitempty"` // light访问量直推
LightVisitFissionCount int64 `bson:"lightVisitFissionCount,omitempty"` // light访问量裂变
LightVisitDeductionCount int64 `bson:"lightVisitDeductionCount,omitempty"` // light访问量扣量
LightVisitNaturalCount int64 `bson:"lightVisitNaturalCount,omitempty"` // light访问量自然
LightVisitWebCount int64 `bson:"lightVisitWebCount,omitempty"` // light访问量官网
LightVisitNormalCount int64 `bson:"lightVisitNormalCount,omitempty"` // light访问量自来
LightVisitDistrictCount int64 `bson:"lightVisitDistrictCount,omitempty"` // light访问量渠道
// ------分类3
H5VisitCount int64 `bson:"h5VisitCount,omitempty"` // H5访问量
H5PcVisitCount int64 `bson:"h5PcVisitCount,omitempty"` // +H5Pc访问量
H5IosVisitCount int64 `bson:"h5IosVisitCount,omitempty"` // +H5Ios访问量
H5AndroidVisitCount int64 `bson:"h5AndroidVisitCount,omitempty"` // +H5Android访问量
// ------分类4
WebVisitCount int64 `bson:"webVisitCount,omitempty"` // **官网访问
NormalVisitCount int64 `bson:"normalVisitCount,omitempty"` // **自来访问
DistrictVisitCount int64 `bson:"districtVisitCount,omitempty"` // **渠道访问
// 落地页访问
LandpageAndroidClick int64 `bson:"landpageAndroidClick,omitempty"` // 落地页android访问次数
LandpageIosAppstoreClick int64 `bson:"landpageIosAppstoreClick,omitempty"` // 落地页iOS商店包访问次数
LandpageIosAthorClick int64 `bson:"landpageIosAthorClick,omitempty"` // 落地页iOS其他包访问次数
LandpageIosH5Click int64 `bson:"landpageIosH5Click,omitempty"` // 落地页H5访问次数
// 充值统计
TotalAmount int64 `bson:"totalAmount,omitempty"` // **充值金额总量
// ------分类1
DirectAmount int64 `bson:"directAmount,omitempty"` // 直推充值金额
DirectAmountCount int64 `bson:"directAmountCount,omitempty"` // 直推充值订单数
FissionAmount int64 `bson:"fissionAmount,omitempty"` // 裂变充值金额
FissionAmountCount int64 `bson:"fissionAmountCount,omitempty"` // 裂变充值订单数
NaturalAmount int64 `bson:"naturalAmount,omitempty"` // 自然充值
NaturalAmountCount int64 `bson:"naturalAmountCount,omitempty"` // 自然充值订单数
DeductionAmount int64 `bson:"deductionAmount,omitempty"` // 充值扣量
DeductionAmountCount int64 `bson:"deductionAmountCount,omitempty"` // 充值扣量次数
// ------分类2
AndroidAmount int64 `bson:"androidAmount,omitempty"` // +安卓充值金额
AndroidAmountCount int64 `bson:"androidAmountCount,omitempty"` // +安卓充值次数
IosAmount int64 `bson:"iosAmount,omitempty"` // +Ios充值金额
IosAmountCount int64 `bson:"iosAmountCount,omitempty"` // +Ios充值次数
// ------分类3
LightAmount int64 `bson:"lightAmount,omitempty"` // light充值金额
LightAmountCount int64 `bson:"lightAmountCount,omitempty"` // light充值次数
LightDirectAmount int64 `bson:"lightDirectAmount,omitempty"` // light充值金额直推
LightDirectAmountCount int64 `bson:"lightDirectAmountCount,omitempty"` // light充值次数直推
LightFissionAmount int64 `bson:"lightFissionAmount,omitempty"` // light充值金额裂变
LightFissionAmountCount int64 `bson:"lightFissionAmountCount,omitempty"` // light充值次数裂变
LightDeductionAmount int64 `bson:"lightDeductionAmount,omitempty"` // light充值金额扣量
LightDeductionAmountCount int64 `bson:"lightDeductionAmountCount,omitempty"` // light充值次数扣量
LightNaturalAmount int64 `bson:"lightNaturalAmount,omitempty"` // light充值金额自然
LightNaturalAmountCount int64 `bson:"lightNaturalAmountCount,omitempty"` // light充值次数自然
LightWebAmount int64 `bson:"lightWebAmount,omitempty"` // light充值金额官网
LightWebAmountCount int64 `bson:"lightWebAmountCount,omitempty"` // light充值次数官网
LightNormalAmount int64 `bson:"lightNormalAmount,omitempty"` // light充值金额自来
LightNormalAmountCount int64 `bson:"lightNormalAmountCount,omitempty"` // light充值次数自来
LightDistrictAmount int64 `bson:"lightDistrictAmount,omitempty"` // light充值金额渠道
LightDistrictAmountCount int64 `bson:"lightDistrictAmountCount,omitempty"` // light充值次数渠道
// ------分类5
H5Amount int64 `bson:"h5Amount,omitempty"` // +H5充值金额
H5AmountCount int64 `bson:"h5AmountCount,omitempty"` // +H5充值次数
H5FormalAmount int64 `bson:"h5FormalAmount,omitempty"` // 当日H5Formal充值
H5FormalAmountCount int64 `bson:"h5FormalAmountCount,omitempty"` // 当日H5Formal充值次数
H5PcAmount int64 `bson:"h5PcAmount,omitempty"` // 当日H5Pc充值
H5PcAmountCount int64 `bson:"h5PcAmountCount,omitempty"` // 当日H5Pc充值次数
H5IosAmount int64 `bson:"todayH5IosRecharge,omitempty"` // 当日H5Ios充值
H5IosAmountCount int64 `bson:"h5IosAmountCount,omitempty"` // 当日H5Ios充值次数
H5AndroidAmount int64 `bson:"h5AndroidAmount,omitempty"` // 当日H5Android充值
H5AndroidAmountCount int64 `bson:"h5AndroidAmountCount,omitempty"` // 当日H5Android充值次数
// ------分类6
WebAmount int64 `bson:"webAmount,omitempty"` // **官网充值
WebAmountCount int64 `bson:"webAmountCount,omitempty"` // **官网充值次数
NormalAmount int64 `bson:"normalAmount,omitempty"` // **自来充值
NormalAmountCount int64 `bson:"normalAmountCount,omitempty"` // **自来充值次数
DistrictAmount int64 `bson:"districtAmount,omitempty"` // **渠道充值
DistrictAmountCount int64 `bson:"districtAmountCount,omitempty"` // **渠道充值次数
// ------分类7
RepeatAmount int64 `bson:"repeatAmount,omitempty"` // 复冲金额
RepeatAmountCount int64 `bson:"repeatAmountCount,omitempty"` // +复冲订单数
SuccessRechargeOrder int64 `bson:"successRechargeOrder,omitempty"` // 充值成功订单数
NewRechargeAmount int64 `bson:"newRechargeAmount,omitempty"` // 新增充值金额
NewRechargeCount int64 `bson:"newRechargeCount,omitempty"` // +新增充值订单
VipPayByMoney int64 `bson:"vipPayByMoney,omitempty"` // 人民币购买
VipPayByAmount int64 `bson:"vipPayByAmount,omitempty"` // 余额购买
VipRepeatAmount int64 `bson:"vipRepeatAmount,omitempty"` // VIP复冲金额
TotalRechargeOrder int64 `bson:"totalRechargeOrder,omitempty"` // 拉起订单数
// 游戏
GameRechageAmount int64 `bson:"gameRechageAmount,omitempty"` // 游戏充值
GameWithdrawAmount int64 `bson:"gameWithdrawAmount,omitempty"` // 游戏提现
// 更新时间
UpdatedAt time.Time `bson:"updatedAt,omitempty"` // 更新时间
}
type DailyHourStatList []*DailyHourStat
type DailyHourStatDoc struct {
SumHour *int `bson:"sumHour,omitempty"` // 小时数
// 注册用户
NewTotalCount *int64 `bson:"newTotalCount,omitempty"` // **新增总量
// ------分类1
NewDirectCount *int64 `bson:"newDirectCount,omitempty"` // 新增直推
NewFissionCount *int64 `bson:"newFissionCount,omitempty"` // 新增裂变
NewDeductionCount *int64 `bson:"newDeductionCount,omitempty"` // 新增扣量
NewNaturalCount *int64 `bson:"newNaturalCount,omitempty"` // 自然新增
// ------分类2
NewAndroidCount *int64 `bson:"newAndroidCount,omitempty"` // android新增
NewIosCount *int64 `bson:"newIosCount,omitempty"` // ios新增
// ------分类3
NewLightCount *int64 `bson:"newLightCount,omitempty"` // light新增
NewLightGuestCount *int64 `bson:"newLightGuestCount,omitempty"` // light新增安装
NewLightFormalCount *int64 `bson:"newLightFormalCount,omitempty"` // light新增注册
NewLightDirectCount *int64 `bson:"newLightDirectCount,omitempty"` // light新增直推
NewLightFissionCount *int64 `bson:"newLightFissionCount,omitempty"` // light新增裂变
NewLightDeductionCount *int64 `bson:"newLightDeductionCount,omitempty"` // light新增扣量
NewLightNaturalCount *int64 `bson:"newLightNaturalCount,omitempty"` // light自然新增
NewLightWebCount *int64 `bson:"newLightWebCount,omitempty"` // light官网新增
NewLightNormalCount *int64 `bson:"newLightNormalCount,omitempty"` // light自来新增
NewLightDistrictCount *int64 `bson:"newLightDistrictCount,omitempty"` // light渠道新增
// ------分类4
NewH5Count *int64 `bson:"newH5Count,omitempty"` // H5新增
NewH5FormalCount *int64 `bson:"newH5FormalCount,omitempty"` // H5注册新增
NewH5PcCount *int64 `bson:"newH5PcCount,omitempty"` // +H5PC新增
NewH5IosCount *int64 `bson:"NewH5IosCount,omitempty"` // +H5IOS新增
NewH5AndroidCount *int64 `bson:"newH5AndroidCount,omitempty"` // +H5Android新增
// ------分类4
NewWebCount *int64 `bson:"newWebCount,omitempty"` // **官网新增
NewNormalCount *int64 `bson:"newNormalCount,omitempty"` // **自来新增
NewDistrictCount *int64 `bson:"newDistrictCount,omitempty"` // **渠道新增
// 访问统计
TotalVisitCount *int64 `bson:"totalVisitCount,omitempty"` // **访问总量
// ------分类1
DirectVisitCount *int64 `bson:"directVisitCount,omitempty"` // 直推访问数
FissionVisitCount *int64 `bson:"fissionVisitCount,omitempty"` // 裂变访问数
NaturalVisitCount *int64 `bson:"naturalVisitCount,omitempty"` // **自然访问数
DeductionVisitCount *int64 `bson:"deductionVisitCount,omitempty"` // 新增扣量
// ------分类2
IosVisitCount *int64 `bson:"iosVisitCount,omitempty"` // +Ios访问量
AndroidVisitCount *int64 `bson:"androidVisitCount,omitempty"` // +Android访问量
// ------分类3
LightVisitCount *int64 `bson:"lightVisitCount,omitempty"` // light访问量
LightVisitDirectCount *int64 `bson:"lightVisitDirectCount,omitempty"` // light访问量直推
LightVisitFissionCount *int64 `bson:"lightVisitFissionCount,omitempty"` // light访问量裂变
LightVisitDeductionCount *int64 `bson:"lightVisitDeductionCount,omitempty"` // light访问量扣量
LightVisitNaturalCount *int64 `bson:"lightVisitNaturalCount,omitempty"` // light访问量自然
LightVisitWebCount *int64 `bson:"lightVisitWebCount,omitempty"` // light访问量官网
LightVisitNormalCount *int64 `bson:"lightVisitNormalCount,omitempty"` // light访问量自来
LightVisitDistrictCount *int64 `bson:"lightVisitDistrictCount,omitempty"` // light访问量渠道
// ------分类3
H5VisitCount *int64 `bson:"h5VisitCount,omitempty"` // H5访问量
H5PcVisitCount *int64 `bson:"h5PcVisitCount,omitempty"` // +H5Pc访问量
H5IosVisitCount *int64 `bson:"h5IosVisitCount,omitempty"` // +H5Ios访问量
H5AndroidVisitCount *int64 `bson:"h5AndroidVisitCount,omitempty"` // +H5Android访问量
// ------分类4
WebVisitCount *int64 `bson:"webVisitCount,omitempty"` // **官网访问
NormalVisitCount *int64 `bson:"normalVisitCount,omitempty"` // **自来访问
DistrictVisitCount *int64 `bson:"districtVisitCount,omitempty"` // **渠道访问
// 落地页访问
LandpageAndroidClick *int64 `bson:"landpageAndroidClick,omitempty"` // 落地页android访问次数
LandpageIosAppstoreClick *int64 `bson:"landpageIosAppstoreClick,omitempty"` // 落地页iOS商店包访问次数
LandpageIosAthorClick *int64 `bson:"landpageIosAthorClick,omitempty"` // 落地页iOS其他包访问次数
LandpageIosH5Click *int64 `bson:"landpageIosH5Click,omitempty"` // 落地页H5访问次数
// 充值统计
TotalAmount *int64 `bson:"totalAmount,omitempty"` // **充值金额总量
// ------分类1
DirectAmount *int64 `bson:"directAmount,omitempty"` // 直推充值金额
DirectAmountCount *int64 `bson:"directAmountCount,omitempty"` // +直推充值订单数
FissionAmount *int64 `bson:"fissionAmount,omitempty"` // 裂变充值金额
FissionAmountCount *int64 `bson:"fissionAmountCount,omitempty"` // +裂变充值订单数
NaturalAmount *int64 `bson:"naturalAmount,omitempty"` // 自然充值
NaturalAmountCount *int64 `bson:"naturalAmountCount,omitempty"` // +自然充值订单数
DeductionAmount *int64 `bson:"deductionAmount,omitempty"` // 充值扣量
DeductionAmountCount *int64 `bson:"deductionAmountCount,omitempty"` // 充值扣量次数
// ------分类2
AndroidAmount *int64 `bson:"androidAmount,omitempty"` // +安卓充值金额
AndroidAmountCount *int64 `bson:"androidAmountCount,omitempty"` // +安卓充值次数
IosAmount *int64 `bson:"iosAmount,omitempty"` // +Ios充值金额
IosAmountCount *int64 `bson:"iosAmountCount,omitempty"` // +Ios充值次数
// ------分类3
LightAmount *int64 `bson:"lightAmount,omitempty"` // light充值金额
LightAmountCount *int64 `bson:"lightAmountCount,omitempty"` // light充值次数
LightDirectAmount *int64 `bson:"lightDirectAmount,omitempty"` // light充值金额直推
LightDirectAmountCount *int64 `bson:"lightDirectAmountCount,omitempty"` // light充值次数直推
LightFissionAmount *int64 `bson:"lightFissionAmount,omitempty"` // light充值金额裂变
LightFissionAmountCount *int64 `bson:"lightFissionAmountCount,omitempty"` // light充值次数裂变
LightDeductionAmount *int64 `bson:"lightDeductionAmount,omitempty"` // light充值金额扣量
LightDeductionAmountCount *int64 `bson:"lightDeductionAmountCount,omitempty"` // light充值次数扣量
LightNaturalAmount *int64 `bson:"lightNaturalAmount,omitempty"` // light充值金额自然
LightNaturalAmountCount *int64 `bson:"lightNaturalAmountCount,omitempty"` // light充值次数自然
LightWebAmount *int64 `bson:"lightWebAmount,omitempty"` // light充值金额官网
LightWebAmountCount *int64 `bson:"lightWebAmountCount,omitempty"` // light充值次数官网
LightNormalAmount *int64 `bson:"lightNormalAmount,omitempty"` // light充值金额自来
LightNormalAmountCount *int64 `bson:"lightNormalAmountCount,omitempty"` // light充值次数自来
LightDistrictAmount *int64 `bson:"lightDistrictAmount,omitempty"` // light充值金额渠道
LightDistrictAmountCount *int64 `bson:"lightDistrictAmountCount,omitempty"` // light充值次数渠道
// ------分类5
H5Amount *int64 `bson:"h5Amount,omitempty"` // +H5充值金额
H5AmountCount *int64 `bson:"h5AmountCount,omitempty"` // +H5充值次数
H5FormalAmount *int64 `bson:"h5FormalAmount,omitempty"` // 当日H5Formal充值
H5FormalAmountCount *int64 `bson:"h5FormalAmountCount,omitempty"` // 当日H5Formal充值次数
H5PcAmount *int64 `bson:"h5PcAmount,omitempty"` // 当日H5Pc充值
H5PcAmountCount *int64 `bson:"h5PcAmountCount,omitempty"` // 当日H5Pc充值次数
H5IosAmount *int64 `bson:"todayH5IosRecharge,omitempty"` // 当日H5Ios充值
H5IosAmountCount *int64 `bson:"h5IosAmountCount,omitempty"` // 当日H5Ios充值次数
H5AndroidAmount *int64 `bson:"h5AndroidAmount,omitempty"` // 当日H5Android充值
H5AndroidAmountCount *int64 `bson:"h5AndroidAmountCount,omitempty"` // 当日H5Android充值次数
// ------分类6
WebAmount *int64 `bson:"webAmount,omitempty"` // **官网充值
WebAmountCount *int64 `bson:"webAmountCount,omitempty"` // **官网充值次数
NormalAmount *int64 `bson:"normalAmount,omitempty"` // **自来充值
NormalAmountCount *int64 `bson:"normalAmountCount,omitempty"` // **自来充值次数
DistrictAmount *int64 `bson:"districtAmount,omitempty"` // **渠道充值
DistrictAmountCount *int64 `bson:"districtAmountCount,omitempty"` // **渠道充值次数
// ------分类7
RepeatAmount *int64 `bson:"repeatAmount,omitempty"` // 复冲金额
RepeatAmountCount *int64 `bson:"repeatAmountCount,omitempty"` // +复冲订单数
SuccessRechargeOrder *int64 `bson:"successRechargeOrder,omitempty"` // 充值成功订单数
NewRechargeAmount *int64 `bson:"newRechargeAmount,omitempty"` // 新增充值金额
NewRechargeCount *int64 `bson:"newRechargeCount,omitempty"` // +新增充值订单
VipPayByMoney *int64 `bson:"vipPayByMoney,omitempty"` // 人民币购买
VipPayByAmount *int64 `bson:"vipPayByAmount,omitempty"` // 余额购买
VipRepeatAmount *int64 `bson:"vipRepeatAmount,omitempty"` // VIP复冲金额
TotalRechargeOrder *int64 `bson:"totalRechargeOrder,omitempty"` // 拉起订单数
// 游戏
GameRechageAmount *int64 `bson:"gameRechageAmount,omitempty"` // 游戏充值
GameWithdrawAmount *int64 `bson:"gameWithdrawAmount,omitempty"` // 游戏提现
}
+128
View File
@@ -0,0 +1,128 @@
package dailystatadvertise
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var db *mongos.MongoTool
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.New(mongos.MgoManager, TN.DailyStatAdvertise)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.DailyStatAdvertise.SumDate, Value: 1},
{Key: FN.DailyStatAdvertise.AppId, Value: 1},
},
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(DailyStatAdvertise:initDailyStatAdvertiseIndex) Create DailyStatAdvertise Index failed! err:%+v:", err))
}
}
//InsertOneDailyStatAdvertise 插入一个VIP购买记录
func InsertOneDailyStatAdvertise(ctx context.Context, DailyStatAdvertise *DailyStatAdvertise) error {
if _, err := db.InsertOne(ctx, DailyStatAdvertise); err != nil {
log.Warn("DailyStatAdvertise:InsertOneDailyStatAdvertise db.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneDailyStatAdvertise 查找一个VIP购买记录
func FindOneDailyStatAdvertise(ctx context.Context, filter bson.M) (
*DailyStatAdvertise, error) {
var DailyStatAdvertise DailyStatAdvertise
if err := db.FindOne(ctx, &DailyStatAdvertise, filter); err != nil {
return nil, err
}
return &DailyStatAdvertise, nil
}
//DelOneDailyStatAdvertise 删除一个VIP购买记录
func DelOneDailyStatAdvertise(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("DailyStatAdvertise:DelOneDailyStatAdvertise db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateOneDailyStatAdvertise 更新一个VIP购买记录
func UpdateOneDailyStatAdvertise(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateOneDailyStatAdvertise db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//CountDailyStatAdvertises 统计VIP购买记录数量
func CountDailyStatAdvertises(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("DailyStatAdvertise:CountDailyStatAdvertises db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateManyDailyStatAdvertise 更新满足条件的VIP购买记录
func UpdateManyDailyStatAdvertise(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyDailyStatAdvertise db.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//FindManyDailyStatAdvertise 查找一批VIP购买记录数据
func FindManyDailyStatAdvertise(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (DailyStatAdvertiseList, error) {
data := make(DailyStatAdvertiseList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("DailyStatAdvertise:FindManyDailyStatAdvertise db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
//FindManyDailyStatAdvertiseWithBind 用自己定义结构查找一批VIP购买记录数据
func FindManyDailyStatAdvertiseWithBind(ctx context.Context, bind interface{}, filter bson.M,
opts ...*options.FindOptions) error {
if err := db.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("DailyStatAdvertise:FindManyDailyStatAdvertiseWithBind db.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//AggregateDailyStatAdvertises 聚合查找一批VIP购买记录信息
func AggregateDailyStatAdvertises(ctx context.Context,
bind interface{}, pipeline []bson.M) error {
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("feedback:AggregateDailyStatAdvertises db.Aggregate failed",
log.E(err), log.Any("pipeline", pipeline))
return err
}
return nil
}
+34
View File
@@ -0,0 +1,34 @@
package dailystatadvertise
type TagDailyStatAdvertise struct {
AppId string
AppName string
Day1RetainRate string
Day3RetainRate string
Day7RetainRate string
DirectVisitCount string
ID string
NewDirectCount string
SumDate string
}
var FN struct {
DailyStatAdvertise TagDailyStatAdvertise
}
var TN struct {
DailyStatAdvertise string
}
func init() {
FN.DailyStatAdvertise.AppId = "appId"
FN.DailyStatAdvertise.AppName = "appName"
FN.DailyStatAdvertise.Day1RetainRate = "day1RetainRate"
FN.DailyStatAdvertise.Day3RetainRate = "day3RetainRate"
FN.DailyStatAdvertise.Day7RetainRate = "day7RetainRate"
FN.DailyStatAdvertise.DirectVisitCount = "directVisitCount"
FN.DailyStatAdvertise.ID = "_id"
FN.DailyStatAdvertise.NewDirectCount = "newDirectCount"
FN.DailyStatAdvertise.SumDate = "sumDate"
TN.DailyStatAdvertise = "dailystat_advertise"
}
+22
View File
@@ -0,0 +1,22 @@
package dailystatadvertise
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// 帖子模型,数据库中的
// @table:dailystat_advertise
type DailyStatAdvertise struct {
ID primitive.ObjectID `bson:"_id,omitempty"` // ID
SumDate time.Time `bson:"sumDate" json:"sumDate"` // 记录时间 按天对齐
AppId int32 `bson:"appId,omitempty" json:"appId"` // appId
AppName string `bson:"appName,omitempty" json:"appName"` // app名称
NewDirectCount int64 `bson:"newDirectCount,omitempty" json:"newDirectCount"` // 新增直推
DirectVisitCount int64 `bson:"directVisitCount,omitempty" json:"directVisitCount"` // 直推访问数
Day1RetainRate string `bson:"day1RetainRate,omitempty" json:"day1RetainRate"` // 次日留存率
Day3RetainRate string `bson:"day3RetainRate,omitempty" json:"day3RetainRate"` // 3日留存率
Day7RetainRate string `bson:"day7RetainRate,omitempty" json:"day7RetainRate"` // 7日留存率
}
type DailyStatAdvertiseList []*DailyStatAdvertise
+177
View File
@@ -0,0 +1,177 @@
package dailystatmod
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"stat/common/utils"
"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, CollDailyStat)
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", CollDailyStat, err))
}
}
// UpsertDailyStat 更新或插入一条统计记录
func UpsertDailyStat(ctx context.Context, sumDate time.Time, appId int32, doc DailyStatDoc) (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 GetDailyStatList(ctx context.Context, appId *[]int32, start, end *time.Time, skip, limit int64) (count int64, data []*DailyStatMod, err error) {
filter := bson.M{}
if appId != nil {
filter["appId"] = bson.M{"$in": 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 GetDailyStatTotalList(ctx context.Context, appId *int32, start, end *time.Time) (data []*DailyStatMod, 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}
}
if err = db.Find(ctx, &data, filter); err != nil {
log.Error("channel GetDailyStatList Find err", log.E(err))
return
}
return
}
type OnItem func(item *DailyStatMod)
// 获取日常统计列表
func GetDailyStatTotalListShard(ctx context.Context, appId *[]int32, start, end *time.Time, shard time.Duration, onItem OnItem) error {
if start == nil {
b := utils.DefaultStatBeginTime
start = &b
}
if end == nil {
e := time.Now()
end = &e
}
segments := utils.CalcTimeSegments(*start, *end, shard)
for _, segment := range segments {
filter := bson.M{
"sumDate": bson.M{"$gte": segment.Begin, "$lt": segment.End},
}
if appId != nil {
filter["appId"] = bson.M{"$in": appId}
}
list := make([]*DailyStatMod, 0)
if err := db.Find(ctx, &list, filter); err != nil {
log.Error("channel GetDailyStatList Find err", log.E(err))
return err
}
for _, item := range list {
onItem(item)
}
}
return nil
}
// 获取日常统计列表
func FindOneDailyStat(ctx context.Context, appId int32, sumDate time.Time) (data DailyStatMod, err error) {
filter := bson.M{
"appId": appId,
"sumDate": sumDate,
}
if err = db.FindOne(ctx, &data, filter); err != nil {
log.Error("channel GetDailyStatList Find err", log.E(err))
return
}
return
}
func FindDailyStatList(ctx context.Context, appIds []int32, sumDate time.Time) (list []DailyStatMod, err error) {
filter := bson.M{
"appId": bson.M{"$in": appIds},
"sumDate": sumDate,
}
log.Info("FindDailyStatList", log.Any("filter", filter))
list = make([]DailyStatMod, 0)
if err = db.Find(ctx, &list, filter); err != nil {
log.Error("channel GetDailyStatList Find err", log.E(err))
return
}
return
}
+24
View File
@@ -0,0 +1,24 @@
package dailystatmod
import "time"
var (
fixTime time.Time
)
func init() {
time.Local, _ = time.LoadLocation("Asia/Shanghai")
fixTime, _ = time.ParseInLocation("2006-01-02", "2023-07-14", time.Local)
}
func (s *DailyStatMod) CorrectValidData() *DailyStatMod {
if s.SumDate.Before(fixTime) {
s.TotalAmount = s.DirectAmount + s.FissionAmount + s.DeductionAmount
s.NewTotalCount = s.NewDirectCount + s.NewFissionCount + s.NewDeductionCount
s.TotalVisitCount = s.DirectVisitCount + s.FissionVisitCount + s.DeductionVisitCount
s.LightAddCount = s.LightDirectCount + s.LightFissionCount + s.LightDeductionCount
s.LightRechargeCount = s.LightDirectRechargeCount + s.LightFissionRechargeCount + s.LightDeductionRechargeCount
s.LightRechargeAmount = s.LightDirectRechargeAmount + s.LightFissionRechargeAmount + s.LightDeductionRechargeAmount
}
return s
}
+260
View File
@@ -0,0 +1,260 @@
package dailystatmod
import (
"stat/common/mongos"
"time"
)
// 表名
const CollDailyStat = "daily_stat"
var db *mongos.MongoTool
// DailyStatMod APP日常统计
type DailyStatMod struct {
SumDate time.Time `bson:"sumDate"` // 记录时间 按天对齐
AppId int32 `bson:"appId"` // appId
// 注册用户
NewTotalCount int64 `bson:"newTotalCount,omitempty"` // 注册总量
NewDirectCount int64 `bson:"newDirectCount,omitempty"` // 直推注册
NewFissionCount int64 `bson:"newFissionCount,omitempty"` // 裂变注册
NewDeductionCount int64 `bson:"newDeductionCount,omitempty"` // 扣量注册
NewNaturalCount int64 `bson:"newNaturalCount,omitempty"` // 自然注册
NewWebCount int64 `bson:"newWebCount,omitempty"` // 官网注册
NewDistrictCount int64 `bson:"newDistrictCount,omitempty"` // 渠道注册
NewNormalCount int64 `bson:"newNormalCount,omitempty"` // 自来注册
AndroidAddCount int64 `bson:"androidAddCount,omitempty"` // android注册
IosAddCount int64 `bson:"iosAddCount,omitempty"` // ios注册
// 轻量注册
LightAddCount int64 `bson:"lightAddCount,omitempty"` // ##轻量注册
LightGuestAddCount int64 `bson:"lightGuestAddCount,omitempty"` // 轻量游客注册
LightFormalAddCount int64 `bson:"lightFormalAddCount,omitempty"` // 轻量正式注册
LightDirectCount int64 `bson:"lightDirectCount,omitempty"` // 轻量直推注册
LightFissionCount int64 `bson:"lightFissionCount,omitempty"` // 轻量裂变注册
LightDeductionCount int64 `bson:"lightDeductionCount,omitempty"` // 轻量扣量注册
LightNaturalCount int64 `bson:"lightNaturalCount,omitempty"` // 轻量自然注册
LightWebCount int64 `bson:"lightWebCount,omitempty"` // 轻量官网注册
LightDistrictCount int64 `bson:"lightDistrictCount,omitempty"` // 轻量渠道注册
LightNormalCount int64 `bson:"lightNormalCount,omitempty"` // 轻量自来注册
// H5注册
H5AddCount int64 `bson:"h5AddCount,omitempty"` // H5注册
H5FormalCount int64 `bson:"h5FormalCount,omitempty"` // H5正式注册
H5PcAddCount int64 `bson:"h5PcAddCount,omitempty"` // H5Pc注册
H5IosAddCount int64 `bson:"h5IosAddCount,omitempty"` // H5Ios注册
H5AndroidAddCount int64 `bson:"h5AndroidAddCount,omitempty"` // H5Android注册
// 访问统计
TotalVisitCount int64 `bson:"totalVisitCount,omitempty"` // 总计访问数
DirectVisitCount int64 `bson:"directVisitCount,omitempty"` // 直推访问数
FissionVisitCount int64 `bson:"fissionVisitCount,omitempty"` // 裂变访问数
DeductionVisitCount int64 `bson:"deductionVisitCount,omitempty"` // 扣量访问数
NaturalVisitCount int64 `bson:"naturalVisitCount,omitempty"` // 自然访问数
TodayDistrictVisitCount int64 `bson:"todayDistrictVisitCount,omitempty"` // 当日渠道访问量
TodayWebVisitCount int64 `bson:"todayWebVisitCount,omitempty"` // 当日官网访问量
TodayNormalVisitCount int64 `bson:"todayNormalVisitCount,omitempty"` // 当日自来访问量
TodayIosVisitCount int64 `bson:"todayIosVisitCount,omitempty"` // 当日IOS访问量
TodayAndroidVisitCount int64 `bson:"todayAndroidVisitCount,omitempty"` // 当日安卓访问量
// 轻量访问
LightVisitCount int64 `bson:"lightVisitCount,omitempty"` // 当日Light访问量
LightDirectVisitCount int64 `bson:"lightDirectVisitCount,omitempty"` // 轻量直推访问
LightFissionVisitCount int64 `bson:"lightFissionVisitCount,omitempty"` // 轻量裂变访问
LightDeductionVisitCount int64 `bson:"lightDeductionVisitCount,omitempty"` // 轻量扣量访问
LightNaturalVisitCount int64 `bson:"lightNaturalVisitCount,omitempty"` // 轻量自然访问
LightWebVisitCount int64 `bson:"lightWebVisitCount,omitempty"` // 轻量官网访问
LightDistrictVisitCount int64 `bson:"lightDistrictVisitCount,omitempty"` // 轻量渠道访问
LightNormalVisitCount int64 `bson:"lightNormalVisitCount,omitempty"` // 轻量自来访问
// H5访问
TodayH5VisitCount int64 `bson:"todayH5VisitCount,omitempty"` // 当日H5访问量
TodayH5PcVisitCount int64 `bson:"todayH5PcVisitCount,omitempty"` // 当日H5Pc访问量
TodayH5IosVisitCount int64 `bson:"todayH5IosVisitCount,omitempty"` // 当日H5Ios访问量
TodayH5AndroidVisitCount int64 `bson:"todayH5AndroidVisitCount,omitempty"` // 当日H5Android访问量
// 落地页访问
LandpageAndroidClick int64 `bson:"landpageAndroidClick,omitempty"` // 落地页android访问次数
LandpageIosAppstoreClick int64 `bson:"landpageIosAppstoreClick,omitempty"` // 落地页iOS商店包访问次数
LandpageIosAthorClick int64 `bson:"landpageIosAthorClick,omitempty"` // 落地页iOS其他包访问次数
LandpageIosH5Click int64 `bson:"landpageIosH5Click,omitempty"` // 落地页H5访问次数
// 当日充值
TotalAmount int64 `bson:"totalAmount,omitempty"` // 充值金额
SuccessRechargeOrder int64 `bson:"successRechargeOrder,omitempty"` // 充值成功订单数
DirectAmount int64 `bson:"directAmount,omitempty"` // 直推充值金额
DirectAmountCount int64 `bson:"directAmountcount,omitempty"` // 直推充值订单
FissionAmount int64 `bson:"fissionAmount,omitempty"` // 裂变充值金额
FissionAmountCount int64 `bson:"fissionAmountcount,omitempty"` // 裂变充值订单
DeductionAmount int64 `bson:"deductionAmount,omitempty"` // 扣量金额
DeductionAmountCount int64 `bson:"deductionAmountCount,omitempty"` // 扣量充值订单
NaturalAmount int64 `bson:"naturalAmount,omitempty"` // 自然充值
NaturalAmountCount int64 `bson:"naturalAmountCount,omitempty"` // 自然充值订单
TodayDistrictRecharge int64 `bson:"todayDistrictRecharge,omitempty"` // 当日渠道充值新增
TodayWebRecharge int64 `bson:"todayWebRecharge,omitempty"` // 当日官网充值新增
TodayNormalRecharge int64 `bson:"todayNormalRecharge,omitempty"` // 当日自来量充值新增
TodayAndroidRecharge int64 `bson:"todayAndroidRecharge,omitempty"` // 当日android充值
TodayIosRecharge int64 `bson:"todayIosRecharge,omitempty"` // 当日Ios充值
TodayH5Recharge int64 `bson:"todayH5Recharge,omitempty"` // 当日H5充值
TodayH5FormalRecharge int64 `bson:"todayH5FormalRecharge,omitempty"` // 当日H5Formal充值
TodayH5PcRecharge int64 `bson:"todayH5PcRecharge,omitempty"` // 当日H5Pc充值
TodayH5IosRecharge int64 `bson:"todayH5IosRecharge,omitempty"` // 当日H5Ios充值
TodayH5AndroidRecharge int64 `bson:"todayH5AndroidRecharge,omitempty"` // 当日H5Android充值
// 轻量充值次数
LightRechargeCount int64 `bson:"lightRechargeCount,omitempty"` // 当日轻量充值次数
LightDirectRechargeCount int64 `bson:"lightDirectRechargeCount,omitempty"` // 轻量直推充值次数
LightFissionRechargeCount int64 `bson:"lightFissionRechargeCount,omitempty"` // 轻量裂变充值次数
LightDeductionRechargeCount int64 `bson:"lightDeductionRechargeCount,omitempty"` // 轻量扣量充值次数
LightNaturalRechargeCount int64 `bson:"lightNaturalRechargeCount,omitempty"` // 轻量自然充值次数
LightWebRechargeCount int64 `bson:"lightWebRechargeCount,omitempty"` // 轻量官网充值次数
LightDistrictRechargeCount int64 `bson:"lightDistrictRechargeCount,omitempty"` // 轻量渠道充值次数
LightNormalRechargeCount int64 `bson:"lightNormalRechargeCount,omitempty"` // 轻量自来充值次数
// 轻量充值钱数
LightRechargeAmount int64 `bson:"lightRechargeAmount,omitempty"` // 当日轻量充值钱数
LightDirectRechargeAmount int64 `bson:"lightDirectRechargeAmount,omitempty"` // 轻量直推充值钱数
LightFissionRechargeAmount int64 `bson:"lightFissionRechargeAmount,omitempty"` // 轻量裂变充值钱数
LightDeductionRechargeAmount int64 `bson:"lightDeductionRechargeAmount,omitempty"` // 轻量扣量充值钱数
LightNaturalRechargeAmount int64 `bson:"lightNaturalRechargeAmount,omitempty"` // 轻量自然充值钱数
LightWebRechargeAmount int64 `bson:"lightWebRechargeAmount,omitempty"` // 轻量官网充值钱数
LightDistrictRechargeAmount int64 `bson:"lightDistrictRechargeAmount,omitempty"` // 轻量渠道充值钱数
LightNormalRechargeAmount int64 `bson:"lightNormalRechargeAmount,omitempty"` // 轻量自来充值钱数
// 其他充值
VipPayByMoney int64 `bson:"vipPayByMoney,omitempty"` // 人民币购买
VipPayByAmount int64 `bson:"vipPayByAmount,omitempty"` // 余额购买
RepeatAmount int64 `bson:"repeatAmount,omitempty"` // 复冲金额
RepeatCount int64 `bson:"repeatCount,omitempty"` // 复冲人数
// 游戏充值
GameRechageAmount int64 `bson:"gameRechageAmount,omitempty"` // 游戏充值
GameWithdrawAmount int64 `bson:"gameWithdrawAmount,omitempty"` // 游戏提现
//
TodayVipRecharge int64 `bson:"todayVipRecharge,omitempty"` // 当日渠道充值新增
NewVipPayMoney int64 `bson:"newVipPayMoney,omitempty"` // 新增购买VIP
RepeatVipMoney int64 `bson:"repeatVipMoney,omitempty"` // 复冲VIP
// 新增充值
NewRechargeAmount int64 `bson:"newRechargeAmount,omitempty"` // 新增充值金额(新用户)
NewRechargeCount int64 `bson:"newRechargeCount,omitempty"` // 新增充值数(新用户)
// 留存率
Day1RetainRate float64 `bson:"day1RetainRate,omitempty"` // 次日留存率
Day3RetainRate float64 `bson:"day3RetainRate,omitempty"` // 3日留存率
Day7RetainRate float64 `bson:"day7RetainRate,omitempty"` // 7日留存率
// 订单
TotalRechargeOrder int64 `bson:"totalRechargeOrder,omitempty"` // 拉起订单数
// 时间
UpdatedAt time.Time `bson:"updatedAt,omitempty"` // 更新时间
}
type DailyStatDoc struct {
// 注册用户
NewTotalCount *int64 `bson:"newTotalCount,omitempty"` // **注册总量
NewDirectCount *int64 `bson:"newDirectCount,omitempty"` // 直推注册
NewFissionCount *int64 `bson:"newFissionCount,omitempty"` // 裂变注册
NewDeductionCount *int64 `bson:"newDeductionCount,omitempty"` // 扣量注册
NewNaturalCount *int64 `bson:"newNaturalCount,omitempty"` // 自然注册
NewWebCount *int64 `bson:"newWebCount,omitempty"` // 官网注册
NewDistrictCount *int64 `bson:"newDistrictCount,omitempty"` // 渠道注册
NewNormalCount *int64 `bson:"newNormalCount,omitempty"` // 自来注册
AndroidAddCount *int64 `bson:"androidAddCount,omitempty"` // android注册
IosAddCount *int64 `bson:"iosAddCount,omitempty"` // ios注册
// 轻量注册
LightAddCount *int64 `bson:"lightAddCount,omitempty"` // ##轻量注册
LightGuestAddCount *int64 `bson:"lightGuestAddCount,omitempty"` // 轻量游客注册
LightFormalAddCount *int64 `bson:"lightFormalAddCount,omitempty"` // 轻量正式注册
LightDirectCount *int64 `bson:"lightDirectCount,omitempty"` // 轻量直推注册
LightFissionCount *int64 `bson:"lightFissionCount,omitempty"` // 轻量裂变注册
LightDeductionCount *int64 `bson:"lightDeductionCount,omitempty"` // 轻量扣量注册
LightNaturalCount *int64 `bson:"lightNaturalCount,omitempty"` // 轻量自然注册
LightWebCount *int64 `bson:"lightWebCount,omitempty"` // 轻量官网注册
LightDistrictCount *int64 `bson:"lightDistrictCount,omitempty"` // 轻量渠道注册
LightNormalCount *int64 `bson:"lightNormalCount,omitempty"` // 轻量自来注册
// H5注册
H5AddCount *int64 `bson:"h5AddCount,omitempty"` // H5注册
H5FormalCount *int64 `bson:"h5FormalCount,omitempty"` // H5正式注册
H5PcAddCount *int64 `bson:"h5PcAddCount,omitempty"` // H5Pc注册
H5IosAddCount *int64 `bson:"h5IosAddCount,omitempty"` // H5Ios注册
H5AndroidAddCount *int64 `bson:"h5AndroidAddCount,omitempty"` // H5Android注册
// 访问统计
TotalVisitCount *int64 `bson:"totalVisitCount,omitempty"` // **总计访问数
DirectVisitCount *int64 `bson:"directVisitCount,omitempty"` // 直推访问数
FissionVisitCount *int64 `bson:"fissionVisitCount,omitempty"` // 裂变访问数
DeductionVisitCount *int64 `bson:"deductionVisitCount,omitempty"` // 扣量访问数
NaturalVisitCount *int64 `bson:"naturalVisitCount,omitempty"` // **自然访问数
TodayDistrictVisitCount *int64 `bson:"todayDistrictVisitCount,omitempty"` // **当日渠道访问量
TodayWebVisitCount *int64 `bson:"todayWebVisitCount,omitempty"` // **当日官网访问量
TodayNormalVisitCount *int64 `bson:"todayNormalVisitCount,omitempty"` // **当日自来访问量
TodayIosVisitCount *int64 `bson:"todayIosVisitCount,omitempty"` // 当日IOS访问量
TodayAndroidVisitCount *int64 `bson:"todayAndroidVisitCount,omitempty"` // 当日安卓访问量
// 轻量访问
LightVisitCount *int64 `bson:"lightVisitCount,omitempty"` // 当日Light访问量
LightDirectVisitCount *int64 `bson:"lightDirectVisitCount,omitempty"` // 轻量直推访问
LightFissionVisitCount *int64 `bson:"lightFissionVisitCount,omitempty"` // 轻量裂变访问
LightDeductionVisitCount *int64 `bson:"lightDeductionVisitCount,omitempty"` // 轻量扣量访问
LightNaturalVisitCount *int64 `bson:"lightNaturalVisitCount,omitempty"` // 轻量自然访问
LightWebVisitCount *int64 `bson:"lightWebVisitCount,omitempty"` // 轻量官网访问
LightDistrictVisitCount *int64 `bson:"lightDistrictVisitCount,omitempty"` // 轻量渠道访问
LightNormalVisitCount *int64 `bson:"lightNormalVisitCount,omitempty"` // 轻量自来访问
// H5访问
TodayH5VisitCount *int64 `bson:"todayH5VisitCount,omitempty"` // 当日H5访问量
TodayH5PcVisitCount *int64 `bson:"todayH5PcVisitCount,omitempty"` // 当日H5Pc访问量
TodayH5IosVisitCount *int64 `bson:"todayH5IosVisitCount,omitempty"` // 当日H5Ios访问量
TodayH5AndroidVisitCount *int64 `bson:"todayH5AndroidVisitCount,omitempty"` // 当日H5Android访问量
// 落地页访问
LandpageAndroidClick *int64 `bson:"landpageAndroidClick,omitempty"` // 落地页android访问次数
LandpageIosAppstoreClick *int64 `bson:"landpageIosAppstoreClick,omitempty"` // 落地页iOS商店包访问次数
LandpageIosAthorClick *int64 `bson:"landpageIosAthorClick,omitempty"` // 落地页iOS其他包访问次数
LandpageIosH5Click *int64 `bson:"landpageIosH5Click,omitempty"` // 落地页H5访问次数
// 当日充值
TotalAmount *int64 `bson:"totalAmount,omitempty"` // 充值金额
SuccessRechargeOrder *int64 `bson:"successRechargeOrder,omitempty"` // 充值成功订单数
DirectAmount *int64 `bson:"directAmount,omitempty"` // 直推充值金额
DirectAmountCount *int64 `bson:"directAmountcount,omitempty"` // 直推充值订单
FissionAmount *int64 `bson:"fissionAmount,omitempty"` // 裂变充值金额
FissionAmountCount *int64 `bson:"fissionAmountcount,omitempty"` // 裂变充值订单
DeductionAmount *int64 `bson:"deductionAmount,omitempty"` // 扣量金额
DeductionAmountCount *int64 `bson:"deductionAmountCount,omitempty"` // 扣量充值订单
NaturalAmount *int64 `bson:"naturalAmount,omitempty"` // 自然充值
NaturalAmountCount *int64 `bson:"naturalAmountCount,omitempty"` // **自然充值订单
TodayDistrictRecharge *int64 `bson:"todayDistrictRecharge,omitempty"` // 当日渠道充值新增
TodayWebRecharge *int64 `bson:"todayWebRecharge,omitempty"` // 当日官网充值新增
TodayNormalRecharge *int64 `bson:"todayNormalRecharge,omitempty"` // 当日自来量充值新增
TodayAndroidRecharge *int64 `bson:"todayAndroidRecharge,omitempty"` // 当日android充值
TodayIosRecharge *int64 `bson:"todayIosRecharge,omitempty"` // 当日Ios充值
TodayH5Recharge *int64 `bson:"todayH5Recharge,omitempty"` // 当日H5充值
TodayH5FormalRecharge *int64 `bson:"todayH5FormalRecharge,omitempty"` // 当日H5Formal充值
TodayH5PcRecharge *int64 `bson:"todayH5PcRecharge,omitempty"` // 当日H5Pc充值
TodayH5IosRecharge *int64 `bson:"todayH5IosRecharge,omitempty"` // 当日H5Ios充值
TodayH5AndroidRecharge *int64 `bson:"todayH5AndroidRecharge,omitempty"` // 当日H5Android充值
// 轻量充值次数
LightRechargeCount *int64 `bson:"lightRechargeCount,omitempty"` // 当日轻量充值次数
LightDirectRechargeCount *int64 `bson:"lightDirectRechargeCount,omitempty"` // 轻量直推充值次数
LightFissionRechargeCount *int64 `bson:"lightFissionRechargeCount,omitempty"` // 轻量裂变充值次数
LightDeductionRechargeCount *int64 `bson:"lightDeductionRechargeCount,omitempty"` // 轻量扣量充值次数
LightNaturalRechargeCount *int64 `bson:"lightNaturalRechargeCount,omitempty"` // 轻量自然充值次数
LightWebRechargeCount *int64 `bson:"lightWebRechargeCount,omitempty"` // 轻量官网充值次数
LightDistrictRechargeCount *int64 `bson:"lightDistrictRechargeCount,omitempty"` // 轻量渠道充值次数
LightNormalRechargeCount *int64 `bson:"lightNormalRechargeCount,omitempty"` // 轻量自来充值次数
// 轻量充值钱数
LightRechargeAmount *int64 `bson:"lightRechargeAmount,omitempty"` // 当日轻量充值钱数
LightDirectRechargeAmount *int64 `bson:"lightDirectRechargeAmount,omitempty"` // 轻量直推充值钱数
LightFissionRechargeAmount *int64 `bson:"lightFissionRechargeAmount,omitempty"` // 轻量裂变充值钱数
LightDeductionRechargeAmount *int64 `bson:"lightDeductionRechargeAmount,omitempty"` // 轻量扣量充值钱数
LightNaturalRechargeAmount *int64 `bson:"lightNaturalRechargeAmount,omitempty"` // 轻量自然充值钱数
LightWebRechargeAmount *int64 `bson:"lightWebRechargeAmount,omitempty"` // 轻量官网充值钱数
LightDistrictRechargeAmount *int64 `bson:"lightDistrictRechargeAmount,omitempty"` // 轻量渠道充值钱数
LightNormalRechargeAmount *int64 `bson:"lightNormalRechargeAmount,omitempty"` // 轻量自来充值钱数
// 其他充值
VipPayByMoney *int64 `bson:"vipPayByMoney,omitempty"` // 人民币购买
VipPayByAmount *int64 `bson:"vipPayByAmount,omitempty"` // 余额购买
RepeatAmount *int64 `bson:"repeatAmount,omitempty"` // 复冲金额
RepeatCount *int64 `bson:"repeatCount,omitempty"` // 复冲人数
// 游戏充值
GameRechageAmount *int64 `bson:"gameRechageAmount,omitempty"` // 游戏充值
GameWithdrawAmount *int64 `bson:"gameWithdrawAmount,omitempty"` // 游戏提现
//
TodayVipRecharge *int64 `bson:"todayVipRecharge,omitempty"` // 当日渠道充值新增
NewVipPayMoney *int64 `bson:"newVipPayMoney,omitempty"` // 新增购买VIP
RepeatVipMoney *int64 `bson:"repeatVipMoney,omitempty"` // 复冲VIP
// 新增充值
NewRechargeAmount *int64 `bson:"newRechargeAmount,omitempty"` // 新增充值金额(新用户)
NewRechargeCount *int64 `bson:"newRechargeCount,omitempty"` // 新增充值数(新用户)
// 留存率
Day1RetainRate *float64 `bson:"day1RetainRate,omitempty"` // 次日留存率
Day3RetainRate *float64 `bson:"day3RetainRate,omitempty"` // 3日留存率
Day7RetainRate *float64 `bson:"day7RetainRate,omitempty"` // 7日留存率
// 订单
TotalRechargeOrder *int64 `bson:"totalRechargeOrder,omitempty"` // 拉起订单数
}
+115
View File
@@ -0,0 +1,115 @@
package domainmod
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"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, CollDomainCheck)
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: "name", Value: 1},
},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{
{Key: "category", Value: 1},
},
},
{
Keys: bson.D{
{Key: "Domainus", Value: 1},
},
},
{
Keys: bson.D{
{Key: "checkTime", Value: 1},
},
},
{
Keys: bson.D{
{Key: "createdAt", Value: 1},
},
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollDomainCheck, err))
}
}
// CountDomains 统计数量
func CountDomains(ctx context.Context, filter bson.M) (int64, error) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("downloadDomain CountDomains db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// InsertOneDomain 插入一个
func InsertOneDomain(ctx context.Context, media *Domain) error {
if _, err := db.InsertOne(ctx, media); err != nil {
log.Warn("downloadDomain:InsertOneDomain db.InsertOne failed", log.E(err))
return err
}
return nil
}
// FindOneDomain 查找一个
func FindOneDomain(ctx context.Context, filter bson.M) (*Domain, error) {
var Domain Domain
if err := db.FindOneEx(ctx, &Domain, filter); err != nil {
log.Warn("downloadDomain:FindOneDomainEx db.FindOneEx failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &Domain, nil
}
// DelOneDomain 删除一个
func DelOneDomain(ctx context.Context, filter bson.M) (int64, error) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("downloadDomain:DelOneDomain db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateOneDomain 更新一个
func UpdateOneDomain(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("downloadDomain:UpdateOneDomain db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// FindManyDomain 查找一批
func FindManyDomain(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (DomainList, error) {
data := make(DomainList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("downloadDomain:FindManyDomain db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
+164
View File
@@ -0,0 +1,164 @@
package domainmod
import (
"stat/common/mongos"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// 表名
const CollDomainCheck = "domain"
var db *mongos.MongoTool
type Category int32
const (
CategoryNone Category = 0 // 无分类
CategoryAPI Category = 1 // API接口
CategoryWeb Category = 2 // 网站
CategoryLand Category = 3 // 落地页
CategoryH5 Category = 4 // H5页面
CategoryDown Category = 5 // 文件下载
CategoryImage Category = 6 // 图片下载
CategoryVideo Category = 7 // 视频播放
CategoryJump Category = 8 // 跳转域名
CategoryLight Category = 9 // 轻量版域名
)
type CheckType int32
const (
CheckTypeNone CheckType = 0 // 占位符,无意义
CheckTypeWeb CheckType = 1 // 网站检测
CheckTypeDNS CheckType = 2 // DNS检测
CheckTypePing CheckType = 3 // Ping检测
CheckTypeHijack CheckType = 4 // 劫持检测
CheckTypePollute CheckType = 5 // 污染检测
CheckTypeQQ CheckType = 6 // QQ拦截检测
CheckTypeWeChat CheckType = 7 // 微信拦截检测
CheckTypeBlack CheckType = 8 // 域名黑名单检测
CheckTypeGFW CheckType = 9 // 被墙检测
)
func (c CheckType) Name() string {
switch c {
case CheckTypeNone:
return "无检测"
case CheckTypeWeb:
return "网站检测"
case CheckTypeDNS:
return "DNS检测"
case CheckTypePing:
return "PING检测"
case CheckTypeHijack:
return "劫持检测"
case CheckTypePollute:
return "污染检测"
case CheckTypeQQ:
return "QQ拦截"
case CheckTypeWeChat:
return "微信拦截"
case CheckTypeBlack:
return "域名黑名单"
case CheckTypeGFW:
return "被墙检测"
default:
return "未知检测"
}
}
func GetCheckTypes() []CheckType {
return []CheckType{CheckTypeWeb, CheckTypeDNS, CheckTypePing, CheckTypeHijack, CheckTypePollute, CheckTypeQQ, CheckTypeWeChat, CheckTypeBlack, CheckTypeGFW}
}
type CheckStatus int32
const (
CheckStatusNone CheckStatus = 0 // 超时跳过
CheckStatusChecking CheckStatus = 1 // 正在检测
CheckStatusSucc CheckStatus = 2 // 完全通过
CheckStatusFailed CheckStatus = 3 // 没有通过
CheckStatusPartPass CheckStatus = 4 // 部分通过
)
func (v CheckStatus) String() string {
switch v {
case CheckStatusNone:
return "超时跳过"
case CheckStatusChecking:
return "正在检测"
case CheckStatusSucc:
return "完全通过"
case CheckStatusFailed:
return "没有通过"
case CheckStatusPartPass:
return "部分通过"
default:
return "未知状态"
}
}
type CheckResult struct {
Domain string `json:"domain" bson:"domain"`
CheckType CheckType `json:"checkType" bson:"checkType"`
NodeCount int `json:"nodeCount" bson:"nodeCount"`
SuccCount int `json:"succCount" bson:"succCount"`
FailedCount int `json:"failedCount" bson:"failedCount"`
NodeErrors []string `json:"nodeErrors" bson:"nodeErrors"`
SuccRate float64 `json:"succRate" bson:"succRate"`
MinRate float64 `json:"minRate" bson:"minRate"`
BeginTime time.Time `json:"beginTime" bson:"beginTime"`
EndTime time.Time `json:"endTime" bson:"endTime"`
CheckSucc bool `json:"checkSucc" bson:"checkSucc"` // 只有检测成功时,检测结果才有意义
ErrorMessage string `json:"errorMessage" bson:"errorMessage"`
Error error `json:"-" bson:"-"`
}
type CheckResultList []*CheckResult
type Domain struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
Name string `json:"name" bson:"name" binding:"required"` // 域名
AppId int32 `json:"appId" bson:"appId"` // AppId
AppName string `json:"appName" bson:"-"` // AppName
Comment string `json:"comment" bson:"comment"` // 备注
Category Category `json:"category" bson:"category"` // 分类
Status CheckStatus `json:"status" bson:"status"` // 状态
Checks []CheckType `json:"checks" bson:"checks"` // 检测方式
Redirected bool `json:"redirected" bson:"redirected"` // 是否已做301跳转
RedirectDomain string `json:"redirectDomain" bson:"redirectDomain"` // 重定向域名
MaxNodes int32 `json:"maxNodes" bson:"maxNodes"` // 最大测试节点数
MinRate float64 `json:"minRate" bson:"minRate"` // 最低检测成功率(成功率低于这个值视为失败)
Report string `json:"report" bson:"report"` // 检测报告
Results CheckResultList `json:"results" bson:"results"` // 检测结果
Enable bool `json:"enable" bson:"enable"` // 是否启用
CheckTime time.Time `json:"checkTime" bson:"checkTime"` // 检测时间
CycleHour int64 `json:"cycleHour" bson:"cycleHour"` // 间隔多少小时检测一次
CheckFinish time.Time `json:"checkFinish" bson:"checkFinish"` // 检测完成时间
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
}
type DomainList []*Domain
type DomainDoc struct {
Name *string `json:"name" bson:"name,omitempty"` // 域名
AppId *int32 `json:"appId" bson:"appId,omitempty"` // AppId
Comment *string `json:"comment" bson:"comment,omitempty"` // 备注
Category *Category `json:"category" bson:"category,omitempty"` // 分类
Status *CheckStatus `json:"status" bson:"status,omitempty"` // 状态
Checks *[]CheckType `json:"checks" bson:"checks,omitempty"` // 检测方式
Redirected *bool `json:"redirected" bson:"redirected,omitempty"` // 是否已做301跳转
RedirectDomain *string `json:"redirectDomain" bson:"redirectDomain,omitempty"` // 重定向域名
MinRate *float64 `json:"minRate" bson:"minRate,omitempty"` // 最低检测成功率(成功率低于这个值视为失败)
Report *string `json:"report" bson:"report,omitempty"` // 检测报告
Results *CheckResultList `json:"results" bson:"results,omitempty"` // 检测结果
Enable *bool `json:"enable" bson:"enable,omitempty"` // 是否启用
CycleHour *int64 `json:"cycleHour" bson:"cycleHour,omitempty"` // 间隔多少小时检测一次
CheckTime *time.Time `json:"checkTime" bson:"checkTime,omitempty"` // 检测时间
CheckFinish *time.Time `json:"checkFinish" bson:"checkFinish,omitempty"` // 检测完成时间
UpdatedAt *time.Time `json:"updatedAt" bson:"updatedAt,omitempty"` // 更新时间
}
+73
View File
@@ -0,0 +1,73 @@
package downloadCpc
import (
"context"
"fmt"
"time"
"stat/common/log"
"stat/common/mongos"
"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, CollLandingPageCPC)
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: "appId", Value: 1}},
},
{
Keys: bson.D{{Key: "createdAt", Value: 1}},
},
{
Keys: bson.D{
{Key: "appId", Value: 1},
{Key: "createdAt", Value: 1},
},
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollLandingPageCPC, err))
}
}
// 插入InsertDownloadInfo 商区记录
func InsertDownloadInfo(ctx context.Context, model *DownloadCpc) (err error) {
_, err = db.InsertOne(ctx, model)
return
}
// 插入InsertDownloadInfoMany 商区记录
func InsertDownloadInfoMany(ctx context.Context, docs []interface{}) (err error) {
_, err = db.GetCollection().InsertMany(ctx, docs)
return
}
// FindManyDownloadCpc 查找一批
func FindManyDownloadCpc(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (DownloadCpcList, error) {
data := make(DownloadCpcList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("FindManyDownloadCpc db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
// 根据appId 获取appInfo
func GetAccessCountByTime(ctx context.Context, appid int32, start, end time.Time) ([]DownloadCpc, error) {
filter := bson.M{"appId": appid, "createdAt": bson.M{"$gte": start, "$lt": end}}
results := make([]DownloadCpc, 0)
if err := db.Find(ctx, &results, filter); err != nil {
log.Error("GetAccessUserByTime FindOne err", log.Any("start", start), log.Any("end", end), log.E(err))
return nil, err
}
return results, nil
}
+26
View File
@@ -0,0 +1,26 @@
package downloadCpc
import (
"stat/common/mongos"
"time"
)
// 表名
const CollLandingPageCPC = "landingpage_cpc"
var db *mongos.MongoTool
type DownloadCpc struct {
AppId int32 `json:"appId" bson:"appId"` // appId
PC string `json:"pc" bson:"pc"` //推广码
DC string `json:"dc" bson:"dc"` //商区序列
CH string `json:"ch" bson:"ch"` //渠道
IP string `json:"ip" bson:"ip"` //用户IP
DevType string `json:"devType" bson:"devType"` //设备类型
SysType string `json:"sysType" bson:"sysType"` //系统类型
PeerIP string `json:"peerIP" bson:"peerIP"` // 网站IP
CreatedAt time.Time `bson:"createdAt"` // 创建时间
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
}
type DownloadCpcList []*DownloadCpc
+136
View File
@@ -0,0 +1,136 @@
package downloadinfo
import (
"context"
"fmt"
"time"
"stat/common/log"
"stat/common/mongos"
"stat/common/utils"
"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, CollLandingPage)
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: "ip", Value: 1},
{Key: "appId", Value: 1},
{Key: "sysType", Value: 1},
},
},
{
Keys: bson.D{
{Key: "ip", Value: 1},
{Key: "appId", Value: 1},
{Key: "sysType", Value: 1},
{Key: "createdAt", Value: 1},
},
},
{
Keys: bson.D{{Key: "createdAt", Value: 1}},
Options: options.Index().SetExpireAfterSeconds(5 * 24 * 60 * 60),
},
{
Keys: bson.D{
{Key: "appId", Value: 1},
{Key: "createdAt", Value: 1},
{Key: "dc", Value: 1},
},
},
{
Keys: bson.D{
{Key: "ip", Value: 1},
{Key: "appId", Value: 1},
{Key: "createdAt", Value: -1},
},
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollLandingPage, err))
}
}
// 插入InsertDownloadInfo 商区记录
func InsertDownloadInfo(ctx context.Context, model *DownloadInfoModel) (err error) {
_, err = db.InsertOne(ctx, model)
return
}
// 插入InsertDownloadInfoMany 商区记录
func InsertDownloadInfoMany(ctx context.Context, docs []interface{}) (err error) {
_, err = db.GetCollection().InsertMany(ctx, docs)
return
}
// FindManyDownloadInfo 查找一批
func FindManyDownloadInfo(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (DownloadInfoList, error) {
data := make(DownloadInfoList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("FindManyDownloadInfo db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
// FindOneChannelIP 根据IP查询渠道信息
func FindOneChannelIP(ctx context.Context, appId int32, ip string, sysType string) (data DownloadInfoModel, err error) {
opts := options.FindOne()
opts.SetSort(bson.D{{Key: "createdAt", Value: -1}})
createAt := utils.BeginOfToday().AddDate(0, 0, -2)
err = db.FindOne(ctx, &data, bson.M{"ip": ip, "appId": appId, "createdAt": bson.M{"$gt": createAt}}, opts)
if err != nil {
log.Error("channel get TrackInfo FindOneChannelIP err", log.E(err))
return
}
return
}
// FindOneChannelUserAgent 根据最近30分钟查询渠道信息
func FindOneChannelUserAgent(ctx context.Context, appId int32, userAgent string) (data DownloadInfoModel, err error) {
opts := options.FindOne()
opts.SetSort(bson.D{{Key: "createdAt", Value: -1}})
createAt := utils.BeginOfToday().Add(-30 * time.Minute)
err = db.FindOne(ctx, &data, bson.M{"userAgent": userAgent, "appId": appId, "createdAt": bson.M{"$gt": createAt}}, opts)
if err != nil {
log.Error("channel get TrackInfo FindOneChannelUserAgent err", log.E(err))
return
}
return
}
// 根据appId 获取appInfo
func GetAccessCountByTime(ctx context.Context, appid int32, start, end time.Time) ([]DownloadInfoModel, error) {
filter := bson.M{"appId": appid, "createdAt": bson.M{"$gte": start, "$lt": end}}
results := make([]DownloadInfoModel, 0)
if err := db.Find(ctx, &results, filter); err != nil {
log.Error("GetAccessUserByTime FindOne err", log.Any("start", start), log.Any("end", end), log.E(err))
return nil, err
}
return results, nil
}
func GetChannelDownloadPageListByTime(ctx context.Context, channel string, appid int32, start, end time.Time) ([]*DownloadInfoModel, error) {
filter := bson.M{
"appId": appid,
"createdAt": bson.M{"$gte": start, "$lt": end},
"dc": channel,
}
results := make([]*DownloadInfoModel, 0)
if err := db.Find(ctx, &results, filter); err != nil {
log.Error("GetChannelDownloadPageListByTime FindOne err", log.Any("start", start), log.Any("end", end), log.E(err))
return nil, err
}
return results, nil
}
+33
View File
@@ -0,0 +1,33 @@
package downloadinfo
import (
"stat/common/mongos"
"stat/models/versionMod"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// 表名
const CollLandingPage = "landingpage_log"
var db *mongos.MongoTool
type DownloadInfoModel struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
AppId int32 `bson:"appId"` // appId
PC string `json:"pc" bson:"pc"` // 推广码
DC string `json:"dc" bson:"dc"` // 商区序列
CH string `json:"ch" bson:"ch"` // 渠道
IP string `json:"ip" bson:"ip"` // 用户IP
Domain string `from:"domain" json:"domain"` // 落地页域名
DevType string `json:"devType" bson:"devType"` // 设备类型
SysType string `json:"sysType" bson:"sysType"` // 系统类型
PeerIP string `json:"peerIP" bson:"peerIP"` // 网站IP
PackageType versionMod.PkgType `from:"packageType" json:"packageType"` // 包类型 1:企业包 2:商店包 3:TF包
UserAgent string `json:"userAgent" bson:"userAgent"` // User-Agent识别
CreatedAt time.Time `bson:"createdAt"` // 创建时间
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
}
type DownloadInfoList []*DownloadInfoModel
+129
View File
@@ -0,0 +1,129 @@
package downloadstat
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
// 初始化model
func Init() {
// 获取数据库表
db = mongos.New(mongos.MgoManager, CollDownloadStat)
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: "appId", Value: 1},
{Key: "type", Value: 1},
{Key: "sumDate", Value: 1},
},
Options: options.Index().SetUnique(true),
},
{
Keys: bson.D{
{Key: "type", Value: 1},
{Key: "sumDate", Value: 1},
},
},
{
Keys: bson.D{
{Key: "type", Value: 1},
},
},
{
Keys: bson.D{
{Key: "hour", Value: 1},
},
},
{
Keys: bson.D{
{Key: "createdAt", Value: 1},
},
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollDownloadStat, err))
}
}
// CountStats 统计数量
func CountStats(ctx context.Context, filter bson.M) (int64, error) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("downloadStat CountStats db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// InsertOneStat 插入一个
func InsertOneStat(ctx context.Context, media *Stat) error {
if _, err := db.InsertOne(ctx, media); err != nil {
log.Warn("downloadStat:InsertOneStat db.InsertOne failed", log.E(err))
return err
}
return nil
}
// FindOneStat 查找一个
func FindOneStat(ctx context.Context, filter bson.M) (*Stat, error) {
var stat Stat
if err := db.FindOneEx(ctx, &stat, filter); err != nil {
log.Warn("downloadStat:FindOneStatEx db.FindOneEx failed",
log.E(err), log.Any("filter", filter))
return nil, err
}
return &stat, nil
}
// DelOneStat 删除一个
func DelOneStat(ctx context.Context, filter bson.M) (int64, error) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("downloadStat:DelOneStat db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateOneStat 更新一个
func UpdateOneStat(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("downloadStat:UpdateOneStat db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// FindManyStat 查找一批
func FindManyStat(ctx context.Context, filter bson.M, opts ...*options.FindOptions) (StatList, error) {
data := make(StatList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("downloadStat:FindManyStat db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
// AggregateStats 聚合查找一批机器人小时统计信息
func AggregateStats(ctx context.Context, bind interface{}, pipeline []bson.M) error {
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("downloadStat:FindManyStat db.Aggregate failed",
log.E(err), log.Any("pipeline", pipeline))
return err
}
return nil
}
+10
View File
@@ -0,0 +1,10 @@
package downloadstat
func StatSummation(base, value *Stat) {
base.VisitTotal += value.VisitTotal
base.VisitUnique += value.VisitUnique
base.DownTotal += value.DownTotal
base.DownUnique += value.DownUnique
base.InstallTotal += value.InstallTotal
base.InstallUnique += value.InstallUnique
}
+58
View File
@@ -0,0 +1,58 @@
package downloadstat
import (
"stat/common/mongos"
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// 表名
const CollDownloadStat = "download_stat"
var db *mongos.MongoTool
type StatType int32
const (
StatTypeNone StatType = 0
StatTypeDaily StatType = 1
StatTypeHour StatType = 2
)
type Stat struct {
ID primitive.ObjectID `json:"id" bson:"_id,omitempty"`
AppId int32 `json:"appId" bson:"appId"`
AppName string `json:"appName" bson:"appName,omitempty"`
SumDate time.Time `json:"sumDate" bson:"sumDate"` // 日期
EndDate time.Time `json:"endDate" bson:"endDate"` // 这个不展示
Hour int `json:"hour" bson:"hour"` // 小时统计展示,每日统计不展示
Type StatType `json:"type" bson:"type"` // 这个不展示
VisitTotal int64 `json:"visitCount" bson:"visitCount"` // 访问总数
VisitUnique int64 `json:"visitUnique" bson:"visitUnique"` // 去重访问数
DownTotal int64 `json:"downTotal" bson:"downTotal"` // 下载总数
DownUnique int64 `json:"downUnique" bson:"downUnique"` // 去重下载数(IP来自独立访问集合)
InstallTotal int64 `json:"installTotal" bson:"installTotal"` // 安装总数
InstallUnique int64 `json:"installUnique" bson:"installUnique"` // 去重安装数(IP来自下载独立集合)
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
}
type StatDoc struct {
VisitTotal *int64 `json:"visitCount" bson:"visitCount"` // 访问总数
VisitUnique *int64 `json:"visitIpCount" bson:"visitIpCount"` // 访问独立数
DownTotal *int64 `json:"downTotal" bson:"downTotal"` // 下载总数
DownUnique *int64 `json:"downUnique" bson:"downUnique"` // 下载独立数(IP来自访问独立集合)
InstallTotal *int64 `json:"installTotal" bson:"installTotal"` // 安装总数
InstallUnique *int64 `json:"installUnique" bson:"installUnique"` // 安装独立数(IP来自下载独立集合)
UpdatedAt *time.Time `json:"updatedAt" bson:"updatedAt"`
}
type StatList []*Stat
+110
View File
@@ -0,0 +1,110 @@
package models
import (
"context"
"stat/models/accessmod"
"stat/models/activityVisit"
"stat/models/activitymod"
"stat/models/adminMod"
"stat/models/advertiseLocMod"
"stat/models/advertiseMod"
"stat/models/advertisestat"
"stat/models/announInfoMod"
"stat/models/appInfoMod"
"stat/models/appcategory"
"stat/models/applicationLocMod"
"stat/models/applicationmod"
"stat/models/applicationstat"
"stat/models/authorityMod"
"stat/models/blocDailystatmod"
"stat/models/botdailyhourstat"
"stat/models/botreport"
"stat/models/channelCodeBlocStatMod"
"stat/models/channelmod"
"stat/models/channelpackage"
"stat/models/channelsettlementrecord"
"stat/models/dailyhourstatmod"
"stat/models/dailystatadvertise"
"stat/models/dailystatmod"
"stat/models/domainmod"
"stat/models/downloadCpc"
downloadinfo "stat/models/downloadinfo"
"stat/models/downloadstat"
"stat/models/landPageConfig"
"stat/models/landingPage"
"stat/models/landpageImg"
"stat/models/mediatag"
"stat/models/minutestatmod"
"stat/models/monitormod"
"stat/models/opLogMod"
"stat/models/rechargechannelmod"
"stat/models/rechargegamemod"
"stat/models/rechargemod"
"stat/models/registermod"
statrecordmod "stat/models/statrecord"
"stat/models/syncgamerecharge"
"stat/models/syncgamewater"
"stat/models/syncrecharge"
"stat/models/syncrecord"
"stat/models/syncvip"
"stat/models/syncwithdraw"
"stat/models/tfpackagemod"
"stat/models/versionMod"
"stat/models/withdrawGameOrdermod"
"stat/models/withdrawUserOrdermod"
)
// 初始化数据库表
func InitIndex() {
ctx := context.Background()
appInfoMod.Init()
authorityMod.Init()
adminMod.Init()
rechargemod.Init()
accessmod.Init()
registermod.Init()
channelmod.Init()
statrecordmod.Init()
dailystatmod.Init()
minutestatmod.Init()
opLogMod.Init()
landingPage.Init()
advertiseMod.Init()
advertiseLocMod.Init()
advertisestat.Init()
versionMod.Init()
downloadinfo.Init()
downloadstat.Init()
announInfoMod.Init()
downloadCpc.Init()
domainmod.Init()
blocDailystatmod.Init()
withdrawUserOrdermod.Init()
rechargechannelmod.Init()
channelCodeBlocStatMod.Init()
syncrecord.Init()
syncwithdraw.Init(ctx)
tfpackagemod.Init(ctx)
syncvip.Init(ctx)
syncrecharge.Init(ctx)
landpageImg.Init(ctx)
mediatag.Init(ctx)
dailyhourstatmod.Init(ctx)
activitymod.Init()
withdrawGameOrdermod.Init()
rechargegamemod.Init()
syncgamerecharge.Init(ctx)
botreport.Init(ctx)
botdailyhourstat.Init(ctx)
dailystatadvertise.Init(ctx)
syncgamewater.Init(ctx)
channelsettlementrecord.Init(ctx)
landPageConfig.Init(ctx)
monitormod.Init(ctx)
activityVisit.Init()
applicationmod.Init(ctx)
appcategory.Init(ctx)
applicationstat.Init(ctx)
applicationLocMod.Init(ctx)
channelpackage.Init(ctx)
}
+126
View File
@@ -0,0 +1,126 @@
package landPageConfig
import (
"context"
"fmt"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"stat/common/log"
"stat/common/mongos"
)
var db *mongos.MongoTool
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.New(mongos.MgoManager, TN.LandPageConfig)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.LandPageConfig.Id, Value: 1},
},
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(LandPageConfig:initLandPageConfigIndex) Create LandPageConfig Index failed! err:%+v:", err))
}
}
//InsertOneLandPageConfig 插入一个视频标签
func InsertOneLandPageConfig(ctx context.Context, LandPageConfig *LandPageConfig) error {
if _, err := db.InsertOne(ctx, LandPageConfig); err != nil {
log.Warn("LandPageConfig:InsertOneLandPageConfig db.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneLandPageConfig 查找一个视频标签
func FindOneLandPageConfig(ctx context.Context, filter bson.M) (
*LandPageConfig, error) {
var LandPageConfig LandPageConfig
if err := db.FindOne(ctx, &LandPageConfig, filter); err != nil {
return nil, err
}
return &LandPageConfig, nil
}
//DelOneLandPageConfig 删除一个视频标签
func DelOneLandPageConfig(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("LandPageConfig:DelOneLandPageConfig db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateOneLandPageConfig 更新一个视频标签
func UpdateOneLandPageConfig(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateOneLandPageConfig db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//CountLandPageConfigs 统计视频标签数量
func CountLandPageConfigs(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("LandPageConfig:CountLandPageConfigs db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateManyLandPageConfig 更新满足条件的视频标签
func UpdateManyLandPageConfig(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyLandPageConfig db.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//FindManyLandPageConfig 查找一批视频标签数据
func FindManyLandPageConfig(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (LandPageConfigList, error) {
data := make(LandPageConfigList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("LandPageConfig:FindManyLandPageConfig db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
//FindManyLandPageConfigWithBind 用自己定义结构查找一批视频标签数据
func FindManyLandPageConfigWithBind(ctx context.Context, bind interface{}, filter bson.M,
opts ...*options.FindOptions) error {
if err := db.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("LandPageConfig:FindManyLandPageConfigWithBind db.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//AggregateLandPageConfigs 聚合查找一批视频标签信息
func AggregateLandPageConfigs(ctx context.Context,
bind interface{}, pipeline []bson.M) error {
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("feedback:AggregateLandPageConfigs db.Aggregate failed",
log.E(err), log.Any("pipeline", pipeline))
return err
}
return nil
}
+44
View File
@@ -0,0 +1,44 @@
package landPageConfig
type TagLandPageConfig struct {
Actor string
AddedTime string
AppId string
Bango string
CreateAt string
Desc string
Id string
LandPageType string
Media string
Picture string
Rank string
Status string
Title string
UpdateAt string
}
var FN struct {
LandPageConfig TagLandPageConfig
}
var TN struct {
LandPageConfig string
}
func init() {
FN.LandPageConfig.Actor = "actor"
FN.LandPageConfig.AddedTime = "addedTime"
FN.LandPageConfig.AppId = "appId"
FN.LandPageConfig.Bango = "bango"
FN.LandPageConfig.CreateAt = "createAt"
FN.LandPageConfig.Desc = "desc"
FN.LandPageConfig.Id = "_id"
FN.LandPageConfig.LandPageType = "landPageType"
FN.LandPageConfig.Media = "media"
FN.LandPageConfig.Picture = "picture"
FN.LandPageConfig.Rank = "rank"
FN.LandPageConfig.Status = "status"
FN.LandPageConfig.Title = "title"
FN.LandPageConfig.UpdateAt = "updateAt"
TN.LandPageConfig = "landPageConfig"
}
+26
View File
@@ -0,0 +1,26 @@
package landPageConfig
import (
"time"
)
// 落地页配置
// @table:landPageConfig
type LandPageConfig struct {
Id int64 `json:"id" bson:"_id"`
AppId int32 `json:"appId" bson:"appId"` //appId
LandPageType int8 `json:"landPageType" bson:"landPageType"` //类型,1PC端,2移动端
Title string `json:"title" bson:"title"` //主题
Desc string `json:"desc" bson:"desc"` //描述
Actor string `json:"actor" bson:"actor"` //演员
Bango string `json:"bango" bson:"bango"` //番号,唯一
AddedTime time.Time `json:"addedTime" bson:"addedTime"` //上架时间(审核通过时间)
Picture string `json:"picture" bson:"picture"` //图片
Media string `json:"media" bson:"media"` //视频
Rank int64 `json:"rank" bson:"rank"` //排序
Status bool `json:"status" bson:"status"` //状态
CreateAt time.Time `json:"createAt" bson:"createAt"` //创建时间
UpdateAt time.Time `json:"updateAt" bson:"updateAt"` //更新时间
}
type LandPageConfigList []*LandPageConfig
+158
View File
@@ -0,0 +1,158 @@
package landingPage
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"stat/common/utils"
"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, CollLandingPage)
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: "appId", Value: 1}},
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("%s model set index err ==>[%+v]", CollLandingPage, err))
}
}
// FindLandingPageList 获取渠道转账列表
func FindLandingPageList(ctx context.Context, appid int32, skip, limit int64) (count int64, data []LandingPage, err error) {
filter := bson.M{"appId": appid}
sort := bson.D{{Key: "status", Value: -1}, {Key: "createdAt", Value: -1}}
opts := options.Find().SetSort(sort).SetSkip(skip).SetLimit(limit)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("LandingPage FindLandingPageList Find err", log.E(err))
return
}
if count, err = db.Count(ctx, filter); err != nil {
log.Error("LandingPage FindLandingPageList Count err", log.E(err))
return
}
return
}
// AddLandingPage 添加落地页请求
func AddLandingPage(ctx context.Context, doc *LandingPage) (id string, err error) {
if id, err = db.InsertOne(ctx, doc); err != nil {
log.Error("LandingPage AddLandingPage InsertOne err", log.E(err))
return
}
return
}
// FindLandingPage 查询订单
func FindLandingPage(ctx context.Context, id int64) (w LandingPage, err error) {
var filter = bson.M{"_id": id}
if err = db.FindOne(ctx, &w, filter); err != nil {
log.Error("LandingPage FindLandingPage FindOne err", log.E(err))
return
}
return
}
// UpdateLandingPage 更新落地页成功
func UpdateLandingPage(ctx context.Context, id int64, doc UpdateDoc) (err error) {
var filter = bson.M{"_id": id}
update, _ := utils.ToBsonM(doc)
if _, err = db.UpdateOne(ctx, filter, bson.M{"$set": update}); err != nil {
log.Error("LandingPage UpdateLandingPageSuccess UpdateOne err", log.E(err))
return
}
return
}
// DelLandingPage 删除落地页
func DelLandingPage(ctx context.Context, id int64) (err error) {
filter := bson.M{"_id": id}
if _, err = db.DeleteOne(ctx, filter); err != nil {
log.Error("LandingPage DelLandingpage DeleteOne err", log.E(err))
return
}
return
}
// FindChannelCodeLandingPage 根据 app 获取落地页
func FindChannelCodeLandingPage(ctx context.Context, appIds []int32) (data []LandingPage, err error) {
if len(appIds) == 0 {
return
}
filter := bson.M{"appId": bson.M{"$in": appIds}, "status": true, "type": 1}
if err = db.Find(ctx, &data, filter); err != nil {
log.Error("LandingPage FindLandingPageByAppsId Find err", log.E(err))
return
}
return
}
// FindShareLandingPage 根据 app 获取落地页
func FindShareLandingPage(ctx context.Context, appId int32) (data []LandingPage, err error) {
filter := bson.M{"appId": appId, "status": true, "type": 2}
if err = db.Find(ctx, &data, filter); err != nil {
log.Error("LandingPage FindLandingPageByAppsId Find err", log.E(err))
return
}
return
}
// FindAllLandingPage 获取所有落地页
func FindAllLandingPage(ctx context.Context) (data []LandingPage, err error) {
filter := bson.M{"status": true}
sort := bson.D{{Key: "createdAt", Value: -1}}
opts := options.Find().SetSort(sort)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("LandingPage FindAllLandingPage Find err", log.E(err))
return
}
return
}
// FindChannelLandingPage 获取配置渠道的落地页
func FindChannelLandingPage(ctx context.Context) (data []LandingPage, err error) {
filter := bson.M{"channelCode": bson.M{"$gt": ""}}
sort := bson.D{{Key: "createdAt", Value: -1}}
opts := options.Find().SetSort(sort)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("LandingPage FindChannelLandingPage Find err", log.E(err))
return
}
return
}
+33
View File
@@ -0,0 +1,33 @@
package landingPage
import (
"stat/common/mongos"
"time"
)
// 表名
const CollLandingPage = "landing_page"
var db *mongos.MongoTool
// LandingPage 落地页管理
type LandingPage struct {
ID int64 `bson:"_id"` //落地页
AppId int32 `bson:"appId"` //appId
Url string `bson:"url"` //url
Status bool `bson:"status,omitempty"` //状态 默认true
ChannelCode string `bson:"channelCode,omitempty"` //渠道
Remark string `bson:"remark"` //备注
Type int32 `form:"type" json:"type"` //类型 1:渠道 2:分享
CreatedAt time.Time `bson:"createdAt,omitempty"` //申请时间
UpdatedAt time.Time `bson:"updatedAt,omitempty"` //更新时间
}
type UpdateDoc struct {
Url *string `bson:"url,omitempty"` //url
Status *bool `bson:"status,omitempty"` //状态 默认true
Remark *string `bson:"remark,omitempty"` //备注
ChannelCode *string `bson:"channelCode,omitempty"` //渠道
Type *int32 `form:"type" json:"type"` //类型 1:渠道 2:分享
UpdatedAt *time.Time `bson:"updatedAt,omitempty"` //更新时间
}
+127
View File
@@ -0,0 +1,127 @@
package landpageImg
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var db *mongos.MongoTool
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.New(mongos.MgoManager, TN.LandpageImg)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.LandpageImg.Name, Value: 1},
},
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(LandpageImg:initLandpageImgIndex) Create LandpageImg Index failed! err:%+v:", err))
}
}
//InsertOneLandpageImg 插入一个落地页资源配置
func InsertOneLandpageImg(ctx context.Context, LandpageImg *LandpageImg) error {
if _, err := db.InsertOne(ctx, LandpageImg); err != nil {
log.Warn("LandpageImg:InsertOneLandpageImg db.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneLandpageImg 查找一个落地页资源配置
func FindOneLandpageImg(ctx context.Context, filter bson.M) (
*LandpageImg, error) {
var LandpageImg LandpageImg
if err := db.FindOne(ctx, &LandpageImg, filter); err != nil {
return nil, err
}
return &LandpageImg, nil
}
//DelOneLandpageImg 删除一个落地页资源配置
func DelOneLandpageImg(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("LandpageImg:DelOneLandpageImg db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateOneLandpageImg 更新一个落地页资源配置
func UpdateOneLandpageImg(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateOneLandpageImg db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//CountLandpageImgs 统计落地页资源配置数量
func CountLandpageImgs(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("LandpageImg:CountLandpageImgs db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateManyLandpageImg 更新满足条件的落地页资源配置
func UpdateManyLandpageImg(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyLandpageImg db.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//FindManyLandpageImg 查找一批落地页资源配置数据
func FindManyLandpageImg(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (LandpageImgList, error) {
data := make(LandpageImgList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("LandpageImg:FindManyLandpageImg db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
//FindManyLandpageImgWithBind 用自己定义结构查找一批落地页资源配置数据
func FindManyLandpageImgWithBind(ctx context.Context, bind interface{}, filter bson.M,
opts ...*options.FindOptions) error {
if err := db.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("LandpageImg:FindManyLandpageImgWithBind db.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//AggregateLandpageImgs 聚合查找一批落地页资源配置信息
func AggregateLandpageImgs(ctx context.Context,
bind interface{}, pipeline []bson.M) error {
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("feedback:AggregateLandpageImgs db.Aggregate failed",
log.E(err), log.Any("pipeline", pipeline))
return err
}
return nil
}
+42
View File
@@ -0,0 +1,42 @@
package landpageImg
type TagLandpageImg struct {
CreatedAt string
ID string
MobileAvatar string
MobileBackgroud string
MobileTiltle string
Music string
Name string
PcAvatar string
PcBackgroud string
PcTitle string
Rank string
Status string
UpdatedAt string
}
var FN struct {
LandpageImg TagLandpageImg
}
var TN struct {
LandpageImg string
}
func init() {
FN.LandpageImg.CreatedAt = "createdAt"
FN.LandpageImg.ID = "_id"
FN.LandpageImg.MobileAvatar = "mobileAvatar"
FN.LandpageImg.MobileBackgroud = "mobileBackgroud"
FN.LandpageImg.MobileTiltle = "mobileTiltle"
FN.LandpageImg.Music = "music"
FN.LandpageImg.Name = "name"
FN.LandpageImg.PcAvatar = "pcAvatar"
FN.LandpageImg.PcBackgroud = "pcBackgroud"
FN.LandpageImg.PcTitle = "pcTitle"
FN.LandpageImg.Rank = "rank"
FN.LandpageImg.Status = "status"
FN.LandpageImg.UpdatedAt = "updatedAt"
TN.LandpageImg = "landpage_img"
}
+26
View File
@@ -0,0 +1,26 @@
package landpageImg
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// 帖子模型,数据库中的
// @table:landpage_img
type LandpageImg struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // ID
Name string `json:"name" bson:"name"` // 图片名称
PcAvatar string `json:"pcAvatar" bson:"pcAvatar"` // PC端图片
MobileAvatar string `json:"mobileAvatar" bson:"mobileAvatar"` // 移动端图片
PcBackgroud string `json:"pcBackgroud" bson:"pcBackgroud"` // PC端背景图
MobileBackgroud string `json:"mobileBackgroud" bson:"mobileBackgroud"` // 移动端背景图
PcTitle string `json:"pcTitle" bson:"pcTitle"` // PC端标语
MobileTiltle string `json:"mobileTiltle" bson:"mobileTiltle"` // 移动端标语
Music string `json:"music" bson:"music"` // 音频文件
Rank int64 `json:"rank" bson:"rank"` // 排序
Status bool `json:"status" bson:"status"` // 是否启用
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
CreatedAt time.Time `bson:"createdAt"` // 创建时间
}
type LandpageImgList []*LandpageImg
+127
View File
@@ -0,0 +1,127 @@
package mediatag
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var db *mongos.MongoTool
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.New(mongos.MgoManager, TN.MediaTag)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.MediaTag.Name, Value: 1},
},
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(MediaTag:initMediaTagIndex) Create MediaTag Index failed! err:%+v:", err))
}
}
//InsertOneMediaTag 插入一个视频标签
func InsertOneMediaTag(ctx context.Context, MediaTag *MediaTag) error {
if _, err := db.InsertOne(ctx, MediaTag); err != nil {
log.Warn("MediaTag:InsertOneMediaTag db.InsertOne failed", log.E(err))
return err
}
return nil
}
//FindOneMediaTag 查找一个视频标签
func FindOneMediaTag(ctx context.Context, filter bson.M) (
*MediaTag, error) {
var MediaTag MediaTag
if err := db.FindOne(ctx, &MediaTag, filter); err != nil {
return nil, err
}
return &MediaTag, nil
}
//DelOneMediaTag 删除一个视频标签
func DelOneMediaTag(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("MediaTag:DelOneMediaTag db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateOneMediaTag 更新一个视频标签
func UpdateOneMediaTag(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateOneMediaTag db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//CountMediaTags 统计视频标签数量
func CountMediaTags(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("MediaTag:CountMediaTags db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
//UpdateManyMediaTag 更新满足条件的视频标签
func UpdateManyMediaTag(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyMediaTag db.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//FindManyMediaTag 查找一批视频标签数据
func FindManyMediaTag(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (MediaTagList, error) {
data := make(MediaTagList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("MediaTag:FindManyMediaTag db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
//FindManyMediaTagWithBind 用自己定义结构查找一批视频标签数据
func FindManyMediaTagWithBind(ctx context.Context, bind interface{}, filter bson.M,
opts ...*options.FindOptions) error {
if err := db.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("MediaTag:FindManyMediaTagWithBind db.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
//AggregateMediaTags 聚合查找一批视频标签信息
func AggregateMediaTags(ctx context.Context,
bind interface{}, pipeline []bson.M) error {
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("feedback:AggregateMediaTags db.Aggregate failed",
log.E(err), log.Any("pipeline", pipeline))
return err
}
return nil
}
+30
View File
@@ -0,0 +1,30 @@
package mediatag
type TagMediaTag struct {
CreatedAt string
ID string
Name string
Rank string
Status string
Type string
UpdatedAt string
}
var FN struct {
MediaTag TagMediaTag
}
var TN struct {
MediaTag string
}
func init() {
FN.MediaTag.CreatedAt = "createdAt"
FN.MediaTag.ID = "_id"
FN.MediaTag.Name = "name"
FN.MediaTag.Rank = "rank"
FN.MediaTag.Status = "status"
FN.MediaTag.Type = "type"
FN.MediaTag.UpdatedAt = "updatedAt"
TN.MediaTag = "media_tag"
}
+27
View File
@@ -0,0 +1,27 @@
package mediatag
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
type MediaTagType int32
const (
MediaTagTypeFirst MediaTagType = 1 // 一级
MediaTagTypeSecond MediaTagType = 2 // 二级
)
// 帖子模型,数据库中的
// @table:media_tag
type MediaTag struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // ID
Name string `json:"name" bson:"name"` // 标签名称
Type MediaTagType `json:"type" bson:"type"` // 类别
Rank int64 `json:"rank" bson:"rank"` // 排序
Status bool `json:"status" bson:"status"` // 是否启用
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
CreatedAt time.Time `bson:"createdAt"` // 创建时间
}
type MediaTagList []*MediaTag
+105
View File
@@ -0,0 +1,105 @@
package minutestatmod
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, CollMinuteStat)
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: "sumDate", Value: 1}, {Key: "updatedAt", Value: 1}},
}, {
Keys: bson.D{{Key: "sumDate", Value: 1}, {Key: "appId", Value: 1}},
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollMinuteStat, err))
}
}
func UpsertMinuteStatEx(ctx context.Context,
filter bson.M, update bson.M) error {
if _, err := db.UpsertOneEx(ctx, filter, update); err != nil {
log.Info("minutestatmod:UpsertMinuteStatEx db.InsertOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
func UpsertMinuteDocStat(ctx context.Context, sumDate time.Time, appId int32, update *MinuteStatDoc) error {
now := time.Now()
update.UpdatedAt = &now
filter := bson.M{
"appId": appId,
"sumDate": sumDate,
}
upsertDoc := bson.M{
"$set": update,
"$setOnInsert": filter,
}
if _, err := db.UpsertOneEx(ctx, filter, upsertDoc); err != nil {
log.Info("minutestatmod:UpsertMinuteStatEx db.InsertOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// UpsertDailyStat 更新或插入一条统计记录
func UpsertMinuteStat(ctx context.Context, sumDate time.Time, appId int32, doc MinuteStatDoc) (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 GetMinuteStatList(ctx context.Context, start, end time.Time, appId int32) (data []MinuteStatMod, err error) {
filter := bson.M{"sumDate": bson.M{"$gte": start, "$lt": end}, "appId": appId}
sort := bson.D{{Key: "sumDate", Value: 1}}
opts := options.Find().SetSort(sort)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("minuteStat GetMinuteStatList Find err", log.E(err))
return
}
return
}
+107
View File
@@ -0,0 +1,107 @@
package minutestatmod
import (
"stat/common/mongos"
"time"
)
// 表名
const CollMinuteStat = "minute_stat"
var db *mongos.MongoTool
// MinuteStatMod 实时统计(5分钟数据)
type MinuteStatMod struct {
SumDate time.Time `bson:"sumDate"` // 记录时间
AppId int32 `bson:"appId"` // appId
// 新增
NewCount int64 `bson:"newCount"` // 新增总量
DirectAddCount int64 `bson:"directAddCount"` // 直推新增
FissionAddCount int64 `bson:"fissionAddCount"` // 裂变新增
WebAddCount int64 `bson:"webAddCount"` // 官网新增
DistrictAddCount int64 `bson:"districtAddCount"` // 渠道新增
NormalAddCount int64 `bson:"normalAddCount"` // 自来新增
AndroidAddCount int64 `bson:"androidAddCount"` // android新增
IosAddCount int64 `bson:"iosAddCount"` // ios新增
H5AddCount int64 `bson:"h5AddCount"` // H5新增
H5FormalAddCount int64 `bson:"h5FormalAddCount"` // H5注册新增
LightGuestAddCount int64 `bson:"lightGuestAddCount"` // 轻量安装新增
LightFormalAddCount int64 `bson:"lightFormalAddCount"` // 轻量注册新增
// 充值
RechargetCount int64 `bson:"rechageCount"` // 充值订单
RechargetMoney int64 `bson:"rechageMoney"` // 充值金额
DirectAmount int64 `bson:"directAmount"` // 直推充值金额
FissionAmount int64 `bson:"fissionAmount"` // 裂变充值金额
DistrictRecharge int64 `bson:"districtRecharge"` // 渠道充值新增
WebRecharge int64 `bson:"webRecharge"` // 官网充值新增
NormalRecharge int64 `bson:"normalRecharge"` // 自来量充值新增
AndroidRecharge int64 `bson:"androidRecharge"` // android充值
IosRecharge int64 `bson:"iosRecharge"` // Ios充值
LightRecharge int64 `bson:"lightRecharge"` // 轻量充值
H5Recharge int64 `bson:"h5Recharge"` // H5充值
// 访问
AccessCount int64 `bson:"accessCount"` // 访问量
AndroidAccessCount int64 `bson:"androidAccessCount"` // android访问量
IosAccessCount int64 `bson:"iosAccessCount"` // ios访问量
H5AccessCount int64 `bson:"h5AccessCount"` // H5
LightAccessCount int64 `bson:"lightAccessCount"` // Light访问量
DirectAccessCount int64 `bson:"directAccessCount"` // 直推访问数
FissionAccessCount int64 `bson:"fissionAccessCount"` // 裂变访问数
NaturalAccessCount int64 `bson:"naturalAccessCount"` // 自然访问数
DistrictAccessCount int64 `bson:"districtAccessCount"` // 渠道访问量
WebAccessCount int64 `bson:"webAccessCount"` // 官网访问量
NormalAccessCount int64 `bson:"normalAccessCount"` // 自来访问量
// 落地页
LandpageAndroidClick int64 `bson:"landpageAndroidClick"` // 落地页android访问次数
LandpageIosAppstoreClick int64 `bson:"landpageIosAppstoreClick"` // 落地页iOS商店包访问次数
LandpageIosAthorClick int64 `bson:"landpageIosAthorClick"` // 落地页iOS其他包访问次数
LandpageIosH5Click int64 `bson:"landpageIosH5Click,omitempty"` // 落地页H5访问次数
UpdatedAt time.Time `bson:"updatedAt"` // 更新时间
}
type MinuteStatDoc struct {
// 新增
NewCount *int64 `bson:"newCount,omitempty"` // 新增总量
DirectAddCount *int64 `bson:"directAddCount,omitempty"` // 直推新增
FissionAddCount *int64 `bson:"fissionAddCount,omitempty"` // 裂变新增
WebAddCount *int64 `bson:"webAddCount,omitempty"` // 官网新增
DistrictAddCount *int64 `bson:"districtAddCount,omitempty"` // 渠道新增
NormalAddCount *int64 `bson:"normalAddCount,omitempty"` // 自来新增
AndroidAddCount *int64 `bson:"androidAddCount,omitempty"` // android新增
IosAddCount *int64 `bson:"iosAddCount,omitempty"` // ios新增
H5AddCount *int64 `bson:"h5AddCount,omitempty"` // H5新增
H5FormalAddCount *int64 `bson:"h5FormalAddCount,omitempty"` // H5注册新增
LightGuestAddCount *int64 `bson:"lightGuestAddCount,omitempty"` // 轻量安装新增
LightFormalAddCount *int64 `bson:"lightFormalAddCount,omitempty"` // 轻量注册新增
// 充值
RechargetCount *int64 `bson:"rechageCount,omitempty"` // 充值订单
RechargetMoney *int64 `bson:"rechageMoney,omitempty"` // 充值金额
DirectAmount *int64 `bson:"directAmount,omitempty"` // 直推充值金额
FissionAmount *int64 `bson:"fissionAmount,omitempty"` // 裂变充值金额
DistrictRecharge *int64 `bson:"districtRecharge,omitempty"` // 渠道充值新增
WebRecharge *int64 `bson:"webRecharge,omitempty"` // 官网充值新增
NormalRecharge *int64 `bson:"normalRecharge,omitempty"` // 自来量充值新增
AndroidRecharge *int64 `bson:"androidRecharge,omitempty"` // android充值
IosRecharge *int64 `bson:"iosRecharge,omitempty"` // Ios充值
LightRecharge *int64 `bson:"lightRecharge,omitempty"` // 轻量充值
H5Recharge *int64 `bson:"h5Recharge,omitempty"` // H5充值
// 访问
AccessCount *int64 `bson:"accessCount,omitempty"` // 访问量
AndroidAccessCount *int64 `bson:"androidAccessCount,omitempty"` // android访问量
IosAccessCount *int64 `bson:"iosAccessCount,omitempty"` // ios访问量
H5AccessCount *int64 `bson:"h5AccessCount,omitempty"` // H5
LightAccessCount *int64 `bson:"lightAccessCount,omitempty"` // Light访问量
DirectAccessCount *int64 `bson:"directAccessCount,omitempty"` // 直推访问数
FissionAccessCount *int64 `bson:"fissionAccessCount,omitempty"` // 裂变访问数
NaturalAccessCount *int64 `bson:"naturalAccessCount,omitempty"` // 自然访问数
DistrictAccessCount *int64 `bson:"districtAccessCount,omitempty"` // 渠道访问量
WebAccessCount *int64 `bson:"webAccessCount,omitempty"` // 官网访问量
NormalAccessCount *int64 `bson:"normalAccessCount,omitempty"` // 自来访问量
// 落地页
LandpageAndroidClick *int64 `bson:"landpageAndroidClick,omitempty"` // 落地页android访问次数
LandpageIosAppstoreClick *int64 `bson:"landpageIosAppstoreClick,omitempty"` // 落地页iOS商店包访问次数
LandpageIosAthorClick *int64 `bson:"landpageIosAthorClick,omitempty"` // 落地页iOS其他包访问次数
LandpageIosH5Click *int64 `bson:"landpageIosH5Click,omitempty"` // 落地页H5访问次数
// 时间
UpdatedAt *time.Time `bson:"updatedAt"` // 更新时间
}
+137
View File
@@ -0,0 +1,137 @@
package monitormod
import (
"context"
"fmt"
"stat/common/log"
"stat/common/mongos"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var db *mongos.MongoTool
func Init(ctx context.Context) {
// 获取数据库表
db = mongos.New(mongos.MgoManager, TN.Monitor)
// 初始化索引
indexes := []mongo.IndexModel{
{
Keys: bson.D{
{Key: FN.Monitor.Name, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.Monitor.AppId, Value: 1},
},
},
{
Keys: bson.D{
{Key: FN.Monitor.Status, Value: 1},
},
},
}
if _, err := db.CreateIndex(ctx, indexes); err != nil {
panic(fmt.Sprintf("(Monitor:initMonitorIndex) Create Monitor Index failed! err:%+v:", err))
}
}
// InsertOneMonitor 插入一个应用监控
func InsertOneMonitor(ctx context.Context, Monitor *Monitor) error {
if _, err := db.InsertOne(ctx, Monitor); err != nil {
log.Warn("Monitor:InsertOneMonitor db.InsertOne failed", log.E(err))
return err
}
return nil
}
// FindOneMonitor 查找一个应用监控
func FindOneMonitor(ctx context.Context, filter bson.M) (
*Monitor, error) {
var Monitor Monitor
if err := db.FindOne(ctx, &Monitor, filter); err != nil {
return nil, err
}
return &Monitor, nil
}
// DelOneMonitor 删除一个应用监控
func DelOneMonitor(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.DeleteOne(ctx, filter)
if err != nil {
log.Warn("Monitor:DelOneMonitor db.DeleteOne failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateOneMonitor 更新一个应用监控
func UpdateOneMonitor(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateOne(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateOneMonitor db.UpdateOne failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// CountMonitors 统计应用监控数量
func CountMonitors(ctx context.Context, filter bson.M) (
int64, error) {
count, err := db.Count(ctx, filter)
if err != nil {
log.Warn("Monitor:CountMonitors db.Count failed",
log.E(err), log.Any("filter", filter))
return 0, err
}
return count, nil
}
// UpdateManyMonitor 更新满足条件的应用监控
func UpdateManyMonitor(ctx context.Context, filter bson.M, update bson.M) error {
_, err := db.UpdateMany(ctx, filter, update)
if err != nil {
log.Warn("user:UpdateManyMonitor db.UpdateMany failed",
log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// FindManyMonitor 查找一批应用监控数据
func FindManyMonitor(ctx context.Context, filter bson.M,
opts ...*options.FindOptions) (MonitorList, error) {
data := make(MonitorList, 0)
if err := db.Find(ctx, &data, filter, opts...); err != nil {
log.Warn("Monitor:FindManyMonitor db.Find failed", log.E(err), log.Any("filter", filter))
return nil, err
}
return data, nil
}
// FindManyMonitorWithBind 用自己定义结构查找一批应用监控数据
func FindManyMonitorWithBind(ctx context.Context, bind interface{}, filter bson.M,
opts ...*options.FindOptions) error {
if err := db.Find(ctx, bind, filter, opts...); err != nil {
log.Warn("Monitor:FindManyMonitorWithBind db.Find failed", log.E(err), log.Any("filter", filter))
return err
}
return nil
}
// AggregateMonitors 聚合查找一批应用监控信息
func AggregateMonitors(ctx context.Context,
bind interface{}, pipeline []bson.M) error {
if err := db.Aggregate(ctx, bind, pipeline); err != nil {
log.Warn("feedback:AggregateMonitors db.Aggregate failed",
log.E(err), log.Any("pipeline", pipeline))
return err
}
return nil
}
+44
View File
@@ -0,0 +1,44 @@
package monitormod
type TagMonitor struct {
ID string
AppId string
Name string
Category string
Device string
Duration string
Compare string
Threshold string
Comment string
Status string
TriggerCount string
CheckCount string
UpdatedAt string
CreatedAt string
}
var FN struct {
Monitor TagMonitor
}
var TN struct {
Monitor string
}
func init() {
FN.Monitor.ID = "_id"
FN.Monitor.AppId = "appId"
FN.Monitor.Name = "name"
FN.Monitor.Category = "category"
FN.Monitor.Device = "device"
FN.Monitor.Duration = "duration"
FN.Monitor.Compare = "compare"
FN.Monitor.Threshold = "threshold"
FN.Monitor.Comment = "comment"
FN.Monitor.Status = "status"
FN.Monitor.TriggerCount = "triggerCount"
FN.Monitor.CheckCount = "checkCount"
FN.Monitor.UpdatedAt = "updatedAt"
FN.Monitor.CreatedAt = "createdAt"
TN.Monitor = "monitor"
}
+44
View File
@@ -0,0 +1,44 @@
package monitormod
import (
"go.mongodb.org/mongo-driver/bson/primitive"
"stat/common/statutils"
"time"
)
type MonitorCategory int
const (
MonitorCategoryNone MonitorCategory = 0 // 占位符,无意义
MonitorCategoryNewUser MonitorCategory = 1 // 新用户监控
)
type Compare int
const (
CompareNone Compare = 0
CompareLT Compare = 1 // 小于
CompareEQ Compare = 2 // 等于
CompareGT Compare = 3 // 大于
)
// 监控模型,数据库中的
// @table:monitor
type Monitor struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"` // ID
Name string `bson:"name" json:"name"` // 名称
AppId int32 `bson:"appId" json:"appId"` // appId
Category MonitorCategory `bson:"category" json:"category"` // 分类
Device statutils.DeviceName `bson:"device" json:"device"` // 设备
Duration int64 `bson:"duration" json:"duration"` // 时间段,单位分钟
Compare Compare `bson:"compare" json:"compare"` // 比较
Threshold int64 `bson:"threshold" json:"threshold"` // 阀值
Comment string `bson:"comment" json:"comment"` // 注释
Status bool `bson:"status" json:"status"` // 是否启用
TriggerCount int64 `bson:"triggerCount" json:"triggerCount"` // 触发次数
CheckCount int64 `bson:"checkCount" json:"checkCount"` // 检测次数
UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"` // 更新时间
CreatedAt time.Time `json:"createdAt" bson:"createdAt"` // 创建时间
}
type MonitorList []*Monitor
+72
View File
@@ -0,0 +1,72 @@
package opLogMod
import (
"context"
"fmt"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"stat/common/log"
"stat/common/mongos"
)
// 初始化model
func Init() {
// 获取数据库表
db = mongos.New(mongos.MgoManager, CollOpLog)
indexes := []mongo.IndexModel{
{
Keys: bson.D{{Key: "createdAt", Value: 1}},
},
{
Keys: bson.D{{Key: "router", Value: 1}},
},
{
Keys: bson.D{{Key: "operator", Value: 1}},
},
}
if _, err := db.CreateIndex(context.Background(), indexes); err != nil {
panic(fmt.Sprintf("Model %s InitIndex error %+v", CollOpLog, err))
}
}
// 增加操作日志
func AddOpLog(ctx context.Context, doc *OpLog) (err error) {
if _, err = db.InsertOne(ctx, doc); err != nil {
log.Error("opLog AddOpLog InsertOne err", log.E(err))
return
}
return
}
// 获取操作日志列表
func GetOpLogList(ctx context.Context, operator *string, router *string, isAdmin *bool, skip, limit int64) (count int64, data []OpLog, err error) {
filter := bson.M{}
if operator != nil {
filter["operator"] = operator
}
if router != nil {
filter["router"] = router
}
if isAdmin != nil {
filter["isAdmin"] = isAdmin
}
sort := bson.D{{"createdAt", -1}}
opts := options.Find().SetSort(sort).SetSkip(skip).SetLimit(limit)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("opLog GetOpLogList Find err", log.E(err))
return
}
if count, err = db.Count(ctx, filter); err != nil {
log.Error("opLog GetOpLogList Count err", log.E(err))
return
}
return
}
+18
View File
@@ -0,0 +1,18 @@
package opLogMod
import (
"stat/common/mongos"
"time"
)
const CollOpLog = "op_log"
var db *mongos.MongoTool
type OpLog struct {
Operator string `bson:"operator"` // 操作人员
Router string `bson:"router"` // 接口路由
Data string `bson:"data"` // 操作数据
IsAdmin bool `bson:"isAdmin"` // 是否是管理员
CreatedAt time.Time `bson:"createdAt"` // 创建时间
}
@@ -0,0 +1,99 @@
package rechargechannelmod
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"
)
func Init() {
db = mongos.New(mongos.MgoManager, CollRechargeChannel)
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", CollRechargeChannel, err))
}
}
// UpsertOneUserRechargeStat 更新或插入一条支付渠道统计
func UpsertOneUserRechargeStat(ctx context.Context, channelName string, appId int32, sumDate time.Time, blocDeduction bool, money, paymoney, channelMoney int64) (err error) {
filter := bson.M{"channelName": channelName, "appId": appId, "sumDate": sumDate}
update := bson.M{}
update["orderCount"] = 1
update["totalOrderMoney"] = money
update["TotalOrderPayMoney"] = paymoney
update["channelMoney"] = channelMoney
if !blocDeduction {
update["blocOrderCount"] = 1
update["blocOrderMoney"] = money
update["blocOrderPayMoney"] = paymoney
update["blocChannelMoney"] = channelMoney
}
exists, err := db.Exists(ctx, filter)
if err != nil {
return err
}
if exists {
_, err = db.UpdateOne(ctx, filter, bson.M{"$inc": update})
} else {
insertDoc := update
insertDoc["sumDate"] = sumDate
insertDoc["appId"] = appId
insertDoc["channelName"] = channelName
_, err = db.InsertOne(ctx, insertDoc)
}
return err
}
// 后台获取统计信息
func GetRechargeChannelStatList(ctx context.Context, appId *int32, channelName *string, start, end *time.Time, skip, limit int64) (count int64, data []RechargeChannelMod, err error) {
filter := bson.M{}
if appId != nil {
filter["appId"] = appId
}
if channelName != nil {
filter["channelName"] = channelName
}
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}, {Key: "appId", Value: 1}}
opts := options.Find().SetSort(sort).SetSkip(skip).SetLimit(limit)
if err = db.Find(ctx, &data, filter, opts); err != nil {
log.Error("channelCodeStat GetRechargeChannelStatList Find err", log.E(err))
return
}
if count, err = db.Count(ctx, filter); err != nil {
log.Error("channelCodeStat GetRechargeChannelStatList Count err", log.E(err))
return
}
return
}
+27
View File
@@ -0,0 +1,27 @@
package rechargechannelmod
import (
"stat/common/mongos"
"time"
)
// 表名
const CollRechargeChannel = "log_recharge_channel"
var db *mongos.MongoTool
// RechargeChannelMod 充值渠道信息
type RechargeChannelMod struct {
SumDate time.Time `bson:"sumDate"` // 记录时间 按天对齐
AppId int32 `bson:"appId"` // appId
ChannelName string `bson:"channelName"` // 支付渠道名称
TotalOrderCount int64 `bson:"orderCount"` // 订单数量
BlocOrderCount int64 `bson:"blocOrderCount"` // 集团订单数量
TotalOrderMoney int64 `bson:"totalOrderMoney"` // 订单金额
BlocOrderMoney int64 `bson:"blocOrderMoney"` // 集团订单金额
TotalOrderPayMoney int64 `bson:"totalOrderPayMoney"` // 订单实际支付金额
BlocOrderPayMoney int64 `bson:"blocOrderPayMoney"` // 集团订单实际支付金额
ChannelMoney int64 `bson:"channelMoney"` // 渠道费用
BlocChannelMoney int64 `bson:"blocChannelMoney"` // 集团渠道费用
CreatedAt time.Time `bson:"createdAt"` // 创建时间
}
+214
View File
@@ -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
}
+255
View File
@@ -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
}
+45
View File
@@ -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
+214
View File
@@ -0,0 +1,214 @@
package rechargemod
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, CollRechargeLog)
// 初始化索引
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]", CollRechargeLog, err))
}
}
// 新增用户充值记录
func AddRechargeLog(ctx context.Context, doc *RechargeMod) (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 []RechargeMod, 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("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 []RechargeMod, 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 *[]*RechargeMod) (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) ([]RechargeMod, error) {
list := make([]RechargeMod, 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) ([]RechargeMod, error) {
list := make([]RechargeMod, 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) ([]RechargeMod, error) {
list := make([]RechargeMod, 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) ([]RechargeMod, error) {
list := make([]RechargeMod, 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 RechargeMod, 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 RechargeMod, 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
}

Some files were not shown because too many files have changed in this diff Show More