Files
stat_center/models/botdailyhourstat/helper.go
T
2026-11-14 11:24:19 +08:00

798 lines
46 KiB
Go
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package botdailyhourstat
import (
"errors"
"fmt"
"stat/common/statutils"
"time"
)
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, lastWeek *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 += s.DisplayCompareText("9️⃣", compare, lastWeek)
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 += s.DisplayCompareText("6️⃣", compare, lastWeek)
text += fmt.Sprintf("🆚【%s】同比数据未找到\n", appName)
}
return text, title, descript
}
// compareMetric 核心对比指标。数据机器人汇报末尾的"核心对比"块用,只挑最常看的几项;
// 全量指标在上面各段落里已经逐行带了同比涨跌,这里不重复。
type compareMetric struct {
Name string
IsMoney bool // true 表示底层值的单位是"分",展示前要除以 100
Pick func(*BotHourStat) int64
}
var compareMetrics = []compareMetric{
{Name: "当日充值", IsMoney: true, Pick: func(s *BotHourStat) int64 { return s.TodayStat.Recharge.Value() }},
{Name: "当日新增", Pick: func(s *BotHourStat) int64 { return s.TodayStat.Register.Count() }},
{Name: "当日日活", Pick: func(s *BotHourStat) int64 { return s.TodayStat.Visit.Count() }},
{Name: "小时充值", IsMoney: true, Pick: func(s *BotHourStat) int64 { return s.HourStat.Recharge.Value() }},
{Name: "小时新增", Pick: func(s *BotHourStat) int64 { return s.HourStat.Register.Count() }},
}
// weekdayCN 星期的中文名,用来拼"周三"这种基准时间标签
var weekdayCN = [...]string{"日", "一", "二", "三", "四", "五", "六"}
// formatRate 把万分比涨跌渲染成带箭头的百分数,箭头用法和 LineCount 保持一致。
// 这里按万分比算而不是沿用 LineCount 的千分比: 千分比只能给出一位小数,
// 23.45% 会被截成 23.40%,而这一块就是专门拿来看涨跌的。
func formatRate(bp int64) string {
v := float64(bp) / 100
switch {
case v < 0:
return fmt.Sprintf("⬇%.2f%%", v)
case v > 0:
return fmt.Sprintf("⬆+%.2f%%", v)
default:
return fmt.Sprintf("%.2f%%", v)
}
}
// divisor 该指标展示时的除数
func (m compareMetric) divisor() int64 {
if m.IsMoney {
return 100
}
return 1
}
// compareCell 渲染一个指标相对某一期基准的涨跌幅。
// base 为 nil 表示那一期的记录没查到;基准为 0 时算不出涨跌幅,
// 写 -- 而不是一个看起来正常的 0.00%。
func compareCell(label string, m compareMetric, curr int64, base *BotHourStat) string {
if base == nil {
return fmt.Sprintf("%s:无数据", label)
}
baseValue := m.Pick(base)
if baseValue == 0 {
return fmt.Sprintf("%s:--", label)
}
bp := (curr - baseValue) * 10000 / baseValue
return fmt.Sprintf("%s:%s", label, formatRate(bp))
}
// hourDesc 把小时对齐的时点写成"11-14 周六 15点"
func hourDesc(t time.Time) string {
return fmt.Sprintf("%s 周%s %d点", t.Format("01-02"), weekdayCN[t.Weekday()], t.Hour())
}
// compareDesc 基准时间的可读描述。不重复写小时(两期基准都跟当日同一个小时),
// 但保留星期: 环比是整七天前,星期几必然和当日一致,写出来才能一眼看出没错位。
// 记录没查到时直接在标签上标出来,免得看到一排"无数据"还要猜是哪天的。
func compareDesc(want time.Time, got *BotHourStat) string {
desc := fmt.Sprintf("%s 周%s", want.Format("01-02"), weekdayCN[want.Weekday()])
if got == nil {
return desc + "(无数据)"
}
return desc
}
// DisplayCompareText 汇报末尾的"核心对比"块。
// 业务口径: 同比 = 对比昨天同一小时, 环比 = 对比上周当日同一小时。
// 这个叫法和财务上的习惯正好相反,是按需求方的要求定的,不要"纠正"过来。
// 两期基准都拿不到时返回空串,不往汇报里塞一块全是"无数据"的内容。
func (s *BotHourStat) DisplayCompareText(index string, yesterday, lastWeek *BotHourStat) string {
if s == nil || (yesterday == nil && lastWeek == nil) {
return ""
}
text := fmt.Sprintf("%s核心对比:\n", index)
text += fmt.Sprintf("┣当日:%s\n", hourDesc(s.SumDate))
text += fmt.Sprintf("┣基准:环比 %s / 同比 %s\n",
compareDesc(s.SumDate.AddDate(0, 0, -7), lastWeek),
compareDesc(s.SumDate.AddDate(0, 0, -1), yesterday))
for _, m := range compareMetrics {
curr := m.Pick(s)
text += fmt.Sprintf("┣%s:%d %s %s\n", m.Name, curr/m.divisor(),
compareCell("环比", m, curr, lastWeek),
compareCell("同比", m, curr, yesterday))
}
return text
}