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

@@ -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