|
|
@ -35,7 +35,7 @@ namespace BBWY.Server.Business |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
public JDBusiness(IMemoryCache memoryCache, NLogManager nLogManager, TaskSchedulerManager taskSchedulerManager) : base(memoryCache, nLogManager, taskSchedulerManager) { } |
|
|
|
public JDBusiness(IMemoryCache memoryCache, NLogManager nLogManager) : base(memoryCache, nLogManager) { } |
|
|
|
|
|
|
|
private IJdClient GetJdClient(string appKey, string appSecret) |
|
|
|
{ |
|
|
@ -695,22 +695,36 @@ namespace BBWY.Server.Business |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void RollBackWhenStartPromotionError(DeleteSkuListRequest deleteSkuRequest, StartPromotionTaskRequest2 startRequest, string brandName, bool haveGiftTemplateSku) |
|
|
|
private void RollBackWhenStartPromotionError(string appKey, |
|
|
|
string appSecret, |
|
|
|
string appToken, |
|
|
|
IList<string> deleteSkuList, |
|
|
|
string mainProductSpu, |
|
|
|
string fullTitle, |
|
|
|
string brandName, |
|
|
|
bool haveGiftTemplateSku) |
|
|
|
{ |
|
|
|
var jdClient = GetJdClient(deleteSkuRequest.AppKey, deleteSkuRequest.AppSecret); |
|
|
|
var jdClient = GetJdClient(appKey, appSecret); |
|
|
|
|
|
|
|
if (haveGiftTemplateSku) |
|
|
|
DeleteSkuList(deleteSkuRequest); |
|
|
|
DeleteSkuList(new DeleteSkuListRequest() |
|
|
|
{ |
|
|
|
AppKey = appKey, |
|
|
|
AppSecret = appSecret, |
|
|
|
AppToken = appToken, |
|
|
|
Platform = Enums.Platform.京东, |
|
|
|
SkuList = deleteSkuList |
|
|
|
}); |
|
|
|
|
|
|
|
#region 设置完整标题
|
|
|
|
{ |
|
|
|
var req = new WareWriteUpdateWareTitleRequest(); |
|
|
|
req.wareId = long.Parse(startRequest.MainProductSpu); |
|
|
|
if (!startRequest.FullTitle.StartsWith(brandName)) |
|
|
|
req.title = $"{brandName}{startRequest.FullTitle}"; |
|
|
|
req.wareId = long.Parse(mainProductSpu); |
|
|
|
if (!fullTitle.StartsWith(brandName)) |
|
|
|
req.title = $"{brandName}{fullTitle}"; |
|
|
|
else |
|
|
|
req.title = startRequest.FullTitle; |
|
|
|
var response = jdClient.Execute(req, startRequest.AppToken, DateTime.Now.ToLocalTime()); |
|
|
|
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)}"); |
|
|
|
} |
|
|
@ -766,7 +780,7 @@ namespace BBWY.Server.Business |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public override long StartJDPromotionTask(StartPromotionTaskRequest2 request) |
|
|
|
public override StartPromotionTaskResponse StartJDPromotionTask(StartPromotionTaskRequest2 request) |
|
|
|
{ |
|
|
|
var stepText = string.Empty; |
|
|
|
//stepText.AppendLine($"任务Id {request.Id} 店铺Id {request.ShopId}");
|
|
|
@ -1051,14 +1065,7 @@ namespace BBWY.Server.Business |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
RollBackWhenStartPromotionError(new DeleteSkuListRequest() |
|
|
|
{ |
|
|
|
AppKey = request.AppKey, |
|
|
|
AppSecret = request.AppSecret, |
|
|
|
AppToken = request.AppToken, |
|
|
|
Platform = request.Platform, |
|
|
|
SkuList = giftSkuIdList |
|
|
|
}, request, brandName, haveGiftTemplateSku); |
|
|
|
RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, true); |
|
|
|
throw ex; |
|
|
|
} |
|
|
|
} |
|
|
@ -1103,7 +1110,7 @@ namespace BBWY.Server.Business |
|
|
|
res.Json = JObject.Parse(res.Body); |
|
|
|
if (res.IsError) |
|
|
|
{ |
|
|
|
RollBackWhenStartPromotionError(deleteGiftSkuRequest, request, brandName, haveGiftTemplateSku); |
|
|
|
RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, haveGiftTemplateSku); |
|
|
|
throw new BusinessException($"创建活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); |
|
|
|
} |
|
|
|
|
|
|
@ -1149,36 +1156,20 @@ namespace BBWY.Server.Business |
|
|
|
var res = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime()); |
|
|
|
if (res.IsError) |
|
|
|
{ |
|
|
|
RollBackWhenStartPromotionError(deleteGiftSkuRequest, request, brandName, haveGiftTemplateSku); |
|
|
|
RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, giftSkuIdList, request.MainProductSpu, request.FullTitle, brandName, haveGiftTemplateSku); |
|
|
|
throw new BusinessException($"创建活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
Task.Factory.StartNew(() => StartJDPromotionTaskDelay(deleteGiftSkuRequest, request, brandName, promotionId), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionDelayTaskScheduler); |
|
|
|
|
|
|
|
//#region 下架赠品sku
|
|
|
|
//stepText = "下架赠品sku";
|
|
|
|
//Thread.Sleep(5000);
|
|
|
|
//DeleteSkuList(deleteGiftSkuRequest);
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
//#region 设置完整标题
|
|
|
|
//{
|
|
|
|
// stepText = "设置完整标题";
|
|
|
|
// var req = new WareWriteUpdateWareTitleRequest();
|
|
|
|
// req.wareId = long.Parse(request.MainProductSpu);
|
|
|
|
// if (!request.FullTitle.StartsWith(brandName))
|
|
|
|
// req.title = $"{brandName}{request.FullTitle}";
|
|
|
|
// else
|
|
|
|
// req.title = request.FullTitle;
|
|
|
|
// var response = jdClient.Execute(req, request.AppToken, DateTime.Now.ToLocalTime());
|
|
|
|
// if (response.IsError)
|
|
|
|
// throw new BusinessException($"设置完整标题出错-{(string.IsNullOrEmpty(response.ErrorMsg) ? response.ErrMsg : response.ErrorMsg)}");
|
|
|
|
//}
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
return promotionId; |
|
|
|
//Task.Factory.StartNew(() => StartJDPromotionTaskDelay(deleteGiftSkuRequest, request, brandName, promotionId), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionDelayTaskScheduler);
|
|
|
|
|
|
|
|
return new StartPromotionTaskResponse() |
|
|
|
{ |
|
|
|
BrandName = brandName, |
|
|
|
JDPromotionId = promotionId, |
|
|
|
DeleteGiftSkuList = giftSkuIdList |
|
|
|
}; |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
@ -1187,6 +1178,40 @@ namespace BBWY.Server.Business |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public override void StartJDPromotionDelayTask(StartPromotionTaskDelayRequest request) |
|
|
|
{ |
|
|
|
Thread.Sleep(30 * 1000); |
|
|
|
try |
|
|
|
{ |
|
|
|
CheckJDPromotionTask(request.JDPromotionId, request.AppKey, request.AppSecret, request.AppToken); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, request.DeleteGiftSkuList, request.MainProductSpu, request.FullTitle, request.BrandName, request.HaveGiftTemplate); |
|
|
|
throw; |
|
|
|
} |
|
|
|
|
|
|
|
Thread.Sleep(30 * 1000); |
|
|
|
|
|
|
|
#region 检查奶妈sku是否完全生效
|
|
|
|
{ |
|
|
|
var i = 0; |
|
|
|
while (i < 10) |
|
|
|
{ |
|
|
|
i++; |
|
|
|
var promotionTaskSkuList = GetPromotionTaskSku(request.AppKey, request.AppSecret, request.AppToken, request.JDPromotionId); |
|
|
|
if (promotionTaskSkuList.Any(s => s.Value<int>("bind_type") == 1 && s.Value<int>("sku_status") == 0)) |
|
|
|
{ |
|
|
|
Thread.Sleep(2000); |
|
|
|
continue; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
RollBackWhenStartPromotionError(request.AppKey, request.AppSecret, request.AppToken, request.DeleteGiftSkuList, request.MainProductSpu, request.FullTitle, request.BrandName, true); |
|
|
|
} |
|
|
|
|
|
|
|
public override void DeleteJDPromotionTask(DeleteJDPromotionTaskRequest request) |
|
|
|
{ |
|
|
|
var jdClient = GetJdClient(request.AppKey, request.AppSecret); |
|
|
@ -1238,22 +1263,17 @@ namespace BBWY.Server.Business |
|
|
|
{ |
|
|
|
var jdClient = GetJdClient(appkey, appSecret); |
|
|
|
Thread.Sleep(3000); |
|
|
|
//var req = new SellerPromotionCheckRequest();
|
|
|
|
//req.promoId = promotionId;
|
|
|
|
//req.status = 4;
|
|
|
|
//var res = jdClient.Execute(req, token, DateTime.Now.ToLocalTime());
|
|
|
|
//if (res.IsError)
|
|
|
|
//{
|
|
|
|
// //RollBackWhenStartPromotionError(deleteGiftSkuRequest, request, brandName, haveGiftTemplateSku);
|
|
|
|
// //throw new BusinessException($"审核活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}");
|
|
|
|
//}
|
|
|
|
|
|
|
|
var req = new PopMarketWritePromotionGiftApproveRequest(); |
|
|
|
req.promoId = promotionId; |
|
|
|
req.requestId = Guid.NewGuid().ToString(); |
|
|
|
|
|
|
|
PopMarketWritePromotionGiftApproveResponse response = jdClient.Execute(req, token, DateTime.Now.ToLocalTime()); |
|
|
|
|
|
|
|
var res = jdClient.Execute(req, token, DateTime.Now.ToLocalTime()); |
|
|
|
if (res.IsError) |
|
|
|
{ |
|
|
|
//RollBackWhenStartPromotionError(deleteGiftSkuRequest, request, brandName, haveGiftTemplateSku);
|
|
|
|
throw new BusinessException($"审核活动失败-{(string.IsNullOrEmpty(res.ErrorMsg) ? res.ErrMsg : res.ErrorMsg)}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private List<JToken> GetPromotionTaskSku(string appkey, string appSecret, string token, long promotionId) |
|
|
@ -1306,30 +1326,5 @@ namespace BBWY.Server.Business |
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void StartJDPromotionTaskDelay(DeleteSkuListRequest deleteSkuRequest, StartPromotionTaskRequest2 startRequest, string brandName, long promotionId) |
|
|
|
{ |
|
|
|
Thread.Sleep(30 * 1000); |
|
|
|
CheckJDPromotionTask(promotionId, deleteSkuRequest.AppKey, deleteSkuRequest.AppSecret, deleteSkuRequest.AppToken); |
|
|
|
Thread.Sleep(30 * 1000); |
|
|
|
|
|
|
|
#region 检查奶妈sku是否完全生效
|
|
|
|
{ |
|
|
|
var i = 0; |
|
|
|
while (i < 10) |
|
|
|
{ |
|
|
|
i++; |
|
|
|
var promotionTaskSkuList = GetPromotionTaskSku(deleteSkuRequest.AppKey, deleteSkuRequest.AppSecret, deleteSkuRequest.AppToken, promotionId); |
|
|
|
if (promotionTaskSkuList.Any(s => s.Value<int>("bind_type") == 1 && s.Value<int>("sku_status") == 0)) |
|
|
|
{ |
|
|
|
Thread.Sleep(2000); |
|
|
|
continue; |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
RollBackWhenStartPromotionError(deleteSkuRequest, startRequest, brandName, true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|