删除数据上报逻辑
移除 pub/dataReport、reportser、srv_report、上报定时任务及 eventmod 事件表, 以及注册/登录/点赞/收藏/评论/解锁/订单/上下架等处的上报调用和 reportSdkConfig 配置下发。 Co-Authored-By: Claude Opus 5.5 (1M context) <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"
|
||||
@@ -210,8 +209,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
|
||||
}
|
||||
}
|
||||
@@ -268,8 +265,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
|
||||
}
|
||||
|
||||
@@ -332,7 +327,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"
|
||||
@@ -138,9 +137,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
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
@@ -123,11 +122,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)
|
||||
// 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()
|
||||
@@ -154,7 +152,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
|
||||
@@ -561,7 +558,6 @@ func GetVideoTagCategoryDataList() []proto.VideoTagCategoryData {
|
||||
return rsl
|
||||
}
|
||||
func Stop() {
|
||||
dataReport.StopSDKConfigCron()
|
||||
skdCron.Stop()
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,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"
|
||||
@@ -654,9 +653,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
|
||||
}
|
||||
|
||||
@@ -676,9 +672,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
|
||||
}
|
||||
|
||||
@@ -728,9 +721,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
|
||||
}
|
||||
|
||||
@@ -750,9 +740,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
|
||||
}
|
||||
|
||||
@@ -1014,7 +1001,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,19 +2,11 @@ package rechargeser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"videoweb/app/service/rechargeser/jiahua"
|
||||
"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 +96,6 @@ func CreateOrder(ctx context.Context,
|
||||
return nil, serr
|
||||
}
|
||||
|
||||
go reportOrderCreated(ctx, order, pkg, userId, ip)
|
||||
|
||||
return &SubmitOrderResp{
|
||||
TradeNo: tradeNo,
|
||||
PayUrl: payInfo.PayUrl,
|
||||
@@ -138,45 +128,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
|
||||
}
|
||||
|
||||
ua := useragent.UA{SysType: 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",
|
||||
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,386 +0,0 @@
|
||||
package reportser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
"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/playletcategorymod"
|
||||
"videoweb/pub/models/playletchaptermod"
|
||||
"videoweb/pub/models/playletmod"
|
||||
"videoweb/pub/models/usermod"
|
||||
"videoweb/pub/pubdef"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
)
|
||||
|
||||
const videoContentTypePlaylet = "short_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 短剧点赞,复用 video_like
|
||||
func ReportPlayletLike(ctx context.Context, userId, playletId, flag int64) {
|
||||
reportPlayletVideoEvent(ctx, userId, playletId, 0, dataReport.EventTypeVideoLike, flag, "")
|
||||
}
|
||||
|
||||
// ReportPlayletCollect 短剧收藏,复用 video_collect
|
||||
func ReportPlayletCollect(ctx context.Context, userId, playletId, flag int64) {
|
||||
reportPlayletVideoEvent(ctx, userId, playletId, 0, dataReport.EventTypeVideoCollect, flag, "")
|
||||
}
|
||||
|
||||
// ReportPlayletChapterLike 短剧剧集点赞,复用 video_like
|
||||
func ReportPlayletChapterLike(ctx context.Context, userId, playletId, chapterId, flag int64) {
|
||||
reportPlayletVideoEvent(ctx, userId, playletId, chapterId, dataReport.EventTypeVideoLike, flag, "")
|
||||
}
|
||||
|
||||
// ReportPlayletChapterCollect 短剧剧集收藏,复用 video_collect
|
||||
func ReportPlayletChapterCollect(ctx context.Context, userId, playletId, chapterId, flag int64) {
|
||||
reportPlayletVideoEvent(ctx, userId, playletId, chapterId, dataReport.EventTypeVideoCollect, flag, "")
|
||||
}
|
||||
|
||||
// ReportPlayletComment 短剧/剧集评论,复用 video_comment
|
||||
func ReportPlayletComment(ctx context.Context, user *usermod.User, playletId, chapterId int64, content string) {
|
||||
if user == nil || playletId <= 0 {
|
||||
return
|
||||
}
|
||||
pub := buildPlayletVideoPub(ctx, playletId, chapterId)
|
||||
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)
|
||||
}
|
||||
|
||||
// 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)
|
||||
reportPlayletPurchase(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(context.Background(), 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 reportPlayletVideoEvent(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 := buildPlayletVideoPub(ctx, playletId, chapterId)
|
||||
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),
|
||||
})
|
||||
case dataReport.EventTypeVideoComment:
|
||||
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoCommentEvent{
|
||||
VideoEventPub: pub,
|
||||
CommentContent: content,
|
||||
})
|
||||
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 reportPlayletPurchase(user *usermod.User, ua useragent.UA, ip string, playlet *playletmod.Playlet, chapter *playletchaptermod.PlayletChapter, amount int64, orderId string) {
|
||||
pub := playletToVideoPub(playlet, chapter)
|
||||
event := dataReport.NewCommonField(dataReport.GenerateGlobalEventID(), dataReport.EventTypeVideoPurchase, user.DistrictCode, ua, strconv.FormatInt(user.Id, 10), ip)
|
||||
event.Payload = dataReport.JsonRawMessage(&dataReport.VideoPurchaseEvent{
|
||||
MediaId: pub.MediaId,
|
||||
VideoID: pub.VideoID,
|
||||
VideoTitle: pub.VideoTitle,
|
||||
VideoTypeID: pub.VideoTypeID,
|
||||
VideoTypeName: pub.VideoTypeName,
|
||||
VideoContentType: pub.VideoContentType,
|
||||
RecommendTraceId: pub.RecommendTraceId,
|
||||
CoinQuantity: dataReport.JsonNumber(amount),
|
||||
OrderID: orderId,
|
||||
})
|
||||
insertEvent(event)
|
||||
}
|
||||
|
||||
func buildPlayletVideoPub(ctx context.Context, playletId, chapterId int64) dataReport.VideoEventPub {
|
||||
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.CategoryIds, Value: 1},
|
||||
{Key: playletmod.FN.Playlet.MediaCenterId, Value: 1},
|
||||
}))
|
||||
if err != nil || playlet == nil {
|
||||
return dataReport.VideoEventPub{}
|
||||
}
|
||||
var chapter *playletchaptermod.PlayletChapter
|
||||
if chapterId > 0 {
|
||||
chapter, _ = playletchaptermod.FindOnePlayletChapter(ctx, bson.M{playletchaptermod.FN.PlayletChapter.Id: chapterId}, options.FindOne().SetProjection(bson.D{
|
||||
{Key: playletchaptermod.FN.PlayletChapter.Id, Value: 1},
|
||||
{Key: playletchaptermod.FN.PlayletChapter.PlayletId, Value: 1},
|
||||
{Key: playletchaptermod.FN.PlayletChapter.Title, Value: 1},
|
||||
{Key: playletchaptermod.FN.PlayletChapter.CurrentEpisode, Value: 1},
|
||||
}))
|
||||
}
|
||||
return playletToVideoPub(playlet, chapter)
|
||||
}
|
||||
|
||||
func playletToVideoPub(playlet *playletmod.Playlet, chapter *playletchaptermod.PlayletChapter) dataReport.VideoEventPub {
|
||||
if playlet == nil {
|
||||
return dataReport.VideoEventPub{}
|
||||
}
|
||||
typeID, typeName := resolvePlayletType(context.Background(), playlet)
|
||||
videoID := strconv.FormatInt(playlet.Id, 10)
|
||||
title := playlet.Title
|
||||
if chapter != nil && chapter.Id > 0 {
|
||||
videoID = strconv.FormatInt(chapter.Id, 10)
|
||||
title = playletUnlockProductName(playlet, chapter)
|
||||
}
|
||||
return dataReport.VideoEventPub{
|
||||
MediaId: playletMediaId(playlet),
|
||||
VideoID: videoID,
|
||||
VideoTitle: title,
|
||||
VideoTypeID: typeID,
|
||||
VideoTypeName: typeName,
|
||||
VideoContentType: videoContentTypePlaylet,
|
||||
}
|
||||
}
|
||||
|
||||
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(ctx context.Context, playlet *playletmod.Playlet) (string, string) {
|
||||
if playlet == nil || len(playlet.CategoryIds) == 0 {
|
||||
return "default", "默认分类"
|
||||
}
|
||||
queryCtx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
||||
defer cancel()
|
||||
category, err := playletcategorymod.FindOnePlayletCategory(queryCtx, bson.M{
|
||||
playletcategorymod.FN.PlayletCategory.Id: playlet.CategoryIds[0],
|
||||
})
|
||||
if err != nil || category == nil {
|
||||
return "default", "默认分类"
|
||||
}
|
||||
return strconv.FormatInt(category.Id, 10), category.Name
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user