From 5f3d728c165aa225108ce889a80a24f89e71be6b Mon Sep 17 00:00:00 2001 From: shanji <18996038927@163.com> Date: Tue, 10 Jan 2023 16:41:01 +0800 Subject: [PATCH] 1 --- .../PlatformSDK/JDBusiness.cs | 231 ++++++++++-------- .../Product/SearchProductSkuRequest.cs | 10 + DongDongInJection/InDll/CSharpAPIs.cs | 8 +- 3 files changed, 138 insertions(+), 111 deletions(-) diff --git a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs index a585e642..c6671396 100644 --- a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs +++ b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs @@ -170,6 +170,13 @@ namespace BBWY.Server.Business break; pageIndex++; } + + if (searchProductSkuRequest.IsCheckSkuCount && + !string.IsNullOrEmpty(searchProductSkuRequest.Sku) && + skuIdList.Count() != skuList.Count()) + { + throw new BusinessException($"{searchProductSkuRequest.CheckStep}-sku条件数量和查询结果数量不一致"); + } return skuList; } @@ -703,24 +710,33 @@ namespace BBWY.Server.Business var req = new SellerPromotionSkuAddRequest(); req.promoId = promotionId; - foreach (var sku in skuList) + var pageIndex = 1; + var pageSize = 100; + var totalPage = (skuList.Count() - 1) / pageSize + 1; + + for (var i = 0; i < totalPage; i++) { - 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.promoPrices = $"{req.promoPrices}{(isGift ? 0 : sku.Price)},"; - } + var currentPageList = skuList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); - 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.promoPrices = req.promoPrices.Substring(0, req.promoPrices.Length - 1); + foreach (var sku in currentPageList) + { + 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.promoPrices = $"{req.promoPrices}{(isGift ? 0 : sku.Price)},"; + } - var res = jdClient.Execute(req, token, DateTime.Now.ToLocalTime()); - if (res.IsError) - throw new BusinessException($"添加活动sku失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); + 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.promoPrices = req.promoPrices.Substring(0, req.promoPrices.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) @@ -736,6 +752,71 @@ namespace BBWY.Server.Business var brandName = string.Empty; var haveGiftTemplateSku = request.GiftTemplateSkuList != null && request.GiftTemplateSkuList.Count() > 0; + #region 前置检查各项sku + var searchProductSkuRequest = new SearchProductSkuRequest() + { + AppKey = request.AppKey, + AppSecret = request.AppSecret, + AppToken = request.AppToken, + Platform = Enums.Platform.京东, + IsCheckSkuCount = true + }; + + IList motherTemplateSkuList = null; + IList customerMotherSkuList = null; + IList mainProductSkuList = null; + IList giftSkuList = null; + + #region 查询奶妈模板SKU + if (!string.IsNullOrEmpty(request.MotherTemplateSku)) + { + stepText = "查询奶妈模板SKU"; + searchProductSkuRequest.Sku = request.MotherTemplateSku; + searchProductSkuRequest.CheckStep = "奶妈模板"; + motherTemplateSkuList = GetProductSkuList(searchProductSkuRequest); + } + #endregion + + #region 查询自定义奶妈SKU + if (!string.IsNullOrEmpty(request.CustomMotherSku)) + { + stepText = "查询自定义奶妈SKU"; + searchProductSkuRequest.Sku = request.CustomMotherSku; + searchProductSkuRequest.CheckStep = "自定义奶妈"; + customerMotherSkuList = GetProductSkuList(searchProductSkuRequest); + } + #endregion + + #region 查询主商品sku + if (!string.IsNullOrEmpty(request.MainProductSku)) + { + stepText = "查询主商品SKU"; + searchProductSkuRequest.Sku = request.MainProductSku; + searchProductSkuRequest.CheckStep = "主商品"; + mainProductSkuList = GetProductSkuList(searchProductSkuRequest); + + //stepText = "添加主商品SKU"; + //AddJDPromotionSku(jdClient, request.AppToken, promotionId, skuList, false); + } + #endregion + + #region 查询主商品赠品sku + if (!string.IsNullOrEmpty(request.MainProductGiftSku)) + { + stepText = "查询主商品赠品SKU"; + searchProductSkuRequest.Sku = request.MainProductGiftSku; + searchProductSkuRequest.CheckStep = "主商品赠品"; + giftSkuList = GetProductSkuList(searchProductSkuRequest); + giftSkuIdList = giftSkuList.Select(gs => gs.Id).ToList(); + + //stepText = "添加赠品SKU"; + //AddJDPromotionSku(jdClient, request.AppToken, promotionId, skuList, true); + } + #endregion + + #endregion + + #region 获取主商品品牌 { stepText = "获取主商品品牌"; @@ -794,19 +875,6 @@ namespace BBWY.Server.Business } #endregion - //#region 获取赠品sku信息 - //stepText = "获取赠品sku信息"; - //var selectGiftSkuList = GetProductSkuList(new SearchProductSkuRequest() - //{ - // AppKey = request.AppKey, - // AppSecret = request.AppSecret, - // AppToken = request.AppToken, - // IsContainSource = true, - // Platform = request.Platform, - // Sku = request.GiftTemplateSku - //}); - //#endregion - #region 获取销售属性 stepText = "获取销售属性"; IList colorSaleAttrs = null; @@ -938,14 +1006,25 @@ namespace BBWY.Server.Business #endregion #endregion - } - else - { - var skuList = request.MainProductGiftSku.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - giftSkuIdList.AddRange(skuList); + + #region 查询上架的赠品 + stepText = "查询上架的赠品SKU"; + searchProductSkuRequest.Sku = string.Join(",", giftSkuIdList); + searchProductSkuRequest.CheckStep = "上架的赠品"; + giftSkuList = GetProductSkuList(searchProductSkuRequest); + #endregion } #region 创建活动 + var deleteGiftSkuRequest = new DeleteSkuListRequest() + { + AppKey = request.AppKey, + AppSecret = request.AppSecret, + AppToken = request.AppToken, + Platform = request.Platform, + SkuList = giftSkuIdList + }; + { stepText = "创建活动"; var req = new SellerPromotionAddRequest(); @@ -966,16 +1045,7 @@ namespace BBWY.Server.Business if (res.IsError) { if (haveGiftTemplateSku) - { - DeleteSkuList(new DeleteSkuListRequest() - { - AppKey = request.AppKey, - AppSecret = request.AppSecret, - AppToken = request.AppToken, - Platform = request.Platform, - SkuList = giftSkuIdList - }); - } + DeleteSkuList(deleteGiftSkuRequest); throw new BusinessException($"创建活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); } @@ -986,57 +1056,29 @@ namespace BBWY.Server.Business #region 添加活动sku { - var searchProductSkuRequest = new SearchProductSkuRequest() + if (motherTemplateSkuList != null && motherTemplateSkuList.Count() > 0) { - AppKey = request.AppKey, - AppSecret = request.AppSecret, - AppToken = request.AppToken, - Platform = Enums.Platform.京东, - }; - - #region 添加奶妈模板SKU - if (!string.IsNullOrEmpty(request.MotherTemplateSku)) - { - stepText = "查询奶妈模板SKU"; - searchProductSkuRequest.Sku = request.MotherTemplateSku; - var skuList = GetProductSkuList(searchProductSkuRequest); stepText = "添加奶妈模板SKU"; - AddJDPromotionSku(jdClient, request.AppToken, promotionId, skuList, false); + AddJDPromotionSku(jdClient, request.AppToken, promotionId, motherTemplateSkuList, false); } - #endregion - #region 添加自定义奶妈SKU - if (!string.IsNullOrEmpty(request.CustomMotherSku)) + if (customerMotherSkuList != null && customerMotherSkuList.Count() > 0) { - stepText = "查询自定义奶妈SKU"; - searchProductSkuRequest.Sku = request.CustomMotherSku; - var skuList = GetProductSkuList(searchProductSkuRequest); stepText = "添加自定义奶妈SKU"; - AddJDPromotionSku(jdClient, request.AppToken, promotionId, skuList, false); + AddJDPromotionSku(jdClient, request.AppToken, promotionId, customerMotherSkuList, false); } - #endregion - #region 添加主商品sku - if (!string.IsNullOrEmpty(request.MainProductSku)) + if (mainProductSkuList != null && mainProductSkuList.Count() > 0) { - stepText = "查询主商品SKU"; - searchProductSkuRequest.Sku = request.MainProductSku; - var skuList = GetProductSkuList(searchProductSkuRequest); stepText = "添加主商品SKU"; - AddJDPromotionSku(jdClient, request.AppToken, promotionId, skuList, false); + AddJDPromotionSku(jdClient, request.AppToken, promotionId, mainProductSkuList, false); } - #endregion - #region 添加赠品sku - if (giftSkuIdList.Count() > 0) + if (giftSkuList != null && giftSkuList.Count() > 0) { - stepText = "查询赠品SKU"; - searchProductSkuRequest.Sku = string.Join(",", giftSkuIdList); - var skuList = GetProductSkuList(searchProductSkuRequest); stepText = "添加赠品SKU"; - AddJDPromotionSku(jdClient, request.AppToken, promotionId, skuList, true); + AddJDPromotionSku(jdClient, request.AppToken, promotionId, giftSkuList, true); } - #endregion } #endregion @@ -1050,16 +1092,7 @@ namespace BBWY.Server.Business if (res.IsError) { if (haveGiftTemplateSku) - { - DeleteSkuList(new DeleteSkuListRequest() - { - AppKey = request.AppKey, - AppSecret = request.AppSecret, - AppToken = request.AppToken, - Platform = request.Platform, - SkuList = giftSkuIdList - }); - } + DeleteSkuList(deleteGiftSkuRequest); throw new BusinessException($"创建活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); } } @@ -1076,16 +1109,7 @@ namespace BBWY.Server.Business if (res.IsError) { if (haveGiftTemplateSku) - { - DeleteSkuList(new DeleteSkuListRequest() - { - AppKey = request.AppKey, - AppSecret = request.AppSecret, - AppToken = request.AppToken, - Platform = request.Platform, - SkuList = giftSkuIdList - }); - } + DeleteSkuList(deleteGiftSkuRequest); throw new BusinessException($"审核活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); } @@ -1095,14 +1119,7 @@ namespace BBWY.Server.Business #region 下架赠品sku stepText = "下架赠品sku"; Thread.Sleep(3000); - DeleteSkuList(new DeleteSkuListRequest() - { - AppKey = request.AppKey, - AppSecret = request.AppSecret, - AppToken = request.AppToken, - Platform = request.Platform, - SkuList = giftSkuIdList - }); + DeleteSkuList(deleteGiftSkuRequest); #endregion #region 设置完整标题 diff --git a/BBWY.Server.Model/Dto/Request/Product/SearchProductSkuRequest.cs b/BBWY.Server.Model/Dto/Request/Product/SearchProductSkuRequest.cs index 51212037..6e644ba1 100644 --- a/BBWY.Server.Model/Dto/Request/Product/SearchProductSkuRequest.cs +++ b/BBWY.Server.Model/Dto/Request/Product/SearchProductSkuRequest.cs @@ -18,5 +18,15 @@ namespace BBWY.Server.Model.Dto /// 是否包含源 /// public bool IsContainSource { get; set; } + + /// + /// 检查sku数量是否匹配,仅在使用sku条件查询时生效 + /// + public bool IsCheckSkuCount { get; set; } + + /// + /// 检查环节 + /// + public string CheckStep { get; set; } } } diff --git a/DongDongInJection/InDll/CSharpAPIs.cs b/DongDongInJection/InDll/CSharpAPIs.cs index 01d19bd2..3754ff3d 100644 --- a/DongDongInJection/InDll/CSharpAPIs.cs +++ b/DongDongInJection/InDll/CSharpAPIs.cs @@ -153,10 +153,10 @@ namespace QYDongDongTool GWL_ID = (-12) } - public static nint SetWindowStyle(IntPtr hwnd) - { - return SetWindowLong(hwnd, (int)GWL.GWL_EXSTYLE, (GetWindowLong(hwnd, (int)GWL.GWL_EXSTYLE) | 0x00000004)); - } + //public static nint SetWindowStyle(IntPtr hwnd) + //{ + // return SetWindowLong(hwnd, (int)GWL.GWL_EXSTYLE, (GetWindowLong(hwnd, (int)GWL.GWL_EXSTYLE) | 0x00000004)); + //} public static bool ReSetParent(IntPtr hWnd) {