|
@ -1,10 +1,15 @@ |
|
|
using BBWYB.Common.Extensions; |
|
|
using BBWYB.Common.Extensions; |
|
|
|
|
|
using BBWYB.Common.Http; |
|
|
using BBWYB.Common.Log; |
|
|
using BBWYB.Common.Log; |
|
|
using BBWYB.Common.Models; |
|
|
using BBWYB.Common.Models; |
|
|
using BBWYB.Server.Model; |
|
|
using BBWYB.Server.Model; |
|
|
using BBWYB.Server.Model.Db; |
|
|
using BBWYB.Server.Model.Db; |
|
|
using BBWYB.Server.Model.Dto; |
|
|
using BBWYB.Server.Model.Dto; |
|
|
using FreeSql; |
|
|
using FreeSql; |
|
|
|
|
|
using MySqlX.XDevAPI; |
|
|
|
|
|
using Newtonsoft.Json; |
|
|
|
|
|
using Org.BouncyCastle.Asn1.X509.Qualified; |
|
|
|
|
|
using System.Net.Http.Headers; |
|
|
using Yitter.IdGenerator; |
|
|
using Yitter.IdGenerator; |
|
|
|
|
|
|
|
|
namespace BBWYB.Server.Business |
|
|
namespace BBWYB.Server.Business |
|
@ -12,10 +17,16 @@ namespace BBWYB.Server.Business |
|
|
public class PurchaseSchemeBusiness : BaseBusiness, IDenpendency |
|
|
public class PurchaseSchemeBusiness : BaseBusiness, IDenpendency |
|
|
{ |
|
|
{ |
|
|
private PurchaseProductAPIService purchaseProductAPIService; |
|
|
private PurchaseProductAPIService purchaseProductAPIService; |
|
|
|
|
|
private RestApiService restApiService; |
|
|
|
|
|
|
|
|
public PurchaseSchemeBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator, PurchaseProductAPIService purchaseProductAPIService) : base(fsql, nLogManager, idGenerator) |
|
|
public PurchaseSchemeBusiness(IFreeSql fsql, |
|
|
|
|
|
NLogManager nLogManager, |
|
|
|
|
|
IIdGenerator idGenerator, |
|
|
|
|
|
PurchaseProductAPIService purchaseProductAPIService, |
|
|
|
|
|
RestApiService restApiService) : base(fsql, nLogManager, idGenerator) |
|
|
{ |
|
|
{ |
|
|
this.purchaseProductAPIService = purchaseProductAPIService; |
|
|
this.purchaseProductAPIService = purchaseProductAPIService; |
|
|
|
|
|
this.restApiService = restApiService; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void ExtractNewPurchaser<T>(IList<T> purchaserSchemeList, IList<Purchaser> addPurchaserList) where T : InputPurchaseSchemeRequest |
|
|
private void ExtractNewPurchaser<T>(IList<T> purchaserSchemeList, IList<Purchaser> addPurchaserList) where T : InputPurchaseSchemeRequest |
|
@ -204,6 +215,16 @@ namespace BBWYB.Server.Business |
|
|
|
|
|
|
|
|
if (batchCURDSchemeRequest.EditPurchaseSchemeList != null && batchCURDSchemeRequest.EditPurchaseSchemeList.Count() > 0) |
|
|
if (batchCURDSchemeRequest.EditPurchaseSchemeList != null && batchCURDSchemeRequest.EditPurchaseSchemeList.Count() > 0) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (batchCURDSchemeRequest.EditPurchaseSchemeList.Any(ps => string.IsNullOrEmpty(ps.ProductId) || |
|
|
|
|
|
string.IsNullOrEmpty(ps.SkuId) || |
|
|
|
|
|
ps.PurchaseSchemeProductList.Any(psp => string.IsNullOrEmpty(psp.ProductId) || |
|
|
|
|
|
string.IsNullOrEmpty(psp.SkuId) || |
|
|
|
|
|
psp.PurchaseSchemeProductSkuList.Any(pss => string.IsNullOrEmpty(pss.ProductId) || |
|
|
|
|
|
string.IsNullOrEmpty(pss.SkuId))))) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new BusinessException("更新方案缺少ProductId/SkuId"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (batchCURDSchemeRequest.EditPurchaseSchemeList.Any(ps => ps.PurchaseSchemeProductList.Any(pp => string.IsNullOrEmpty(pp.PurchaserId) || |
|
|
if (batchCURDSchemeRequest.EditPurchaseSchemeList.Any(ps => ps.PurchaseSchemeProductList.Any(pp => string.IsNullOrEmpty(pp.PurchaserId) || |
|
|
string.IsNullOrEmpty(pp.PurchaserName)))) |
|
|
string.IsNullOrEmpty(pp.PurchaserName)))) |
|
|
throw new BusinessException("更新方案中有采购商Id/Name/Location为空"); |
|
|
throw new BusinessException("更新方案中有采购商Id/Name/Location为空"); |
|
@ -217,6 +238,16 @@ namespace BBWYB.Server.Business |
|
|
|
|
|
|
|
|
if (batchCURDSchemeRequest.AddPurchaseSchemeList != null && batchCURDSchemeRequest.AddPurchaseSchemeList.Count() > 0) |
|
|
if (batchCURDSchemeRequest.AddPurchaseSchemeList != null && batchCURDSchemeRequest.AddPurchaseSchemeList.Count() > 0) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (batchCURDSchemeRequest.AddPurchaseSchemeList.Any(ps => string.IsNullOrEmpty(ps.ProductId) || |
|
|
|
|
|
string.IsNullOrEmpty(ps.SkuId) || |
|
|
|
|
|
ps.PurchaseSchemeProductList.Any(psp => string.IsNullOrEmpty(psp.ProductId) || |
|
|
|
|
|
string.IsNullOrEmpty(psp.SkuId) || |
|
|
|
|
|
psp.PurchaseSchemeProductSkuList.Any(pss => string.IsNullOrEmpty(pss.ProductId) || |
|
|
|
|
|
string.IsNullOrEmpty(pss.SkuId))))) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new BusinessException("新增方案缺少ProductId/SkuId"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (batchCURDSchemeRequest.AddPurchaseSchemeList.Any(ps => ps.PurchaseSchemeProductList.Any(pp => string.IsNullOrEmpty(pp.PurchaserId) || |
|
|
if (batchCURDSchemeRequest.AddPurchaseSchemeList.Any(ps => ps.PurchaseSchemeProductList.Any(pp => string.IsNullOrEmpty(pp.PurchaserId) || |
|
|
string.IsNullOrEmpty(pp.PurchaserName)))) |
|
|
string.IsNullOrEmpty(pp.PurchaserName)))) |
|
|
throw new BusinessException("新增方案中有采购商Id/Name/Location为空"); |
|
|
throw new BusinessException("新增方案中有采购商Id/Name/Location为空"); |
|
@ -237,6 +268,11 @@ namespace BBWYB.Server.Business |
|
|
var dbPurchaseSchemeList_sameGroup = dbPurchaseSchemeList.Where(ps => ps.SchemeGroupId == addPurchaseScheme.SchemeGroupId).ToList(); |
|
|
var dbPurchaseSchemeList_sameGroup = dbPurchaseSchemeList.Where(ps => ps.SchemeGroupId == addPurchaseScheme.SchemeGroupId).ToList(); |
|
|
if (dbPurchaseSchemeList_sameGroup.Any(ps => ps.SkuId == addPurchaseScheme.SkuId)) |
|
|
if (dbPurchaseSchemeList_sameGroup.Any(ps => ps.SkuId == addPurchaseScheme.SkuId)) |
|
|
throw new BusinessException($"采购方案分组中Sku不允许重复,{dbSchemeGroup.GroupName}已存在{addPurchaseScheme.SkuId}的采购方案"); |
|
|
throw new BusinessException($"采购方案分组中Sku不允许重复,{dbSchemeGroup.GroupName}已存在{addPurchaseScheme.SkuId}的采购方案"); |
|
|
|
|
|
if (!string.IsNullOrEmpty(addPurchaseScheme.HYSchemeId)) |
|
|
|
|
|
{ |
|
|
|
|
|
if (dbPurchaseSchemeList.Any(ps => ps.HYSchemeId == addPurchaseScheme.HYSchemeId)) |
|
|
|
|
|
throw new BusinessException($"慧眼方案Id{addPurchaseScheme.HYSchemeId}已被其他采购方案使用"); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -419,7 +455,7 @@ namespace BBWYB.Server.Business |
|
|
.WhereIf(!string.IsNullOrEmpty(request.PurchaserId), (psp, p) => psp.PurchaserId == request.PurchaserId) |
|
|
.WhereIf(!string.IsNullOrEmpty(request.PurchaserId), (psp, p) => psp.PurchaserId == request.PurchaserId) |
|
|
.Where((psp, p) => psp.SkuPurchaseSchemeId == ps.Id).Any()); |
|
|
.Where((psp, p) => psp.SkuPurchaseSchemeId == ps.Id).Any()); |
|
|
} |
|
|
} |
|
|
var sql = select.ToSql(); |
|
|
//var sql = select.ToSql();
|
|
|
var purchaseSchemeList = select.OrderByDescending(ps => ps.CreateTime).ToList<PurchaseSchemeResponse>(); |
|
|
var purchaseSchemeList = select.OrderByDescending(ps => ps.CreateTime).ToList<PurchaseSchemeResponse>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -499,6 +535,9 @@ namespace BBWYB.Server.Business |
|
|
}); |
|
|
}); |
|
|
if (basicInfo != null) |
|
|
if (basicInfo != null) |
|
|
{ |
|
|
{ |
|
|
|
|
|
schemeProduct.PurchaseProductLogo = basicInfo.ProductLogo; |
|
|
|
|
|
schemeProduct.PurchaseProductName = basicInfo.ProductName; |
|
|
|
|
|
|
|
|
foreach (var schemeProductSku in schemeProduct.PurchaseSchemeProductSkuList) |
|
|
foreach (var schemeProductSku in schemeProduct.PurchaseSchemeProductSkuList) |
|
|
{ |
|
|
{ |
|
|
var basicSku = basicInfo.ItemList.FirstOrDefault(x => x.PurchaseSkuId == schemeProductSku.PurchaseSkuId); |
|
|
var basicSku = basicInfo.ItemList.FirstOrDefault(x => x.PurchaseSkuId == schemeProductSku.PurchaseSkuId); |
|
@ -688,5 +727,115 @@ namespace BBWYB.Server.Business |
|
|
} |
|
|
} |
|
|
return list; |
|
|
return list; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据慧眼标的Id获取采购方案(含全部配件基本信息)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <exception cref="BusinessException"></exception>
|
|
|
|
|
|
public IList<HYPurchaseSchemeResponse> GetPurchaseSchemeByHYBDId(QueryHYSchemeRequest request) |
|
|
|
|
|
{ |
|
|
|
|
|
if (request.ShopId == 0) |
|
|
|
|
|
throw new BusinessException("缺少店铺Id"); |
|
|
|
|
|
if (string.IsNullOrEmpty(request.ProductId)) |
|
|
|
|
|
throw new BusinessException("缺少商品Id"); |
|
|
|
|
|
if (string.IsNullOrEmpty(request.HYBDId)) |
|
|
|
|
|
throw new BusinessException("缺少标的Id"); |
|
|
|
|
|
|
|
|
|
|
|
var hyHttpResult = restApiService.SendRequest("http://hyapi.qiyue666.com", "/HuiYan/ItemPlan/GetPlanByOrderId", $"orderId={request.HYBDId}", null, HttpMethod.Get); |
|
|
|
|
|
if (hyHttpResult.StatusCode != System.Net.HttpStatusCode.OK) |
|
|
|
|
|
throw new BusinessException(hyHttpResult.Content); |
|
|
|
|
|
var hyResponse = JsonConvert.DeserializeObject<ApiResponse<IList<HYPurchaseScheme>>>(hyHttpResult.Content); |
|
|
|
|
|
if (!hyResponse.Success) |
|
|
|
|
|
throw new BusinessException(hyResponse.Msg); |
|
|
|
|
|
if (hyResponse.Data == null || hyResponse.Data.Count() == 0) |
|
|
|
|
|
throw new BusinessException("该标的Id缺少采购方案"); |
|
|
|
|
|
var hySchemeList = hyResponse.Data; |
|
|
|
|
|
var hySchemeIdList = hySchemeList.Select(x => x.Id.ToString()).ToList(); |
|
|
|
|
|
var dbSchemeList = fsql.Select<PurchaseScheme>().Where(ps => ps.ProductId == request.ProductId && |
|
|
|
|
|
!string.IsNullOrEmpty(ps.HYSchemeId) && |
|
|
|
|
|
hySchemeIdList.Contains(ps.HYSchemeId)).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
var resultList = new List<HYPurchaseSchemeResponse>(); |
|
|
|
|
|
foreach (var hyScheme in hySchemeList) |
|
|
|
|
|
{ |
|
|
|
|
|
if (hyScheme.PlanItems == null || hyScheme.PlanItems.Count() == 0) |
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
var hySchemeResponse = new HYPurchaseSchemeResponse() |
|
|
|
|
|
{ |
|
|
|
|
|
Id = 0, |
|
|
|
|
|
CreateTime = DateTime.Now, |
|
|
|
|
|
HYBDId = request.HYBDId, |
|
|
|
|
|
IsAdded = dbSchemeList.Any(ps => ps.HYBDId == request.HYBDId && ps.HYSchemeId == hyScheme.Id.ToString()), |
|
|
|
|
|
HYSchemeId = hyScheme.Id.ToString(), |
|
|
|
|
|
ProductId = request.ProductId, |
|
|
|
|
|
ShopId = request.ShopId |
|
|
|
|
|
}; |
|
|
|
|
|
resultList.Add(hySchemeResponse); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var hySchemeProduct in hyScheme.PlanItems) |
|
|
|
|
|
{ |
|
|
|
|
|
var basicInfo = GetPurchaseSkuBasicInfo(new PurchaseSkuBasicInfoRequest() |
|
|
|
|
|
{ |
|
|
|
|
|
FirstApiMode = Enums.PurchaseProductAPIMode.Spider, |
|
|
|
|
|
PriceMode = Enums.PurchaseOrderMode.批发, |
|
|
|
|
|
Platform = Enums.Platform.阿里巴巴, |
|
|
|
|
|
PurchaseProductId = hySchemeProduct.ItemId |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var hySchemeProductResponse = new PurchaseSchemeProductResponse() |
|
|
|
|
|
{ |
|
|
|
|
|
Id = 0, |
|
|
|
|
|
ProductId = request.ProductId, |
|
|
|
|
|
PurchasePlatform = Enums.Platform.阿里巴巴, |
|
|
|
|
|
PurchaseProductId = hySchemeProduct.ItemId, |
|
|
|
|
|
PurchaseProductLogo = basicInfo.ProductLogo, |
|
|
|
|
|
PurchaseProductName = basicInfo.ProductName, |
|
|
|
|
|
PurchaserId = basicInfo.Purchaser?.Id, |
|
|
|
|
|
PurchaserId2 = basicInfo.Purchaser?.Id2, |
|
|
|
|
|
PurchaserMemberId = basicInfo.Purchaser?.MemberId, |
|
|
|
|
|
PurchaserLocation = basicInfo.Purchaser?.Location, |
|
|
|
|
|
PurchaserName = basicInfo.Purchaser?.Name, |
|
|
|
|
|
PurchaseUrl = $"https://detail.1688.com/offer/{hySchemeProduct.ItemId}.html" |
|
|
|
|
|
}; |
|
|
|
|
|
hySchemeResponse.PurchaseSchemeProductList.Add(hySchemeProductResponse); |
|
|
|
|
|
|
|
|
|
|
|
if (!hySchemeResponse.PurchaserList.Any(p => p.Id == hySchemeProductResponse.PurchaserId)) |
|
|
|
|
|
{ |
|
|
|
|
|
hySchemeResponse.PurchaserList.Add(new Purchaser() |
|
|
|
|
|
{ |
|
|
|
|
|
Id = hySchemeProductResponse.PurchaserId, |
|
|
|
|
|
Id2 = hySchemeProductResponse.PurchaserId2, |
|
|
|
|
|
Location = hySchemeProductResponse.PurchaserLocation, |
|
|
|
|
|
Name = hySchemeProductResponse.PurchaserName, |
|
|
|
|
|
Platform = hySchemeProductResponse.PurchasePlatform, |
|
|
|
|
|
MemberId = hySchemeProductResponse.PurchaserMemberId |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
foreach (var skuBasicInfo in basicInfo.ItemList) |
|
|
|
|
|
{ |
|
|
|
|
|
var hySchemeProductSkuResponse = new PurchaseSchemeProductSkuResponse() |
|
|
|
|
|
{ |
|
|
|
|
|
Id = 0, |
|
|
|
|
|
ActualPrice = skuBasicInfo.Price, |
|
|
|
|
|
ProductId = request.ProductId, |
|
|
|
|
|
PurchaseProductId = skuBasicInfo.PurchaseProductId, |
|
|
|
|
|
PurchaseRatio = 1, |
|
|
|
|
|
PurchaseSkuId = skuBasicInfo.PurchaseSkuId, |
|
|
|
|
|
PurchaseSkuLogo = skuBasicInfo.Logo, |
|
|
|
|
|
PurchaseSkuPrice = skuBasicInfo.Price, |
|
|
|
|
|
PurchaseSkuSpecId = skuBasicInfo.PurchaseSkuSpecId, |
|
|
|
|
|
PurchaseSkuTitle = skuBasicInfo.Title |
|
|
|
|
|
}; |
|
|
|
|
|
hySchemeProductResponse.PurchaseSchemeProductSkuList.Add(hySchemeProductSkuResponse); |
|
|
|
|
|
hySchemeResponse.DefaultCost += skuBasicInfo.Price; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return resultList; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|