Browse Source

云鼎开始任务返回上架赠品,bbwy开始任务保存上架赠品

qianyi
shanji 2 years ago
parent
commit
e5cc6aa90d
  1. 6
      BBWY.Common/Http/RestAPIService.cs
  2. 59
      BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs
  3. 155
      BBWY.Server.Business/PlatformSDK/JDBusiness.cs
  4. 2
      BBWY.Server.Business/PlatformSDK/PDDBusiness.cs
  5. 12
      BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs
  6. 2
      BBWY.Server.Business/PlatformSDK/TaoBaoBusiness.cs
  7. 2
      BBWY.Server.Business/PlatformSDK/_1688Business.cs
  8. 12
      BBWY.Server.Model/Db/EvaluationAssistant/PromotionTask.cs
  9. 18
      BBWY.Server.Model/Dto/Request/PromotionTask/StartPromotionTaskRequest.cs
  10. 10
      BBWY.Server.Model/Dto/Response/PromotionTask/PromotionTaskResponse.cs
  11. 13
      BBWY.Server.Model/Dto/Response/PromotionTask/StartPromotionTaskResponse.cs
  12. 7
      JD.API/Controllers/PlatformSDKController.cs

6
BBWY.Common/Http/RestAPIService.cs

@ -48,7 +48,8 @@ namespace BBWY.Common.Http
bool enableRandomTimeStamp = false,
bool getResponseHeader = false,
HttpCompletionOption httpCompletionOption = HttpCompletionOption.ResponseContentRead,
string httpClientName = "")
string httpClientName = "",
int timeOutSeconds = 0)
{
//Get和Delete强制使用QueryString形式传参
if (httpMethod == HttpMethod.Get)
@ -71,7 +72,10 @@ namespace BBWY.Common.Http
using (var httpClient = string.IsNullOrEmpty(httpClientName) ? httpClientFactory.CreateClient() : httpClientFactory.CreateClient(httpClientName))
{
if (timeOutSeconds == 0)
httpClient.Timeout = TimeOut;
else
httpClient.Timeout = TimeSpan.FromSeconds(timeOutSeconds);
using (var request = new HttpRequestMessage(httpMethod, url))
{
if (requestHeaders != null && requestHeaders.Count > 0)

59
BBWY.Server.Business/EvaluationAssistant/EvaluationAssistantBusiness.cs

@ -375,17 +375,64 @@ namespace BBWY.Server.Business
if (httpApiResult.StatusCode != System.Net.HttpStatusCode.OK)
throw new BusinessException(httpApiResult.Content);
var response = JsonConvert.DeserializeObject<ApiResponse<long?>>(httpApiResult.Content);
var response = JsonConvert.DeserializeObject<ApiResponse<StartPromotionTaskResponse>>(httpApiResult.Content);
if (!response.Success)
throw new BusinessException(response.Msg);
var promotionId = response.Data;
if (promotionId == null || promotionId == 0)
return;
fsql.Update<PromotionTask>(request.Id).Set(pt => pt.PromotionId, promotionId)
var startResponse = response.Data;
if (dbPromotionTask.GiftTemplateId != null &&
dbPromotionTask.GiftTemplateId != 0 &&
startResponse.DeleteGiftSkuList != null &&
startResponse.DeleteGiftSkuList.Count() != 0)
dbPromotionTask.GiftTemplatePutNewSku = string.Join(",", startResponse.DeleteGiftSkuList);
fsql.Update<PromotionTask>(request.Id).Set(pt => pt.PromotionId, startResponse.JDPromotionId)
.SetIf(!string.IsNullOrEmpty(dbPromotionTask.GiftTemplatePutNewSku), pt => pt.GiftTemplatePutNewSku, dbPromotionTask.GiftTemplatePutNewSku)
.Set(pt => pt.StartTime, DateTime.Now)
.Set(pt => pt.EndTime, DateTime.Now.AddDays(180))
.Set(pt => pt.Status, Enums.PromitionTaskStatus.)
.ExecuteAffrows();
//开启延迟任务
Task.Factory.StartNew(() => StartPromotionDelayTask(request, startResponse, dbPromotionTask), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.JDPromotionDelayTaskScheduler);
}
private void StartPromotionDelayTask(StartPromotionTaskRequest request, StartPromotionTaskResponse startResponse, PromotionTask promotionTask)
{
var host = GetPlatformRelayAPIHost(Enums.Platform.);
var httpApiResult = restApiService.SendRequest(host, "api/PlatformSDK/StartJDPromotionDelayTask", new StartPromotionTaskDelayRequest()
{
Platform = Enums.Platform.,
AppKey = request.AppKey,
AppSecret = request.AppSecret,
AppToken = request.AppToken,
BrandName = startResponse.BrandName,
FullTitle = promotionTask.FullTitle,
JDPromotionId = startResponse.JDPromotionId,
MainProductSpu = promotionTask.MainProductSpu,
HaveGiftTemplate = promotionTask.GiftTemplateId != null && promotionTask.GiftTemplateId != 0,
DeleteGiftSkuList = startResponse.DeleteGiftSkuList
}, GetYunDingRequestHeader(), HttpMethod.Post, timeOutSeconds: 150);
var errorBack = new Action<long, string>((id, errorMsg) =>
{
fsql.Update<PromotionTask>(id).Set(pt => pt.Status, Enums.PromitionTaskStatus.)
.Set(pt => pt.ErrorMsg, errorMsg)
.ExecuteAffrows();
});
if (httpApiResult.StatusCode != System.Net.HttpStatusCode.OK)
{
errorBack(promotionTask.Id, httpApiResult.Content);
return;
}
var response = JsonConvert.DeserializeObject<ApiResponse<object>>(httpApiResult.Content);
if (!response.Success)
{
errorBack(promotionTask.Id, response.Msg);
return;
}
}
/// <summary>
@ -495,8 +542,6 @@ namespace BBWY.Server.Business
}
#endregion
#region 自动任务
public void StartMonitor(long? shopId)

155
BBWY.Server.Business/PlatformSDK/JDBusiness.cs

@ -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);
}
}
}

