|
|
@ -657,10 +657,6 @@ namespace BBWYB.Server.Business |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 采购配件最近采购价
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 采购商累计信息
|
|
|
@ -861,5 +857,98 @@ namespace BBWYB.Server.Business |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void RepairPurchaseSchemeLastPurchasePrice() |
|
|
|
{ |
|
|
|
/* |
|
|
|
select opi.SchemeId,opi.PurchaseOrderId from orderpurchaserelationinfo opi |
|
|
|
inner join (select max(opi1.OrderId) as maxOrderId,opi1.SchemeId from orderpurchaserelationinfo opi1 group by opi1.SchemeId) as temp |
|
|
|
on opi.OrderId=temp.maxOrderId and opi.SchemeId=temp.SchemeId |
|
|
|
group by opi.SchemeId,opi.PurchaseOrderId |
|
|
|
*/ |
|
|
|
|
|
|
|
var opiList = fsql.Select<OrderPurchaseRelationInfo>().ToList(); |
|
|
|
var pssList = fsql.Select<PurchaseSchemeProductSku>().ToList(); |
|
|
|
var poList = fsql.Select<OrderPurchaseInfo>().ToList(); |
|
|
|
|
|
|
|
var purchaseAccountList = freeSqlMultiDBManager.MDSfsql.Select<Model.Db.MDS.Purchaseaccount, Model.Db.Mds.Shops>() |
|
|
|
.InnerJoin((pa, s) => pa.ShopId == s.Id) |
|
|
|
.Where((pa, s) => s.PlatformId == 10 && pa.PurchasePlatformId == "2") |
|
|
|
.ToList((pa, s) => new |
|
|
|
{ |
|
|
|
s.ShopId, |
|
|
|
pa.AppKey, |
|
|
|
pa.AppSecret, |
|
|
|
pa.AppToken |
|
|
|
}); |
|
|
|
|
|
|
|
var schemeGroups = fsql.Select<OrderPurchaseRelationInfo>() |
|
|
|
.GroupBy(opi1 => opi1.SchemeId) |
|
|
|
.WithTempQuery(g => new { MaxOrderId = g.Max(g.Value.OrderId), SchemeId = g.Value.SchemeId }) |
|
|
|
.From<OrderPurchaseRelationInfo>() |
|
|
|
.InnerJoin((opi1, opi2) => opi1.MaxOrderId == opi2.OrderId && opi1.SchemeId == opi2.SchemeId) |
|
|
|
.GroupBy((opi1, opi2) => new { opi2.SchemeId, opi2.PurchaseOrderId }) |
|
|
|
.ToList(g => new |
|
|
|
{ |
|
|
|
g.Value.Item2.SchemeId, |
|
|
|
g.Value.Item2.PurchaseOrderId |
|
|
|
}).GroupBy(x => x.SchemeId); |
|
|
|
|
|
|
|
var client = pp_PlatformClientFactory.GetClient(AdapterEnums.PlatformType.阿里巴巴); |
|
|
|
|
|
|
|
IDictionary<string, IList<PP_QueryOrderDetailSkuResponse>> purchaseOrderDictionary = new Dictionary<string, IList<PP_QueryOrderDetailSkuResponse>>(); |
|
|
|
var index = 1; |
|
|
|
foreach (var schemeGroup in schemeGroups) |
|
|
|
{ |
|
|
|
var schemeId = schemeGroup.Key; |
|
|
|
var lastPurchasePriceCost = 0M; |
|
|
|
foreach (var schemeItem in schemeGroup) |
|
|
|
{ |
|
|
|
Thread.Sleep(1500); |
|
|
|
try |
|
|
|
{ |
|
|
|
var poId = schemeItem.PurchaseOrderId; |
|
|
|
var currentOpiList = opiList.Where(x => x.SchemeId == schemeId && x.PurchaseOrderId == poId).ToList(); |
|
|
|
if (!purchaseOrderDictionary.TryGetValue(poId, out var _1688itemList)) |
|
|
|
{ |
|
|
|
var po = poList.FirstOrDefault(x => x.PurchaseOrderId == poId); |
|
|
|
if (po == null) |
|
|
|
continue; |
|
|
|
var shopId = po.ShopId.ToString(); |
|
|
|
var pa = purchaseAccountList.FirstOrDefault(x => x.ShopId == shopId); |
|
|
|
|
|
|
|
var purchaseOrderSimpleInfo = client.QueryOrderDetail(new PP_QueryOrderDetailRequest() |
|
|
|
{ |
|
|
|
AppKey = pa.AppKey, |
|
|
|
AppSecret = pa.AppSecret, |
|
|
|
AppToken = pa.AppToken, |
|
|
|
OrderId = poId |
|
|
|
}); |
|
|
|
_1688itemList = purchaseOrderSimpleInfo.ItemList; |
|
|
|
purchaseOrderDictionary.TryAdd(poId, _1688itemList); |
|
|
|
} |
|
|
|
foreach (var ppsku in _1688itemList) |
|
|
|
{ |
|
|
|
if (currentOpiList.Any(x => x.PurchaseSkuId == ppsku.SkuId)) |
|
|
|
{ |
|
|
|
var pss = pssList.FirstOrDefault(x => x.SkuPurchaseSchemeId == schemeId && x.PurchaseSkuId == ppsku.SkuId); |
|
|
|
if (pss != null) |
|
|
|
{ |
|
|
|
lastPurchasePriceCost += ppsku.Price * (pss.PurchaseRatio ?? 1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
Console.WriteLine($"{schemeItem.PurchaseOrderId},{ex.Message}"); |
|
|
|
} |
|
|
|
} |
|
|
|
fsql.Update<PurchaseScheme>(schemeId).Set(ps => ps.LastPurchasePriceCost, lastPurchasePriceCost).ExecuteAffrows(); |
|
|
|
Console.WriteLine($"更新进度 {index}/{schemeGroups.Count()}"); |
|
|
|
index++; |
|
|
|
} |
|
|
|
Console.WriteLine(schemeGroups.Count()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|