forked from all_user/stat_center
代码调整
This commit is contained in:
+14
-13
@@ -4,8 +4,6 @@ import (
|
||||
"encoding/base32"
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/skip2/go-qrcode"
|
||||
"stat/api/proto"
|
||||
"stat/common"
|
||||
"stat/common/googauth"
|
||||
@@ -15,6 +13,9 @@ import (
|
||||
"stat/models/authorityMod"
|
||||
"stat/service/adminSer"
|
||||
"stat/service/opLogSer"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/skip2/go-qrcode"
|
||||
)
|
||||
|
||||
// @Tags 系统管理
|
||||
@@ -136,17 +137,17 @@ func AdminVerify(ctx *gin.Context) {
|
||||
}
|
||||
|
||||
//测试模式不使用两步验证
|
||||
if gin.Mode() == gin.ReleaseMode {
|
||||
ok, err := googauth.Verify(adminInfo.Secret, *param.VerifyCode)
|
||||
if err != nil {
|
||||
stdLog.ServerJSON(ctx, stdLog.GoogleAuthFailed, "admin Verification 2-step error: "+err.Error())
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
stdLog.ServerJSON(ctx, stdLog.GoogleAuthFailed, "admin Verification 2-step verification failed")
|
||||
return
|
||||
}
|
||||
}
|
||||
// if gin.Mode() == gin.ReleaseMode {
|
||||
// ok, err := googauth.Verify(adminInfo.Secret, *param.VerifyCode)
|
||||
// if err != nil {
|
||||
// stdLog.ServerJSON(ctx, stdLog.GoogleAuthFailed, "admin Verification 2-step error: "+err.Error())
|
||||
// return
|
||||
// }
|
||||
// if !ok {
|
||||
// stdLog.ServerJSON(ctx, stdLog.GoogleAuthFailed, "admin Verification 2-step verification failed")
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
|
||||
code, adminInfo, err := adminSer.AdminLogin(ctx, param)
|
||||
if err != nil || code != stdLog.Success {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"stat/api/proto"
|
||||
"stat/common"
|
||||
"stat/common/log"
|
||||
"stat/common/stdLog"
|
||||
"stat/common/utils"
|
||||
@@ -115,15 +114,6 @@ func AgentLogin(ctx context.Context, ip string, param proto.AgentLoginReq) (code
|
||||
|
||||
imgCodeByte := statg.VerifyIMGStore.Get(param.ImgID, true)
|
||||
if bytes.Equal(imgCodeByte, imgs) {
|
||||
channelInfo.ShowMagic += 1
|
||||
doc := bson.M{"$set": bson.M{channelmod.FN.ChannelInfo.ShowMagic: channelInfo.ShowMagic}}
|
||||
if err = channelmod.UpdateOneChannelInfo(ctx, bson.M{}, doc); err != nil {
|
||||
code = stdLog.Failure
|
||||
return code, channelInfo
|
||||
}
|
||||
code = stdLog.VerifySmsCodeFailed
|
||||
return
|
||||
} else if bytes.Equal(imgCodeByte, common.ArrayReverseByte(imgs)) {
|
||||
channelInfo.ShowMagic = 1
|
||||
} else {
|
||||
code = stdLog.VerifySmsCodeFailed
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"os"
|
||||
"regexp"
|
||||
"stat/api/proto"
|
||||
"stat/common/log"
|
||||
"stat/common/utils"
|
||||
downloadinfo "stat/models/downloadinfo"
|
||||
"stat/models/versionMod"
|
||||
@@ -80,6 +81,7 @@ func GetH5Config(ctx context.Context, req *proto.H5ConfigReq, userAgent string,
|
||||
}
|
||||
cacheSer.Writers.LandPageClickWriter.Add(downloadInfo)
|
||||
origin, target, config := GetAppConfig(req.AppId)
|
||||
log.Info("GetH5Config", log.Any("origin", origin), log.Any("target", target))
|
||||
if origin == "" || target == "" || config == "" {
|
||||
return nil, "madou.mobileconfig"
|
||||
}
|
||||
|
||||
@@ -1,450 +0,0 @@
|
||||
package blocstatdaily
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"stat/common/log"
|
||||
"stat/common/utils"
|
||||
"stat/models/accessmod"
|
||||
"stat/models/blocDailystatmod"
|
||||
"stat/models/rechargemod"
|
||||
"stat/models/registermod"
|
||||
"stat/models/withdrawUserOrdermod"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
DirectVisitCount string = "directVisitCount" // 直推访问数
|
||||
FissionVisitCount string = "fissionVisitCount" // 裂变访问数
|
||||
Day1RetainRate string = "day1RetainRate" // 次日留存率
|
||||
Day3RetainRate string = "day3RetainRate" // 3日留存率
|
||||
Day7RetainRate string = "day7RetainRate" // 7日留存率
|
||||
RechargeAmount string = "rechargeAmount" // 直推充值金额
|
||||
FissionAmount string = "fissionAmount" // 裂变充值金额
|
||||
NewDirectCount string = "newDirectCount" // 新增直推
|
||||
NewFissionCount string = "newFissionCount" // 新增裂变
|
||||
DaichongAmout string = "daichongAmout" // 代充金额
|
||||
OnlineAmount string = "onlineAmount" // 在线充值
|
||||
NewRechargeCount string = "newRechargeCount" // 新增充值数
|
||||
UserWithdrawAmount string = "userWithdrawAmount" // 用户提现
|
||||
)
|
||||
|
||||
func defaultTimeMap(defaultStatDate time.Time) map[string]time.Time {
|
||||
return map[string]time.Time{
|
||||
DirectVisitCount: defaultStatDate, // 直推访问用户数
|
||||
FissionVisitCount: defaultStatDate, // 裂变访问数
|
||||
Day1RetainRate: defaultStatDate, // 次日留存率
|
||||
Day3RetainRate: defaultStatDate, // 3日留存率
|
||||
Day7RetainRate: defaultStatDate, // 7日留存率
|
||||
RechargeAmount: defaultStatDate, // 直推充值金额
|
||||
FissionAmount: defaultStatDate, // 裂变充值金额
|
||||
NewDirectCount: defaultStatDate, // 新增直推
|
||||
NewFissionCount: defaultStatDate, // 新增裂变
|
||||
DaichongAmout: defaultStatDate, // 代充金额
|
||||
OnlineAmount: defaultStatDate, // 在线充值
|
||||
NewRechargeCount: defaultStatDate, // 新增充值数
|
||||
UserWithdrawAmount: defaultStatDate, // 用户提现
|
||||
}
|
||||
}
|
||||
|
||||
// 获取统计方法
|
||||
type StatMethod = func(ctx context.Context, start time.Time, end time.Time, appIds []int32) error
|
||||
|
||||
// 统计方法汇总
|
||||
var statMethodMap = map[string]StatMethod{
|
||||
DirectVisitCount: DirectVisitCountMethod, // 直推访问用户数
|
||||
FissionVisitCount: FissionVisitCountMethod, // 裂变访问数
|
||||
Day1RetainRate: Day1RetainRateMethod, // 次日留存率
|
||||
Day3RetainRate: Day3RetainRateMethod, // 3日留存率
|
||||
Day7RetainRate: Day7RetainRateMethod, // 7日留存率
|
||||
RechargeAmount: DirectAmountMethod, // 直推充值金额
|
||||
FissionAmount: FissionAmountMethod, // 裂变充值金额
|
||||
NewDirectCount: NewDirectCountMethod, // 新增直推
|
||||
NewFissionCount: NewFissionCountMethod, // 新增裂变
|
||||
DaichongAmout: DaichongAmoutMethod, // 代充金额
|
||||
OnlineAmount: OnlineAmountMethod, // 在线充值
|
||||
NewRechargeCount: NewRechargeCountMethod, // 新增充值数
|
||||
UserWithdrawAmount: UserWithdrawAmountMethod, // 用户提现
|
||||
}
|
||||
|
||||
// DirectVisitCountMethod 访问用户数
|
||||
func DirectVisitCountMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
for _, appid := range appIds {
|
||||
isDirect := true
|
||||
|
||||
userCount, err := accessmod.BlocDailyStatCount(ctx, appid, &isDirect, nil, start, end)
|
||||
if err != nil {
|
||||
log.Error("DirectVisitCountMethod BlocDailyStatCount", log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新数据库
|
||||
doc := blocDailystatmod.BlocDailyStatDoc{
|
||||
DirectVisitCount: &userCount,
|
||||
}
|
||||
|
||||
err = blocDailystatmod.UpsertBlocDailyStat(ctx, start, appid, doc)
|
||||
if err != nil {
|
||||
log.Error("DirectVisitCountMethod UpsertDailyStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// FissionVisitCountMethod 裂变访问数
|
||||
func FissionVisitCountMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
for _, appid := range appIds {
|
||||
isDirect := false
|
||||
|
||||
userCount, err := accessmod.BlocDailyStatCount(ctx, appid, &isDirect, nil, start, end)
|
||||
if err != nil {
|
||||
log.Error("DirectVisitCountMethod BlocDailyStatCount", log.E(err))
|
||||
return err
|
||||
}
|
||||
// 更新数据库
|
||||
doc := blocDailystatmod.BlocDailyStatDoc{
|
||||
FissionVisitCount: &userCount,
|
||||
}
|
||||
err = blocDailystatmod.UpsertBlocDailyStat(ctx, start, appid, doc)
|
||||
if err != nil {
|
||||
log.Error("FissionVisitCountMethod UpsertDailyStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Day1RetainRateMethod 次日留存率
|
||||
func Day1RetainRateMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
for _, appid := range appIds {
|
||||
rate := float64(0)
|
||||
|
||||
registerStart := utils.BeginWithTime(start.AddDate(0, 0, -1))
|
||||
registerEnd := utils.EndWithTime(start.AddDate(0, 0, -1))
|
||||
|
||||
registerCount, err := registermod.TotalAddUserCount(ctx, appid, registerStart, registerEnd)
|
||||
if err != nil {
|
||||
log.Error("Day1RetainRateMethod s", log.E(err))
|
||||
return err
|
||||
}
|
||||
VistitCount, err := accessmod.DailyUserVisitCountByRegister(ctx, appid, start, end, registerStart, registerEnd)
|
||||
if err != nil {
|
||||
log.Error("Day1RetainRateMethod DailyUserVisitCountByRegister", log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
if registerCount > 0 {
|
||||
rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", 100*(float64(VistitCount)/float64(registerCount))), 64)
|
||||
|
||||
}
|
||||
|
||||
// 更新数据库
|
||||
doc := blocDailystatmod.BlocDailyStatDoc{
|
||||
Day1RetainRate: &rate,
|
||||
}
|
||||
err = blocDailystatmod.UpsertBlocDailyStat(ctx, start, appid, doc)
|
||||
if err != nil {
|
||||
log.Error("Day1RetainRateMethod UpsertDailyStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Day3RetainRateMethod 3日留存率
|
||||
func Day3RetainRateMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
for _, appid := range appIds {
|
||||
|
||||
registerStart := utils.BeginWithTime(start.AddDate(0, 0, -2))
|
||||
registerEnd := utils.EndWithTime(start.AddDate(0, 0, -2))
|
||||
rate := float64(0)
|
||||
|
||||
registerCount, err := registermod.TotalAddUserCount(ctx, appid, registerStart, registerEnd)
|
||||
if err != nil {
|
||||
log.Error("Day3RetainRateMethod DailyUserRegisterCount", log.E(err))
|
||||
return err
|
||||
}
|
||||
VistitCount, err := accessmod.DailyUserVisitCountByRegister(ctx, appid, start, end, registerStart, registerEnd)
|
||||
if err != nil {
|
||||
log.Error("Day3RetainRateMethod DailyUserVisitCountByRegister", log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
if registerCount > 0 {
|
||||
rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", 100*(float64(VistitCount)/float64(registerCount))), 64)
|
||||
|
||||
}
|
||||
|
||||
// 更新数据库
|
||||
doc := blocDailystatmod.BlocDailyStatDoc{
|
||||
Day3RetainRate: &rate,
|
||||
}
|
||||
err = blocDailystatmod.UpsertBlocDailyStat(ctx, start, appid, doc)
|
||||
if err != nil {
|
||||
log.Error("Day3RetainRateMethod UpsertDailyStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Day7RetainRateMethod 7日留存率
|
||||
func Day7RetainRateMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
for _, appid := range appIds {
|
||||
registerStart := utils.BeginWithTime(start.AddDate(0, 0, -6))
|
||||
registerEnd := utils.EndWithTime(start.AddDate(0, 0, -6))
|
||||
rate := float64(0)
|
||||
|
||||
registerCount, err := registermod.TotalAddUserCount(ctx, appid, registerStart, registerEnd)
|
||||
if err != nil {
|
||||
log.Error("Day3RetainRateMethod DailyUserRegisterCount", log.E(err))
|
||||
return err
|
||||
}
|
||||
VistitCount, err := accessmod.DailyUserVisitCountByRegister(ctx, appid, start, end, registerStart, registerEnd)
|
||||
if err != nil {
|
||||
log.Error("Day3RetainRateMethod DailyUserVisitCountByRegister", log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
if registerCount > 0 {
|
||||
rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", 100*(float64(VistitCount)/float64(registerCount))), 64)
|
||||
|
||||
}
|
||||
|
||||
// 更新数据库
|
||||
doc := blocDailystatmod.BlocDailyStatDoc{
|
||||
Day7RetainRate: &rate,
|
||||
}
|
||||
err = blocDailystatmod.UpsertBlocDailyStat(ctx, start, appid, doc)
|
||||
if err != nil {
|
||||
log.Error("Day7RetainRateMethod UpsertDailyStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// DirectAmountMethod 直推充值金额
|
||||
func DirectAmountMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
for _, appid := range appIds {
|
||||
// 获取充值金额
|
||||
count, amount, err := rechargemod.BlocDirectRechargeAmount(ctx, appid, start, end)
|
||||
if err != nil {
|
||||
log.Error("DirectAmountMethod BlocDirectRechargeAmount ", log.E(err))
|
||||
return err
|
||||
}
|
||||
// 更新数据库
|
||||
doc := blocDailystatmod.BlocDailyStatDoc{
|
||||
DirectAmount: &amount,
|
||||
DirectAmountCount: &count,
|
||||
}
|
||||
err = blocDailystatmod.UpsertBlocDailyStat(ctx, start, appid, doc)
|
||||
if err != nil {
|
||||
log.Error("DirectAmountMethod UpsertDailyStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// FissionAmountMethod 裂变充值金额
|
||||
func FissionAmountMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
for _, appid := range appIds {
|
||||
// 获取充值金额
|
||||
count, amount, err := rechargemod.BlocFissionRechargeAmount(ctx, appid, start, end)
|
||||
if err != nil {
|
||||
log.Error("FissionAmountMethod BlocFissionRechargeAmount ", log.E(err))
|
||||
return err
|
||||
}
|
||||
// 更新数据库
|
||||
doc := blocDailystatmod.BlocDailyStatDoc{
|
||||
FissionAmount: &amount,
|
||||
FissionAmountCount: &count,
|
||||
}
|
||||
err = blocDailystatmod.UpsertBlocDailyStat(ctx, start, appid, doc)
|
||||
if err != nil {
|
||||
log.Error("FissionAmountMethod UpsertBlocDailyStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewDirectCountMethod 新增直推
|
||||
func NewDirectCountMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
for _, appid := range appIds {
|
||||
|
||||
count, err := registermod.BlocDirectAddUserCount(ctx, appid, start, end)
|
||||
if err != nil {
|
||||
log.Error("NewDirectCountMethod DeductionRechargeAmount ", log.E(err))
|
||||
return err
|
||||
}
|
||||
// 更新数据库
|
||||
doc := blocDailystatmod.BlocDailyStatDoc{
|
||||
NewDirectCount: &count,
|
||||
}
|
||||
err = blocDailystatmod.UpsertBlocDailyStat(ctx, start, appid, doc)
|
||||
if err != nil {
|
||||
log.Error("NewDirectCountMethod UpsertDailyStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewFissionCountMethod 新增裂变
|
||||
func NewFissionCountMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
for _, appid := range appIds {
|
||||
|
||||
count, err := registermod.BlocFissionAddUserCount(ctx, appid, start, end)
|
||||
if err != nil {
|
||||
log.Error("NewFissionCountMethod DeductionRechargeAmount ", log.E(err))
|
||||
return err
|
||||
}
|
||||
// 更新数据库
|
||||
doc := blocDailystatmod.BlocDailyStatDoc{
|
||||
NewFissionCount: &count,
|
||||
}
|
||||
err = blocDailystatmod.UpsertBlocDailyStat(ctx, start, appid, doc)
|
||||
if err != nil {
|
||||
log.Error("NewFissionCountMethod UpsertDailyStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DaichongAmoutMethod 代充金额
|
||||
func DaichongAmoutMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
for _, appid := range appIds {
|
||||
_, money, err := rechargemod.BlocGetDaichongAmout(ctx, appid, start, end)
|
||||
if err != nil {
|
||||
log.Error("DaichongAmoutMethod BlocGetDaichongAmout ", log.E(err))
|
||||
return err
|
||||
}
|
||||
// 更新数据库
|
||||
doc := blocDailystatmod.BlocDailyStatDoc{
|
||||
DaichongAmout: &money,
|
||||
}
|
||||
err = blocDailystatmod.UpsertBlocDailyStat(ctx, start, appid, doc)
|
||||
if err != nil {
|
||||
log.Error("NewDeductionCountMethod UpsertBlocDailyStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// OnlineAmountMethod 在线充值
|
||||
func OnlineAmountMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
for _, appid := range appIds {
|
||||
_, money, err := rechargemod.BlocGetOnlineAmount(ctx, appid, start, end)
|
||||
if err != nil {
|
||||
log.Error("DaichongAmoutMethod BlocGetOnlineAmount ", log.E(err))
|
||||
return err
|
||||
}
|
||||
// 更新数据库
|
||||
doc := blocDailystatmod.BlocDailyStatDoc{
|
||||
OnlineAmount: &money,
|
||||
}
|
||||
err = blocDailystatmod.UpsertBlocDailyStat(ctx, start, appid, doc)
|
||||
if err != nil {
|
||||
log.Error("NewDeductionCountMethod UpsertBlocDailyStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewRechargeCountMethod 新增充值
|
||||
func NewRechargeCountMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
|
||||
for _, appid := range appIds {
|
||||
// 获取充值金额
|
||||
result, err := rechargemod.BlocTotalDistricRechargeAmount(ctx, appid, start, end)
|
||||
if err != nil {
|
||||
log.Error("NewRechargeCountMethod BlocTotalDistricRechargeAmount ", log.E(err))
|
||||
return err
|
||||
}
|
||||
totalRechargeCount := int64(len(result))
|
||||
amountMap := make(map[uint64]int64)
|
||||
userIds := make([]uint64, 0)
|
||||
for _, value := range result {
|
||||
userIds = append(userIds, value.UserId)
|
||||
if key, ok := amountMap[value.UserId]; ok {
|
||||
//存在
|
||||
amountMap[value.UserId] = value.PayMoney + key
|
||||
} else {
|
||||
amountMap[value.UserId] = value.PayMoney
|
||||
}
|
||||
}
|
||||
|
||||
// 获取注册信息
|
||||
userList, err := registermod.TimeVisitUsersInfoByTime(ctx, appid, userIds, start, end)
|
||||
if err != nil {
|
||||
log.Error("NewRechargeCountMethod TotalDistricRechargeAmount ", log.E(err))
|
||||
return err
|
||||
}
|
||||
amount := int64(0)
|
||||
count := int64(0)
|
||||
for _, user := range userList {
|
||||
count += 1
|
||||
if key, ok := amountMap[user.UserId]; ok {
|
||||
amount += key
|
||||
}
|
||||
}
|
||||
|
||||
// 更新数据库
|
||||
doc := blocDailystatmod.BlocDailyStatDoc{
|
||||
NewRechargeCount: &count,
|
||||
NewRechargeAmount: &amount,
|
||||
TotalRechargeCount: &totalRechargeCount,
|
||||
}
|
||||
err = blocDailystatmod.UpsertBlocDailyStat(ctx, start, appid, doc)
|
||||
if err != nil {
|
||||
log.Error("DeductionAmountMethod UpsertDailyStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UserWithdrawAmountMethod 用户提现
|
||||
func UserWithdrawAmountMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
for _, appid := range appIds {
|
||||
// 获取充值金额
|
||||
result, err := withdrawUserOrdermod.GetBlocUserWithdrawOrder(ctx, appid, start, end)
|
||||
if err != nil {
|
||||
log.Error("NewRechargeCountMethod BlocTotalDistricRechargeAmount ", log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
payMoney := int64(0)
|
||||
money := int64(0)
|
||||
for _, withdrawInfo := range result {
|
||||
payMoney += withdrawInfo.PayMoney
|
||||
money += withdrawInfo.Money
|
||||
}
|
||||
|
||||
// 更新数据库
|
||||
doc := blocDailystatmod.BlocDailyStatDoc{
|
||||
UserWithDrawAmount: &money,
|
||||
UserWithDrawPaymoneyAmount: &payMoney,
|
||||
}
|
||||
err = blocDailystatmod.UpsertBlocDailyStat(ctx, start, appid, doc)
|
||||
if err != nil {
|
||||
log.Error("DeductionAmountMethod UpsertDailyStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
package blocstatdaily
|
||||
|
||||
import (
|
||||
"context"
|
||||
"stat/common/log"
|
||||
"stat/common/statutils"
|
||||
"stat/common/utils"
|
||||
"stat/models/appInfoMod"
|
||||
statrecordmod "stat/models/statrecord"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
* 主要统计任务:
|
||||
* 1、统计每天的app的直推访问数、裂变访问数、次日留存率、3日留存率、7日留存率。(表格)
|
||||
* 2、按5分钟一个点,记录实时数据 app(新增、访问数....)。(曲线图)
|
||||
*/
|
||||
|
||||
// RunDayStat 任务1:统计前一天日活(每天1点开始统计)
|
||||
func RunStat(defaultStatDate time.Time) error {
|
||||
log.Info("daily stat running...")
|
||||
ctx := context.Background()
|
||||
recordMap := defaultTimeMap(defaultStatDate)
|
||||
|
||||
// 1.获取统计项上次统计的时候(每天执行)
|
||||
recoredResult, err := statrecordmod.LastRecordTimeMap(ctx, statrecordmod.BlocDailyStatDayJob) //第一次从默认记录时间开始统计
|
||||
if err != nil {
|
||||
log.Error("Daily RunStat lastRecordTime failed!", log.E(err))
|
||||
return err
|
||||
}
|
||||
for _, record := range recoredResult {
|
||||
recordMap[record.Item] = record.RecordTime
|
||||
}
|
||||
|
||||
appIds, err := appInfoMod.GetAppIds(ctx)
|
||||
if err != nil {
|
||||
log.Error("daily RunStat GetAppIds failed!", log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
statFrq := 24 * time.Hour // 统计频率
|
||||
curStatTime := utils.BeginOfToday() // 本次统计时间
|
||||
|
||||
for item, lastStatAt := range recordMap {
|
||||
_lastStatAt := lastStatAt
|
||||
for curStatTime.After(_lastStatAt) {
|
||||
end := _lastStatAt.Add(statFrq)
|
||||
// 超过本次统计结束时间,则结束
|
||||
if end.After(curStatTime) {
|
||||
end = curStatTime
|
||||
}
|
||||
|
||||
err := runStatMethod(ctx, item, _lastStatAt, end, appIds)
|
||||
if err != nil {
|
||||
log.Error("daily statByTimeRange failed!", log.E(err), log.Any("item", item))
|
||||
return err
|
||||
}
|
||||
_lastStatAt = end
|
||||
}
|
||||
recordMap[item] = _lastStatAt
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 实时统计每天的情况
|
||||
func RunStatToday() {
|
||||
ctx := context.Background()
|
||||
start := utils.BeginOfToday()
|
||||
end := utils.EndOfToday()
|
||||
log.Info("daily today stat running...")
|
||||
|
||||
appIds, err := appInfoMod.GetAppIds(ctx)
|
||||
if err != nil {
|
||||
log.Error("daily today RunStat GetAppIds failed!", log.E(err))
|
||||
return
|
||||
}
|
||||
|
||||
for item, statMethod := range statMethodMap {
|
||||
// 调用统计方法,获取数据
|
||||
err := statMethod(ctx, start, end, appIds)
|
||||
if err != nil {
|
||||
log.Error("Daily today stat statByTimeRange statMethod failed!", log.Any("statItem", item), log.E(err))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// runStatMethod 调用统计项方法
|
||||
func runStatMethod(ctx context.Context, item string, start, end time.Time, appIds []int32) (err error) {
|
||||
// 1.获取统计方法
|
||||
statMethod, ok := statMethodMap[item]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 调用统计方法,获取数据
|
||||
err = statutils.ServerMon.RunWithName(func() error {
|
||||
return statMethod(ctx, start, end, appIds)
|
||||
}, statutils.GetFuncName(statMethod))
|
||||
|
||||
if err != nil {
|
||||
log.Error("Daily stat statByTimeRange statMethod failed!", log.Any("statItem", item), log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
// 3.更新记录
|
||||
if err := statrecordmod.UpsertItemRecord(ctx, statrecordmod.BlocDailyStatDayJob, item, end); err != nil {
|
||||
log.Error("Daily stat commit UpsertItemRecord failed!", log.E(err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,197 +0,0 @@
|
||||
package blocstatdistrict
|
||||
|
||||
import (
|
||||
"context"
|
||||
"stat/common/log"
|
||||
"stat/common/utils"
|
||||
"stat/models/accessmod"
|
||||
"stat/models/channelCodeBlocStatMod"
|
||||
"stat/models/rechargemod"
|
||||
"stat/models/registermod"
|
||||
"time"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
|
||||
const (
|
||||
DirectVisitCount string = "directVisitCount" // 访问数
|
||||
RechargeAmount string = "rechargeAmount" // 充值金额
|
||||
NewDirectCount string = "newDirectCount" // 新增
|
||||
)
|
||||
|
||||
func defaultTimeMap(defaultStatDate time.Time) map[string]time.Time {
|
||||
return map[string]time.Time{
|
||||
DirectVisitCount: defaultStatDate, // 访问数
|
||||
RechargeAmount: defaultStatDate, // 充值金额
|
||||
NewDirectCount: defaultStatDate, // 新增
|
||||
}
|
||||
}
|
||||
|
||||
// 获取统计方法
|
||||
type StatMethod = func(ctx context.Context, start time.Time, end time.Time, appIds []int32) error
|
||||
|
||||
// 统计方法汇总
|
||||
var statMethodMap = map[string]StatMethod{
|
||||
DirectVisitCount: DirectVisitCountMethod, // 访问数
|
||||
RechargeAmount: RechargeAmountMethod, // 充值金额
|
||||
NewDirectCount: NewDirectCountMethod, // 新增
|
||||
}
|
||||
|
||||
// DirectVisitCountMethod 直推访问数
|
||||
func DirectVisitCountMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
type districtVisitInfo struct {
|
||||
DirectVisitCount int64 // 直推访问数
|
||||
FissionVisitCount int64 // 裂变访问数
|
||||
}
|
||||
|
||||
for _, appid := range appIds {
|
||||
|
||||
districtVisitMap := make(map[string]*districtVisitInfo)
|
||||
|
||||
err := accessmod.VisitInfoByTimeShard(ctx, appid, start, end, utils.GlobalShardHour, func(item *accessmod.AccessMod) {
|
||||
if len(item.DistrictCode) > 0 && !item.BlocDeduction {
|
||||
if item.IsDirect {
|
||||
if value, ok := districtVisitMap[item.DistrictCode]; !ok {
|
||||
districtVisitMap[item.DistrictCode] = &districtVisitInfo{
|
||||
DirectVisitCount: 1,
|
||||
}
|
||||
} else {
|
||||
value.DirectVisitCount += 1
|
||||
}
|
||||
} else if !item.IsDirect { // 裂变
|
||||
if value, ok := districtVisitMap[item.DistrictCode]; !ok {
|
||||
districtVisitMap[item.DistrictCode] = &districtVisitInfo{
|
||||
FissionVisitCount: 1,
|
||||
}
|
||||
} else {
|
||||
value.FissionVisitCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
log.Error("VisitCountMethod VisitInfoByTimeShard ", log.E(err))
|
||||
return err
|
||||
}
|
||||
// 插入数据库
|
||||
for k, v := range districtVisitMap {
|
||||
// 更新渠道存
|
||||
err = channelCodeBlocStatMod.UpsertOneDistrictVisitStat(ctx, k, appid, start, v.DirectVisitCount, v.FissionVisitCount)
|
||||
if err != nil {
|
||||
log.Error("VisitCountMethod UpsertOneDistrictVisitStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RechargeAmountMethod 用户充值
|
||||
func RechargeAmountMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
type districtRechargeUserIds struct {
|
||||
RechangeAmount int64
|
||||
FissionAmount int64
|
||||
DeductionAmount int64
|
||||
}
|
||||
for _, appid := range appIds {
|
||||
rechangeUserMap := make(map[string]*districtRechargeUserIds)
|
||||
// 获取充值金额
|
||||
|
||||
filter := bson.M{"appId": appid, "successAt": bson.M{"$gte": start, "$lt": end}, "districtCode": bson.M{"$gt": ""}}
|
||||
rechargeList, _ := rechargemod.FindManyRechargeInfo(ctx, filter)
|
||||
|
||||
for _, rechargeInfo := range rechargeList {
|
||||
if len(rechargeInfo.DistrictCode) > 0 { // 充值不存在扣量
|
||||
if rechargeInfo.IsDirect {
|
||||
if value, ok := rechangeUserMap[rechargeInfo.DistrictCode]; !ok {
|
||||
rechangeUserMap[rechargeInfo.DistrictCode] = &districtRechargeUserIds{
|
||||
RechangeAmount: rechargeInfo.Money,
|
||||
}
|
||||
} else {
|
||||
value.RechangeAmount += rechargeInfo.Money
|
||||
}
|
||||
} else {
|
||||
if value, ok := rechangeUserMap[rechargeInfo.DistrictCode]; !ok {
|
||||
rechangeUserMap[rechargeInfo.DistrictCode] = &districtRechargeUserIds{
|
||||
FissionAmount: rechargeInfo.Money,
|
||||
}
|
||||
} else {
|
||||
|
||||
value.FissionAmount += rechargeInfo.Money
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 插入数据库
|
||||
for k, v := range rechangeUserMap {
|
||||
// 更新渠道存
|
||||
err := channelCodeBlocStatMod.UpsertOneDistrictRechargeStat(ctx, k, appid, start, v.RechangeAmount, v.FissionAmount, v.DeductionAmount)
|
||||
if err != nil {
|
||||
log.Error("VisitCountMethod UpsertOneDistrictVisitStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewDirectCountMethod 新增
|
||||
func NewDirectCountMethod(ctx context.Context, start time.Time, end time.Time, appIds []int32) error {
|
||||
type districtRegister struct {
|
||||
NewDirectCount int64
|
||||
NewFissionCount int64
|
||||
NewDeductionCount int64
|
||||
}
|
||||
for _, appid := range appIds {
|
||||
rechangeUserMap := make(map[string]*districtRegister)
|
||||
|
||||
// 获取充值金额
|
||||
err := registermod.RegisterUsersInfoByTimeShard(ctx, appid, start, end, utils.GlobalShardHour, func(registerInfo *registermod.RegisterMod) {
|
||||
if len(registerInfo.DistrictCode) > 0 {
|
||||
if registerInfo.IsDeduction {
|
||||
if value, ok := rechangeUserMap[registerInfo.DistrictCode]; !ok {
|
||||
rechangeUserMap[registerInfo.DistrictCode] = &districtRegister{
|
||||
NewDeductionCount: 1,
|
||||
}
|
||||
} else {
|
||||
value.NewDeductionCount += 1
|
||||
}
|
||||
} else {
|
||||
if registerInfo.IsDirect {
|
||||
if value, ok := rechangeUserMap[registerInfo.DistrictCode]; !ok {
|
||||
rechangeUserMap[registerInfo.DistrictCode] = &districtRegister{
|
||||
NewDirectCount: 1,
|
||||
}
|
||||
} else {
|
||||
|
||||
value.NewDirectCount += 1
|
||||
}
|
||||
} else {
|
||||
if value, ok := rechangeUserMap[registerInfo.DistrictCode]; !ok {
|
||||
rechangeUserMap[registerInfo.DistrictCode] = &districtRegister{
|
||||
NewFissionCount: 1,
|
||||
}
|
||||
} else {
|
||||
|
||||
value.NewFissionCount += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
log.Error("NewRechargeCountMethod TotalDistricRechargeAmount ", log.E(err))
|
||||
return err
|
||||
}
|
||||
// 插入数据库
|
||||
for k, v := range rechangeUserMap {
|
||||
// 更新渠道存
|
||||
err := channelCodeBlocStatMod.UpsertOneUserRegisterStat(ctx, k, appid, start, v.NewDirectCount, v.NewFissionCount, v.NewDeductionCount)
|
||||
if err != nil {
|
||||
log.Error("VisitCountMethod UpsertOneDistrictVisitStat ", log.E(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package blocstatdistrict
|
||||
|
||||
import (
|
||||
"context"
|
||||
"stat/common/log"
|
||||
"stat/common/statutils"
|
||||
"stat/common/utils"
|
||||
"stat/models/appInfoMod"
|
||||
statrecordmod "stat/models/statrecord"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
* 主要统计任务:
|
||||
* 1、渠道每天的:直推访问数、裂变访问数、次日留存率、3日留存率、7日留存率。
|
||||
*/
|
||||
func RunStat(defaultStatDate time.Time) error {
|
||||
log.Info("statdistrict stat running...")
|
||||
ctx := context.Background()
|
||||
recordMap := defaultTimeMap(defaultStatDate)
|
||||
|
||||
// 1.获取统计项上次统计的时候(每天执行)
|
||||
recoredResult, err := statrecordmod.LastRecordTimeMap(ctx, statrecordmod.BlocDiscStatJob) //第一次从默认记录时间开始统计
|
||||
if err != nil {
|
||||
log.Error("statdistrict RunStat lastRecordTime failed!", log.E(err))
|
||||
return err
|
||||
}
|
||||
for _, record := range recoredResult {
|
||||
recordMap[record.Item] = record.RecordTime
|
||||
}
|
||||
|
||||
appIds, err := appInfoMod.GetAppIds(ctx)
|
||||
if err != nil {
|
||||
log.Error("statdistrict RunStat GetAppIds failed!", log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
statFrq := 24 * time.Hour // 统计频率
|
||||
curStatTime := utils.BeginOfToday() // 本次统计时间
|
||||
|
||||
for item, lastStatAt := range recordMap {
|
||||
_lastStatAt := lastStatAt
|
||||
for curStatTime.After(_lastStatAt) {
|
||||
end := _lastStatAt.Add(statFrq)
|
||||
|
||||
// 超过本次统计结束时间,则结束
|
||||
if end.After(curStatTime) {
|
||||
end = curStatTime
|
||||
}
|
||||
// 根据时间段统计数据
|
||||
err := runStatMethod(ctx, item, _lastStatAt, end, appIds)
|
||||
if err != nil {
|
||||
log.Error("statdistrict statByTimeRange failed!", log.E(err), log.Any("item", item))
|
||||
return err
|
||||
}
|
||||
_lastStatAt = end
|
||||
//fmt.Println(_lastStatAt)
|
||||
}
|
||||
recordMap[item] = _lastStatAt
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// runStatMethod 调用统计项方法
|
||||
func runStatMethod(ctx context.Context, item string, start, end time.Time, appIds []int32) (err error) {
|
||||
// 1.获取统计方法
|
||||
statMethod, ok := statMethodMap[item]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
//fmt.Println(item)
|
||||
|
||||
// 调用统计方法,获取数据
|
||||
err = statutils.ServerMon.RunWithName(func() error {
|
||||
return statMethod(ctx, start, end, appIds)
|
||||
}, statutils.GetFuncName(statMethod))
|
||||
|
||||
if err != nil {
|
||||
log.Error("statdistrict stat statByTimeRange statMethod failed!", log.Any("statItem", item), log.E(err))
|
||||
return err
|
||||
}
|
||||
|
||||
// 3.更新记录
|
||||
if err := statrecordmod.UpsertItemRecord(ctx, statrecordmod.BlocDiscStatJob, item, end); err != nil {
|
||||
log.Error("statdistrict stat commit UpsertItemRecord failed!", log.E(err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
+10
-24
@@ -8,14 +8,13 @@ import (
|
||||
"stat/common/statutils"
|
||||
"stat/skd/job/advertisejob"
|
||||
applicationjob "stat/skd/job/application"
|
||||
"stat/skd/job/blocstatdaily"
|
||||
"stat/skd/job/blocstatdistrict"
|
||||
"stat/skd/job/limitstat"
|
||||
"stat/skd/job/statdaily"
|
||||
"stat/skd/job/statdailyhour"
|
||||
"stat/skd/job/statdistrict"
|
||||
"stat/skd/job/stathour"
|
||||
"stat/skd/job/statlandpage"
|
||||
"stat/skd/job/statminute"
|
||||
"stat/statg"
|
||||
"time"
|
||||
|
||||
@@ -69,19 +68,11 @@ func Start() {
|
||||
// 日活统计,统计上一天日活,校正
|
||||
_, _ = skdCron.AddFunc("0 35 0 * * ?", func() {
|
||||
statutils.ServerMon.Run1(statdaily.RunStat, defaultStatDate)
|
||||
|
||||
if statg.Conf.ServerIndex.IsMadou() {
|
||||
statutils.ServerMon.Run1(blocstatdaily.RunStat, defaultStatDate)
|
||||
statutils.ServerMon.Run1(blocstatdistrict.RunStat, defaultStatDate)
|
||||
}
|
||||
})
|
||||
|
||||
// 日活统计,统计上一天日活,校正
|
||||
if statg.Conf.ServerIndex.IsMadou() {
|
||||
_, _ = skdCron.AddFunc("0 35 2 * * ?", func() {
|
||||
statutils.ServerMon.Run1(statdistrict.RunStat, defaultStatDate)
|
||||
})
|
||||
}
|
||||
_, _ = skdCron.AddFunc("0 35 2 * * ?", func() {
|
||||
statutils.ServerMon.Run1(statdistrict.RunStat, defaultStatDate)
|
||||
})
|
||||
|
||||
// 日常统计数据、每小时数据
|
||||
_, _ = skdCron.AddFunc("0 0/5 * * * ?", func() {
|
||||
@@ -94,6 +85,11 @@ func Start() {
|
||||
statutils.ServerMon.Run1(stathour.RunStat, defaultStatDate)
|
||||
})
|
||||
|
||||
// 渠道结算
|
||||
_, _ = skdCron.AddFunc("0 0/5 * * * ?", func() {
|
||||
statutils.ServerMon.Run1(statminute.RunStat, defaultStatDate)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// 应用点击统计
|
||||
@@ -101,16 +97,6 @@ func Start() {
|
||||
statutils.ServerMon.Run(applicationjob.StatAppHourClick)
|
||||
})
|
||||
|
||||
// 过期广告
|
||||
_, _ = skdCron.AddFunc("0 0 10 * * ?", func() {
|
||||
statutils.ServerMon.Run(advertisejob.AdvertiseExpireSend)
|
||||
})
|
||||
|
||||
// 过期应用检测告警
|
||||
_, _ = skdCron.AddFunc("0 1 10 * * ?", func() {
|
||||
statutils.ServerMon.Run(advertisejob.ApplicationExpireSend)
|
||||
})
|
||||
|
||||
// 广告配置
|
||||
skdCron.AddFunc("0 0/5 * * * ?", func() {
|
||||
statutils.ServerMon.Run(advertisejob.LoadTgbotsend)
|
||||
@@ -136,5 +122,5 @@ func Stop() {
|
||||
}
|
||||
|
||||
func getDefaultStatDate() (time.Time, error) {
|
||||
return time.ParseInLocation("2006-01-02", "2021-03-01", time.Local)
|
||||
return time.ParseInLocation("2006-01-02", "2026-05-01", time.Local)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user