Browse Source

sku列表接口支持自动分批获取

赠品/主商品/奶妈模板sku/自定义奶妈sku 分别添加活动sku
检查奶妈sku是否在其他正在进行的促销活动中
qianyi
shanji 2 years ago
parent
commit
d486df8a83
  1. 186
      BBWY.Server.Business/PlatformSDK/JDBusiness.cs
  2. 2
      BBWY.Server.Business/Vender/VenderBusiness.cs

186
BBWY.Server.Business/PlatformSDK/JDBusiness.cs

@ -125,26 +125,50 @@ namespace BBWY.Server.Business
field = "logo,saleAttrs,status,created,barCode,categoryId,multiCateProps"
};
var skuList = new List<ProductSkuResponse>();
IList<string> skuIdList = null;
var pageIndex = 1;
var pageSize = 0;
if (!string.IsNullOrEmpty(searchProductSkuRequest.Spu))
req_skuList.wareId = searchProductSkuRequest.Spu;
pageSize = 1;
else if (!string.IsNullOrEmpty(searchProductSkuRequest.Sku))
req_skuList.skuId = searchProductSkuRequest.Sku;
var rep_skuList = jdClient.Execute(req_skuList, searchProductSkuRequest.AppToken, DateTime.Now.ToLocalTime());
if (rep_skuList.IsError)
throw new BusinessException(string.IsNullOrEmpty(rep_skuList.ErrorMsg) ? rep_skuList.ErrMsg : rep_skuList.ErrorMsg);
{
skuIdList = searchProductSkuRequest.Sku.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
pageSize = (skuIdList.Count() - 1) / 20 + 1;
}
return ((JArray)rep_skuList.Json["jingdong_sku_read_searchSkuList_responce"]["page"]["data"]).Select(s => new ProductSkuResponse()
while (true)
{
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 = searchProductSkuRequest.IsContainSource ? s : null
}).ToList();
if (!string.IsNullOrEmpty(searchProductSkuRequest.Spu))
req_skuList.wareId = searchProductSkuRequest.Spu;
else if (!string.IsNullOrEmpty(searchProductSkuRequest.Sku))
req_skuList.skuId = string.Join(",", skuIdList.Skip((pageIndex - 1) * pageSize).Take(pageSize));
var rep_skuList = jdClient.Execute(req_skuList, searchProductSkuRequest.AppToken, DateTime.Now.ToLocalTime());
if (rep_skuList.IsError)
throw new BusinessException(string.IsNullOrEmpty(rep_skuList.ErrorMsg) ? rep_skuList.ErrMsg : rep_skuList.ErrorMsg);
var currentList = ((JArray)rep_skuList.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 = searchProductSkuRequest.IsContainSource ? s : null
}).ToList();
if (currentList != null && currentList.Count() > 0)
skuList.AddRange(currentList);
if (pageIndex >= pageSize)
break;
pageIndex++;
}
return skuList;
}
public override IList<SimpleProductSkuResponse> GetSimpleProductSkuList(SearchProductSkuRequest searchProductSkuRequest)
@ -662,6 +686,38 @@ namespace BBWY.Server.Business
}
}
/// <summary>
/// 添加JD促销活动sku
/// </summary>
/// <param name="jdClient"></param>
/// <param name="token"></param>
/// <param name="promotionId"></param>
/// <param name="skuList"></param>
/// <param name="isGift"></param>
/// <exception cref="BusinessException"></exception>
private void AddJDPromotionSku(IJdClient jdClient, string token, long promotionId, IList<ProductSkuResponse> skuList, bool isGift)
{
var req = new SellerPromotionSkuAddRequest();
req.promoId = promotionId;
foreach (var sku in skuList)
{
req.skuIds = $"{req.skuIds}{sku.Id},";
req.jdPrices = $"{req.jdPrices}{sku.Price},";
req.bindType = $"{req.bindType}{(isGift ? 2 : 1)},";
req.num = $"{req.num}1,";
}
req.skuIds = req.skuIds.Substring(0, req.skuIds.Length - 1);
req.jdPrices = req.jdPrices.Substring(0, req.jdPrices.Length - 1);
req.bindType = req.bindType.Substring(0, req.bindType.Length - 1);
req.num = req.num.Substring(0, req.num.Length - 1);
var res = jdClient.Execute(req, token, DateTime.Now.ToLocalTime());
if (res.IsError)
throw new BusinessException($"添加活动sku失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
}
public override long StartJDPromotionTask(StartPromotionTaskRequest2 request)
{
var stepText = string.Empty;
@ -924,81 +980,57 @@ namespace BBWY.Server.Business
#region 添加活动sku
{
#region 查询奶妈和主商品sku
var mainSkuList = new List<ProductSkuResponse>();
if (!string.IsNullOrEmpty(request.MotherTemplateSku))
var searchProductSkuRequest = new SearchProductSkuRequest()
{
var skuList = GetProductSkuList(new SearchProductSkuRequest()
{
AppKey = request.AppKey,
AppSecret = request.AppSecret,
AppToken = request.AppToken,
Platform = Enums.Platform.,
Sku = request.MotherTemplateSku
});
mainSkuList.AddRange(skuList);
}
if (!string.IsNullOrEmpty(request.MainProductSku))
AppKey = request.AppKey,
AppSecret = request.AppSecret,
AppToken = request.AppToken,
Platform = Enums.Platform.,
};
#region 添加奶妈模板SKU
if (!string.IsNullOrEmpty(request.MotherTemplateSku))
{
var skuList = GetProductSkuList(new SearchProductSkuRequest()
{
AppKey = request.AppKey,
AppSecret = request.AppSecret,
AppToken = request.AppToken,
Platform = Enums.Platform.,
Sku = request.MainProductSku
});
mainSkuList.AddRange(skuList);
stepText = "查询奶妈模板SKU";
searchProductSkuRequest.Sku = request.MotherTemplateSku;
var skuList = GetProductSkuList(searchProductSkuRequest);
stepText = "添加奶妈模板SKU";
AddJDPromotionSku(jdClient, request.AppToken, promotionId, skuList, false);
}
#endregion
#region 查询赠品sku
var giftSkuList = new List<ProductSkuResponse>();
if (giftSkuIdList.Count() > 0)
#region 添加自定义奶妈SKU
if (!string.IsNullOrEmpty(request.CustomMotherSku))
{
var giftSkuIds = string.Join(",", giftSkuIdList);
var skuList = GetProductSkuList(new SearchProductSkuRequest()
{
AppKey = request.AppKey,
AppSecret = request.AppSecret,
AppToken = request.AppToken,
Platform = Enums.Platform.,
Sku = giftSkuIds
});
giftSkuList.AddRange(skuList);
stepText = "查询自定义奶妈SKU";
searchProductSkuRequest.Sku = request.CustomMotherSku;
var skuList = GetProductSkuList(searchProductSkuRequest);
stepText = "添加自定义奶妈SKU";
AddJDPromotionSku(jdClient, request.AppToken, promotionId, skuList, false);
}
#endregion
stepText = "添加活动sku";
var req = new SellerPromotionSkuAddRequest();
req.promoId = promotionId;
foreach (var sku in mainSkuList)
#region 添加主商品sku
if (!string.IsNullOrEmpty(request.MainProductSku))
{
req.skuIds = $"{req.skuIds}{sku.Id},";
req.jdPrices = $"{req.jdPrices}{sku.Price},";
req.bindType = $"{req.bindType}1,";
req.num = $"{req.num}1,";
stepText = "查询主商品SKU";
searchProductSkuRequest.Sku = request.MainProductSku;
var skuList = GetProductSkuList(searchProductSkuRequest);
stepText = "添加主商品SKU";
AddJDPromotionSku(jdClient, request.AppToken, promotionId, skuList, false);
}
#endregion
foreach (var sku in giftSkuList)
#region 添加赠品sku
if (giftSkuIdList.Count() > 0)
{
req.skuIds = $"{req.skuIds}{sku.Id},";
req.jdPrices = $"{req.jdPrices}{sku.Price},";
req.bindType = $"{req.bindType}2,";
req.num = $"{req.num}1,";
stepText = "查询赠品SKU";
searchProductSkuRequest.Sku = string.Join(",", giftSkuIdList);
var skuList = GetProductSkuList(searchProductSkuRequest);
stepText = "添加赠品SKU";
AddJDPromotionSku(jdClient, request.AppToken, promotionId, skuList, true);
}
req.skuIds = req.skuIds.Substring(0, req.skuIds.Length - 1);
req.jdPrices = req.jdPrices.Substring(0, req.jdPrices.Length - 1);
req.bindType = req.bindType.Substring(0, req.bindType.Length - 1);
req.num = req.num.Substring(0, req.num.Length - 1);
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
if (res.IsError)
throw new BusinessException($"添加活动sku失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
#endregion
}
#endregion

2
BBWY.Server.Business/Vender/VenderBusiness.cs

@ -63,7 +63,7 @@ namespace BBWY.Server.Business
appSecret = "8a42bc2301e8439b896e99f5475e0a9b";
appKeyType = Enums.AppKeyType.;
}
else if (jDShopToken.State == "merp_1058051655896924160")
else if (jDShopToken.State == "merp_1058051655896924160_2")
{
//商品Key
appKey = "E1AA9247D5583A6D87449CE6AB290185";

Loading…
Cancel
Save