public List <StageCustomerEntity> GetUserCustomers(string userid, string teamid, string begintime, string endtime, string agentid, string clientid) { List <StageCustomerEntity> list = new List <StageCustomerEntity>(); DataSet ds = CustomerRPTDAL.BaseProvider.GetUserCustomers(userid, teamid, begintime, endtime, agentid, clientid); DataTable dt = ds.Tables["Users"]; var stages = SystemBusiness.BaseBusiness.GetCustomStages(agentid, clientid); if (!string.IsNullOrEmpty(userid)) { #region 统计个人 StageCustomerEntity model = new StageCustomerEntity(); model.Name = OrganizationBusiness.GetUserByUserID(userid, agentid).Name; model.Stages = new List <StageCustomerItem>(); foreach (var stage in stages) { StageCustomerItem item = new StageCustomerItem(); item.Name = stage.StageName; var drs = dt.Select("StageID='" + item.StageID + "'"); if (drs.Count() > 0) { item.Count = Convert.ToInt32(drs[0]["Value"]); } else { item.Count = 0; } model.Stages.Add(item); } list.Add(model); #endregion } else if (!string.IsNullOrEmpty(teamid)) { #region 统计团队 var team = SystemBusiness.BaseBusiness.GetTeamByID(teamid, agentid); StageCustomerEntity model = new StageCustomerEntity(); model.Name = team.TeamName; model.GUID = team.TeamID; model.Stages = new List <StageCustomerItem>(); model.ChildItems = new List <StageCustomerEntity>(); //遍历成员 foreach (var user in team.Users) { StageCustomerEntity childModel = new StageCustomerEntity(); childModel.GUID = user.UserID; childModel.Name = user.Name; childModel.PID = team.TeamID; childModel.Stages = new List <StageCustomerItem>(); //遍历阶段 foreach (var stage in stages) { StageCustomerItem childItem = new StageCustomerItem(); childItem.Name = stage.StageName; var drs = dt.Select("StageID='" + stage.StageID + "' and OwnerID='" + user.UserID + "'"); if (drs.Count() > 0) { childItem.Count = Convert.ToInt32(drs[0]["Value"]); } else { childItem.Count = 0; } if (model.Stages.Where(m => m.StageID == stage.StageID).Count() > 0) { model.Stages.Where(m => m.StageID == stage.StageID).FirstOrDefault().Count += childItem.Count; } else { StageCustomerItem item = new StageCustomerItem(); item.Name = stage.StageName; item.StageID = stage.StageID; item.Count = childItem.Count; model.Stages.Add(item); } childModel.Stages.Add(childItem); } model.ChildItems.Add(childModel); } list.Add(model); #endregion } else { #region 统计所有 var teams = SystemBusiness.BaseBusiness.GetTeams(agentid); foreach (var team in teams) { StageCustomerEntity model = new StageCustomerEntity(); model.Name = team.TeamName; model.GUID = team.TeamID; model.Stages = new List <StageCustomerItem>(); model.ChildItems = new List <StageCustomerEntity>(); //遍历成员 foreach (var user in team.Users) { StageCustomerEntity childModel = new StageCustomerEntity(); childModel.GUID = user.UserID; childModel.Name = user.Name; childModel.PID = team.TeamID; childModel.Stages = new List <StageCustomerItem>(); //遍历阶段 foreach (var stage in stages) { StageCustomerItem childItem = new StageCustomerItem(); childItem.Name = stage.StageName; var drs = dt.Select("StageID='" + stage.StageID + "' and OwnerID='" + user.UserID + "'"); if (drs.Count() > 0) { childItem.Count = Convert.ToInt32(drs[0]["Value"]); } else { childItem.Count = 0; } if (model.Stages.Where(m => m.StageID == stage.StageID).Count() > 0) { model.Stages.Where(m => m.StageID == stage.StageID).FirstOrDefault().Count += childItem.Count; } else { StageCustomerItem item = new StageCustomerItem(); item.Name = stage.StageName; item.StageID = stage.StageID; item.Count = childItem.Count; model.Stages.Add(item); } childModel.Stages.Add(childItem); } model.ChildItems.Add(childModel); } list.Add(model); } #endregion } return(list); }
public List <StageCustomerEntity> GetUserOpportunitys(string userid, string teamid, string begintime, string endtime, string agentid, string clientid) { List <StageCustomerEntity> list = new List <StageCustomerEntity>(); DataSet ds = SalesRPTDAL.BaseProvider.GetUserOpportunitys(userid, teamid, begintime, endtime, agentid, clientid); DataTable dt = ds.Tables["Users"]; var stages = SystemBusiness.BaseBusiness.GetOpportunityStages(agentid, clientid); #region 统计所有 var teams = SystemBusiness.BaseBusiness.GetTeams(agentid); foreach (var team in teams) { StageCustomerEntity model = new StageCustomerEntity(); model.Name = team.TeamName; model.GUID = team.TeamID; model.Stages = new List <StageCustomerItem>(); model.ChildItems = new List <StageCustomerEntity>(); //遍历成员 foreach (var user in team.Users) { StageCustomerEntity childModel = new StageCustomerEntity(); childModel.GUID = user.UserID; childModel.Name = user.Name; childModel.PID = team.TeamID; childModel.Stages = new List <StageCustomerItem>(); //遍历阶段 foreach (var stage in stages) { StageCustomerItem childItem = new StageCustomerItem(); childItem.Name = stage.StageName; var drs = dt.Select("StageID='" + stage.StageID + "' and OwnerID='" + user.UserID + "'"); if (drs.Count() > 0) { childItem.Count = Convert.ToInt32(drs[0]["Value"]); childItem.Money = Convert.ToDecimal(drs[0]["TotalMoney"]); } else { childItem.Count = 0; childItem.Money = 0; } if (model.Stages.Where(m => m.StageID == stage.StageID).Count() > 0) { model.Stages.Where(m => m.StageID == stage.StageID).FirstOrDefault().Count += childItem.Count; model.Stages.Where(m => m.StageID == stage.StageID).FirstOrDefault().Money += childItem.Money; } else { StageCustomerItem item = new StageCustomerItem(); item.Name = stage.StageName; item.StageID = stage.StageID; item.Count = childItem.Count; item.Money = childItem.Money; model.Stages.Add(item); } childModel.Stages.Add(childItem); } model.ChildItems.Add(childModel); } list.Add(model); } #endregion return(list); }