This commit is contained in:
邹宗楠
2026-05-15 09:17:29 +08:00
parent adeb6575cb
commit d7aab91a20
9 changed files with 156 additions and 32 deletions

View File

@@ -322,6 +322,9 @@ func genNormalHavePageResultParser(dataKey string) (handler PageResultParser) {
return nil, 0, platformapi.ErrResponseDataFormatWrong
}
}
if resultStr, ok := tempResult.(map[string]interface{}); ok {
result0 = resultStr
}
result = result0
if totalCount == 0 {

View File

@@ -30,7 +30,9 @@ func init() {
// 天天果园
//api = New("c45e6510-00ba-4be2-977e-bcb9c9792cc7", "5d5577a2506f41b8b4ec520ba83490f5", "0b01b9eeb15b41dab1c3d05d95c17a26")
// 京东果园 320406
api = New("de4a9818-b171-41ed-ba37-0b060cad001f", "1dba76d40cac446ca500c0391a0b6c9d", "a88d031a1e7b462cb1579f12e97fe7f4")
//api = New("de4a9818-b171-41ed-ba37-0b060cad001f", "1dba76d40cac446ca500c0391a0b6c9d", "a88d031a1e7b462cb1579f12e97fe7f4")
// 京东秒送
api = New("697379cc-dde4-4b42-b845-5257ac5b4312", "64C3C0F83C23398B706BDAF3C8276B5A", "10b7d760b8504bf98e6faeba2561c7b9")
// 京东白货
//api = New("9053e4fd-4e0e-4e9e-8ab1-f348e5cbf3e7", "4602bd4b84984186815dbc03299c7094", "386ab19719d9470487011217d0c57349")
// 果切 379599

View File

@@ -2,10 +2,9 @@ package jdapi
import (
"fmt"
"git.rosy.net.cn/baseapi/utils"
"regexp"
"strings"
"git.rosy.net.cn/baseapi/utils"
)
const (
@@ -188,26 +187,25 @@ const (
)
type OpSkuParam struct {
TraceID string `json:"traceId"`
OutSkuID string `json:"outSkuId"`
ShopCategories []int64 `json:"shopCategories,omitempty"`
CategoryID int64 `json:"categoryId,omitempty"`
BrandID int64 `json:"brandId,omitempty"`
SkuName string `json:"skuName,omitempty"`
SkuPrice int `json:"skuPrice,omitempty"`
Weight float64 `json:"weight,omitempty"`
FixedStatus int `json:"fixedStatus,omitempty"` // 商家商品上下架状态(1:上架;2:下架;4:删除;)
IsSale int `json:"-"` // 创建0,1可售-1不可售更新0忽略1可售-1不可售
DontUseThisFieldDirectlyIsSale bool `json:"isSale"` // 门店商品可售状态(true/false)新建商品时如果为true门店商品可售状态初始为可售如果为false 门店商品可售状态初始为不可售。后续修改各个门店商品可售状态时,请使用根据京东到家商品编码批量修改门店商品可售状态接口。
Upc string `json:"upcCode,omitempty"` // TODO 老版与新版接口参数不一致UPC编码商品条码限1-35个字符包装类的商品要求UPC编码必填且要符合条码编写的校验否则商品会不予通过接口返回错误状态码code为10059。
Images []string `json:"images,omitempty"`
ProductDesc string `json:"productDesc,omitempty"`
IfViewDesc int `json:"ifViewDesc"`
Slogan string `json:"slogan,omitempty"`
SloganStartTime string `json:"sloganStartTime,omitempty"`
SloganEndTime string `json:"sloganEndTime,omitempty"`
SellCities []int64 `json:"sellCities,omitempty"`
TraceID string `json:"traceId"`
OutSkuID string `json:"outSkuId"`
ShopCategories []int64 `json:"shopCategories,omitempty"`
CategoryID int64 `json:"categoryId,omitempty"`
BrandID int64 `json:"brandId,omitempty"`
SkuName string `json:"skuName,omitempty"`
SkuPrice int `json:"skuPrice,omitempty"`
Weight float64 `json:"weight,omitempty"`
FixedStatus int `json:"fixedStatus,omitempty"` // 商家商品上下架状态(1:上架;2:下架;4:删除;)
IsSale int `json:"-"` // 创建0,1可售-1不可售更新0忽略1可售-1不可售
DontUseThisFieldDirectlyIsSale bool `json:"isSale"` // 门店商品可售状态(true/false)新建商品时如果为true门店商品可售状态初始为可售如果为false 门店商品可售状态初始为不可售。后续修改各个门店商品可售状态时,请使用根据京东到家商品编码批量修改门店商品可售状态接口。
Upc string `json:"upcCode,omitempty"` // TODO 老版与新版接口参数不一致UPC编码商品条码限1-35个字符包装类的商品要求UPC编码必填且要符合条码编写的校验否则商品会不予通过接口返回错误状态码code为10059。
Images []string `json:"images,omitempty"`
ProductDesc string `json:"productDesc,omitempty"`
IfViewDesc int `json:"ifViewDesc"`
Slogan string `json:"slogan,omitempty"`
SloganStartTime string `json:"sloganStartTime,omitempty"`
SloganEndTime string `json:"sloganEndTime,omitempty"`
SellCities []int64 `json:"sellCities,omitempty"`
}
type QueryListBySkuIdsParam struct {
@@ -415,6 +413,60 @@ func (a *API) AddSku2(param *OpSkuParam) (skuID string, err error) {
return "", err
}
func (a *API) NewAddSku(param *NewAddSkuParam) (skuID string, err error) {
mapData := utils.Struct2MapByJson(param)
result, err := a.AccessAPINoPage("pms/addSku", mapData, nil, nil, nil)
if err == nil {
skuId := utils.Interface2Int64WithDefault(result.(map[string]interface{})["skuId"], 0)
return utils.Int64ToStr(skuId), nil
}
return "", err
}
type NewAddSkuParam struct {
//LimitPurchaseNum int `json:"limitPurchaseNum"`
TraceId string `json:"traceId"`
OutSkuId string `json:"outSkuId"`
ShopCategories []int64 `json:"shopCategories"`
CategoryId int64 `json:"categoryId"`
BrandId int64 `json:"brandId"`
SkuName string `json:"skuName"`
SkuPrice int64 `json:"skuPrice"`
Weight float64 `json:"weight"`
Upc string `json:"upc"`
Images []string `json:"images"`
ProductDesc string `json:"productDesc"`
//IfViewDesc int `json:"ifViewDesc"`
//Slogan string `json:"slogan"`
//SloganStartTime time.Time `json:"sloganStartTime"`
//SloganEndTime time.Time `json:"sloganEndTime"`
//PrefixKeyId string `json:"prefixKeyId"`
//PrefixKey string `json:"prefixKey"`
//PreKeyStartTime time.Time `json:"preKeyStartTime"`
//PreKeyEndTime time.Time `json:"preKeyEndTime"`
//Length int `json:"length"`
//Width int `json:"width"`
//Height int `json:"height"`
//TransportAttribute string `json:"transportAttribute"`
//LiquidStatue string `json:"liquidStatue"`
//Prescripition string `json:"prescripition"`
//HighSingularValue string `json:"highSingularValue"`
//IsBreakable string `json:"isBreakable"`
FixedStatus int `json:"fixedStatus"`
IsSale bool `json:"isSale"`
//SellCities []int64 `json:"sellCities"`
//PackageFee float64 `json:"packageFee"`
//BusinessMark []int `json:"businessMark"`
//ReturnLabel string `json:"returnLabel"`
//RegistImage string `json:"registImage"`
//ApprovalTime time.Time `json:"approvalTime"`
//EndTime time.Time `json:"endTime"`
//CategoryAttrs interface{} `json:"categoryAttrs"`
//SalePointList interface{} `json:"salePointList"`
//StationShopCategories interface{} `json:"stationShopCategories"`
//OutStationNos interface{} `json:"outStationNos"`
}
// 根据商家商品编码修改商品信息接口
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=180&apiid=290bdb0ea8a44e10b86b05591254ad68
func (a *API) UpdateSku(outSkuId string, params map[string]interface{}) (skuId string, err error) {
@@ -797,7 +849,7 @@ func GetJdSkuIDFromError(err error) int64 {
func (a *API) GetSkuCategoryBySkuName(productName string) (*GetSkuCategoryBySkuName, error) {
result, err := a.AccessAPINoPage("pms/getSkuCateBrandBySkuName", map[string]interface{}{
"productName": productName,
"fields": []string{"category"},
"fields": []string{"category", "brand"},
}, nil, nil, nil)
if err != nil {
return nil, err

View File

@@ -3,6 +3,7 @@ package jdapi
import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals"
"math"
"strings"
"testing"
"time"
@@ -67,8 +68,64 @@ func TestAddsku(t *testing.T) {
globals.SugarLogger.Debugf("--------result := %v", err)
}
func TestNewAddSku(t *testing.T) {
param := &NewAddSkuParam{
TraceId: "DF9546E34F6211F1921B525400E86DC0,18981810340",
OutSkuId: "233273851",
ShopCategories: []int64{104189639},
CategoryId: 28303,
SkuName: "猎豹清理大师16GBU盘一枚",
SkuPrice: 4300,
Weight: math.Round(0.00099*1000) / 1000,
FixedStatus: 1,
IsSale: true,
Upc: "6970773196481", //
Images: []string{
"http://p1.meituan.net/retailsp/2baf3c5c5fddffe84fac0a557c52455f264447.jpg",
},
//IfViewDesc: 0,
}
if param.Upc == "" {
productInfo, _ := api.GetJdUpcCodeByName(param.SkuName, "", 1, 10)
if len(productInfo) != 0 {
param.Upc = productInfo[0].UpcCode
}
}
brandList, err := api.GetSkuCategoryBySkuName(param.SkuName)
if brandList == nil || err != nil {
param.BrandId = 35247
} else {
param.BrandId = int64(brandList.BrandId)
param.CategoryId = int64(brandList.CategoryId)
}
result, err := api.NewAddSku(param)
globals.SugarLogger.Debugf("--------result r1 := %s", result)
globals.SugarLogger.Debugf("--------err r1 := %v", err)
err1 := api.UpdateCurrentQty("1122131212", "23378966", utils.Str2Int64(result), 9999)
if err1 != nil {
globals.SugarLogger.Debugf("--------err r1 := %v", err1)
}
_, err2 := api.UpdateVendibility("225886314785", []*QueryStockRequest{
&QueryStockRequest{
StationNo: "23378966",
SkuId: utils.Str2Int64(result),
DoSale: 0,
},
})
if err2 != nil {
globals.SugarLogger.Debugf("--------err r1 := %v", err2)
}
globals.SugarLogger.Debugf("--------result := %s", utils.Format4Output(result, false))
globals.SugarLogger.Debugf("--------result := %v", err)
}
// 根据品名获取到家品牌编号ID
func TestQueryPageBrandInfo(t *testing.T) {
brandList, _, err := api.QueryPageBrandInfo(1, 20, 0, "锐澳 海盐荔枝伏特加味鸡尾酒")
brandList, _, err := api.QueryPageBrandInfo(1, 20, 0, "锐澳")
globals.SugarLogger.Debugf("--------result := %s", utils.Format4Output(brandList, false))
globals.SugarLogger.Debugf("--------result := %v", err)
}

View File

@@ -40,7 +40,7 @@ func TestGetStationsByVenderId(t *testing.T) {
}
func TestGetStoreInfoByStationNo(t *testing.T) {
result, err := api.GetStoreInfoByStationNo2("21103071")
result, err := api.GetStoreInfoByStationNo2("23378966")
if err != nil {
t.Fatal(err)
}