2
BBWY.Server.Business/PlatformSDK/PDDBusiness.cs

@ -10,7 +10,7 @@ namespace BBWY.Server.Business
public class PDDBusiness : PlatformSDKBusiness
{
public override Enums.Platform Platform => Enums.Platform.;
public PDDBusiness(IMemoryCache memoryCache, NLogManager nLogManager, TaskSchedulerManager taskSchedulerManager) : base(memoryCache, nLogManager, taskSchedulerManager)
public PDDBusiness(IMemoryCache memoryCache, NLogManager nLogManager) : base(memoryCache, nLogManager)
{
}
}

12
BBWY.Server.Business/PlatformSDK/PlatformSDKBusiness.cs

@ -20,13 +20,11 @@ namespace BBWY.Server.Business
public virtual Enums.Platform Platform { get; }
protected NLogManager nLogManager;
protected TaskSchedulerManager taskSchedulerManager;
public PlatformSDKBusiness(IMemoryCache memoryCache, NLogManager nLogManager, TaskSchedulerManager taskSchedulerManager)
public PlatformSDKBusiness(IMemoryCache memoryCache, NLogManager nLogManager)
{
this.memoryCache = memoryCache;
this.nLogManager = nLogManager;
this.taskSchedulerManager = taskSchedulerManager;
this.expirationTimeSpan = TimeSpan.FromMinutes(60);
}
@ -150,7 +148,12 @@ namespace BBWY.Server.Business
throw new NotImplementedException();
}
public virtual long StartJDPromotionTask(StartPromotionTaskRequest2 request)
public virtual StartPromotionTaskResponse StartJDPromotionTask(StartPromotionTaskRequest2 request)
{
throw new NotImplementedException();
}
public virtual void StartJDPromotionDelayTask(StartPromotionTaskDelayRequest request)
{
throw new NotImplementedException();
}
@ -184,5 +187,6 @@ namespace BBWY.Server.Business
{
throw new NotImplementedException();
}
}
}

2
BBWY.Server.Business/PlatformSDK/TaoBaoBusiness.cs

