61 lines
2.2 KiB
Go
61 lines
2.2 KiB
Go
package orderstatus
|
||
|
||
type Info struct {
|
||
Icon string
|
||
Label string
|
||
Class string
|
||
Step int
|
||
Terminal bool
|
||
}
|
||
|
||
var statuses = map[string]Info{
|
||
"pending": {Icon: "⏳", Label: "В ожидании", Class: "status--pending", Step: 1},
|
||
"unpaid": {Icon: "💳", Label: "Не оплачено", Class: "status--unpaid", Step: 1},
|
||
"paid": {Icon: "✓", Label: "Оплачено", Class: "status--paid", Step: 2},
|
||
"processing": {Icon: "⚙", Label: "В обработке", Class: "status--processing", Step: 3},
|
||
"shipped": {Icon: "📦", Label: "Отправлен", Class: "status--shipped", Step: 4},
|
||
"delivered": {Icon: "✓", Label: "Доставлен", Class: "status--delivered", Step: 5},
|
||
"cancelled": {Icon: "✕", Label: "Отменён", Class: "status--cancelled", Step: 0, Terminal: true},
|
||
"refunded": {Icon: "↩", Label: "Возврат", Class: "status--refunded", Step: 0, Terminal: true},
|
||
// совместимость со старыми заказами
|
||
"new": {Icon: "⏳", Label: "В ожидании", Class: "status--pending", Step: 1},
|
||
"confirmed": {Icon: "✓", Label: "Оплачено", Class: "status--paid", Step: 2},
|
||
}
|
||
|
||
// Timeline — основной путь доставки (для таймлайна в кабинете)
|
||
var Timeline = []string{"pending", "paid", "processing", "shipped", "delivered"}
|
||
|
||
// AllCodes — все статусы для выбора в админке
|
||
var AllCodes = []string{
|
||
"pending", "unpaid", "paid", "processing", "shipped", "delivered", "cancelled", "refunded",
|
||
}
|
||
|
||
func Normalize(code string) string {
|
||
if code == "new" {
|
||
return "pending"
|
||
}
|
||
if code == "confirmed" {
|
||
return "paid"
|
||
}
|
||
return code
|
||
}
|
||
|
||
func Get(code string) Info {
|
||
code = Normalize(code)
|
||
if s, ok := statuses[code]; ok {
|
||
return s
|
||
}
|
||
return Info{Label: code, Class: "status--pending", Step: 1}
|
||
}
|
||
|
||
func Label(code string) string { return Get(code).Label }
|
||
func Icon(code string) string { return Get(code).Icon }
|
||
func Class(code string) string { return Get(code).Class }
|
||
func Step(code string) int { return Get(code).Step }
|
||
func IsTerminal(code string) bool { return Get(code).Terminal }
|
||
|
||
func Valid(code string) bool {
|
||
_, ok := statuses[Normalize(code)]
|
||
return ok
|
||
}
|