步步为盈
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

252 lines
10 KiB

3 years ago
using BBWY.Server.Model.Dto;
using Jd.Api;
3 years ago
using Jd.Api.Request;
using Newtonsoft.Json;
3 years ago
using Newtonsoft.Json.Linq;
3 years ago
using System;
using System.Collections.Generic;
3 years ago
using System.Linq;
3 years ago
namespace BBWY.Test
{
3 years ago
public class JDProductAPITest
3 years ago
{
public void GetSkus(IJdClient client, string token, string spu)
{
var req_skuList = new SkuReadSearchSkuListRequest()
{
pageSize = 50,//50
field = "logo,saleAttrs,status,created,barCode,categoryId,multiCateProps"
};
req_skuList.wareId = spu;
var response = client.Execute(req_skuList, token, DateTime.Now.ToLocalTime());
Console.WriteLine(JsonConvert.SerializeObject(response));
}
3 years ago
public void QueryTouTu(IJdClient client, string token, string spu)
{
var req = new TransparentImageReadFindByWareIdAndColorIdRequest();
req.wareId = long.Parse(spu);
req.colorId = "0000000000";
var response = client.Execute(req, token, DateTime.Now.ToLocalTime());
Console.WriteLine(JsonConvert.SerializeObject(response));
}
/// <summary>
/// 查询SKU细节图
/// </summary>
public void FindImageByColor(IJdClient client, string token, string spu)
{
var req = new ImageReadFindImagesByColorRequest();
req.wareId = long.Parse(spu);
req.colorId = "0000000000";
var response = client.Execute(req, token, DateTime.Now.ToLocalTime());
Console.WriteLine(JsonConvert.SerializeObject(response));
}
public void ShangJiaTest(IJdClient client, string token)
{
3 years ago
var mainSpu = "10022905456671";
3 years ago
var giftSpu = "10023500913672";
var barCode = "";
var categoryId = "";
3 years ago
3 years ago
IList<JToken> multiCateProps = null;
var selectGiftSkuList = new List<ProductSkuResponse>();
#region 取主商品信息
{
var req = new SkuReadSearchSkuListRequest()
{
pageSize = 50,//50
field = "logo,saleAttrs,status,created,barCode,categoryId,multiCateProps"
};
req.wareId = mainSpu;
var res = client.Execute(req, token, DateTime.Now.ToLocalTime());
var skuList = ((JArray)res.Json["jingdong_sku_read_searchSkuList_responce"]["page"]["data"]).Select(s => new ProductSkuResponse()
{
Id = s.Value<string>("skuId"),
ProductId = s.Value<string>("wareId"),
Price = s.Value<decimal>("jdPrice"),
Title = s["saleAttrs"] != null ? string.Join("-", s["saleAttrs"].Select(a => a["attrValueAlias"][0].ToString())) : string.Empty,
Logo = $"https://img13.360buyimg.com/n9/s80x80_{s.Value<string>("logo")}",
State = s.Value<int>("status"),
//CreateTime = s.Value<long>("created").StampToDateTime(),
Source = s
}).ToList();
barCode = skuList[0].Source.Value<string>("barCode");
categoryId = skuList[0].Source.Value<string>("categoryId");
3 years ago
3 years ago
multiCateProps = skuList[0].Source["multiCateProps"] != null ? skuList[0].Source["multiCateProps"].ToList() : null;
}
#endregion
#region 取赠品信息
{
var giftTitleList = new List<string>() { "粉丝价", "放心购", "闪电退款", "免费", "价格保护", "极速审核", "质量保护", "运费险" };
var req = new SkuReadSearchSkuListRequest()
{
pageSize = 50,//50
field = "logo,saleAttrs,status,created,barCode,categoryId,multiCateProps"
};
req.wareId = giftSpu;
var res = client.Execute(req, token, DateTime.Now.ToLocalTime());
var skuList = ((JArray)res.Json["jingdong_sku_read_searchSkuList_responce"]["page"]["data"]).Select(s => new ProductSkuResponse()
{
Id = s.Value<string>("skuId"),
ProductId = s.Value<string>("wareId"),
Price = s.Value<decimal>("jdPrice"),
Title = s["saleAttrs"] != null ? string.Join("-", s["saleAttrs"].Select(a => a["attrValueAlias"][0].ToString())) : string.Empty,
Logo = $"https://img13.360buyimg.com/n9/s80x80_{s.Value<string>("logo")}",
State = s.Value<int>("status"),
//CreateTime = s.Value<long>("created").StampToDateTime(),
Source = s
}).ToList();
foreach (var sku in skuList)
{
if (!giftTitleList.Contains(sku.Title))
continue;
selectGiftSkuList.Add(sku);
}
}
#endregion
3 years ago
#region 获取销售属性
IList<JToken> colorSaleAttrs = null;
{
var req = new CategoryReadFindAttrsByCategoryIdUnlimitCateRequest();
req.cid = long.Parse(categoryId);
req.attributeType = 4;
req.field = "attrValueList,attrGroup";
var response = client.Execute(req, token, DateTime.Now.ToLocalTime());
Console.WriteLine("销售属性");
if (response.Json == null)
response.Json = JObject.Parse(response.Body);
3 years ago
var colorProperty = response.Json["jingdong_category_read_findAttrsByCategoryIdUnlimitCate_responce"]["findattrsbycategoryidunlimitcate_result"].FirstOrDefault(j => j.Value<string>("name") == "颜色");
3 years ago
if (colorProperty == null)
throw new Exception("缺少颜色属性");
colorSaleAttrs = colorProperty["attrValueList"].ToList();
}
#endregion
#region 增量保存sku
3 years ago
{
var skusParamList = new List<SkuWriteUpdateSkusItem>();
3 years ago
var takeColorIndex = colorSaleAttrs.Count() - 10;
for (var i = 0; i < 3; i++)
3 years ago
{
3 years ago
var giftSku = selectGiftSkuList[i];
3 years ago
var p = new SkuWriteUpdateSkusItem()
{
wareId = long.Parse(mainSpu),
3 years ago
//skuId = long.Parse(sku.Id),
jdPrice = giftSku.Price,
stockNum = 500,
3 years ago
barCode = barCode,
};
3 years ago
var colorProperty = colorSaleAttrs[takeColorIndex];
3 years ago
p.saleAttrs = new List<SkuWriteUpdateSkusItemSaleAttrs>();
3 years ago
var m = new SkuWriteUpdateSkusItemSaleAttrs();
3 years ago
m.type = "com.jd.pop.ware.ic.api.domain.Prop";
3 years ago
m.attrId = colorProperty.Value<string>("attId");
m.attrValues = new List<string>() { colorProperty.Value<string>("id") };
3 years ago
m.attrValueAlias = new List<string>() {
giftSku.Title
//colorProperty.Value<string>("name")
};
3 years ago
m.index = takeColorIndex;
p.saleAttrs.Add(m);
takeColorIndex--;
//foreach (var saleAttr in colorSaleAttrs)
//{
// var m = new SkuWriteUpdateSkusItemSaleAttrs();
// m.attrId = saleAttr.Value<string>("attrId");
// m.attrValues = saleAttr.Value<JArray>("attrValues").Select(x => x.ToString()).ToList();
// p.saleAttrs.Add(m);
//}
//p.multiCateProps = new List<SkuWriteUpdateSkusItemSaleAttrs>();
//if (multiCateProps != null && multiCateProps.Count() > 0)
//{
// foreach (var multiCateProp in multiCateProps)
// {
// var m = new SkuWriteUpdateSkusItemSaleAttrs();
// m.attrId = multiCateProp.Value<string>("attrId");
// m.attrValues = multiCateProp.Value<JArray>("attrValues").Select(x => x.ToString()).ToList();
// p.multiCateProps.Add(m);
// }
//}
3 years ago
skusParamList.Add(p);
}
var req = new SkuWriteUpdateSkusRequest();
req.wareId = long.Parse(mainSpu);
req.skus = skusParamList;
Console.WriteLine("请求参数");
Console.WriteLine(JsonConvert.SerializeObject(req));
var res = client.Execute(req, token, DateTime.Now.ToLocalTime());
Console.WriteLine();
Console.WriteLine("返回内容");
Console.WriteLine(JsonConvert.SerializeObject(res));
}
#endregion
}
3 years ago
public void (IJdClient client, string token)
{
var mainSpu = "10022905456671";
var request = new WareWriteUpdateWareSaleAttrvalueAliasRequest();
request.wareId = long.Parse(mainSpu);
request.props = new List<WareWriteUpdateWareSaleAttrvalueAliasRequestItem>();
request.props.Add(new WareWriteUpdateWareSaleAttrvalueAliasRequestItem()
{
attrId = "1001050679",
attrValues = new List<string>() { "2912651180" },
attrValueAlias = new List<string>() { "粉丝价" }
});
request.props.Add(new WareWriteUpdateWareSaleAttrvalueAliasRequestItem()
{
attrId = "1001050679",
attrValues = new List<string>() { "2912655473" },
attrValueAlias = new List<string>() { "放心购" }
});
request.props.Add(new WareWriteUpdateWareSaleAttrvalueAliasRequestItem()
{
attrId = "1001050679",
attrValues = new List<string>() { "2912660446" },
attrValueAlias = new List<string>() { "闪电退款" }
});
Console.WriteLine("请求参数");
Console.WriteLine(JsonConvert.SerializeObject(request));
var res = client.Execute(request, token, DateTime.Now.ToLocalTime());
Console.WriteLine();
Console.WriteLine("返回内容");
Console.WriteLine(JsonConvert.SerializeObject(res));
}
3 years ago
}
}