Commit d93a1435 by guanzhenshan

增加指定sku利润特殊处理

parent b3f7294d
......@@ -7,30 +7,29 @@ namespace Bailun.DC.DailyPurchaseSellStock
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("启动服务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Services>();
});
await builder.RunConsoleAsync();
}
//static void Main(string[] args)
//static async Task Main(string[] args)
//{
// var _services = new Services();
// var start = DateTime.Parse("2020-01-01");
// while (start.AddDays(1) < DateTime.Now)
// Console.WriteLine("启动服务 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
// var builder = new HostBuilder().ConfigureServices((hostContext, services) =>
// {
// Console.WriteLine(start);
// _services.Init(start);
// }
// services.AddHostedService<Services>();
// });
// await builder.RunConsoleAsync();
//}
static void Main(string[] args)
{
var _services = new Services();
var start = DateTime.Parse("2020-03-23");
while (start.AddDays(1) < DateTime.Now)
{
Console.WriteLine(start);
_services.Init(start);
start = start.AddDays(1);
}
}
}
}
......@@ -1732,7 +1732,7 @@ namespace Bailun.DC.Services
sql += " and t10.source=" + skusource;
}
if (shippingstrategy.HasValue) //1专线;2中国发货;3美国
if (shippingstrategy.HasValue) //1专线;2中国发货;3海外仓; 4FBA
{
if (shippingstrategy.Value != 1)
{
......@@ -1761,7 +1761,7 @@ namespace Bailun.DC.Services
sql += " where tb.bailun_order_status!='Canceled' and ((tb.platform_type!='FBA' and tb.bailun_order_status!='CantHandle') or tb.platform_type='FBA') and tb.has_scalp=0 and tb.has_innersale=0 and tb.bailun_interception_status in ('None','Failed') ";
if (shippingstrategy.HasValue) //1专线;2中国发货;3美国
if (shippingstrategy.HasValue) //1专线;2中国发货;3海外仓; 4FBA
{
var listSpecialLogistics = CommonServices.ListLogisticsConfig(1);
......@@ -5265,9 +5265,42 @@ namespace Bailun.DC.Services
sql += " and t10.source=" + skusource;
}
if (shippingstrategy.HasValue) //1专线;2中国发货;3美国仓
if (shippingstrategy.HasValue) //1专线;2中国发货;3海外仓; 4FBA仓
{
sql += " join dc_base_oms_sku t11 on t1.bailun_sku=t11.bailun_sku and t1.origin_order_id=t11.origin_order_id and t1.bailun_account_id=t11.bailun_account_id and t11.has_delete=0 ";
if (shippingstrategy.Value == 1)
{
var listSpecialLogistics = CommonServices.ListLogisticsConfig(1);
if (shippingstrategy.Value == 1)
{
sql += " and t11.logistics_method_code in ('" + string.Join("','", listSpecialLogistics.Select(a => a.code)) + "')";
}
else if (shippingstrategy.Value == 2)
{
sql += " and t11.logistics_method_code not in ('" + string.Join("','", listSpecialLogistics.Select(a => a.code)) + "')";
}
}
else
{
sql += " join dc_base_warehouse t20 on t11.warehouse_code = t20.warehouse_code ";
if (shippingstrategy.Value == 2) //中国发货
{
sql += " and t20.area_id=18 ";
}
else if (shippingstrategy.Value == 3) //海外仓
{
sql += " and t20.hq_type='第三方仓库' ";
}
else if (shippingstrategy.Value == 4) //FBA仓
{
sql += " and t20.hq_type='FBA仓' ";
}
}
}
}
......@@ -6327,6 +6360,499 @@ namespace Bailun.DC.Services
#endregion
#region For Sku:FJH-L-2 profit
/// <summary>
/// 获取Sku:FJH-L-2的利润
/// </summary>
/// <param name="platform">平台类型</param>
/// <param name="start">付款开始时间</param>
/// <param name="end">付款结束时间</param>
/// <returns></returns>
public List<Models.Orders.dc_base_oms_sku> ListSkuProfit_FJH_L_2(string platform, string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, bool isUSD, int? companyid, string skucategoryids, int[] producttype, int? skusource, int? shippingstrategy, DateTime? createstart = null, DateTime? createend = null)
{
var sqlparam = new DynamicParameters();
var sql = "select tb.platform_type,count(distinct tb.bailun_order_id) order_count,sum(tb.amount_sales*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "* tb.bailun_sku_quantity_ordered) as amount_sales,sum(tb.cost_platform_fee*(if(tb.platform_type='Ebay'," + (isUSD ? "tb.other_to_usd_exchange_rate" : "tb.seller_other_exchange_rate") + "," + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "))*tb.bailun_sku_quantity_ordered) as cost_platform_fee,sum(tb.cost_first*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + "*tb.bailun_sku_quantity_ordered) as cost_first,sum(tb.cost_tail*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + "*tb.bailun_sku_quantity_ordered) cost_tail,sum(tb.cost_handle_bailun*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + "*tb.bailun_sku_quantity_ordered) cost_handle_bailun,sum(tb.cost_handle_platform*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + "*tb.bailun_sku_quantity_ordered) cost_handle_platform,sum(tb.amount_refund*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "*tb.bailun_sku_quantity_ordered) amount_refund,sum(tb.cost_fba_fee*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "*tb.bailun_sku_quantity_ordered) cost_fba_fee,sum(tb.cost_paypal_fee*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "*tb.bailun_sku_quantity_ordered) cost_paypal_fee,sum(tb.amount_shipping*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "*tb.bailun_sku_quantity_ordered) amount_shipping,sum(tb.cost_promotion*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + "*tb.bailun_sku_quantity_ordered) cost_promotion,sum(tb.cost_product*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + "*tb.bailun_sku_quantity_ordered) cost_product,sum(tb.profit_total*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + "*tb.bailun_sku_quantity_ordered) profit_total,(sum(tb.profit_total*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + ")/sum(tb.amount_sales*" + (isUSD ? "tb.order_to_usd_exchange_rate" : "tb.seller_order_exchange_rate") + ")) profit_rate,count((tb.amount_prepaid>0 and tb.bailun_order_status!='Finished') or null) as noshippingcount,sum(tb.amount_prepaid*" + (isUSD ? "tb.cny_to_usd_exchange_rate" : "1") + "*tb.bailun_sku_quantity_ordered) amount_prepaid from dc_base_oms_sku tb ";
if (shipstart.HasValue || shipend.HasValue)
{
sql += " left join dc_base_oms_pick t1 on tb.bailun_order_id =t1.bailun_order_id ";
}
if (!string.IsNullOrWhiteSpace(skucategoryids))
{
sql += @" join (select distinct bailun_order_id from dc_base_oms_sku t3
join dc_base_sku t4 on t3.bailun_sku=t4.bailun_sku
";
var arr = skucategoryids.Split('|').Where(a => !string.IsNullOrEmpty(a)).ToList();
if (arr.Count > 0)
{
//获取选中分类下所有的分类
//var AllCategory = Services.CommonServices.GetCategoryList(0);
//var listcategory = new List<Models.Common.CategoryDto>();
//foreach (var item in arr)
//{
// listcategory.AddRange(Services.CommonServices.GetCategoryListAll(AllCategory, int.Parse(item)));
//}
var s = string.Join(",", arr);
if (!string.IsNullOrEmpty(s))
{
//sql += " and t3.bailun_category_id in (" + s + ") ";
sql += " and t4.category_simple_id in (" + s + ")";
}
}
sql += " where t3.bailun_order_status!='Canceled' and ((t3.platform_type!='FBA' and t3.bailun_order_status!='CantHandle') or t3.platform_type='FBA') and t3.has_scalp=0 and t3.has_innersale=0 and t3.bailun_interception_status in ('None','Failed') and t3.has_delete=0 and t3.bailun_sku='FJH-L-2' ";
if (companyid.HasValue && companyid.Value > 0)
{
sql += " and t3.company_id=" + companyid.Value; //增加公司id过滤
}
if (!string.IsNullOrWhiteSpace(platform))
{
sql += " and t3.platform_type='" + platform + "'";
}
if (!string.IsNullOrWhiteSpace(website))
{
sql += " and t3.website='" + website + "'";
}
if (start.HasValue)
{
sql += " and t3.paid_time>='" + start.Value.ToString("yyyy-MM-dd") + "'";
}
if (end.HasValue)
{
sql += " and t3.paid_time<'" + end.Value.AddDays(1).ToString("yyyy-MM-dd") + "'";
}
sql += ") t33 on tb.bailun_order_id=t33.bailun_order_id";
}
//Add by Allan at 20200320,for 增加sku级别的利润统计
if ((producttype != null && producttype.Count() > 0) || skusource.HasValue || shippingstrategy.HasValue)
{
sql += $@" join (select t1.bailun_order_id,t2.product_type from dc_base_oms_sku t1
join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku
where t1.bailun_order_id in (select t1.bailun_order_id from dc_base_oms_sku t1
where t1.bailun_sku='FJH-L-2' and t1.bailun_order_status != 'Canceled' and t1.has_scalp = 0 and ((t1.platform_type!='FBA' and t1.bailun_order_status!='CantHandle') or t1.platform_type='FBA') and t1.has_scalp = 0 and t1.has_innersale = 0 and t1.has_delete=0 and t1.paid_time>='{start.Value.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.paid_time<'{end.Value.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss")}'
)
and t1.bailun_sku!='FJH-L-2'
group by t1.bailun_order_id,t2.product_type) t99
on tb.bailun_order_id=t99.bailun_order_id ";
if (producttype.Count() > 0)
{
sql += " and t99.product_type in (" + string.Join(",", producttype) + ") ";
}
if (skusource.HasValue)
{
sql += " join dc_base_sku t10 on tb.bailun_sku=t10.bailun_sku ";
sql += " and t10.source=" + skusource;
}
if (shippingstrategy.HasValue) //1专线;2中国发货;3海外仓; 4FBA仓
{
if (shippingstrategy.Value != 1)
{
sql += " join dc_base_warehouse t20 on tb.warehouse_code = t20.warehouse_code ";
if (shippingstrategy.Value == 2) //中国发货
{
sql += " and t20.area_id=18 ";
}
else if (shippingstrategy.Value == 3) //海外仓
{
sql += " and t20.hq_type='第三方仓库' ";
}
else if (shippingstrategy.Value == 4) //FBA仓
{
sql += " and t20.hq_type='FBA仓' ";
}
}
}
}
sql += " where tb.bailun_order_status!='Canceled' and ((tb.platform_type!='FBA' and tb.bailun_order_status!='CantHandle') or tb.platform_type='FBA') and tb.has_scalp=0 and tb.has_innersale=0 and tb.bailun_interception_status in ('None','Failed') and tb.bailun_sku='FJH-L-2'";
if (shippingstrategy.HasValue) //1专线;2中国发货;3海外仓; 4FBA仓
{
var listSpecialLogistics = CommonServices.ListLogisticsConfig(1);
if (shippingstrategy.Value == 1)
{
sql += " and tb.logistics_method_code in ('" + string.Join("','", listSpecialLogistics.Select(a => a.code)) + "')";
}
else if (shippingstrategy.Value == 2)
{
sql += " and tb.logistics_method_code not in ('" + string.Join("','", listSpecialLogistics.Select(a => a.code)) + "')";
}
}
if (companyid.HasValue && companyid.Value > 0)
{
sql += " and tb.company_id=" + companyid.Value; //增加公司id过滤
}
if (!string.IsNullOrWhiteSpace(platform))
{
sql += " and tb.platform_type=@platform_type";
sqlparam.Add("platform_type", platform);
}
if (!string.IsNullOrWhiteSpace(website))
{
sql += " and tb.website=@website";
sqlparam.Add("website", website);
}
if (start.HasValue)
{
sql += " and tb.paid_time>=@paid_time_start";
sqlparam.Add("paid_time_start", start.Value);
}
if (end.HasValue)
{
sql += " and tb.paid_time<@paid_time_end";
sqlparam.Add("paid_time_end", end.Value.AddDays(1));
}
if (shipstart.HasValue)
{
sql += " and ((tb.platform_type='FBA' and tb.paid_time>=@shipstart) or (tb.platform_type!='FBA' and t1.shipping_time>=@shipstart))";
sqlparam.Add("shipstart", shipstart.Value);
}
if (shipend.HasValue)
{
sql += " and ((tb.platform_type='FBA' and tb.paid_time<@shipend) or (tb.platform_type!='FBA' and t1.shipping_time<@shipend))";
sqlparam.Add("shipend", shipend.Value.AddDays(1));
}
if (createstart.HasValue)
{
sql += " and tb.create_time>=@createstart";
sqlparam.Add("createstart", createstart.Value);
}
if (createend.HasValue)
{
sql += " and tb.create_time<@createend";
sqlparam.Add("createend", createend.Value.AddDays(1));
}
sql += " group by tb.platform_type";
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
var obj = cn.Query<Models.Orders.dc_base_oms_sku>(sql, sqlparam, null, true, 2 * 60);
return obj.AsList();
}
}
/// <summary>
/// 根据发货时间获取Sku:FJH-L-2的利润统计
/// </summary>
/// <param name="platform">平台类型</param>
/// <param name="start">付款开始时间</param>
/// <param name="end">付款结束时间</param>
/// <param name="shipstart">发货开始时间</param>
/// <param name="shipend">发货结束时间</param>
/// <returns></returns>
public List<Models.Orders.dc_base_oms_sku> ListSkuProfit_FJH_L_2_ByShipTime(string platform, string website, DateTime? start, DateTime? end, DateTime? shipstart, DateTime? shipend, bool isUSD, int? companyid, string skucategoryids, int[] producttype, int? skusource, int? shippingstrategy)
{
var sqlparam = new DynamicParameters();
var sql = @"select t2.platform_type,count(DISTINCT t2.bailun_order_id) order_count,sum(t2.amount_sales*" + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "*t1.quantity_shipped) as amount_sales,sum(t2.cost_platform_fee*(if(t2.platform_type='Ebay'," + (isUSD ? "t2.other_to_usd_exchange_rate" : "t2.seller_other_exchange_rate") + "," + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "))*t1.quantity_shipped) as cost_platform_fee,sum(t2.cost_first*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped) as cost_first,sum(t2.cost_logistics*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped) cost_tail,sum(t2.cost_handle_bailun*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped) cost_handle_bailun,sum(t2.cost_handle_platform*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped) cost_handle_platform,sum(t2.amount_refund*" + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "*t1.quantity_shipped) amount_refund,sum(t2.cost_product*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped) cost_product,sum(t2.profit_total*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped) profit_total,(sum(t2.profit_total*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped)/sum(t2.amount_sales*" + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "*t1.quantity_shipped)) profit_rate,count(t2.amount_prepaid>0 or null) as noshippingcount,sum(t2.amount_prepaid*" + (isUSD ? "t2.cny_to_usd_exchange_rate" : "1") + "*t1.quantity_shipped) amount_prepaid,sum(t2.cost_fba_fee*" + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "*t1.quantity_shipped) cost_fba_fee,sum(t2.cost_paypal_fee*" + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "*t1.quantity_shipped) cost_paypal_fee,sum(t2.amount_shipping*" + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "*t1.quantity_shipped) amount_shipping,sum(t2.cost_promotion*" + (isUSD ? "t2.order_to_usd_exchange_rate" : "t2.seller_order_exchange_rate") + "*t1.quantity_shipped) cost_promotion from (select t0.id,t0.bailun_order_id,t0.quantity_shipped,t0.bailun_sku from dc_base_oms_pick t0 ";
var tempsql = "";
if (shippingstrategy.HasValue) //1专线;2中国发货;3海外仓 4 FBA仓
{
var listSpecialLogistics = CommonServices.ListLogisticsConfig(1);
if (shippingstrategy.Value == 1) //专线
{
tempsql = " and t0.logistics_order_id in ('" + string.Join("','", listSpecialLogistics.Select(a => a.code)) + "') ";
}
else if (shippingstrategy.Value == 2) //中国发货
{
sql += " join dc_base_warehouse t2 on t0.warehouse_code=t2.warehouse_code and t2.area_id=18 ";
tempsql = " and t0.logistics_order_id not in ('" + string.Join("','", listSpecialLogistics.Select(a => a.code)) + "') ";
}
else if (shippingstrategy.Value == 3) //海外仓
{
sql += " join dc_base_warehouse t2 on t0.warehouse_code=t2.warehouse_code and t2.hq_type='第三方仓库' ";
}
else if (shippingstrategy.Value == 4) //FBA仓
{
sql += " join dc_base_warehouse t2 on t0.warehouse_code=t2.warehouse_code and t2.hq_type='FBA仓' ";
}
}
sql += " where t0.bailun_sku='FJH-L-2' and t0.has_delete=0 and t0.shipping_status = 'TotalShipping'" + tempsql;
if (companyid.HasValue && companyid.Value > 0)
{
sql += " and t0.company_id=" + companyid.Value; //增加公司id过滤
}
if (shipstart.HasValue)
{
sql += " and t0.shipping_time>='" + shipstart.Value.ToString("yyyy-MM-dd") + "'";
}
if (shipend.HasValue)
{
sql += " and t0.shipping_time<'" + shipend.Value.AddDays(1).ToString("yyyy-MM-dd") + "'";
}
sql += " ) t1 ";
sql += " join dc_base_oms_sku t2 on t1.bailun_order_id = t2.bailun_order_id and t1.bailun_sku=t2.bailun_sku and t2.bailun_order_status != 'Canceled' and t2.has_scalp = 0 and ((t2.platform_type!='FBA' and t2.bailun_order_status!='CantHandle') or t2.platform_type='FBA') and t2.has_scalp = 0 and t2.has_innersale = 0 and t2.has_delete=0 and t2.bailun_sku='FJH-L-2' ";
//Add by Allan at 20200320,for 增加sku级别的利润统计
if ((producttype != null && producttype.Count() > 0) || skusource.HasValue || shippingstrategy.HasValue)
{
sql += $@" join (select t1.bailun_order_id,t2.product_type from dc_base_oms_sku t1
join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku
where t1.bailun_order_id in (select t1.bailun_order_id from dc_base_oms_pick t1
where t1.bailun_sku='FJH-L-2' and t1.bailun_order_status != 'Canceled' and t1.has_scalp = 0 and ((t1.platform_type!='FBA' and t1.bailun_order_status!='CantHandle') or t1.platform_type='FBA') and t1.has_scalp = 0 and t1.has_innersale = 0 and t1.has_delete=0 and t1.shipping_time>='{start.Value.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.shipping_time<'{end.Value.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss")}'
)
and t1.bailun_sku!='FJH-L-2'
group by t1.bailun_order_id,t2.product_type) t99
on t2.bailun_order_id=t99.bailun_order_id ";
if (producttype.Count() > 0)
{
sql += " and t99.product_type in (" + string.Join(",", producttype) + ") ";
}
if (skusource.HasValue)
{
sql += " join dc_base_sku t10 on t2.bailun_sku=t10.bailun_sku ";
sql += " and t10.source=" + skusource;
}
}
if (!string.IsNullOrWhiteSpace(platform))
{
sql += " and t2.platform_type=@platform_type";
sqlparam.Add("platform_type", platform);
}
if (!string.IsNullOrWhiteSpace(website))
{
sql += " and t2.website=@website";
sqlparam.Add("website", website);
}
if (start.HasValue)
{
sql += " and t2.paid_time>=@paid_time_start";
sqlparam.Add("paid_time_start", start.Value);
}
if (end.HasValue)
{
sql += " and t2.paid_time<@paid_time_end";
sqlparam.Add("paid_time_end", end.Value.AddDays(1));
}
if (!string.IsNullOrWhiteSpace(skucategoryids))
{
sql += " join dc_base_sku t4 on t2.bailun_sku=t4.bailun_sku ";
var arr = skucategoryids.Split('|').Where(a => !string.IsNullOrEmpty(a)).ToList();
if (arr.Count > 0)
{
//获取选中分类下所有的分类
//var AllCategory = Services.CommonServices.GetCategoryList(0);
//var listcategory = new List<Models.Common.CategoryDto>();
//foreach (var item in arr)
//{
// listcategory.AddRange(Services.CommonServices.GetCategoryListAll(AllCategory, int.Parse(item)));
//}
var s = string.Join(",", arr);
if (!string.IsNullOrEmpty(s))
{
//sql += " and t4.bailun_category_id in (" + s + ") ";
sql += " and t4.category_simple_id in (" + s + ") ";
}
}
}
var strwhere = " ";
strwhere += " group by t2.platform_type";
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
var obj = cn.Query<Models.Orders.dc_base_oms_sku>(sql + strwhere, sqlparam, null, true, 10 * 60);
return obj.AsList();
}
}
/// <summary>
/// 获取Sku:FJH-L-2的退款数据
/// </summary>
/// <param name="start"></param>
/// <param name="end"></param>
/// <param name="paycompanyid"></param>
/// <param name="platform"></param>
/// <param name="website"></param>
/// <param name="isUSD"></param>
/// <returns></returns>
public List<dc_base_oms_order> ListSku_FJH_L_2_Refund(DateTime? start, DateTime? end, int? companyid, string platform, string website, bool isUSD, bool containNotShipping, int[] producttype, int? skusource, int? shippingstrategy)
{
var sqlparam = new DynamicParameters();
var sql = $"select t1.platform_type,{(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)
{
sql += $@" join (select t1.transaction_id as origin_order_id,t2.product_type from dc_base_oms_sku t1 join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku where (t1.platform_type='Ebay' and t1.transaction_id in (select t1.origin_order_id from dc_base_crm_refund t1 where t1.bailun_sku='FJH-L-2' and t1.shipping_status='TotalShipping' and t1.is_deleted=0 and is_freeze=0 and t1.refund_time>='{start.Value.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.refund_time<'{end.Value.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss")}' )) and t1.bailun_sku!='FJH-L-2' group by t1.bailun_order_id,t2.product_type
union all
select t1.origin_order_id,t2.product_type from dc_base_oms_sku t1 join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku where (t1.platform_type!='Ebay' and t1.origin_order_id in (select t1.origin_order_id from dc_base_crm_refund t1 where t1.bailun_sku='FJH-L-2' and t1.shipping_status='TotalShipping' and t1.is_deleted=0 and is_freeze=0 and t1.refund_time>='{start.Value.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.refund_time<'{end.Value.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss")}' )) and t1.bailun_sku!='FJH-L-2' group by t1.bailun_order_id,t2.product_type) t99
on t1.origin_order_id=t99.origin_order_id ";
if (producttype.Count() > 0)
{
sql += " and t99.product_type in (" + string.Join(",", producttype) + ") ";
}
if (skusource.HasValue)
{
sql += " join dc_base_sku t10 on t1.bailun_sku=t10.bailun_sku ";
sql += " and t10.source=" + skusource;
}
if (shippingstrategy.HasValue) //1专线;2中国发货;3海外仓; 4FBA仓
{
sql += " join dc_base_oms_sku t11 on t1.bailun_sku=t11.bailun_sku and t1.origin_order_id=t11.origin_order_id and t1.bailun_account_id=t11.bailun_account_id and t11.has_delete=0 ";
if (shippingstrategy.Value == 1)
{
var listSpecialLogistics = CommonServices.ListLogisticsConfig(1);
if (shippingstrategy.Value == 1)
{
sql += " and t11.logistics_method_code in ('" + string.Join("','", listSpecialLogistics.Select(a => a.code)) + "')";
}
else if (shippingstrategy.Value == 2)
{
sql += " and t11.logistics_method_code not in ('" + string.Join("','", listSpecialLogistics.Select(a => a.code)) + "')";
}
}
else
{
sql += " join dc_base_warehouse t20 on t11.warehouse_code = t20.warehouse_code ";
if (shippingstrategy.Value == 2) //中国发货
{
sql += " and t20.area_id=18 ";
}
else if (shippingstrategy.Value == 3) //海外仓
{
sql += " and t20.hq_type='第三方仓库' ";
}
else if (shippingstrategy.Value == 4) //FBA仓
{
sql += " and t20.hq_type='FBA仓' ";
}
}
}
}
sql += " where t1.shipping_status='TotalShipping' and t1.is_deleted=0 and is_freeze=0 and t1.bailun_sku='FJH-L-2' ";
if (companyid.HasValue && companyid.Value != 0)
{
sql += " and t1.company_id=" + companyid.Value;
}
if (!string.IsNullOrWhiteSpace(platform))
{
sql += " and t1.platform_type=@platform_type";
sqlparam.Add("platform_type", platform);
}
if (!string.IsNullOrWhiteSpace(website))
{
sql += " and t1.website=@website";
sqlparam.Add("website", website);
}
if (start.HasValue)
{
sql += " and t1.refund_time>=@start";
sqlparam.Add("start", start.Value);
}
if (end.HasValue)
{
sql += " and t1.refund_time<@end";
sqlparam.Add("end", end.Value.AddDays(1));
}
if (!containNotShipping)
{
sql += " and t1.shipping_status!='UnShipping'";
}
sql += " group by t1.platform_type";
using (var cn = new MySqlConnection(Common.GlobalConfig.ConnectionString))
{
if (cn.State == System.Data.ConnectionState.Closed)
{
cn.Open();
}
var obj = cn.Query<dc_base_oms_order>(sql, sqlparam, null, true, 2 * 60);
return obj.AsList();
}
}
#endregion
#region API Service
/// <summary>
......
......@@ -1624,25 +1624,130 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
//Add by Allan at 20200320,for 增加sku级别的利润统计
if (producttype.Length>0 || skusource.HasValue || shippingstrategy.HasValue)
{
if (shipstart.HasValue || shipend.HasValue)
{
result = _service.ListPlatformProfitByShipTime(platform, website, start, end, shipstart, shipend, currency.ToUpper() == "USD", companyid, skucategoryids, producttype, skusource, shippingstrategy);
var fbaResult = _service.ListPlatformProfit(string.IsNullOrEmpty(platform) ? "FBA" : "", website, null, null, null, null, currency.ToUpper() == "USD", companyid, skucategoryids, producttype, skusource, shippingstrategy, shipstart, shipend);
result.AddRange(fbaResult);
dtstart = shipstart;
dtend = shipend;
listRefund = _service.ListPlatformRefund(dtstart, dtend, companyid, platform, website, currency.ToUpper() == "USD", false, producttype, skusource, shippingstrategy); //不包含未发货的退款金额
//针对SKU FJH-L-2 做特殊处理
if (producttype.Length > 0)
{
var result_FJH = _service.ListSkuProfit_FJH_L_2_ByShipTime(platform, website, start, end, shipstart, shipend, currency.ToUpper() == "USD", companyid, skucategoryids, producttype, skusource, shippingstrategy);
var fbaresult_FJH = _service.ListSkuProfit_FJH_L_2(string.IsNullOrEmpty(platform) ? "FBA" : "", website, null, null, null, null, currency.ToUpper() == "USD", companyid, skucategoryids, producttype, skusource, shippingstrategy, shipstart, shipend);
foreach (var item in result)
{
var objFJH = result_FJH.Where(a => a.platform_type == item.platform_type).FirstOrDefault();
if (objFJH != null)
{
item.cost_platform_fee += objFJH.cost_platform_fee;
item.profit_total += objFJH.profit_total;
item.amount_refund += objFJH.amount_refund;
item.amount_sales += objFJH.amount_sales;
item.cost_first += objFJH.cost_first;
item.cost_handle_bailun += objFJH.cost_handle_bailun;
item.cost_handle_platform += objFJH.cost_handle_platform;
item.cost_tail += objFJH.cost_tail;
item.amount_prepaid += objFJH.amount_prepaid;
item.cost_product += objFJH.cost_product;
item.cost_fba_fee += objFJH.cost_fba_fee;
item.cost_paypal_fee += objFJH.cost_paypal_fee;
}
}
foreach (var item in fbaResult)
{
var objFJH = fbaresult_FJH.Where(a => a.platform_type == item.platform_type).FirstOrDefault();
if (objFJH != null)
{
item.cost_platform_fee += objFJH.cost_platform_fee;
item.profit_total += objFJH.profit_total;
item.amount_refund += objFJH.amount_refund;
item.amount_sales += objFJH.amount_sales;
item.cost_first += objFJH.cost_first;
item.cost_handle_bailun += objFJH.cost_handle_bailun;
item.cost_handle_platform += objFJH.cost_handle_platform;
item.cost_tail += objFJH.cost_tail;
item.amount_prepaid += objFJH.amount_prepaid;
item.cost_product += objFJH.cost_product;
item.cost_fba_fee += objFJH.cost_fba_fee;
item.cost_paypal_fee += objFJH.cost_paypal_fee;
}
}
//退款
var listRefund_FJH = _service.ListSku_FJH_L_2_Refund(dtstart, dtend, companyid, platform, website, currency.ToUpper() == "USD", false, producttype, skusource, shippingstrategy); //不包含未发货的退款金额
foreach (var item in listRefund)
{
var objRefundFJH = listRefund_FJH.Where(a => a.platform_type == item.platform_type).FirstOrDefault();
if (objRefundFJH != null)
{
item.amount_refund += objRefundFJH.amount_refund;
}
}
}
result.AddRange(fbaResult);
}
else
{
result = _service.ListPlatformProfit(platform, website, start, end, shipstart, shipend, currency.ToUpper() == "USD", companyid, skucategoryids, producttype, skusource, shippingstrategy);
listRefund = _service.ListPlatformRefund(dtstart, dtend, companyid, platform, website, currency.ToUpper() == "USD", true, producttype, skusource, shippingstrategy); //包含未发货的退款金额
//针对SKU FJH-L-2 做特殊处理
if (producttype.Length > 0)
{
var result_FJH = _service.ListSkuProfit_FJH_L_2(platform, website, start, end, shipstart, shipend, currency.ToUpper() == "USD", companyid, skucategoryids, producttype, skusource, shippingstrategy);
foreach (var item in result)
{
var objFJH = result_FJH.Where(a => a.platform_type == item.platform_type).FirstOrDefault();
if (objFJH != null)
{
item.cost_platform_fee += objFJH.cost_platform_fee;
item.profit_total += objFJH.profit_total;
item.amount_refund += objFJH.amount_refund;
item.amount_sales += objFJH.amount_sales;
item.cost_first += objFJH.cost_first;
item.cost_handle_bailun += objFJH.cost_handle_bailun;
item.cost_handle_platform += objFJH.cost_handle_platform;
item.cost_tail += objFJH.cost_tail;
item.amount_prepaid += objFJH.amount_prepaid;
item.cost_product += objFJH.cost_product;
item.cost_fba_fee += objFJH.cost_fba_fee;
item.cost_paypal_fee += objFJH.cost_paypal_fee;
}
}
//退款
var listRefund_FJH = _service.ListSku_FJH_L_2_Refund(dtstart, dtend, companyid, platform, website, currency.ToUpper() == "USD", false, producttype, skusource, shippingstrategy); //不包含未发货的退款金额
foreach (var item in listRefund)
{
var objRefundFJH = listRefund_FJH.Where(a => a.platform_type == item.platform_type).FirstOrDefault();
if (objRefundFJH != null)
{
item.amount_refund += objRefundFJH.amount_refund;
}
}
}
}
ebayADFee = _service.EbayFeeCount(companyid, dtstart, dtend, ADfeeType, "", "", currency.ToUpper() == "USD", "",producttype,skusource,shippingstrategy);
ebayPutAway = _service.EbayFeeCount(companyid, dtstart, dtend, PutAwayFeeType, "", "", currency.ToUpper() == "USD", "",producttype,skusource,shippingstrategy);
......@@ -1651,6 +1756,7 @@ 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");
//aliexpressAD = _service.ListAliexpressADCount(companyid, "", dtstart, dtend, currency.ToUpper() == "USD");
}
else
{
......@@ -1681,7 +1787,6 @@ namespace Bailun.DC.Web.Areas.Reports.Controllers
}
foreach (var item in result)
{
item.adfee = 0;
......
......@@ -29,8 +29,8 @@
<body class="fixed-sidebar full-height-layout gray-bg" style="overflow:hidden">
<script type="text/javascript">
//login_localhost();
login();
login_localhost();
//login();
window.location = "@Url.Content("~/Home/Main")";
</script>
</body>
......
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