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_logistics*"+(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 ";
varsql="select t1.id,t1.account_entry_type,t1.description,t1.bj_date as gmt_date,t1.gross_amount,t1.item_id,t1.net_amount,t1.vat_percent,t1.order_line_id,t1.currency,t1.exchange_rate,(t1.exchange_rate*t1.gross_amount) gross_amount_rmb,t2.account_name,t1.memo,t1.ref_number from dc_base_finance_ebay t1 ";
varsql=$@"select t2.order_currency as currency,t1.transaction_id,sum(t1.amount_sales*t1.bailun_sku_quantity_ordered) sales_amount_sku,sum(bailun_sku_quantity_ordered) count_sales,sum(t1.bailun_sku_quantity_shipped) count_shipping from dc_base_oms_sku t1
join dc_base_oms_order t2 on t1.origin_order_id=t2.origin_order_id and t2.bailun_merge_status!='Merged'
where t1.transaction_id in ('{string.Join("','",transactions)}') and t1.has_delete=0
where t1.transaction_id in ('{string.Join("','",transactions)}') and t1.has_delete=0
group by t1.transaction_id
union all
select t2.order_currency as currency,t2.transaction_id,sum(t1.amount_sales*t1.bailun_sku_quantity_ordered) sales_amount_sku,sum(bailun_sku_quantity_ordered) count_sales,sum(t1.bailun_sku_quantity_shipped) count_shipping from dc_base_oms_sku t1
varsql=$@"select t1.platform_type,t1.website,t1.bailun_sku,sum(t1.bailun_sku_quantity_ordered) as bailun_sku_quantity_ordered,sum(t1.bailun_sku_quantity_ordered*t1.amount_sales*t1.seller_order_exchange_rate) as amount_sales from dc_base_oms_sku t1
where bailun_order_status!='Canceled' and has_scalp=0 and has_delete=0 and has_innersale=0 and has_innersale=0 ";
varsql=$@"select distinct DATE_FORMAT(t1.purchase_create_time,'%Y-%m-%d') from dc_base_oms_sku as t1 where (t1.gmt_modified >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.gmt_modified <='{end.ToString("yyyy-MM-dd HH:mm:ss")}') or (
(t1.has_delete = 1 or t1.has_scalp = 1) and t1.gmt_modified >= '{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.gmt_modified <='{end.ToString("yyyy-MM-dd HH:mm:ss")}')";
// select distinct t1.platform_type,CONCAT('`',t1.origin_order_id) as origin_order_id,t1.refund_time,t1.amount_refund,t1.order_currency as currency,t1.shipping_status,t1.bailun_sku,t4.financecategoryname,t2.shipping_time,t1.order_total_amount,t6.order_currency,t6.website,t6.transaction_id as trancation_id,t1.amount_refund_rmb
varlistNotEbayOrderInfo=cn.Query<dc_base_oms_order>($"select platform_type,website,order_currency,origin_order_id,transaction_id from dc_base_oms_order where platform_type!='Ebay' and origin_order_id in ('{string.Join("','",obj.Where(a=>a.platform_type.ToLower()!="ebay").Select(a=>a.origin_order_id))}')").ToList();
varlistEbayOrderInfo=cn.Query<dc_base_oms_order>($"select platform_type,website,order_currency,origin_order_id,transaction_id from dc_base_oms_order where platform_type='Ebay' and transaction_id in ('{string.Join("','",obj.Where(a=>a.platform_type.ToLower()=="ebay").Select(a=>a.origin_order_id))}')").ToList();
varlistEbayOrderInfo=cn.Query<dc_base_oms_order>($"select platform_type,website,order_currency,origin_order_id,transaction_id from dc_base_oms_order where platform_type='Ebay' and transaction_id in ('{string.Join("','",obj.Where(a=>a.platform_type.ToLower()=="ebay").Select(a=>a.origin_order_id))}')").ToList();
varsql=$"select t1.campaign_name,t2.account_name,t1.daily_total_campaign_spend,(t1.daily_total_campaign_spend*{(isUSD?"t1.other_to_usd_exchange_rate":"t1.other_to_cny_exchange_rate")}) daily_total_campaign_spend_rmb,t1.record_time from dc_base_finance_wish t1 join dc_base_company_account t2 on t1.account_id=t2.account_id where 1=1 ";
varsql=$"select t1.campaign_name,t2.account_name,t1.daily_total_campaign_spend,(t1.daily_total_campaign_spend*{(isUSD?"t1.other_to_usd_exchange_rate":"t1.other_to_cny_exchange_rate")}) daily_total_campaign_spend_rmb,t1.record_time from dc_base_finance_wish t1 join dc_base_company_account t2 on t1.account_id=t2.account_id where 1=1 ";
varsql=$"select t1.campaign_name,t2.account_name,t1.daily_total_campaign_spend,(t1.daily_total_campaign_spend*{(isUSD?"t1.other_to_usd_exchange_rate":"t1.other_to_cny_exchange_rate")}) daily_total_campaign_spend_rmb,t1.record_time from dc_base_finance_wish t1 join dc_base_company_account t2 on t1.account_id=t2.account_id where 1=1 ";
varsql=$" select account_name,product_name,exposure,clickcount,clickrate,cost_fee,(cost_fee*{(isUSD?"to_usd_rate":"to_rmb_rate")}) cost_fee_rmb,currency,recore_time from dc_base_finance_aliexpress where delstatus=0";
varsql=$" select account_name,product_name,exposure,clickcount,clickrate,cost_fee,(cost_fee*{(isUSD?"to_usd_rate":"to_rmb_rate")}) cost_fee_rmb,currency,recore_time from dc_base_finance_aliexpress where delstatus=0";
varsql="select t1.transaction_id,t1.receipt_id,t1.transaction_type,t1.payment_type,t1.payment_date,t1.gross_amount,t1.payment_status,t1.business,t1.receiver,t1.currency,(t1.gross_amount*t1.other_to_cny_exchange_rate) gross_amount_rmb from dc_base_finance_paypal t1 where 1=1 ";
varsql=$"select Count(id) id,sum(amount_sales*seller_order_exchange_rate) amount_sales,sum(profit_total) profit_total,sum(profit_total)/sum(amount_sales*seller_order_exchange_rate) as profit_rate from dc_base_oms_order where create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'";
varsql=$@"select t1.platform_type,t1.item_id,sum(t1.platform_sku_quantity_ordered) platform_sku_quantity_ordered from dc_base_oms_platform_sku t1 where t1.bailun_order_status!='Canceled' and t1.has_cancle=0 and t1.has_delete=0 and t1.has_scalp=0 and ((t1.platform_type!='FBA' and t1.bailun_order_status!='CantHandle') or t1.platform_type='FBA')
varsql=$@"select t1.bailun_sku,sum(t1.bailun_sku_quantity_refund) as refundcount,t1.website,t1.platform_type,t1.bailun_account_id from dc_base_crm_refund t1
where t1.refund_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.refund_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.is_deleted=0 and t1.is_freeze=0 and t1.company_id=1
//var sql = $@"select t1.platform_type,t1.bailun_sku_title_cn,t1.bailun_sku,sum(amount_product) as amount_product,sum(ordercount) as ordercount,sum(t1.bailun_sku_quantity_ordered) as bailun_sku_quantity_ordered,sum(t1.amount_sales) amount_sales,sum(cost_platform_fee) cost_platform_fee,sum(cost_product) cost_product,sum(t1.cost_logistics) cost_logistics,sum(profit_total) profit_total from (
// select t1.platform_type,t1.bailun_sku_title_cn,t1.bailun_sku,sum(t1.amount_product*t1.bailun_sku_quantity_ordered*t1.seller_order_exchange_rate) as amount_product,count(DISTINCT bailun_order_id) as ordercount,sum(t1.bailun_sku_quantity_ordered) as bailun_sku_quantity_ordered,sum(t1.amount_sales*t1.bailun_sku_quantity_ordered*t1.seller_order_exchange_rate) amount_sales,sum(cost_platform_fee*t1.bailun_sku_quantity_ordered*t1.seller_order_exchange_rate) cost_platform_fee,sum(cost_product*t1.bailun_sku_quantity_ordered) cost_product,sum(t1.cost_logistics*t1.bailun_sku_quantity_ordered) cost_logistics,sum(profit_total*t1.bailun_sku_quantity_ordered) profit_total from dc_base_oms_sku t1
varsql=$@"select t1.origin_order_id,t1.bailun_order_id,t1.website,t1.platform_type,t1.seller_name,t1.bailun_account_id,t1.platform_sku_quantity_ordered,t1.platform_sku_unit_price,t1.platform_sku,t1.order_currency,t1.item_id,seller_order_exchange_rate from dc_base_oms_platform_sku t1 where t1.bailun_order_status != 'Canceled' and t1.has_delete = 0 and t1.has_cancle = 0 ";
if(!string.IsNullOrEmpty(platform))
if(!string.IsNullOrEmpty(platform))
{
sql+=" and t1.platform_type='"+platform+"'";
sql+=" and t1.platform_type='"+platform+"'";
}
if(orderIds!=null&&orderIds.Count>0)
{
sql+=" and t1.origin_order_id in ('"+string.Join("','",orderIds)+"')";
sql+=" and t1.origin_order_id in ('"+string.Join("','",orderIds)+"')";