Commit b1a7f188 by lizefeng

FIX

parent e71af189
...@@ -261,23 +261,23 @@ namespace AutoTurnOver.Services ...@@ -261,23 +261,23 @@ namespace AutoTurnOver.Services
var now = DateTime.Now; var now = DateTime.Now;
var fees = GetFinancialEventGroups(item, new_task_synchro_log.start_time, new_task_synchro_log.end_time); var fees = GetFinancialEventGroups(item, new_task_synchro_log.start_time, new_task_synchro_log.end_time);
//var json = fees.ToJson(); //var json = fees.ToJson();
foreach (var feeItem in fees.Where(s => s.FundTransferStatus == "Succeeded")) foreach (var feeItem in fees.Where(s => s.FundTransferStatus == "Succeeded"))
{ {
dc_base_amazon_fee transferFee = new dc_base_amazon_fee dc_base_amazon_fee transferFee = new dc_base_amazon_fee
{ {
account = item.Account, account = item.Account,
date = feeItem.FundTransferDate==null?new DateTime(1991,1,1) : feeItem.FundTransferDate.Value, date = feeItem.FundTransferDate == null ? new DateTime(1991, 1, 1) : feeItem.FundTransferDate.Value,
end_date = (feeItem.FinancialEventGroupEnd == null ? new DateTime(1991, 1, 1) : feeItem.FinancialEventGroupEnd.Value).AddHours(8), end_date = (feeItem.FinancialEventGroupEnd == null ? new DateTime(1991, 1, 1) : feeItem.FinancialEventGroupEnd.Value).AddHours(8),
start_date = (feeItem.FinancialEventGroupStart == null ? new DateTime(1991, 1, 1) : feeItem.FinancialEventGroupStart.Value).AddHours(8), start_date = (feeItem.FinancialEventGroupStart == null ? new DateTime(1991, 1, 1) : feeItem.FinancialEventGroupStart.Value).AddHours(8),
AmazonOrderId = feeItem.FinancialEventGroupId, AmazonOrderId = feeItem.FinancialEventGroupId,
SellerOrderId = feeItem.TraceId, SellerOrderId = feeItem.TraceId,
_ts = DateTime.Now, _ts = DateTime.Now,
settlement_id="-", settlement_id = "-",
description = $"To account ending in: {feeItem.AccountTail}", description = $"To account ending in: {feeItem.AccountTail}",
type = "Transfer", // 提现 type = "Transfer", // 提现
total = (decimal)feeItem.BeginningBalance.CurrencyAmount - (decimal)feeItem.OriginalTotal.CurrencyAmount , total = (decimal)feeItem.BeginningBalance.CurrencyAmount - (decimal)feeItem.OriginalTotal.CurrencyAmount,
currency_code = feeItem.OriginalTotal.CurrencyCode currency_code = feeItem.OriginalTotal.CurrencyCode
}; };
transferFee.settlement_date_str = $"{transferFee.start_date.Value.ToString("yyyy-MM-ddTHH:mm:ss")}~{transferFee.end_date.Value.ToString("yyyy-MM-ddTHH:mm:ss")}"; transferFee.settlement_date_str = $"{transferFee.start_date.Value.ToString("yyyy-MM-ddTHH:mm:ss")}~{transferFee.end_date.Value.ToString("yyyy-MM-ddTHH:mm:ss")}";
...@@ -322,7 +322,7 @@ namespace AutoTurnOver.Services ...@@ -322,7 +322,7 @@ namespace AutoTurnOver.Services
/// <summary> /// <summary>
/// 拉取报表 /// 拉取报表
/// </summary> /// </summary>
public void SynchroReportIds(ReportTypes reportTypeEnum,int version =8) public void SynchroReportIds(ReportTypes reportTypeEnum, int version = 8)
{ {
// 拉取亚马逊账号 // 拉取亚马逊账号
var amazonAccounts = ApiServices.GetAmazonAccountList(); var amazonAccounts = ApiServices.GetAmazonAccountList();
...@@ -521,7 +521,7 @@ namespace AutoTurnOver.Services ...@@ -521,7 +521,7 @@ namespace AutoTurnOver.Services
/// <summary> /// <summary>
/// 解析报告 /// 解析报告
/// </summary> /// </summary>
public void AnaReport(int status = 0,string data_id = "") public void AnaReport(int status = 0, string data_id = "")
{ {
var reportTypeEnum = ReportTypes.GET_V2_SETTLEMENT_REPORT_DATA_XML; var reportTypeEnum = ReportTypes.GET_V2_SETTLEMENT_REPORT_DATA_XML;
//var reportTypeEnum = ReportTypes.GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_V2; //var reportTypeEnum = ReportTypes.GET_V2_SETTLEMENT_REPORT_DATA_FLAT_FILE_V2;
...@@ -544,10 +544,11 @@ namespace AutoTurnOver.Services ...@@ -544,10 +544,11 @@ namespace AutoTurnOver.Services
} }
try try
{ {
var pamsAccount = ApiServices.GetAmazonAccountList().FirstOrDefault(s => s.Id == ana_task.pams_account_id);
string jsonText = ana_task.content; string jsonText = ana_task.content;
if (string.IsNullOrWhiteSpace(jsonText)) if (string.IsNullOrWhiteSpace(jsonText))
{ {
var pamsAccount = ApiServices.GetAmazonAccountList().FirstOrDefault(s => s.Id == ana_task.pams_account_id);
var filePath = DownloadReport(pamsAccount, ana_task.report_id); var filePath = DownloadReport(pamsAccount, ana_task.report_id);
StringBuilder response_str = new StringBuilder() { }; StringBuilder response_str = new StringBuilder() { };
using (StreamReader sr = new StreamReader(filePath)) using (StreamReader sr = new StreamReader(filePath))
...@@ -559,7 +560,7 @@ namespace AutoTurnOver.Services ...@@ -559,7 +560,7 @@ namespace AutoTurnOver.Services
doc.LoadXml(response_str.ToString()); doc.LoadXml(response_str.ToString());
jsonText = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc); jsonText = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);
} }
ana_task.content = jsonText; ana_task.content = jsonText;
//序列化 //序列化
...@@ -569,7 +570,7 @@ namespace AutoTurnOver.Services ...@@ -569,7 +570,7 @@ namespace AutoTurnOver.Services
List<dc_base_amazon_fee> feeDatas = new List<dc_base_amazon_fee> { }; List<dc_base_amazon_fee> feeDatas = new List<dc_base_amazon_fee> { };
foreach (var orderItem in settlementData.AmazonEnvelope.Message.SettlementReport.Order) foreach (var orderItem in settlementData.AmazonEnvelope.Message.SettlementReport.Order)
{ {
if(orderItem.AmazonOrderID== "202-9714395-5172367") if (orderItem.AmazonOrderID == "202-9714395-5172367")
{ {
} }
...@@ -594,7 +595,7 @@ namespace AutoTurnOver.Services ...@@ -594,7 +595,7 @@ namespace AutoTurnOver.Services
} }
} }
if (settlementData.AmazonEnvelope.Message.SettlementReport.SellerCouponPayment != null) if (settlementData.AmazonEnvelope.Message.SettlementReport.SellerCouponPayment != null)
{ {
foreach (var sellerCouponPaymentItem in settlementData.AmazonEnvelope.Message.SettlementReport.SellerCouponPayment) foreach (var sellerCouponPaymentItem in settlementData.AmazonEnvelope.Message.SettlementReport.SellerCouponPayment)
...@@ -609,7 +610,7 @@ namespace AutoTurnOver.Services ...@@ -609,7 +610,7 @@ namespace AutoTurnOver.Services
} }
var marketplaceName = ""; var marketplaceName = "";
//精准读取系统站点 //精准读取系统站点
if (feeDatas.Count >= 1) if (feeDatas.Count >= 1)
{ {
...@@ -628,17 +629,17 @@ namespace AutoTurnOver.Services ...@@ -628,17 +629,17 @@ namespace AutoTurnOver.Services
{ {
foreach (var otherTransactionItemFee in otherTransactionItem.Fees.Fee) foreach (var otherTransactionItemFee in otherTransactionItem.Fees.Fee)
{ {
var otherTransactionItemData = ApiOtherTransactionDataMapDbData(marketplaceName,pamsAccount, settlementData.AmazonEnvelope.Message.SettlementReport.SettlementData, var otherTransactionItemData = ApiOtherTransactionDataMapDbData(marketplaceName, pamsAccount, settlementData.AmazonEnvelope.Message.SettlementReport.SettlementData,
otherTransactionItem.TransactionID, otherTransactionItem.PostedDate, otherTransactionItem.TransactionID, otherTransactionItem.PostedDate,
otherTransactionItemFee.Amount.Text ?? 0, otherTransactionItemFee.Type, otherTransactionItemFee.Amount.Currency,"other", otherTransactionItem.AmazonOrderID); otherTransactionItemFee.Amount.Text ?? 0, otherTransactionItemFee.Type, otherTransactionItemFee.Amount.Currency, "other", otherTransactionItem.AmazonOrderID);
feeDatas.Add(otherTransactionItemData); feeDatas.Add(otherTransactionItemData);
} }
} }
else else
{ {
var otherTransactionItemData = ApiOtherTransactionDataMapDbData(marketplaceName,pamsAccount, settlementData.AmazonEnvelope.Message.SettlementReport.SettlementData, var otherTransactionItemData = ApiOtherTransactionDataMapDbData(marketplaceName, pamsAccount, settlementData.AmazonEnvelope.Message.SettlementReport.SettlementData,
otherTransactionItem.TransactionID, otherTransactionItem.PostedDate, otherTransactionItem.TransactionID, otherTransactionItem.PostedDate,
otherTransactionItem.Amount.Text ?? 0, otherTransactionItem.TransactionType, otherTransactionItem.Amount.Currency, "other" ,otherTransactionItem.AmazonOrderID); otherTransactionItem.Amount.Text ?? 0, otherTransactionItem.TransactionType, otherTransactionItem.Amount.Currency, "other", otherTransactionItem.AmazonOrderID);
feeDatas.Add(otherTransactionItemData); feeDatas.Add(otherTransactionItemData);
} }
...@@ -657,7 +658,7 @@ namespace AutoTurnOver.Services ...@@ -657,7 +658,7 @@ namespace AutoTurnOver.Services
} }
dc_base_amazon_settlement settlementDbData = new dc_base_amazon_settlement dc_base_amazon_settlement settlementDbData = new dc_base_amazon_settlement
{ {
...@@ -687,11 +688,11 @@ namespace AutoTurnOver.Services ...@@ -687,11 +688,11 @@ namespace AutoTurnOver.Services
{ {
try try
{ {
feeItem.MarketplaceNameSys = marketplaceNameSys; feeItem.MarketplaceNameSys = marketplaceNameSys;
feeItem.start_date = settlementDbData.start_date; feeItem.start_date = settlementDbData.start_date;
feeItem.end_date = settlementDbData.end_date; feeItem.end_date = settlementDbData.end_date;
feeItem.settlement_date_str =$"{feeItem.start_date.Value.ToString("yyyy-MM-ddTHH:mm:ss")}~{feeItem.end_date.Value.ToString("yyyy-MM-ddTHH:mm:ss")}"; feeItem.settlement_date_str = $"{feeItem.start_date.Value.ToString("yyyy-MM-ddTHH:mm:ss")}~{feeItem.end_date.Value.ToString("yyyy-MM-ddTHH:mm:ss")}";
feeItem._ts = DateTime.Now; feeItem._ts = DateTime.Now;
feeItem.id = MyMySqlConnection._connection.QueryFirstOrDefault<int?>("select id from dc_base_amazon_fee where data_id=@data_id", new { data_id = feeItem.data_id }) ?? 0; feeItem.id = MyMySqlConnection._connection.QueryFirstOrDefault<int?>("select id from dc_base_amazon_fee where data_id=@data_id", new { data_id = feeItem.data_id }) ?? 0;
if (feeItem.id > 0) if (feeItem.id > 0)
{ {
...@@ -710,12 +711,12 @@ namespace AutoTurnOver.Services ...@@ -710,12 +711,12 @@ namespace AutoTurnOver.Services
} }
ana_task.data_id = settlementDbData.settlement_id; ana_task.data_id = settlementDbData.settlement_id;
} }
ana_task.ana_error = ""; ana_task.ana_error = "";
ana_task.ana_stack_trace = ""; ana_task.ana_stack_trace = "";
ana_task.ana_status = 1; ana_task.ana_status = 1;
...@@ -755,11 +756,12 @@ namespace AutoTurnOver.Services ...@@ -755,11 +756,12 @@ namespace AutoTurnOver.Services
string jsonText = response_str.ToString(); string jsonText = response_str.ToString();
ana_task.content = jsonText; ana_task.content = jsonText;
var table = CsvFileHelper.ReadFromCSV(filePath, true,jsonText.Contains("amazon-order-id") ?'\t':','); var table = CsvFileHelper.ReadFromCSV(filePath, true, jsonText.Contains("amazon-order-id") ? '\t' : ',');
foreach (DataRow row in table.Rows) foreach (DataRow row in table.Rows)
{ {
int comIndex = 0; int comIndex = 0;
dc_base_amazon_fulfilled_shipments fulfilledShipments = new dc_base_amazon_fulfilled_shipments { dc_base_amazon_fulfilled_shipments fulfilledShipments = new dc_base_amazon_fulfilled_shipments
{
amazon_order_id = row.DataRowToString(comIndex++), amazon_order_id = row.DataRowToString(comIndex++),
merchant_order_id = row.DataRowToString(comIndex++), merchant_order_id = row.DataRowToString(comIndex++),
shipment_id = row.DataRowToString(comIndex++), shipment_id = row.DataRowToString(comIndex++),
...@@ -806,12 +808,12 @@ namespace AutoTurnOver.Services ...@@ -806,12 +808,12 @@ namespace AutoTurnOver.Services
tracking_number = row.DataRowToString(comIndex++), tracking_number = row.DataRowToString(comIndex++),
estimated_arrival_date = row.DataRowToDateTime(comIndex++), estimated_arrival_date = row.DataRowToDateTime(comIndex++),
fulfillment_center_id = row.DataRowToString(comIndex++), fulfillment_center_id = row.DataRowToString(comIndex++),
fulfillment_channel = row.DataRowToString(comIndex++), fulfillment_channel = row.DataRowToString(comIndex++),
sales_channel = row.DataRowToString(comIndex++) sales_channel = row.DataRowToString(comIndex++)
}; };
fulfilledShipments._ts = DateTime.Now; fulfilledShipments._ts = DateTime.Now;
fulfilledShipments.data_id = $"{fulfilledShipments.amazon_order_id}-{fulfilledShipments.amazon_order_item_id}-{fulfilledShipments.sku}-{fulfilledShipments.merchant_order_item_id}-{fulfilledShipments.shipment_id}-{fulfilledShipments.shipment_item_id}-end"; fulfilledShipments.data_id = $"{fulfilledShipments.amazon_order_id}-{fulfilledShipments.amazon_order_item_id}-{fulfilledShipments.sku}-{fulfilledShipments.merchant_order_item_id}-{fulfilledShipments.shipment_id}-{fulfilledShipments.shipment_item_id}-end";
fulfilledShipments.id = MyMySqlConnection._connection.QueryFirstOrDefault<int?>(" select id from dc_base_amazon_fulfilled_shipments where data_id=@data_id ",new { data_id = fulfilledShipments.data_id })??0; fulfilledShipments.id = MyMySqlConnection._connection.QueryFirstOrDefault<int?>(" select id from dc_base_amazon_fulfilled_shipments where data_id=@data_id ", new { data_id = fulfilledShipments.data_id }) ?? 0;
if (fulfilledShipments.id > 0) if (fulfilledShipments.id > 0)
{ {
MyMySqlConnection._connection.Update(fulfilledShipments); MyMySqlConnection._connection.Update(fulfilledShipments);
...@@ -842,16 +844,16 @@ namespace AutoTurnOver.Services ...@@ -842,16 +844,16 @@ namespace AutoTurnOver.Services
/// </summary> /// </summary>
/// <param name="currency"></param> /// <param name="currency"></param>
/// <returns></returns> /// <returns></returns>
public string ComputeMarketplaceNameByCurrency(string currency) public string ComputeMarketplaceNameByCurrency(string currency)
{ {
switch (currency.ToUpper()) switch (currency.ToUpper())
{ {
case "USD":return "Amazon.com"; case "USD": return "Amazon.com";
case "SEK": return "Amazon.se"; case "SEK": return "Amazon.se";
case "GBP": return "Amazon.co.uk"; case "GBP": return "Amazon.co.uk";
case "MXN": return "Amazon.com.mx"; case "MXN": return "Amazon.com.mx";
case "CAD": return "Amazon.ca"; case "CAD": return "Amazon.ca";
default:return ""; default: return "";
} }
} }
...@@ -893,7 +895,7 @@ namespace AutoTurnOver.Services ...@@ -893,7 +895,7 @@ namespace AutoTurnOver.Services
{ {
feeShipmentEvent.fba_fees = item.ItemFees.Fee.Where(s => fbaFeeTypeList.Any(f1 => f1.Equals(s.Type, StringComparison.InvariantCultureIgnoreCase))).Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.fba_fees = item.ItemFees.Fee.Where(s => fbaFeeTypeList.Any(f1 => f1.Equals(s.Type, StringComparison.InvariantCultureIgnoreCase))).Sum(s => s.Amount.Text ?? 0);
feeShipmentEvent.selling_fees = item.ItemFees.Fee.Where(s => sellingFeesList.Any(f1 => s.Type.Equals(f1, StringComparison.InvariantCultureIgnoreCase))).Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.selling_fees = item.ItemFees.Fee.Where(s => sellingFeesList.Any(f1 => s.Type.Equals(f1, StringComparison.InvariantCultureIgnoreCase))).Sum(s => s.Amount.Text ?? 0);
feeShipmentEvent.fee_types =string.Join(",", item.ItemFees.Fee.Select(s=>s.Type)) ; feeShipmentEvent.fee_types = string.Join(",", item.ItemFees.Fee.Select(s => s.Type));
} }
...@@ -904,10 +906,14 @@ namespace AutoTurnOver.Services ...@@ -904,10 +906,14 @@ namespace AutoTurnOver.Services
feeShipmentEvent.postage_credits = item.ItemPrice.Component.Where(s => s.Type.Equals("Shipping", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.postage_credits = item.ItemPrice.Component.Where(s => s.Type.Equals("Shipping", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
feeShipmentEvent.shipping_credits_tax = item.ItemPrice.Component.Where(s => s.Type.Equals("ShippingTax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.shipping_credits_tax = item.ItemPrice.Component.Where(s => s.Type.Equals("ShippingTax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
feeShipmentEvent.product_sales_tax = item.ItemPrice.Component.Where(s => s.Type.Equals("Tax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.product_sales_tax = item.ItemPrice.Component.Where(s => s.Type.Equals("Tax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
if (feeShipmentEvent.shipping_credits_tax == 0 && feeShipmentEvent.postage_credits != 0) if (!"Amazon.com".Equals(feeShipmentEvent.MarketplaceName))
{ {
feeShipmentEvent.shipping_credits_tax = Math.Round(feeShipmentEvent.postage_credits * 0.2M, 2, MidpointRounding.ToEven); if (feeShipmentEvent.shipping_credits_tax == 0 && feeShipmentEvent.postage_credits != 0)
{
feeShipmentEvent.shipping_credits_tax = Math.Round(feeShipmentEvent.postage_credits * 0.2M, 2, MidpointRounding.ToEven);
}
} }
feeShipmentEvent.gift_wrap_credits = item.ItemPrice.Component.Where(s => s.Type.Equals("GiftWrap", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.gift_wrap_credits = item.ItemPrice.Component.Where(s => s.Type.Equals("GiftWrap", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
feeShipmentEvent.gift_wrap_credits_tax = item.ItemPrice.Component.Where(s => s.Type.Equals("GiftWrapTax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.gift_wrap_credits_tax = item.ItemPrice.Component.Where(s => s.Type.Equals("GiftWrapTax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
feeShipmentEvent.product_sales = item.ItemPrice.Component.Where(s => s.Type.Equals("Principal", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.product_sales = item.ItemPrice.Component.Where(s => s.Type.Equals("Principal", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
...@@ -929,7 +935,7 @@ namespace AutoTurnOver.Services ...@@ -929,7 +935,7 @@ namespace AutoTurnOver.Services
feeShipmentEvent.other = 0; feeShipmentEvent.other = 0;
if (item.Promotion != null && item.Promotion.Any(s=>s.Amount.Text != 0)) if (item.Promotion != null && item.Promotion.Any(s => s.Amount.Text != 0))
{ {
feeShipmentEvent.promotional_rebates = item.Promotion.Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.promotional_rebates = item.Promotion.Sum(s => s.Amount.Text ?? 0);
// 美国站统一没有这个 // 美国站统一没有这个
...@@ -1004,10 +1010,14 @@ namespace AutoTurnOver.Services ...@@ -1004,10 +1010,14 @@ namespace AutoTurnOver.Services
feeShipmentEvent.postage_credits = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("Shipping", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.postage_credits = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("Shipping", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
feeShipmentEvent.shipping_credits_tax = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("ShippingTax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.shipping_credits_tax = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("ShippingTax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
feeShipmentEvent.product_sales_tax = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("Tax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.product_sales_tax = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("Tax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
if (feeShipmentEvent.shipping_credits_tax == 0 && feeShipmentEvent.postage_credits != 0) if (!"Amazon.com".Equals(feeShipmentEvent.MarketplaceName))
{ {
feeShipmentEvent.shipping_credits_tax = Math.Round(feeShipmentEvent.postage_credits * 0.2M, 2, MidpointRounding.ToEven); if (feeShipmentEvent.shipping_credits_tax == 0 && feeShipmentEvent.postage_credits != 0)
{
feeShipmentEvent.shipping_credits_tax = Math.Round(feeShipmentEvent.postage_credits * 0.2M, 2, MidpointRounding.ToEven);
}
} }
feeShipmentEvent.gift_wrap_credits = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("GiftWrap", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.gift_wrap_credits = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("GiftWrap", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
feeShipmentEvent.gift_wrap_credits_tax = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("GiftWrapTax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.gift_wrap_credits_tax = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("GiftWrapTax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
feeShipmentEvent.product_sales = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("Principal", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0); feeShipmentEvent.product_sales = itemFeeAdjustment.ItemPriceAdjustments.Component.Where(s => s.Type.Equals("Principal", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.Amount.Text ?? 0);
...@@ -1029,15 +1039,15 @@ namespace AutoTurnOver.Services ...@@ -1029,15 +1039,15 @@ namespace AutoTurnOver.Services
feeShipmentEvent.other = 0; feeShipmentEvent.other = 0;
if (itemFeeAdjustment.PromotionAdjustment != null && itemFeeAdjustment.PromotionAdjustment.Any(s=>s.Amount.Text != 0)) if (itemFeeAdjustment.PromotionAdjustment != null && itemFeeAdjustment.PromotionAdjustment.Any(s => s.Amount.Text != 0))
{ {
feeShipmentEvent.promotional_rebates = itemFeeAdjustment.PromotionAdjustment.Sum(s=>s.Amount.Text??0); feeShipmentEvent.promotional_rebates = itemFeeAdjustment.PromotionAdjustment.Sum(s => s.Amount.Text ?? 0);
// 美国站统一没有这个 // 美国站统一没有这个
if (!"Amazon.com".Equals(feeShipmentEvent.MarketplaceName)) if (!"Amazon.com".Equals(feeShipmentEvent.MarketplaceName))
{ {
feeShipmentEvent.promotional_rebates_tax = 0 - feeShipmentEvent.shipping_credits_tax; feeShipmentEvent.promotional_rebates_tax = 0 - feeShipmentEvent.shipping_credits_tax;
} }
} }
feeShipmentEvent.total = feeShipmentEvent.total =
...@@ -1064,8 +1074,8 @@ namespace AutoTurnOver.Services ...@@ -1064,8 +1074,8 @@ namespace AutoTurnOver.Services
} }
public dc_base_amazon_fee ApiOtherTransactionDataMapDbData(string marketplaceName,AmazonAccountDto account, ApiAmazonSettlementDto.AmazonEnvelopeDto.MessageDto.SettlementReportDto.SettlementDataDto xmlSettlementData, public dc_base_amazon_fee ApiOtherTransactionDataMapDbData(string marketplaceName, AmazonAccountDto account, ApiAmazonSettlementDto.AmazonEnvelopeDto.MessageDto.SettlementReportDto.SettlementDataDto xmlSettlementData,
string transactionID, DateTime? postedDate, decimal amount, string type, string currency_code,string source = "other",string amazonOrderID = null) string transactionID, DateTime? postedDate, decimal amount, string type, string currency_code, string source = "other", string amazonOrderID = null)
{ {
var fbaTypeDic = new Dictionary<string, string> { }; var fbaTypeDic = new Dictionary<string, string> { };
fbaTypeDic.Add("Storage Fee", "FBA Inventory Fee"); fbaTypeDic.Add("Storage Fee", "FBA Inventory Fee");
...@@ -1087,7 +1097,7 @@ namespace AutoTurnOver.Services ...@@ -1087,7 +1097,7 @@ namespace AutoTurnOver.Services
{ {
feeShipmentEvent.AmazonOrderId = transactionID; feeShipmentEvent.AmazonOrderId = transactionID;
} }
feeShipmentEvent.currency_code = currency_code; feeShipmentEvent.currency_code = currency_code;
feeShipmentEvent.MarketplaceName = marketplaceName; feeShipmentEvent.MarketplaceName = marketplaceName;
feeShipmentEvent.description = type; feeShipmentEvent.description = type;
...@@ -1100,7 +1110,7 @@ namespace AutoTurnOver.Services ...@@ -1100,7 +1110,7 @@ namespace AutoTurnOver.Services
{ {
feeShipmentEvent.other_transaction_fees = amount; feeShipmentEvent.other_transaction_fees = amount;
} }
feeShipmentEvent.type = "Other"; feeShipmentEvent.type = "Other";
if (!string.IsNullOrWhiteSpace(type)) if (!string.IsNullOrWhiteSpace(type))
{ {
...@@ -1112,7 +1122,7 @@ namespace AutoTurnOver.Services ...@@ -1112,7 +1122,7 @@ namespace AutoTurnOver.Services
} }
feeShipmentEvent.date = postedDate == null ? new DateTime(1991, 1, 1) : postedDate.Value; feeShipmentEvent.date = postedDate == null ? new DateTime(1991, 1, 1) : postedDate.Value;
feeShipmentEvent.data_id = $"{account.Account}_OtherTransaction_{transactionID}_{feeShipmentEvent.AmazonOrderId}_{ feeShipmentEvent.description}_{feeShipmentEvent.settlement_id}_{feeShipmentEvent.date.ToString("yyyy-MM-ddTHH:mm:ss")}"; feeShipmentEvent.data_id = $"{account.Account}_OtherTransaction_{transactionID}_{feeShipmentEvent.AmazonOrderId}_{ feeShipmentEvent.description}_{feeShipmentEvent.settlement_id}_{feeShipmentEvent.date.ToString("yyyy-MM-ddTHH:mm:ss")}";
return feeShipmentEvent; return feeShipmentEvent;
} }
...@@ -1381,20 +1391,22 @@ namespace AutoTurnOver.Services ...@@ -1381,20 +1391,22 @@ namespace AutoTurnOver.Services
/// <summary> /// <summary>
/// 通过精准的时分秒的结算时间,寻找结算id /// 通过精准的时分秒的结算时间,寻找结算id
/// </summary> /// </summary>
public void SetSettlementByDate() public void SetSettlementByDate()
{ {
var datas = MyMySqlConnection._connection.Query<dc_base_amazon_fee>(" select * from dc_base_amazon_fee where settlement_id='-' order by id desc limit 100 ").ToList(); var datas = MyMySqlConnection._connection.Query<dc_base_amazon_fee>(" select * from dc_base_amazon_fee where settlement_id='-' order by id desc limit 100 ").ToList();
foreach (var item in datas) foreach (var item in datas)
{ {
//查询同账号下,相同时间节点的费用 //查询同账号下,相同时间节点的费用
var feeSingleData = MyMySqlConnection._connection.QueryFirstOrDefault<dc_base_amazon_fee>(" select * from dc_base_amazon_fee where settlement_date_str=@settlement_date_str and account=@account and settlement_id!='-' limit 1 ", new { var feeSingleData = MyMySqlConnection._connection.QueryFirstOrDefault<dc_base_amazon_fee>(" select * from dc_base_amazon_fee where settlement_date_str=@settlement_date_str and account=@account and settlement_id!='-' limit 1 ", new
settlement_date_str= item.settlement_date_str, {
settlement_date_str = item.settlement_date_str,
account = item.account account = item.account
}); });
if (feeSingleData != null) if (feeSingleData != null)
{ {
item.settlement_id = feeSingleData.settlement_id; item.settlement_id = feeSingleData.settlement_id;
MyMySqlConnection._connection.Execute(" update dc_base_amazon_fee set settlement_id=@settlement_id,_ts=now() where id=@id ",new { MyMySqlConnection._connection.Execute(" update dc_base_amazon_fee set settlement_id=@settlement_id,_ts=now() where id=@id ", new
{
settlement_id = item.settlement_id, settlement_id = item.settlement_id,
id = item.id id = item.id
}); });
...@@ -1406,21 +1418,23 @@ namespace AutoTurnOver.Services ...@@ -1406,21 +1418,23 @@ namespace AutoTurnOver.Services
/// <summary> /// <summary>
/// 计算站点 (目前只有欧洲站点有这个情况) /// 计算站点 (目前只有欧洲站点有这个情况)
/// </summary> /// </summary>
public void SetMarketplaceName(DateTime nowDate) public void SetMarketplaceName(DateTime nowDate)
{ {
var allSites = new List<string> { "Amazon.it", "Amazon.fr", "Amazon.nl", "Amazon.es", "Amazon.de", "Amazon.com.be" }; var allSites = new List<string> { "Amazon.it", "Amazon.fr", "Amazon.nl", "Amazon.es", "Amazon.de", "Amazon.com.be" };
// 查询没有找到站点的结算表 // 查询没有找到站点的结算表
var datas = MyMySqlConnection._connection.Query<dc_base_amazon_settlement>(" select * from dc_base_amazon_settlement where marketplace_name_sys='' and currency='EUR' and _ts<@nowDate order by id desc limit 100 ", new { var datas = MyMySqlConnection._connection.Query<dc_base_amazon_settlement>(" select * from dc_base_amazon_settlement where marketplace_name_sys='' and currency='EUR' and _ts<@nowDate order by id desc limit 100 ", new
nowDate = nowDate {
}).ToList(); nowDate = nowDate
}).ToList();
foreach (var item in datas) foreach (var item in datas)
{ {
// 查询这个计算表差不多时间 // 查询这个计算表差不多时间
var settlements = MyMySqlConnection._connection.Query<dc_base_amazon_settlement>(" select * from dc_base_amazon_settlement where start_date<=@etime and end_date>=@btime and account=@account ", new { var settlements = MyMySqlConnection._connection.Query<dc_base_amazon_settlement>(" select * from dc_base_amazon_settlement where start_date<=@etime and end_date>=@btime and account=@account ", new
{
btime = item.start_date.Value.AddDays(-1), btime = item.start_date.Value.AddDays(-1),
etime = item.start_date.Value.AddDays(1), etime = item.start_date.Value.AddDays(1),
account = item.account account = item.account
}).ToList().Where(s=>!string.IsNullOrWhiteSpace( s.marketplace_name_sys)).ToList(); }).ToList().Where(s => !string.IsNullOrWhiteSpace(s.marketplace_name_sys)).ToList();
// 把已经有站点的账单挑出去,在剩余站点中随便找一个 // 把已经有站点的账单挑出去,在剩余站点中随便找一个
var useDatas = allSites.Where(s => !settlements.Any(s1 => s1.marketplace_name_sys == s)).ToList(); var useDatas = allSites.Where(s => !settlements.Any(s1 => s1.marketplace_name_sys == s)).ToList();
if (useDatas.Count >= 1) if (useDatas.Count >= 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment