Commit 8afac2ab by guanzhenshan

调整sku利润统计报表,增加ebay广告费、上架费、亚马逊广告费和退款数据

parent b7ff9ccd
......@@ -230,5 +230,7 @@ namespace Bailun.DC.Models
/// 站点
/// </summary>
public string site_en { get; set; }
public string platform { get; set; }
}
}
......@@ -123,5 +123,7 @@ namespace Bailun.DC.Models
/// 帐号
/// </summary>
public string account_name { get; set; }
public string platform { get; set; }
}
}
......@@ -1645,7 +1645,6 @@ namespace Bailun.DC.Services
}
/// <summary>
/// 获取平台利润
/// </summary>
......@@ -1883,7 +1882,6 @@ namespace Bailun.DC.Services
}
/// <summary>
/// 根据发货时间获取平台利润统计
/// </summary>
......@@ -3504,6 +3502,130 @@ namespace Bailun.DC.Services
}
/// <summary>
/// 获取Ebay的费用统计
/// </summary>
/// <param name="companyid"></param>
/// <param name="start"></param>
/// <param name="end"></param>
/// <param name="total"></param>
/// <param name="feetype"></param>
/// <returns></returns>
public List<dc_base_finance_ebay> EbayFeeCount(int? companyid, DateTime? start, DateTime? end, string[] feetype, string orderno, string account, bool isUSD, string itemid, int[] producttype, int? skusource, int? shippingstrategy, int statistictype)
{
var sqlparam = new DynamicParameters();
var sql = $"select sum(t1.gross_amount) gross_amount,sum(t1.net_amount) net_amount,sum(t1.{(isUSD ? "exchange_rate_usd" : "exchange_rate")}*t1.gross_amount) gross_amount_rmb from dc_base_finance_ebay t1 ";
if (!string.IsNullOrWhiteSpace(account))
{
sql += " join dc_base_company_account t2 on t1.company_id=t2.company_id and t1.account_id=t2.account_id ";
sql += " and t2.account_name=@account_name ";
sqlparam.Add("account_name", account);
}
//Add by Allan at 20200320
if ((producttype != null && producttype.Count() > 0) || skusource.HasValue || shippingstrategy.HasValue || statistictype!=0)
{
var s = "";
if (statistictype == 1) //sku产品类型
{
s = " t10.bailun_category_id as platform,";
}
else if (statistictype == 2) //sku来源
{
s = " t10.source as platform,";
}
sql = $"select {s}0 gross_amount,0 net_amount,sum(t1.{(isUSD ? "exchange_rate_usd" : "exchange_rate")}*t1.sku_amount*t1.sku_count) gross_amount_rmb from dc_base_finance_ebay_item t1 ";
sqlparam = new DynamicParameters();
if (!string.IsNullOrWhiteSpace(account))
{
sql += " join dc_base_company_account t2 on t1.company_id=t2.company_id and t1.account_id=t2.account_id ";
sql += " and t2.account_name=@account_name ";
sqlparam.Add("account_name", account);
}
sql += " join dc_base_sku t10 on t1.bailun_sku=t10.bailun_sku ";
if (producttype.Count() > 0)
{
sql += " and t10.bailun_category_id in (" + string.Join(",", producttype) + ") ";
}
if (skusource.HasValue)
{
sql += " and t10.source=" + skusource;
}
if (shippingstrategy.HasValue) //1专线;2中国发货;3美国仓
{
}
}
sql += " where t1.id!=0 ";
if (start.HasValue)
{
sql += " and t1.bj_date>=@start";
sqlparam.Add("start", start.Value);
}
if (end.HasValue)
{
sql += " and t1.bj_date<@end";
sqlparam.Add("end", end.Value.AddDays(1));
}
if (companyid.HasValue && companyid.Value > 0)
{
sql += " and t1.company_id=@companyid";
sqlparam.Add("companyid", companyid.Value);
}
if (!string.IsNullOrEmpty(orderno))
{
sql += " and t1.order_line_id=@orderno";
sqlparam.Add("orderno", orderno);
}
if (!string.IsNullOrWhiteSpace(itemid))
{
sql += " and t1.item_id=@item_id";
sqlparam.Add("item_id", itemid);
}
if (feetype != null && feetype.Length > 0)
{
sql += " and t1.account_entry_type in ('" + string.Join("','", feetype) + "')";
}
if (statistictype == 1) //1:sku品类
{
sql += "group by t10.bailun_category_id";
}
else if (statistictype == 2) //2:sku来源
{
sql += "group by t10.source";
}
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
var obj = cn.Query<dc_base_finance_ebay>(sql, sqlparam).ToList();
return obj;
}
}
/// <summary>
/// 获取汇损费用列表
/// </summary>
/// <param name="parameter"></param>
......@@ -5338,23 +5460,23 @@ namespace Bailun.DC.Services
if (statistictype == 1) //sku品类
{
str_statistic_col = "t10.bailun_category_id as platform_type";
}
else if (statistictype == 2) //sku来源
{
str_statistic_col = "t60.source as platform_type";
str_statistic_col = "t10.source as platform_type";
}
var sqlparam = new DynamicParameters();
var sql = $"select {str_statistic_col},{(isUSD? "sum(t1.amount_refund_usd)" : "sum(t1.amount_refund_rmb)")} as amount_refund from dc_base_crm_refund t1 ";
if ((producttype!=null && producttype.Count()>0) || skusource.HasValue || shippingstrategy.HasValue)
if ((producttype!=null && producttype.Count()>0) || skusource.HasValue || shippingstrategy.HasValue || statistictype!=0)
{
sql += " join dc_base_sku t10 on t1.bailun_sku=t10.bailun_sku ";
if (producttype.Count()>0)
if (producttype!=null && producttype.Count()>0)
{
sql += " and t10.product_type in (" + string.Join(",",producttype)+") ";
sql += " and t10.bailun_category_id in (" + string.Join(",",producttype)+") ";
}
if (skusource.HasValue)
......@@ -5408,7 +5530,7 @@ namespace Bailun.DC.Services
}
else if (statistictype == 2) //sku来源
{
sql += " join dc_base_sku t60 on t1.bailun_sku=t60.bailun_sku and t60.source in (1,2,3,6,7,11) ";
sql += " and t10.source in (1,2,3,6,7,11) ";
}
sql += " where t1.shipping_status='TotalShipping' and t1.is_deleted=0 and is_freeze=0 ";
......@@ -5454,11 +5576,11 @@ namespace Bailun.DC.Services
}
else if (statistictype == 1)
{
sql += " group by t10.bailun_category_id";
}
else if (statistictype == 2)
{
sql += " group by t60.source";
sql += " group by t10.source";
}
......@@ -5631,7 +5753,7 @@ namespace Bailun.DC.Services
if (producttype.Count()>0)
{
sql += " and t10.product_type in (" + string.Join(",",producttype)+") ";
sql += " and t10.bailun_category_id in (" + string.Join(",",producttype)+") ";
}
if (skusource.HasValue)
......@@ -5681,6 +5803,113 @@ namespace Bailun.DC.Services
}
/// <summary>
/// 亚马逊广告费汇总
/// </summary>
/// <param name="account"></param>
/// <param name="start"></param>
/// <param name="end"></param>
/// <param name="companyid"></param>
/// <returns></returns>
public List<dc_base_finance_amazon_ad_product> ListAmazonADSkuCount(string account, DateTime? start, DateTime? end, int? companyid, bool isUSD, int[] producttype, int? skusource, int? shippingstrategy,int statistictype)
{
var sqlparam = new DynamicParameters();
var sql = $"select sum(cost) cost,sum(cost*{(isUSD ? "exchange_rate_usd" : "exchange_rate")}) cost_rmb from dc_base_finance_amazon_ad_product t1 join dc_base_company_account t2 on t1.account_id=t2.account_id ";
if (!string.IsNullOrEmpty(account))
{
sql += " and t2.account_name=@account";
sqlparam.Add("account", account);
}
//Add by Allan at 20200320
if ((producttype != null && producttype.Count() > 0) || skusource.HasValue || shippingstrategy.HasValue || statistictype!=0)
{
var s = "";
if (statistictype == 1)
{
s = " t10.bailun_category_id as platform,";
}
else if (statistictype == 2)
{
s = " t10.source as platform,";
}
sql = $"select {s} sum(cost) cost,sum(cost*{(isUSD ? "exchange_rate_usd" : "exchange_rate")}) cost_rmb from dc_base_finance_amazon_item t1 join dc_base_company_account t2 on t1.account_id=t2.account_id ";
sqlparam = new DynamicParameters();
if (!string.IsNullOrEmpty(account))
{
sql += " and t2.account_name=@account";
sqlparam.Add("account", account);
}
sql += " join dc_base_sku t10 on t1.bailun_sku=t10.bailun_sku ";
if (producttype.Count() > 0)
{
sql += " and t10.bailun_category_id in (" + string.Join(",", producttype) + ") ";
}
if (skusource.HasValue)
{
sql += " and t10.source=" + skusource;
}
if (shippingstrategy.HasValue) //1专线;2中国发货;3美国仓
{
}
}
sql += " where t1.id!=0 ";
if (companyid.HasValue && companyid.Value > 0)
{
sql += " and t1.company_id=@companyid";
sqlparam.Add("companyid", companyid);
}
if (start.HasValue)
{
sql += " and t1.report_date>=@start";
sqlparam.Add("start", start.Value);
}
if (end.HasValue)
{
sql += " and t1.report_date<@end";
sqlparam.Add("end", end.Value.AddDays(1));
}
if (statistictype == 1)
{
sql += " group by t10.bailun_category_id ";
}
else if (statistictype == 2)
{
sql += " group by t10.source ";
}
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
var obj = cn.Query<dc_base_finance_amazon_ad_product>(sql, sqlparam).ToList();
return obj;
}
}
#endregion
#region Wish
......
......@@ -1591,6 +1591,12 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
var wishAD = new dc_base_finance_wish();
var aliexpressAD = new dc_base_finance_aliexpress();
var listebayADFee = new List<dc_base_finance_ebay>();
var listebayPutAway = new List<dc_base_finance_ebay>();
var listamazonAD = new List<dc_base_finance_amazon_ad_product>();
var ADfeeType = new string[] {
"FeeAd"
};
......@@ -1770,6 +1776,13 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
aliexpressAD = _service.ListAliexpressADCount(companyid, "", dtstart, dtend, currency.ToUpper() == "USD");
wishAD = _service.ListWishADCount(companyid, null, dtstart, dtend, currency.ToUpper() == "USD");
}
else
{
listebayADFee = _service.EbayFeeCount(companyid, dtstart, dtend, ADfeeType, "", "", currency.ToUpper() == "USD", "", producttype, skusource, shippingstrategy, statistictype);
listebayPutAway = _service.EbayFeeCount(companyid, dtstart, dtend, PutAwayFeeType, "", "", currency.ToUpper() == "USD", "", producttype, skusource, shippingstrategy,statistictype);
listamazonAD = _service.ListAmazonADSkuCount("", dtstart, dtend, companyid, currency.ToUpper() == "USD", producttype, skusource, shippingstrategy,statistictype);
}
//aliexpressAD = _service.ListAliexpressADCount(companyid, "", dtstart, dtend, currency.ToUpper() == "USD");
......@@ -1794,13 +1807,24 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
listRefund = _service.ListPlatformRefund(dtstart, dtend, companyid, platform, website, currency.ToUpper() == "USD", true, null, null, null,statistictype); //包含未发货的退款金额
}
ebayADFee = _service.EbayFeeCount(companyid, dtstart, dtend, ADfeeType, "", "", currency.ToUpper() == "USD", "",null,null,null);
ebayPutAway = _service.EbayFeeCount(companyid, dtstart, dtend, PutAwayFeeType, "", "", currency.ToUpper() == "USD", "",null,null,null);
if (statistictype == 0)
{
ebayADFee = _service.EbayFeeCount(companyid, dtstart, dtend, ADfeeType, "", "", currency.ToUpper() == "USD", "", null, null, null);
ebayPutAway = _service.EbayFeeCount(companyid, dtstart, dtend, PutAwayFeeType, "", "", currency.ToUpper() == "USD", "", null, null, null);
amazonAD = _service.ListAmazonADSkuCount("", dtstart, dtend, companyid, currency.ToUpper() == "USD",null,null,null);
amazonAD = _service.ListAmazonADSkuCount("", dtstart, dtend, companyid, currency.ToUpper() == "USD", null, null, null);
wishAD = _service.ListWishADCount(companyid, null, dtstart, dtend, currency.ToUpper() == "USD");
aliexpressAD = _service.ListAliexpressADCount(companyid, "", dtstart, dtend, currency.ToUpper() == "USD");
}
else
{
listebayADFee = _service.EbayFeeCount(companyid, dtstart, dtend, ADfeeType, "", "", currency.ToUpper() == "USD", "", producttype, skusource, shippingstrategy, statistictype);
listebayPutAway = _service.EbayFeeCount(companyid, dtstart, dtend, PutAwayFeeType, "", "", currency.ToUpper() == "USD", "", producttype, skusource, shippingstrategy, statistictype);
listamazonAD = _service.ListAmazonADSkuCount("", dtstart, dtend, companyid, currency.ToUpper() == "USD", producttype, skusource, shippingstrategy, statistictype);
}
}
if (statistictype == 1) //按产品类型统计时,格式化数据
{
......@@ -1824,6 +1848,12 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
var children = result.Where(a => arrcategory.Contains(a.platform_type)).ToList();
var children_EbayAD = listebayADFee.Where(a => arrcategory.Contains(a.platform)).ToList();
var children_EbayPutAway = listebayPutAway.Where(a => arrcategory.Contains(a.platform)).ToList();
var children_AmazonAD = listamazonAD.Where(a => arrcategory.Contains(a.platform)).ToList();
var children_Return = listRefund.Where(a => arrcategory.Contains(a.platform_type)).ToList();
var m = result.Where(a => a.platform_type == item.c_id.ToString()).FirstOrDefault();
if (children.Count > 0)
......@@ -1832,7 +1862,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
{
m = new Models.Orders.dc_base_oms_sku {
id = item.c_id,
platform_type= item.c_name,
platform_type = item.c_name,
cost_platform_fee = 0,
profit_total = 0,
amount_refund = 0,
......@@ -1848,6 +1878,9 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
cost_paypal_fee = 0,
order_count = 0,
customerprice = 0,
adfee = 0,
putawayfee = 0,
};
}
......@@ -1857,7 +1890,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
m.cost_platform_fee += children.Sum(a => a.cost_platform_fee);
m.profit_total += children.Sum(a => a.profit_total);
m.amount_refund += children.Sum(a => a.amount_refund);
//m.amount_refund += children.Sum(a => a.amount_refund);
m.amount_sales += children.Sum(a => a.amount_sales);
m.cost_first += children.Sum(a => a.cost_first);
......@@ -1869,6 +1902,10 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
m.cost_fba_fee += children.Sum(a => a.cost_fba_fee);
m.cost_paypal_fee += children.Sum(a => a.cost_paypal_fee);
m.adfee += (children_EbayAD.Count > 0 ? children_EbayAD.Sum(a => a.gross_amount_rmb) : 0) + (children_AmazonAD.Count > 0 ? children_AmazonAD.Sum(a => a.cost_rmb) : 0);
m.putawayfee += (children_EbayPutAway.Count > 0 ? children_EbayPutAway.Sum(a => a.gross_amount_rmb) : 0);
m.amount_refund += (children_Return.Count > 0 ? children_Return.Sum(a => a.amount_refund) : 0);
m.amount_refund_rate = (m.amount_sales > 0 ? m.amount_refund / m.amount_sales : 0);
}
if (m != null)
......@@ -1885,6 +1922,8 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
foreach (var item in result)
{
if (statistictype == 0)
{
item.adfee = 0;
item.putawayfee = 0;
......@@ -1895,7 +1934,7 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
item.putawayfee = ebayPutAway != null ? ebayPutAway.gross_amount_rmb : 0;
item.profit_total = (item.profit_total - (item.adfee ?? 0) - (item.putawayfee ?? 0));
item.profit_rate = item.amount_sales != 0?Math.Round((item.profit_total / item.amount_sales), 2):0;
item.profit_rate = item.amount_sales != 0 ? Math.Round((item.profit_total / item.amount_sales), 2) : 0;
}
else if (item.platform_type.ToLower() == "fba") //亚马逊广告费
......@@ -1903,23 +1942,59 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
item.adfee = amazonAD != null ? amazonAD.cost_rmb : 0;
item.profit_total = (item.profit_total - item.adfee ?? 0);
item.profit_rate = item.amount_sales != 0 ? Math.Round((item.profit_total / item.amount_sales), 2):0;
item.profit_rate = item.amount_sales != 0 ? Math.Round((item.profit_total / item.amount_sales), 2) : 0;
}
else if (item.platform_type.ToLower() == "wish") //Wish广告费
{
item.adfee = wishAD != null ? wishAD.daily_total_campaign_spend : 0;
item.profit_total = (item.profit_total - item.adfee ?? 0);
item.profit_rate = item.amount_sales != 0 ? Math.Round((item.profit_total / item.amount_sales), 2):0;
item.profit_rate = item.amount_sales != 0 ? Math.Round((item.profit_total / item.amount_sales), 2) : 0;
}
else if (item.platform_type.ToLower() == "aliexpress") //速卖通广告费
{
item.adfee = aliexpressAD != null ? aliexpressAD.cost_fee : 0;
item.profit_total = (item.profit_total - item.adfee ?? 0);
item.profit_rate = item.amount_sales != 0 ? Math.Round((item.profit_total / item.amount_sales), 2):0;
item.profit_rate = item.amount_sales != 0 ? Math.Round((item.profit_total / item.amount_sales), 2) : 0;
}
}
else if (statistictype == 1)
{
item.profit_total = item.profit_total - (item.adfee ?? 0) - (item.putawayfee ?? 0);
item.profit_rate = item.amount_sales != 0 ? Math.Round((item.profit_total / item.amount_sales), 2) : 0;
}
else if (statistictype == 2) //sku来源
{
item.adfee = 0;
item.putawayfee = 0;
var _objEbayAd = listebayADFee.Where(a => a.platform == item.platform_type).FirstOrDefault();
if (_objEbayAd != null)
{
item.adfee += _objEbayAd.gross_amount_rmb;
item.profit_total -= _objEbayAd.gross_amount_rmb;
}
var _objEbayPutAway = listebayPutAway.Where(a => a.platform == item.platform_type).FirstOrDefault();
if (_objEbayPutAway != null)
{
item.putawayfee += _objEbayPutAway.gross_amount_rmb;
item.profit_total -= _objEbayPutAway.gross_amount_rmb;
}
var _objAmazonAD = listamazonAD.Where(a => a.platform == item.platform_type).FirstOrDefault();
if (_objAmazonAD != null)
{
item.adfee += _objAmazonAD.cost_rmb;
item.profit_total -= _objAmazonAD.cost_rmb;
}
item.profit_rate = item.amount_sales != 0 ? Math.Round((item.profit_total / item.amount_sales), 2) : 0;
}
if (statistictype != 1)
{
item.amount_refund = 0;
item.amount_refund_rate = 0;
var objRefund = listRefund.Where(a => a.platform_type.ToLower() == item.platform_type.ToLower()).FirstOrDefault();
......@@ -1931,7 +2006,9 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
//利润减去退款
item.profit_total = (item.profit_total - item.amount_refund);
item.profit_rate = item.amount_sales!=0?Math.Round((item.profit_total / item.amount_sales), 2):0;
item.profit_rate = item.amount_sales != 0 ? Math.Round((item.profit_total / item.amount_sales), 2) : 0;
}
if (statistictype == 2)
......
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