From d486df8a83d170141c8ee3efc3356ac7bdca9aaa Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Wed, 4 Jan 2023 02:53:42 +0800 Subject: [PATCH] =?UTF-8?q?sku=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=8A=A8=E5=88=86=E6=89=B9=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=20=E8=B5=A0=E5=93=81/=E4=B8=BB=E5=95=86=E5=93=81/?= =?UTF-8?q?=E5=A5=B6=E5=A6=88=E6=A8=A1=E6=9D=BFsku/=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=A5=B6=E5=A6=88sku=20=E5=88=86=E5=88=AB=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=B4=BB=E5=8A=A8sku=20=E6=A3=80=E6=9F=A5=E5=A5=B6?= =?UTF-8?q?=E5=A6=88sku=E6=98=AF=E5=90=A6=E5=9C=A8=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E6=AD=A3=E5=9C=A8=E8=BF=9B=E8=A1=8C=E7=9A=84=E4=BF=83=E9=94=80?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlatformSDK/JDBusiness.cs | 186 ++++++++++-------- BBWY.Server.Business/Vender/VenderBusiness.cs | 2 +- 2 files changed, 110 insertions(+), 78 deletions(-) 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";