customer/internal/utils/promo_LTV.go

35 lines
991 B
Go
Raw Normal View History

2024-04-26 15:49:40 +00:00
package utils
import (
"go.mongodb.org/mongo-driver/bson"
2024-11-18 07:23:41 +00:00
codeword_rpc "gitea.pena/PenaSide/customer/internal/proto/codeword"
2024-04-26 15:49:40 +00:00
"time"
)
func MatchGen(codewordData map[string][]*codeword_rpc.PromoActivationResp_UserTime, from, to int64) bson.M {
2024-04-26 15:49:40 +00:00
userActivations := make(map[string]int64)
for _, values := range codewordData {
for _, activation := range values {
2024-04-26 15:49:40 +00:00
userActivations[activation.UserID] = activation.Time
}
}
var conditions []bson.M
for userID, activation := range userActivations {
var condition bson.M
if activation < from {
condition = bson.M{"userId": userID, "createdAt": bson.M{"$gte": time.Unix(from, 0), "$lte": time.Unix(to, 0)}, "key": "payment.succeeded"}
} else {
condition = bson.M{"userId": userID, "createdAt": bson.M{"$gte": time.Unix(activation, 0), "$lte": time.Unix(to, 0)}, "key": "payment.succeeded"}
}
conditions = append(conditions, condition)
}
match := bson.M{
"$match": bson.M{"$or": conditions},
}
return match
}