修正商品发货地定位逻辑

改用高德地图附近 POI 查询发货地,移除闲鱼定位接口调用。发货地改为可选项,虚拟商品可直接发布;修正闲鱼网页版要求的纬度、经度 GPS 顺序,并补充前端映射与发布测试。
This commit is contained in:
Christ committed 2026-08-13 11:44:35 +08:00
1 parent 65bcb8f15c
commit ac85ac8a0a
15 files changed
+255 -214

No files matched your search

-52
View File
@@ -23,7 +23,6 @@ func (s *Server) mountItemsReal(r chi.Router) {
r.Post("/items/get-all-from-account", s.syncItemsFromAccount)
r.Post("/items/get-by-page", s.syncItemsPageFromAccount)
r.Post("/items/publish", s.publishItem)
r.Post("/items/publish-locations", s.publishLocations)
r.Post("/items/publish-categories/recommend", s.recommendItemPublishCategory)
r.Post("/items/publish-batches/preview", s.previewItemPublishBatch)
r.Post("/items/publish-batches", s.startItemPublishBatch)
@@ -42,57 +41,6 @@ func (s *Server) mountItemsReal(r chi.Router) {
r.Put("/items/{cookie_id}/{item_id}/multi-quantity-delivery", s.setItemMultiQuantity)
}
func (s *Server) publishLocations(w http.ResponseWriter, r *http.Request) {
var req struct {
CookieID string `json:"cookie_id"`
Longitude float64 `json:"longitude"`
Latitude float64 `json:"latitude"`
}
if err := decodeJSON(r, &req); err != nil || strings.TrimSpace(req.CookieID) == "" {
writeErr(w, http.StatusBadRequest, "请选择账号并提供当前位置")
return
}
_, userID, ok := s.cookieForCurrentUser(w, r, strings.TrimSpace(req.CookieID))
if !ok {
return
}
credentialUnlock := s.Store.LockAccountCredentials(req.CookieID)
defer credentialUnlock()
latest, err := s.Store.Cookies.GetDetails(r.Context(), req.CookieID)
if err != nil || latest == nil || latest.UserID != userID || !hasStoredCookieCredential(latest) {
writeErr(w, http.StatusConflict, "账号凭证已变化,请重试")
return
}
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
defer cancel()
mtopCtx, cookieSession := withMTopCookieSnapshot(ctx, latest)
locator, ok := s.mtopClient().(interface {
PublishLocations(context.Context, string, float64, float64) ([]mtop.PublishLocation, string, error)
})
if !ok {
writeErr(w, http.StatusNotImplemented, "当前客户端不支持查询发货地")
return
}
locations, updated, callErr := locator.PublishLocations(mtopCtx, latest.Value, req.Longitude, req.Latitude)
value, changed, handled, persistErr := s.persistMTopCookieSessionLocked(r.Context(), latest, cookieSession)
if persistErr != nil {
writeErr(w, http.StatusInternalServerError, "保存账号登录状态失败")
return
}
if !handled && updated != "" && updated != latest.Value {
if err := s.Store.Cookies.UpdateValueOwned(r.Context(), req.CookieID, updated, userID); err == nil {
s.updateRunningCookie(r.Context(), req.CookieID, updated)
}
} else if handled && changed {
s.updateRunningCookie(r.Context(), req.CookieID, value)
}
if callErr != nil {
writeErr(w, http.StatusBadGateway, callErr.Error())
return
}
writeJSON(w, http.StatusOK, map[string]any{"success": true, "locations": locations})
}
func (s *Server) publishItem(w http.ResponseWriter, r *http.Request) {
// 最多 9 张 10 MiB 图片,额外预留 multipart 元数据空间。
r.Body = http.MaxBytesReader(w, r.Body, maxItemPublishBytes)
-4
View File
@@ -241,8 +241,6 @@ func TestPublishItemSuccess(t *testing.T) {
switch {
case strings.Contains(u, "stream-upload.goofish.com"):
respBody = `{"object":{"url":"https://img.alicdn.com/published.png","pix":"800_800"}}`
case strings.Contains(u, "mtop.taobao.idle.local.poi.get"):
respBody = `{"ret":["SUCCESS::调用成功"],"data":{"commonAddresses":[{"address":"北京"}]}}`
case strings.Contains(u, "mtop.taobao.idle.kgraph.property.recommend"):
respBody = `{"ret":["SUCCESS::调用成功"],"data":{"categoryPredictResult":{"catId":"99","catName":"数码"}}}`
case strings.Contains(u, "mtop.idle.pc.idleitem.publish"):
@@ -330,8 +328,6 @@ func TestPublishItemStockPermissionMissing(t *testing.T) {
switch {
case strings.Contains(u, "stream-upload.goofish.com"):
respBody = `{"object":{"url":"https://img.alicdn.com/published.png","pix":"800_800"}}`
case strings.Contains(u, "mtop.taobao.idle.local.poi.get"):
respBody = `{"ret":["SUCCESS::调用成功"],"data":{"commonAddresses":[{"address":"北京"}]}}`
case strings.Contains(u, "mtop.taobao.idle.kgraph.property.recommend"):
respBody = `{"ret":["SUCCESS::调用成功"],"data":{"categoryPredictResult":{"catId":"99","catName":"数码"}}}`
case strings.Contains(u, "mtop.idle.pc.idleitem.publish"):
@@ -311,8 +311,6 @@ func TestRunItemPublishBatch_Success(t *testing.T) {
switch {
case strings.Contains(u, "stream-upload.goofish.com"):
body = `{"object":{"url":"https://img.alicdn.com/published.png","pix":"800_800"}}`
case strings.Contains(u, "mtop.taobao.idle.local.poi.get"):
body = `{"ret":["SUCCESS::调用成功"],"data":{"commonAddresses":[{"address":"北京"}]}}`
case strings.Contains(u, "mtop.taobao.idle.kgraph.property.recommend"):
body = `{"ret":["SUCCESS::调用成功"],"data":{}}`
case strings.Contains(u, "mtop.idle.pc.idleitem.publish"):