|
|
@ -225,6 +225,14 @@ namespace BBWYB.Server.Business |
|
|
|
throw new BusinessException("更新方案缺少ProductId/SkuId"); |
|
|
|
} |
|
|
|
|
|
|
|
if (batchCURDSchemeRequest.EditPurchaseSchemeList.Any(ps => ps.PurchaseSchemeProductList == null || |
|
|
|
ps.PurchaseSchemeProductList.Count() == 0 || |
|
|
|
ps.PurchaseSchemeProductList.Any(psp => psp.PurchaseSchemeProductSkuList == null || |
|
|
|
psp.PurchaseSchemeProductSkuList.Count() == 0))) |
|
|
|
{ |
|
|
|
throw new BusinessException("更新方案缺少商品信息"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (batchCURDSchemeRequest.EditPurchaseSchemeList.Any(ps => ps.PurchaseSchemeProductList.Any(pp => string.IsNullOrEmpty(pp.PurchaserId) || |
|
|
|
string.IsNullOrEmpty(pp.PurchaserId2) || |
|
|
@ -250,6 +258,15 @@ namespace BBWYB.Server.Business |
|
|
|
throw new BusinessException("新增方案缺少ProductId/SkuId"); |
|
|
|
} |
|
|
|
|
|
|
|
if (batchCURDSchemeRequest.AddPurchaseSchemeList.Any(ps => ps.PurchaseSchemeProductList == null || |
|
|
|
ps.PurchaseSchemeProductList.Count() == 0 || |
|
|
|
ps.PurchaseSchemeProductList.Any(psp => psp.PurchaseSchemeProductSkuList == null || |
|
|
|
psp.PurchaseSchemeProductSkuList.Count() == 0))) |
|
|
|
{ |
|
|
|
throw new BusinessException("新增方案缺少商品信息"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (batchCURDSchemeRequest.AddPurchaseSchemeList.Any(ps => ps.PurchaseSchemeProductList.Any(pp => string.IsNullOrEmpty(pp.PurchaserId) || |
|
|
|
string.IsNullOrEmpty(pp.PurchaserId2) || |
|
|
|
string.IsNullOrEmpty(pp.PurchaserName)))) |
|
|
@ -870,16 +887,27 @@ namespace BBWYB.Server.Business |
|
|
|
long? pssId = null; |
|
|
|
foreach (var schemeProduct in scheme.PurchaseSchemeProductList) |
|
|
|
{ |
|
|
|
foreach (var schemeProductSku in schemeProduct.PurchaseSchemeProductSkuList) |
|
|
|
{ |
|
|
|
if (schemeProductSku.SkuId == request.SkuId && |
|
|
|
schemeProductSku.PurchaseSkuId == request.PurchaseSkuId) |
|
|
|
var tartegtPurchaseProductSku = schemeProduct.PurchaseSchemeProductSkuList.FirstOrDefault(pss => pss.SkuId == request.SkuId && |
|
|
|
pss.PurchaseSkuId == request.PurchaseSkuId); |
|
|
|
|
|
|
|
if (tartegtPurchaseProductSku != null) |
|
|
|
{ |
|
|
|
schemeProductSku.PurchaseRatio = request.Ratio; |
|
|
|
pssId = schemeProductSku.Id; |
|
|
|
} |
|
|
|
defaultCost += ((schemeProductSku.ActualPrice ?? schemeProductSku.PurchaseSkuPrice) ?? 0) * (schemeProductSku.PurchaseRatio ?? 1); |
|
|
|
tartegtPurchaseProductSku.PurchaseRatio = request.Ratio; |
|
|
|
pssId = tartegtPurchaseProductSku.Id; |
|
|
|
} |
|
|
|
|
|
|
|
defaultCost += schemeProduct.PurchaseSchemeProductSkuList.Sum(pss => ((pss.ActualPrice ?? pss.PurchaseSkuPrice) ?? 0) * (pss.PurchaseRatio ?? 1)); |
|
|
|
|
|
|
|
//foreach (var schemeProductSku in schemeProduct.PurchaseSchemeProductSkuList)
|
|
|
|
//{
|
|
|
|
// if (schemeProductSku.SkuId == request.SkuId &&
|
|
|
|
// schemeProductSku.PurchaseSkuId == request.PurchaseSkuId)
|
|
|
|
// {
|
|
|
|
// schemeProductSku.PurchaseRatio = request.Ratio;
|
|
|
|
// pssId = schemeProductSku.Id;
|
|
|
|
// }
|
|
|
|
// defaultCost += ((schemeProductSku.ActualPrice ?? schemeProductSku.PurchaseSkuPrice) ?? 0) * (schemeProductSku.PurchaseRatio ?? 1);
|
|
|
|
//}
|
|
|
|
} |
|
|
|
if (pssId == null) |
|
|
|
throw new BusinessException("未找到需要更新的采购配件"); |
|
|
@ -890,5 +918,44 @@ namespace BBWYB.Server.Business |
|
|
|
}); |
|
|
|
return defaultCost; |
|
|
|
} |
|
|
|
|
|
|
|
public decimal DeletePurchaseSku(DeletePurchaseSkuRequest request) |
|
|
|
{ |
|
|
|
if (request.SchemeId == 0 || string.IsNullOrEmpty(request.SkuId) || string.IsNullOrEmpty(request.PurchaseSkuId)) |
|
|
|
throw new BusinessException("参数不完整"); |
|
|
|
var schemeList = GetPurchaseSchemeList(new QuerySchemeRequest() |
|
|
|
{ |
|
|
|
IncludePurchaseSkuBasicInfo = 1, |
|
|
|
SchemeId = request.SchemeId |
|
|
|
}); |
|
|
|
if (schemeList.Count() == 0) |
|
|
|
throw new BusinessException("采购方案不存在"); |
|
|
|
var scheme = schemeList[0]; |
|
|
|
var defaultCost = 0M; |
|
|
|
long? pssId = null; |
|
|
|
foreach (var schemeProduct in scheme.PurchaseSchemeProductList) |
|
|
|
{ |
|
|
|
var tartegtPurchaseProductSku = schemeProduct.PurchaseSchemeProductSkuList.FirstOrDefault(pss => pss.SkuId == request.SkuId && |
|
|
|
pss.PurchaseSkuId == request.PurchaseSkuId); |
|
|
|
if (tartegtPurchaseProductSku != null) |
|
|
|
{ |
|
|
|
if (schemeProduct.PurchaseSchemeProductSkuList.Count() == 1) |
|
|
|
throw new BusinessException("最后一个采购sku不能被移除"); |
|
|
|
pssId = tartegtPurchaseProductSku.Id; |
|
|
|
} |
|
|
|
|
|
|
|
defaultCost += schemeProduct.PurchaseSchemeProductSkuList.Where(pss => !(pss.SkuId == request.SkuId && pss.PurchaseSkuId == request.PurchaseSkuId)) |
|
|
|
.Sum(pss => ((pss.ActualPrice ?? pss.PurchaseSkuPrice) ?? 0) * (pss.PurchaseRatio ?? 1)); |
|
|
|
} |
|
|
|
|
|
|
|
if (pssId == null) |
|
|
|
throw new BusinessException("未找到需要移除的采购sku"); |
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
fsql.Update<PurchaseScheme>(request.SchemeId).Set(ps => ps.DefaultCost, defaultCost).ExecuteAffrows(); |
|
|
|
fsql.Delete<PurchaseSchemeProductSku>(pssId.Value).ExecuteAffrows(); |
|
|
|
}); |
|
|
|
return defaultCost; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|