488 lines
13 KiB
Go
488 lines
13 KiB
Go
package tao_vegetable
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
request1475 "git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability1475/request"
|
|
domain585 "git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability585/domain"
|
|
request585 "git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability585/request"
|
|
domain589 "git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability589/domain"
|
|
request589 "git.rosy.net.cn/baseapi/platformapi/tao_vegetable/sdk/ability589/request"
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"git.rosy.net.cn/jx-callback/globals"
|
|
"image/jpeg"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// 上传图片
|
|
func TestUploadImg(t *testing.T) {
|
|
uploadImg(apiTao, []string{"http://img20.360buyimg.com/vc/jfs/t2473/147/1629369634/4242813/e73adcd0/566a65f3N8aa04ec1.jpg"})
|
|
//uploadImg(apiTao, []string{"http://image.jxc4.com/image/2c28b6e2a1de59adba0f117b1519b5f7.png"})
|
|
}
|
|
|
|
func TestAddStoreSku(t *testing.T) {
|
|
param1 := &request585.AlibabaWdkSkuAddRequest{}
|
|
param := make([]domain585.AlibabaWdkSkuAddSkuDo, 0, 0)
|
|
sku1 := domain585.AlibabaWdkSkuAddSkuDo{
|
|
Barcodes: utils.String2Pointer("19930827"),
|
|
BrandName: utils.String2Pointer("京西菜场"),
|
|
//CategoryCode: utils.String2Pointer("222201"),
|
|
OuCode: utils.String2Pointer("JX668594"),
|
|
InventoryUnit: utils.String2Pointer("份"),
|
|
//MainPicUrls: utils.String2Pointer("https://img.alicdn.com/imgextra/i1/2680068332/O1CN01nXtVt92BQ6ryMXDpS_!!2680068332.png"), // 多图逗号
|
|
//DetailPicUrls: utils.String2Pointer("https://img.alicdn.com/imgextra/i1/2680068332/O1CN01nXtVt92BQ6ryMXDpS_!!2680068332.png"), // 多图逗号
|
|
ProducerPlace: utils.String2Pointer("中国"),
|
|
//ShelfLife: utils.Int64ToPointer(7),
|
|
SkuCode: utils.String2Pointer("19930827"),
|
|
SkuName: utils.String2Pointer("西兰花 500g/份"),
|
|
//SkuType: utils.Int64ToPointer(13),
|
|
StorageType: utils.Int64ToPointer(242),
|
|
SuggestedPrice: utils.String2Pointer("9"),
|
|
Weight: utils.String2Pointer("500"),
|
|
WeightFlag: utils.Int64ToPointer(0),
|
|
ShortTitle: utils.String2Pointer("美味西兰花"),
|
|
TxtDesc: utils.String2Pointer("美味西兰花"),
|
|
NetContent: utils.String2Pointer("500"),
|
|
SaleUnit: utils.String2Pointer("份"),
|
|
LifeStatus: utils.String2Pointer("A"),
|
|
SaleSpec: utils.String2Pointer("1*1份"),
|
|
AvgWeight: utils.String2Pointer("1"), // 每个虾饺重量
|
|
PreMinusWeight: utils.String2Pointer("1"), // 每个购买单位重量,预扣重量
|
|
StepQuantity: utils.Int64ToPointer(1), // 每次购买至少增加一个购买单位
|
|
PurchaseQuantity: utils.Int64ToPointer(1), // 起购单位
|
|
SubTitle: utils.String2Pointer("同城包邮"),
|
|
SubTitle1: utils.String2Pointer("一小时速达"),
|
|
OnlineSaleFlag: utils.Int64ToPointer(1), // 门店控制是否可见
|
|
DeliveryUnit: utils.String2Pointer("份"),
|
|
DeliverySpec: utils.String2Pointer("1"),
|
|
MemberPrice: utils.String2Pointer("9"),
|
|
Storage: utils.String2Pointer("冷藏"),
|
|
PickFloatRate: utils.String2Pointer("0"), // ? 0
|
|
ForbidReceiveDays: utils.Int64ToPointer(0), // ? 7
|
|
ForbidSalesDays: utils.Int64ToPointer(0), // ? 0
|
|
OverloadRate: utils.String2Pointer("0"), // ? 0
|
|
WarnDays: utils.Int64ToPointer(0), // ? 0
|
|
FixedFlag: utils.Int64ToPointer(0), // ? 0
|
|
PurchaseSpec: utils.String2Pointer("1"), // ? 1
|
|
PurchaseUnit: utils.String2Pointer("份"), // ? 同上
|
|
LabelStyleType: utils.String2Pointer("无价签"), // 库存单位
|
|
RichText: utils.String2Pointer("优先使用这个(txt_desc)"),
|
|
//BackCatCode: , // 优先使用BackCatCode HmCategoryCode靠后
|
|
//HmCategoryCode: ,
|
|
SkuPrice: utils.String2Pointer("9"), // 优先使用skuPrice 靠后SalePrice
|
|
Period: utils.Int64ToPointer(7), // 优先使用period 靠后shelf_life
|
|
ItemTypeNew: utils.Int64ToPointer(1), // 优先使用 靠后 sku_type
|
|
MerchantCatCode: utils.String2Pointer("222201"), // 优先使用 靠后 category_code
|
|
SkuPicUrls: utils.String2Pointer("https://image.jxc4.com/image/af9501e559555d062f2bba830adcd04a.jpg,https://image.jxc4.com/image/26d4f62c006180050df1237b92a007de.jpg"), // 第一张主图,后面是详情 优先使用本字段 靠后 同字段main_pic_urls和detail_pic_urls
|
|
FragileFlag: utils.Int64ToPointer(1),
|
|
DeliveryStorage: utils.String2Pointer("常温"),
|
|
TemporaryFlag: utils.Int64ToPointer(0),
|
|
IsOnline: utils.Int64ToPointer(1),
|
|
}
|
|
sku1.SkuSuppliers = &[]domain585.AlibabaWdkSkuAddSkuSupplierDo{
|
|
domain585.AlibabaWdkSkuAddSkuSupplierDo{
|
|
ReturnFlag: utils.Int64ToPointer(0),
|
|
Minimum: utils.String2Pointer("1"),
|
|
PurchasePrice: utils.String2Pointer(""),
|
|
SupplierNo: nil,
|
|
SupplierName: nil,
|
|
MainFlag: nil,
|
|
},
|
|
}
|
|
sku1.ChannelProps = &[]domain585.AlibabaWdkSkuAddChannelProp{
|
|
domain585.AlibabaWdkSkuAddChannelProp{
|
|
ChannelType: utils.String2Pointer("txd"),
|
|
Props: &[]domain585.AlibabaWdkSkuAddPropField{
|
|
domain585.AlibabaWdkSkuAddPropField{
|
|
Value: utils.String2Pointer("1"),
|
|
Key: utils.String2Pointer("ONE_HOUR_STATUS"),
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
param = append(param, sku1)
|
|
param1.ParamList = ¶m
|
|
result, err := apiTao.AddStoreSku(param1)
|
|
globals.SugarLogger.Debugf("result = %s", utils.Format4Output(result, false))
|
|
globals.SugarLogger.Debugf("err = %s", utils.Format4Output(err, false))
|
|
}
|
|
|
|
var skucodeMap = []string{
|
|
"JX100829:25278",
|
|
}
|
|
|
|
func TestUpdateSku(t *testing.T) {
|
|
data2 := make([]string, 0, 0)
|
|
for _, v := range skucodeMap {
|
|
storeCodeAndSkuCode := strings.Split(v, ":")
|
|
skuCode := []string{storeCodeAndSkuCode[1]}
|
|
storeCode1 := utils.String2Pointer(storeCodeAndSkuCode[0])
|
|
result, err := apiTao.QueryStoreSKu(&request585.AlibabaWdkSkuQueryRequest{Param: &domain585.AlibabaWdkSkuQuerySkuQueryDo{
|
|
OuCode: storeCode1,
|
|
SkuCodes: &skuCode,
|
|
}})
|
|
if err != nil {
|
|
data2 = append(data2, v)
|
|
continue
|
|
}
|
|
|
|
storeCode := *result
|
|
if len(storeCode) > 0 && utils.Str2Float64WithDefault(*storeCode[0].Model.SalePrice, 0) < 5 {
|
|
param := &request585.AlibabaWdkSkuUpdateRequest{}
|
|
updateSkuList := make([]domain585.AlibabaWdkSkuUpdateSkuDo, 0, 0)
|
|
updateSku := domain585.AlibabaWdkSkuUpdateSkuDo{
|
|
OuCode: storeCode1,
|
|
SkuCode: utils.String2Pointer(skuCode[0]),
|
|
SkuPrice: utils.String2Pointer(utils.Float64ToStr(utils.Str2Float64WithDefault(*storeCode[0].Model.SalePrice, 0) + 2)), // 优先使用skuPrice 靠后SalePrice
|
|
}
|
|
updateSkuList = append(updateSkuList, updateSku)
|
|
param.ParamList = &updateSkuList
|
|
_, err := apiTao.UpdateStoreSku(param)
|
|
if err != nil {
|
|
data2 = append(data2, v)
|
|
continue
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
globals.SugarLogger.Debugf("data2 :============ %s", utils.Format4Output(data2, false))
|
|
|
|
}
|
|
|
|
// 商品上下架
|
|
func TestStoreSkuUpdateOffShelf(t *testing.T) {
|
|
for _, storeID := range storeList {
|
|
globals.SugarLogger.Debugf("store %d", storeID)
|
|
err := apiTao.StoreSkuUpdateOffShelfList(storeID, skuList)
|
|
if err != nil {
|
|
globals.SugarLogger.Debugf("err := %s", utils.Format4Output(err, false))
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
var storeList = []int64{100930, 100871}
|
|
|
|
var skuList = []int64{
|
|
26125,
|
|
22596,
|
|
25103,
|
|
25104,
|
|
25105,
|
|
24656,
|
|
30670,
|
|
23422,
|
|
24097,
|
|
30669,
|
|
23424,
|
|
25535,
|
|
23620,
|
|
23621,
|
|
23622,
|
|
31308,
|
|
25022,
|
|
25717,
|
|
25023,
|
|
25718,
|
|
25685,
|
|
27264,
|
|
27265,
|
|
30396,
|
|
24300,
|
|
23001,
|
|
26049,
|
|
23002,
|
|
26050,
|
|
23417,
|
|
26287,
|
|
23419,
|
|
26289,
|
|
30625,
|
|
30691,
|
|
30611,
|
|
23291,
|
|
30686,
|
|
23294,
|
|
31254,
|
|
30672,
|
|
30671,
|
|
30702,
|
|
35420,
|
|
30687,
|
|
30730,
|
|
30727,
|
|
31312,
|
|
31238,
|
|
24264,
|
|
31022,
|
|
24266,
|
|
31229,
|
|
30663,
|
|
23879,
|
|
30777,
|
|
30889,
|
|
30676,
|
|
30814,
|
|
30219,
|
|
30675,
|
|
30627,
|
|
25518,
|
|
31518,
|
|
25519,
|
|
35242,
|
|
26057,
|
|
26058,
|
|
26447,
|
|
26448,
|
|
30365,
|
|
30830,
|
|
25412,
|
|
30641,
|
|
30657,
|
|
30656,
|
|
23818,
|
|
31200,
|
|
6045175,
|
|
33638,
|
|
31682,
|
|
6045386,
|
|
24935,
|
|
35241,
|
|
30875,
|
|
26700,
|
|
30888,
|
|
26701,
|
|
31248,
|
|
6042133,
|
|
34897,
|
|
23907,
|
|
30559,
|
|
30363,
|
|
6045167,
|
|
6041753,
|
|
30700,
|
|
26842,
|
|
26843,
|
|
26040,
|
|
35504,
|
|
6041970,
|
|
26065,
|
|
6041969,
|
|
6045177,
|
|
6045185,
|
|
30094,
|
|
6045186,
|
|
26067,
|
|
6045232,
|
|
31299,
|
|
6045404,
|
|
30667,
|
|
30780,
|
|
30881,
|
|
30644,
|
|
6041954,
|
|
6041955,
|
|
30639,
|
|
30775,
|
|
34417,
|
|
30811,
|
|
6045326,
|
|
35487,
|
|
23408,
|
|
31020,
|
|
23409,
|
|
35486,
|
|
35490,
|
|
23411,
|
|
25947,
|
|
25949,
|
|
30522,
|
|
24120,
|
|
25014,
|
|
30890,
|
|
26864,
|
|
6040867,
|
|
6042128,
|
|
25665,
|
|
30649,
|
|
34959,
|
|
25668,
|
|
35503,
|
|
30768,
|
|
26059,
|
|
6045098,
|
|
31243,
|
|
23163,
|
|
33156,
|
|
6039630,
|
|
27056,
|
|
34826,
|
|
30635,
|
|
30876,
|
|
30619,
|
|
30645,
|
|
30904,
|
|
31240,
|
|
24226,
|
|
31524,
|
|
25936,
|
|
32914,
|
|
25735,
|
|
32913,
|
|
29645,
|
|
33391,
|
|
30184,
|
|
23841,
|
|
34354,
|
|
30320,
|
|
25736,
|
|
6045549,
|
|
24251,
|
|
6045550,
|
|
24253,
|
|
31423,
|
|
31291,
|
|
35152,
|
|
22840,
|
|
27006,
|
|
22842,
|
|
30900,
|
|
26641,
|
|
30616,
|
|
30743,
|
|
26642,
|
|
30807,
|
|
26493,
|
|
26643,
|
|
25059,
|
|
25158,
|
|
26494,
|
|
25061,
|
|
26495,
|
|
31275,
|
|
25062,
|
|
30704,
|
|
26936,
|
|
31815,
|
|
33075,
|
|
30779,
|
|
25335,
|
|
25336,
|
|
22993,
|
|
30352,
|
|
25417,
|
|
25696,
|
|
23402,
|
|
25418,
|
|
25419,
|
|
26908,
|
|
}
|
|
|
|
// 商品库存修改
|
|
func TestStoreSkuStock(t *testing.T) {
|
|
param := request589.AlibabaWdkStockPublishRequest{}
|
|
batchStockPublishDto := &domain589.AlibabaWdkStockPublishBatchStockPublishDto{
|
|
UpdateType: utils.Int64ToPointer(1),
|
|
BillNo: utils.String2Pointer(utils.Int64ToStr(time.Now().UnixNano())),
|
|
BillType: utils.Int64ToPointer(UpdateTypeStokeBillType),
|
|
PublishSource: utils.String2Pointer("JX668594"),
|
|
ShopCode: utils.String2Pointer("JX668594"),
|
|
Operator: utils.String2Pointer("liulei"),
|
|
StockPublishDtos: nil,
|
|
}
|
|
stockPublishDtos := make([]domain589.AlibabaWdkStockPublishStockPublishDto, 0, 0)
|
|
stockPublishDtos = append(stockPublishDtos, domain589.AlibabaWdkStockPublishStockPublishDto{
|
|
SkuCode: utils.String2Pointer("22640"),
|
|
Quantity: utils.String2Pointer("99"),
|
|
OrderNo: utils.String2Pointer(fmt.Sprintf("%s_%d_%d", "JX668594", time.Now().UnixNano(), 84671)),
|
|
OrderType: utils.String2Pointer("10006800"),
|
|
})
|
|
batchStockPublishDto.StockPublishDtos = &stockPublishDtos
|
|
param.BatchStockPublishDto = batchStockPublishDto
|
|
|
|
if err := apiTao.StoreSkuStock(¶m); err != nil {
|
|
globals.SugarLogger.Debugf("err := %s", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestGetSkuDetaul(t *testing.T) {
|
|
result, err := apiTao.QueryStoreSKu(&request585.AlibabaWdkSkuQueryRequest{Param: &domain585.AlibabaWdkSkuQuerySkuQueryDo{
|
|
OuCode: utils.String2Pointer("JX666678"),
|
|
}})
|
|
globals.SugarLogger.Debugf("err := %s ", utils.Format4Output(err, false))
|
|
globals.SugarLogger.Debugf("result := %s ", utils.Format4Output(result, false))
|
|
}
|
|
func uploadImg(api *API, imgs []string) *string {
|
|
result := make([]string, 0, 0)
|
|
for _, v := range imgs {
|
|
if v == "" {
|
|
continue
|
|
}
|
|
|
|
inputTitle := strings.LastIndex(v, "/")
|
|
title := strings.LastIndex(v, ".")
|
|
resp, err := http.Get(v)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
body, _ := ioutil.ReadAll(resp.Body)
|
|
if strings.Contains(string(body), "Document not found") {
|
|
continue
|
|
}
|
|
if float64(len(body))/float64(1024)/float64(1024) > float64(3) {
|
|
jpgimg, err := jpeg.Decode(strings.NewReader(string(body))) // 文件解码成图像对象
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
var buf bytes.Buffer
|
|
err = jpeg.Encode(&buf, jpgimg, &jpeg.Options{Quality: 30})
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
body = buf.Bytes()
|
|
}
|
|
|
|
if newImg, _ := api.UploadImg(&request1475.AlibabaWdkPictureUploadRequest{
|
|
PictureCategoryId: utils.Int64ToPointer(0),
|
|
Img: &body,
|
|
ImgInputTitle: utils.String2Pointer(v[inputTitle+1:]),
|
|
Title: utils.String2Pointer(v[inputTitle+1 : title]),
|
|
}); newImg != "" {
|
|
result = append(result, newImg)
|
|
}
|
|
}
|
|
|
|
return utils.String2Pointer(strings.Join(result, ","))
|
|
}
|
|
|
|
func TestUpLoadImg(t *testing.T) {
|
|
v := `http://image.jxc4.com/9e8e8471ba959d10166d0cf4f08ccb2d.jpg`
|
|
inputTitle := strings.LastIndex(v, "/")
|
|
title := strings.LastIndex(v, ".")
|
|
resp, err := http.Get(v)
|
|
globals.SugarLogger.Debugf("err := get err := %s", utils.Format4Output(err, false))
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
globals.SugarLogger.Debugf("err :=2 get err := %s", utils.Format4Output(err, false))
|
|
|
|
dataa, err3 := apiTao.UploadImg(&request1475.AlibabaWdkPictureUploadRequest{
|
|
PictureCategoryId: utils.Int64ToPointer(0),
|
|
Img: &body,
|
|
ImgInputTitle: utils.String2Pointer(v[inputTitle:]),
|
|
Title: utils.String2Pointer(v[inputTitle:title]),
|
|
})
|
|
globals.SugarLogger.Debugf("errr3 := %s", utils.Format4Output(err3, false))
|
|
globals.SugarLogger.Debugf("data2 := %s", utils.Format4Output(dataa, false))
|
|
}
|
|
|
|
// 上传文件到七牛云
|
|
func TestQiNiuYn(t *testing.T) {
|
|
|
|
}
|