varsql="select tb.platform_type,count(tb.bailun_order_id) order_count,sum(tb.amount_sales*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") 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")+"))) as cost_platform_fee,sum(tb.cost_first*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") as cost_first,sum(tb.cost_tail*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") cost_tail,sum(tb.cost_handle_bailun*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") cost_handle_bailun,sum(tb.cost_handle_platform*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") cost_handle_platform,sum(tb.amount_refund*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") amount_refund,sum(tb.cost_fba_fee*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") cost_fba_fee,sum(tb.cost_paypal_fee*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") cost_paypal_fee,sum(tb.amount_shipping*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") amount_shipping,sum(tb.cost_promotion*"+(isUSD?"tb.order_to_usd_exchange_rate":"tb.seller_order_exchange_rate")+") cost_promotion,sum(tb.cost_product*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") cost_product,sum(tb.profit_total*"+(isUSD?"tb.cny_to_usd_exchange_rate":"1")+") 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")+") amount_prepaid from dc_base_oms_order tb ";
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') ";
varsql="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
//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 ";
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";
sql+=" join dc_base_sku t10 on tb.bailun_sku=t10.bailun_sku ";
if(producttype.HasValue)
{
sql+=" and t10.product_type="+producttype.Value;
}
if(skusource.HasValue)
{
sql+=" and t10.source="+skusource;
}
if(shippingstrategy.HasValue)//1专线;2中国发货;3美国仓
{
}
}
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(companyid.HasValue&&companyid.Value>0)
{
sql+=" and tb.company_id="+companyid.Value;//增加公司id过滤
varsql=@"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 id,bailun_order_id,quantity_shipped,bailun_sku from dc_base_oms_pick where has_delete=0 and shipping_status = 'TotalShipping' ";
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 ";
varsql=$"select t1.platform_type,{(isUSD?"sum(t1.amount_refund_usd)":"sum(t1.amount_refund_rmb)")} as amount_refund from dc_base_crm_refund t1 where t1.shipping_status='TotalShipping' and t1.is_deleted=0 and is_freeze=0 ";
varsql=$"select t1.platform_type,{(isUSD?"sum(t1.amount_refund_usd)":"sum(t1.amount_refund_rmb)")} as amount_refund from dc_base_crm_refund t1 ";