|
|
@ -312,28 +312,49 @@ namespace BBWYB.Server.Business.Sync |
|
|
|
List<IUpdate<ProductSku>> updateProductSkuList = new List<IUpdate<ProductSku>>(); |
|
|
|
|
|
|
|
#region 查询变化的spu
|
|
|
|
var spuRequest = new OP_QueryProductRequest() |
|
|
|
{ |
|
|
|
PageSize = 50, |
|
|
|
PageIndex = 1, |
|
|
|
AppKey = shop.AppKey, |
|
|
|
AppSecret = shop.AppSecret, |
|
|
|
AppToken = shop.AppToken, |
|
|
|
Platform = SDKAdapter.AdapterEnums.PlatformType.拳探, |
|
|
|
UpdateStartTime = DateTime.Now.AddHours(-1), |
|
|
|
UpdateEndTime = DateTime.Now |
|
|
|
}; |
|
|
|
while (true) |
|
|
|
{ |
|
|
|
var response = productBusiness.GetProductList(spuRequest); |
|
|
|
if (response == null || response.Items == null || response.Items.Count == 0) |
|
|
|
break; |
|
|
|
#region 上架的spu
|
|
|
|
var spuRequest = new OP_QueryProductRequest() |
|
|
|
{ |
|
|
|
PageSize = 50, |
|
|
|
PageIndex = 1, |
|
|
|
AppKey = shop.AppKey, |
|
|
|
AppSecret = shop.AppSecret, |
|
|
|
AppToken = shop.AppToken, |
|
|
|
Platform = SDKAdapter.AdapterEnums.PlatformType.拳探, |
|
|
|
UpdateStartTime = DateTime.Now.AddHours(-1), |
|
|
|
UpdateEndTime = DateTime.Now |
|
|
|
}; |
|
|
|
while (true) |
|
|
|
{ |
|
|
|
var response = productBusiness.GetProductList(spuRequest); |
|
|
|
if (response == null || response.Items == null || response.Items.Count == 0) |
|
|
|
break; |
|
|
|
|
|
|
|
opProductList.AddRange(response.Items); |
|
|
|
if (response.Items.Count < 50) |
|
|
|
break; |
|
|
|
opProductList.AddRange(response.Items); |
|
|
|
if (response.Items.Count < spuRequest.PageSize) |
|
|
|
break; |
|
|
|
|
|
|
|
spuRequest.PageIndex++; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
spuRequest.PageIndex++; |
|
|
|
#region 下架的spu
|
|
|
|
spuRequest.PageIndex = 1; |
|
|
|
spuRequest.ProductState = SDKAdapter.AdapterEnums.ProuctState.下架; |
|
|
|
while (true) |
|
|
|
{ |
|
|
|
var response = productBusiness.GetProductList(spuRequest); |
|
|
|
if (response == null || response.Items == null || response.Items.Count == 0) |
|
|
|
break; |
|
|
|
|
|
|
|
opProductList.AddRange(response.Items); |
|
|
|
if (response.Items.Count < spuRequest.PageSize) |
|
|
|
break; |
|
|
|
|
|
|
|
spuRequest.PageIndex++; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
@ -379,39 +400,31 @@ namespace BBWYB.Server.Business.Sync |
|
|
|
updateProductList.Add(update); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 查询变化的sku
|
|
|
|
#region 对比sku
|
|
|
|
|
|
|
|
var skuRequest = new OP_QueryProductSkuRequest() |
|
|
|
{ |
|
|
|
AppKey = shop.AppKey, |
|
|
|
AppSecret = shop.AppSecret, |
|
|
|
AppToken = shop.AppToken, |
|
|
|
Platform = SDKAdapter.AdapterEnums.PlatformType.拳探, |
|
|
|
//Spu = product.Id,
|
|
|
|
PageSize = 50, |
|
|
|
PageIndex = 1, |
|
|
|
UpdateStartTime = DateTime.Now.AddHours(-1), |
|
|
|
UpdateEndTime = DateTime.Now |
|
|
|
}; |
|
|
|
while (true) |
|
|
|
foreach (var product in opProductList) |
|
|
|
{ |
|
|
|
var skuRequest = new OP_QueryProductSkuRequest() |
|
|
|
{ |
|
|
|
AppKey = shop.AppKey, |
|
|
|
AppSecret = shop.AppSecret, |
|
|
|
AppToken = shop.AppToken, |
|
|
|
Platform = SDKAdapter.AdapterEnums.PlatformType.拳探, |
|
|
|
Spu = product.Id, |
|
|
|
PageSize = 50, |
|
|
|
PageIndex = 1, |
|
|
|
}; |
|
|
|
|
|
|
|
var response = productBusiness.GetProductSkuList(skuRequest); |
|
|
|
if (response == null || response.Items == null || response.Items.Count == 0) |
|
|
|
break; |
|
|
|
|
|
|
|
continue; |
|
|
|
opProductSkuList.AddRange(response.Items); |
|
|
|
if (response.Items.Count < 50) |
|
|
|
break; |
|
|
|
|
|
|
|
skuRequest.PageIndex++; |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 对比sku
|
|
|
|
|
|
|
|
var skuIdList = opProductSkuList.Select(x => x.Id); |
|
|
|
dbProductSkuList = fsql.Select<ProductSku>(skuIdList).ToList(); |
|
|
@ -430,7 +443,7 @@ namespace BBWYB.Server.Business.Sync |
|
|
|
SkuName = ps.Title, |
|
|
|
State = ps.State, |
|
|
|
SyncTime = DateTime.Now, |
|
|
|
UpdateTime = ps.UpdateTime, |
|
|
|
UpdateTime = DateTime.Now, |
|
|
|
UpperTime = ps.CreateTime, |
|
|
|
CategoryId = ps.CategoryId, |
|
|
|
CategoryName = ps.CategoryName |
|
|
@ -440,27 +453,36 @@ namespace BBWYB.Server.Business.Sync |
|
|
|
|
|
|
|
#region 找出状态变化的SKU
|
|
|
|
var stateChangeProductSkuList = opProductSkuList.Where(ps => dbProductSkuList.Any(dps => dps.Id == ps.Id && |
|
|
|
(dps.State != ps.State || |
|
|
|
dps.SkuName != ps.Title || |
|
|
|
dps.Price != ps.Price || |
|
|
|
dps.Logo != ps.Logo || |
|
|
|
dps.CategoryId != ps.CategoryId))).ToList(); |
|
|
|
(dps.State != ps.State || |
|
|
|
dps.SkuName != ps.Title || |
|
|
|
dps.Price != ps.Price || |
|
|
|
dps.Logo != ps.Logo || |
|
|
|
dps.CategoryId != ps.CategoryId))).ToList(); |
|
|
|
if (stateChangeProductSkuList.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var productSku in stateChangeProductSkuList) |
|
|
|
{ |
|
|
|
var update = fsql.Update<ProductSku>(productSku.Id).Set(ps => ps.State, productSku.State) |
|
|
|
.Set(ps => ps.SkuName, productSku.Title) |
|
|
|
.Set(ps => ps.Price, productSku.Price) |
|
|
|
.Set(ps => ps.Logo, productSku.Logo) |
|
|
|
.Set(ps => ps.CategoryId, productSku.CategoryId) |
|
|
|
.Set(ps => ps.CategoryName, productSku.CategoryName) |
|
|
|
.Set(ps => ps.UpdateTime, productSku.UpdateTime); |
|
|
|
var update = fsql.Update<ProductSku>(productSku.Id).Set(p => p.State, productSku.State) |
|
|
|
.Set(p => p.SkuName, productSku.Title) |
|
|
|
.Set(p => p.Price, productSku.Price) |
|
|
|
.Set(p => p.Logo, productSku.Logo) |
|
|
|
.Set(p => p.CategoryId, productSku.CategoryId) |
|
|
|
.Set(p => p.CategoryName, productSku.CategoryName); |
|
|
|
updateProductSkuList.Add(update); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 找出接口查不出的SKU
|
|
|
|
var goneProductSkuList = dbProductSkuList.Where(dps => !opProductSkuList.Any(ps => ps.Id == dps.Id)).ToList(); |
|
|
|
if (goneProductSkuList.Count() > 0) |
|
|
|
{ |
|
|
|
var goneProductSkuIdList = goneProductSkuList.Select(ps => ps.Id).ToList(); |
|
|
|
var update = fsql.Update<ProductSku>().Set(ps => ps.State, 0).Where(ps => goneProductSkuIdList.Contains(ps.Id)); |
|
|
|
updateProductSkuList.Add(update); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 数据库操作
|
|
|
|