varsql="select platform_type, sum(amount_sales*seller_order_exchange_rate*bailun_sku_quantity_shipped) amount_sales,count(bailun_order_id) order_count,sum(cost_platform_fee*seller_order_exchange_rate*bailun_sku_quantity_shipped) cost_platform_fee,(sum(amount_sales*seller_order_exchange_rate*bailun_sku_quantity_shipped)/count(bailun_order_id)) customerprice,sum(profit_total*bailun_sku_quantity_shipped) profit_total,(sum(profit_total*bailun_sku_quantity_shipped)/sum(amount_sales*seller_order_exchange_rate*bailun_sku_quantity_shipped)) profitrate,sum(amount_refund*seller_order_exchange_rate*bailun_sku_quantity_shipped) amount_refund,sum(cost_first*bailun_sku_quantity_shipped) cost_first,sum(cost_tail*bailun_sku_quantity_shipped) cost_tail,sum(cost_handle_bailun*bailun_sku_quantity_shipped) cost_handle_bailun,sum(cost_handle_platform*bailun_sku_quantity_shipped) cost_handle_platform from dc_base_oms_sku where bailun_order_status!='Canceled' and bailun_sku_quantity_shipped>0";
varsql="select tb.platform_type,count(tb.bailun_order_id) order_count,sum(tb.amount_sales) as amount_sales,sum(tb.cost_platform_fee) as cost_platform_fee,sum(cost_first) as cost_first,sum(cost_tail) cost_tail,sum(cost_handle_bailun) cost_handle_bailun,sum(cost_handle_platform) cost_handle_platform,sum(tb.profit_total) as profit_total,(sum(tb.profit_total)/sum(tb.amount_sales)) profitrate ,sum(amount_refund) amount_refund from (select bailun_order_id,platform_type,sum(amount_sales*seller_order_exchange_rate*bailun_sku_quantity_shipped) amount_sales,sum(cost_platform_fee*seller_order_exchange_rate*bailun_sku_quantity_shipped) cost_platform_fee,sum(profit_total*bailun_sku_quantity_shipped) profit_total,sum(amount_refund*seller_order_exchange_rate*bailun_sku_quantity_shipped) amount_refund,sum(cost_first*bailun_sku_quantity_shipped) cost_first,sum(cost_tail*bailun_sku_quantity_shipped) cost_tail,sum(cost_handle_bailun*bailun_sku_quantity_shipped) cost_handle_bailun,sum(cost_handle_platform*bailun_sku_quantity_shipped) cost_handle_platform from dc_base_oms_sku where bailun_order_status!='Canceled' and bailun_sku_quantity_shipped>0";
varpresql="select platform_type,sum(amount_prepaid) amount_prepaid from dc_base_oms_sku where bailun_order_status!='Canceled' and amount_prepaid>0 ";
varpresql="select platform_type,sum(amount_prepaid) amount_prepaid from dc_base_oms_sku where bailun_order_status!='Canceled' and amount_prepaid>0 ";
varprecolumn="select bailun_order_id,sum(amount_prepaid*seller_order_exchange_rate) amount_prepaid from dc_base_oms_sku where bailun_order_status!='Canceled' ";
sql+=" join dc_base_oms_pick t2 on t1.origin_order_id=t2.origin_order_id "+(!string.IsNullOrEmpty(warehousecode)?" and t2.warehouse_code=@warehousecode":"");
sql+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.warehouse_type_ex=@warehoursetype";
sql+=" join dc_base_warehouse t3 on t2.warehouse_code =t3.warehouse_code and hq_type=@warehousetype";
presql+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.warehouse_type_ex=@warehoursetype";
sqlparam.Add("warehoursetype",warehousetype);
presql+=" join dc_base_oms_pick t2 on t1.origin_order_id=t2.origin_order_id "+(!string.IsNullOrEmpty(warehousecode)?" and t2.warehouse_code=@warehousecode":"");
presql+=" join dc_base_warehouse t3 on t2.warehouse_code =t3.warehouse_code and hq_type=@warehousetype";
sqlparam.Add("warehousetype",warehousetype);
if(!string.IsNullOrEmpty(warehousecode))
{
sqlparam.Add("warehousecode",warehousecode);
}
}
}
elseif(!string.IsNullOrEmpty(warehousecode))
if(!string.IsNullOrEmpty(warehousecode))
{
{
sql+=" join dc_base_oms_pick t2 on t1.origin_order_id=t2.origin_order_id and t2.warehouse_code=@warehousecode";
if(!string.IsNullOrEmpty(warehousetype))
presql+=" join dc_base_oms_pick t2 on t1.origin_order_id=t2.origin_order_id and t2.warehouse_code=@warehousecode";
{
sqlparam.Add("warehousecode",warehousecode);
sql+=" and t2.warehouse_code=@warehouse_code";
presql+=" and t2.warehouse_code=@warehouse_code";
sqlparam.Add("warehouse_code",warehousecode);
}
else
{
sql+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.warehouse_code=@warehouse_code";
presql+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.warehouse_code=@warehouse_code";
sqlparam.Add("warehouse_code",warehousecode);
}
}
}
varfromsql=" where platform_type='Ebay' and bailun_order_status!='Canceled' ";
if(!string.IsNullOrWhiteSpace(account))
if(!string.IsNullOrWhiteSpace(account))
{
{
sqlwhere+=" and t1.seller_account=@seller_account";
fromsql+=" and t1.seller_account=@seller_account";
sqlparam.Add("seller_account",account);
sqlparam.Add("seller_account",account);
}
}
if(!string.IsNullOrWhiteSpace(website))
if(!string.IsNullOrWhiteSpace(website))
{
{
sqlwhere+=" and t1.website=@website";
fromsql+=" and t1.website=@website";
sqlparam.Add("website",website);
sqlparam.Add("website",website);
}
}
if(start.HasValue)
if(start.HasValue)
{
{
sqlwhere+=" and t1.paid_time>='"+start.Value.ToString("yyyy-MM-dd")+"'";
fromsql+=" and t1.paid_time>='"+start.Value.ToString("yyyy-MM-dd")+"'";
}
}
if(end.HasValue)
if(end.HasValue)
{
{
sqlwhere+=" and t1.paid_time<'"+end.Value.AddDays(1).ToString("yyyy-MM-dd")+"'";
fromsql+=" and t1.paid_time<'"+end.Value.AddDays(1).ToString("yyyy-MM-dd")+"'";
}
}
varprefromsql=sqlwhere;
varprefromsql=fromsql;
sqlwhere+=" and bailun_sku_quantity_shipped>0";
fromsql+=" and bailun_sku_quantity_shipped>0";
sqlwhere+=" group by t1.seller_account,t1.platform_type";
fromsql+=" group by seller_account,website,order_currency,platform_type";
if(!string.IsNullOrWhiteSpace(parameter.sort))
if(!string.IsNullOrWhiteSpace(parameter.sort))
{
{
sqlwhere+=" order by "+parameter.sort+" "+parameter.order;
fromsql+=" order by "+parameter.sort+" "+parameter.order;
prefromsql+=" and bailun_sku_quantity_shipped<=0";
prefromsql+=" and bailun_sku_quantity_shipped<=0";
prefromsql+=" and seller_account in ('"+string.Join("','",list.Select(a=>a.seller_account))+"')";
prefromsql+=" and seller_account in ('"+string.Join("','",list.Select(a=>a.seller_account))+"') and website in ('"+string.Join("','",list.Select(a=>a.website))+"') and order_currency in ('"+string.Join("','",list.Select(a=>a.order_currency))+"')";
prefromsql+=" group by seller_account,platform_type";
prefromsql+=" group by seller_account,website,order_currency,platform_type";