CONCAT(t1.bailun_sku,t1.warehouse_code) as 'bailun_sku_warehouse_code',
t1.purchase_id as 'purchase_no',
t1.create_time as 'purchase_create_time',
t1.estimated_arrival_time as 'purchase_arrivaldate',
t3.last_signtime as 'purchase_sign_time',
max(t2.create_time) as 'purchase_put_time',
t1.`count` as 'purchase_quantity',
t3.quantity_arrival as 'purchase_quantity_arrival',
ifnull( sum(t2.`count`),0) as 'purchase_quantity_inbound',
t1.`count` - ifnull( sum(t2.`count`),0) as 'purchase_quantity_not_inbound',
(case when t1.transport_type=1 then '铁路运输' when t1.transport_type=2 then '海运' when t1.transport_type=3 then '空运' else '' end ) as 'transfer_transporttype',
t1.buy_status as 'purchase_status'
from dc_base_purchase as t1
left join dc_base_purchase_inbound t2 on t1.bailun_sku = t2.bailun_sku and t1.parent_id = t2.parent_id
left join dc_base_purchase_details t3 on t1.bailun_sku = t3.bailun_sku and t1.purchase_id = t3.purchase_id
where 1=1
";
if(string.IsNullOrWhiteSpace(bailun_sku))
{
sql+=@" and t1.buy_status in (0, 1, 2, 3, 9)
and t1.has_delete = 0
and t1.`count` > 0
and (t1.`count` > t2.`count` or t2.`count` is null) ";
}
else
{
sql+=" and t1.bailun_sku=@bailun_sku and t1.purchase_id in @purchase_ids ";