diff --git a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs index b90597eb..6f88a915 100644 --- a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs +++ b/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(); + IList 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("skuId"), - ProductId = s.Value("wareId"), - Price = s.Value("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("logo")}", - State = s.Value("status"), - CreateTime = s.Value("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("skuId"), + ProductId = s.Value("wareId"), + Price = s.Value("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("logo")}", + State = s.Value("status"), + CreateTime = s.Value("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 GetSimpleProductSkuList(SearchProductSkuRequest searchProductSkuRequest) @@ -662,6 +686,38 @@ namespace BBWY.Server.Business } } + /// + /// 添加JD促销活动sku + /// + /// + /// + /// + /// + /// + /// + private void AddJDPromotionSku(IJdClient jdClient, string token, long promotionId, IList 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(); - 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(); - 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 diff --git a/BBWY.Server.Business/Vender/VenderBusiness.cs b/BBWY.Server.Business/Vender/VenderBusiness.cs index 937daf04..b71eec6c 100644 --- a/BBWY.Server.Business/Vender/VenderBusiness.cs +++ b/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";