589 lines
14 KiB
Go
589 lines
14 KiB
Go
package jdshopapi
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/md5"
|
|
"encoding/json"
|
|
"fmt"
|
|
"image"
|
|
"image/gif"
|
|
"image/jpeg"
|
|
"image/png"
|
|
"io/ioutil"
|
|
"math"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"git.rosy.net.cn/baseapi/platformapi"
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
)
|
|
|
|
func TestFindShopCategories(t *testing.T) {
|
|
result, err := api.FindShopCategories()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestDeleteShopCategory(t *testing.T) {
|
|
result, err := api.DeleteShopCategory(14439186)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestUploadPicture(t *testing.T) {
|
|
data, _, err := DownloadFileByURL("https://image.jxc4.com/noGoodsImg.jpg")
|
|
// img, outMimeType, _ := Binary2Image(data, "")
|
|
// result2, _ := Image2Binary(img, outMimeType)
|
|
result, err := api.UploadPicture(data, 0, "noGoodsImg")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func DownloadFileByURL(fileURL string) (bodyData []byte, fileMD5 string, err error) {
|
|
response, err := http.Get(fileURL)
|
|
if err == nil {
|
|
defer response.Body.Close()
|
|
if response.StatusCode == http.StatusOK {
|
|
if bodyData, err = ioutil.ReadAll(response.Body); err == nil {
|
|
fileMD5 = fmt.Sprintf("%X", md5.Sum(bodyData))
|
|
}
|
|
} else {
|
|
err = platformapi.ErrHTTPCodeIsNot200
|
|
}
|
|
}
|
|
return bodyData, fileMD5, err
|
|
}
|
|
|
|
func Binary2Image(binaryData []byte, mimeType string) (img image.Image, outMimeType string, err error) {
|
|
if mimeType == "" {
|
|
mimeType = http.DetectContentType(binaryData)
|
|
}
|
|
switch mimeType {
|
|
case model.MimeTypeJpeg:
|
|
img, err = jpeg.Decode(bytes.NewReader(binaryData))
|
|
case model.MimeTypePng:
|
|
img, err = png.Decode(bytes.NewReader(binaryData))
|
|
case model.MimeTypeGif:
|
|
img, err = gif.Decode(bytes.NewReader(binaryData))
|
|
}
|
|
return img, mimeType, err
|
|
}
|
|
|
|
func Image2Binary(img image.Image, mimeType string) (binaryData []byte, err error) {
|
|
buf := new(bytes.Buffer)
|
|
switch mimeType {
|
|
case model.MimeTypeJpeg:
|
|
jpeg.Encode(buf, img, nil)
|
|
case model.MimeTypePng:
|
|
png.Encode(buf, img)
|
|
case model.MimeTypeGif:
|
|
gif.Encode(buf, img, nil)
|
|
}
|
|
binaryData = buf.Bytes()
|
|
return binaryData, err
|
|
}
|
|
|
|
func TestGetFeightMb(t *testing.T) {
|
|
err := api.GetFeightMb()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestAA(t *testing.T) {
|
|
ware := &CreateSkuParamWare{
|
|
Title: "测试商品1",
|
|
ShopCategorys: []int{11},
|
|
CategoryID: 13577,
|
|
TransportID: TransportID,
|
|
MobileDesc: "测试",
|
|
Introduction: "测试",
|
|
WareStatus: 8,
|
|
OuterID: "1",
|
|
Weight: 2300,
|
|
Height: 100,
|
|
Length: 100,
|
|
Width: 100,
|
|
JdPrice: 20,
|
|
MarketPrice: 10,
|
|
VenderID: 0,
|
|
BrandID: JxBrandId,
|
|
}
|
|
result, _ := json.Marshal(ware)
|
|
fmt.Println(string(result))
|
|
}
|
|
|
|
func TestCreateSku(t *testing.T) {
|
|
var images []*CreateSkuParamImages
|
|
var skus []*CreateSkuParamSkus
|
|
var attrs []*CreateSkuParamAttrs
|
|
var attrs2 []*CreateSkuParamAttrs
|
|
var attrs3 []*CreateSkuParamAttrs
|
|
var features []*CreateSkuParamFeatures
|
|
feature := &CreateSkuParamFeatures{
|
|
Key: "is7ToReturn",
|
|
Value: "0",
|
|
}
|
|
features = append(features, feature)
|
|
// desc = "aa"
|
|
// desc := `<p>因生鲜比较脆弱,发货途中如果有磕碰损坏,请收到联系客服,闪电赔付。请核对好地址,发货后不可修改地址,因改地址导致损坏不能赔付,谢谢理解</p><p><img style="width:auto;height:auto;max-width:100%;" src="//img10.360buyimg.com/imgzone/jfs/t1/111969/32/6692/171733/5ebbb9daE5bedb5b2/38350dca19e2b9d2.jpg"><br></p><p><br></p>`
|
|
desc := `<p>因生鲜比较脆弱,发货途中如果有磕碰损坏,请收到联系客服,闪电赔付。请核对好地址,发货后不可修改地址,因改地址导致损坏不能赔付,谢谢理解</p><p><img style="width:auto;height:auto;max-width:100%;" src="//img10.360buyimg.com/imgzone/jfs/t1/126814/22/1326/472568/5ebb888dEa2cfb5f6/c0c81db660994246.jpg"><br></p><p><br></p>`
|
|
ware := &CreateSkuParamWare{
|
|
Title: "测试商品1",
|
|
// ShopCategorys: []int{11},
|
|
CategoryID: 13577,
|
|
TransportID: TransportID,
|
|
// MobileDesc: "测试",
|
|
// Introduction: "测试",
|
|
WareStatus: 8,
|
|
OuterID: "1",
|
|
Weight: 2300,
|
|
Height: 100,
|
|
Length: 100,
|
|
Width: 100,
|
|
JdPrice: 20,
|
|
MarketPrice: 10,
|
|
VenderID: 0,
|
|
BrandID: JxBrandId,
|
|
PromiseID: JdsPromiseID,
|
|
}
|
|
ware.Features = features
|
|
ware.MobileDesc = "aa"
|
|
ware.Introduction = desc
|
|
image := &CreateSkuParamImages{
|
|
ColorID: "0000000000",
|
|
ImgIndex: 1,
|
|
ImgURL: "jfs/t1/124185/34/1067/20460/5eb90d1aE2a81b6e4/ab451433f5e963b0.jpg",
|
|
}
|
|
images = append(images, image)
|
|
ware.Images = images
|
|
sku := &CreateSkuParamSkus{
|
|
JdPrice: 10,
|
|
StockNum: 1,
|
|
Type: "com.jd.pop.ware.ic.api.domain.sku",
|
|
Type2: "com.jd.pop.ware.ic.api.domain.Sku",
|
|
OuterID: "1",
|
|
}
|
|
sku2 := &CreateSkuParamSkus{
|
|
JdPrice: 10,
|
|
StockNum: 1,
|
|
Type: "com.jd.pop.ware.ic.api.domain.sku",
|
|
Type2: "com.jd.pop.ware.ic.api.domain.Sku",
|
|
OuterID: "2",
|
|
}
|
|
attr1 := &CreateSkuParamAttrs{
|
|
AttrID: "109692",
|
|
AttrValues: []string{"613613"},
|
|
}
|
|
// attr2 := &CreateSkuParamAttrs{
|
|
// AttrID: "109897",
|
|
// AttrValues: []string{"613771"},
|
|
// }
|
|
attr3 := &CreateSkuParamAttrs{
|
|
AttrID: "160508",
|
|
AttrValues: []string{"0.5"},
|
|
}
|
|
attr4 := &CreateSkuParamAttrs{
|
|
AttrID: "160781",
|
|
AttrValues: []string{"5"},
|
|
}
|
|
attr5 := &CreateSkuParamAttrs{
|
|
AttrID: "1001027606",
|
|
AttrValues: []string{"2440273517"},
|
|
}
|
|
attr6 := &CreateSkuParamAttrs{
|
|
AttrID: "1001027606",
|
|
AttrValues: []string{"2440272539"},
|
|
}
|
|
attrs = append(attrs, attr1)
|
|
// attrs = append(attrs, attr2)
|
|
attrs = append(attrs, attr3)
|
|
attrs = append(attrs, attr4)
|
|
attrs2 = append(attrs2, attr5)
|
|
attrs3 = append(attrs3, attr6)
|
|
ware.MultiCateProps = attrs
|
|
sku2.SaleAttrs = attrs3
|
|
sku.SaleAttrs = attrs2
|
|
skus = append(skus, sku)
|
|
skus = append(skus, sku2)
|
|
// ware.Skus = skus
|
|
result, err := api.CreateWare(ware, skus)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestFindVendorCategories(t *testing.T) {
|
|
result, err := api.FindVendorCategories()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestFindAttrs(t *testing.T) {
|
|
result, err := api.FindAttrs(15245)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestFindValuesByAttrId(t *testing.T) {
|
|
result, no, err := api.FindValuesByAttrId(1001038262)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
fmt.Println(no)
|
|
}
|
|
|
|
func TestSaveVenderAttrValue(t *testing.T) {
|
|
_, err := api.SaveVenderAttrValue("100g", 1001027606, 13577, 2)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestDeleteWare(t *testing.T) {
|
|
err := api.DeleteWare(14518369562)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestUpOrDown(t *testing.T) {
|
|
err := api.UpOrDown(14518369562, 2)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestUpdateWare(t *testing.T) {
|
|
err := api.UpdateWare(&UpdateWareParam{
|
|
WareID: 14545996691,
|
|
Title: "进口凤梨",
|
|
Features: []*CreateSkuParamFeatures{
|
|
&CreateSkuParamFeatures{
|
|
Key: "fdms",
|
|
Value: "1",
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestFindSkuStock(t *testing.T) {
|
|
err := api.FindSkuStock(69353673334)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestQueryPicture(t *testing.T) {
|
|
result, err := api.QueryPicture("[畅销]香蕉1")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestImageUpdate(t *testing.T) {
|
|
err := api.ImageUpdate(14535527473, 1, "jfs/t1/116844/10/7385/198098/5ec3853bEa53d0730/168e5654c6309c96.jpg")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestSearchWare4Valid(t *testing.T) {
|
|
result, err := api.SearchWare4Valid("猕猴桃 奇异果", 0, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestUpdateSkus(t *testing.T) {
|
|
_, err := api.UpdateSkus(&UpdateSkusParam{
|
|
WareID: 14537944716,
|
|
Skus: []*UpdateSkusParamSkus{
|
|
&UpdateSkusParamSkus{
|
|
WareID: 14537944716,
|
|
JdPrice: 1.5,
|
|
StockNum: "99",
|
|
OuterID: "11",
|
|
SaleAttrs: []*CreateSkuParamAttrs{
|
|
&CreateSkuParamAttrs{
|
|
AttrID: "1001027602",
|
|
AttrValues: []string{"2440977935"},
|
|
},
|
|
},
|
|
Type: "com.jd.pop.ware.ic.api.domain.sku",
|
|
Type2: "com.jd.pop.ware.ic.api.domain.Sku",
|
|
},
|
|
&UpdateSkusParamSkus{
|
|
WareID: 14537944716,
|
|
JdPrice: 1.8,
|
|
StockNum: "99",
|
|
OuterID: "123",
|
|
SaleAttrs: []*CreateSkuParamAttrs{
|
|
&CreateSkuParamAttrs{
|
|
AttrID: "1001027602",
|
|
AttrValues: []string{"2441761921"},
|
|
},
|
|
},
|
|
Type: "com.jd.pop.ware.ic.api.domain.sku",
|
|
Type2: "com.jd.pop.ware.ic.api.domain.Sku",
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestDeleteSku(t *testing.T) {
|
|
err := api.DeleteSku(69576828876)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestFindSkuById(t *testing.T) {
|
|
result, err := api.FindSkuById(69948250090)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestUpdateWareMarketPrice(t *testing.T) {
|
|
err := api.UpdateWareMarketPrice(14539778638, 500)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestFindOpReason(t *testing.T) {
|
|
result, err := api.FindOpReason(14519009105)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestAAAA(t *testing.T) {
|
|
var (
|
|
lng = 114.893295
|
|
lat = 25.85793
|
|
)
|
|
const (
|
|
maxRadius = 5000
|
|
maxStoreCount4User = 5
|
|
)
|
|
lng2, _ := ConvertDistanceToLogLat(lng, lat, float64(maxRadius), 90)
|
|
_, lat2 := ConvertDistanceToLogLat(lng, lat, float64(maxRadius), 0)
|
|
lng1 := lng - (lng2 - lng)
|
|
lat1 := lat - (lat2 - lat)
|
|
fmt.Println(lng1, lng2, lat1, lat2)
|
|
}
|
|
|
|
func ConvertDistanceToLogLat(lng, lat, distance, angle float64) (newLng, newLat float64) {
|
|
oneDu := 111319.55 // 单位为米
|
|
newLng = lng + (distance*math.Sin(angle*math.Pi/180))/(oneDu*math.Cos(lat*math.Pi/180)) //将距离转换成经度的计算公式
|
|
newLat = lat + (distance*math.Cos(angle*math.Pi/180))/oneDu //将距离转换成纬度的计算公式
|
|
return newLng, newLat
|
|
}
|
|
|
|
func TestFindWareById(t *testing.T) {
|
|
err := api.FindWareById(14546096098)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestTransparentImageAdd(t *testing.T) {
|
|
str := "12300548611401"
|
|
// suffix := str[12:len(str)]
|
|
fmt.Println(str[:12])
|
|
}
|
|
|
|
func TestUpdateWareSaleAttrvalueAlias(t *testing.T) {
|
|
err := api.UpdateWareSaleAttrvalueAlias(&UpdateWareSaleAttrvalueAliasParam{
|
|
WareID: 14566414324,
|
|
Props: []*CreateSkuParamAttrs2{
|
|
&CreateSkuParamAttrs2{
|
|
AttrID: "1001038262",
|
|
AttrValues: []string{"2453826609"},
|
|
AttrValueAlias: []string{"500g 下午易缺货"},
|
|
Type: "com.jd.pop.ware.ic.api.domain.prop",
|
|
Type2: "com.jd.pop.ware.ic.api.domain.Prop",
|
|
},
|
|
},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestSearchSkuList(t *testing.T) {
|
|
var wareIDs = []int64{
|
|
14518860227,
|
|
14518865342,
|
|
14518857791,
|
|
14518863440,
|
|
14518850181,
|
|
14518869426,
|
|
14518865836,
|
|
14518860282,
|
|
14518862865,
|
|
14518860089,
|
|
14518861773,
|
|
14518857091,
|
|
14518859794,
|
|
14518878413,
|
|
14518874243,
|
|
14518992990,
|
|
14519010404,
|
|
14519010010,
|
|
14519006838,
|
|
14519009822,
|
|
14541114008,
|
|
14542371664,
|
|
14542409106,
|
|
14542477967,
|
|
14542585438,
|
|
14542602011,
|
|
14542586377,
|
|
14542927723,
|
|
14542946611,
|
|
14542948535,
|
|
14543031285,
|
|
14543077206,
|
|
14544951705,
|
|
14546014638,
|
|
14565258994,
|
|
14565275855,
|
|
14566133342,
|
|
14566144059,
|
|
14566419305,
|
|
14566403990,
|
|
14566408956,
|
|
14567187277,
|
|
14567793468,
|
|
14567911336,
|
|
14567910034,
|
|
14567907049,
|
|
14567904981,
|
|
14567909664,
|
|
14567907786,
|
|
14568001774,
|
|
14568152611,
|
|
14568138877,
|
|
14568146252,
|
|
14568161923,
|
|
14568508881,
|
|
14568512475,
|
|
14568524772,
|
|
14568533264,
|
|
14568540322,
|
|
14568534834,
|
|
14568546936,
|
|
14568542882,
|
|
14568806841,
|
|
14576405495,
|
|
14576832607,
|
|
14576832017,
|
|
14576946037,
|
|
14576974106,
|
|
14576993226,
|
|
14579143223,
|
|
14581769973,
|
|
14581773059,
|
|
14581773646,
|
|
14581780520,
|
|
14581782920,
|
|
14581768094,
|
|
14581788365,
|
|
14581805504,
|
|
14581919920,
|
|
14581915051,
|
|
14581920950,
|
|
14581971709,
|
|
14581979302,
|
|
14581974927,
|
|
14581974739,
|
|
14581964099,
|
|
14581974639,
|
|
14581976637,
|
|
14581979946,
|
|
14581989815,
|
|
14581987337,
|
|
14581987251,
|
|
14581981273,
|
|
14581996123,
|
|
14581984285,
|
|
14581994544,
|
|
14581996576,
|
|
14582006319,
|
|
14582000952,
|
|
14582000668,
|
|
14581993998,
|
|
14581996999,
|
|
14582016736,
|
|
14582053303,
|
|
14594027838,
|
|
14594055255,
|
|
14594104816,
|
|
14594233747,
|
|
14594245738,
|
|
14594249079,
|
|
14594296303,
|
|
14594987858,
|
|
14596828148,
|
|
14600091528,
|
|
14600094614,
|
|
14600087648,
|
|
14566414324}
|
|
for _, v := range wareIDs {
|
|
result, _ := api.SearchSkuList(v)
|
|
for _, vv := range result {
|
|
api.DeleteSku(vv.SkuID)
|
|
}
|
|
}
|
|
// result, err := api.SearchSkuList(14518857091)
|
|
// if err != nil {
|
|
// t.Fatal(err)
|
|
// }
|
|
// t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestAAAAAA(t *testing.T) {
|
|
result, err := api.SearchSkuList(14518860227)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|