优化首页分页和图片上传
This commit is contained in:
@@ -65,6 +65,49 @@ type AdminListResult struct {
|
||||
PageSize int `json:"page_size"`
|
||||
}
|
||||
|
||||
type PublicListQuery struct {
|
||||
Page int
|
||||
PageSize int
|
||||
Keyword string
|
||||
Sort string
|
||||
Zone string
|
||||
Server []string
|
||||
Region []string
|
||||
LoginMethod []string
|
||||
Rank []string
|
||||
Insurance []string
|
||||
Stamina []string
|
||||
Load []string
|
||||
SkinGroup []string
|
||||
SkinName []string
|
||||
MinCoin *float64
|
||||
MaxCoin *float64
|
||||
MinPrice *float64
|
||||
MaxPrice *float64
|
||||
MinDeposit *float64
|
||||
MaxDeposit *float64
|
||||
MinTotal *float64
|
||||
MaxTotal *float64
|
||||
MinFireLevel *float64
|
||||
MaxFireLevel *float64
|
||||
MinSecretKD *float64
|
||||
MaxSecretKD *float64
|
||||
ResourceRanges map[string]NumberRange
|
||||
}
|
||||
|
||||
type NumberRange struct {
|
||||
Min *float64
|
||||
Max *float64
|
||||
}
|
||||
|
||||
type PublicListResult struct {
|
||||
Items []ListingDTO `json:"items"`
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
ZoneCounts map[string]int64 `json:"zone_counts"`
|
||||
}
|
||||
|
||||
type AdminActionRequest struct {
|
||||
Reason string `json:"reason" binding:"required"`
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"hfb_sys/backend/internal/middleware"
|
||||
filemodule "hfb_sys/backend/internal/modules/file"
|
||||
@@ -196,12 +197,12 @@ func (h *Handler) Offline(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (h *Handler) ListPublic(c *gin.Context) {
|
||||
items, err := h.service.ListPublic()
|
||||
items, err := h.service.ListPublic(parsePublicListQuery(c))
|
||||
if err != nil {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
}
|
||||
response.OK(c, gin.H{"items": items})
|
||||
response.OK(c, items)
|
||||
}
|
||||
|
||||
func (h *Handler) FindPublic(c *gin.Context) {
|
||||
@@ -227,7 +228,7 @@ func (h *Handler) Cover(c *gin.Context) {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
}
|
||||
h.writePublicObject(c, key)
|
||||
h.writePublicObject(c, filemodule.ImageVariantFallbackKeys(key, filemodule.ImageVariantThumb)...)
|
||||
}
|
||||
|
||||
func (h *Handler) Screenshot(c *gin.Context) {
|
||||
@@ -245,16 +246,23 @@ func (h *Handler) Screenshot(c *gin.Context) {
|
||||
writeListingError(c, err)
|
||||
return
|
||||
}
|
||||
h.writePublicObject(c, key)
|
||||
h.writePublicObject(c, filemodule.ImageVariantFallbackKeys(key, filemodule.ImageVariantMedium)...)
|
||||
}
|
||||
|
||||
func (h *Handler) writePublicObject(c *gin.Context, key string) {
|
||||
func (h *Handler) writePublicObject(c *gin.Context, keys ...string) {
|
||||
if h.storage == nil {
|
||||
response.ServiceUnavailable(c, "文件存储未连接")
|
||||
return
|
||||
}
|
||||
object, err := h.storage.Get(c.Request.Context(), key)
|
||||
if err != nil {
|
||||
var object *filemodule.Object
|
||||
for _, key := range keys {
|
||||
nextObject, err := h.storage.Get(c.Request.Context(), key)
|
||||
if err == nil {
|
||||
object = nextObject
|
||||
break
|
||||
}
|
||||
}
|
||||
if object == nil {
|
||||
response.Error(c, http.StatusNotFound, "not_found", "图片不存在或暂不可访问")
|
||||
return
|
||||
}
|
||||
@@ -368,6 +376,124 @@ func parseAdminListQuery(c *gin.Context) (AdminListQuery, bool) {
|
||||
return query, true
|
||||
}
|
||||
|
||||
func parsePublicListQuery(c *gin.Context) PublicListQuery {
|
||||
query := PublicListQuery{
|
||||
Page: parsePositiveInt(c.DefaultQuery("page", "1"), 1),
|
||||
PageSize: parsePositiveInt(c.DefaultQuery("page_size", "20"), 20),
|
||||
Keyword: strings.TrimSpace(c.Query("keyword")),
|
||||
Sort: strings.TrimSpace(c.Query("sort")),
|
||||
Zone: strings.TrimSpace(c.Query("zone")),
|
||||
Server: parseCSVQuery(c.Query("server")),
|
||||
Region: parseCSVQuery(c.Query("region")),
|
||||
LoginMethod: parseCSVQuery(firstNonEmpty(c.Query("login_method"), c.Query("login"))),
|
||||
Rank: parseCSVQuery(c.Query("rank")),
|
||||
Insurance: parseCSVQuery(c.Query("insurance")),
|
||||
Stamina: parseCSVQuery(c.Query("stamina")),
|
||||
Load: parseCSVQuery(c.Query("load")),
|
||||
SkinGroup: parseCSVQuery(c.Query("skin_group")),
|
||||
SkinName: parseCSVQuery(firstNonEmpty(c.Query("skin_name"), c.Query("skin"))),
|
||||
MinCoin: parseOptionalFloat(c.Query("min_coin")),
|
||||
MaxCoin: parseOptionalFloat(c.Query("max_coin")),
|
||||
MinPrice: parseOptionalFloat(c.Query("min_price")),
|
||||
MaxPrice: parseOptionalFloat(c.Query("max_price")),
|
||||
MinDeposit: parseOptionalFloat(c.Query("min_deposit")),
|
||||
MaxDeposit: parseOptionalFloat(c.Query("max_deposit")),
|
||||
MinTotal: parseOptionalFloat(c.Query("min_total")),
|
||||
MaxTotal: parseOptionalFloat(c.Query("max_total")),
|
||||
MinFireLevel: parseOptionalFloat(c.Query("min_fire_level")),
|
||||
MaxFireLevel: parseOptionalFloat(c.Query("max_fire_level")),
|
||||
MinSecretKD: parseOptionalFloat(c.Query("min_secret_kd")),
|
||||
MaxSecretKD: parseOptionalFloat(c.Query("max_secret_kd")),
|
||||
ResourceRanges: parseResourceRanges(c),
|
||||
}
|
||||
if query.PageSize > 50 {
|
||||
query.PageSize = 50
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
func parsePositiveInt(value string, fallback int) int {
|
||||
parsed, err := strconv.Atoi(strings.TrimSpace(value))
|
||||
if err != nil || parsed <= 0 {
|
||||
return fallback
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
func parseOptionalFloat(value string) *float64 {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
return nil
|
||||
}
|
||||
parsed, err := strconv.ParseFloat(value, 64)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return &parsed
|
||||
}
|
||||
|
||||
func parseCSVQuery(value string) []string {
|
||||
parts := strings.Split(value, ",")
|
||||
result := make([]string, 0, len(parts))
|
||||
seen := make(map[string]struct{}, len(parts))
|
||||
for _, part := range parts {
|
||||
part = strings.TrimSpace(part)
|
||||
if part == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[part]; ok {
|
||||
continue
|
||||
}
|
||||
seen[part] = struct{}{}
|
||||
result = append(result, part)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func parseResourceRanges(c *gin.Context) map[string]NumberRange {
|
||||
ranges := make(map[string]NumberRange)
|
||||
for key, values := range c.Request.URL.Query() {
|
||||
if !strings.HasPrefix(key, "resource_") {
|
||||
continue
|
||||
}
|
||||
var resourceKey string
|
||||
var isMin bool
|
||||
switch {
|
||||
case strings.HasSuffix(key, "_min"):
|
||||
resourceKey = strings.TrimSuffix(strings.TrimPrefix(key, "resource_"), "_min")
|
||||
isMin = true
|
||||
case strings.HasSuffix(key, "_max"):
|
||||
resourceKey = strings.TrimSuffix(strings.TrimPrefix(key, "resource_"), "_max")
|
||||
default:
|
||||
continue
|
||||
}
|
||||
if resourceKey == "" || len(values) == 0 {
|
||||
continue
|
||||
}
|
||||
value := parseOptionalFloat(values[0])
|
||||
if value == nil {
|
||||
continue
|
||||
}
|
||||
numberRange := ranges[resourceKey]
|
||||
if isMin {
|
||||
numberRange.Min = value
|
||||
} else {
|
||||
numberRange.Max = value
|
||||
}
|
||||
ranges[resourceKey] = numberRange
|
||||
}
|
||||
return ranges
|
||||
}
|
||||
|
||||
func firstNonEmpty(values ...string) string {
|
||||
for _, value := range values {
|
||||
if strings.TrimSpace(value) != "" {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func writeListingError(c *gin.Context, err error) {
|
||||
switch {
|
||||
case errors.Is(err, ErrDependencyUnavailable):
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -385,17 +386,56 @@ func (r *Repository) Offline(ownerID uint64, listingID uint64) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (r *Repository) ListPublic() ([]ListingDTO, error) {
|
||||
func (r *Repository) ListPublic(query PublicListQuery) (*PublicListResult, error) {
|
||||
var rows []listingRow
|
||||
err := r.baseQuery().
|
||||
Where("l.status = ? AND l.review_status = ? AND l.in_transaction = ?", "published", "approved", false).
|
||||
Order("l.published_at DESC, l.id DESC").
|
||||
Limit(100).
|
||||
Scan(&rows).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return publicListings(rowsToDTO(rows)), nil
|
||||
items := publicListings(rowsToDTO(rows))
|
||||
baseQuery := query
|
||||
baseQuery.Zone = ""
|
||||
items = filterPublicListings(items, baseQuery)
|
||||
zoneCounts := publicZoneCounts(items)
|
||||
if query.Zone != "" && query.Zone != "all" {
|
||||
items = filterPublicListings(items, query)
|
||||
}
|
||||
sortPublicListings(items, query.Sort)
|
||||
total := int64(len(items))
|
||||
page := query.Page
|
||||
if page <= 0 {
|
||||
page = 1
|
||||
}
|
||||
pageSize := query.PageSize
|
||||
if pageSize <= 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
if pageSize > 50 {
|
||||
pageSize = 50
|
||||
}
|
||||
start := (page - 1) * pageSize
|
||||
if start < 0 {
|
||||
start = 0
|
||||
}
|
||||
if start >= len(items) {
|
||||
items = []ListingDTO{}
|
||||
} else {
|
||||
end := start + pageSize
|
||||
if end > len(items) {
|
||||
end = len(items)
|
||||
}
|
||||
items = items[start:end]
|
||||
}
|
||||
return &PublicListResult{
|
||||
Items: items,
|
||||
Total: total,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
ZoneCounts: zoneCounts,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (r *Repository) ListMine(ownerID uint64) ([]ListingDTO, error) {
|
||||
@@ -410,6 +450,379 @@ func (r *Repository) ListMine(ownerID uint64) ([]ListingDTO, error) {
|
||||
return sellerListings(rowsToDTO(rows)), nil
|
||||
}
|
||||
|
||||
func filterPublicListings(items []ListingDTO, query PublicListQuery) []ListingDTO {
|
||||
filtered := make([]ListingDTO, 0, len(items))
|
||||
for _, item := range items {
|
||||
if !matchesPublicQuery(item, query) {
|
||||
continue
|
||||
}
|
||||
filtered = append(filtered, item)
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
func matchesPublicQuery(item ListingDTO, query PublicListQuery) bool {
|
||||
if !matchesPublicZone(item, query.Zone) {
|
||||
return false
|
||||
}
|
||||
if keyword := strings.ToLower(strings.TrimSpace(query.Keyword)); keyword != "" && !strings.Contains(publicSearchText(item), keyword) {
|
||||
return false
|
||||
}
|
||||
if !matchesAny(query.Server, strings.TrimSpace(item.ServerRegion)) {
|
||||
return false
|
||||
}
|
||||
if len(query.Region) > 0 && !intersects(query.Region, assetRegionsFromSummary(item.AssetSummary)) {
|
||||
return false
|
||||
}
|
||||
if !matchesAny(query.LoginMethod, strings.TrimSpace(item.LoginPlatform)) {
|
||||
return false
|
||||
}
|
||||
if !matchesAny(query.Rank, strings.TrimSpace(item.RankLevel)) {
|
||||
return false
|
||||
}
|
||||
if !matchesAny(query.Insurance, readAssetString(item.AssetSummary, "season_insurance")) {
|
||||
return false
|
||||
}
|
||||
if !matchesAny(query.Stamina, readAssetString(item.AssetSummary, "stamina_level")) {
|
||||
return false
|
||||
}
|
||||
if !matchesAny(query.Load, readAssetString(item.AssetSummary, "load_level")) {
|
||||
return false
|
||||
}
|
||||
if len(query.SkinName) > 0 {
|
||||
if len(query.SkinGroup) > 0 {
|
||||
if !skinGroupsContainAny(item.AssetSummary, query.SkinGroup, query.SkinName) {
|
||||
return false
|
||||
}
|
||||
} else if !intersects(query.SkinName, skinNamesFromSummary(item.AssetSummary)) {
|
||||
return false
|
||||
}
|
||||
} else if len(query.SkinGroup) > 0 && !skinGroupsHaveAny(item.AssetSummary, query.SkinGroup) {
|
||||
return false
|
||||
}
|
||||
|
||||
price := item.Price
|
||||
deposit := item.DepositAmount
|
||||
total := price + deposit
|
||||
coinM := coinMFromListing(item)
|
||||
if !numberInRange(coinM, NumberRange{Min: query.MinCoin, Max: query.MaxCoin}) {
|
||||
return false
|
||||
}
|
||||
if !numberInRange(price, NumberRange{Min: query.MinPrice, Max: query.MaxPrice}) {
|
||||
return false
|
||||
}
|
||||
if !numberInRange(deposit, NumberRange{Min: query.MinDeposit, Max: query.MaxDeposit}) {
|
||||
return false
|
||||
}
|
||||
if !numberInRange(total, NumberRange{Min: query.MinTotal, Max: query.MaxTotal}) {
|
||||
return false
|
||||
}
|
||||
if !numberInRange(readSummaryNumber(item.AssetSummary["fire_level"]), NumberRange{Min: query.MinFireLevel, Max: query.MaxFireLevel}) {
|
||||
return false
|
||||
}
|
||||
if !numberInRange(readSummaryNumber(item.AssetSummary["secret_kd"]), NumberRange{Min: query.MinSecretKD, Max: query.MaxSecretKD}) {
|
||||
return false
|
||||
}
|
||||
for resourceKey, resourceRange := range query.ResourceRanges {
|
||||
if !numberInRange(resourceQuantity(item.AssetSummary, resourceKey), resourceRange) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func sortPublicListings(items []ListingDTO, sortKey string) {
|
||||
sort.SliceStable(items, func(i, j int) bool {
|
||||
a := items[i]
|
||||
b := items[j]
|
||||
switch sortKey {
|
||||
case "priceAsc":
|
||||
return a.Price < b.Price
|
||||
case "priceDesc":
|
||||
return a.Price > b.Price
|
||||
case "coinDesc":
|
||||
return a.HafCoinAmount > b.HafCoinAmount
|
||||
case "awmDesc":
|
||||
aAmmo := resourceQuantity(a.AssetSummary, "awmAmmo")
|
||||
bAmmo := resourceQuantity(b.AssetSummary, "awmAmmo")
|
||||
if aAmmo != bAmmo {
|
||||
return aAmmo > bAmmo
|
||||
}
|
||||
return a.HafCoinAmount > b.HafCoinAmount
|
||||
case "published", "recommended", "comprehensive", "":
|
||||
return publicRecentLess(a, b)
|
||||
default:
|
||||
return publicRecentLess(a, b)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func publicRecentLess(a ListingDTO, b ListingDTO) bool {
|
||||
aTime := time.Time{}
|
||||
bTime := time.Time{}
|
||||
if a.PublishedAt != nil {
|
||||
aTime = *a.PublishedAt
|
||||
}
|
||||
if b.PublishedAt != nil {
|
||||
bTime = *b.PublishedAt
|
||||
}
|
||||
if !aTime.Equal(bTime) {
|
||||
return aTime.After(bTime)
|
||||
}
|
||||
return a.ID > b.ID
|
||||
}
|
||||
|
||||
func matchesPublicZone(item ListingDTO, zone string) bool {
|
||||
switch zone {
|
||||
case "", "all":
|
||||
return true
|
||||
case "sale":
|
||||
return item.IsAccelerated
|
||||
case "gift":
|
||||
return hasGiftResourcesSummary(item.AssetSummary)
|
||||
case "night":
|
||||
return isNightAvailableSummary(item.AssetSummary)
|
||||
case "password":
|
||||
return strings.Contains(item.LoginPlatform, "账密") || strings.Contains(item.LoginPlatform, "账号密码")
|
||||
case "highCoin":
|
||||
return coinMFromListing(item) >= 100
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func publicZoneCounts(items []ListingDTO) map[string]int64 {
|
||||
counts := map[string]int64{
|
||||
"all": int64(len(items)),
|
||||
"sale": 0,
|
||||
"gift": 0,
|
||||
"night": 0,
|
||||
"password": 0,
|
||||
"highCoin": 0,
|
||||
}
|
||||
for _, item := range items {
|
||||
for _, zone := range []string{"sale", "gift", "night", "password", "highCoin"} {
|
||||
if matchesPublicZone(item, zone) {
|
||||
counts[zone]++
|
||||
}
|
||||
}
|
||||
}
|
||||
return counts
|
||||
}
|
||||
|
||||
func publicSearchText(item ListingDTO) string {
|
||||
parts := []string{
|
||||
item.Title,
|
||||
item.Description,
|
||||
item.RankLevel,
|
||||
item.ServerRegion,
|
||||
item.LoginPlatform,
|
||||
}
|
||||
parts = append(parts, assetRegionsFromSummary(item.AssetSummary)...)
|
||||
parts = append(parts, skinNamesFromSummary(item.AssetSummary)...)
|
||||
return strings.ToLower(strings.Join(parts, " "))
|
||||
}
|
||||
|
||||
func matchesAny(options []string, value string) bool {
|
||||
if len(options) == 0 {
|
||||
return true
|
||||
}
|
||||
for _, option := range options {
|
||||
if option == value {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func intersects(options []string, values []string) bool {
|
||||
if len(options) == 0 {
|
||||
return true
|
||||
}
|
||||
valueSet := make(map[string]struct{}, len(values))
|
||||
for _, value := range values {
|
||||
valueSet[value] = struct{}{}
|
||||
}
|
||||
for _, option := range options {
|
||||
if _, ok := valueSet[option]; ok {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func numberInRange(value float64, numberRange NumberRange) bool {
|
||||
if numberRange.Min != nil && value < *numberRange.Min {
|
||||
return false
|
||||
}
|
||||
if numberRange.Max != nil && value > *numberRange.Max {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func coinMFromListing(item ListingDTO) float64 {
|
||||
return float64(item.HafCoinAmount) / 1000000
|
||||
}
|
||||
|
||||
func readAssetString(summary map[string]any, key string) string {
|
||||
if summary == nil {
|
||||
return ""
|
||||
}
|
||||
value, _ := summary[key].(string)
|
||||
return strings.TrimSpace(value)
|
||||
}
|
||||
|
||||
func assetRegionsFromSummary(summary map[string]any) []string {
|
||||
if summary == nil {
|
||||
return nil
|
||||
}
|
||||
values, ok := summary["common_regions"].([]any)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
result := make([]string, 0, len(values))
|
||||
for _, value := range values {
|
||||
text, ok := value.(string)
|
||||
if ok && strings.TrimSpace(text) != "" {
|
||||
result = append(result, strings.TrimSpace(text))
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func skinNamesFromSummary(summary map[string]any) []string {
|
||||
groups := skinGroupsFromSummary(summary)
|
||||
result := make([]string, 0)
|
||||
for _, skins := range groups {
|
||||
result = append(result, skins...)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func skinGroupsContainAny(summary map[string]any, groupKeys []string, skinNames []string) bool {
|
||||
groups := skinGroupsFromSummary(summary)
|
||||
for _, groupKey := range groupKeys {
|
||||
if intersects(skinNames, groups[groupKey]) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func skinGroupsHaveAny(summary map[string]any, groupKeys []string) bool {
|
||||
groups := skinGroupsFromSummary(summary)
|
||||
for _, groupKey := range groupKeys {
|
||||
if len(groups[groupKey]) > 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func skinGroupsFromSummary(summary map[string]any) map[string][]string {
|
||||
result := make(map[string][]string)
|
||||
if summary == nil {
|
||||
return result
|
||||
}
|
||||
rawGroups, ok := summary["skin_groups"].(map[string]any)
|
||||
if !ok {
|
||||
return result
|
||||
}
|
||||
for key, rawSkins := range rawGroups {
|
||||
values, ok := rawSkins.([]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
for _, value := range values {
|
||||
text, ok := value.(string)
|
||||
if ok && strings.TrimSpace(text) != "" {
|
||||
result[key] = append(result[key], strings.TrimSpace(text))
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func resourceQuantity(summary map[string]any, resourceKey string) float64 {
|
||||
if summary == nil {
|
||||
return 0
|
||||
}
|
||||
resources, ok := summary["resources"].([]any)
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
for _, resource := range resources {
|
||||
row, ok := resource.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if rowKey, _ := row["key"].(string); rowKey == resourceKey {
|
||||
return readSummaryNumber(row["quantity"])
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func hasGiftResourcesSummary(summary map[string]any) bool {
|
||||
if summary == nil {
|
||||
return false
|
||||
}
|
||||
resources, ok := summary["resources"].([]any)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
for _, resource := range resources {
|
||||
row, ok := resource.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if mode, _ := row["mode"].(string); mode == "赠送" && readSummaryNumber(row["quantity"]) > 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isNightAvailableSummary(summary map[string]any) bool {
|
||||
if summary == nil {
|
||||
return false
|
||||
}
|
||||
onlineTime, ok := summary["online_time"].(map[string]any)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
start, okStart := parseTimeHourValue(onlineTime["start"])
|
||||
end, okEnd := parseTimeHourValue(onlineTime["end"])
|
||||
if !okStart || !okEnd {
|
||||
return false
|
||||
}
|
||||
return timeRangeCoversHour(start, end, 22) || timeRangeCoversHour(start, end, 23) || timeRangeCoversHour(start, end, 0)
|
||||
}
|
||||
|
||||
func parseTimeHourValue(value any) (int, bool) {
|
||||
text, ok := value.(string)
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
parts := strings.Split(text, ":")
|
||||
hour, err := strconv.Atoi(parts[0])
|
||||
if err != nil || hour < 0 || hour > 23 {
|
||||
return 0, false
|
||||
}
|
||||
return hour, true
|
||||
}
|
||||
|
||||
func timeRangeCoversHour(start int, end int, hour int) bool {
|
||||
if start == end {
|
||||
return true
|
||||
}
|
||||
if start < end {
|
||||
return hour >= start && hour <= end
|
||||
}
|
||||
return hour >= start || hour <= end
|
||||
}
|
||||
|
||||
func (r *Repository) FindPublic(id uint64) (*ListingDTO, error) {
|
||||
dto, err := r.findDTO("l.id = ? AND l.status = ? AND l.review_status = ? AND l.in_transaction = ?", id, "published", "approved", false)
|
||||
if err != nil {
|
||||
|
||||
@@ -163,11 +163,11 @@ func (s *Service) Offline(ownerID uint64, id uint64) error {
|
||||
return s.repo.Offline(ownerID, id)
|
||||
}
|
||||
|
||||
func (s *Service) ListPublic() ([]ListingDTO, error) {
|
||||
func (s *Service) ListPublic(query PublicListQuery) (*PublicListResult, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.ListPublic()
|
||||
return s.repo.ListPublic(query)
|
||||
}
|
||||
|
||||
func (s *Service) ListMine(ownerID uint64) ([]ListingDTO, error) {
|
||||
|
||||
Reference in New Issue
Block a user