@ -5,7 +5,7 @@ namespace BBWY.Server.Business
{
public class TaoBaoBusiness : PlatformSDKBusiness
{
public TaoBaoBusiness(IMemoryCache memoryCache, NLogManager nLogManager, TaskSchedulerManager taskSchedulerManager) : base(memoryCache, nLogManager, taskSchedulerManager)
public TaoBaoBusiness(IMemoryCache memoryCache, NLogManager nLogManager) : base(memoryCache, nLogManager)
{
}

2
BBWY.Server.Business/PlatformSDK/_1688Business.cs

@ -23,7 +23,7 @@ namespace BBWY.Server.Business
private RestApiService restApiService;
private _1688TradeTypeCompare _1688TradeTypeCompare;
public _1688Business(IMemoryCache memoryCache, NLogManager nLogManager, RestApiService restApiService, TaskSchedulerManager taskSchedulerManager) : base(memoryCache, nLogManager,taskSchedulerManager)
public _1688Business(IMemoryCache memoryCache, NLogManager nLogManager, RestApiService restApiService) : base(memoryCache, nLogManager)
{
this.restApiService = restApiService;
_1688TradeTypeCompare = new _1688TradeTypeCompare();

12
BBWY.Server.Model/Db/EvaluationAssistant/PromotionTask.cs

@ -45,6 +45,12 @@ namespace BBWY.Server.Model.Db
public string MainProductGiftSku { get; set; }
/// <summary>
/// 赠品模板上架的Sku(开始任务之后有值),逗号间隔,可空
/// </summary>
public string GiftTemplatePutNewSku { get; set; }
/// <summary>
/// 主商品sku,逗号间隔,可空
/// </summary>
@ -114,6 +120,7 @@ namespace BBWY.Server.Model.Db
/// </summary>
public string CustomMotherSku { get; set; }
/// <summary>
/// 任务数量
/// </summary>
@ -128,6 +135,11 @@ namespace BBWY.Server.Model.Db
/// 前置任务Id
/// </summary>
public long? BeforeTaskId { get; set; }
/// <summary>
/// 错误信息
/// </summary>
public string ErrorMsg { get; set; }
}
}

18
BBWY.Server.Model/Dto/Request/PromotionTask/StartPromotionTaskRequest.cs

@ -56,4 +56,22 @@ namespace BBWY.Server.Model.Dto
/// </summary>
public string CustomMotherSku { get; set; }
}
public class StartPromotionTaskDelayRequest : PlatformRequest
{
public string BrandName { get; set; }
public long JDPromotionId { get; set; }
public string MainProductSpu { get; set; }
public string FullTitle { get; set; }
public IList<string> DeleteGiftSkuList { get; set; }
/// <summary>
/// 是否包含赠品模板
/// </summary>
public bool HaveGiftTemplate { get; set; }
}
}

10
BBWY.Server.Model/Dto/Response/PromotionTask/PromotionTaskResponse.cs

@ -113,6 +113,16 @@ namespace BBWY.Server.Model.Dto
/// 已完成任务量
/// </summary>
public int CompletedTaskCount { get; set; }
/// <summary>
/// 前置任务Id
/// </summary>
public long? BeforeTaskId { get; set; }
/// <summary>
/// 错误信息
/// </summary>
public string ErrorMsg { get; set; }
}
public class PromotionTaskResponse

13
BBWY.Server.Model/Dto/Response/PromotionTask/StartPromotionTaskResponse.cs

@ -0,0 +1,13 @@
using System.Collections.Generic;
namespace BBWY.Server.Model.Dto
{
public class StartPromotionTaskResponse
{
public string BrandName { get; set; }
public long JDPromotionId { get; set; }
public IList<string> DeleteGiftSkuList { get; set; }
}
}

7
JD.API/Controllers/PlatformSDKController.cs

@ -283,11 +283,16 @@ namespace JD.API.API.Controllers
/// <param name="request"></param>
/// <returns></returns>
[HttpPost]
public long StartJDPromotionTask([FromBody] StartPromotionTaskRequest2 request)
public StartPromotionTaskResponse StartJDPromotionTask([FromBody] StartPromotionTaskRequest2 request)
{
return platformSDKBusinessList.FirstOrDefault(p => p.Platform == request.Platform).StartJDPromotionTask(request);
}
public void StartJDPromotionDelayTask([FromBody]StartPromotionTaskDelayRequest request)
{
platformSDKBusinessList.FirstOrDefault(p => p.Platform == request.Platform).StartJDPromotionDelayTask(request);
}
/// <summary>
/// 删除京东活动
/// </summary>

Loading…
Cancel
Save