|
|
@ -264,8 +264,12 @@ namespace BBWYB.Server.Business |
|
|
|
throw new BusinessException("缺少收货人信息"); |
|
|
|
if (request.PurchaseAccountList == null || request.PurchaseAccountList.Count() == 0) |
|
|
|
throw new BusinessException("缺少采购账号"); |
|
|
|
if (request.CargoParamGroupList == null || request.CargoParamGroupList.Count() == 0 || request.CargoParamGroupList.Any(g => string.IsNullOrEmpty(g.PurchaserId))) |
|
|
|
if (request.CargoParamGroupList == null || request.CargoParamGroupList.Count() == 0) |
|
|
|
throw new BusinessException("缺少下单商品参数"); |
|
|
|
if (request.CargoParamGroupList.Any(g => string.IsNullOrEmpty(g.PurchaserId))) |
|
|
|
throw new BusinessException("缺少采购商Id"); |
|
|
|
if (request.CargoParamGroupList.GroupBy(c => c.PurchaserId).Any(g => g.Count() > 1)) |
|
|
|
throw new BusinessException("提交采购商包含重复"); |
|
|
|
|
|
|
|
#region 验证同一个批次中,一个订单sku不能同时拥有多个采购方案
|
|
|
|
IDictionary<string, long> schemeValidationDictionary = new Dictionary<string, long>(); |
|
|
@ -501,7 +505,7 @@ namespace BBWYB.Server.Business |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
|
|
|
|
#region 更新采购方案最近采购价格
|
|
|
|
#region 更新采购方案
|
|
|
|
{ |
|
|
|
var allCargoParamList = new List<CargoParamRequest>(); |
|
|
|
|
|
|
@ -518,7 +522,7 @@ namespace BBWYB.Server.Business |
|
|
|
.Select(x => x.Price * (cargoParam.PurchaseRatio ?? 1)) |
|
|
|
.DefaultIfEmpty(0M) |
|
|
|
.First()); |
|
|
|
var purchasedAmount = insertOrderCostDetails.FirstOrDefault(ocd => ocd.SkuId == skuId)?.SkuAmount ?? 0M; |
|
|
|
var purchasedAmount = insertOrderCostDetails.Where(ocd => ocd.SkuId == skuId).Sum(ocd => ocd.SkuAmount); |
|
|
|
var update = fsql.Update<PurchaseScheme>(schemeId).Set(ps => ps.LastPurchaseTime, DateTime.Now) |
|
|
|
.Set(ps => ps.LastPurchasePriceCost, lastPurchasePriceCost) |
|
|
|
.Set(ps => ps.PurchasedCount + 1) |
|
|
@ -528,7 +532,7 @@ namespace BBWYB.Server.Business |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 更新采购商采购次数和sku数
|
|
|
|
#region 更新采购商
|
|
|
|
{ |
|
|
|
var purchaserIdList = new List<string>(); |
|
|
|
var purchaserSkuDictionary = new Dictionary<string, List<string>>(); |
|
|
@ -540,7 +544,7 @@ namespace BBWYB.Server.Business |
|
|
|
|
|
|
|
//采购商的sku采购关系表
|
|
|
|
var dbSkuAndPurchaserRelationList = fsql.Select<SkuHistoryPurchaserRelation>() |
|
|
|
.Where(spr => purchaserIdList.Contains(spr.PurchaserId)) |
|
|
|
.Where(spr => purchaserIdList.Contains(spr.PurchaserId) && spr.ShopId == request.ShopId) |
|
|
|
.ToList(); |
|
|
|
|
|
|
|
foreach (var purchaserId in purchaserIdList) |
|
|
@ -551,10 +555,22 @@ namespace BBWYB.Server.Business |
|
|
|
.Distinct() |
|
|
|
.ToList(); |
|
|
|
var exceptSkuList = fromRequestSkuList.Except(fromDBSkuList); |
|
|
|
if (exceptSkuList.Count() > 0) |
|
|
|
var newSkuRelationCount = exceptSkuList.Count(); |
|
|
|
if (newSkuRelationCount > 0) |
|
|
|
{ |
|
|
|
//insertSkuHistoryPurchaserRelationList.AddRange();
|
|
|
|
insertSkuHistoryPurchaserRelationList.AddRange(exceptSkuList.Select(x => new SkuHistoryPurchaserRelation() |
|
|
|
{ |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
CreateTime = DateTime.Now, |
|
|
|
PurchaserId = purchaserId, |
|
|
|
ShopId = request.ShopId, |
|
|
|
SkuId = x |
|
|
|
})); |
|
|
|
} |
|
|
|
var update = fsql.Update<Purchaser>(purchaserId) |
|
|
|
.Set(p => p.PurchasedCount + 1) |
|
|
|
.SetIf(newSkuRelationCount > 0, p => p.PurchasedSkuCount + newSkuRelationCount); |
|
|
|
updatePurchaserList.Add(update); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|