diff --git a/BBWY.JDSDK/Request/SkuWriteUpdateSkusRequest.cs b/BBWY.JDSDK/Request/SkuWriteUpdateSkusRequest.cs index 10ff3bef..3b37b675 100644 --- a/BBWY.JDSDK/Request/SkuWriteUpdateSkusRequest.cs +++ b/BBWY.JDSDK/Request/SkuWriteUpdateSkusRequest.cs @@ -26,9 +26,11 @@ namespace Jd.Api.Request [JsonProperty("@type")] public string type { get; set; } = "com.jd.pop.ware.ic.api.domain.Sku"; - public Nullable wareId { get; set; } + public long? wareId { get; set; } + + public long? skuId { get; set; } - public Nullable skuId { get; set; } + public int? enable { get; set; } public List saleAttrs { get; set; } @@ -50,7 +52,7 @@ namespace Jd.Api.Request public class SkuWriteUpdateSkusItemSaleAttrs { [JsonProperty("@type")] - public string type { get; set; } + public string type { get; set; } = "com.jd.pop.ware.ic.api.domain.Prop"; public string attrId { get; set; } diff --git a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs index 1277a24e..1f500d51 100644 --- a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs +++ b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs @@ -155,7 +155,7 @@ namespace BBWY.Server.Business var req_skuList = new SkuReadSearchSkuListRequest() { pageSize = 50,//50 - field = "logo,saleAttrs,status,created,barCode,categoryId,multiCateProps" + field = "logo,saleAttrs,status,created,barCode,categoryId,multiCateProps,promiseId,saleAttrTemplateId,enable,stockNum" }; var skuList = new List(); @@ -834,6 +834,72 @@ namespace BBWY.Server.Business #endregion } + private void DisableGiftSkuAndRecoverFullTitle(string appKey, + string appSecret, + string appToken, + IList deleteSkuList, + string mainProductSpu, + string fullTitle, + string brandName, + bool haveGiftTemplateSku) + { + var jdClient = GetJdClient(appKey, appSecret); + var wareId = long.Parse(mainProductSpu); + if (haveGiftTemplateSku && deleteSkuList != null && deleteSkuList.Count() > 0 && !deleteSkuList.Any(s => string.IsNullOrEmpty(s))) + { + var disableSkuList = GetProductSkuList(new SearchProductSkuRequest() + { + AppKey = appKey, + AppSecret = appSecret, + AppToken = appToken, + Platform = Enums.Platform.京东, + Sku = string.Join(",", deleteSkuList), + IsContainSource = true, + CheckStep = "", + IsCheckSkuCount = false + }); + + var req = new SkuWriteUpdateSkusRequest(); + req.wareId = wareId; + req.skus = disableSkuList.Select(ps => + { + var p = JsonConvert.DeserializeObject(ps.Source.ToString()); + p.enable = 2; //禁用 + return p; + }).ToList(); + + var res = jdClient.Execute(req, appToken, DateTime.Now.ToLocalTime()); + + if (res.Json == null) + res.Json = JObject.Parse(res.Body); + + if (res.IsError) + { + var errorMsg = res.Body.Contains("en_desc") ? + res.Json["error_response"].Value("en_desc") : + (string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg); + + RollBackWhenStartPromotionError(appKey, appSecret, appToken, deleteSkuList, mainProductSpu, fullTitle, brandName, false); + throw new BusinessException($"禁用赠品sku失败-{errorMsg}"); + } + } + + #region 设置完整标题 + { + if (string.IsNullOrEmpty(brandName)) + return; + var req = new WareWriteUpdateWareTitleRequest() { wareId = wareId }; + if (!fullTitle.StartsWith(brandName)) + req.title = $"{brandName}{fullTitle}"; + else + req.title = fullTitle; + var response = jdClient.Execute(req, appToken, DateTime.Now.ToLocalTime()); + if (response.IsError) + throw new BusinessException($"设置完整标题出错-{(string.IsNullOrEmpty(response.ErrorMsg) ? response.ErrMsg : response.ErrorMsg)}"); + } + #endregion + } + /// /// 添加JD促销活动sku /// @@ -1046,13 +1112,14 @@ namespace BBWY.Server.Business { //非结构属性 var tempDataJarray = JArray.Parse(res.Json["jingdong_category_read_findSaleAttrTemplates_responce"]["categoryAttrTemplates"]["templateData"].ToString()); - var colorProperty = tempDataJarray.FirstOrDefault(j => j.Value("name") == "颜色"); - if (colorProperty == null) - colorProperty = tempDataJarray.FirstOrDefault(j => j["attrValueList"] != null && j["attrValueList"].Count() > 0); + var colorProperty = tempDataJarray.FirstOrDefault(j => (j.Value("name") == "颜色" || + j.Value("name") == "规格" || + j.Value("name") == "类别") && + j["attrValueList"].Children().Count() > 0); if (colorProperty == null) { RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, haveGiftTemplateSku); - throw new BusinessException("缺少销售属性"); + throw new BusinessException("缺少包含attrValueList的销售属性"); } var colorSaleAttrs = colorProperty["attrValueList"].ToList(); attrId = colorSaleAttrs[0].Value("attId"); @@ -1241,6 +1308,7 @@ namespace BBWY.Server.Business { type = "com.jd.pop.ware.ic.api.domain.Sku", wareId = wareId, + enable = 1, jdPrice = giftSku.Price ?? 0, stockNum = 9999, barCode = request.MainProductBarCode, @@ -1645,7 +1713,7 @@ namespace BBWY.Server.Business catch { } #endregion - RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, request.DeleteGiftSkuList, request.MainProductSpu, request.FullTitle, request.BrandName, true); + DisableGiftSkuAndRecoverFullTitle(request.AppKey, request.AppSecret, request.AppToken, request.DeleteGiftSkuList, request.MainProductSpu, request.FullTitle, request.BrandName, true); } public override void DeleteJDPromotionTask(DeleteJDPromotionTaskRequest request)