sql+=" where t1.bailun_order_status!='Canceled' and ((t1.platform_type!='FBA' and t1.bailun_order_status!='CantHandle') or t1.platform_type='FBA') and t1.has_scalp=0 and t1.has_innersale=0 and t1.bailun_interception_status in ('None','Failed') ";
if(companyid.HasValue&&companyid.Value>0)
if(companyid.HasValue&&companyid.Value>0)
{
sql+=" and t1.company_id = "+companyid.Value;//增加公司id判断
varstrwhere=" where t1.bailun_order_status!='Canceled' and ((t1.platform_type!='FBA' and t1.bailun_order_status!='CantHandle') or t1.platform_type='FBA') and t1.has_scalp=0 and t1.has_innersale=0 and t1.bailun_interception_status in ('None','Failed') ";
if(companyid.HasValue&&companyid.Value>0)
if(companyid.HasValue&&companyid.Value>0)
{
strwhere+=" and t1.company_id="+companyid.Value;//增加公司id过滤
}
...
...
@@ -795,7 +795,7 @@ namespace Bailun.DC.Services
if(!string.IsNullOrWhiteSpace(itemid))
{
//sql += " join dc_base_oms_platform_sku t3 on t1.bailun_order_id=t3.bailun_order_id and t3.item_id=@itemid";
sql+=$" join (select bailun_order_id,item_id from dc_base_oms_platform_sku where has_delete=0 and has_cancle=0 and item_id=@itemid {(start.HasValue?" and paid_time>=@ppaid_time_start ":"")+(end.HasValue?" and paid_time<@ppaid_time_end ":"")} GROUP BY bailun_order_id,item_id) t3 on t1.bailun_order_id=t3.bailun_order_id ";
sql+=$" join (select bailun_order_id,item_id from dc_base_oms_platform_sku where has_delete=0 and has_cancle=0 and item_id=@itemid {(start.HasValue?" and paid_time>=@ppaid_time_start ":"")+(end.HasValue?" and paid_time<@ppaid_time_end ":"")} GROUP BY bailun_order_id,item_id) t3 on t1.bailun_order_id=t3.bailun_order_id ";
//sql += " join dc_base_oms_platform_sku t3 on t1.bailun_order_id=t3.bailun_order_id and t3.item_id=@itemid";
sql+=$" join (select bailun_order_id,item_id from dc_base_oms_platform_sku where has_delete=0 and has_cancle=0 and item_id=@itemid {(start.HasValue?" and paid_time>=@ppaid_time_start ":"")+(end.HasValue?" and paid_time<@ppaid_time_end ":"")} GROUP BY bailun_order_id,item_id) t3 on t1.bailun_order_id=t3.bailun_order_id ";
sql+=$" join (select bailun_order_id,item_id from dc_base_oms_platform_sku where has_delete=0 and has_cancle=0 and item_id=@itemid {(start.HasValue?" and paid_time>=@ppaid_time_start ":"")+(end.HasValue?" and paid_time<@ppaid_time_end ":"")} GROUP BY bailun_order_id,item_id) t3 on t1.bailun_order_id=t3.bailun_order_id ";
varsql="select t1.origin_order_id,t1.platform_type,t1.website,t1.seller_account,t1.platform_order_type,t1.bailun_sku,t1.amount_product,t1.cost_first,t1.amount_shipping,t1.cost_promotion,t1.cost_shipping,t1.cost_fba_fee,t1.cost_platform_fee,t1.cost_package,t1.amount_total,t1.cost_total+t1.cost_shipping as cost_total,t1.paid_time,t1.seller_order_exchange_rate,t1.finance_order_exchange_rate from dc_base_oms_sku t1";
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_tail*"+(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 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 t2.platform_type,count(DISTINCT t2.bailun_order_id) order_count,sum(t2.amount_sales*"+(isUSD?"t2.order_to_usd_exchange_rate":"t2.seller_order_exchange_rate")+"*t1.quantity_shipped) as amount_sales,sum(t2.cost_platform_fee*(if(t2.platform_type='Ebay',"+(isUSD?"t2.other_to_usd_exchange_rate":"t2.seller_other_exchange_rate")+","+(isUSD?"t2.order_to_usd_exchange_rate":"t2.seller_order_exchange_rate")+"))*t1.quantity_shipped) as cost_platform_fee,sum(t2.cost_first*"+(isUSD?"t2.cny_to_usd_exchange_rate":"1")+"*t1.quantity_shipped) as cost_first,sum(t2.cost_tail*"+(isUSD?"t2.cny_to_usd_exchange_rate":"1")+"*t1.quantity_shipped) cost_tail,sum(t2.cost_handle_bailun*"+(isUSD?"t2.cny_to_usd_exchange_rate":"1")+"*t1.quantity_shipped) cost_handle_bailun,sum(t2.cost_handle_platform*"+(isUSD?"t2.cny_to_usd_exchange_rate":"1")+"*t1.quantity_shipped) cost_handle_platform,sum(t2.amount_refund*"+(isUSD?"t2.order_to_usd_exchange_rate":"t2.seller_order_exchange_rate")+"*t1.quantity_shipped) amount_refund,sum(t2.cost_product*"+(isUSD?"t2.cny_to_usd_exchange_rate":"1")+"*t1.quantity_shipped) cost_product,sum(t2.profit_total*"+(isUSD?"t2.cny_to_usd_exchange_rate":"1")+"*t1.quantity_shipped) profit_total,(sum(t2.profit_total*"+(isUSD?"t2.cny_to_usd_exchange_rate":"1")+"*t1.quantity_shipped)/sum(t2.amount_sales*"+(isUSD?"t2.order_to_usd_exchange_rate":"t2.seller_order_exchange_rate")+"*t1.quantity_shipped)) profit_rate,count(t2.amount_prepaid>0 or null) as noshippingcount,sum(t2.amount_prepaid*"+(isUSD?"t2.cny_to_usd_exchange_rate":"1")+"*t1.quantity_shipped) amount_prepaid,sum(t2.cost_fba_fee*"+(isUSD?"t2.order_to_usd_exchange_rate":"t2.seller_order_exchange_rate")+"*t1.quantity_shipped) cost_fba_fee,sum(t2.cost_paypal_fee*"+(isUSD?"t2.order_to_usd_exchange_rate":"t2.seller_order_exchange_rate")+"*t1.quantity_shipped) cost_paypal_fee,sum(t2.amount_shipping*"+(isUSD?"t2.order_to_usd_exchange_rate":"t2.seller_order_exchange_rate")+"*t1.quantity_shipped) amount_shipping,sum(t2.cost_promotion*"+(isUSD?"t2.order_to_usd_exchange_rate":"t2.seller_order_exchange_rate")+"*t1.quantity_shipped) cost_promotion from (select id,bailun_order_id,quantity_shipped,bailun_sku from dc_base_oms_pick where has_delete=0 and shipping_status = 'TotalShipping' ";
varsql="select bailun_order_id,GROUP_CONCAT(item_id) as item_id from dc_base_oms_platform_sku where bailun_order_id in ('"+string.Join("','",orderid)+"') group by bailun_order_id;";
varsql="select bailun_order_id,GROUP_CONCAT(item_id) as item_id from dc_base_oms_platform_sku where bailun_order_id in ('"+string.Join("','",orderid)+"') group by bailun_order_id;";
varsql=$"select id,account_entry_type,description,bj_date,gross_amount,item_id,account_id,currency,exchange_rate,company_id from dc_base_finance_ebay where bj_date>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and bj_date<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and account_entry_type in ('{string.Join("','",feetype)}') ";
varsql=$"select id,account_entry_type,description,bj_date,gross_amount,item_id,account_id,currency,exchange_rate,company_id from dc_base_finance_ebay where bj_date>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and bj_date<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and account_entry_type in ('{string.Join("','",feetype)}') ";
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 from dc_base_finance_ebay t1 ";
varsql="select t1.*,if(t2.bailun_shipping_status is null,t3.bailun_shipping_status,t2.bailun_shipping_status) as bailun_shipping_status from dc_base_crm_refund t1 left join dc_base_oms_order t2 on t1.origin_order_id=t2.origin_order_id left join dc_base_oms_order t3 on t1.origin_order_id=t3.transaction_id where 1=1 ";
varsql="select sum(amount_refund) amount_refund,sum(bailun_sku_quantity_refund) bailun_sku_quantity_refund,sum(amount_refund_rmb) amount_refund_rmb from dc_base_crm_refund where 1=1 ";
varsql="select origin_order_id,bailun_order_id,platform_type,website,seller_account,paid_time,(amount_sales*seller_order_exchange_rate) amount_sales,(amount_shipping*seller_order_exchange_rate) amount_shipping,(amount_product*seller_order_exchange_rate) amount_product,(amount_tax*seller_order_exchange_rate) amount_tax,(amount_adjustment*seller_order_exchange_rate) amount_adjustment,(amount_gift_wrap*seller_order_exchange_rate) amount_gift_wrap,(amount_refund*seller_order_exchange_rate) amount_refund,amount_prepaid,(cost_promotion*seller_order_exchange_rate) cost_promotion,(cost_platform_fee*seller_order_exchange_rate) cost_platform_fee,cost_product,cost_shipping,cost_package,(cost_fba_fee*seller_order_exchange_rate) cost_fba_fee,(cost_paypal_fee*seller_order_exchange_rate) cost_paypal_fee,(cost_refund_commisson*seller_order_exchange_rate) cost_refund_commisson,cost_handle_bailun,cost_handle_platform,cost_tail,cost_first,profit_total,profit_rate,(cost_total) cost_total from dc_base_oms_order where bailun_order_status='Handling' and bailun_shipping_status!='TotalShipping' and amount_prepaid>0 and has_scalp=0 and has_innersale=0 and bailun_interception_status in ('None','Failed') ";
varsql="select origin_order_id,platform_type,website,order_currency,seller_order_exchange_rate,platform_sku_quantity_ordered,platform_sku_unit_price,item_id,platform_sku from dc_base_oms_platform_sku where has_delete=0 and has_scalp=0 and bailun_order_status!='Canceled' ";
varcommonCondition=$" ##.bailun_order_status!='Canceled' and ((##.platform_type!='FBA' and ##.bailun_order_status!='CantHandle') or ##.platform_type='FBA') and ##.has_scalp=0 and ##.paid_time>='{start.ToString("yyyy-MM-dd HH:mm:ss")}' and ##.paid_time<'{end.ToString("yyyy-MM-dd HH:mm:ss")}' and ##.platform_type=@platform ";
varsql=$@"select Count(t1.bailun_order_id) as count,platform_sku as itemid from dc_base_oms_platform_sku t1
join dc_base_oms_order t2 on t1.bailun_order_id=t2.bailun_order_id and t2.has_innersale=0 and {commonCondition.Replace("##","t2")}
where {commonCondition.Replace("##","t1")} and platform_sku in ('{string.Join("','",itemid)}')
join dc_base_oms_order t2 on t1.bailun_order_id=t2.bailun_order_id and t2.has_innersale=0 and {commonCondition.Replace("##","t2")}
where {commonCondition.Replace("##","t1")} and platform_sku in ('{string.Join("','",itemid)}')
varsql="select seller_id,seller_account,sum(profit_total) profit_total from dc_base_oms_order where has_scalp=0 and has_innersale=0 and bailun_order_status!='Canceled'";
varsqlselect="select t1.platform_type,t1.website,t1.origin_order_id,t1.seller_account,t1.amount_refund,(t1.seller_order_exchange_rate*t1.amount_refund) as refundrmb,t1.refund_time,t1.refund_reference_id from dc_base_oms_order t1 ";
varsql="select t1.platform_type,t1.website,t1.origin_order_id,t1.seller_account,t1.amount_refund,(t1.seller_order_exchange_rate*t1.amount_refund) as refundrmb,t1.refund_time,t1.refund_reference_id from dc_base_oms_order t1 ";
//sql += " where ((t1.platform_type!='FBA' and t1.bailun_order_status!='CantHandle') or t1.platform_type='FBA') and t1.amount_refund>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 ";
if(start.HasValue)
{
sql+=" and t1.payment_date>=@start";
sqlparam.Add("start",start.Value);
}
if(end.HasValue)
{
sql+=" and t1.payment_date<@end";
sqlparam.Add("end",end.Value.AddDays(1));
}
if(companyid.HasValue&&companyid.Value!=0)
{
sql+=" and t1.saas_company_id=@companyid";
sqlparam.Add("companyid",companyid.Value);
}
if(!string.IsNullOrWhiteSpace(parameter.sort))
{
sql+=" and t1."+parameter.sort+" "+parameter.order;
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 ";