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_tail*"+(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 from dc_base_oms_pick t1";
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_tail*"+(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 from (select id,bailun_order_id,quantity_shipped 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 t2.bailun_order_status != 'Canceled' and t2.has_scalp = 0 and t2.bailun_order_status != 'CantHandle' and t2.has_scalp = 0 and t2.has_innersale = 0 ";
//where t1.shipping_status = 'TotalShipping' and t1.shipping_time >= '2019-06-14' and t1.shipping_time < '2019-06-15' and t1.company_id = 1
//GROUP BY t2.platform_type";
if(companyid.HasValue&&companyid.Value>0)
{
sql+=" and company_id="+companyid.Value;//增加公司id过滤
}
if(shipstart.HasValue)
{
sql+=" and shipping_time>='"+shipstart.Value.ToString("yyyy-MM-dd")+"'";
}
if(shipend.HasValue)
{
sql+=" and 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 t2.bailun_order_status != 'Canceled' and t2.has_scalp = 0 and t2.bailun_order_status != 'CantHandle' and t2.has_scalp = 0 and t2.has_innersale = 0 ";
varsql=@"select t2.hq_type as warehousetype,t2.warehouse_name as warehousename,t2.warehouse_code,t1.bailun_sku as sku,t3.category_id,t3.category_name,t3.sku_title_cn as skuname,(case when t4.status=0 then 1 else 2 end) monitorstatus,t5.clearancestatus,t5.tortstatus,t5.str_skutag,t3.unit_price as buyprice,t1.usable_stock,(t1.usable_stock*t3.unit_price) amount_stock,t6.quantity_purchase,(t6.quantity_purchase*t3.unit_price) as purchase_amount,t6.quantity_transfer,(t6.quantity_transfer*t3.unit_price) amount_transit,t6.quantity_out_stock,t7.oneday_total_sales,(t7.oneday_total_sales*t3.unit_price) as amount_onedaysale,t7.sevenday_total_sales,(t7.sevenday_total_sales*t3.unit_price) amount_sevendaysale,t7.fourteenday_total_sales,t7.thirtyday_total_sales,t7.sevenday_average_sales,t7.fourteenday_average_sales,t7.thirtyday_average_sales,t3.create_time as skucreatetime,t2.area_id,t2.area_name,t5.groupname,t6.quantity_unshipped
varsql=@"select t2.hq_type as warehousetype,t2.warehouse_name as warehousename,t2.warehouse_code,t1.bailun_sku as sku,t3.category_id,t3.category_name,t3.sku_title_cn as skuname,(case when t4.status=1 then 0 else 1 end) status,t5.clearancestatus,t5.tortstatus,t5.str_skutag,t3.unit_price as buyprice,t1.usable_stock,(t1.usable_stock*t3.unit_price) amount_stock,t6.quantity_purchase,(t6.quantity_purchase*t3.unit_price) as purchase_amount,t6.quantity_transfer,(t6.quantity_transfer*t3.unit_price) amount_transit,t6.quantity_out_stock,t7.oneday_total_sales,(t7.oneday_total_sales*t3.unit_price) as amount_onedaysale,t7.sevenday_total_sales,(t7.sevenday_total_sales*t3.unit_price) amount_sevendaysale,t7.fourteenday_total_sales,t7.thirtyday_total_sales,t7.sevenday_average_sales,t7.fourteenday_average_sales,t7.thirtyday_average_sales,t3.create_time as skucreatetime,t2.area_id,t2.area_name,t5.groupname,t6.quantity_unshipped
from dc_base_stock t1
from dc_base_stock t1
left join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code
left join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code
left join dc_base_sku t3 on t1.bailun_sku=t3.bailun_sku
left join dc_base_sku t3 on t1.bailun_sku=t3.bailun_sku