This commit is contained in:
Artem Tsyrulnikov
2026-02-03 22:20:56 +03:00
parent 7c8589e000
commit 09145e510a
10 changed files with 124 additions and 101 deletions

View File

@@ -17,6 +17,7 @@ import (
type PurchaseOptionalDetails struct {
ProjectID string
ProjectTitle string
ProjectDefaultLinkType string
CreativeID string
CreativeTitle string
Channels []PurchaseChannelInput
@@ -254,15 +255,16 @@ func (s *PurchaseOptionalDetails) HandleCallback(b *bot.Bot, u *echotron.Update)
case "back":
// Сохраняем текущее состояние перед возвратом назад
b.SetState(&SelectChannelsForPurchase{
ProjectID: s.ProjectID,
ProjectTitle: s.ProjectTitle,
CreativeID: s.CreativeID,
CreativeTitle: s.CreativeTitle,
Channels: s.Channels,
Duplicates: []string{},
ParsingErrors: []ParseError{},
OptionalDetailsState: s, // Сохраняем текущее состояние
BackState: s.BackState,
ProjectID: s.ProjectID,
ProjectTitle: s.ProjectTitle,
ProjectDefaultLinkType: s.ProjectDefaultLinkType,
CreativeID: s.CreativeID,
CreativeTitle: s.CreativeTitle,
Channels: s.Channels,
Duplicates: []string{},
ParsingErrors: []ParseError{},
OptionalDetailsState: s, // Сохраняем текущее состояние
BackState: s.BackState,
}, bot.EditMessage)
case "next":
jwt := b.Session.JWT
@@ -314,11 +316,6 @@ func (s *PurchaseOptionalDetails) HandleCallback(b *bot.Bot, u *echotron.Update)
}
if strings.HasPrefix(u.CallbackQuery.Data, "type:") {
value := strings.TrimPrefix(u.CallbackQuery.Data, "type:")
if value == "custom" {
s.InputMode = "type_custom"
s.Enter(b, bot.EditMessage)
return
}
// Нормализуем значение для БД
switch value {
case "self_promo":
@@ -372,12 +369,6 @@ func (s *PurchaseOptionalDetails) HandleMessage(b *bot.Bot, u *echotron.Update)
}
switch s.InputMode {
case "type_custom":
if s.CurrentChannel != "" {
s.PurchaseTypeByChannel[s.CurrentChannel] = text
} else {
s.PurchaseType = text
}
case "format_custom":
s.setFormatValue(text)
case "comment":
@@ -639,11 +630,7 @@ func (s *PurchaseOptionalDetails) renderInputPrompt(b *bot.Bot, mode bot.RenderM
case "type":
text += "<b>Выберите тип закупа</b>"
keyboard := Keyboard(
Row(
Button("Самопиар", "type:self_promo"),
Button("Стандарт", "type:standard"),
),
Row(Button("Другое", "type:custom")),
Row(Button("Самопиар", "type:self_promo"), Button("Стандарт", "type:standard")),
Row(Button("← Назад", "back_to_optional")),
)
if mode == bot.EditMessage {
@@ -652,8 +639,6 @@ func (s *PurchaseOptionalDetails) renderInputPrompt(b *bot.Bot, mode bot.RenderM
b.SendNew(text, keyboard)
}
return
case "type_custom":
text += "<b>Введите тип закупа</b>\n\nНапример: <code>вп</code>"
case "cost_value":
text += "<b>Ввод стоимости</b>\n\nНапример: <code>15000</code>"
if s.CurrentChannel != "" {
@@ -1639,6 +1624,12 @@ func (s *PurchaseOptionalDetails) ensureDefaults() {
if s.InviteLinkTypeMode == "" {
s.InviteLinkTypeMode = "common"
}
if s.InviteLinkType == "" {
s.InviteLinkType = s.ProjectDefaultLinkType
if s.InviteLinkType == "" {
s.InviteLinkType = "approval"
}
}
if s.PlacementByChannel == nil {
s.PlacementByChannel = make(map[string]*time.Time)
}
@@ -2255,22 +2246,22 @@ func (s *PurchaseOptionalDetails) buildChannelDetails(channelKey string, placeme
// Placement date
if s.PlacementMode == "per_channel" && len(s.Channels) > 1 {
if value, ok := s.PlacementByChannel[channelKey]; ok && value != nil {
formatted := value.Format(time.RFC3339)
formatted := value.UTC().Format(time.RFC3339)
details.PlacementAt = &formatted
}
} else if s.PlacementDateTime != nil {
formatted := s.PlacementDateTime.Format(time.RFC3339)
formatted := s.PlacementDateTime.UTC().Format(time.RFC3339)
details.PlacementAt = &formatted
}
// Payment date
if s.PaymentDateMode == "per_channel" && len(s.Channels) > 1 {
if value, ok := s.PaymentDateByChannel[channelKey]; ok && value != nil {
formatted := value.Format(time.RFC3339)
formatted := value.UTC().Format(time.RFC3339)
details.PaymentAt = &formatted
}
} else if s.PaymentDate != nil {
formatted := s.PaymentDate.Format(time.RFC3339)
formatted := s.PaymentDate.UTC().Format(time.RFC3339)
details.PaymentAt = &formatted
}