change getting all promo, now search first promo user activation
This commit is contained in:
parent
6ca31c1a43
commit
e45a21de2e
@ -81,38 +81,35 @@ func (r *StatsRepository) GetStatistics(ctx context.Context, promoCodeID string)
|
|||||||
|
|
||||||
func (r *StatsRepository) GetAllPromoActivations(ctx context.Context, req *codeword_rpc.Time) (*codeword_rpc.PromoActivationResp, error) {
|
func (r *StatsRepository) GetAllPromoActivations(ctx context.Context, req *codeword_rpc.Time) (*codeword_rpc.PromoActivationResp, error) {
|
||||||
var pipeline []bson.M
|
var pipeline []bson.M
|
||||||
pipeline = append(pipeline, []bson.M{
|
pipeline = append(pipeline, bson.M{
|
||||||
{
|
"$project": bson.M{
|
||||||
"$project": bson.M{
|
"_id": 1,
|
||||||
"_id": 1,
|
"usageArray": bson.M{"$objectToArray": "$usageMap"},
|
||||||
"usageArray": bson.M{"$objectToArray": "$usageMap"},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
})
|
||||||
"$unwind": "$usageArray",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"$unwind": "$usageArray.v",
|
|
||||||
},
|
|
||||||
}...)
|
|
||||||
|
|
||||||
if req.To != 0 && req.From != 0 {
|
pipeline = append(pipeline, bson.M{
|
||||||
pipeline = append(pipeline, bson.M{
|
"$unwind": "$usageArray",
|
||||||
"$match": bson.M{
|
})
|
||||||
"usageArray.v.time": bson.M{
|
|
||||||
"$gte": req.From,
|
pipeline = append(pipeline, bson.M{
|
||||||
"$lte": req.To,
|
"$unwind": "$usageArray.v",
|
||||||
},
|
})
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pipeline = append(pipeline, bson.M{
|
pipeline = append(pipeline, bson.M{
|
||||||
"$group": bson.M{
|
"$group": bson.M{
|
||||||
"_id": "$_id",
|
"_id": "$usageArray.v.userID",
|
||||||
|
"promoID": bson.M{"$first": "$_id"},
|
||||||
|
"Time": bson.M{"$first": "$usageArray.v.time"},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
pipeline = append(pipeline, bson.M{
|
||||||
|
"$group": bson.M{
|
||||||
|
"_id": "$promoID",
|
||||||
"users": bson.M{"$push": bson.M{
|
"users": bson.M{"$push": bson.M{
|
||||||
"UserID": "$usageArray.v.userID",
|
"UserID": "$_id",
|
||||||
"Time": "$usageArray.v.time",
|
"Time": "$Time",
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user