Add admin order management with full status workflow.
This commit is contained in:
@@ -1,37 +1,58 @@
|
||||
package orderstatus
|
||||
|
||||
type Info struct {
|
||||
Label string
|
||||
Class string
|
||||
Step int
|
||||
Label string
|
||||
Class string
|
||||
Step int
|
||||
Terminal bool
|
||||
}
|
||||
|
||||
var statuses = map[string]Info{
|
||||
"new": {Label: "Новый", Class: "status--new", Step: 1},
|
||||
"confirmed": {Label: "Подтверждён", Class: "status--confirmed", Step: 2},
|
||||
"pending": {Label: "В ожидании", Class: "status--pending", Step: 1},
|
||||
"unpaid": {Label: "Не оплачено", Class: "status--unpaid", Step: 1},
|
||||
"paid": {Label: "Оплачено", Class: "status--paid", Step: 2},
|
||||
"processing": {Label: "В обработке", Class: "status--processing", Step: 3},
|
||||
"shipped": {Label: "Отправлен", Class: "status--shipped", Step: 4},
|
||||
"delivered": {Label: "Доставлен", Class: "status--delivered", Step: 5},
|
||||
"cancelled": {Label: "Отменён", Class: "status--cancelled", Step: 0},
|
||||
"cancelled": {Label: "Отменён", Class: "status--cancelled", Step: 0, Terminal: true},
|
||||
"refunded": {Label: "Возврат", Class: "status--refunded", Step: 0, Terminal: true},
|
||||
// совместимость со старыми заказами
|
||||
"new": {Label: "В ожидании", Class: "status--pending", Step: 1},
|
||||
"confirmed": {Label: "Оплачено", Class: "status--paid", Step: 2},
|
||||
}
|
||||
|
||||
var Timeline = []string{"new", "confirmed", "processing", "shipped", "delivered"}
|
||||
// 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--new", Step: 1}
|
||||
return Info{Label: code, Class: "status--pending", Step: 1}
|
||||
}
|
||||
|
||||
func Label(code string) string {
|
||||
return Get(code).Label
|
||||
}
|
||||
func Label(code string) string { return Get(code).Label }
|
||||
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 Class(code string) string {
|
||||
return Get(code).Class
|
||||
}
|
||||
|
||||
func Step(code string) int {
|
||||
return Get(code).Step
|
||||
func Valid(code string) bool {
|
||||
_, ok := statuses[Normalize(code)]
|
||||
return ok
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user