You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
5.2 KiB
111 lines
5.2 KiB
using BBWY.Common.Models;
|
|
using BBWY.Server.Model.Db;
|
|
using BBWY.Server.Model.Dto;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Yitter.IdGenerator;
|
|
|
|
namespace BBWY.Server.Business
|
|
{
|
|
public class BatchPurchaseBusiness : BaseBusiness, IDenpendency
|
|
{
|
|
private ProductBusiness productBusiness;
|
|
public BatchPurchaseBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator, ProductBusiness productBusiness) : base(fsql, nLogManager, idGenerator)
|
|
{
|
|
this.productBusiness = productBusiness;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取包含对应平台采购方案的sku列表
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="BusinessException"></exception>
|
|
public IList<ProductSkuWithSchemeResponse> GetProductSkuAndSchemeList(SearchProductSkuAndSchemeRequest request)
|
|
{
|
|
if (string.IsNullOrEmpty(request.Spu) || string.IsNullOrEmpty(request.Sku))
|
|
throw new BusinessException("至少具备一个Sku或Spu条件");
|
|
|
|
var productSkuList = productBusiness.GetProductSkuList(new SearchProductSkuRequest()
|
|
{
|
|
AppKey = request.AppKey,
|
|
AppSecret = request.AppSecret,
|
|
AppToken = request.AppToken,
|
|
Platform = request.Platform,
|
|
Sku = request.Sku,
|
|
Spu = request.Spu
|
|
});
|
|
if (productSkuList == null || productSkuList.Count() == 0)
|
|
return null;
|
|
|
|
var skuIdList = productSkuList.Select(s => s.Id).ToList();
|
|
var schemeList = fsql.Select<PurchaseScheme, Purchaser>().InnerJoin((ps, p) => ps.PurchaserId == p.Id)
|
|
.Where((ps, p) => ps.ShopId == request.ShopId)
|
|
.Where((ps, p) => skuIdList.Contains(ps.SkuId))
|
|
.ToList((ps, p) => new
|
|
{
|
|
PurchaseSchemeId = ps.Id,
|
|
ps.PurchaserId,
|
|
PurchaseName = p.Name,
|
|
ps.PurchasePlatform,
|
|
ps.SkuId
|
|
});
|
|
var list = new List<ProductSkuWithSchemeResponse>();
|
|
foreach (var productSku in productSkuList)
|
|
{
|
|
var currentSchemeList = schemeList.Where(ps => ps.SkuId == productSku.Id).ToList();
|
|
if (currentSchemeList == null || currentSchemeList.Count() == 0)
|
|
{
|
|
list.Add(new ProductSkuWithSchemeResponse()
|
|
{
|
|
Id = productSku.Id,
|
|
SkuId = productSku.Id,
|
|
ProductId = productSku.ProductId,
|
|
CreateTime = productSku.CreateTime,
|
|
Logo = productSku.Logo,
|
|
Price = productSku.Price,
|
|
Title = productSku.Title,
|
|
State = productSku.State
|
|
});
|
|
}
|
|
else
|
|
{
|
|
foreach (var currentScheme in currentSchemeList)
|
|
{
|
|
list.Add(new ProductSkuWithSchemeResponse()
|
|
{
|
|
Id = $"{productSku.Id}_{currentScheme.PurchaseSchemeId}",
|
|
SkuId = productSku.Id,
|
|
ProductId = productSku.ProductId,
|
|
CreateTime = productSku.CreateTime,
|
|
Logo = productSku.Logo,
|
|
Price = productSku.Price,
|
|
Title = productSku.Title,
|
|
State = productSku.State,
|
|
PurchaseName = currentScheme.PurchaseName,
|
|
PurchasePlatform = currentScheme.PurchasePlatform,
|
|
PurchaserId = currentScheme.PurchaserId,
|
|
PurchaseSchemeId = currentScheme.PurchaseSchemeId
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//var pruductSkuSchemeList = productSkuList.Map<IList<ProductSkuWithSchemeResponse>>();
|
|
//foreach (var ps in pruductSkuSchemeList)
|
|
//{
|
|
// var scheme = schemeList.FirstOrDefault(s => s.SkuId == ps.Id);
|
|
// if (scheme == null)
|
|
// continue;
|
|
// ps.PurchaseSchemeId = scheme.PurchaseSchemeId;
|
|
// ps.PurchaserId = scheme.PurchaserId;
|
|
// ps.PurchaseName = scheme.PurchaseName;
|
|
// ps.PurchasePlatform = scheme.PurchasePlatform;
|
|
//}
|
|
return list;
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|