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.
84 lines
3.1 KiB
84 lines
3.1 KiB
using BBWYB.Common.Log;
|
|
using BBWYB.Common.Models;
|
|
using BBWYB.Server.Model;
|
|
using BBWYB.Server.Model.Dto;
|
|
using SDKAdapter.OperationPlatform.Client;
|
|
using SDKAdapter.OperationPlatform.Models;
|
|
using Yitter.IdGenerator;
|
|
|
|
namespace BBWYB.Server.Business
|
|
{
|
|
public class ProductBusiness : BaseBusiness, IDenpendency
|
|
{
|
|
private OP_PlatformClientFactory opPlatformClientFactory;
|
|
|
|
public ProductBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator, OP_PlatformClientFactory opPlatformClientFactory) : base(fsql, nLogManager, idGenerator)
|
|
{
|
|
this.opPlatformClientFactory = opPlatformClientFactory;
|
|
}
|
|
|
|
public OP_ProductListResponse GetProductList(OP_QueryProductRequest request)
|
|
{
|
|
return opPlatformClientFactory.GetClient(request.Platform).GetProductList(request);
|
|
}
|
|
|
|
public OP_ProductSkuListResponse GetProductSkuList(OP_QueryProductSkuRequest request)
|
|
{
|
|
return opPlatformClientFactory.GetClient(request.Platform).GetProductSkuList(request);
|
|
}
|
|
|
|
public decimal? GetProductSkuPrice(QueryProductSkuPriceRequest request)
|
|
{
|
|
var response = GetProductSkuList(new OP_QueryProductSkuRequest()
|
|
{
|
|
AppSecret = request.AppSecret,
|
|
AppKey = request.AppKey,
|
|
AppToken = request.AppToken,
|
|
PageIndex = 1,
|
|
PageSize = 1,
|
|
Platform = (SDKAdapter.AdapterEnums.PlatformType)request.Platform,
|
|
Sku = request.Sku
|
|
});
|
|
return response.Items?.FirstOrDefault()?.Price;
|
|
}
|
|
|
|
public void EditProductPrice(OP_EditProductPriceRequest request)
|
|
{
|
|
var skuRequest = new OP_QueryProductSkuRequest()
|
|
{
|
|
AppKey = request.AppKey,
|
|
AppSecret = request.AppSecret,
|
|
AppToken = request.AppToken,
|
|
PageIndex = 1,
|
|
PageSize = 50,
|
|
Platform = request.Platform,
|
|
Spu = request.Spu
|
|
};
|
|
var editSkuList = new List<OP_EditProductSkuPriceRequest>();
|
|
while (true)
|
|
{
|
|
var response = GetProductSkuList(skuRequest);
|
|
if (response.Items.Count > 0)
|
|
{
|
|
editSkuList.AddRange(response.Items.Select(sku => new OP_EditProductSkuPriceRequest()
|
|
{
|
|
Sku = sku.Id,
|
|
Price = sku.Price,
|
|
}));
|
|
}
|
|
if (response.Items.Count < 50)
|
|
break;
|
|
skuRequest.PageIndex++;
|
|
}
|
|
foreach (var editReq in request.EditSkuList)
|
|
{
|
|
var editSku = editSkuList.FirstOrDefault(x => x.Sku == editReq.Sku);
|
|
if (editSku != null)
|
|
editSku.Price = editReq.Price;
|
|
}
|
|
request.EditSkuList.Clear();
|
|
request.EditSkuList.AddRange(editSkuList);
|
|
opPlatformClientFactory.GetClient(request.Platform).EditProductPrice(request);
|
|
}
|
|
}
|
|
}
|
|
|