From d390fa4825c6cf8cb44a86efd0540f19699b920c Mon Sep 17 00:00:00 2001 From: poignatov Date: Mon, 19 Jan 2026 22:25:28 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=81=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0=20=D0=B6=D0=B5=D0=BB=D0=B0=D0=BD=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=B8=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=203.14.11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VERSION | 2 +- play-life-backend/main.go | 47 ++++++++++++++++++++++++++++++++++++-- play-life-web/package.json | 2 +- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index 6345df5..bbbefde 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.14.10 +3.14.11 diff --git a/play-life-backend/main.go b/play-life-backend/main.go index 08870d9..0ac0960 100644 --- a/play-life-backend/main.go +++ b/play-life-backend/main.go @@ -12346,6 +12346,41 @@ func (a *App) getBoardCompletedHandler(w http.ResponseWriter, r *http.Request) { } // getWishlistItemsByBoard загружает желания конкретной доски +// calculateUnlockValue вычисляет значение для сортировки желаний +// Возвращает значение, где: +// - Отрицательные значения: unlocked элементы (ставим в начало) +// - Положительные значения: сумма оставшихся баллов для locked элементов (меньше = выше в списке) +func calculateUnlockValue(item WishlistItem) float64 { + // Если элемент уже unlocked, ставим его в начало (отрицательное значение) + if item.Unlocked { + return -1.0 + } + + // Суммируем оставшиеся баллы по всем условиям project_points + var totalRemaining float64 = 0.0 + var hasProjectPointsConditions bool = false + + for _, condition := range item.UnlockConditions { + if condition.Type == "project_points" { + hasProjectPointsConditions = true + if condition.CurrentPoints != nil && condition.RequiredPoints != nil { + remaining := *condition.RequiredPoints - *condition.CurrentPoints + if remaining > 0 { + totalRemaining += remaining + } + } + } + } + + // Если есть условия project_points, возвращаем сумму оставшихся баллов + if hasProjectPointsConditions { + return totalRemaining + } + + // Элементы без условий project_points ставим в конец (большое значение) + return 999999.0 +} + func (a *App) getWishlistItemsByBoard(boardID int, userID int) ([]WishlistItem, error) { query := ` SELECT @@ -12521,9 +12556,17 @@ func (a *App) getWishlistItemsByBoard(boardID int, userID int) ([]WishlistItem, items = append(items, *item) } - // Сортируем по ID для стабильного порядка + // Сортируем: сначала unlocked, затем по сумме оставшихся баллов (от меньшего к большему) sort.Slice(items, func(i, j int) bool { - return items[i].ID < items[j].ID + valueI := calculateUnlockValue(items[i]) + valueJ := calculateUnlockValue(items[j]) + + // Если значения равны, сортируем по ID для стабильного порядка + if valueI == valueJ { + return items[i].ID < items[j].ID + } + + return valueI < valueJ }) return items, nil diff --git a/play-life-web/package.json b/play-life-web/package.json index 55481c5..8c3aede 100644 --- a/play-life-web/package.json +++ b/play-life-web/package.json @@ -1,6 +1,6 @@ { "name": "play-life-web", - "version": "3.14.10", + "version": "3.14.11", "type": "module", "scripts": { "dev": "vite",