SELECT Id FROM rb_member_user WHERE SuperiorId BETWEEN 1 and 20
) AND o.UserId <> 39370
ORDER BY o.OrderId ASC ";
stringcommSql2=$@"SELECT o.OrderId,o.OrderNo,od.Id AS DetailId,o.UserId,u.`Name`,o.Income,o.Consignee,o.Mobile,o.ShoppingAddress,od.GoodsName,od.Specification,od.Final_Price,
od.Number,
CASE WHEN d1.Id IS NULL THEN d2.OneCommission * od.Number ELSE d1.OneCommission * od.Number END AS OneCommission,
CASE WHEN d1.Id IS NULL THEN d2.TwoCommission * od.Number ELSE d1.TwoCommission * od.Number END AS TwoCommission
FROM rb_goods_order o
INNER JOIN rb_goods_orderdetail od on o.OrderId=od.OrderId
INNER JOIN rb_member_user u on o.UserId = u.Id
LEFT JOIN rb_goods_distributioncommission d1 on d1.GoodsId=od.GoodsId AND d1.DistributorGrade=74 and d1.SpecificationSort=od.SpecificationSort
LEFT JOIN rb_goods_distributioncommission d2 on d2.GoodsId=od.GoodsId AND d2.DistributorGrade=74 and d2.SpecificationSort=''
WHERE o.OrderId in(
SELECT t.OrderId FROM(
SELECT cm.OrderId,cm.UserId FROM rb_goods_ordercommission cm WHERE CommissionState = 2 AND TenantId =1 AND MallBaseId =1
AND cm.OrderId in(SELECT cm1.OrderId FROM rb_goods_ordercommission cm1 WHERE cm1.UserId in(SELECT Id FROM rb_member_user WHERE Id <> 39370 AND SuperiorId BETWEEN 1 and 20))
GROUP BY cm.OrderId,cm.UserId
)t GROUP BY t.OrderId HAVING COUNT(0)=1)
AND o.OrderId >=34137 and o.OrderId <=80622 and o.OrderId <> 63803 AND o.OrderId <> 63839
AND o.UserId in(
SELECT mu2.Id FROM rb_member_user mu1
INNER JOIN rb_member_user mu2 on mu1.Id = mu2.SuperiorId
WHERE mu1.Id <> 39370 AND mu1.SuperiorId BETWEEN 1 and 20
)
ORDER BY o.OrderId ASC;";
stringsql3=$@"SELECT o.OrderId,o.OrderNo,od.Id AS DetailId,o.UserId,u.`Name`,o.Income,o.Consignee,o.Mobile,o.ShoppingAddress,od.GoodsName,od.Specification,od.Final_Price,
od.Number,
CASE WHEN d1.Id IS NULL THEN d2.OneCommission * od.Number ELSE d1.OneCommission * od.Number END AS OneCommission,
CASE WHEN d1.Id IS NULL THEN d2.TwoCommission * od.Number ELSE d1.TwoCommission * od.Number END AS TwoCommission,
u21.Id AS FUserId,
u21.`Name` AS FName
FROM rb_goods_order o
INNER JOIN rb_goods_orderdetail od on o.OrderId=od.OrderId
INNER JOIN rb_member_user u on o.UserId = u.Id
INNER JOIN rb_member_user u21 on u.SuperiorId = u21.Id
LEFT JOIN rb_goods_distributioncommission d1 on d1.GoodsId=od.GoodsId AND d1.DistributorGrade=74 and d1.SpecificationSort=od.SpecificationSort
LEFT JOIN rb_goods_distributioncommission d2 on d2.GoodsId=od.GoodsId AND d2.DistributorGrade=74 and d2.SpecificationSort=''
WHERE o.OrderId in(
SELECT t.OrderId FROM(
SELECT cm.OrderId,cm.UserId FROM rb_goods_ordercommission cm WHERE CommissionState = 2 AND TenantId =1 AND MallBaseId =1
AND cm.OrderId in(SELECT cm1.OrderId FROM rb_goods_ordercommission cm1 WHERE cm1.UserId in(SELECT Id FROM rb_member_user WHERE Id <> 39370 AND SuperiorId BETWEEN 1 and 20))
GROUP BY cm.OrderId,cm.UserId
)t GROUP BY t.OrderId HAVING COUNT(0)=1)
AND o.OrderId >=34137 and o.OrderId <=80622 and o.OrderId <> 63803 AND o.OrderId <> 63839
AND o.UserId in(
SELECT mu2.Id FROM rb_member_user mu1
INNER JOIN rb_member_user mu2 on mu1.Id = mu2.SuperiorId
WHERE mu1.Id <> 39370 AND mu1.SuperiorId BETWEEN 1 and 20
insert into rb_goods_ordercommission (OrderId,OrderDetailId,UserId,Grade,Commission,IsGoodsDistribution,CommissionState,Remark,TenantId,MallBaseId,CreateDate,UpdateDate,Type,IsRemit)
stringUserComm=$@"update rb_distributor_info set TotalCommission=TotalCommission+{TwoCommission},CommissionWithdrawal=CommissionWithdrawal+{TwoCommission}";
insert into rb_goods_ordercommission (OrderId,OrderDetailId,UserId,Grade,Commission,IsGoodsDistribution,CommissionState,Remark,TenantId,MallBaseId,CreateDate,UpdateDate,Type,IsRemit)