diff --git a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs index f89f73d6..ff9835ae 100644 --- a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs +++ b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs @@ -872,7 +872,8 @@ namespace BBWY.Server.Business AppSecret = request.AppSecret, AppToken = request.AppToken, Platform = Enums.Platform.京东, - IsCheckSkuCount = true + IsCheckSkuCount = true, + IsContainSource = true }; IList motherTemplateSkuList = null; @@ -989,15 +990,35 @@ namespace BBWY.Server.Business #region 组装上架/改名/设置细节图参数 stepText = "组装上架/改名/设置细节图参数"; - var takeColorIndex = colorSaleAttrs.Count() - 1; + var indexCount = colorSaleAttrs.Count() - 1; + var noUsedIndexList = new List(); + try + { + var usedIndexList = new List(); + usedIndexList.AddRange(mainProductSkuList.Select(ps => Convert.ToInt32(ps.Source["saleAttrs"][0]["attrValuesSeqNo"][0].ToString()))); + for (var i = 0; i <= indexCount; i++) + { + if (usedIndexList.Contains(i)) + continue; + noUsedIndexList.Add(i); + } + } + catch (Exception ex) + { + for (var i = 0; i <= indexCount; i++) + { + noUsedIndexList.Add(i); + } + } + var skusParamList = new List(); var updateSkuTitleParamList = new List(); var imageWriteUpdateRequestList = new List(); - + var skuIndex = noUsedIndexList.Count() - 1; for (var i = 0; i < request.GiftTemplateSkuList.Count(); i++) { var giftSku = request.GiftTemplateSkuList[i]; - var colorPropertyValue = colorSaleAttrs[takeColorIndex]; + //var colorPropertyValue = colorSaleAttrs[takeColorIndex]; var p = new SkuWriteUpdateSkusItem() { @@ -1009,14 +1030,13 @@ namespace BBWY.Server.Business outerId = $"{request.OuterId}{(i + 1).ToString().PadLeft(3, '0')}", saleAttrs = new List() { - - new SkuWriteUpdateSkusItemSaleAttrs() + new SkuWriteUpdateSkusItemSaleAttrs() { type = "com.jd.pop.ware.ic.api.domain.Prop", - attrId = colorPropertyValue.Value("attId"), + attrId = colorSaleAttrs[0].Value("attId"), attrValueAlias = new List(){ giftSku.Title }, - index = takeColorIndex, - attrValuesSeqNo = new List(){ takeColorIndex } + index = noUsedIndexList[skuIndex], + attrValuesSeqNo = new List(){ noUsedIndexList[skuIndex] } } }, saleAttrTemplateId = "POP_MODEL" @@ -1034,8 +1054,8 @@ namespace BBWY.Server.Business p.multiCateProps.Add(m); } } - - takeColorIndex--; + skuIndex--; + //takeColorIndex--; skusParamList.Add(p); } #endregion @@ -1105,48 +1125,45 @@ namespace BBWY.Server.Business } } - //记录上架返回值 - nLogManager.Default().Info($"任务Id {request.Id} 店铺Id {request.ShopId} 上架赠品返回值 {res.Body}"); + Thread.Sleep(30 * 1000); + stepText = "查询上架的赠品"; + giftSkuList = new List(); + var newMainProductSkuList = GetProductSkuList(new SearchProductSkuRequest() + { + AppKey = request.AppKey, + AppSecret = request.AppSecret, + AppToken = request.AppToken, + Platform = Enums.Platform.京东, + Spu = request.MainProductSpu, + IsContainSource = true + }); - stepText = "获取上架skuId"; - var newSkuIdList = res.Json["jingdong_sku_write_updateSkus_responce"]["skuList"].ToList().Select(x => x.Value("skuId")).ToList(); + //记录上架返回值 + nLogManager.Default().Info($"查询上架的赠品,任务Id {request.Id} 店铺Id {request.ShopId}, {JsonConvert.SerializeObject(newMainProductSkuList)}"); - #region 处理上架之后没有skuId的情况 - if (newSkuIdList.Any(s => string.IsNullOrEmpty(s))) + foreach (var ps in newMainProductSkuList) { - newSkuIdList.Clear(); - Thread.Sleep(30 * 1000); - var _mainProductSkuList = GetProductSkuList(new SearchProductSkuRequest() + if (request.GiftTemplateSkuList.Any(x => x.Title == ps.Title)) { - AppKey = request.AppKey, - AppSecret = request.AppSecret, - AppToken = request.AppToken, - Platform = Enums.Platform.京东, - Spu = request.MainProductSpu - }); - foreach (var ps in _mainProductSkuList) - { - if (request.GiftTemplateSkuList.Any(x => x.Title == ps.Title)) - { - //此sku是赠品sku - newSkuIdList.Add(ps.Id); - } + //此sku是赠品sku + //newSkuIdList.Add(ps.Id); + giftSkuList.Add(ps); } - if (newSkuIdList.Count() == 0) - throw new BusinessException("未能从sku列表接口正常获取新上架sku"); } - #endregion + if (giftSkuList.Count() == 0) + throw new BusinessException("未能从sku列表接口正常获取新上架sku"); - giftSkuIdList.AddRange(newSkuIdList); + giftSkuIdList.AddRange(giftSkuList.Select(gs => gs.Id)); - stepText = "获取上架sku"; - var newSkuList = res.Json["jingdong_sku_write_updateSkus_responce"]["skuList"].ToList(); + stepText = "设置赠品图片"; + //var newSkuList = res.Json["jingdong_sku_write_updateSkus_responce"]["skuList"].ToList(); var imgIndex = 1; StringBuilder colorBuilder = new StringBuilder(); StringBuilder imgUrlBuilder = new StringBuilder(); StringBuilder imgIndexBuilder = new StringBuilder(); - foreach (var skuJToken in newSkuList) + foreach (var giftsku in giftSkuList) { + var skuJToken = giftsku.Source; var skuTitle = skuJToken["saleAttrs"][0]["attrValueAlias"][0].ToString(); var colorId = "0000000000"; try @@ -1212,22 +1229,22 @@ namespace BBWY.Server.Business #endregion - #region 查询上架的赠品 - stepText = "查询上架的赠品SKU"; - Thread.Sleep(60 * 1000); - searchProductSkuRequest.Sku = string.Join(",", giftSkuIdList); - searchProductSkuRequest.CheckStep = "上架的赠品"; - try - { - giftSkuList = GetProductSkuList(searchProductSkuRequest); - } - catch - { - RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, haveGiftTemplateSku); - throw; - } - - #endregion + //#region 查询上架的赠品 + //stepText = "查询上架的赠品SKU"; + //Thread.Sleep(60 * 1000); + //searchProductSkuRequest.Sku = string.Join(",", giftSkuIdList); + //searchProductSkuRequest.CheckStep = "上架的赠品"; + //try + //{ + // giftSkuList = GetProductSkuList(searchProductSkuRequest); + //} + //catch + //{ + // RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, haveGiftTemplateSku); + // throw; + //} + + //#endregion } #region 创建活动