common/model/model.go

328 lines
10 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 model
import (
"github.com/golang/protobuf/proto"
"penahub.gitlab.yandexcloud.net/backend/penahub_common/privilege"
"time"
)
const (
StatusDraft = "draft"
StatusTemplate = "template"
StatusStop = "stop"
StatusStart = "start"
StatusTimeout = "timeout"
StatusOffLimit = "offlimit"
TypeVariant = "variant"
TypeImages = "images"
TypeVarImages = "varimg"
TypeFile = "file"
TypeText = "text"
TypeEmoji = "emoji"
TypeSelect = "select"
TypeDate = "date"
TypeNumber = "number"
TypePage = "page"
TypeRating = "rating"
TypeResult = "result"
)
// Quiz is a struct for set up an quiz settings
type Quiz struct {
Id uint64 `json:"id"`
Qid string `json:"qid"` // uuid for secure data get and post
AccountId string `json:"accountid"` // account that created the quiz
Deleted bool `json:"deleted"` // fake delete field
Archived bool `json:"archived"` // field for archiving quiz
Fingerprinting bool `json:"fingerprinting"` // field that need for storing device id
Repeatable bool `json:"repeatable"` // make it true for allow more than one quiz checkouting
NotePrevented bool `json:"note_prevented"` // note answers even if the quiz was aborted
MailNotifications bool `json:"mail_notifications"` // set true if you want get an email with every quiz passing
UniqueAnswers bool `json:"unique_answers"` // set true if we you mention only last quiz passing
Name string `json:"name"`
Description string `json:"description"`
Config string `json:"config"` // serialize json with config for page rules
Status string `json:"status"` // status of quiz as enum. see Status const higher
Limit uint64 `json:"limit"` // max count of quiz passing
DueTo uint64 `json:"due_to"` // time when quiz is end
TimeOfPassing uint64 `json:"time_of_passing"` // amount of seconds for give all appropriate answers for quiz
Pausable bool `json:"pausable"` // true allows to pause the quiz taking
Version int `json:"version"`
VersionComment string `json:"version_comment"`
ParentIds []int32 `json:"parent_ids"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
QuestionsCount uint64 `json:"questions_count"`
SessionCount uint64 `json:"session_count"`
PassedCount uint64 `json:"passed_count"`
AverageTime uint64 `json:"average_time"`
Super bool `json:"super"`
GroupId uint64 `json:"group_id"`
}
type QuizConfig struct {
Mailing ResultInfo `json:"resultInfo"`
}
type ResultInfo struct {
When string `json:"when"` // before|after|email
Theme string `json:"theme"` // тема письма
Reply string `json:"reply"` // email для ответов, указывается в создании письма
ReplName string `json:"repl_name"` // имя отправителя
}
// Question is a struct for implementing question for quiz
type Question struct {
Id uint64 `json:"id"`
QuizId uint64 `json:"quiz_id"` // relation to quiz table
Title string `json:"title"` // title of question
Description string `json:"description"` // html\text representation of question and question description for answerer
Type string `json:"type"` // type field. enum with constants from consts higher
Required bool `json:"required"` // answerer must answer this question
Deleted bool `json:"deleted"` // fake deleting field
Page int `json:"page"` // set page number for question
//serialized json. caption for button type, array of key-value pairs for checkbox and select types,
// placeholder and input title for text and file types
Content string `json:"content"`
Version int `json:"version"`
//todo check the best choice: question duplication and no statistics about the most unstable question or
//low performance of high complexity join-on-array query
ParentIds []int32 `json:"parent_ids"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// Answer record of question answer
type Answer struct {
Id uint64
Content string `json:"content"` //serialized json. empty for buttons
QuestionId uint64 `json:"question_id"` // relation for quiz
QuizId uint64 // relation for quiz
Fingerprint string // device Id
Session string // xid of session
Result bool
CreatedAt time.Time
New bool `json:"new"`
Deleted bool
Email string
DeviceType string
Device string
Browser string
IP string
OS string
Start bool
Utm UTMSavingMap
}
type ResultContent struct {
Text string `json:"text"`
Name string `json:"name"`
Email string `json:"email"`
Phone string `json:"phone"`
Address string `json:"address"`
Telegram string `json:"telegram"`
Wechat string `json:"wechat"`
Viber string `json:"viber"`
Vk string `json:"vk"`
Skype string `json:"skype"`
Whatsup string `json:"whatsup"`
Messenger string `json:"messenger"`
Custom map[string]string `json:"customs"`
Start bool `json:"start"`
//IMGContent ImageContent `json:"imagecontent"`
}
type ImageContent struct {
Description string
Image string
}
type ResultAnswer struct {
Content string
CreatedAt time.Time
QuestionID uint64
AnswerID uint64
}
const skey = "squiz"
var (
Privileges = []privilege.Privilege{
{
PrivilegeID: "quizCnt",
Name: "Количество Заявок",
ServiceKey: skey,
Description: "Количество полных прохождений опросов",
Type: "count",
Value: "заявка",
},
{
PrivilegeID: "quizUnlimTime",
Name: "Безлимит Опросов",
ServiceKey: skey,
Description: "Количество дней, в течении которых пользование сервисом безлимитно",
Type: "day",
Value: "день",
},
{
PrivilegeID: "squizHideBadge",
Name: "Скрытие шильдика в опроснике",
ServiceKey: skey,
Description: "Количество дней скрытия шильдика в опроснике",
Type: "day",
Value: "день",
},
{
PrivilegeID: "quizManual",
Name: "Заказать quiz",
ServiceKey: skey,
Description: "Закажите квиз и мы сделаем его в течении трех дней",
Type: "count",
Value: "шт",
},
}
)
const (
ServiceKey = "templategen"
PrivilegeTemplateCount = "templateCnt"
PrivilegeTemplateUnlimTime = "templateUnlimTime"
PrivilegeTemplateStorage = "templateStorage"
BasicAmountPrivilegeTemplateCount = 15
BasicAmountPrivilegeTemplateStorage = 100
)
type Tariff struct {
ID string `json:"_id"`
Name string `json:"name"`
UserID string `json:"user_id"`
Price int64 `json:"price"`
IsCustom bool `json:"isCustom"`
Privileges []Privilege `json:"privileges"`
Deleted bool `json:"isDeleted"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt,omitempty"`
}
type Privilege struct {
ID string `json:"_id"`
Amount int64 `json:"amount"`
PrivilegeID string `json:"privilegeId"`
Name string `json:"name"`
ServiceKey string `json:"serviceKey"`
Description string `json:"description"`
Type string `json:"type"`
Value string `json:"value"`
Price float64 `json:"price"`
IsDeleted bool `json:"isDeleted"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt time.Time `json:"deletedAt"`
}
type CustomerMessage struct {
Privileges []PrivilegeMessage `protobuf:"bytes,1,rep,name=Privileges,proto3" json:"Privileges,omitempty"`
UserID string `protobuf:"bytes,2,opt,name=UserID,proto3" json:"UserID,omitempty"`
}
type PrivilegeMessage struct {
PrivilegeID string `protobuf:"bytes,1,opt,name=PrivilegeID,proto3" json:"PrivilegeID,omitempty"`
ServiceKey string `protobuf:"bytes,2,opt,name=ServiceKey,proto3" json:"ServiceKey,omitempty"`
Type PrivilegeType `protobuf:"varint,3,opt,name=Type,proto3,enum=broker.PrivilegeType" json:"Type,omitempty"`
Value string `protobuf:"bytes,4,opt,name=Value,proto3" json:"Value,omitempty"`
Amount uint64 `protobuf:"varint,5,opt,name=Amount,proto3" json:"Amount,omitempty"`
}
type PrivilegeType int32
func (m *CustomerMessage) Reset() {
*m = CustomerMessage{}
}
func (m *CustomerMessage) String() string {
return proto.CompactTextString(m)
}
func (m *CustomerMessage) ProtoMessage() {
}
type ShortPrivilege struct {
ID string `json:"id"`
PrivilegeID string `json:"privilege_id"`
PrivilegeName string `json:"privilege_name"`
Amount uint64 `json:"amount"`
CreatedAt time.Time `json:"created_at"`
}
type ExpiredPrivileges struct {
UserID string
Privilege ShortPrivilege
}
type Account struct {
ID string `json:"id"`
UserID string `json:"user_id"`
CreatedAt time.Time `json:"created_at"`
Deleted bool `json:"deleted"`
Privileges map[string]ShortPrivilege `json:"privileges"`
}
type DefaultData struct {
Amount uint64
PrivilegeID string
UnlimID string
}
type ShortQuestion struct {
Title string
Content string
Description string
}
type AnswerExport struct {
Content string `json:"content"`
Id uint64 `json:"id"`
New bool `json:"new"`
CreatedAt time.Time `json:"created_at"`
}
type UTMSavingMap map[string]string
type LeadTarget struct {
ID int64 `json:"id"`
AccountID string `json:"accountID"`
Type LeadTargetType `json:"type"`
QuizID int32 `json:"quizID"`
Target string `json:"target"`
Deleted bool `json:"deleted"`
CreatedAt time.Time `json:"createdAt"`
}
type LeadTargetType string
const (
LeadTargetEmail LeadTargetType = "mail"
LeadTargetTg LeadTargetType = "telegram"
LeadTargetTgWhatsapp LeadTargetType = "whatsapp"
)