Remove 买点 (user acquisition tracking) subsystem
Delete the dataReport SDK, event storage model, and scheduled uploader, along with the reportser/srv_report wrapper services and all ~20 Report* call sites in business code. Also drop the ReportSDKConfig field from the APP config response, the TrackerAppId helper, and the related dataReport yaml config block. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
"videoweb/app/appg"
|
||||
"videoweb/app/service/reportser"
|
||||
"videoweb/pub/common/enum/consts"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
@@ -212,8 +211,6 @@ func Register(ctx context.Context, guestUserId int64, accountNo, email, password
|
||||
if serr != nil {
|
||||
return nil, serr
|
||||
}
|
||||
reportser.ReportUserRegister(guest, ua, ip, "username")
|
||||
reportser.ReportUserLogin(guest, ua, ip, pubdef.LoginTypeAccount)
|
||||
return toLoginResp(ctx, guest, token, true), nil
|
||||
}
|
||||
}
|
||||
@@ -270,8 +267,6 @@ func Register(ctx context.Context, guestUserId int64, accountNo, email, password
|
||||
if serr != nil {
|
||||
return nil, serr
|
||||
}
|
||||
reportser.ReportUserRegister(user, ua, ip, "username")
|
||||
reportser.ReportUserLogin(user, ua, ip, pubdef.LoginTypeAccount)
|
||||
return toLoginResp(ctx, user, token, false), nil
|
||||
}
|
||||
|
||||
@@ -333,7 +328,6 @@ func Login(ctx context.Context, account, password string, ua useragent.UA, ip, c
|
||||
bson.M{usermod.FN.User.Id: user.Id},
|
||||
bson.M{"$set": setDoc},
|
||||
)
|
||||
reportser.ReportUserLogin(user, ua, ip, pubdef.LoginTypeAccount)
|
||||
return toLoginResp(ctx, user, token, true), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"videoweb/app/middleware/reptilerecord"
|
||||
"videoweb/app/middleware/visit"
|
||||
"videoweb/app/service/configser"
|
||||
"videoweb/app/service/reportser"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/netutil"
|
||||
"videoweb/pub/common/srvdef"
|
||||
@@ -137,9 +136,7 @@ func GuestLogin(ctx context.Context, userId int64, ip string, req *GuestLoginReq
|
||||
resp.IsNewUser = isNewUser
|
||||
if isNewUser {
|
||||
visit.RecordDailyVisit(ctx, user.Id, ua, ip)
|
||||
reportser.ReportUserRegister(user, ua, ip, "deviceid")
|
||||
}
|
||||
reportser.ReportUserLogin(user, ua, ip, pubdef.LoginTypeDevice)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2,19 +2,12 @@ package coinser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"videoweb/app/service/rechargeser"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/common/useragent"
|
||||
"videoweb/pub/dataReport"
|
||||
"videoweb/pub/models/eventmod"
|
||||
"videoweb/pub/models/rechargepackagemod"
|
||||
"videoweb/pub/models/usermod"
|
||||
"videoweb/pub/models/vipordermod"
|
||||
@@ -116,8 +109,6 @@ func CreateCoinOrder(ctx context.Context,
|
||||
return nil, serr
|
||||
}
|
||||
|
||||
go reportCoinOrderCreated(order, pkg, ip)
|
||||
|
||||
return &BuyCoinResp{
|
||||
TradeNo: tradeNo,
|
||||
PayUrl: payInfo.PayUrl,
|
||||
@@ -126,65 +117,6 @@ func CreateCoinOrder(ctx context.Context,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func reportCoinOrderCreated(order *vipordermod.VipOrder, pkg *rechargepackagemod.RechargePackage, ip string) {
|
||||
ctx := context.Background()
|
||||
user, _ := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: order.UserId})
|
||||
districtCode := order.DistrictCode
|
||||
if user != nil && strings.TrimSpace(user.DistrictCode) != "" {
|
||||
districtCode = user.DistrictCode
|
||||
}
|
||||
|
||||
sourceKey, sourceName := orderSource(order)
|
||||
ua := order.Client.UA(order.SysType)
|
||||
eventId := newEventId(pubdef.TrackerAppId(), order.UserId, order.TradeNo, order.CreatedAt.Unix())
|
||||
commonField := dataReport.NewCommonField(eventId, dataReport.EventTypeOrderCreated, districtCode, ua, strconv.FormatInt(order.UserId, 10), ip)
|
||||
commonField.Payload = dataReport.JsonRawMessage(&dataReport.OrderCreatedEvent{
|
||||
OrderID: order.TradeNo,
|
||||
OrderType: "coin_purchase",
|
||||
ProductID: strconv.FormatInt(pkg.Id, 10),
|
||||
ProductName: pkg.Name,
|
||||
Amount: dataReport.JsonNumber(order.Amount),
|
||||
Currency: "CNY",
|
||||
CoinQuantity: dataReport.JsonNumber(order.Coin),
|
||||
SourcePageKey: sourceKey,
|
||||
SourcePageName: sourceName,
|
||||
CreateTime: dataReport.JsonNumber(order.CreatedAt.Unix()),
|
||||
})
|
||||
|
||||
eventData, _ := json.Marshal(commonField)
|
||||
if err := eventmod.InsertOneEvent(ctx, &eventmod.Event{
|
||||
EventId: commonField.EventID,
|
||||
EventType: commonField.Event,
|
||||
Data: string(eventData),
|
||||
Status: eventmod.Default,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}); err != nil {
|
||||
log.Error("reportCoinOrderCreated InsertOneEvent failed",
|
||||
log.Any("tradeNo", order.TradeNo), log.E(err))
|
||||
}
|
||||
}
|
||||
|
||||
func orderSource(order *vipordermod.VipOrder) (string, string) {
|
||||
key, name := "deposit", "金币充值"
|
||||
if order != nil && order.Client != nil {
|
||||
if value := strings.TrimSpace(order.Client.SourcePageKey); value != "" {
|
||||
key = value
|
||||
}
|
||||
if value := strings.TrimSpace(order.Client.SourcePageName); value != "" {
|
||||
name = value
|
||||
}
|
||||
}
|
||||
return key, name
|
||||
}
|
||||
|
||||
func newEventId(appId string, uid int64, orderId interface{}, createTime int64) string {
|
||||
input := fmt.Sprintf("%v%v%v%v", appId, uid, orderId, createTime)
|
||||
h := md5.New()
|
||||
h.Write([]byte(input))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
// GetCoinOrderHistory 查询用户金币购买记录
|
||||
func GetCoinOrderHistory(ctx context.Context, userId int64, page, pageSize int64) (vipordermod.VipOrderList, int64, *srvdef.SrvErr) {
|
||||
filter := bson.M{
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"unicode/utf8"
|
||||
"videoweb/app/api/proto"
|
||||
"videoweb/app/service/configser"
|
||||
"videoweb/app/service/reportser"
|
||||
"videoweb/pub/common/enum/redisconst"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/netutil"
|
||||
@@ -126,13 +125,6 @@ func SendComment(ctx context.Context, userId int64, ip string, req *proto.Commen
|
||||
log.Error("评论发布后更新短剧热度失败", log.Any("短剧ID", playletId), log.Any("评论信息", info), log.E(err))
|
||||
return err
|
||||
}
|
||||
chapterId := int64(0)
|
||||
if req.ObjectType == ObjectTypePlayletChapter {
|
||||
chapterId = req.ObjectId
|
||||
}
|
||||
reportser.ReportPlayletComment(ctx, user, playletId, chapterId, text)
|
||||
} else if req.ObjectType == ObjectTypeVideo {
|
||||
reportser.ReportVideoComment(ctx, user, req.ObjectId, text)
|
||||
}
|
||||
// app端发布评论先进入待审核状态,不立即增加业务对象评论数;后台审核通过时再统一同步 countComment
|
||||
return nil
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/netutil"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/dataReport"
|
||||
"videoweb/pub/models/announcementmod"
|
||||
"videoweb/pub/models/cfg"
|
||||
"videoweb/pub/models/ipblackmod"
|
||||
@@ -61,7 +60,6 @@ func init() {
|
||||
|
||||
func Start() {
|
||||
ctx := context.Background()
|
||||
dataReport.StartSDKConfigCron()
|
||||
UpdateConfigInfo(ctx)
|
||||
UpdateAdvitiseDataFromJt()
|
||||
updateIpBlack()
|
||||
@@ -155,7 +153,6 @@ func UpdateConfigInfo(ctx context.Context) {
|
||||
config.DHSiteName = sysCfg.DHSiteName
|
||||
config.DHTitle = sysCfg.DHTitle
|
||||
config.ActressBackGround = netutil.MergeURL(sysCfg.ImgAppCdn, sysCfg.ActressBackGround)
|
||||
config.ReportSDKConfig = dataReport.GetSDKDomainConfig()
|
||||
config.WatermarkImage = sysCfg.WatermarkImage
|
||||
config.CustomerServiceHost = sysCfg.CustomerServiceHost
|
||||
config.ChannelCode = sysCfg.ChannelCode
|
||||
@@ -563,7 +560,6 @@ func GetVideoTagCategoryDataList() []proto.VideoTagCategoryData {
|
||||
return rsl
|
||||
}
|
||||
func Stop() {
|
||||
dataReport.StopSDKConfigCron()
|
||||
skdCron.Stop()
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"videoweb/app/api/proto"
|
||||
"videoweb/app/service/configser"
|
||||
"videoweb/app/service/playletcache"
|
||||
"videoweb/app/service/reportser"
|
||||
"videoweb/app/service/videoser"
|
||||
"videoweb/pub/common/enum/redisconst"
|
||||
"videoweb/pub/common/log"
|
||||
@@ -920,9 +919,6 @@ func SetLike(ctx context.Context, userId int64, req *proto.PlayletLikeSetReq) (*
|
||||
IsLike: operateStatusByFlag(*req.IsLike),
|
||||
CountLike: countLike,
|
||||
}
|
||||
if changed {
|
||||
reportser.ReportPlayletLike(ctx, userId, req.Id, resp.IsLike)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -942,9 +938,6 @@ func SetCollect(ctx context.Context, userId int64, req *proto.PlayletCollectSetR
|
||||
IsCollect: operateStatusByFlag(*req.IsCollect),
|
||||
CountCollect: countCollect,
|
||||
}
|
||||
if changed {
|
||||
reportser.ReportPlayletCollect(ctx, userId, req.Id, resp.IsCollect)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -994,9 +987,6 @@ func SetChapterLike(ctx context.Context, userId int64, req *proto.PlayletChapter
|
||||
IsLike: operateStatusByFlag(*req.IsLike),
|
||||
CountLike: countLike,
|
||||
}
|
||||
if changed {
|
||||
reportser.ReportPlayletChapterLike(ctx, userId, chapter.PlayletId, req.ChapterId, resp.IsLike)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -1016,9 +1006,6 @@ func SetChapterCollect(ctx context.Context, userId int64, req *proto.PlayletChap
|
||||
IsCollect: operateStatusByFlag(*req.IsCollect),
|
||||
CountCollect: countCollect,
|
||||
}
|
||||
if changed {
|
||||
reportser.ReportPlayletChapterCollect(ctx, userId, chapter.PlayletId, req.ChapterId, resp.IsCollect)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -1282,7 +1269,6 @@ func UnlockChapter(ctx context.Context, userId int64, req *proto.PlayletChapterU
|
||||
return nil, srvdef.New(srvdef.DBTransaction, "解锁失败,请稍后重试", "解锁失败,请稍后重试")
|
||||
}
|
||||
updatePlayletChapterUnlockStatsAsync(chapter.PlayletId, chapter.Id)
|
||||
reportser.ReportPlayletUnlock(ctx, user, playlet, chapter, chapter.SingleCoins, user.Recharge, balanceAfter, orderNo)
|
||||
return playletChapterUnlockResp(chapter, balanceAfter, -chapter.SingleCoins), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2,18 +2,11 @@ package rechargeser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/srvdef"
|
||||
"videoweb/pub/common/useragent"
|
||||
"videoweb/pub/dataReport"
|
||||
"videoweb/pub/models/eventmod"
|
||||
"videoweb/pub/models/rechargepackagemod"
|
||||
"videoweb/pub/models/usermod"
|
||||
"videoweb/pub/models/vipordermod"
|
||||
@@ -104,8 +97,6 @@ func CreateOrder(ctx context.Context,
|
||||
return nil, serr
|
||||
}
|
||||
|
||||
go reportOrderCreated(ctx, order, pkg, userId, ip)
|
||||
|
||||
return &SubmitOrderResp{
|
||||
TradeNo: tradeNo,
|
||||
PayUrl: payInfo.PayUrl,
|
||||
@@ -138,56 +129,3 @@ func GetOrderHistory(ctx context.Context, userId int64, page, pageSize int64) (v
|
||||
func GetUserInfo(ctx context.Context, userId int64) (*usermod.User, *srvdef.SrvErr) {
|
||||
return usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
|
||||
}
|
||||
|
||||
func reportOrderCreated(ctx context.Context, order *vipordermod.VipOrder, pkg *rechargepackagemod.RechargePackage, userId int64, ip string) {
|
||||
user, _ := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
|
||||
districtCode := ""
|
||||
if user != nil {
|
||||
districtCode = user.DistrictCode
|
||||
}
|
||||
|
||||
sourceKey, sourceName := "deposit", "金币充值"
|
||||
if order.Client != nil {
|
||||
if value := strings.TrimSpace(order.Client.SourcePageKey); value != "" {
|
||||
sourceKey = value
|
||||
}
|
||||
if value := strings.TrimSpace(order.Client.SourcePageName); value != "" {
|
||||
sourceName = value
|
||||
}
|
||||
}
|
||||
ua := order.Client.UA(order.SysType)
|
||||
eventId := newEventId(pubdef.TrackerAppId(), user.Id, order.TradeNo, order.CreatedAt.Unix())
|
||||
commonField := dataReport.NewCommonField(eventId, dataReport.EventTypeOrderCreated, districtCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
||||
|
||||
commonField.Payload = dataReport.JsonRawMessage(&dataReport.OrderCreatedEvent{
|
||||
OrderID: order.TradeNo,
|
||||
OrderType: "vip_subscription",
|
||||
ProductID: strconv.FormatInt(pkg.Id, 10),
|
||||
ProductName: pkg.Name,
|
||||
Amount: dataReport.JsonNumber(order.Amount),
|
||||
Currency: "CNY",
|
||||
SourcePageKey: sourceKey,
|
||||
SourcePageName: sourceName,
|
||||
CreateTime: dataReport.JsonNumber(order.CreatedAt.Unix()),
|
||||
})
|
||||
|
||||
eventData, _ := json.Marshal(commonField)
|
||||
if err := eventmod.InsertOneEvent(ctx, &eventmod.Event{
|
||||
EventId: commonField.EventID,
|
||||
EventType: commonField.Event,
|
||||
Data: string(eventData),
|
||||
Status: eventmod.Default,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}); err != nil {
|
||||
log.Error("reportOrderCreated InsertOneEvent failed",
|
||||
log.Any("tradeNo", order.TradeNo), log.E(err))
|
||||
}
|
||||
}
|
||||
|
||||
func newEventId(appId string, uid int64, orderId interface{}, createTime int64) string {
|
||||
input := fmt.Sprintf("%v%v%v%v", appId, uid, orderId, createTime)
|
||||
h := md5.New()
|
||||
h.Write([]byte(input))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
@@ -1,559 +0,0 @@
|
||||
package reportser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"videoweb/app/service/playletcache"
|
||||
"videoweb/pub/common"
|
||||
"videoweb/pub/common/enum/consts"
|
||||
"videoweb/pub/common/ipaddr"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/useragent"
|
||||
"videoweb/pub/dataReport"
|
||||
"videoweb/pub/models/eventmod"
|
||||
"videoweb/pub/models/playletchaptermod"
|
||||
"videoweb/pub/models/playletmod"
|
||||
"videoweb/pub/models/usermod"
|
||||
"videoweb/pub/models/videoinformationmod"
|
||||
"videoweb/pub/pubdef"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
const (
|
||||
videoContentTypeVideo = "video"
|
||||
)
|
||||
|
||||
// ReportUserRegister 用户注册事件
|
||||
func ReportUserRegister(user *usermod.User, ua useragent.UA, ip, registerType string) {
|
||||
if user == nil {
|
||||
return
|
||||
}
|
||||
if registerType == "" {
|
||||
registerType = "deviceid"
|
||||
}
|
||||
ua = fillUserUA(user, ua)
|
||||
createAt := user.CreatedAt
|
||||
if !user.RegisterTime.IsZero() {
|
||||
createAt = user.RegisterTime
|
||||
}
|
||||
eventId := newEventId(pubdef.TrackerAppId(), user.Id, "", createAt.Unix())
|
||||
event := dataReport.NewCommonField(eventId, dataReport.EventTypeUserRegister, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
||||
event.Payload = dataReport.JsonRawMessage(&dataReport.UserRegisterEvent{
|
||||
Type: registerType,
|
||||
CreateTime: dataReport.JsonNumber(createAt.Unix()),
|
||||
})
|
||||
insertEvent(event)
|
||||
}
|
||||
|
||||
// ReportUserLogin 用户登录事件
|
||||
func ReportUserLogin(user *usermod.User, ua useragent.UA, ip string, loginType pubdef.LoginType) {
|
||||
if user == nil {
|
||||
return
|
||||
}
|
||||
ua = fillUserUA(user, ua)
|
||||
createTime := time.Now().Unix()
|
||||
eventId := newEventId(pubdef.TrackerAppId(), user.Id, "", createTime)
|
||||
event := dataReport.NewCommonField(eventId, dataReport.EventTypeUserLogin, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
||||
event.Payload = dataReport.JsonRawMessage(&dataReport.UserLoginEvent{
|
||||
Type: loginTypeEventValue(loginType),
|
||||
})
|
||||
insertEvent(event)
|
||||
}
|
||||
|
||||
// ReportPlayletLike 短剧点赞
|
||||
func ReportPlayletLike(ctx context.Context, userId, playletId, flag int64) {
|
||||
reportDramaEvent(ctx, userId, playletId, 0, dataReport.EventTypeDramaLike, flag, "")
|
||||
}
|
||||
|
||||
// ReportVideoLike 视频点赞
|
||||
func ReportVideoLike(ctx context.Context, userId, videoId, flag int64) {
|
||||
reportVideoEvent(ctx, userId, videoId, dataReport.EventTypeVideoLike, flag)
|
||||
}
|
||||
|
||||
// ReportPlayletCollect 短剧收藏
|
||||
func ReportPlayletCollect(ctx context.Context, userId, playletId, flag int64) {
|
||||
reportDramaEvent(ctx, userId, playletId, 0, dataReport.EventTypeDramaCollect, flag, "")
|
||||
}
|
||||
|
||||
// ReportVideoCollect 视频收藏
|
||||
func ReportVideoCollect(ctx context.Context, userId, videoId, flag int64) {
|
||||
reportVideoEvent(ctx, userId, videoId, dataReport.EventTypeVideoCollect, flag)
|
||||
}
|
||||
|
||||
// ReportVideoComment 视频评论
|
||||
func ReportVideoComment(ctx context.Context, user *usermod.User, videoId int64, content string) {
|
||||
if user == nil || videoId <= 0 {
|
||||
return
|
||||
}
|
||||
pub := buildVideoPub(ctx, videoId)
|
||||
if pub.VideoID == "" {
|
||||
return
|
||||
}
|
||||
ua, ip := uaAndIPFromCtx(ctx)
|
||||
ua = fillUserUA(user, ua)
|
||||
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), dataReport.EventTypeVideoComment, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
||||
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoCommentEvent{
|
||||
VideoEventPub: pub,
|
||||
CommentContent: content,
|
||||
})
|
||||
insertEvent(event)
|
||||
}
|
||||
|
||||
// ReportPlayletChapterLike 短剧剧集点赞
|
||||
func ReportPlayletChapterLike(ctx context.Context, userId, playletId, chapterId, flag int64) {
|
||||
reportDramaEvent(ctx, userId, playletId, chapterId, dataReport.EventTypeDramaLike, flag, "")
|
||||
}
|
||||
|
||||
// ReportPlayletChapterCollect 短剧剧集收藏
|
||||
func ReportPlayletChapterCollect(ctx context.Context, userId, playletId, chapterId, flag int64) {
|
||||
reportDramaEvent(ctx, userId, playletId, chapterId, dataReport.EventTypeDramaCollect, flag, "")
|
||||
}
|
||||
|
||||
// ReportPlayletComment 短剧/剧集评论
|
||||
func ReportPlayletComment(ctx context.Context, user *usermod.User, playletId, chapterId int64, content string) {
|
||||
if user == nil || playletId <= 0 {
|
||||
return
|
||||
}
|
||||
pub := buildDramaPub(ctx, playletId, chapterId)
|
||||
if pub.DramaID == "" {
|
||||
return
|
||||
}
|
||||
ua, ip := uaAndIPFromCtx(ctx)
|
||||
ua = fillUserUA(user, ua)
|
||||
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), dataReport.EventTypeDramaComment, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
||||
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaCommentEvent{
|
||||
DramaEventPub: pub,
|
||||
CommentContent: content,
|
||||
})
|
||||
insertEvent(event)
|
||||
}
|
||||
|
||||
// ReportPlayletUnlock 短剧剧集金币解锁:同时上报金币消耗和购买
|
||||
func ReportPlayletUnlock(ctx context.Context, user *usermod.User, playlet *playletmod.Playlet, chapter *playletchaptermod.PlayletChapter, amount, balanceBefore, balanceAfter int64, orderNo string) {
|
||||
if user == nil || playlet == nil || chapter == nil || amount <= 0 {
|
||||
return
|
||||
}
|
||||
if full, err := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: user.Id}); err == nil && full != nil {
|
||||
user = full
|
||||
}
|
||||
ua, ip := uaAndIPFromCtx(ctx)
|
||||
ua = fillUserUA(user, ua)
|
||||
productId := strconv.FormatInt(chapter.Id, 10)
|
||||
productName := playletUnlockProductName(playlet, chapter)
|
||||
reportCoinConsume(user, ua, ip, productId, productName, amount, balanceBefore, balanceAfter, KeyPlayletUnlock, orderNo)
|
||||
reportDramaPurchase(ctx, user, ua, ip, playlet, chapter, amount, orderNo)
|
||||
}
|
||||
|
||||
// ReportPlayletStatusChange 短剧上下架,复用 video_status_change
|
||||
func ReportPlayletStatusChange(playlet *playletmod.Playlet, flag int64) {
|
||||
if playlet == nil || playlet.Id == 0 || flag == 0 {
|
||||
return
|
||||
}
|
||||
typeID, typeName := resolvePlayletType(playlet)
|
||||
event := dataReport.NewCommonField("", dataReport.EventTypeVideoStatusChange, "", useragent.UA{}, "", "")
|
||||
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoStatusChangeEvent{
|
||||
MediaId: playletMediaId(playlet),
|
||||
VideoID: strconv.FormatInt(playlet.Id, 10),
|
||||
VideoTitle: playlet.Title,
|
||||
VideoTypeID: typeID,
|
||||
VideoTypeName: typeName,
|
||||
Flag: dataReport.JsonNumber(flag),
|
||||
})
|
||||
insertEvent(event)
|
||||
}
|
||||
|
||||
// PlayletStatusFlag 短剧上下架映射上报 flag:1上架 2下架
|
||||
func PlayletStatusFlag(status playletmod.Status) int64 {
|
||||
switch status {
|
||||
case playletmod.StatusUp:
|
||||
return 1
|
||||
case playletmod.StatusDown:
|
||||
return 2
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func reportDramaEvent(ctx context.Context, userId, playletId, chapterId int64, eventType string, flag int64, content string) {
|
||||
if userId <= 0 || playletId <= 0 {
|
||||
return
|
||||
}
|
||||
user, err := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
|
||||
if err != nil || user == nil {
|
||||
return
|
||||
}
|
||||
pub := buildDramaPub(ctx, playletId, chapterId)
|
||||
if pub.DramaID == "" {
|
||||
return
|
||||
}
|
||||
ua, ip := uaAndIPFromCtx(ctx)
|
||||
ua = fillUserUA(user, ua)
|
||||
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), eventType, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
||||
switch eventType {
|
||||
case dataReport.EventTypeDramaLike:
|
||||
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaLikeEvent{
|
||||
DramaEventPub: pub,
|
||||
Flag: dataReport.JsonNumber(flag),
|
||||
})
|
||||
case dataReport.EventTypeDramaCollect:
|
||||
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaCollectEvent{
|
||||
DramaEventPub: pub,
|
||||
Flag: dataReport.JsonNumber(flag),
|
||||
})
|
||||
case dataReport.EventTypeDramaComment:
|
||||
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaCommentEvent{
|
||||
DramaEventPub: pub,
|
||||
CommentContent: content,
|
||||
})
|
||||
default:
|
||||
return
|
||||
}
|
||||
insertEvent(event)
|
||||
}
|
||||
|
||||
func reportVideoEvent(ctx context.Context, userId, videoId int64, eventType string, flag int64) {
|
||||
if userId <= 0 || videoId <= 0 {
|
||||
return
|
||||
}
|
||||
user, err := usermod.FindOneUser(ctx, bson.M{usermod.FN.User.Id: userId})
|
||||
if err != nil || user == nil {
|
||||
return
|
||||
}
|
||||
pub := buildVideoPub(ctx, videoId)
|
||||
if pub.VideoID == "" {
|
||||
return
|
||||
}
|
||||
ua, ip := uaAndIPFromCtx(ctx)
|
||||
ua = fillUserUA(user, ua)
|
||||
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), eventType, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
||||
switch eventType {
|
||||
case dataReport.EventTypeVideoLike:
|
||||
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoLikeEvent{
|
||||
VideoEventPub: pub,
|
||||
Flag: dataReport.JsonNumber(flag),
|
||||
})
|
||||
case dataReport.EventTypeVideoCollect:
|
||||
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoCollectEvent{
|
||||
VideoEventPub: pub,
|
||||
Flag: dataReport.JsonNumber(flag),
|
||||
})
|
||||
default:
|
||||
return
|
||||
}
|
||||
insertEvent(event)
|
||||
}
|
||||
|
||||
func reportCoinConsume(user *usermod.User, ua useragent.UA, ip, productId, productName string, amount, balanceBefore, balanceAfter int64, reason Key, orderId string) {
|
||||
if user == nil || amount == 0 {
|
||||
return
|
||||
}
|
||||
if productId == "" {
|
||||
if productName == "" {
|
||||
productName = "金币消耗"
|
||||
}
|
||||
productId = md5String(productName)
|
||||
}
|
||||
createTime := time.Now().Unix()
|
||||
eventId := newEventId(pubdef.TrackerAppId(), user.Id, orderId, createTime)
|
||||
event := dataReport.NewCommonField(eventId, dataReport.EventTypeCoinConsume, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
||||
event.Payload = dataReport.JsonRawMessage(&dataReport.CoinConsumeEvent{
|
||||
ProductID: productId,
|
||||
ProductName: productName,
|
||||
CoinConsumeAmount: dataReport.JsonNumber(amount),
|
||||
CoinBalanceBefore: dataReport.JsonNumber(balanceBefore),
|
||||
CoinBalanceAfter: dataReport.JsonNumber(balanceAfter),
|
||||
ConsumeReasonKey: reason.Key(),
|
||||
ConsumeReasonName: reason.Name(),
|
||||
CreateTime: dataReport.JsonNumber(createTime),
|
||||
OrderId: orderId,
|
||||
})
|
||||
insertEvent(event)
|
||||
}
|
||||
|
||||
func reportDramaPurchase(ctx context.Context, user *usermod.User, ua useragent.UA, ip string, playlet *playletmod.Playlet, chapter *playletchaptermod.PlayletChapter, amount int64, orderId string) {
|
||||
pub := dataReport.DramaEventPub{}
|
||||
if playlet != nil && chapter != nil && chapter.Id > 0 {
|
||||
pub = buildDramaPub(ctx, playlet.Id, chapter.Id)
|
||||
}
|
||||
if pub.DramaID == "" {
|
||||
pub = playletToDramaPub(playlet, chapter)
|
||||
}
|
||||
if pub.DramaID == "" {
|
||||
return
|
||||
}
|
||||
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), dataReport.EventTypeDramaPurchase, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
||||
event.Payload = dataReport.JsonRawMessage(&dataReport.DramaPurchaseEvent{
|
||||
DramaEventPub: pub,
|
||||
CoinQuantity: dataReport.JsonNumber(amount),
|
||||
OrderID: orderId,
|
||||
UnlockType: dataReport.DramaUnlockTypeCoin,
|
||||
})
|
||||
insertEvent(event)
|
||||
}
|
||||
|
||||
func buildDramaPub(ctx context.Context, playletId, chapterId int64) dataReport.DramaEventPub {
|
||||
playlet, err := playletmod.FindOnePlaylet(ctx, bson.M{playletmod.FN.Playlet.Id: playletId}, options.FindOne().SetProjection(bson.D{
|
||||
{Key: playletmod.FN.Playlet.Id, Value: 1},
|
||||
{Key: playletmod.FN.Playlet.Title, Value: 1},
|
||||
{Key: playletmod.FN.Playlet.ThemeIds, Value: 1},
|
||||
{Key: playletmod.FN.Playlet.TagIds, Value: 1},
|
||||
{Key: playletmod.FN.Playlet.TotalEpisode, Value: 1},
|
||||
}))
|
||||
if err != nil || playlet == nil {
|
||||
return dataReport.DramaEventPub{}
|
||||
}
|
||||
chapter := findDramaReportChapter(ctx, playletId, chapterId)
|
||||
return playletToDramaPub(playlet, chapter)
|
||||
}
|
||||
|
||||
// findDramaReportChapter 取上报用剧集。指定了剧集就用该集,短剧维度事件用第一集,保证 drama_id、video_id 都来自剧集。
|
||||
func findDramaReportChapter(ctx context.Context, playletId, chapterId int64) *playletchaptermod.PlayletChapter {
|
||||
projection := options.FindOne().SetProjection(bson.D{
|
||||
{Key: playletchaptermod.FN.PlayletChapter.Id, Value: 1},
|
||||
{Key: playletchaptermod.FN.PlayletChapter.PlayletId, Value: 1},
|
||||
{Key: playletchaptermod.FN.PlayletChapter.MediaContentId, Value: 1},
|
||||
{Key: playletchaptermod.FN.PlayletChapter.Title, Value: 1},
|
||||
{Key: playletchaptermod.FN.PlayletChapter.CurrentEpisode, Value: 1},
|
||||
{Key: playletchaptermod.FN.PlayletChapter.MediaTime, Value: 1},
|
||||
})
|
||||
if chapterId > 0 {
|
||||
chapter, _ := playletchaptermod.FindOnePlayletChapter(ctx, bson.M{playletchaptermod.FN.PlayletChapter.Id: chapterId}, projection)
|
||||
return chapter
|
||||
}
|
||||
chapter, _ := playletchaptermod.FindOnePlayletChapter(ctx, bson.M{playletchaptermod.FN.PlayletChapter.PlayletId: playletId}, projection.SetSort(bson.D{
|
||||
{Key: playletchaptermod.FN.PlayletChapter.CurrentEpisode, Value: 1},
|
||||
{Key: playletchaptermod.FN.PlayletChapter.Id, Value: 1},
|
||||
}))
|
||||
return chapter
|
||||
}
|
||||
|
||||
func buildVideoPub(ctx context.Context, videoId int64) dataReport.VideoEventPub {
|
||||
video, err := videoinformationmod.FindOneVideoInformationWithOptions(ctx, bson.M{videoinformationmod.FN.VideoInformation.Id: videoId}, options.FindOne().SetProjection(bson.D{
|
||||
{Key: videoinformationmod.FN.VideoInformation.Id, Value: 1},
|
||||
{Key: videoinformationmod.FN.VideoInformation.Title, Value: 1},
|
||||
{Key: videoinformationmod.FN.VideoInformation.MediaType, Value: 1},
|
||||
{Key: videoinformationmod.FN.VideoInformation.Video.FileId, Value: 1},
|
||||
{Key: videoinformationmod.FN.VideoInformation.Video.TaskId, Value: 1},
|
||||
{Key: videoinformationmod.FN.VideoInformation.SyncId, Value: 1},
|
||||
}))
|
||||
if err != nil || video == nil {
|
||||
return dataReport.VideoEventPub{}
|
||||
}
|
||||
return videoToVideoPub(video)
|
||||
}
|
||||
|
||||
func videoToVideoPub(video *videoinformationmod.VideoInformation) dataReport.VideoEventPub {
|
||||
if video == nil {
|
||||
return dataReport.VideoEventPub{}
|
||||
}
|
||||
mediaId := video.Video.FileId
|
||||
if mediaId == "" {
|
||||
mediaId = video.Video.TaskId
|
||||
}
|
||||
if mediaId == "" {
|
||||
mediaId = video.SyncId
|
||||
}
|
||||
return dataReport.VideoEventPub{
|
||||
MediaId: mediaId,
|
||||
VideoID: strconv.FormatInt(video.Id, 10),
|
||||
VideoTitle: video.Title,
|
||||
VideoTypeID: strconv.FormatInt(int64(video.MediaType), 10),
|
||||
VideoTypeName: videoMediaTypeName(video.MediaType),
|
||||
VideoContentType: videoContentTypeVideo,
|
||||
}
|
||||
}
|
||||
|
||||
func playletToDramaPub(playlet *playletmod.Playlet, chapter *playletchaptermod.PlayletChapter) dataReport.DramaEventPub {
|
||||
if playlet == nil {
|
||||
return dataReport.DramaEventPub{}
|
||||
}
|
||||
typeID, typeName := resolvePlayletType(playlet)
|
||||
tagKey, tagName := resolvePlayletTags(playlet.TagIds)
|
||||
episode := int64(1)
|
||||
duration := int64(0)
|
||||
dramaID := ""
|
||||
videoID := ""
|
||||
if chapter != nil && chapter.Id > 0 {
|
||||
if chapter.CurrentEpisode > 0 {
|
||||
episode = chapter.CurrentEpisode
|
||||
}
|
||||
duration = chapter.MediaTime
|
||||
dramaID = strconv.FormatInt(chapter.Id, 10)
|
||||
if chapter.MediaContentId > 0 {
|
||||
videoID = strconv.FormatUint(uint64(chapter.MediaContentId), 10)
|
||||
}
|
||||
}
|
||||
return dataReport.DramaEventPub{
|
||||
DramaID: dramaID,
|
||||
DramaTitle: playlet.Title,
|
||||
Episode: dataReport.JsonNumber(episode),
|
||||
VideoID: videoID,
|
||||
TotalEpisode: dataReport.JsonNumber(playlet.TotalEpisode),
|
||||
DramaTypeID: typeID,
|
||||
DramaTypeName: typeName,
|
||||
DramaContentType: dataReport.DramaContentTypeShortDrama,
|
||||
DramaTagKey: tagKey,
|
||||
DramaTagName: tagName,
|
||||
DramaDuration: dataReport.JsonNumber(duration),
|
||||
}
|
||||
}
|
||||
|
||||
func videoMediaTypeName(mediaType videoinformationmod.MediaType) string {
|
||||
switch mediaType {
|
||||
case videoinformationmod.MediaType_Video:
|
||||
return "视频"
|
||||
case videoinformationmod.MediaType_Collection:
|
||||
return "合集"
|
||||
case videoinformationmod.MediaType_Advitise:
|
||||
return "广告"
|
||||
case videoinformationmod.MediaType_VideoV2:
|
||||
return "视频"
|
||||
default:
|
||||
return "视频"
|
||||
}
|
||||
}
|
||||
|
||||
func playletUnlockProductName(playlet *playletmod.Playlet, chapter *playletchaptermod.PlayletChapter) string {
|
||||
title := ""
|
||||
if playlet != nil {
|
||||
title = playlet.Title
|
||||
}
|
||||
if chapter == nil {
|
||||
return title
|
||||
}
|
||||
if chapter.Title != "" {
|
||||
if title == "" {
|
||||
return chapter.Title
|
||||
}
|
||||
return fmt.Sprintf("%s %s", title, chapter.Title)
|
||||
}
|
||||
if chapter.CurrentEpisode > 0 {
|
||||
if title == "" {
|
||||
return fmt.Sprintf("第%d集", chapter.CurrentEpisode)
|
||||
}
|
||||
return fmt.Sprintf("%s 第%d集", title, chapter.CurrentEpisode)
|
||||
}
|
||||
return title
|
||||
}
|
||||
|
||||
func playletMediaId(playlet *playletmod.Playlet) string {
|
||||
if playlet == nil || playlet.MediaCenterId == 0 {
|
||||
return ""
|
||||
}
|
||||
return strconv.FormatUint(uint64(playlet.MediaCenterId), 10)
|
||||
}
|
||||
|
||||
func resolvePlayletType(playlet *playletmod.Playlet) (string, string) {
|
||||
if playlet == nil || len(playlet.ThemeIds) == 0 {
|
||||
return "default", "默认分类"
|
||||
}
|
||||
id := playlet.ThemeIds[0]
|
||||
if id <= 0 {
|
||||
return "default", "默认分类"
|
||||
}
|
||||
name := strings.TrimSpace(playletcache.ThemeNameMap([]int64{id})[id])
|
||||
if name == "" {
|
||||
name = "默认分类"
|
||||
}
|
||||
return strconv.FormatInt(id, 10), name
|
||||
}
|
||||
|
||||
func resolvePlayletTags(ids []int64) (string, string) {
|
||||
keys := make([]string, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
if id > 0 {
|
||||
keys = append(keys, strconv.FormatInt(id, 10))
|
||||
}
|
||||
}
|
||||
if len(keys) == 0 {
|
||||
return "default", "默认标签"
|
||||
}
|
||||
nameMap := playletcache.TagNameMap(ids)
|
||||
names := make([]string, 0, len(keys))
|
||||
for _, id := range ids {
|
||||
if id <= 0 {
|
||||
continue
|
||||
}
|
||||
name := strings.TrimSpace(nameMap[id])
|
||||
if name == "" {
|
||||
name = strconv.FormatInt(id, 10)
|
||||
}
|
||||
names = append(names, name)
|
||||
}
|
||||
return strings.Join(keys, ","), strings.Join(names, ",")
|
||||
}
|
||||
|
||||
func uaAndIPFromCtx(ctx context.Context) (useragent.UA, string) {
|
||||
gc, ok := ctx.(*gin.Context)
|
||||
if !ok {
|
||||
if v := ctx.Value(consts.CtxUA); v != nil {
|
||||
if ua, ok := v.(useragent.UA); ok {
|
||||
return ua, ""
|
||||
}
|
||||
}
|
||||
return useragent.UA{}, ""
|
||||
}
|
||||
ua, _ := common.GetUA(gc)
|
||||
return ua, ipaddr.ResolveClientIP(gc)
|
||||
}
|
||||
|
||||
func fillUserUA(user *usermod.User, ua useragent.UA) useragent.UA {
|
||||
if user == nil {
|
||||
return ua
|
||||
}
|
||||
if ua.DevID == "" {
|
||||
ua.DevID = user.DevID
|
||||
}
|
||||
if ua.DevType == "" {
|
||||
ua.DevType = user.Device
|
||||
}
|
||||
if ua.SysType == "" {
|
||||
ua.SysType = user.SysType
|
||||
}
|
||||
return ua
|
||||
}
|
||||
|
||||
func loginTypeEventValue(loginType pubdef.LoginType) string {
|
||||
switch loginType {
|
||||
case pubdef.LoginTypeAccount:
|
||||
return "username"
|
||||
case pubdef.LoginTypeEmail:
|
||||
return "email"
|
||||
default:
|
||||
return "deviceid"
|
||||
}
|
||||
}
|
||||
|
||||
func newEventId(appId string, uid int64, orderId interface{}, createTime int64) string {
|
||||
input := fmt.Sprintf("%v%v%v%v", appId, uid, orderId, createTime)
|
||||
return md5String(input)
|
||||
}
|
||||
|
||||
func md5String(input string) string {
|
||||
h := md5.New()
|
||||
h.Write([]byte(input))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
func insertEvent(event dataReport.CommonField) {
|
||||
b, _ := json.Marshal(event)
|
||||
if err := eventmod.InsertOneEvent(context.Background(), &eventmod.Event{
|
||||
EventId: event.EventID,
|
||||
EventType: event.Event,
|
||||
Data: string(b),
|
||||
Status: eventmod.Default,
|
||||
CreatedAt: time.Now(),
|
||||
UpdatedAt: time.Now(),
|
||||
}); err != nil {
|
||||
log.Error("reportser insertEvent failed", log.Any("eventType", event.Event), log.Any("eventId", event.EventID), log.E(err))
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package reportser
|
||||
|
||||
type Key string
|
||||
|
||||
const (
|
||||
KeyPlayletUnlock Key = "playlet_unlock" // 短剧剧集解锁
|
||||
KeyCoinConsume Key = "coin_consume" // 金币消耗
|
||||
)
|
||||
|
||||
var keyMap = map[Key]string{
|
||||
KeyPlayletUnlock: "短剧解锁",
|
||||
KeyCoinConsume: "金币消耗",
|
||||
}
|
||||
|
||||
func (p Key) Name() string {
|
||||
return keyMap[p]
|
||||
}
|
||||
|
||||
func (p Key) Key() string {
|
||||
return string(p)
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"strings"
|
||||
"videoweb/app/api/proto"
|
||||
"videoweb/app/service/configser"
|
||||
"videoweb/app/service/reportser"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/netutil"
|
||||
"videoweb/pub/common/srvdef"
|
||||
@@ -255,9 +254,6 @@ func SetLike(ctx context.Context, userId int64, req *proto.VideoLikeSetReq) (*pr
|
||||
IsLike: videoOperateStatusByFlag(*req.IsLike),
|
||||
CountLike: countLike,
|
||||
}
|
||||
if changed {
|
||||
reportser.ReportVideoLike(ctx, userId, req.Id, resp.IsLike)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -277,9 +273,6 @@ func SetCollect(ctx context.Context, userId int64, req *proto.VideoCollectSetReq
|
||||
IsCollect: videoOperateStatusByFlag(*req.IsCollect),
|
||||
CountCollect: countCollect,
|
||||
}
|
||||
if changed {
|
||||
reportser.ReportVideoCollect(ctx, userId, req.Id, resp.IsCollect)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user