varsql="select sum(amount_sales*seller_order_exchange_rate) amount_sales,sum(cost_platform_fee*seller_order_exchange_rate) as cost_platform_fee,sum(cost_fba_fee*seller_order_exchange_rate) cost_fba_fee,sum(cost_promotion*seller_order_exchange_rate) cost_promotion,sum(cost_paypal_fee*seller_order_exchange_rate) cost_paypal_fee,sum(cost_tail) cost_tail,sum(cost_handle_bailun) cost_handle_bailun from dc_base_oms_order where bailun_order_status!='Canceled' ";
varsql=@"select platform_type,seller_account,website,sum(amount_product*seller_order_exchange_rate) 'amount_product',sum(cost_product) 'cost_product',sum(cost_platform_fee*seller_order_exchange_rate) 'platform_fee',sum(cost_first) 'head_fee',count(id) 'order_count',sum(cost_total) 'cost_count',sum(cost_shipping) 'nofba_logisticsfee',sum(profit_total) 'profit_count',(sum(profit_total)/sum(amount_sales*seller_order_exchange_rate)) 'profit_rate',sum(amount_prepaid) amount_prepaid,sum(amount_refund*seller_order_exchange_rate) amount_refund from dc_base_oms_order where paid_time>='"+start.ToString("yyyy-MM-dd")+"' and paid_time<'"+end.AddDays(1).ToString("yyyy-MM-dd")+"' and platform_type='Amazon' and bailun_order_status!='Canceled' ";
varpresql="select platform_type,seller_account,website,order_currency,sum(amount_prepaid) as amount_prepaid from dc_base_oms_sku t1 ";
if(!string.IsNullOrEmpty(warehoursetype))
{
sql+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.warehouse_type_ex=@warehoursetype";
presql+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.warehouse_type_ex=@warehoursetype";
sqlparam.Add("warehoursetype",warehoursetype);
}
if(!string.IsNullOrEmpty(warehousecode))
{
if(!string.IsNullOrEmpty(warehoursetype))
{
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 paid_time>='"+start.ToString("yyyy-MM-dd")+"' and paid_time<'"+end.AddDays(1).ToString("yyyy-MM-dd")+"' and platform_type='Amazon' and bailun_order_status!='Canceled' ";
if(!string.IsNullOrWhiteSpace(account))
{
sql+=" and seller_account=@seller_account";
fromsql+=" and seller_account=@seller_account";
sqlparam.Add("seller_account",account);
}
if(!string.IsNullOrWhiteSpace(website))
{
sql+=" and website=@website";
fromsql+=" and website=@website";
sqlparam.Add("website",website);
}
sql+=" group by seller_account,website,order_currency,platform_type";
varprefromsql=fromsql;
fromsql+=" and bailun_sku_quantity_shipped>0";
fromsql+=" group by seller_account,website,order_currency,platform_type";
if(!string.IsNullOrWhiteSpace(parameter.sort))
{
sql+=" order by "+parameter.sort+" "+parameter.order;
fromsql+=" order by "+parameter.sort+" "+parameter.order;
prefromsql+=" and bailun_sku_quantity_shipped<=0";
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,website,order_currency,platform_type";
varsql=@"select sum(amount_product*seller_order_exchange_rate) 'amount_product',sum(cost_product) 'cost_product',sum(cost_platform_fee*seller_order_exchange_rate) 'platform_fee',sum(cost_first) 'head_fee',count(id) 'order_count',sum(cost_total) 'cost_count',sum(cost_shipping) 'nofba_logisticsfee',sum(profit_total) 'profit_count',(sum(profit_total)/sum(amount_sales*seller_order_exchange_rate)) 'profit_rate',sum(amount_prepaid) amount_prepaid,sum(amount_refund*seller_order_exchange_rate) amount_refund from dc_base_oms_order where paid_time>='"+start.ToString("yyyy-MM-dd")+"' and paid_time<'"+end.AddDays(1).ToString("yyyy-MM-dd")+"' and platform_type='Amazon' and bailun_order_status!='Canceled' ";
varpresql="select sum(amount_prepaid) as amount_prepaid from dc_base_oms_sku t1 ";
sql+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.warehouse_type_ex=@warehoursetype";
presql+=" join dc_base_warehouse t2 on t1.warehouse_code=t2.warehouse_code and t2.warehouse_type_ex=@warehoursetype";
sqlparam.Add("warehoursetype",warehoursetype);
}
if(!string.IsNullOrEmpty(warehousecode))
{
if(!string.IsNullOrEmpty(warehoursetype))
{
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 paid_time>='"+start.ToString("yyyy-MM-dd")+"' and paid_time<'"+end.AddDays(1).ToString("yyyy-MM-dd")+"' and platform_type='Amazon' and bailun_order_status!='Canceled' ";