|
|
@ -989,26 +989,85 @@ namespace BBWY.Server.Business |
|
|
|
|
|
|
|
#region 获取销售属性
|
|
|
|
stepText = "获取销售属性"; |
|
|
|
IList<JToken> colorSaleAttrs = null; |
|
|
|
var attrId = string.Empty; |
|
|
|
//IList<JToken> colorSaleAttrs = null;
|
|
|
|
//{
|
|
|
|
// var req = new CategoryReadFindAttrsByCategoryIdUnlimitCateRequest();
|
|
|
|
// req.cid = long.Parse(request.MainProductCategoryId);
|
|
|
|
// req.attributeType = 4;
|
|
|
|
// req.field = "attrValueList,attrGroup";
|
|
|
|
// var response = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
// if (response.Json == null)
|
|
|
|
// response.Json = JObject.Parse(response.Body);
|
|
|
|
// var colorProperty = response.Json["jingdong_category_read_findAttrsByCategoryIdUnlimitCate_responce"]["findattrsbycategoryidunlimitcate_result"].FirstOrDefault(j => j.Value<string>("name") == "颜色");
|
|
|
|
// if (colorProperty == null)
|
|
|
|
// {
|
|
|
|
// colorProperty = response.Json["jingdong_category_read_findAttrsByCategoryIdUnlimitCate_responce"]["findattrsbycategoryidunlimitcate_result"].FirstOrDefault(j => j["attrValueList"] != null && j["attrValueList"].Count() > 0);
|
|
|
|
// }
|
|
|
|
// if (colorProperty == null)
|
|
|
|
// {
|
|
|
|
// RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, haveGiftTemplateSku);
|
|
|
|
// throw new BusinessException("缺少销售属性");
|
|
|
|
// }
|
|
|
|
// colorSaleAttrs = colorProperty["attrValueList"].ToList();
|
|
|
|
//}
|
|
|
|
List<AttrValueAliasJson> strutsSaleAttrValueList = new List<AttrValueAliasJson>(); |
|
|
|
var isStruts = false; |
|
|
|
{ |
|
|
|
var req = new CategoryReadFindAttrsByCategoryIdUnlimitCateRequest(); |
|
|
|
req.cid = long.Parse(request.MainProductCategoryId); |
|
|
|
req.attributeType = 4; |
|
|
|
req.field = "attrValueList,attrGroup"; |
|
|
|
var response = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime()); |
|
|
|
if (response.Json == null) |
|
|
|
response.Json = JObject.Parse(response.Body); |
|
|
|
var colorProperty = response.Json["jingdong_category_read_findAttrsByCategoryIdUnlimitCate_responce"]["findattrsbycategoryidunlimitcate_result"].FirstOrDefault(j => j.Value<string>("name") == "颜色"); |
|
|
|
if (colorProperty == null) |
|
|
|
var req = new CategoryReadFindSaleAttrTemplatesRequest(); |
|
|
|
req.cid = int.Parse(request.MainProductCategoryId); |
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime()); |
|
|
|
if (res.IsError) |
|
|
|
{ |
|
|
|
colorProperty = response.Json["jingdong_category_read_findAttrsByCategoryIdUnlimitCate_responce"]["findattrsbycategoryidunlimitcate_result"].FirstOrDefault(j => j["attrValueList"] != null && j["attrValueList"].Count() > 0); |
|
|
|
var errorMsg = string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg; |
|
|
|
throw new BusinessException(errorMsg); |
|
|
|
} |
|
|
|
if (colorProperty == null) |
|
|
|
if (res.Json == null) |
|
|
|
res.Json = JObject.Parse(res.Body); |
|
|
|
|
|
|
|
if (res.Json["jingdong_category_read_findSaleAttrTemplates_responce"]["categoryAttrTemplates"]["templateType"].ToString() == "1") |
|
|
|
{ |
|
|
|
RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, haveGiftTemplateSku); |
|
|
|
throw new BusinessException("缺少销售属性"); |
|
|
|
//非结构属性
|
|
|
|
var tempDataJarray = JArray.Parse(res.Json["jingdong_category_read_findSaleAttrTemplates_responce"]["categoryAttrTemplates"]["templateData"].ToString()); |
|
|
|
var colorProperty = tempDataJarray.FirstOrDefault(j => j.Value<string>("name") == "颜色"); |
|
|
|
if (colorProperty == null) |
|
|
|
colorProperty = tempDataJarray.FirstOrDefault(j => j["attrValueList"] != null && j["attrValueList"].Count() > 0); |
|
|
|
if (colorProperty == null) |
|
|
|
{ |
|
|
|
RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, haveGiftTemplateSku); |
|
|
|
throw new BusinessException("缺少销售属性"); |
|
|
|
} |
|
|
|
var colorSaleAttrs = colorProperty["attrValueList"].ToList(); |
|
|
|
attrId = colorSaleAttrs[0].Value<string>("attId"); |
|
|
|
} |
|
|
|
else if (res.Json["jingdong_category_read_findSaleAttrTemplates_responce"]["categoryAttrTemplates"]["templateType"].ToString() == "2") |
|
|
|
{ |
|
|
|
isStruts = true; |
|
|
|
var tempDataJarray = JArray.Parse(res.Json["jingdong_category_read_findSaleAttrTemplates_responce"]["categoryAttrTemplates"]["templateData"].ToString()); |
|
|
|
var tempDataJToken = tempDataJarray.FirstOrDefault(j => j.Value<string>("valueRules").Contains("颜色")); |
|
|
|
if (tempDataJToken == null) |
|
|
|
{ |
|
|
|
RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, haveGiftTemplateSku); |
|
|
|
throw new BusinessException("缺少结构化属性-颜色"); |
|
|
|
} |
|
|
|
attrId = tempDataJToken.Value<string>("attrId"); |
|
|
|
var tempDataValuesJToken = JObject.Parse(tempDataJToken["valueRules"].ToString()); |
|
|
|
var tempDataValues_Level1_JToken = tempDataValuesJToken["items"][0]; |
|
|
|
if (tempDataValues_Level1_JToken["properties"]["id"]["type"].ToString() == "model") |
|
|
|
{ |
|
|
|
//[{\"id\":5,\"unit\":\"\",\"value\":\"红色\","valueId":1234567}]
|
|
|
|
var tempJarray = tempDataValues_Level1_JToken["properties"]["value"]["enum"][0]["preprocessingSaleAttrValTemplateValueList"] as JArray; |
|
|
|
strutsSaleAttrValueList.AddRange(tempJarray.Select(j => new AttrValueAliasJson |
|
|
|
{ |
|
|
|
id = int.Parse(tempDataValues_Level1_JToken["properties"]["id"]["enum"][0].ToString()), |
|
|
|
value = j.Value<string>("name"), |
|
|
|
valueId = j.Value<int>("id"), |
|
|
|
unit = string.Empty |
|
|
|
})); |
|
|
|
} |
|
|
|
else |
|
|
|
throw new BusinessException($"不支持的properties.id.type {tempDataValues_Level1_JToken["properties"]["id"]["type"]}"); |
|
|
|
} |
|
|
|
colorSaleAttrs = colorProperty["attrValueList"].ToList(); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
@ -1061,12 +1120,26 @@ namespace BBWY.Server.Business |
|
|
|
var skusParamList = new List<SkuWriteUpdateSkusItem>(); |
|
|
|
var updateSkuTitleParamList = new List<WareWriteUpdateWareSaleAttrvalueAliasRequestItem>(); |
|
|
|
var imageWriteUpdateRequestList = new List<ImageWriteUpdateRequest>(); |
|
|
|
var skuIndex = noUsedIndexList.Count() - 1; |
|
|
|
//var skuIndex = noUsedIndexList.Count() - 1;
|
|
|
|
var skuIndex = isStruts ? strutsSaleAttrValueList.Count() - 1 : noUsedIndexList.Count() - 1; |
|
|
|
|
|
|
|
for (var i = 0; i < request.GiftTemplateSkuList.Count(); i++) |
|
|
|
{ |
|
|
|
var giftSku = request.GiftTemplateSkuList[i]; |
|
|
|
//var colorPropertyValue = colorSaleAttrs[takeColorIndex];
|
|
|
|
|
|
|
|
var attrValueAlias = string.Empty; |
|
|
|
if (isStruts) |
|
|
|
{ |
|
|
|
var value = strutsSaleAttrValueList[skuIndex]; |
|
|
|
value.value = giftSku.Title; |
|
|
|
attrValueAlias = JsonConvert.SerializeObject(new object[] { value }); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
attrValueAlias = giftSku.Title; |
|
|
|
} |
|
|
|
|
|
|
|
var p = new SkuWriteUpdateSkusItem() |
|
|
|
{ |
|
|
|
type = "com.jd.pop.ware.ic.api.domain.Sku", |
|
|
@ -1080,8 +1153,8 @@ namespace BBWY.Server.Business |
|
|
|
new SkuWriteUpdateSkusItemSaleAttrs() |
|
|
|
{ |
|
|
|
type = "com.jd.pop.ware.ic.api.domain.Prop", |
|
|
|
attrId = colorSaleAttrs[0].Value<string>("attId"), |
|
|
|
attrValueAlias = new List<string>(){ giftSku.Title }, |
|
|
|
attrId = attrId, |
|
|
|
attrValueAlias = new List<string>(){ attrValueAlias }, |
|
|
|
index = noUsedIndexList[skuIndex], |
|
|
|
attrValuesSeqNo = new List<int?>(){ noUsedIndexList[skuIndex] } |
|
|
|
} |
|
|
@ -1192,7 +1265,7 @@ namespace BBWY.Server.Business |
|
|
|
|
|
|
|
foreach (var ps in newMainProductSkuList) |
|
|
|
{ |
|
|
|
if (request.GiftTemplateSkuList.Any(x => x.Title == ps.Title)) |
|
|
|
if (request.GiftTemplateSkuList.Any(x => x.Title == ps.Title || ps.Title.Contains(x.Title))) |
|
|
|
{ |
|
|
|
//此sku是赠品sku
|
|
|
|
//newSkuIdList.Add(ps.Id);
|
|
|
@ -1213,7 +1286,8 @@ namespace BBWY.Server.Business |
|
|
|
foreach (var giftsku in giftSkuList) |
|
|
|
{ |
|
|
|
var skuJToken = giftsku.Source; |
|
|
|
var skuTitle = skuJToken["saleAttrs"][0]["attrValueAlias"][0].ToString(); |
|
|
|
//var skuTitle = skuJToken["saleAttrs"][0]["attrValueAlias"][0].ToString();
|
|
|
|
var skuTitle = GetSkuTitle(skuJToken); |
|
|
|
var colorId = "0000000000"; |
|
|
|
try |
|
|
|
{ |
|
|
@ -1222,7 +1296,7 @@ namespace BBWY.Server.Business |
|
|
|
catch { } |
|
|
|
var currentImgIndex = imgIndex; |
|
|
|
imgIndex++; |
|
|
|
var giftSku = request.GiftTemplateSkuList.FirstOrDefault(x => x.Title == skuTitle); |
|
|
|
var giftSku = request.GiftTemplateSkuList.FirstOrDefault(x => x.Title == skuTitle || skuTitle.Contains(x.Title)); |
|
|
|
var imgUrl = giftSku.Logo.Substring(giftSku.Logo.IndexOf("jfs")); |
|
|
|
|
|
|
|
colorBuilder.Append($"{colorId},"); |
|
|
|