stringwhere=$" 1=1 and o.Recycled=2 and oa.ReOrderId is null";
if(dmodel.TenantId>0)
{
where+=$@" and oc.{nameof(RB_Goods_OrderCommission.TenantId)}={dmodel.TenantId}";
}
if(dmodel.MallBaseId>0)
{
where+=$@" and oc.{nameof(RB_Goods_OrderCommission.MallBaseId)}={dmodel.MallBaseId}";
}
if(dmodel.OrderId>0)
{
where+=$@" and o.{nameof(RB_Goods_OrderCommission.OrderId)}={dmodel.OrderId}";
}
if(dmodel.UserId>0)
{
where+=string.Format(@" and (oc.UserId={0} OR o.UserId={0}) ",dmodel.UserId);
}
if(!string.IsNullOrEmpty(dmodel.OrderIds))
{
where+=$@" and oc.{nameof(RB_Goods_OrderCommission.OrderId)} in({dmodel.OrderIds})";
}
if(dmodel.DistrbutionOrderSelectStatus>0)
{
switch(dmodel.DistrbutionOrderSelectStatus)
{
case1:where+=$@" and o.{nameof(RB_Goods_Order.OrderStatus)}={(int)OrderStatusEnum.NonPayment}";break;
case2:where+=$@" and o.{nameof(RB_Goods_Order.OrderStatus)} in(2,3,4,6)";break;
case3:where+=$@" and o.{nameof(RB_Goods_Order.OrderStatus)}={(int)OrderStatusEnum.Completed}";break;
}
}
else
{
where+=$@" and o.{nameof(RB_Goods_Order.OrderStatus)} in(1,2,3,4,5,6)";
}
stringsql=$@"
SELECT oc.OrderId,o.OrderNo,o.UserId,oc.Type,oc.Grade,oc.CommissionState,o.OrderStatus as DistrbutionOrderSelectStatus,SUM(oc.Commission) as Commission
FROM rb_goods_order o LEFT JOIN RB_Goods_OrderCommission oc on oc.OrderId = o.OrderId
left join rb_goods_orderaftersale oa on oc.OrderDetailId= oa.OrderDetialId and oa.Type=1 and oa.Status=0 and oa.ReOrderStatus in (2,3,4,5)
where {where} group by oc.OrderId,o.OrderNo,oc.UserId,oc.Type,oc.Grade order by oc.OrderId desc";