codeword/internal/models/bonus.go
2024-04-09 22:03:20 +03:00

109 lines
5.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package models
import (
"go.mongodb.org/mongo-driver/bson/primitive"
"time"
)
type PromoCode struct {
ID primitive.ObjectID `json:"id" bson:"_id"`
Codeword string `json:"codeword" bson:"codeword"` // то, что будет вводить пользователь, чтобы получить плюшки
Description string `json:"description" bson:"description"` // описание, необходимое менеджеру в админке
Greetings string `json:"greetings" bson:"greetings"` // текст, выдаваемый пользователю в ответ на активацию промокода
DueTo int64 `json:"dueTo" bson:"dueTo"` // таймштамп времени окончания работы активации промокода
ActivationCount int64 `json:"activationCount" bson:"activationCount"` // предел количества активаций промокода
ActivationLimit int64 `json:"activationLimit" bson:"activationLimit"` // лимит если 0 то без лимита
Bonus struct {
Privilege struct {
PrivilegeID string `json:"privilegeID" bson:"privilegeID"` // айдишник привилегии, которая будет выдаваться
Amount uint64 `json:"amount" bson:"amount"` // количество
ServiceKey string `json:"serviceKey" bson:"serviceKey"` // тип сервиса
} `json:"privilege" bson:"privilege"`
Discount struct {
Layer uint32 `json:"layer" bson:"layer"` // 1|2
Factor float64 `json:"factor" bson:"factor"` // процент скидки, вернее множитель, при котором достигается этот процент скидки
Target string `json:"target" bson:"target"` // PrivilegeID или ServiceKey в зависимости от слоя
Threshold int64 `json:"threshold" bson:"threshold"` // граничное значение, при пересечении которого применяется эта скидка
} `json:"discount" bson:"discount"`
} `json:"bonus" bson:"bonus"`
Outdated bool `json:"outdated" bson:"outdated"`
OffLimit bool `json:"offLimit" bson:"offLimit"`
Delete bool `json:"delete" bson:"delete"`
CreatedAt time.Time `json:"createdAt" bson:"createdAt"`
FastLinks []string `json:"fastLinks" bson:"fastLinks"`
}
type ReqEditPromoCode struct {
ID string `json:"id" bson:"_id"` // айдишник промокода, который обновляем
Description *string `json:"description,omitempty" bson:"description"` // описание, необходимое менеджеру в админке
Greetings *string `json:"greetings,omitempty" bson:"greetings"` // текст, выдаваемый пользователю в ответ на активацию промокода
DueTo *int64 `json:"dueTo,omitempty" bson:"dueTo"` // таймштамп времени окончания работы активации промокода
ActivationCount *int64 `json:"activationCount,omitempty" bson:"activationCount"` // предел количества активаций промокода
ActivationLimit *int64 `json:"activationLimit,omitempty" bson:"activationLimit"` // лимит если 0 то без лимита
Delete *bool `json:"delete,omitempty" bson:"delete"`
Bonus *struct {
Privilege *struct {
PrivilegeID string `json:"privilegeID,omitempty" bson:"privilegeID"`
Amount uint64 `json:"amount,omitempty" bson:"amount"`
ServiceKey string `json:"serviceKey,omitempty" bson:"serviceKey"` // тип сервиса
} `json:"privilege,omitempty" bson:"privilege"`
Discount *struct {
Layer int `json:"layer,omitempty" bson:"layer"`
Factor float64 `json:"factor,omitempty" bson:"factor"`
Target string `json:"target,omitempty" bson:"target"`
Threshold int64 `json:"threshold,omitempty" bson:"threshold"`
} `json:"discount,omitempty" bson:"discount"`
} `json:"bonus,omitempty" bson:"bonus"`
}
type GetPromoCodesListReqFilter struct {
Text string `json:"text"` // полнотекстовый поиск пo Codeword, Decription, Greetings полям
Active bool `json:"active"` // если true, то выбирать deleted==false && outdated== false && offlimit == false
}
type GetPromoCodesListReq struct {
Page int `json:"page"` //номер страницы выборки. начинается с 0. по сути, skip для выборки из mongodb
Limit int `json:"limit"` //размер страницы выборки. больше 10, меньше 250. отвечает за skip = page*limit, и за limit
Filter GetPromoCodesListReqFilter `json:"filter"`
}
type GetPromoCodesListResp struct {
Count int64 `json:"count"` // количество в выборке всего
Items []PromoCode `json:"items"` // "страница" промокодов
}
type ActivateReq struct {
Codeword string `json:"codeword"`
FastLink string `json:"fastLink"`
}
type ActivateResp struct {
Greetings string `json:"greetings"` // поле из активированного промокода
}
type PromoStatReq struct {
PromoCodeID string `json:"id,omitempty"`
From uint64 `json:"from"`
To uint64 `json:"to"`
}
type PromoCodeStats struct {
ID string `json:"id,omitempty"`
UsageMap map[string][]Usage `json:"usageMap"`
}
type Usage struct {
UserID string `bson:"userID" json:"userID"`
Time uint64 `bson:"time" json:"time"`
}
type PromoCodeStatsResp struct {
ID string `json:"id,omitempty"`
UsageCount int `json:"usageCount"`
UsageMap map[string]int `json:"usageMap"`
}