feat: 统一蝦皮与顺运宝 PDD 关联入口 (#68)
This commit is contained in:
+47
-20
@@ -7,6 +7,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -29,8 +30,6 @@ func (h *Handler) ShopeeList(c *gin.Context) {
|
||||
// 复用 #18 的弹窗机制:行上写 data-detail-id="{{.GoodsID}}",
|
||||
// 前端拿 goods_id 拼到 data-detail-url 后面,以 "id" 作为查询参数名
|
||||
// (固定写法,见 static/js/app.js「双击行打开详情弹窗」)。
|
||||
//
|
||||
// `[必须]` 这个弹窗只读,不含保存表单——ShopeeSave 仍是 501,见 #41。
|
||||
func (h *Handler) ShopeeDetail(c *gin.Context) {
|
||||
goodsID := strings.TrimSpace(c.Query("id"))
|
||||
if goodsID == "" {
|
||||
@@ -48,7 +47,11 @@ func (h *Handler) ShopeeDetail(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "shopee/detail_modal", gin.H{"D": detail})
|
||||
c.HTML(http.StatusOK, "shopee/detail_modal", gin.H{
|
||||
"D": detail, "CSRFToken": csrfToken(c),
|
||||
"Keyword": c.Query("goods_id"), "StatusFilter": c.Query("status"),
|
||||
"CurrentPage": service.ParsePage(c.Query("page")),
|
||||
})
|
||||
}
|
||||
|
||||
// ShopeeImport 处理 Excel 上传导入。
|
||||
@@ -182,9 +185,19 @@ func (h *Handler) renderShopeeList(c *gin.Context, keyword, statusRaw, pageRaw,
|
||||
"IsFiltered": result.IsFiltered,
|
||||
"Failures": failures,
|
||||
"Pagination": service.NewPaginationView(result.Page, result.TotalPages, values.Encode()),
|
||||
"DetailURL": "/shopee/detail?" + detailValuesForShopee(values, result.Page),
|
||||
}))
|
||||
}
|
||||
|
||||
func detailValuesForShopee(values url.Values, pageNum int) string {
|
||||
detailValues := url.Values{}
|
||||
for key, entries := range values {
|
||||
detailValues[key] = append([]string(nil), entries...)
|
||||
}
|
||||
detailValues.Set("page", strconv.Itoa(pageNum))
|
||||
return detailValues.Encode()
|
||||
}
|
||||
|
||||
// shopeeStatusLine 组装底部状态条的默认文案(没有 msg 覆盖时)。
|
||||
//
|
||||
// `[必须]` 显示的是筛选后的**全量**总数(result.Total),不是本页行数,
|
||||
@@ -198,22 +211,15 @@ func shopeeStatusLine(statusFilter string, result *service.ShopeeListResult) str
|
||||
return fmt.Sprintf("%s · 第 %d/%d 页", prefix, result.Page, result.TotalPages)
|
||||
}
|
||||
|
||||
// ShopeeSave 保存编辑弹窗里的内容(PDD 链接、颜色、尺码、建议)。
|
||||
//
|
||||
// 这是**从蝦皮商品出发**录入 PDD 链接的入口,
|
||||
// 见 docs/admin/05-ui-specification.md §4.3。PDD 商品页(§5)也能录入,
|
||||
// 两处并存;本页这个目前还是骨架,合并与否由「蝦皮↔PDD 关联入口」工单决定。
|
||||
//
|
||||
// `[不做]` 本工单(#38)明确不实现这个接口,保持 501。
|
||||
// ShopeeSave 保存蝦皮商品当前关联的 PDD 商品。
|
||||
func (h *Handler) ShopeeSave(c *gin.Context) {
|
||||
// TODO(骨架): 保存 PDD 链接时调 repository.EnsurePddProduct,
|
||||
// 由它去建 / 复用 / 复活 pdd_products 那一行。
|
||||
//
|
||||
// **采集状态不在蝦皮这边**:它属于 PDD 商品(pdd_products.collect_status)。
|
||||
// "还没填链接"由 shopee_products.pdd_goods_id IS NULL 表达——
|
||||
// 没填链接时 pdd_products 里根本不会有那一行。
|
||||
// 不要写 no_link,那个值在 #16 已从 CHECK 约束里删掉了,写了会直接撞约束。
|
||||
fail(c, http.StatusNotImplemented, "保存功能尚未实现。")
|
||||
goodsID, err := service.AssociateShopeePdd(h.db, c.PostForm("shopee_goods_id"),
|
||||
c.PostForm("pdd_url"), c.PostForm("confirm_replace") == "1")
|
||||
if err != nil {
|
||||
h.shopeeRedirect(c, "PDD 关联未保存:"+err.Error()+"。请核对链接后重试。")
|
||||
return
|
||||
}
|
||||
h.shopeeRedirect(c, fmt.Sprintf("已关联 PDD 商品 %s,可继续创建采集任务", goodsID))
|
||||
}
|
||||
|
||||
// ShopeeDelete 批量删除勾选的行。
|
||||
@@ -236,6 +242,27 @@ func (h *Handler) ShopeeDelete(c *gin.Context) {
|
||||
//
|
||||
// `[不做]` 本工单(#38)明确不实现这个接口,保持 501。
|
||||
func (h *Handler) ShopeeCollect(c *gin.Context) {
|
||||
// TODO(骨架): 调 service.CreateCollectTasks(goodsIDs, clientID)
|
||||
fail(c, http.StatusNotImplemented, "采集功能尚未实现。")
|
||||
result, err := service.CreateShopeePddCollectTask(h.db, c.PostForm("shopee_goods_id"))
|
||||
if err != nil {
|
||||
h.shopeeRedirect(c, "采集任务未创建:"+err.Error())
|
||||
return
|
||||
}
|
||||
h.shopeeRedirect(c, service.FormatCollectTaskMessage(result))
|
||||
}
|
||||
|
||||
func (h *Handler) shopeeRedirect(c *gin.Context, msg string) {
|
||||
params := url.Values{}
|
||||
if value := strings.TrimSpace(c.PostForm("list_goods_id")); value != "" {
|
||||
params.Set("goods_id", value)
|
||||
}
|
||||
if value := strings.TrimSpace(c.PostForm("status")); value != "" {
|
||||
params.Set("status", service.ParseShopeeStatus(value))
|
||||
}
|
||||
if value := strings.TrimSpace(c.PostForm("page")); value != "" {
|
||||
params.Set("page", value)
|
||||
}
|
||||
if msg != "" {
|
||||
params.Set("msg", msg)
|
||||
}
|
||||
c.Redirect(http.StatusSeeOther, "/shopee?"+params.Encode())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user