where+=$@" and {nameof(RB_Member_User.TenantId)}={dmodel.TenantId}";
where+=$@" and a.{nameof(RB_Member_User.TenantId)}={dmodel.TenantId}";
}
}
if(dmodel.MallBaseId>0)
if(dmodel.MallBaseId>0)
{
{
where+=$@" and {nameof(RB_Member_User.MallBaseId)}={dmodel.MallBaseId}";
where+=$@" and a.{nameof(RB_Member_User.MallBaseId)}={dmodel.MallBaseId}";
}
}
if(!string.IsNullOrEmpty(dmodel.Name))
if(!string.IsNullOrEmpty(dmodel.Name))
{
{
where+=$@" and ({nameof(RB_Member_User.Name)} like '%{dmodel.Name}%' or {nameof(RB_Member_User.Id)} like '%{dmodel.Name}%')";
where+=$@" and (a.{nameof(RB_Member_User.Name)} like '%{dmodel.Name}%' or a.{nameof(RB_Member_User.Id)} like '%{dmodel.Name}%')";
}
}
if(!string.IsNullOrEmpty(dmodel.AliasName))
if(!string.IsNullOrEmpty(dmodel.AliasName))
{
{
where+=$@" and {nameof(RB_Member_User.AliasName)} like '%{dmodel.AliasName}%'";
where+=$@" and a.{nameof(RB_Member_User.AliasName)} like '%{dmodel.AliasName}%'";
}
}
if(dmodel.Source>0)
if(dmodel.Source>0)
{
{
where+=$@" and {nameof(RB_Member_User.Source)} ={(int)dmodel.Source}";
where+=$@" and a.{nameof(RB_Member_User.Source)} ={(int)dmodel.Source}";
}
}
if(!string.IsNullOrEmpty(dmodel.Moblie))
if(!string.IsNullOrEmpty(dmodel.Moblie))
{
{
where+=$@" and {nameof(RB_Member_User.Moblie)} like '%{dmodel.Moblie}%'";
where+=$@" and a.{nameof(RB_Member_User.Moblie)} like '%{dmodel.Moblie}%'";
}
}
if(dmodel.MemberGrade>0)
if(dmodel.MemberGrade>0)
{
{
where+=$@" and {nameof(RB_Member_User.MemberGrade)}={dmodel.MemberGrade}";
where+=$@" and a.{nameof(RB_Member_User.MemberGrade)}={dmodel.MemberGrade}";
}
}
if(dmodel.SuperiorId>0)
if(dmodel.SuperiorId>0)
{
{
where+=$@" and {nameof(RB_Member_User.SuperiorId)}={dmodel.SuperiorId}";
where+=$@" and a.{nameof(RB_Member_User.SuperiorId)}={dmodel.SuperiorId}";
}
}
if(string.IsNullOrWhiteSpace(dmodel.OrderBy))
if(string.IsNullOrWhiteSpace(dmodel.OrderBy))
{
{
dmodel.OrderBy=" Id asc";
dmodel.OrderBy=" Id asc";
}
}
stringsql=$@" select * from ( SELECT a.Id,a.Source,a.`Name`,a.AliasName,a.Photo, b.TotalCommission,b.Price,c.Commission,d.ChildrenNum,
stringsql=$@" select * from ( SELECT a.Id,a.Source,a.`Name`,a.AliasName,a.Photo, b.TotalCommission,b.Price,c.Commission,d.ChildrenNum,e.twoChildren,f.ThreeChildren,g.AllOrderNum,
0 as AllChildrenNum ,
(IFNULL(d.ChildrenNum,0)+IFNULL(e.twoChildren,0)+IFNULL(f.ThreeChildren,0)) as AllChildrenNum
0 as OrderNum
from rb_member_user as a
from rb_member_user as a
LEFT JOIN (SELECT UserId,MAX(TotalCommission) as TotalCommission,SUM(IFNULL(TotalCommission,0)-IFNULL(CommissionWithdrawal,0)) as Price from rb_distributor_info GROUP BY UserId) as b on a.Id=b.UserId
LEFT JOIN (SELECT UserId,MAX(TotalCommission) as TotalCommission,SUM(IFNULL(TotalCommission,0)-IFNULL(CommissionWithdrawal,0)) as Price from rb_distributor_info
GROUP BY UserId) as b on a.Id=b.UserId
LEFT JOIN
LEFT JOIN
(SELECT goc.UserId,SUM(Commission) as Commission from rb_goods_ordercommission as goc
(SELECT goc.UserId,SUM(Commission) as Commission from rb_goods_ordercommission as goc
LEFT JOIN rb_goods_order go on goc.OrderId=go.OrderId where go.OrderStatus!=7 GROUP BY goc.UserId) as c on a.Id=c.UserId
LEFT JOIN rb_goods_order go on goc.OrderId=go.OrderId where go.OrderStatus!=7 GROUP BY goc.UserId) as c on a.Id=c.UserId
LEFT JOIN (SELECT SuperiorId,COUNT(SuperiorId) as ChildrenNum from rb_member_user GROUP BY SuperiorId) as d on d.SuperiorId=a.Id) as t order by {dmodel.OrderBy} ";
LEFT JOIN (SELECT SuperiorId,COUNT(SuperiorId) as ChildrenNum from rb_member_user GROUP BY SuperiorId) as d on d.SuperiorId=a.Id
LEFT JOIN (SELECT COUNT(u1.Id) as twoChildren,u.SuperiorId FROM rb_member_user u
INNER JOIN rb_member_user u1 on u.Id=u1.SuperiorId GROUP BY u.SuperiorId ) as e on e.SuperiorId=a.Id
LEFT JOIN (SELECT COUNT(u2.Id) as ThreeChildren,u.SuperiorId FROM rb_member_user u
INNER JOIN rb_member_user u1 on u.Id=u1.SuperiorId
INNER JOIN rb_member_user u2 on u1.Id=u2.SuperiorId GROUP BY u.SuperiorId ) as f on f.SuperiorId=a.Id
LEFT JOIN (SELECT UserId,COUNT(OrderId) as AllOrderNum from rb_goods_ordercommission GROUP BY UserId) as g on g.UserId=a.Id {where} ) as t