Commit 28f9c24f by lizefeng

发布亚马逊费用抓取

parent 6bda5576
......@@ -75,7 +75,7 @@ namespace AutoTurnOver.Services
foreach (var shipmentItem in shipmentEvent.ShipmentItemList)
{
feeDatas.Add(ApiDataMapDbData(item.Account, shipmentEvent, shipmentItem,"order"));
feeDatas.Add(ApiDataMapDbData(item.Account, shipmentEvent, shipmentItem, "order"));
}
}
}
......@@ -88,13 +88,13 @@ namespace AutoTurnOver.Services
foreach (var shipmentItemAdjustmentList in refundEventList.ShipmentItemAdjustmentList)
{
feeDatas.Add(ApiDataMapDbData(item.Account,refundEventList, shipmentItemAdjustmentList,"refund"));
feeDatas.Add(ApiDataMapDbData(item.Account, refundEventList, shipmentItemAdjustmentList, "refund"));
}
}
}
// 服务费 (该费用没有实际时间,如果抓取时间跟当前时间相差不超过24小时,则以当前时间为准,否则跳过该费用)
if((DateTime.Now- new_task_synchro_log.start_time).TotalHours <= 24)
if ((DateTime.Now - new_task_synchro_log.start_time).TotalHours <= 24)
{
if (fee.ServiceFeeEventList != null && fee.ServiceFeeEventList.Count >= 1)
{
......@@ -102,7 +102,8 @@ namespace AutoTurnOver.Services
{
foreach (var serviceFeeEventFeeItem in serviceFeeEvent.FeeList)
{
if (serviceFeeEventFeeItem.FeeAmount != null && serviceFeeEventFeeItem.FeeAmount.CurrencyAmount != 0){
if (serviceFeeEventFeeItem.FeeAmount != null && serviceFeeEventFeeItem.FeeAmount.CurrencyAmount != 0)
{
dc_base_amazon_fee serviceFeeEventFee = new dc_base_amazon_fee
{
account = item.Account,
......@@ -130,12 +131,12 @@ namespace AutoTurnOver.Services
dc_base_amazon_fee productAdsPaymentFee = new dc_base_amazon_fee
{
account = item.Account,
date = productAdsPayment.PostedDate==null?new DateTime(1991,1,1) : productAdsPayment.PostedDate.Value,
date = productAdsPayment.PostedDate == null ? new DateTime(1991, 1, 1) : productAdsPayment.PostedDate.Value,
AmazonOrderId = productAdsPayment.InvoiceId,
description = "Cost of Advertising",
type = "Service Fee",
total = (decimal)productAdsPayment.TransactionValue.CurrencyAmount,
other =0,
other = 0,
currency_code = productAdsPayment.TransactionValue.CurrencyCode
};
productAdsPaymentFee.data_id = $"{item.Account}_{productAdsPaymentFee.type}_{productAdsPaymentFee.description}_{productAdsPaymentFee.date.ToString("yyyy-MM-ddTHH:mm:ssZ")}_{productAdsPaymentFee.currency_code}_{productAdsPaymentFee.AmazonOrderId}";
......@@ -144,10 +145,10 @@ namespace AutoTurnOver.Services
}
// 客户退款
if(fee.AdjustmentEventList!=null && fee.AdjustmentEventList.Count >= 1)
if (fee.AdjustmentEventList != null && fee.AdjustmentEventList.Count >= 1)
{
// 客户退款
foreach (var customerReturn in fee.AdjustmentEventList.Where(s=>s.AdjustmentType== "REVERSAL_REIMBURSEMENT"))
foreach (var customerReturn in fee.AdjustmentEventList.Where(s => s.AdjustmentType == "REVERSAL_REIMBURSEMENT"))
{
foreach (var customerReturnItem in customerReturn.AdjustmentItemList)
{
......@@ -159,7 +160,7 @@ namespace AutoTurnOver.Services
type = "Ajustement",
total = (decimal)customerReturnItem.TotalAmount.CurrencyAmount,
other = 0,
sku= customerReturnItem.SellerSKU,
sku = customerReturnItem.SellerSKU,
currency_code = customerReturnItem.TotalAmount.CurrencyCode
};
customerReturnFee.data_id = $"{item.Account}_{customerReturnFee.type}_{customerReturnFee.description}_{customerReturnFee.date.ToString("yyyy-MM-ddTHH:mm:ssZ")}_{customerReturnFee.currency_code}_{customerReturnFee.sku}";
......@@ -174,7 +175,7 @@ namespace AutoTurnOver.Services
foreach (var feeItem in feeDatas)
{
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)
{
MyMySqlConnection._connection.Update(feeItem);
......@@ -195,7 +196,15 @@ namespace AutoTurnOver.Services
}
catch (Exception ex)
{
throw;
MyMySqlConnection._connection.Insert(new dc_task_error_log
{
date = DateTime.Now,
message = ex.Message,
stack_trace = ex.StackTrace,
task_name = "SynchroAmazonFee"
});
//throw;
}
......@@ -222,30 +231,50 @@ namespace AutoTurnOver.Services
feeShipmentEvent.sku = shipmentItem.SellerSKU;
if (type == "refund")
{
feeShipmentEvent.currency_code = shipmentItem.ItemFeeAdjustmentList.FirstOrDefault()?.FeeAmount.CurrencyCode;
if (shipmentItem.ItemFeeAdjustmentList != null && shipmentItem.ItemFeeAdjustmentList.Count >= 1)
{
feeShipmentEvent.fba_fees = (decimal)shipmentItem.ItemFeeAdjustmentList.Where(s => fbaFeeTypeList.Any(f1 => f1.Equals(s.FeeType, StringComparison.InvariantCultureIgnoreCase))).Sum(s => s.FeeAmount.CurrencyAmount);
feeShipmentEvent.selling_fees = (decimal)shipmentItem.ItemFeeAdjustmentList.Where(s => sellingFeesList.Any(f1 => s.FeeType.Equals(f1, StringComparison.InvariantCultureIgnoreCase))).Sum(s => s.FeeAmount.CurrencyAmount);
}
if (shipmentItem.ItemChargeAdjustmentList != null && shipmentItem.ItemChargeAdjustmentList.Count >= 1)
{
feeShipmentEvent.currency_code = shipmentItem.ItemChargeAdjustmentList.FirstOrDefault()?.ChargeAmount.CurrencyCode;
feeShipmentEvent.shipping_credits_tax = (decimal)shipmentItem.ItemChargeAdjustmentList.Where(s => s.ChargeType.Equals("ShippingTax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.ChargeAmount.CurrencyAmount);
feeShipmentEvent.postage_credits = (decimal)shipmentItem.ItemChargeAdjustmentList.Where(s => s.ChargeType.Equals("ShippingCharge", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.ChargeAmount.CurrencyAmount);
feeShipmentEvent.product_sales_tax = (decimal)shipmentItem.ItemChargeAdjustmentList.Where(s => s.ChargeType.Equals("Tax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.ChargeAmount.CurrencyAmount);
feeShipmentEvent.selling_fees = (decimal)shipmentItem.ItemFeeAdjustmentList.Where(s => sellingFeesList.Any(f1 => s.FeeType.Equals(f1, StringComparison.InvariantCultureIgnoreCase))).Sum(s => s.FeeAmount.CurrencyAmount);
feeShipmentEvent.gift_wrap_credits = (decimal)shipmentItem.ItemChargeAdjustmentList.Where(s => s.ChargeType.Equals("GiftWrap", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.ChargeAmount.CurrencyAmount);
feeShipmentEvent.gift_wrap_credits_tax = (decimal)shipmentItem.ItemChargeAdjustmentList.Where(s => s.ChargeType.Equals("GiftWrapTax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.ChargeAmount.CurrencyAmount);
feeShipmentEvent.product_sales = (decimal)shipmentItem.ItemChargeAdjustmentList.Where(s => s.ChargeType.Equals("Principal", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.ChargeAmount.CurrencyAmount);
}
}
else
{
feeShipmentEvent.currency_code = shipmentItem.ItemFeeList.FirstOrDefault()?.FeeAmount.CurrencyCode;
if (shipmentItem.ItemFeeList != null && shipmentItem.ItemFeeList.Count >= 1)
{
feeShipmentEvent.fba_fees = (decimal)shipmentItem.ItemFeeList.Where(s => fbaFeeTypeList.Any(f1 => f1.Equals(s.FeeType, StringComparison.InvariantCultureIgnoreCase))).Sum(s => s.FeeAmount.CurrencyAmount);
feeShipmentEvent.tax_collection_model = shipmentItem.ItemTaxWithheldList.FirstOrDefault().TaxCollectionModel;
feeShipmentEvent.marketplace_withheld_tax = (decimal)shipmentItem.ItemTaxWithheldList.Sum(s => s.TaxesWithheld.Sum(s1 => s1.ChargeAmount.CurrencyAmount));
feeShipmentEvent.selling_fees = (decimal)shipmentItem.ItemFeeList.Where(s => sellingFeesList.Any(f1 => s.FeeType.Equals(f1, StringComparison.InvariantCultureIgnoreCase))).Sum(s => s.FeeAmount.CurrencyAmount);
}
feeShipmentEvent.currency_code = shipmentItem.ItemChargeList.FirstOrDefault()?.ChargeAmount.CurrencyCode;
if (shipmentItem.ItemTaxWithheldList != null && shipmentItem.ItemTaxWithheldList.Count >= 1)
{
feeShipmentEvent.tax_collection_model = shipmentItem.ItemTaxWithheldList?.FirstOrDefault()?.TaxCollectionModel;
feeShipmentEvent.marketplace_withheld_tax = (decimal)shipmentItem.ItemTaxWithheldList?.Sum(s => s.TaxesWithheld.Sum(s1 => s1.ChargeAmount.CurrencyAmount));
}
if (shipmentItem.ItemChargeList != null && shipmentItem.ItemChargeList.Count >= 1)
{
feeShipmentEvent.shipping_credits_tax = (decimal)shipmentItem.ItemChargeList.Where(s => s.ChargeType.Equals("ShippingTax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.ChargeAmount.CurrencyAmount);
feeShipmentEvent.postage_credits = (decimal)shipmentItem.ItemChargeList.Where(s => s.ChargeType.Equals("ShippingCharge", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.ChargeAmount.CurrencyAmount);
feeShipmentEvent.product_sales_tax = (decimal)shipmentItem.ItemChargeList.Where(s => s.ChargeType.Equals("Tax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.ChargeAmount.CurrencyAmount);
feeShipmentEvent.selling_fees = (decimal)shipmentItem.ItemFeeList.Where(s => sellingFeesList.Any(f1 => s.FeeType.Equals(f1, StringComparison.InvariantCultureIgnoreCase))).Sum(s => s.FeeAmount.CurrencyAmount);
feeShipmentEvent.gift_wrap_credits = (decimal)shipmentItem.ItemChargeList.Where(s => s.ChargeType.Equals("GiftWrap", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.ChargeAmount.CurrencyAmount);
feeShipmentEvent.gift_wrap_credits_tax = (decimal)shipmentItem.ItemChargeList.Where(s => s.ChargeType.Equals("GiftWrapTax", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.ChargeAmount.CurrencyAmount);
feeShipmentEvent.product_sales = (decimal)shipmentItem.ItemChargeList.Where(s => s.ChargeType.Equals("Principal", StringComparison.InvariantCultureIgnoreCase)).Sum(s => s.ChargeAmount.CurrencyAmount);
}
}
feeShipmentEvent.quantity = (shipmentItem.QuantityShipped ?? 0).ToString();
feeShipmentEvent.promotional_rebates = 0;
......@@ -296,6 +325,7 @@ namespace AutoTurnOver.Services
queryParameters.Add("MaxResultsPerPage", "100");
queryParameters.Add("PostedAfter", btime.AddHours(-8).ToString("yyyy-MM-ddTHH:mm:ssZ"));
queryParameters.Add("PostedBefore", etime.AddHours(-8).ToString("yyyy-MM-ddTHH:mm:ssZ"));
queryParameters.Add("Marketplace", account.MarketPlaceObj.multiMwsMid);
}
string response = getResponse(account, "/finances/v0/financialEvents", Method.Get, false, null, queryParameters);
......
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