bindbox-game/internal/api/admin/activity_commitment_admin.go
win 8d1eef2f7f fix(channel): 修复渠道统计GMV重复计数和商城直购误计入
1. 排除商城直购(source_type=1):GMV和成本过滤条件从IN(1,2,3,4)改为IN(2,3,4)
2. 排除次卡免费使用订单(actual_amount=0):避免购买次卡和使用次卡双重计入GMV
   - source_type=4 一番赏使用次卡:1578单 44032元重复
   - source_type=3 对对碰使用次卡:422单 7042元重复
   - 合计去除51074元虚增GMV(29.1%)
3. 成本过滤条件同步修正:source_type IN(2,3,4),total_amount>0

修正后:GMV从175600降至124527元,毛利率从37.4%回到真实的11.8%
2026-03-16 21:41:39 +08:00

114 lines
3.9 KiB
Go
Executable File

package admin
import (
"net/http"
"strconv"
"bindbox-game/internal/code"
"bindbox-game/internal/pkg/core"
"bindbox-game/internal/repository/mysql/dao"
activitysvc "bindbox-game/internal/service/activity"
)
type activityCommitGenerateResp struct {
SeedVersion int32 `json:"seed_version"`
}
type activityCommitSummaryResp struct {
SeedVersion int32 `json:"seed_version"`
Algo string `json:"algo"`
HasSeed bool `json:"has_seed"`
LenSeedMaster int `json:"len_seed_master"`
LenSeedHash int `json:"len_seed_hash"`
LenItemsRoot int `json:"len_items_root"`
ItemsRootHex string `json:"items_root_hex"`
}
type activityCredentialResp struct {
SeedMasterHex string `json:"seed_master_hex"`
SeedHashHex string `json:"seed_hash_hex"`
ItemsRootHex string `json:"items_root_hex"`
}
func (h *handler) GenerateActivityCommitmentGeneral() core.HandlerFunc {
return func(ctx core.Context) {
activityID, err := strconv.ParseInt(ctx.Param("activity_id"), 10, 64)
if err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递活动ID"))
return
}
svc := activitysvc.NewActivityCommitmentService(dao.Use(h.repo.GetDbR()), dao.Use(h.repo.GetDbW()), h.repo)
ver, e := svc.Generate(ctx.RequestContext(), activityID)
if e != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, 170301, e.Error()))
return
}
ctx.Payload(&activityCommitGenerateResp{SeedVersion: ver})
}
}
func (h *handler) GetActivityCommitmentSummaryGeneral() core.HandlerFunc {
return func(ctx core.Context) {
activityID, err := strconv.ParseInt(ctx.Param("activity_id"), 10, 64)
if err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递活动ID"))
return
}
svc := activitysvc.NewActivityCommitmentService(dao.Use(h.repo.GetDbR()), dao.Use(h.repo.GetDbW()), h.repo)
sum, e := svc.Summary(ctx.RequestContext(), activityID)
if e != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, 170302, e.Error()))
return
}
var lenMaster, lenHash, lenRoot *int
_ = h.repo.GetDbR().Raw("SELECT LENGTH(commitment_seed_master) FROM activities WHERE id=?", activityID).Scan(&lenMaster)
_ = h.repo.GetDbR().Raw("SELECT LENGTH(commitment_seed_hash) FROM activities WHERE id=?", activityID).Scan(&lenHash)
_ = h.repo.GetDbR().Raw("SELECT LENGTH(commitment_items_root) FROM activities WHERE id=?", activityID).Scan(&lenRoot)
var itemsHex *string
_ = h.repo.GetDbR().Raw("SELECT HEX(commitment_items_root) FROM activities WHERE id=?", activityID).Scan(&itemsHex)
lm, lh, lr := 0, 0, 0
if lenMaster != nil {
lm = *lenMaster
}
if lenHash != nil {
lh = *lenHash
}
if lenRoot != nil {
lr = *lenRoot
}
ih := ""
if itemsHex != nil {
ih = *itemsHex
}
ctx.Payload(&activityCommitSummaryResp{SeedVersion: sum.SeedVersion, Algo: sum.Algo, HasSeed: sum.HasSeed, LenSeedMaster: lm, LenSeedHash: lh, LenItemsRoot: lr, ItemsRootHex: ih})
}
}
func (h *handler) GetActivityCredential() core.HandlerFunc {
return func(ctx core.Context) {
activityID, err := strconv.ParseInt(ctx.Param("activity_id"), 10, 64)
if err != nil {
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "未传递活动ID"))
return
}
var seedMasterHex, seedHashHex, itemsRootHex *string
_ = h.repo.GetDbR().Raw("SELECT HEX(commitment_seed_master) FROM activities WHERE id=?", activityID).Scan(&seedMasterHex)
_ = h.repo.GetDbR().Raw("SELECT HEX(commitment_seed_hash) FROM activities WHERE id=?", activityID).Scan(&seedHashHex)
_ = h.repo.GetDbR().Raw("SELECT HEX(commitment_items_root) FROM activities WHERE id=?", activityID).Scan(&itemsRootHex)
resp := &activityCredentialResp{}
if seedMasterHex != nil {
resp.SeedMasterHex = *seedMasterHex
}
if seedHashHex != nil {
resp.SeedHashHex = *seedHashHex
}
if itemsRootHex != nil {
resp.ItemsRootHex = *itemsRootHex
}
ctx.Payload(resp)
}
}