varsql1=$" union all select t1.platform_type,{(isUSD?"sum(t1.amount_refund_usd)":"sum(t1.amount_refund_rmb)")} as amount_refund from dc_base_crm_refund t1 join dc_base_oms_order t2 on t1.origin_order_id=t2.transaction_id and t2.bailun_order_status!='Canceled' ";
varsql1=$" union all select t1.platform_type,{(isUSD?"sum(t1.amount_refund_usd)":"sum(t1.amount_refund_rmb)")} as amount_refund from dc_base_crm_refund t1 join dc_base_oms_order t2 on t1.origin_order_id=t2.transaction_id and t2.bailun_order_status!='Canceled' ";
sql+=" where t1.is_deleted=0 and t1.is_freeze=0 and t1.platform_type!='Ebay' ";
sql+=" where t1.is_deleted=0 and t1.is_freeze=0 and t1.platform_type!='Ebay' ";
sql1+=" where t1.is_deleted=0 and t1.is_freeze=0 and t1.platform_type='Ebay' ";
sql1+=" where t1.is_deleted=0 and t1.is_freeze=0 and t1.platform_type='Ebay' ";
//合并订单的退款数据 非Ebay
varsql01=$@" union all select t01.platform_type,{(isUSD?"sum(t01.amount_refund_usd)":"sum(t01.amount_refund_rmb)")} as amount_refund from (
select t1.amount_refund_rmb,t1.amount_refund_usd,t1.platform_type,t2.aftermerged_bailun_order_no from dc_base_crm_refund t1
join dc_base_oms_order t2 on t1.origin_order_id=t2.origin_order_id and t2.aftermerged_bailun_order_no != ''
where t1.is_deleted=0 and t1.is_freeze=0 and t1.platform_type!='Ebay' ";
//合并订单的退款数据 Ebay
varsql02=$@" union all select t01.platform_type,{(isUSD?"sum(t01.amount_refund_usd)":"sum(t01.amount_refund_rmb)")} as amount_refund from (
select t1.amount_refund_rmb,t1.amount_refund_usd,t1.platform_type,t2.aftermerged_bailun_order_no from dc_base_crm_refund t1
join dc_base_oms_order t2 on t1.origin_order_id=t2.transaction_id and t2.aftermerged_bailun_order_no !=''
where t1.is_deleted=0 and t1.is_freeze=0 and t1.platform_type='Ebay' ";
varsql=$@"select t1.warehouse_code,t1.bailun_sku,t1.usable_stock from dc_base_stock t1";
//var objStock = cn.Query<Models.mSkuCount>()
//先保存采购的
//先保存采购的
varsql=$@"select t1.warehouse_code,t1.warehouse_name,t1.bailun_sku,sum(t1.count) count,sum(t1.count*t2.unit_price) amount from dc_base_purchase t1
sql=$@"select t1.warehouse_code,t1.warehouse_name,t1.bailun_sku,sum(t1.count) count,sum(t1.count*t2.unit_price) amount from dc_base_purchase t1
left join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku
left join dc_base_sku t2 on t1.bailun_sku=t2.bailun_sku
where t1.has_delete=0 and t1.status!=-1 and t1.create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'
where t1.has_delete=0 and t1.status!=-1 and t1.create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'
sql=$@"select tb.warehouse_code,tb.bailun_sku,sum(tb.count) count,sum(tb.count*t4.unit_price) amount from (
select t1.warehouse_code,t1.warehouse_name,t1.bailun_sku,t1.count from dc_base_purchase_inbound t1
join dc_base_purchase t2 on t1.purchase_id=t2.purchase_id and t1.bailun_sku=t2.bailun_sku and t2.has_transfer=0 and t2.`status`>0
where t1.`status`=1 and t1.update_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.update_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'
union all
select warehouse_code,warehouse_name,bailun_sku,count from dc_base_transfer_inbound t1 where t1.deleted=0 and t1.count>0 and t1.create_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and t1.create_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}'
) tb
left join dc_base_sku t4 on tb.bailun_sku=t4.bailun_sku