feat: 支持蝦皮批量创建 PDD 采集任务 (#185)
This commit is contained in:
+44
-15
@@ -75,6 +75,12 @@ func (h *Handler) renderShopeeList(c *gin.Context, keyword, shopName, statusRaw,
|
||||
"读取蝦皮数据失败,数据没有被改动。刷新页面重试;一直失败请把这句话报给维护者。")
|
||||
return
|
||||
}
|
||||
assignableClients, err := service.ListAssignableClients(h.db, currentUser(c), h.onlineThreshold)
|
||||
if err != nil {
|
||||
fail(c, http.StatusInternalServerError,
|
||||
"读取可选客户端失败,数据没有被改动。刷新页面重试。")
|
||||
return
|
||||
}
|
||||
|
||||
status := msg
|
||||
if status == "" {
|
||||
@@ -99,21 +105,22 @@ func (h *Handler) renderShopeeList(c *gin.Context, keyword, shopName, statusRaw,
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "shopee/list", page(c, "shopee", "蝦皮数据", gin.H{
|
||||
"Keyword": keyword,
|
||||
"ShopNameKeyword": filter.ShopName,
|
||||
"StatusFilter": filter.Status,
|
||||
"StatusOptions": service.ShopeeStatusOptions(),
|
||||
"ShopFilter": filter.Shop,
|
||||
"ShopOptions": service.ShopeePresenceOptions("有店铺", "无店铺"),
|
||||
"ImageFilter": filter.Image,
|
||||
"ImageOptions": service.ShopeePresenceOptions("有图片", "无图片"),
|
||||
"Rows": result.Rows,
|
||||
"Status": status,
|
||||
"HasAnyProducts": result.HasAnyProducts,
|
||||
"IsFiltered": result.IsFiltered,
|
||||
"Pagination": service.NewPaginationView(result.Page, result.TotalPages, values.Encode()),
|
||||
"CurrentPage": result.Page,
|
||||
"DetailURL": "/shopee/detail?" + detailValuesForShopee(values, result.Page),
|
||||
"Keyword": keyword,
|
||||
"ShopNameKeyword": filter.ShopName,
|
||||
"StatusFilter": filter.Status,
|
||||
"StatusOptions": service.ShopeeStatusOptions(),
|
||||
"ShopFilter": filter.Shop,
|
||||
"ShopOptions": service.ShopeePresenceOptions("有店铺", "无店铺"),
|
||||
"ImageFilter": filter.Image,
|
||||
"ImageOptions": service.ShopeePresenceOptions("有图片", "无图片"),
|
||||
"Rows": result.Rows,
|
||||
"Status": status,
|
||||
"HasAnyProducts": result.HasAnyProducts,
|
||||
"IsFiltered": result.IsFiltered,
|
||||
"Pagination": service.NewPaginationView(result.Page, result.TotalPages, values.Encode()),
|
||||
"CurrentPage": result.Page,
|
||||
"DetailURL": "/shopee/detail?" + detailValuesForShopee(values, result.Page),
|
||||
"AssignableClients": assignableClients,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -180,6 +187,28 @@ func (h *Handler) ShopeeCollect(c *gin.Context) {
|
||||
h.shopeeRedirect(c, service.FormatCollectTaskMessage(result))
|
||||
}
|
||||
|
||||
// ShopeeCollectBatch 为勾选的蝦皮商品按当前 PDD 关联批量创建采集任务。
|
||||
func (h *Handler) ShopeeCollectBatch(c *gin.Context) {
|
||||
ids := c.PostFormArray("ids")
|
||||
if len(ids) == 0 {
|
||||
h.shopeeRedirect(c, "没有勾选任何蝦皮商品,没有创建任务")
|
||||
return
|
||||
}
|
||||
result, err := service.CreateShopeePddCollectTasksForUser(
|
||||
h.db, currentUser(c), ids, c.PostForm("client_id"))
|
||||
if err != nil {
|
||||
status := http.StatusInternalServerError
|
||||
message := "创建采集任务失败,系统没有改动这一批数据。请稍后重试。"
|
||||
if service.IsValidationError(err) {
|
||||
status = http.StatusBadRequest
|
||||
message = err.Error() + "。这一批任务整体没有创建,请重新选择。"
|
||||
}
|
||||
fail(c, status, message)
|
||||
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 != "" {
|
||||
|
||||
@@ -59,6 +59,7 @@ func Register(r *gin.Engine, db *sql.DB, onlineThreshold time.Duration) {
|
||||
pages.POST("/shopee/save", h.ShopeeSave)
|
||||
pages.POST("/shopee/delete", h.ShopeeDelete)
|
||||
pages.POST("/shopee/collect", h.ShopeeCollect)
|
||||
pages.POST("/shopee/collect-batch", h.ShopeeCollectBatch)
|
||||
|
||||
// 2. PDD 商品
|
||||
pages.GET("/pdd", h.PddList)
|
||||
|
||||
Reference in New Issue
Block a user