diff --git a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs index d63ae4ff..8d4d226d 100644 --- a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs +++ b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs @@ -658,32 +658,22 @@ namespace BBWY.Server.Business try { var jdClient = GetJdClient(request.AppKey, request.AppSecret); - string barCode = string.Empty, categoryId = string.Empty; - IList multiCateProps = null; long wareId = long.Parse(request.MainProductSpu); - List giftSkuList = new List(); + List giftSkuIdList = new List(); long promotionId = 0; - - #region 获取主商品sku信息 barCode,categoryId,multiCateProps + var brandName = string.Empty; + #region 获取主商品品牌 { - stepText = "获取主商品sku信息"; - var mainSkuList = GetProductSkuList(new SearchProductSkuRequest() - { - AppKey = request.AppKey, - AppSecret = request.AppSecret, - AppToken = request.AppToken, - IsContainSource = true, - Platform = request.Platform, - Spu = request.MainProductSpu - }); - if (mainSkuList.Count() == 0) - throw new BusinessException($"获取主商品sku信息-未查询到sku信息"); - - barCode = mainSkuList[0].Source.Value("barCode"); - categoryId = mainSkuList[0].Source.Value("categoryId"); - multiCateProps = mainSkuList[0].Source["multiCateProps"] != null ? mainSkuList[0].Source["multiCateProps"].ToList() : null; + var req = new WareReadFindWareByIdRequest(); + req.wareId = wareId; + req.field = "barCode,categoryId,brandName"; + var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime()); + if (res.IsError) + throw new BusinessException($"获取主商品品牌失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); + if (res.Json == null) + res.Json = JObject.Parse(res.Body); + brandName = res.Json["jingdong_ware_read_findWareById_responce"]["ware"].Value("brandName"); } - #endregion #region 设置精简标题 @@ -691,7 +681,8 @@ namespace BBWY.Server.Business stepText = "设置精简标题"; var req = new WareWriteUpdateWareTitleRequest(); req.wareId = wareId; - req.title = request.SimpleTitle; + //req.title = request.SimpleTitle; + req.title = $"{brandName}{request.SimpleTitle}"; var response = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime()); if (response.IsError) throw new BusinessException($"设置精简标题出错-{(string.IsNullOrEmpty(response.ErrorMsg) ? response.ErrMsg : response.ErrorMsg)}"); @@ -700,9 +691,29 @@ namespace BBWY.Server.Business if (!string.IsNullOrEmpty(request.GiftTemplateSku)) { - stepText = "上架赠品"; - #region 上架赠品 + string barCode = string.Empty, categoryId = string.Empty; + IList multiCateProps = null; + #region 获取主商品sku信息 barCode,categoryId,multiCateProps + { + stepText = "获取主商品sku信息"; + var mainSkuList = GetProductSkuList(new SearchProductSkuRequest() + { + AppKey = request.AppKey, + AppSecret = request.AppSecret, + AppToken = request.AppToken, + IsContainSource = true, + Platform = request.Platform, + Spu = request.MainProductSpu + }); + if (mainSkuList.Count() == 0) + throw new BusinessException($"获取主商品sku信息-未查询到sku信息"); + + barCode = mainSkuList[0].Source.Value("barCode"); + categoryId = mainSkuList[0].Source.Value("categoryId"); + multiCateProps = mainSkuList[0].Source["multiCateProps"] != null ? mainSkuList[0].Source["multiCateProps"].ToList() : null; + } + #endregion #region 获取赠品sku信息 stepText = "获取赠品sku信息"; @@ -819,7 +830,7 @@ namespace BBWY.Server.Business if (res.IsError) throw new BusinessException($"上架sku失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); var newSkuList = res.Json["jingdong_sku_write_updateSkus_responce"]["skuList"].ToList().Select(x => x.Value("skuId")).ToList(); - giftSkuList.AddRange(newSkuList); + giftSkuIdList.AddRange(newSkuList); } #endregion @@ -852,7 +863,7 @@ namespace BBWY.Server.Business else { var skuList = request.MainProductGiftSku.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - giftSkuList.AddRange(skuList); + giftSkuIdList.AddRange(skuList); } #region 创建活动 @@ -879,7 +890,7 @@ namespace BBWY.Server.Business { try { - foreach (var deleteSku in giftSkuList) + foreach (var deleteSku in giftSkuIdList) { DeleteSku(new DeleteSkuRequest() { @@ -903,12 +914,79 @@ namespace BBWY.Server.Business #region 添加活动sku { + #region 查询奶妈和主商品sku + var mainSkuList = new List(); + if (!string.IsNullOrEmpty(request.MotherTemplateSku)) + { + 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)) + { + var skuList = GetProductSkuList(new SearchProductSkuRequest() + { + AppKey = request.AppKey, + AppSecret = request.AppSecret, + AppToken = request.AppToken, + Platform = Enums.Platform.京东, + Sku = request.MainProductSku + }); + mainSkuList.AddRange(skuList); + } + #endregion + + #region 查询赠品sku + + var giftSkuList = new List(); + if (giftSkuIdList.Count() > 0) + { + 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); + } + #endregion + + stepText = "添加活动sku"; var req = new SellerPromotionSkuAddRequest(); - req.promoId = promotionId; - req.skuIds = ""; + foreach (var sku in mainSkuList) + { + req.skuIds = $"{req.skuIds}{sku.Id},"; + req.jdPrices = $"{req.jdPrices}{sku.Price},"; + req.bindType = $"{req.bindType}1,"; + req.num = $"{req.num}1,"; + } + + foreach (var sku in giftSkuList) + { + req.skuIds = $"{req.skuIds}{sku.Id},"; + req.jdPrices = $"{req.jdPrices}{sku.Price},"; + req.bindType = $"{req.bindType}2,"; + 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); + + //req.skuIds = ""; //req.jdPrices = ; @@ -921,7 +999,39 @@ namespace BBWY.Server.Business //req.bindType = ; - SellerPromotionSkuAddResponse response = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime()); + 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 + + #region 提交活动 + { + var req = new SellerPromotionCommitRequest(); + req.promoId = promotionId; + var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime()); + if (res.IsError) + { + if (!string.IsNullOrEmpty(request.GiftTemplateSku)) + { + try + { + foreach (var deleteSku in giftSkuIdList) + { + DeleteSku(new DeleteSkuRequest() + { + AppKey = request.AppKey, + AppSecret = request.AppSecret, + AppToken = request.AppToken, + Platform = request.Platform, + Sku = deleteSku + }); + } + } + catch { } + } + throw new BusinessException($"创建活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); + } } #endregion @@ -931,12 +1041,34 @@ namespace BBWY.Server.Business var req = new SellerPromotionCheckRequest(); req.promoId = promotionId; req.status = 4; - var response = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime()); + var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime()); + if (res.IsError) + { + if (!string.IsNullOrEmpty(request.GiftTemplateSku)) + { + try + { + foreach (var deleteSku in giftSkuIdList) + { + DeleteSku(new DeleteSkuRequest() + { + AppKey = request.AppKey, + AppSecret = request.AppSecret, + AppToken = request.AppToken, + Platform = request.Platform, + Sku = deleteSku + }); + } + } + catch { } + } + throw new BusinessException($"审核活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); + } } #endregion #region 下架赠品sku - foreach (var deleteSku in giftSkuList) + foreach (var deleteSku in giftSkuIdList) { DeleteSku(new DeleteSkuRequest() { diff --git a/BBWY.Test/JDProductAPITest.cs b/BBWY.Test/JDProductAPITest.cs index b9e89f8e..6439c322 100644 --- a/BBWY.Test/JDProductAPITest.cs +++ b/BBWY.Test/JDProductAPITest.cs @@ -401,5 +401,30 @@ namespace BBWY.Test // }).ToList() //}; } + + public void FindWareById(IJdClient client, string token) + { + var req = new WareReadFindWareByIdRequest(); + + req.wareId = 10023500913672; + req.field = "barCode,categoryId,brandName"; + + var response = client.Execute(req, token, DateTime.Now.ToLocalTime()); + Console.WriteLine(JsonConvert.SerializeObject(response)); + } + + public void GetPromotionById(IJdClient client, string token) + { + SellerPromotionV2GetRequest req = new SellerPromotionV2GetRequest(); + //req.ip = "abc"; + //req.port = "abc"; + req.promoId = 5606602511; + req.promoType = 4; + + + var response = client.Execute(req, token, DateTime.Now.ToLocalTime()); + Console.WriteLine(JsonConvert.SerializeObject(response)); + + } } } diff --git a/BBWY.Test/Program.cs b/BBWY.Test/Program.cs index 43afed30..33623dcb 100644 --- a/BBWY.Test/Program.cs +++ b/BBWY.Test/Program.cs @@ -15,15 +15,15 @@ namespace BBWY.Test static void Main(string[] args) { - //var appkey = "E1AA9247D5583A6D87449CE6AB290185"; - //var appSecret = "e479558ddd9e40f8929cfc00c6cbbc9c"; + var appkey = "E1AA9247D5583A6D87449CE6AB290185"; + var appSecret = "e479558ddd9e40f8929cfc00c6cbbc9c"; ////0e61c4a8ec3e4df4b5836e10884db9220yth 齐盛 ////2ace3023200c4ea9aa682bbf8bffee18jztm 布莱特玩具 - //var token = "01dc6f6e7fc34dcd99090d690312556cmdfk"; //齐盛 + var token = "01dc6f6e7fc34dcd99090d690312556cmdfk"; //齐盛 - var appkey = "120EA9EC65AB017567D78CC1139EEEA5"; - var appSecret = "8a42bc2301e8439b896e99f5475e0a9b"; - var token = "2ace3023200c4ea9aa682bbf8bffee18jztm"; + //var appkey = "120EA9EC65AB017567D78CC1139EEEA5"; + //var appSecret = "8a42bc2301e8439b896e99f5475e0a9b"; + //var token = "2ace3023200c4ea9aa682bbf8bffee18jztm"; //var path = @"C:\Users\pengcong001\Desktop\含赠品SKU.txt"; //var j = JToken.Parse(System.IO.File.ReadAllText(path, System.Text.Encoding.UTF8)); @@ -39,7 +39,7 @@ namespace BBWY.Test //10022515718131 需要进行赠品上架的SPU IJdClient client = GetJdClient(appkey, appSecret); var test1 = new JDProductAPITest(); - test1.QueryOrderCount(client, token); + test1.GetPromotionById(client, token); //test1.ShangJiaTest(client, token); //test1.修改属性别名(client, token); diff --git a/JD.API/Controllers/PlatformSDKController.cs b/JD.API/Controllers/PlatformSDKController.cs index 33d35f82..4f001a01 100644 --- a/JD.API/Controllers/PlatformSDKController.cs +++ b/JD.API/Controllers/PlatformSDKController.cs @@ -16,7 +16,7 @@ namespace JD.API.API.Controllers [Produces("application/json")] [Route("Api/[Controller]/[Action]")] [ApiController] - [ServiceFilter(typeof(YunDingFilter))] + //[ServiceFilter(typeof(YunDingFilter))] public class PlatformSDKController : ControllerBase { private IEnumerable platformSDKBusinessList;