package pickup import ( "strconv" "strings" "time" "hfb_sys/backend/internal/middleware" "hfb_sys/backend/pkg/response" "github.com/gin-gonic/gin" ) func currentAdminID(c *gin.Context) (uint64, bool) { value, ok := c.Get(middleware.ContextAdminID) if !ok { return 0, false } adminID, ok := value.(uint64) return adminID, ok } func currentUserID(c *gin.Context) (uint64, bool) { value, ok := c.Get(middleware.ContextUserID) if !ok { return 0, false } userID, ok := value.(uint64) return userID, ok } func parseID(c *gin.Context) (uint64, bool) { id, err := strconv.ParseUint(c.Param("id"), 10, 64) if err != nil || id == 0 { response.BadRequest(c, "ID 不正确") return 0, false } return id, true } func parsePagination(c *gin.Context) (int, int) { page, _ := strconv.Atoi(c.DefaultQuery("page", "1")) pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20")) if page < 1 { page = 1 } if pageSize < 1 { pageSize = 20 } if pageSize > 100 { pageSize = 100 } return page, pageSize } func parseFlexibleTime(val string) *time.Time { val = strings.TrimSpace(val) if val == "" { return nil } layouts := []string{ "2006-01-02 15:04:05", time.RFC3339, "2006-01-02T15:04:05", "2006-01-02", } loc := time.Local for _, layout := range layouts { if t, err := time.ParseInLocation(layout, val, loc); err == nil { return &t } } return nil } func parseAdminQuery(c *gin.Context) AdminPickupQuery { page, pageSize := parsePagination(c) return AdminPickupQuery{ Page: page, PageSize: pageSize, Keyword: c.Query("keyword"), Status: c.Query("status"), ShopName: c.Query("shop_name"), AccountSource: c.Query("account_source"), OfflineSettlementStatus: c.Query("offline_settlement_status"), Operator: c.Query("operator"), ThirdPartyOrderNo: c.Query("third_party_order_no"), StartTime: parseFlexibleTime(c.Query("start_time")), EndTime: parseFlexibleTime(c.Query("end_time")), } } func parsePickupShopQuery(c *gin.Context) PickupShopQuery { return PickupShopQuery{ Keyword: c.Query("keyword"), Platform: c.Query("platform"), Status: c.Query("status"), } } func parseSellerQuery(c *gin.Context) SellerPickupQuery { page, pageSize := parsePagination(c) return SellerPickupQuery{ Page: page, PageSize: pageSize, Status: c.Query("status"), } }