@@ -655,12 +655,12 @@ sum(o.OrderProfit) as OrderProfit,sum(o.OrderSalesMoney) as OrderSalesMoney,SUM(
from(
select o.OrderId,{branchSql},o.PreferPrice,o.Income,o.Refund,o.PlatformTax,o.ZaiTuMoney,o.DiscountMoney,o.RedEnvelopeMoney,o.GuestNum,o.PreferTipAmount,(case when IFNULL(o.PreferTipAmount,0)>=IFNULL(o.CompensationMoney,0) then o.CompensationMoney else 0 end)as CompensationMoney,
case when (p.TeamType>0 or p.PriceTeamType =7) and r.TCID is not null and r.TGuestNum >0 then ROUND(r.ShiJiLiRun * IFNULL(o.GuestNum,0)/r.TGuestNum,2) else 0 end as OrderProfit,
case when p.TeamType>0 or p.PriceTeamType =7 then 0 else IFNULL(o.PreferPrice,0)- IFNULL(o.DiscountMoney,0) -IFNULL(o.RedEnvelopeMoney,0) end as OrderSalesMoney,SUM(IFNULL(o.Meet,0)) AS Meet
case when p.TeamType>0 or p.PriceTeamType =7 then 0 else IFNULL(o.PreferPrice,0)- IFNULL(o.DiscountMoney,0) -IFNULL(o.RedEnvelopeMoney,0) end as OrderSalesMoney,IFNULL(o.Meet,0) AS Meet
FROM rb_travel_order o
LEFT JOIN rb_travel_price p on o.TCID =p.TCID
left join
(SELECT r.TCID,SUM(case when r.TCID in(16381,17415,17606,17879) then case when r.TCID =16381 then 33285 else case when r.TCID =17415 then 37815 else case when r.TCID =17606 then 35820 else 32715 end end end else IFNULL(r.ShiJiLiRun,0) + IFNULL(r.TiCheng,0) - IFNULL(r.YongJinShouRu,0) end) AS ShiJiLiRun,sum(IFNULL(GuestNum,0)) as TGuestNum
FROM {(Config.IsOnline?"uat_reborn_datastatistics":"reborn_datastatistics")}.rb_revenuereport r WHERE r.Rb_Group_Id =2 and r.DataType =1 and r.Type =1 and r.StartDate >='2023-01-01' GROUP BY r.TCID) r on r.TCID =o.TCID
FROM {(Config.IsOnline?"uat_reborn_datastatistics":"reborn_datastatistics")}.rb_revenuereport r WHERE r.Rb_Group_Id ={demodel.GroupId} and r.DataType =1 and r.Type =1 and r.StartDate >='2023-01-01' GROUP BY r.TCID) r on r.TCID =o.TCID
{(demodel.LineId>0||demodel.CommissionType>0?"LEFT JOIN rb_travel_config c on p.ConfigID = c.ID":"")}
{(!string.IsNullOrEmpty(demodel.CustomerName)?"LEFT JOIN rb_travel_guest g on o.CRMGuestId = g.Id":"")}
{(demodel.BranchId>0?$"LEFT JOIN {(Config.IsOnline?"uat_reborn_user":"reborn_user")}.rb_employee e on o.EnterID = e.EmployeeId":"")}