feat: 接入旧站管理端并完整迁移后台能力
This commit is contained in:
@@ -2,11 +2,13 @@ package pickup
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"hfb_jysh/backend/internal/auditlog"
|
||||
"hfb_jysh/backend/internal/middleware"
|
||||
"hfb_jysh/backend/internal/timeutil"
|
||||
"hfb_jysh/backend/pkg/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -244,6 +246,31 @@ func (h *Handler) List(c *gin.Context) {
|
||||
response.OK(c, result)
|
||||
}
|
||||
|
||||
// Export 导出线下提号 CSV(管理员)。
|
||||
func (h *Handler) Export(c *gin.Context) {
|
||||
adminID, ok := currentAdminID(c)
|
||||
if !ok {
|
||||
response.Unauthorized(c, "缺少管理员上下文")
|
||||
return
|
||||
}
|
||||
query := parseAdminQuery(c)
|
||||
data, rowCount, err := h.service.ExportAdmin(c.Request.Context(), query, adminID, auditMeta(c))
|
||||
if err != nil {
|
||||
writePickupError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
timestamp := timeutil.ShanghaiNow().Format("20060102-150405")
|
||||
filename := fmt.Sprintf("线下提号_%s.csv", timestamp)
|
||||
asciiFilename := fmt.Sprintf("pickup-export-%s.csv", timestamp)
|
||||
c.Header(
|
||||
"Content-Disposition",
|
||||
fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, asciiFilename, encodeExportFilename(filename)),
|
||||
)
|
||||
c.Header("X-Export-Row-Count", fmt.Sprintf("%d", rowCount))
|
||||
c.Data(http.StatusOK, "text/csv; charset=utf-8", data)
|
||||
}
|
||||
|
||||
// ShopOptions 返回后台提号已使用的店铺名称。
|
||||
func (h *Handler) ShopOptions(c *gin.Context) {
|
||||
items, err := h.service.ListShopNames(c.Request.Context(), c.Query("platform"))
|
||||
@@ -333,6 +360,13 @@ func writePickupError(c *gin.Context, err error) {
|
||||
response.BadRequest(c, "提号订单已取消,不能补录单号")
|
||||
case errors.Is(err, ErrInvalidThirdPartyOrderNo):
|
||||
response.BadRequest(c, "第三方单号不能为空且长度不能超过128位")
|
||||
case errors.Is(err, ErrPickupExportTooLarge):
|
||||
response.Error(
|
||||
c,
|
||||
http.StatusBadRequest,
|
||||
"pickup_export_too_large",
|
||||
fmt.Sprintf("导出数据超过 %d 条,请缩小筛选范围", maxAdminPickupExportRows),
|
||||
)
|
||||
default:
|
||||
response.Error(c, http.StatusInternalServerError, "pickup_error", err.Error())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user