|
|
@ -1,4 +1,5 @@ |
|
|
|
using BBWY.Common.Models; |
|
|
|
using BBWY.Common.Http; |
|
|
|
using BBWY.Common.Models; |
|
|
|
using BBWY.Server.Model; |
|
|
|
using BBWY.Server.Model.Db; |
|
|
|
using BBWY.Server.Model.Db.QK; |
|
|
@ -9,6 +10,7 @@ using Newtonsoft.Json.Linq; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Net.Http; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Yitter.IdGenerator; |
|
|
@ -19,18 +21,19 @@ namespace BBWY.Server.Business |
|
|
|
{ |
|
|
|
private ProductBusiness productBusiness; |
|
|
|
private IEnumerable<PlatformSDKBusiness> platformSDKBusinessList; |
|
|
|
|
|
|
|
|
|
|
|
//private TaskSchedulerManager taskSchedulerManager;
|
|
|
|
private RestApiService restApiService; |
|
|
|
|
|
|
|
public BatchPurchaseBusiness(IFreeSql fsql, |
|
|
|
NLogManager nLogManager, |
|
|
|
IIdGenerator idGenerator, |
|
|
|
ProductBusiness productBusiness, |
|
|
|
IEnumerable<PlatformSDKBusiness> platformSDKBusinessList) : base(fsql, nLogManager, idGenerator) |
|
|
|
IEnumerable<PlatformSDKBusiness> platformSDKBusinessList, |
|
|
|
RestApiService restApiService) : base(fsql, nLogManager, idGenerator) |
|
|
|
{ |
|
|
|
this.productBusiness = productBusiness; |
|
|
|
this.platformSDKBusinessList = platformSDKBusinessList; |
|
|
|
|
|
|
|
this.restApiService = restApiService; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -218,6 +221,7 @@ namespace BBWY.Server.Business |
|
|
|
|
|
|
|
var successSkuIdList = new List<string>(); |
|
|
|
var failSkuList = new List<BatchCreareOrderFailDetail>(); |
|
|
|
var qikuPackSkuConfigRequestList = new List<object>(); |
|
|
|
|
|
|
|
var extJArray = JsonConvert.DeserializeObject<JArray>(request.Extensions); |
|
|
|
var purchaseGroups = request.ProductParamList.GroupBy(p => p.PurchaserId); |
|
|
@ -279,6 +283,10 @@ namespace BBWY.Server.Business |
|
|
|
List<long> updatePurchaseTimeSchemeIdList = productParamList.Select(p => p.BelongPurchaseSchemeId).Distinct().ToList(); |
|
|
|
List<PurchaseOrderSku> insertPurchaseOrderSkuList = new List<PurchaseOrderSku>(); |
|
|
|
|
|
|
|
List<object> skuPackConfigList = null; |
|
|
|
if (purchasePlatform == Enums.Platform.拳探) |
|
|
|
skuPackConfigList = new List<object>(); |
|
|
|
|
|
|
|
foreach (var belongSkuGroup in belongSkuGroups) |
|
|
|
{ |
|
|
|
var firstProductParam = belongSkuGroup.FirstOrDefault(); |
|
|
@ -308,6 +316,23 @@ namespace BBWY.Server.Business |
|
|
|
CreateTime = DateTime.Now |
|
|
|
}; |
|
|
|
insertPurchaseOrderSkuList.Add(purchaseOrderSku); |
|
|
|
|
|
|
|
if (purchasePlatform == Enums.Platform.拳探) |
|
|
|
{ |
|
|
|
var skuPackConfig = request.PackSkuConfigList.FirstOrDefault(s => s.SkuId == firstProductParam.BelongSkuId); |
|
|
|
skuPackConfigList.Add(new |
|
|
|
{ |
|
|
|
skuId = firstProductParam.BelongSkuId, |
|
|
|
skuCount = skuPackConfig.PurchaseCount, |
|
|
|
markMessage = string.Empty, |
|
|
|
wareHourses = skuPackConfig.PackSkuSplitConfigList.Select(x => new |
|
|
|
{ |
|
|
|
wareId = x.Store.Id, |
|
|
|
wareName = x.Store.Name, |
|
|
|
count = x.PackCount |
|
|
|
}) |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var purchaseOrderV2 = new PurchaseOrderV2() |
|
|
@ -345,6 +370,19 @@ namespace BBWY.Server.Business |
|
|
|
fsql.Update<PurchaseScheme>(updatePurchaseTimeSchemeIdList).Set(p => p.LastPurchaseTime, DateTime.Now).ExecuteAffrows(); |
|
|
|
}); |
|
|
|
successSkuIdList.AddRange(belongSkuGroups.Select(g => g.Key)); |
|
|
|
|
|
|
|
if (purchasePlatform == Enums.Platform.拳探) |
|
|
|
{ |
|
|
|
qikuPackSkuConfigRequestList.Add(new |
|
|
|
{ |
|
|
|
orderId = purchaseOrderV2.Id, |
|
|
|
shopId = request.ShopId.ToString(), |
|
|
|
originShopName = request.ShopName, |
|
|
|
userName = purchaseAccount.AccountName, |
|
|
|
platform = Enums.Platform.拳探, |
|
|
|
purchaseTaskModels = skuPackConfigList |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
@ -357,6 +395,30 @@ namespace BBWY.Server.Business |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (qikuPackSkuConfigRequestList.Count() > 0) |
|
|
|
{ |
|
|
|
Task.Factory.StartNew(() => |
|
|
|
{ |
|
|
|
foreach (var qikuPackSkuConfigRequest in qikuPackSkuConfigRequestList) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
var qikuResponse = restApiService.SendRequest("http://qiku.qiyue666.com/", |
|
|
|
"api/PackPurchaseTask/PublicPurchaseTask", |
|
|
|
qikuPackSkuConfigRequest, |
|
|
|
null, |
|
|
|
HttpMethod.Post); |
|
|
|
if (qikuResponse.StatusCode != System.Net.HttpStatusCode.OK) |
|
|
|
throw new Exception(qikuResponse.Content); |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
nLogManager.GetLogger($"发布打包任务-{request.ShopName}").Error(ex, JsonConvert.SerializeObject(qikuPackSkuConfigRequest)); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
return new BatchCreareOrderResponse() |
|
|
|
{ |
|
|
|
FailSkuList = failSkuList, |
|
|
|