Пример #1
0
        public ActionResult Index(Orders Orders, EFPagingInfo <Orders> p, bool?IsShowSupAgent, int IsFirst = 0, int TimeType = 1)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            p          = this.Condition(Orders, p, IsShowSupAgent, TimeType);
            p.PageSize = 1000;
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <Orders> OrdersList = null;

            if (IsFirst == 0)
            {
                OrdersList = new PageOfItems <Orders>(new List <Orders>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                OrdersList = Entity.Selects <Orders>(p);
            }

            ViewBag.OrdersList = OrdersList;
            ViewBag.Orders     = Orders;
            IList <Orders> List = OrdersList.GroupBy(n => n.UId).Select(n => n.First()).ToList();
            List <int>     UId  = new List <int>();

            foreach (var pp in List)
            {
                UId.Add(pp.UId);
            }
            var agentIDs           = OrdersList.Select(o => o.Agent).Distinct().ToList();
            var OrdersListSysAgent = Entity.SysAgent.Where(o => agentIDs.Contains(o.Id)).ToList();//订单对应的代理

            ViewBag.UsersList          = Entity.Users.Where(n => n.State == 1 && UId.Contains(n.Id)).ToList();
            ViewBag.PayConfigList      = Entity.PayConfig.Where(n => n.State == 1).ToList();
            ViewBag.SysAgentList       = Entity.SysAgent.Where(n => n.State == 1).ToList();
            ViewBag.IsShowSupAgent     = IsShowSupAgent;
            ViewBag.OrdersListSysAgent = OrdersListSysAgent;
            ViewBag.Xls      = this.checkPower("Xls");
            ViewBag.TimeType = TimeType;
            return(View());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="Orders"></param>
        /// <param name="p"></param>
        /// <param name="IsShowSupAgent">是否显示下级</param>
        /// <param name="LowerLevel">下级代理商</param>
        /// <returns></returns>
        public ActionResult Index(Orders Orders, EFPagingInfo <Orders> p, bool?IsShowSupAgent, int?LowerLevel, int IsFirst = 0)
        {
            bool IsAll = false;

            if (checkPower("ALL"))
            {
                IsAll = true;
            }
            ViewBag.IsAll = IsAll;
            #region 条件校验
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            LowerLevel = LowerLevel == null ? 0 : LowerLevel;
            p.SqlWhere.Add(f => f.PayState != 0);
            p.SqlWhere.Add(f => f.TState == 2);
            if (!Orders.TNum.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TNum == Orders.TNum);
            }
            if (!Orders.TName.IsNullOrEmpty())
            {
                IList <Users> UList = Entity.Users.Where(n => n.TrueName == Orders.TName || n.NeekName == Orders.TName || n.UserName == Orders.TName).ToList();
                List <int>    UIds  = new List <int>();
                foreach (var pp in UList)
                {
                    UIds.Add(pp.Id);
                }
                p.SqlWhere.Add(f => UIds.Contains(f.UId));
            }
            if (!Orders.TType.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TType == Orders.TType);
            }
            if (!Orders.AId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AId == Orders.AId);
            }
            if (!Orders.AgentState.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AgentState == Orders.AgentState);
            }
            if (!Orders.STime.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.PayTime > Orders.STime);
            }
            else
            {
                Orders.STime = DateTime.Now.AddMonths(-1);
            }
            if (!Orders.ETime.IsNullOrEmpty())
            {
                DateTime ETime = Orders.ETime;
                p.SqlWhere.Add(f => f.PayTime < ETime);
            }
            else
            {
                Orders.ETime = DateTime.Now;
            }
            TimeSpan TS   = Orders.ETime.Subtract(Orders.STime);
            int      Days = TS.Days;
            if (Days > 31)
            {
                ViewBag.ErrorMsg = "统计时间间隔不能超过31天!";
                return(View("Error"));
            }
            if (IsAll)
            {
                IList <SysAgent> SysAgentList = null;
                if ((bool)IsShowSupAgent)
                {
                    IList <int> UID = new List <int>();
                    if (LowerLevel != 0)
                    {
                        SysAgent LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == LowerLevel).FirstOrNew();
                        SysAgentList = LowerLevelAgent.GetSupAgent(Entity, true);
                    }
                    else
                    {
                        SysAgentList = BasicAgent.GetSupAgent(Entity, true);//获取所有下级代理商信息
                    }
                    UID = SysAgentList.Select(o => o.Id).ToList();
                    p.SqlWhere.Add(f => UID.Contains(f.Agent));
                }
                else
                {
                    p.SqlWhere.Add(f => f.Agent == BasicAgent.Id);//读取全部分支机构
                }
            }
            else
            {
                p.SqlWhere.Add(f => f.AId == AdminUser.Id);//读取用户
            }
            #endregion
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <Orders> OrdersList = null;
            if (IsFirst == 0)
            {
                OrdersList = new PageOfItems <Orders>(new List <Orders>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                OrdersList = Entity.Selects <Orders>(p);
            }

            ViewBag.OrdersList = OrdersList;
            ViewBag.Orders     = Orders;
            //统计查询
            if (OrdersList.TotalCount > 0)
            {
                var iquery = Entity.Orders.AsQueryable();
                foreach (var item in p.SqlWhere)
                {
                    iquery = iquery.Where(item);
                }
                //总金额
                decimal SumAmoney = iquery.Sum(o => o.Amoney);
                ViewBag.SumAmoney = SumAmoney;
                //我的总佣金
                decimal?SumMyProfit = Entity.OrderProfitLog.Where(o => o.Agent == BasicAgent.Id).Join(iquery, op => op.TNum, o => o.TNum, (op, o) => op.Profit).Sum(o => (decimal?)o);
                ViewBag.SumMyProfit = SumMyProfit;
            }

            //商户查询
            IList <Orders> List = OrdersList.GroupBy(n => n.UId).Select(n => n.First()).ToList();
            List <int>     UId  = new List <int>();
            foreach (var pp in List)
            {
                UId.Add(pp.UId);
            }
            Dictionary <string, decimal> DicOrderProfitLog = new Dictionary <string, decimal>();
            IList <Users> UsersList = Entity.Users.Where(n => UId.Contains(n.Id)).ToList();
            foreach (var item in OrdersList)
            {
                DicOrderProfitLog.Add(item.TNum, Entity.OrderProfitLog.Where(o => o.TNum == item.TNum && o.Agent == BasicAgent.Id).Select(o => o.Profit).FirstOrDefault());
            }
            ViewBag.DicOrderProfitLog = DicOrderProfitLog;
            ViewBag.UsersList         = UsersList;
            ViewBag.SysAdminList      = Entity.SysAdmin.Where(n => n.State == 1 && n.AgentId == AdminUser.AgentId).ToList();
            //ViewBag.PayConfigList = Entity.PayConfig.Where(n => n.State == 1).ToList();
            ViewBag.IsShowSupAgent = IsShowSupAgent;
            ViewBag.BasicAgent     = BasicAgent;
            SysSet SysSet = Entity.SysSet.FirstOrNew();
            ViewBag.SysSet     = SysSet;
            ViewBag.LowerLevel = LowerLevel;
            ViewBag.Edit       = this.checkPower("Edit");
            return(View());
        }
        public ActionResult Index(Orders Orders, EFPagingInfo <Orders> p, bool?IsShowSupAgent, int IsFirst = 0)
        {
            this.TempData.Remove("SysAgentList");
            #region 校验与初始化
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }

            if (Orders.STime.IsNullOrEmpty())
            {
                Orders.STime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            }
            if (Orders.ETime.IsNullOrEmpty())
            {
                //Orders.ETime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                Orders.ETime = DateTime.Now;
            }
            p.SqlWhere.Add(f => f.PayState == 1);
            p.SqlWhere.Add(f => f.TState == 2);
            if (!Orders.TNum.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TNum == Orders.TNum);
            }
            if (!Orders.TName.IsNullOrEmpty())
            {
                IList <Users> UList = Entity.Users.Where(n => n.TrueName == Orders.TName || n.NeekName == Orders.TName || n.UserName == Orders.TName).ToList();
                List <int>    UIds  = new List <int>();
                foreach (var pp in UList)
                {
                    UIds.Add(pp.Id);
                }
                p.SqlWhere.Add(f => UIds.Contains(f.UId));
            }
            if (!Orders.TType.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TType == Orders.TType);
            }
            if (!Orders.Agent.IsNullOrEmpty())
            {
                //是否要显示下级
                if ((bool)IsShowSupAgent)
                {
                    SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == Orders.Agent).FirstOrNew();
                    IList <SysAgent> SysAgentList    = LowerLevelAgent.GetSupAgent(Entity);
                    IList <int>      UID             = new List <int>();
                    foreach (var s in SysAgentList)
                    {
                        UID.Add(s.Id);
                    }
                    p.SqlWhere.Add(f => UID.Contains(f.Agent));
                }
                else
                {
                    p.SqlWhere.Add(f => f.Agent == Orders.Agent);
                }
            }
            if (!Orders.AgentState.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AgentState == (Orders.AgentState == 99 ? 0 : Orders.AgentState));
            }
            if (!Orders.STime.IsNullOrEmpty() && !Orders.ETime.IsNullOrEmpty())
            {
                DateTime ETime = Orders.ETime;
                p.SqlWhere.Add(f => f.PayTime > Orders.STime && f.PayTime < ETime);
            }
            #endregion
            p.PageSize = 99999999;
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <Orders> OrdersList = null;
            if (IsFirst == 0)
            {
                OrdersList = new PageOfItems <Orders>(new List <Orders>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                OrdersList = Entity.Selects <Orders>(p);
            }
            ViewBag.OrdersList = OrdersList;
            ViewBag.Orders     = Orders;
            IList <Orders> List = OrdersList.GroupBy(n => n.UId).Select(n => n.First()).ToList();
            List <int>     UId  = new List <int>();
            foreach (var pp in List)
            {
                UId.Add(pp.UId);
            }
            ViewBag.UsersList     = Entity.Users.Where(n => n.State == 1 && UId.Contains(n.Id)).ToList();
            ViewBag.PayConfigList = Entity.PayConfig.Where(n => n.State == 1).ToList();
            IList <Orders> List1   = OrdersList.GroupBy(n => n.Agent).Select(n => n.First()).ToList();
            List <int>     AgentId = new List <int>();
            foreach (var pp in List1)
            {
                AgentId.Add(pp.Agent);
            }
            ViewBag.SysAgentList          = Entity.SysAgent.Where(n => AgentId.Contains(n.Id) && n.Tier == 1).ToList();
            this.TempData["SysAgentList"] = ViewBag.SysAgentList;
            ViewBag.SelectSysAgentList    = Entity.SysAgent.Where(n => n.State == 1).ToList();
            ViewBag.IsShowSupAgent        = IsShowSupAgent;
            ViewBag.Xls = this.checkPower("Xls");
            return(View());
        }