Browse Source

在线采购更新采购方案和采购商

yijia
shanji 2 years ago
parent
commit
b472a0877f
  1. 30
      BBWYB.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs
  2. 8
      BBWYB.Server.Business/PurchaseScheme/PurchaseSchemeBusiness.cs
  3. 12
      BBWYB.Server.Model/Dto/Response/PurchaseScheme/PurchaseSchemeProductResponse.cs

30
BBWYB.Server.Business/PurchaseOrder/PurchaseOrderBusiness.cs

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

8
BBWYB.Server.Business/PurchaseScheme/PurchaseSchemeBusiness.cs

@ -663,7 +663,9 @@ namespace BBWYB.Server.Business
PurchaserLocation = p.Location,
PurchaserName = p.Name,
PurchasePlatform = p.Platform,
PurchaserMemberId = p.MemberId
PurchaserMemberId = p.MemberId,
PurchaserPurchasedCount = p.PurchasedCount,
PurchaserPurchasedSkuCount = p.PurchasedSkuCount,
});
var purchaseSchemeProductSkuList = fsql.Select<PurchaseSchemeProductSku>().Where(p => purchaseSchemeIdList.Contains(p.SkuPurchaseSchemeId))
@ -696,7 +698,9 @@ namespace BBWYB.Server.Business
Location = schemeProduct.PurchaserLocation,
Name = schemeProduct.PurchaserName,
Platform = schemeProduct.PurchasePlatform,
MemberId = schemeProduct.PurchaserMemberId
MemberId = schemeProduct.PurchaserMemberId,
PurchasedCount = schemeProduct.PurchaserPurchasedCount,
PurchasedSkuCount = schemeProduct.PurchaserPurchasedSkuCount
});
}
}

12
BBWYB.Server.Model/Dto/Response/PurchaseScheme/PurchaseSchemeProductResponse.cs

@ -2,6 +2,7 @@
{
public class PurchaseSchemeProductResponse : Model.Db.PurchaseSchemeProduct
{
#region 采购商信息
public string PurchaserName { get; set; }
public string PurchaserId2 { get; set; }
@ -12,6 +13,17 @@
public string PurchaserMemberId { get; set; }
/// <summary>
/// 采购商的采购次数
/// </summary>
public int? PurchaserPurchasedCount { get; set; }
/// <summary>
/// 采购商的采购SKU数
/// </summary>
public int? PurchaserPurchasedSkuCount { get; set; }
#endregion
/// <summary>
/// 采购商品标题 仅在查询条件IncludePurchaseSkuBasicInfo=1时具备该值
/// </summary>

Loading…
Cancel
Save