varsql=$@"select sum(t2.amount_sales*t1.quantity_shipped*t2.seller_order_exchange_rate) as amount_sales,sum(t2.cost_product*t1.quantity_shipped) as cost_product,sum(t2.cost_platform_fee*(if(t2.platform_type='Ebay',t2.seller_other_exchange_rate,t2.seller_order_exchange_rate))*t1.quantity_shipped) as cost_platform_fee,sum(t2.cost_paypal_fee*t2.seller_order_exchange_rate*t1.quantity_shipped) as cost_paypal_fee,sum(t2.cost_first*t1.quantity_shipped) as cost_first,sum(t2.cost_logistics*t1.quantity_shipped) as cost_logistics,sum(t2.cost_handle_platform*t1.quantity_shipped) as cost_handle_platform from dc_base_oms_pick t1
sql=$@"select sum(t2.amount_sales*t1.quantity_shipped*t2.seller_order_exchange_rate) as amount_sales,sum(t2.cost_product*t1.quantity_shipped) as cost_product,sum(t2.cost_platform_fee*(if(t2.platform_type='Ebay',t2.seller_other_exchange_rate,t2.seller_order_exchange_rate))*t1.quantity_shipped) as cost_platform_fee,sum(t2.cost_paypal_fee*t2.seller_order_exchange_rate*t1.quantity_shipped) as cost_paypal_fee,sum(t2.cost_first*t1.quantity_shipped) as cost_first,sum(t2.cost_logistics*t1.quantity_shipped) as cost_logistics,sum(t2.cost_handle_platform*t1.quantity_shipped) as cost_handle_platform from dc_base_oms_pick t1
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 and t2.company_id=1
where t1.has_delete=0 and t1.shipping_status = 'TotalShipping' and t1.company_id=1 and t1.shipping_time>='{day.ToString("yyyy-MM-dd")}' and t1.shipping_time<'{day.AddMonths(1).ToString("yyyy-MM-dd")}'";
sql=$@"select sum(amount_sales*seller_order_exchange_rate) as amount_sales,sum(cost_product) as cost_product,sum(cost_platform_fee*seller_order_exchange_rate) as cost_platform_fee,sum(cost_first) as cost_first,sum(cost_logistics) as cost_logistics,sum(cost_fba_fee*seller_order_exchange_rate) cost_fba_fee from dc_base_oms_order tb where tb.company_id=1 and 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') and tb.platform_type='FBA' and tb.create_time>='{day.ToString("yyyy-MM-dd")}' and tb.create_time<'{day.AddMonths(1).ToString("yyyy-MM-dd")}'";
varlist=cn.Query<dc_month_sale_profit>("select * from dc_month_sale_profit where month>'"+day.AddMonths(-3).ToString("yyyy-MM")+"'");
list=cn.Query<dc_month_sale_profit>("select * from dc_month_sale_profit where month>'"+day.AddMonths(-3).ToString("yyyy-MM")+"'").AsList();
}
foreach(varminlist)
{
varstart=DateTime.Parse(m.month+"-01");
varsql=$@"select sum(t2.amount_sales*t1.quantity_shipped*t2.seller_order_exchange_rate) as amount_sales,sum(t2.cost_product*t1.quantity_shipped) as cost_product,sum(t2.cost_platform_fee*(if(t2.platform_type='Ebay',t2.seller_other_exchange_rate,t2.seller_order_exchange_rate))*t1.quantity_shipped) as cost_platform_fee,sum(t2.cost_paypal_fee*t2.seller_order_exchange_rate*t1.quantity_shipped) as cost_paypal_fee,sum(t2.cost_first*t1.quantity_shipped) as cost_first,sum(t2.cost_logistics*t1.quantity_shipped) as cost_logistics,sum(t2.cost_handle_platform*t1.quantity_shipped) as cost_handle_platform from dc_base_oms_pick t1
sql=$@"select sum(t2.amount_sales*t1.quantity_shipped*t2.seller_order_exchange_rate) as amount_sales,sum(t2.cost_product*t1.quantity_shipped) as cost_product,sum(t2.cost_platform_fee*(if(t2.platform_type='Ebay',t2.seller_other_exchange_rate,t2.seller_order_exchange_rate))*t1.quantity_shipped) as cost_platform_fee,sum(t2.cost_paypal_fee*t2.seller_order_exchange_rate*t1.quantity_shipped) as cost_paypal_fee,sum(t2.cost_first*t1.quantity_shipped) as cost_first,sum(t2.cost_logistics*t1.quantity_shipped) as cost_logistics,sum(t2.cost_handle_platform*t1.quantity_shipped) as cost_handle_platform from dc_base_oms_pick t1
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 and t2.company_id=1
where t1.has_delete=0 and t1.shipping_status = 'TotalShipping' and t1.company_id=1 and t1.shipping_time>='{start.ToString("yyyy-MM-dd")}' and t1.shipping_time<'{start.AddMonths(1).ToString("yyyy-MM-dd")}'";
sql=$@"select sum(amount_sales*seller_order_exchange_rate) as amount_sales,sum(cost_product) as cost_product,sum(cost_platform_fee*seller_order_exchange_rate) as cost_platform_fee,sum(cost_first) as cost_first,sum(cost_logistics) as cost_logistics,sum(cost_fba_fee*seller_order_exchange_rate) cost_fba_fee from dc_base_oms_order tb where tb.company_id=1 and 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') and tb.platform_type='FBA' and tb.create_time>='{start.ToString("yyyy-MM-dd")}' and tb.create_time<'{start.AddMonths(1).ToString("yyyy-MM-dd")}'";
sql=$@"select sum(t1.amount_refund_rmb) from dc_base_crm_refund t1 where t1.shipping_status in ('TotalShipping','PartShipping') and t1.is_deleted=0 and is_freeze=0 and t1.company_id=1 and t1.refund_time>='{start.ToString("yyyy-MM-dd")}' and t1.refund_time<'{start.AddMonths(1).ToString("yyyy-MM-dd")}' and t1.shipping_status!='UnShipping'";
sql=$@"update dc_month_sale_profit set amount_sale="+m.amount_sale+",cost_sale="+m.cost_sale+",pt_platformfee="+m.pt_platformfee+",pt_ebay_postingfee="+m.pt_ebay_postingfee+",pt_paypal_fee="+m.pt_paypal_fee+",pt_platform_logistics_fee="+m.pt_platform_logistics_fee+",pt_platform_ad_subscribe_fee="+m.pt_platform_ad_subscribe_fee+",pt_refund_amount="+m.pt_refund_amount+",ls_head_cost="+m.ls_head_cost+",ls_tail_cost="+m.ls_tail_cost+",ls_platform_operation_fee="+m.ls_platform_operation_fee+",pt_count="+m.pt_count+",pt_incoming="+m.pt_incoming+",ls_count="+m.ls_count+",sale_fee_count="+m.sale_fee_count+",sale_profit="+m.sale_profit+",sale_profit_rate="+m.sale_profit_rate+",sale_manager_cost="+m.sale_manager_cost+",direct_manager_cost="+m.direct_manager_cost+",manager_cost_count="+m.manager_cost_count+",business_profit="+m.business_profit+",business_profit_rate="+m.business_profit_rate+",actual_profit="+m.actual_profit+",balance_of_profit="+m.balance_of_profit+",manager_cost_yangshan="+m.manager_cost_yangshan+",manager_cost_xinhuilan="+m.manager_cost_xinhuilan+" where id="+m.id;
sql=$@"update dc_month_sale_profit set amount_sale="+m.amount_sale+",cost_sale="+m.cost_sale+",pt_platformfee="+m.pt_platformfee+",pt_ebay_postingfee="+m.pt_ebay_postingfee+",pt_paypal_fee="+m.pt_paypal_fee+",pt_platform_logistics_fee="+m.pt_platform_logistics_fee+",pt_platform_ad_subscribe_fee="+m.pt_platform_ad_subscribe_fee+",pt_refund_amount="+m.pt_refund_amount+",ls_head_cost="+m.ls_head_cost+",ls_tail_cost="+m.ls_tail_cost+",ls_platform_operation_fee="+m.ls_platform_operation_fee+",pt_count="+m.pt_count+",pt_incoming="+m.pt_incoming+",ls_count="+m.ls_count+",sale_fee_count="+m.sale_fee_count+",sale_profit="+m.sale_profit+",sale_profit_rate="+m.sale_profit_rate+",sale_manager_cost="+m.sale_manager_cost+",direct_manager_cost="+m.direct_manager_cost+",manager_cost_count="+m.manager_cost_count+",business_profit="+m.business_profit+",business_profit_rate="+m.business_profit_rate+",actual_profit="+m.actual_profit+",balance_of_profit="+m.balance_of_profit+",manager_cost_yangshan="+m.manager_cost_yangshan+",manager_cost_xinhuilan="+m.manager_cost_xinhuilan+" where id="+m.id;