cn.Execute($"delete from dc_mid_itemno_profit_order where day='{end.ToString("yyyy-MM-dd")}'");
cn.Execute($"delete from dc_mid_itemno_profit_order where day='{end.ToString("yyyy-MM-dd")}'");
varsql=$@"insert into dc_mid_itemno_profit_order (day,order_sku_id,bailun_order_id,origin_order_id,item_id,platform_sku,platform_sku_quantity_ordered,count,bailun_sku,paid_time,amount_sales,cost_product,cost_platform_fee,cost_paypal_fee,cost_fba_fee,cost_first,cost_logistics,cost_handle_platform,cost_handle_bailun,warehouse_code,shipping_status,seller_order_exchange_rate,platform_type,website,bailun_account_id)
varsql=$@"insert into dc_mid_itemno_profit_order (day,order_sku_id,bailun_order_id,origin_order_id,item_id,platform_sku,platform_sku_quantity_ordered,count,bailun_sku,paid_time,amount_sales,cost_product,cost_platform_fee,cost_paypal_fee,cost_fba_fee,cost_first,cost_logistics,cost_handle_platform,cost_handle_bailun,warehouse_code,shipping_status,seller_order_exchange_rate,platform_type,website,bailun_account_id)
select distinct '{end.ToString("yyyy-MM-dd")}' as day,t3.id as order_sku_id,t1.bailun_order_id,t1.origin_order_id,t1.item_id,t1.platform_sku,t1.platform_sku_quantity_ordered,t2.count,t3.bailun_sku,t3.paid_time,t3.amount_sales,t3.cost_product,t3.cost_platform_fee,t3.cost_paypal_fee,t3.cost_fba_fee,t3.cost_first,t3.cost_logistics,t3.cost_handle_platform,t3.cost_handle_bailun,t3.warehouse_code,t3.shipping_status,t3.seller_order_exchange_rate,t1.platform_type,t1.website,t1.bailun_account_id from dc_base_oms_platform_sku t1
select distinct '{end.ToString("yyyy-MM-dd")}' as day,t3.id as order_sku_id,t1.bailun_order_id,t1.origin_order_id,t1.item_id,t1.platform_sku,t1.platform_sku_quantity_ordered,t2.count,t3.bailun_sku,t3.paid_time,(t3.amount_sales*t1.platform_sku_quantity_ordered*t2.count) as amount_sales,(t3.cost_product*t1.platform_sku_quantity_ordered*t2.count) cost_product,(t3.cost_platform_fee*t1.platform_sku_quantity_ordered*t2.count) cost_platform_fee,(t3.cost_paypal_fee*t1.platform_sku_quantity_ordered*t2.count) cost_paypal_fee,(t3.cost_fba_fee*t1.platform_sku_quantity_ordered*t2.count) cost_fba_fee,(t3.cost_first*t1.platform_sku_quantity_ordered*t2.count) cost_first,(t3.cost_logistics*t1.platform_sku_quantity_ordered*t2.count) cost_logistics,(t3.cost_handle_platform*t1.platform_sku_quantity_ordered*t2.count) cost_handle_platform,(t3.cost_handle_bailun*t1.platform_sku_quantity_ordered*t2.count) cost_handle_bailun,t3.warehouse_code,t3.shipping_status,t3.seller_order_exchange_rate,t1.platform_type,t1.website,t1.bailun_account_id from dc_base_oms_platform_sku t1
join dc_base_sku_mapping t2 on t1.item_id=t2.item_id and t2.platform_sku=t1.platform_sku and t1.website=t2.site and t2.has_deleted=0
join dc_base_sku_mapping t2 on t1.item_id=t2.item_id and t2.platform_sku=t1.platform_sku and t1.website=t2.site and t2.has_deleted=0
join dc_base_oms_sku t3 on t1.bailun_order_id=t3.bailun_order_id and t2.bailun_sku=t3.bailun_sku and t2.account_id=t3.bailun_account_id
join dc_base_oms_sku t3 on t1.bailun_order_id=t3.bailun_order_id and t2.bailun_sku=t3.bailun_sku and t2.account_id=t3.bailun_account_id
where t1.platform_type in ('Ebay','FBA','Amazon') and t3.has_delete=0 and t3.company_id=1 and t1.paid_time>='{start.ToString("yyyy-MM-dd")}' and t1.paid_time<'{end.AddDays(1).ToString("yyyy-MM-dd")}'";
where t1.platform_type in ('Ebay','FBA','Amazon') and t3.has_delete=0 and t3.company_id=1 and t1.paid_time>='{start.ToString("yyyy-MM-dd")}' and t1.paid_time<'{end.AddDays(1).ToString("yyyy-MM-dd")}'";
cn.Execute($@"update dc_mid_itemno_profit_order set losswithdraw=amount_sales*seller_order_exchange_rate*{withdrawpercent} where day='{end.ToString("yyyy-MM-dd")}' and platform_type='ebay'",null,null,6*60);
varsql=$@"select sum(amount_sales) as amount_sales,sum(cost_product) cost_product,sum(cost_platform_fee) cost_platform_fee,sum(cost_paypal_fee) cost_paypal_fee,sum(cost_fba_fee) cost_fba_fee,sum(cost_first) cost_first,sum(cost_logistics) cost_logistics,sum(cost_handle_platform) cost_handle_platform,sum(cost_handle_bailun) cost_handle_bailun,sum(losswithdraw) losswithdraw from dc_mid_itemno_profit_order where item_id='{itemid}' and day='{day.ToString("yyyy-MM-dd")}'";