public void GetUsers(string UserName, bool?IsShowSupAgent)
        {
            if (UserName.IsNullOrEmpty())
            {
                Response.Write("[]");
                return;
            }
            IList <Users> List = null;

            if (!(bool)IsShowSupAgent)
            {
                List = Entity.Users.Where(n => (n.TrueName.Contains(UserName) || n.NeekName.Contains(UserName) || n.UserName == UserName) && n.Agent == BasicAgent.Id).ToList();
                //List = List.Where(n => n.Agent == BasicAgent.Id).ToList();
            }
            else
            {
                SysAgent         LowerLevelAgent = Entity.SysAgent.FirstOrDefault(s => s.Id == BasicAgent.Id);
                IList <SysAgent> SysAgentList    = LowerLevelAgent.GetSupAgent(Entity);
                IList <int>      UID             = new List <int>();
                foreach (var s in SysAgentList)
                {
                    UID.Add(s.Id);
                }
                List = Entity.Users.Where(n => (n.TrueName.Contains(UserName) || n.NeekName.Contains(UserName) || n.UserName == UserName) && UID.Contains(n.Agent)).ToList();
                // List = List.Where(n => UID.Contains(n.Agent)).ToList();
            }
            foreach (var p in List)
            {
                p.Cols = "Id,UserName,TrueName,NeekName";
            }
            string Json = List.EntityToJson();

            Response.Write(Json);
        }
        public ActionResult Index(JobOrders JobOrders, EFPagingInfo <JobOrders> p, bool?IsShowSupAgent, int?LowerLevel, DateTime?STime, DateTime?ETime, int IsFirst = 0)
        {
            IPageOfItems <JobOrders> JobOrdersList = null;

            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            ViewBag.BasicAgent = BasicAgent;
            ViewBag.IsAll      = IsAll;
            LowerLevel         = LowerLevel == null ? 0 : LowerLevel;
            if (IsFirst == 0)
            {
                JobOrders.State = 99;
                JobOrdersList   = new PageOfItems <JobOrders>(new List <JobOrders>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                p = this.Condition(JobOrders, p, STime, ETime);

                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.AgentId));
                }
                else
                {
                    p.SqlWhere.Add(f => f.AgentId == BasicAgent.Id);//读取全部分支机构
                }

                JobOrdersList = Entity.Selects <JobOrders>(p);
            }
            ViewBag.JobOrdersList  = JobOrdersList;
            ViewBag.JobOrders      = JobOrders;
            ViewBag.Edit           = this.checkPower("Edit");
            ViewBag.ETime          = ETime;
            ViewBag.STime          = STime;
            ViewBag.IsShowSupAgent = IsShowSupAgent;
            ViewBag.LowerLevel     = LowerLevel;
            List <int> UId = JobOrdersList.Select(o => o.UId).Distinct().ToList();

            ViewBag.UsersList = Entity.Users.Where(n => n.State == 1 && UId.Contains(n.Id)).ToList();
            return(View());
        }
Ejemplo n.º 3
0
        private EFPagingInfo <OrderProfitLog> Condition(OrderProfitLog OrderProfitLog, EFPagingInfo <OrderProfitLog> p, string TName, DateTime?STime, DateTime?ETime, bool?IsShowSupAgent)
        {
            #region 校验与初始化

            // p.SqlWhere.Add(f => f.PayState == 1);
            if (!OrderProfitLog.TNum.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TNum == OrderProfitLog.TNum);
            }
            if (!TName.IsNullOrEmpty())
            {
                IList <Users> UList = Entity.Users.Where(n => n.TrueName == TName || n.NeekName == TName || n.UserName == 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 (!OrderProfitLog.Agent.IsNullOrEmpty())
            {
                //是否要显示下级
                if ((bool)IsShowSupAgent)
                {
                    SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == OrderProfitLog.Agent).FirstOrNew();
                    IList <SysAgent> AgentsList      = LowerLevelAgent.GetSupAgent(Entity);
                    IList <int>      UID             = new List <int>();
                    foreach (var s in AgentsList)
                    {
                        UID.Add(s.Id);
                    }
                    p.SqlWhere.Add(f => UID.Contains(f.Agent));
                }
                else
                {
                    p.SqlWhere.Add(f => f.Agent == OrderProfitLog.Agent);
                }
            }
            //if (!JobOrders.AgentState.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.AgentState == (JobOrders.AgentState == 99 ? 0 : JobOrders.AgentState)); }
            if (!STime.IsNullOrEmpty() && !ETime.IsNullOrEmpty())
            {
                DateTime ETimes = ETime.Value;
                p.SqlWhere.Add(f => f.AddTime > STime && f.AddTime < ETimes);
            }
            #endregion
            p.SqlWhere.Add(o => o.OrderType == 31);
            p.OrderByList.Add("Id", "DESC");

            return(p);
        }
        public ActionResult Index(Orders Orders, bool?IsShowSupAgent, int IsFirst = 0)
        {
            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;
            }
            EFPagingInfo <ApplyCredit> cp = new EFPagingInfo <ApplyCredit>();
            EFPagingInfo <ApplyLoan>   lp = new EFPagingInfo <ApplyLoan>();

            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);
                    }
                    cp.SqlWhere.Add(f => UID.Contains(f.AgentId));
                    lp.SqlWhere.Add(f => UID.Contains(f.AgentId));
                }
                else
                {
                    cp.SqlWhere.Add(f => f.AgentId == Orders.Agent);
                    lp.SqlWhere.Add(f => f.AgentId == Orders.Agent);
                }
            }
            if (!Orders.STime.IsNullOrEmpty() && !Orders.ETime.IsNullOrEmpty())
            {
                DateTime ETime = Orders.ETime;
                cp.SqlWhere.Add(f => f.PayTime > Orders.STime && f.PayTime < ETime);
                lp.SqlWhere.Add(f => f.PayTime > Orders.STime && f.PayTime < ETime);
            }
            cp.SqlWhere.Add(f => f.PayState == 1);
            lp.SqlWhere.Add(f => f.PayState == 1);
            cp.PageSize = 99999999;
            lp.PageSize = 99999999;
            cp.OrderByList.Add("Id", "DESC");
            lp.OrderByList.Add("Id", "DESC");
            IPageOfItems <ApplyCredit> ApplyCreditList = null;
            IPageOfItems <ApplyLoan>   ApplyLoanList   = null;

            if (IsFirst == 0)
            {
                ApplyLoanList   = new PageOfItems <ApplyLoan>(new List <ApplyLoan>(), 0, 10, 0, new Hashtable());
                ApplyCreditList = new PageOfItems <ApplyCredit>(new List <ApplyCredit>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                if (Orders.TType.IsNullOrEmpty())
                {
                    ApplyCreditList = Entity.Selects <ApplyCredit>(cp);
                    ApplyLoanList   = Entity.Selects <ApplyLoan>(lp);
                }
                else if (Orders.TType == 1)
                {
                    ApplyCreditList = Entity.Selects <ApplyCredit>(cp);
                    ApplyLoanList   = new PageOfItems <ApplyLoan>(new List <ApplyLoan>(), 0, 10, 0, new Hashtable());
                }
                else if (Orders.TType == 2)
                {
                    ApplyLoanList   = Entity.Selects <ApplyLoan>(lp);
                    ApplyCreditList = new PageOfItems <ApplyCredit>(new List <ApplyCredit>(), 0, 10, 0, new Hashtable());
                }
                else
                {
                    ApplyLoanList   = new PageOfItems <ApplyLoan>(new List <ApplyLoan>(), 0, 10, 0, new Hashtable());
                    ApplyCreditList = new PageOfItems <ApplyCredit>(new List <ApplyCredit>(), 0, 10, 0, new Hashtable());
                }
            }
            ViewBag.ApplyLoanList   = ApplyLoanList;
            ViewBag.ApplyCreditList = ApplyCreditList;
            ViewBag.Orders          = Orders;
            ViewBag.SysAgentList    = Entity.SysAgent.Where(n => n.Tier == 1).ToList();
            ViewBag.IsShowSupAgent  = IsShowSupAgent;
            ViewBag.Xls             = this.checkPower("Xls");
            return(View());
        }
        public ActionResult Index(StopPayAudit StopPayAudit, EFPagingInfo <StopPayAudit> p, bool IsShowSupAgent = false, int LowerLevel = 0, int IsFirst = 0)
        {
            #region 条件

            if (!StopPayAudit.Agent.IsNullOrEmpty())
            {
                //是否要显示下级
                if ((bool)IsShowSupAgent)
                {
                    SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == StopPayAudit.Agent).FirstOrNew();
                    IList <SysAgent> SysAgentList    = LowerLevelAgent.GetSupAgent(Entity, true);
                    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 == StopPayAudit.Agent);
                }
            }
            if (!StopPayAudit.TState.IsNullOrEmpty())
            {
                p.SqlWhere.Add(o => o.TState == StopPayAudit.TState);
            }
            if (!StopPayAudit.CreateAdminName.IsNullOrEmpty())
            {
                List <int> uids = new List <int>();
                if (StopPayAudit.UId == 1)
                {
                    uids = Entity.Users.Where(o => o.UserName == StopPayAudit.CreateAdminName).Select(o => o.Id).ToList();
                }
                else if (StopPayAudit.UId == 2)
                {
                    uids = Entity.Users.Where(o => o.Mobile == StopPayAudit.CreateAdminName).Select(o => o.Id).ToList();
                }
                else if (StopPayAudit.UId == 3)
                {
                    uids = Entity.Users.Where(o => o.TrueName == StopPayAudit.CreateAdminName).Select(o => o.Id).ToList();
                }
                p.SqlWhere.Add(f => uids.Contains(f.UId));
            }
            #endregion
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <StopPayAudit> StopPayAuditList = null;
            if (IsFirst == 0)
            {
                StopPayAuditList = new PageOfItems <StopPayAudit>(new List <StopPayAudit>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                StopPayAuditList = Entity.Selects <StopPayAudit>(p);
            }
            ViewBag.StopPayAuditList = StopPayAuditList;
            ViewBag.StopPayAudit     = StopPayAudit;
            //用户表
            var SPAUsersList = StopPayAuditList.Select(o => o.UId).ToList();
            ViewBag.UserSelect = Entity.Users.Where(o => SPAUsersList.Contains(o.Id)).ToList();

            ViewBag.SysAgentList   = Entity.SysAgent.Where(n => n.Tier == 1).ToList();
            ViewBag.IsShowSupAgent = IsShowSupAgent;//是否显示下级
            ViewBag.IsAudit        = this.checkPower("Audit");
            return(View());
        }
        /// <summary>
        /// 解冻管理
        /// </summary>
        /// <param name="Users"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public ActionResult Index(StopPayAudit StopPayAudit, EFPagingInfo <StopPayAudit> p, bool IsShowSupAgent = false, int LowerLevel = 0, int UserSelect = 1, int IsFirst = 0)
        {
            if (!StopPayAudit.TState.IsNullOrEmpty())
            {
                p.SqlWhere.Add(o => o.TState == StopPayAudit.TState);
            }
            //一级只有的功能
            if (BasicAgent.Tier == 1)
            {
                IList <SysAgent> SysAgentList = null;
                if (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.Agent == BasicAgent.Id);
            }

            if (!StopPayAudit.CreateAdminName.IsNullOrEmpty())
            {
                List <int> uids = new List <int>();
                if (StopPayAudit.UId == 1)
                {
                    uids = Entity.Users.Where(o => o.UserName == StopPayAudit.CreateAdminName).Select(o => o.Id).ToList();
                }
                else if (StopPayAudit.UId == 2)
                {
                    uids = Entity.Users.Where(o => o.Mobile == StopPayAudit.CreateAdminName).Select(o => o.Id).ToList();
                }
                else if (StopPayAudit.UId == 3)
                {
                    uids = Entity.Users.Where(o => o.TrueName == StopPayAudit.CreateAdminName).Select(o => o.Id).ToList();
                }
                p.SqlWhere.Add(f => uids.Contains(f.UId));
            }
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <StopPayAudit> StopPayAuditList = null;

            if (IsFirst == 0)
            {
                StopPayAuditList = new PageOfItems <StopPayAudit>(new List <StopPayAudit>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                StopPayAuditList = Entity.Selects <StopPayAudit>(p);
            }
            //用户表
            var SPAUsersList = StopPayAuditList.Select(o => o.UId).ToList();

            ViewBag.UserSelect = Entity.Users.Where(o => SPAUsersList.Contains(o.Id)).ToList();

            ViewBag.StopPayAuditList = StopPayAuditList;
            ViewBag.StopPayAudit     = StopPayAudit;
            ViewBag.IsShowSupAgent   = IsShowSupAgent;
            ViewBag.LowerLevel       = LowerLevel;
            return(View());
        }
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[Users]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            Users Users = new Users();

            Users = JsonToObject.ConvertJsonToModel(Users, json);

            //获取用户信息
            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == Users.Token);

            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            if (baseUsers.CardStae != 2)//未实名认证
            {
                DataObj.OutError("2006");
                return;
            }
            if (baseUsers.MiBao != 1)//未设置支付密码
            {
                DataObj.OutError("2008");
                return;
            }
            if (Users.UserType != 1 && Users.UserType != 2)
            {
                DataObj.OutError("9002");
                return;
            }

            //判断是否为代理商
            SysAgent         SysAgent     = Entity.SysAgent.FirstOrDefault(o => o.LinkMobile == baseUsers.UserName && o.State == 1);
            IList <SysAgent> SysAgentList = null;
            IList <Users>    UsersList    = null;
            SysSet           baseSysSet   = Entity.SysSet.FirstOrDefault();

            //1用户2代理商
            if (SysAgent == null && Users.UserType == 2)
            {
                DataObj.OutError("9003");
                return;
            }
            //if (Users.UserType == 1 && SysAgent!=null)
            //{
            //    UsersList = baseUsers.GetSupUsers(Entity, baseSysSet.GlobaPromoteMaxLevel);
            //    SysAgentList = SysAgent.GetSupAgent(Entity);
            //    IList<int> agents = SysAgentList.Select(o => o.Id).ToList();
            //    IList<Users> AgentUsersList = Entity.Users.Where(o => agents.Contains(o.Agent)).ToList();
            //    UsersList = UsersList.Concat(AgentUsersList).ToList();
            //}
            if (Users.UserType == 1)
            {
                UsersList = baseUsers.GetSupUsers(Entity, baseSysSet.GlobaPromoteMaxLevel);
            }
            if (Users.UserType == 2)
            {
                SysAgentList = SysAgent.GetSupAgent(Entity);
                //IList<int> agents = SysAgentList.Select(o => o.Id).ToList();
                //UsersList = Entity.Users.Where(o => agents.Contains(o.Agent)).ToList();
                IList <string> agents = SysAgentList.Select(o => o.LinkMobile).ToList();
                UsersList = Entity.Users.Where(o => agents.Contains(o.UserName)).ToList();
            }

            EFPagingInfo <Users> p = new EFPagingInfo <Users>();

            if (!Users.Pg.IsNullOrEmpty())
            {
                p.PageIndex = Users.Pg;
            }
            if (!Users.Pgs.IsNullOrEmpty())
            {
                p.PageSize = Users.Pgs;
            }
            if (UsersList == null)
            {
                p.SqlWhere.Add(o => o.Id == 0);
                p.OrderByList.Add("Id", "DESC");
                IPageOfItems <Users> List1  = Entity.Selects <Users>(p);
                IList <Users>        iList1 = List1.ToList();
                StringBuilder        sb1    = new StringBuilder("");
                sb1.Append("{");
                sb1.Append(List1.PageToString());
                sb1.Append(",");
                sb1.Append(iList1.EntityToString());
                sb1.Append("}");
                DataObj.Data = sb1.ToString();
                DataObj.Code = "0000";
                DataObj.OutString();
                return;
            }
            IList <int> usersid = UsersList.Where(o => o.Id != baseUsers.Id).Select(o => o.Id).ToList();

            p.SqlWhere.Add(f => usersid.Contains(f.Id));
            p.SqlWhere.Add(f => f.Id != baseUsers.Id);
            p.OrderByList.Add("Agent", "ASC");

            IPageOfItems <Users> List = Entity.Selects <Users>(p);

            IList <Users> iList = List.ToList();

            foreach (var info in iList)
            {
                if (Users.UserType == 1)
                {
                    if (info.MyPId != baseUsers.Id)
                    {
                        info.TrueName = info.TrueName.IsNullOrEmpty() ? "未认证" : info.TrueName.Substring(0, 1) + "**";
                        info.UserName = info.UserName.Substring(0, 3) + "****" + info.UserName.Substring(7, 4);
                    }
                    else
                    {
                        info.TrueName = info.TrueName.IsNullOrEmpty() ? "未认证" : info.TrueName;
                    }
                }
                if (Users.UserType == 2)
                {
                    SysAgent agentTemp = Entity.SysAgent.FirstOrDefault(o => o.Id == info.Agent);
                    if (agentTemp == null || agentTemp.AgentID != SysAgent.Id)
                    {
                        info.TrueName = info.TrueName.IsNullOrEmpty() ? "未认证" : info.TrueName.Substring(0, 1) + "**";
                        info.UserName = info.UserName.Substring(0, 3) + "****" + info.UserName.Substring(7, 4);
                    }
                    else
                    {
                        info.TrueName = info.TrueName.IsNullOrEmpty() ? "未认证" : info.TrueName;
                    }
                }
            }
            StringBuilder sb = new StringBuilder("");

            sb.Append("{");
            sb.Append(List.PageToString());
            sb.Append(",");
            sb.Append(iList.EntityToString());
            sb.Append("}");
            DataObj.Data = sb.ToString();
            DataObj.Code = "0000";
            DataObj.OutString();
        }
        public ActionResult Index(Card Card, EFPagingInfo <Card> p, string Num0, string Num1, bool?IsShowSupAgent, int IsFirst = 0)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            if (IsFirst == 0)
            {
                PageOfItems <Card> CardList1 = new PageOfItems <Card>(new List <Card>(), 0, 10, 0, new Hashtable());
                ViewBag.CardList       = CardList1;
                ViewBag.Card           = Card;
                ViewBag.SysAgentList   = Entity.SysAgent.Where(n => n.State == 1).ToList();
                ViewBag.Num0           = Num0;
                ViewBag.Num1           = Num1;
                ViewBag.IsShowSupAgent = IsShowSupAgent;
                ViewBag.Add            = this.checkPower("Add");
                ViewBag.Xls            = this.checkPower("Xls");
                ViewBag.Save           = this.checkPower("Save");
                return(View());
            }
            if (!Card.Code.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Code == Card.Code);
            }
            if (!Card.AId.IsNullOrEmpty())
            {
                //是否要显示下级
                if ((bool)IsShowSupAgent)
                {
                    SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == Card.AId).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.AId));
                }
                else
                {
                    p.SqlWhere.Add(f => f.AId == Card.AId);
                }
            }
            if (!Card.State.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.State == (Card.State == 99 ? 0 : Card.State));
            }
            if (!Card.Auto.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Auto == (Card.Auto == 99 ? 0 : Card.Auto));
            }
            if (!Num0.IsNullOrEmpty() && !Num1.IsNullOrEmpty())
            {
                long num0 = Int64.Parse(Num0);
                long num1 = Int64.Parse(Num1);
                num0 = num0 - 1000000000;
                num1 = num1 - 1000000000;
                p.SqlWhere.Add(f => f.Id >= num0 && f.Id <= num1);
            }
            else
            {
                if (!Num0.IsNullOrEmpty())
                {
                    p.SqlWhere.Add(f => f.Code == Num0);
                }
            }
            p.OrderByList.Add("Id", "DESC");
            if (p.PageSize.IsNullOrEmpty())
            {
                p.PageSize = 20;
            }
            if (p.PageSize == 10)
            {
                p.PageSize = 20;
            }
            IPageOfItems <Card> CardList = Entity.Selects <Card>(p);

            ViewBag.CardList       = CardList;
            ViewBag.Card           = Card;
            ViewBag.SysAgentList   = Entity.SysAgent.Where(n => n.State == 1).ToList();
            ViewBag.Num0           = Num0;
            ViewBag.Num1           = Num1;
            ViewBag.IsShowSupAgent = IsShowSupAgent;
            ViewBag.Add            = this.checkPower("Add");
            ViewBag.Xls            = this.checkPower("Xls");
            ViewBag.Save           = this.checkPower("Save");
            return(View());
        }
        public object Save(SysAgent SysAgent, List <string> PId, List <Attach> Contract, Attach IDCard_Front, Attach IDCard_Reverse, Attach IDCard_Hand, List <Attach> Certificate, List <int> DelIds, string PassWord, int?AnsyCash0, int?AnsyNext0, int?AnsyCash1, int?AnsyNext1)
        {
            SysAgent baseSysAgent = Entity.SysAgent.FirstOrDefault(n => n.Id == SysAgent.Id);

            if (baseSysAgent == null)
            {
                ViewBag.ErrorMsg = AgentLanguage.Empty;
                return(View("Error"));
            }
            if (!IsBelongToAgent(baseSysAgent.Id))
            {
                ViewBag.ErrorMsg = AgentLanguage.Surmount;
                return(View("Error"));
            }
            if (SysAgent.Tel.Contains("400-608-6765") || SysAgent.Tel.Contains("23769678") || SysAgent.Tel.Contains("22220076") || SysAgent.Tel.Contains("4006086765"))
            {
                ViewBag.ErrorMsg = "该客服号码禁止使用";
                return(View("Error"));
            }
            SysAgent.PayGet  = SysAgent.PayGet.IsNullOrEmpty() ? 0 : SysAgent.PayGet / 100;
            SysAgent.CashGet = 0;//SysAgent.CashGet.IsNullOrEmpty() ? 0 : SysAgent.CashGet / 100;
            SysAgent.LoanGet = SysAgent.LoanGet.IsNullOrEmpty() ? 0 : SysAgent.LoanGet / 100;
            SysAgent.Credit  = SysAgent.Credit.IsNullOrEmpty() ? 0 : SysAgent.Credit / 100;

            SysAgent.Cash0 = SysAgent.Cash0.IsNullOrEmpty() ? 0 : SysAgent.Cash0 / 1000;
            SysAgent.Cash1 = SysAgent.Cash1.IsNullOrEmpty() ? 0 : SysAgent.Cash1 / 1000;

            bool MySysAgentMoney = this.checkPower("MySysAgent", "MoneySave");

            if (!MySysAgentMoney)
            {
                //无权限的时候,以上级代理为准
                SysAgent.Cash0      = BasicAgent.Cash0;
                SysAgent.Cash1      = BasicAgent.Cash1;
                SysAgent.ECash0     = BasicAgent.ECash0;
                SysAgent.ECash1     = BasicAgent.ECash1;
                SysAgent.Cash0Times = BasicAgent.Cash0Times;
                SysAgent.Cash1Times = BasicAgent.Cash1Times;
            }

            if (SysAgent.Cash0 < BasicSet.AgentCash0 || SysAgent.ECash0 < BasicSet.AgentECash0 || SysAgent.Cash1 < BasicSet.AgentCash1 || SysAgent.ECash1 < BasicSet.AgentECash1)
            {
                ViewBag.ErrorMsg = "费率设置有误!";
                return(View("Error"));
            }
            if (SysAgent.Cash0Times > BasicSet.AgentCash0Times || SysAgent.Cash1Times > BasicSet.AgentCash1Times)
            {
                ViewBag.ErrorMsg = "费率设置有误!";
                return(View("Error"));
            }

            SysAgent.AgentState = SysAgent.AgentState;

            //已绑定,手机不能改
            if (!baseSysAgent.MyUId.IsNullOrEmpty())
            {
                SysAgent.LinkMobile = baseSysAgent.LinkMobile;
            }
            bool IsLock = false;

            if (baseSysAgent.State == 1 && SysAgent.State == 0)
            {
                IsLock = true;
            }
            //保存销售记录为了取得id
            var salesLog = new SalesLog()
            {
                AddTime    = DateTime.Now,
                AgentFee   = SysAgent.AgentFee,
                ExpireTime = SysAgent.ExpireTime,
                State      = 1,
                AgentId    = SysAgent.Id,
                Salesman   = SysAgent.Salesman,
            };

            Entity.SalesLog.AddObject(salesLog);
            Entity.SaveChanges();
            baseSysAgent = Request.ConvertRequestToModel <SysAgent>(baseSysAgent, SysAgent);
            //处理推广代理佣金
            if (baseSysAgent.DaiLiGetType == 1)
            {
                baseSysAgent.DaiLiGet = baseSysAgent.DaiLiGet / 100;
            }
            //权限
            string Str = string.Empty;

            if (PId != null)
            {
                foreach (var p in PId)
                {
                    if (p != string.Empty)
                    {
                        Str += "," + p;
                    }
                }
                Str += ",";
            }

            string           AgentIds  = baseSysAgent.Id.ToString();//用户下方批量更新下级代理
            IList <SysAgent> AgentList = null;

            //取得之前的权限
            string powerChar = Entity.SysAdmin.FirstOrDefault(s => s.Id == baseSysAgent.AdminId).PowerID;

            //取得之前的权限跟修改后的权限不同的权限
            string[] strSpile   = Str.Split(',');
            string[] powerSpile = powerChar.Split(',');
            strSpile   = strSpile.Where(s => !string.IsNullOrEmpty(s)).ToArray();
            powerSpile = powerSpile.Where(x => !string.IsNullOrEmpty(x)).ToArray();
            //只有减少权限的时候才执行
            if (strSpile.Length < powerSpile.Length)
            {
                string retChar = "";

                for (int i = 0; i < powerSpile.Length; i++)
                {
                    if (!string.IsNullOrWhiteSpace(powerSpile[i]))
                    {
                        if (!strSpile.Contains(powerSpile[i]))
                        {
                            retChar += powerSpile[i] + ",";
                        }
                    }
                }
                //取得代理商所有的下级
                AgentList = SysAgent.GetSupAgent(Entity, true);
                foreach (var agentItem in AgentList)
                {
                    IList <SysAdmin> SysAdminList = Entity.SysAdmin.Where(x => x.AgentId == agentItem.Id).ToList();
                    string[]         retSplit     = retChar.Split(',');
                    foreach (var modelAdmin in SysAdminList)
                    {
                        foreach (var item in retSplit)
                        {
                            string formatChar = string.Format(",{0},", item);
                            if (modelAdmin.PowerID.Contains(formatChar))
                            {
                                modelAdmin.PowerID = modelAdmin.PowerID.Replace(formatChar, ",");
                            }
                        }
                        if (!string.IsNullOrWhiteSpace(modelAdmin.PowerID) && !modelAdmin.PowerID.StartsWith(","))
                        {
                            modelAdmin.PowerID = "," + modelAdmin.PowerID;
                        }
                        string SQL = "Update SysAdmin set PowerID = '" + modelAdmin.PowerID + "' where Id=" + modelAdmin.Id;
                        Entity.ExecuteStoreCommand(SQL);
                    }
                }
            }

            SysAdmin SysAdmin = Entity.SysAdmin.FirstOrDefault(n => n.Id == baseSysAgent.AdminId);

            if (SysAdmin != null)
            {
                SysAdmin.PowerID = Str;
                if (!PassWord.IsNullOrEmpty())
                {
                    SysAdmin.PassWord = PassWord.GetAdminMD5();
                }
                SysAdmin.State = SysAgent.State;
            }
            this.ProcessAttach(SysAgent, salesLog, Contract, IDCard_Front, IDCard_Reverse, IDCard_Hand, Certificate, DelIds);
            Entity.SaveChanges();
            //如果是修改的话这个应该不会执行
            OpenOrBindUser(SysAgent.Id, Str);
            if (IsLock)
            {
                //锁定其下级所有代理 2016-07-05 Lin
                this.LockAllAgent(baseSysAgent);
            }
            Entity.SaveChanges();


            if (!AnsyCash0.IsNullOrEmpty() || !AnsyCash1.IsNullOrEmpty() || !AnsyNext0.IsNullOrEmpty() || !AnsyNext1.IsNullOrEmpty())
            {
                if (AgentList == null)
                {
                    //取得代理商所有的下级
                    AgentList = SysAgent.GetSupAgent(Entity, true);
                }
                ;
                foreach (var p in AgentList)
                {
                    AgentIds = AgentIds + "," + p.Id;
                }
            }
            if (AnsyCash0 == 1)//同步到用户
            {
                string SQL = "Update Users Set ECash0=" + baseSysAgent.ECash0 + ",Cash0=" + baseSysAgent.Cash0 + " where Agent in(" + AgentIds + ")";
                Entity.ExecuteStoreCommand(SQL);
            }
            if (AnsyCash1 == 1)//同步到用户
            {
                string SQL = "Update Users Set ECash1=" + baseSysAgent.ECash1 + ",Cash1=" + baseSysAgent.Cash1 + " where Agent in(" + AgentIds + ")";
                Entity.ExecuteStoreCommand(SQL);
            }
            if (AnsyNext0 == 1)//同步到代理
            {
                string SQL = "Update SysAgent Set ECash0=" + baseSysAgent.ECash0 + ",Cash0=" + baseSysAgent.Cash0 + ",Cash0Times=" + baseSysAgent.Cash0Times + " where Id in(" + AgentIds + ")";
                Entity.ExecuteStoreCommand(SQL);
            }
            if (AnsyNext0 == 1)//同步到代理
            {
                string SQL = "Update SysAgent Set ECash1=" + baseSysAgent.ECash1 + ",Cash1=" + baseSysAgent.Cash1 + ",Cash1Times=" + baseSysAgent.Cash1Times + " where Id in(" + AgentIds + ")";
                Entity.ExecuteStoreCommand(SQL);
            }

            ViewBag.Msg     = "操作成功!";
            ViewBag.IsColse = true;
            return(View("Succeed"));
        }
        public ActionResult Index(Users Users, EFPagingInfo<Users> p, bool? IsShowSupAgent, int IsFirst = 0)
        {
            #region 条件
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }

            if (Users.CardStae.IsNullOrEmpty())
            {
                Users.CardStae = 2;
            }
            if (!Users.UserName.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.UserName == Users.UserName); }
            if (!Users.TrueName.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.TrueName.Contains(Users.TrueName) || f.NeekName.Contains(Users.TrueName)); }
            if (!Users.Mobile.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.Mobile == Users.Mobile); }
            if (!Users.State.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.State == (Users.State == 99 ? 0 : Users.State)); }
            if (!Users.CardNum.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.CardNum == Users.CardNum); }
            if (!Users.Agent.IsNullOrEmpty())
            {
                //是否要显示下级
                if ((bool)IsShowSupAgent)
                {
                    SysAgent LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == Users.Agent).FirstOrNew();
                    IList<SysAgent> SysAgentList = LowerLevelAgent.GetSupAgent(Entity, true);
                    IList<int> UID = SysAgentList.Select(o => o.Id).ToList();
                    p.SqlWhere.Add(f => UID.Contains(f.Agent));
                }
                else
                {
                    p.SqlWhere.Add(f => f.Agent == Users.Agent);
                }
            }
            if (!Users.CardId.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.CardId == Users.CardId); }
            if (!Users.MyPId.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.MyPId == Users.MyPId && f.ShareType == 1); }
            if (!Users.RegAddress.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.RegAddress.Contains(Users.RegAddress)); }
            if (!Users.CardStae.IsNullOrEmpty())
            {
                int CardStae = Users.CardStae;
                if (CardStae == 99)
                {
                    CardStae = 0;
                }
                if (CardStae != 88)
                {
                    p.SqlWhere.Add(f => f.CardStae == CardStae);
                }
            }
            if (!Users.HasT0.IsNullOrEmpty())
            {
                int HasT0 = Users.HasT0;
                if (HasT0 == 2)
                {
                    HasT0 = 0;
                }
                p.SqlWhere.Add(f => f.HasT0 == HasT0);
            }
            #endregion
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems<Users> UsersList = null;
            if (IsFirst == 0)
            {

                UsersList = new PageOfItems<Users>(new List<Users>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                UsersList = Entity.Selects<Users>(p);
            }
            ViewBag.UsersList = UsersList;
            ViewBag.Users = Users;
            ViewBag.SysAgentList = Entity.SysAgent.Where(n => n.State==1).ToList();
            //显示上级名字
            var ulids = UsersList.Select(o => o.Id).Distinct().ToArray();
            ViewBag.PName = Entity.Users.Select(o => new { o.Id, o.TrueName }).ToDictionary(o => o.Id, o => o.TrueName);
            ViewBag.IsShowSupAgent = IsShowSupAgent;//是否显示下级
            ViewBag.Edit = this.checkPower("Edit");
            ViewBag.DeductMoney = this.checkPower("DeductMoney");
            ViewBag.MyUsers = this.checkPower("MyUsers");
            ViewBag.Save = this.checkPower("Save");
            ViewBag.ClearPId = this.checkPower("ClearPId");
            ViewBag.StopPay = this.checkPower("StopPay");
            ViewBag.StopPaySave = this.checkPower("StopPaySave");
            ViewBag.UnFrozenList = this.checkPower("UnFrozenList");
            ViewBag.UnFrozenAudit = this.checkPower("UnFrozenAudit");
            ViewBag.Clear = this.checkPower("Clear");
            ViewBag.ClearRZ = this.checkPower("ClearRZ");
            ViewBag.UserTrail = this.checkPower("UserTrail", "Index");
            ViewBag.UserMaillist = this.checkPower("UserMaillist", "Index");
            ViewBag.UserIdCard = this.checkPower("UserIdCard", "Index");
            ViewBag.UserIdLog = this.checkPower("UserIdCard", "Log");
            ViewBag.UserLog = this.checkPower("UserLog", "Index");
            ViewBag.ChangeT0BlackList = this.checkPower("Users", "ChangeT0BlackList");
            ViewBag.ExcelInport = this.checkPower("ExcelInport");
            ViewBag.Download = this.checkPower("Download");
            return View();
        }
Ejemplo n.º 11
0
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[Users]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            Users Users = new Users();

            Users = JsonToObject.ConvertJsonToModel(Users, json);

            //获取用户信息
            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == Users.Token);

            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            //判断是否为代理商
            SysAgent         SysAgent     = Entity.SysAgent.FirstOrDefault(o => o.LinkMobile == baseUsers.UserName && o.State == 1);
            IList <SysAgent> SysAgentList = null;
            IList <Users>    UsersList    = null;
            SysSet           baseSysSet   = Entity.SysSet.FirstOrDefault();

            //1用户2代理商
            if (SysAgent != null)
            {
                baseUsers.UserType = 2;
            }
            else
            {
                baseUsers.UserType = 1;
            }
            //if (baseUsers.UserType == 1)
            //{
            UsersList           = baseUsers.GetSupUsers(Entity, baseSysSet.GlobaPromoteMaxLevel);
            UsersList           = UsersList.Where(o => o.Id != baseUsers.Id).ToList();
            baseUsers.UserTotal = UsersList.Count();
            // }
            if (baseUsers.UserType == 2)
            {
                SysAgentList = SysAgent.GetSupAgent(Entity);
                IList <int> agents = SysAgentList.Where(o => o.Id != SysAgent.Id).Select(o => o.Id).ToList();
                // UsersList = Entity.Users.Where(o => agents.Contains(o.Agent) && o.Id != baseUsers.Id).ToList();
                //baseUsers.UserTotal = UsersList.Count();
                //SysAgentList = SysAgentList.Where(o => o.Id != SysAgent.Id).ToList();
                baseUsers.AgentTotal = agents.Count();
            }
            baseUsers.Cols = "Id,UserName,UserType,UserTotal,AgentTotal";
            DataObj.Data   = baseUsers.OutJson();
            DataObj.Code   = "0000";
            DataObj.OutString();
        }
 /// <summary>
 /// 条件
 /// </summary>
 private EFPagingInfo <OrderCash> Condition(OrderCash OrderCash, EFPagingInfo <OrderCash> p, bool?IsShowSupAgent)
 {
     p.SqlWhere.Add(f => f.OrderState == 2);
     p.SqlWhere.Add(f => f.PayState == 1 || f.PayState == 2);
     //if (OrderCash.AddTime.IsNullOrEmpty())
     //{
     //    OrderCash.AddTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
     //}
     //if (OrderCash.FTime.IsNullOrEmpty())
     //{
     //    //OrderCash.FTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
     //    OrderCash.FTime = DateTime.Now;
     //}
     //if (!OrderCash.UId.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.UId == OrderCash.UId); }
     if (!OrderCash.Owner.IsNullOrEmpty())
     {
         IList <Users> UList = Entity.Users.Where(n => n.TrueName == OrderCash.Owner || n.NeekName == OrderCash.Owner || n.UserName == OrderCash.Owner).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 (!OrderCash.Cash.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.Amoney >= OrderCash.Cash);
     }
     if (!OrderCash.ECash.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.Amoney <= OrderCash.ECash);
     }
     if (!OrderCash.OId.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.OId == OrderCash.OId);
     }
     if (!OrderCash.Agent.IsNullOrEmpty())
     {
         //是否要显示下级
         if ((bool)IsShowSupAgent)
         {
             SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == OrderCash.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 == OrderCash.Agent);
         }
     }
     if (!OrderCash.FState.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.FState == (OrderCash.FState == 99 ? 0 : OrderCash.FState));
     }
     if (!OrderCash.TrunType.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.TrunType == (OrderCash.TrunType == 99 ? 0 : OrderCash.TrunType));
     }
     if (!OrderCash.AId.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.AId == OrderCash.AId);
     }
     if (!OrderCash.FId.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.FId == OrderCash.FId);
     }
     if (!OrderCash.AgentState.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.AgentState == OrderCash.AgentState);
     }
     if (!OrderCash.AddTime.IsNullOrEmpty() && !OrderCash.FTime.IsNullOrEmpty())
     {
         // DateTime FTime = ((DateTime)OrderCash.FTime).AddDays(1);
         DateTime FTime = OrderCash.FTime.Value;
         p.SqlWhere.Add(f => f.AddTime > OrderCash.AddTime && f.AddTime < FTime);
     }
     return(p);
 }
        public void PayCash(OrderCash OrderCash, EFPagingInfo <OrderCash> p, bool?IsShowSupAgent)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            p.PageSize = 99999999;
            p.SqlWhere.Add(f => f.OrderState == 2);
            p.SqlWhere.Add(f => f.PayState == 1 || f.PayState == 2);

            if (OrderCash.AddTime.IsNullOrEmpty())
            {
                OrderCash.AddTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            }
            if (OrderCash.FTime.IsNullOrEmpty())
            {
                OrderCash.FTime = DateTime.Now;
            }
            if (!OrderCash.Owner.IsNullOrEmpty())
            {
                IList <Users> UList = Entity.Users.Where(n => n.TrueName.Contains(OrderCash.Owner) || n.NeekName.Contains(OrderCash.Owner) || n.UserName == OrderCash.Owner).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 (!OrderCash.Cash.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Amoney >= OrderCash.Cash);
            }
            if (!OrderCash.ECash.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Amoney <= OrderCash.ECash);
            }
            if (!OrderCash.OId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.OId == OrderCash.OId);
            }
            if (!OrderCash.Agent.IsNullOrEmpty())
            {
                //是否要显示下级
                if ((bool)IsShowSupAgent)
                {
                    SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == OrderCash.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 == OrderCash.Agent);
                }
            }
            if (!OrderCash.FState.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.FState == (OrderCash.FState == 99 ? 0 : OrderCash.FState));
            }
            if (!OrderCash.TrunType.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TrunType == (OrderCash.TrunType == 99 ? 0 : OrderCash.TrunType));
            }
            if (!OrderCash.AId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AId == OrderCash.AId);
            }
            if (!OrderCash.FId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.FId == OrderCash.FId);
            }
            if (!OrderCash.AgentState.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AgentState == OrderCash.AgentState);
            }
            if (!OrderCash.AddTime.IsNullOrEmpty() && !OrderCash.FTime.IsNullOrEmpty())
            {
                // DateTime FTime = ((DateTime)OrderCash.FTime).AddDays(1);
                DateTime FTime = OrderCash.FTime.Value;
                p.SqlWhere.Add(f => f.AddTime > OrderCash.AddTime && f.AddTime < FTime);
            }
            p.OrderByList.Add("Id", "ASC");
            IPageOfItems <OrderCash> OrderCashList = Entity.Selects <OrderCash>(p);

            TaskCash TaskCash = new TaskCash();

            TaskCash.State   = 0;
            TaskCash.AddTime = DateTime.Now;
            TaskCash.Total   = OrderCashList.Count();
            TaskCash.Success = 0;
            TaskCash.Fail    = 0;
            Entity.TaskCash.AddObject(TaskCash);
            Entity.SaveChanges();
            int suc  = 0;
            int fa   = 0;
            int same = 0;

            foreach (var O in OrderCashList)
            {
                if (O.PayState == 1 && O.OrderState == 2)
                {
                    TaskCashInfo TaskCashInfo = Entity.TaskCashInfo.FirstOrDefault(n => n.OId == O.OId);
                    if (TaskCashInfo == null)
                    {
                        TaskCashInfo         = new TaskCashInfo();
                        TaskCashInfo.OId     = O.OId;
                        TaskCashInfo.TId     = TaskCash.Id;
                        TaskCashInfo.State   = 0;
                        TaskCashInfo.OState  = 0;
                        TaskCashInfo.NState  = 0;
                        TaskCashInfo.AddTime = DateTime.Now;
                        Entity.TaskCashInfo.AddObject(TaskCashInfo);
                        suc++;
                    }
                    else
                    {
                        same++;
                    }
                }
                else
                {
                    fa++;
                }
            }
            TaskCash.Total = suc;
            Entity.SaveChanges();
            System.Web.HttpContext.Current.Response.AddHeader("content-type", "application/json");
            Response.Write("{\"id\":" + TaskCash.Id + ",\"same\":" + same + ",\"success\":" + suc + ",\"fail\":" + fa + "}");
        }
        public ActionResult Index(BaoUsers BaoUsers, EFPagingInfo <BaoUsersVM> p, string UserName, int?AgentID, bool?HasMoney, int IsFirst = 0, bool IsShowSupAgent = false)
        {
            int id     = 0;
            var iquery = Entity.BaoUsers.Join(this.Entity.Users, b => b.UId, u => u.Id, (b, u) => new BaoUsersVM()
            {
                Users = u, BaoUsers = b
            });

            if (!UserName.IsNullOrEmpty())
            {
                iquery = iquery.Where(o => o.Users.UserName == UserName);
            }
            if (!BaoUsers.PayPwd.IsNullOrEmpty())
            {
                id = this.Entity.Users.FirstOrNew(o => o.CardId == BaoUsers.PayPwd).Id;
                if (id != 0)
                {
                    iquery = iquery.Where(o => o.BaoUsers.UId == id);
                }
            }
            if (HasMoney.HasValue)
            {
                if (HasMoney.Value)
                {
                    iquery = iquery.Where(o => o.BaoUsers.AllMoney > 0);
                }
                else
                {
                    iquery = iquery.Where(o => o.BaoUsers.AllMoney == 0);
                }
            }

            if (AgentID.HasValue)
            {
                //是否要显示下级
                if ((bool)IsShowSupAgent)
                {
                    SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == AgentID.Value).FirstOrNew();
                    IList <SysAgent> SysAgentList    = LowerLevelAgent.GetSupAgent(Entity, true);
                    IList <int>      UID             = SysAgentList.Select(o => o.Id).ToList();
                    iquery = iquery.Where(f => UID.Contains(f.Users.Agent));
                }
                else
                {
                    iquery = iquery.Where(f => f.Users.Agent == AgentID.Value);
                }
            }
            PageOfItems <BaoUsersVM> BaoUsersList = null;
            decimal sumAllMoney = 0m;
            decimal sumInMoney  = 0m;

            if (IsFirst == 0)
            {
                BaoUsersList = new PageOfItems <BaoUsersVM>(new List <BaoUsersVM>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                var count = iquery.Count();
                sumAllMoney = iquery.Sum(o => (decimal?)o.BaoUsers.AllMoney) ?? 0;
                sumInMoney  = iquery.Sum(o => (decimal?)o.BaoUsers.InMoney) ?? 0;
                List <BaoUsersVM> a = iquery.OrderByDescending(o => o.BaoUsers.AllMoney).Skip(p.PageIndex < 1 ? 0 : ((p.PageIndex - 1) * p.PageSize)).Take(p.PageSize).ToList();
                BaoUsersList = new PageOfItems <BaoUsersVM>(a, p.PageIndex, p.PageSize, count, p.OrderByList);
            }

            ViewBag.BaoUsersList = BaoUsersList;
            ViewBag.BaoUsers     = BaoUsers;

            ViewBag.SysAgentList   = Entity.SysAgent.Where(n => n.Tier == 1).ToList();
            ViewBag.IsShowSupAgent = IsShowSupAgent;//是否显示下级
            ViewBag.AgentID        = AgentID;
            ViewBag.UserName       = UserName;

            ViewBag.sumAllMoney  = sumAllMoney;
            ViewBag.sumInMoney   = sumInMoney;
            ViewBag.HasMoney     = HasMoney;
            ViewBag.Log          = this.checkPower("Log");
            ViewBag.TransferUser = this.checkPower("TransferUser");
            return(View());
        }
        public void Save(SysAgent SysAgent, List <string> PId, List <Attach> Contract, Attach IDCard_Front, Attach IDCard_Reverse, Attach IDCard_Hand, List <Attach> Certificate, List <int> DelIds, string PassWord, int?AnsyCash0, int?AnsyNext0, int?AnsyCash1, int?AnsyNext1, int sameid)
        {
            SysAgent.PayGet  = SysAgent.PayGet.IsNullOrEmpty() ? 0 : SysAgent.PayGet / 100;
            SysAgent.CashGet = 0;//SysAgent.CashGet.IsNullOrEmpty() ? 0 : SysAgent.CashGet / 100;
            SysAgent.LoanGet = SysAgent.LoanGet.IsNullOrEmpty() ? 0 : SysAgent.LoanGet / 100;
            SysAgent.Credit  = SysAgent.Credit.IsNullOrEmpty() ? 0 : SysAgent.Credit / 100;
            //已绑定,手机不能改
            SysAgent baseSysAgent = Entity.SysAgent.FirstOrDefault(n => n.Id == SysAgent.Id);

            if (!baseSysAgent.MyUId.IsNullOrEmpty())
            {
                SysAgent.LinkMobile = baseSysAgent.LinkMobile;
            }
            bool IsLock = false;

            if (baseSysAgent.State == 1 && SysAgent.State == 0)
            {
                IsLock = true;
            }
            //保存销售记录为了取得id
            var salesLog = new SalesLog()
            {
                AddTime    = DateTime.Now,
                AgentFee   = SysAgent.AgentFee,
                ExpireTime = SysAgent.ExpireTime,
                State      = 1,
                AgentId    = SysAgent.Id,
                Salesman   = SysAgent.Salesman,
            };

            Entity.SalesLog.AddObject(salesLog);
            Entity.SaveChanges();

            SysAgent.Cash0 = SysAgent.Cash0 / 1000;
            SysAgent.Cash1 = SysAgent.Cash1 / 1000;

            //判断是否更新级数
            bool IsUpMaxTier = false;

            if (SysAgent.AgentLevelMax > baseSysAgent.AgentLevelMax)
            {
                IsUpMaxTier = true;
            }
            else
            {
                SysAgent.AgentLevelMax = baseSysAgent.AgentLevelMax;//不大于的情况下不能修改
            }
            baseSysAgent = Request.ConvertRequestToModel <SysAgent>(baseSysAgent, SysAgent);
            //处理推广代理佣金
            if (baseSysAgent.DaiLiGetType == 1)
            {
                baseSysAgent.DaiLiGet = baseSysAgent.DaiLiGet / 100;
            }

            //默认代理不能被关闭
            if (baseSysAgent.State == 0 && baseSysAgent.Id == 1)
            {
                baseSysAgent.State = 1;
            }

            //处理设置
            if (SysAgent.IsTeiPai != 1)
            {
                SysAgent.Set3 = 0;
                SysAgent.Set4 = 0;
            }

            //权限
            string Str = string.Empty;

            if (PId != null)
            {
                foreach (var p in PId)
                {
                    if (p != string.Empty)
                    {
                        Str += "," + p;
                    }
                }
                Str += ",";
            }
            string           AgentIds  = baseSysAgent.Id.ToString();//用户下方批量更新下级代理
            IList <SysAgent> AgentList = null;
            //取得之前的权限
            string powerChar = Entity.SysAdmin.FirstOrDefault(s => s.Id == baseSysAgent.AdminId).PowerID;

            //取得之前的权限跟修改后的权限不同的权限
            string[] strSpile   = Str.Split(',');
            string[] powerSpile = powerChar.Split(',');
            strSpile   = strSpile.Where(s => !string.IsNullOrEmpty(s)).ToArray();
            powerSpile = powerSpile.Where(x => !string.IsNullOrEmpty(x)).ToArray();
            //只有减少权限的时候才执行
            if (strSpile.Length < powerSpile.Length)
            {
                string retChar = "";

                for (int i = 0; i < powerSpile.Length; i++)
                {
                    if (!string.IsNullOrWhiteSpace(powerSpile[i]))
                    {
                        if (!strSpile.Contains(powerSpile[i]))
                        {
                            retChar += powerSpile[i] + ",";
                        }
                    }
                }

                //取得代理商所有的下级
                AgentList = SysAgent.GetSupAgent(Entity);

                foreach (var agentItem in AgentList)
                {
                    //根据商户Id获取管理员信息
                    IList <SysAdmin> SysAdminList = Entity.SysAdmin.Where(x => x.AgentId == agentItem.Id).ToList();
                    string[]         retSplit     = retChar.Split(',');
                    foreach (var modelAdmin in SysAdminList)
                    {
                        foreach (var item in retSplit)
                        {
                            string formatChar = string.Format(",{0},", item);
                            if (modelAdmin.PowerID.Contains(formatChar))
                            {
                                modelAdmin.PowerID = modelAdmin.PowerID.Replace(formatChar, ",");
                            }
                        }
                        if (!string.IsNullOrWhiteSpace(modelAdmin.PowerID) && !modelAdmin.PowerID.StartsWith(","))
                        {
                            modelAdmin.PowerID = "," + modelAdmin.PowerID;
                        }
                        string SQL = "Update SysAdmin set PowerID = '" + modelAdmin.PowerID + "' where Id=" + modelAdmin.Id;
                        Entity.ExecuteStoreCommand(SQL);
                    }
                }
            }

            SysAdmin SysAdmin = Entity.SysAdmin.FirstOrDefault(n => n.Id == baseSysAgent.AdminId);

            if (SysAdmin != null)
            {
                SysAdmin.PowerID = Str;
                if (!PassWord.IsNullOrEmpty())
                {
                    SysAdmin.PassWord = PassWord.GetAdminMD5();
                }
                SysAdmin.State = SysAgent.State;
            }
            this.ProcessAttach(SysAgent, salesLog, Contract, IDCard_Front, IDCard_Reverse, IDCard_Hand, Certificate, DelIds);
            Entity.SaveChanges();
            //如果是修改的话这个应该不会执行
            OpenOrBindUser(SysAgent.Id, Str);
            if (IsLock)
            {
                //锁定其下级所有代理 2016-07-05 Lin
                this.LockAllAgent(baseSysAgent);
            }
            Entity.SaveChanges();

            //if (SysAgent)

            if (!AnsyCash0.IsNullOrEmpty() || !AnsyCash1.IsNullOrEmpty() || !AnsyNext0.IsNullOrEmpty() || !AnsyNext1.IsNullOrEmpty() || IsUpMaxTier)
            {
                if (AgentList == null)
                {
                    //取得代理商所有的下级
                    AgentList = SysAgent.GetSupAgent(Entity, true);
                }
                foreach (var p in AgentList)
                {
                    AgentIds = AgentIds + "," + p.Id;
                }
            }
            if (IsUpMaxTier)
            {
                string SQL = "Update SysAgent Set AgentLevelMax=" + baseSysAgent.AgentLevelMax + " where Id in(" + AgentIds + ")";
                Entity.ExecuteStoreCommand(SQL);
            }
            if (AnsyCash0 == 1)//同步到用户
            {
                string SQL = "Update Users Set ECash0=" + baseSysAgent.ECash0 + ",Cash0=" + baseSysAgent.Cash0 + " where Agent in(" + AgentIds + ")";
                Entity.ExecuteStoreCommand(SQL);
            }
            if (AnsyCash1 == 1)//同步到用户
            {
                string SQL = "Update Users Set ECash1=" + baseSysAgent.ECash1 + ",Cash1=" + baseSysAgent.Cash1 + " where Agent in(" + AgentIds + ")";
                Entity.ExecuteStoreCommand(SQL);
            }
            if (AnsyNext0 == 1)//同步到代理
            {
                string SQL = "Update SysAgent Set ECash0=" + baseSysAgent.ECash0 + ",Cash0=" + baseSysAgent.Cash0 + ",Cash0Times=" + baseSysAgent.Cash0Times + " where Id in(" + AgentIds + ")";
                Entity.ExecuteStoreCommand(SQL);
            }
            if (AnsyNext0 == 1)//同步到代理
            {
                string SQL = "Update SysAgent Set ECash1=" + baseSysAgent.ECash1 + ",Cash1=" + baseSysAgent.Cash1 + ",Cash1Times=" + baseSysAgent.Cash1Times + " where Id in(" + AgentIds + ")";
                Entity.ExecuteStoreCommand(SQL);
            }
            if (sameid != SysAgent.SameAgent)
            {
                SysAgent     tempAgent    = Entity.SysAgent.FirstOrNew(o => o.Id == SysAgent.SameAgent); //调入商户
                SysAgent     Agengt       = Entity.SysAgent.FirstOrNew(o => o.Id == sameid);             //调出商户
                UsersMoveLog UsersMoveLog = new UsersMoveLog()
                {
                    AddTime   = DateTime.Now,
                    ToSAId    = tempAgent.Id,
                    ToName    = tempAgent.Name.IsNullOrEmpty()?"":tempAgent.Name,
                    FromName  = Agengt.Name.IsNullOrEmpty()?"":Agengt.Name,
                    FromSAId  = Agengt.Id,
                    UId       = baseSysAgent.Id,
                    UTrueName = baseSysAgent.Name.IsNullOrEmpty() ? "" : baseSysAgent.Name,
                    OpName    = AdminUser.TrueName,
                    Type      = 3,
                    Tel       = baseSysAgent.LinkMobile,
                };
                this.Entity.UsersMoveLog.AddObject(UsersMoveLog);
                Entity.SaveChanges();
            }

            BaseRedirect();
        }
        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());
        }
        public void PaySave(SysAgent SysAgent, int[] PId, double[] Cost, int[] PState, int?AnsyCash, int?AnsyNext)
        {
            if (SysAgent.Id != 0)
            {
                SysAgent = Entity.SysAgent.FirstOrDefault(n => n.Id == SysAgent.Id);
            }
            if (SysAgent == null)
            {
                return;
            }
            for (int i = 0; i < PId.Length; i++)
            {
                int          Pid = PId[i];
                UserPayAgent PCT = Entity.UserPayAgent.FirstOrNew(n => n.AId == SysAgent.Id && n.PId == Pid);
                PCT.Cost = Cost[i] / 1000;
                if (PCT.Id.IsNullOrEmpty())
                {
                    PCT.PId = PId[i];
                    PCT.AId = SysAgent.Id;
                    Entity.UserPayAgent.AddObject(PCT);
                }
            }
            Entity.SaveChanges();

            IList <PayConfig>    PayConfigList    = new List <PayConfig>();
            IList <UserPayAgent> UserPayAgentList = new List <UserPayAgent>();
            IList <SysAgent>     AgentList        = new List <SysAgent>();
            string AgentIds = "0";

            if (AnsyCash == 1 || AnsyNext == 1)
            {
                PayConfigList    = Entity.PayConfig.Where(n => n.State == 1).ToList();
                UserPayAgentList = Entity.UserPayAgent.Where(n => n.AId == SysAgent.Id).ToList();
                //取得代理商所有的下级
                AgentList = SysAgent.GetSupAgent(Entity);
                foreach (var p in AgentList)
                {
                    AgentIds = AgentIds + "," + p.Id;
                }
            }
            if (AnsyCash == 1)
            {
                //使用删除全部后根据用户表生成,有效解决了因接口关闭或新增加接口,老用户没有配置问题
                string SQL = "Delete UserPay Where UId in(Select Id From Users Where Agent in(" + AgentIds + "))";
                Entity.ExecuteStoreCommand(SQL);
                foreach (var p in PayConfigList)
                {
                    double?      cost = p.CostUser;
                    UserPayAgent PCT  = UserPayAgentList.FirstOrNew(n => n.AId == SysAgent.Id && n.PId == p.Id);
                    if (!PCT.Id.IsNullOrEmpty())
                    {
                        cost = PCT.Cost;
                    }
                    SQL = "INSERT INTO UserPay(UId,PId,Cost,IsDel) Select ID," + p.Id + " As PId," + cost + " As Cost, 0 As IsDel From Users where Id in(Select Id From Users Where Agent in(" + AgentIds + "))";
                    Entity.ExecuteStoreCommand(SQL);
                }
            }
            if (AnsyNext == 1)
            {
                //使用删除全部后根据用户表生成,有效解决了因接口关闭或新增加接口,老用户没有配置问题
                string SQL = "Delete UserPayAgent Where AId in (" + AgentIds + ")";
                Entity.ExecuteStoreCommand(SQL);
                foreach (var p in PayConfigList)
                {
                    double?      cost = p.CostUser;
                    UserPayAgent PCT  = UserPayAgentList.FirstOrNew(n => n.AId == SysAgent.Id && n.PId == p.Id);
                    if (!PCT.Id.IsNullOrEmpty())
                    {
                        cost = PCT.Cost;
                    }
                    SQL = "INSERT INTO UserPayAgent(AId,PId,Cost,IsDel) Select ID," + p.Id + " As PId," + cost + " As Cost, 0 As IsDel From SysAgent where Id in(" + AgentIds + ")";
                    Entity.ExecuteStoreCommand(SQL);
                }
            }

            BaseRedirect();
        }
        public ActionResult Index(Users Users, EFPagingInfo <Users> p, bool?IsShowSupAgent, int?LowerLevel, int IsFirst = 0)
        {
            #region 条件
            if (checkPower("ALL"))
            {
                IsAll = true;
            }
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            LowerLevel    = LowerLevel == null ? 0 : LowerLevel;
            ViewBag.IsAll = IsAll;

            /*有没有指定交易所属代理
             * 有:校验是否从属关系
             * 无:指定当前代理
             */
            if (!Users.Agent.IsNullOrEmpty())
            {
                if (!IsBelongToAgent(Users.Agent))
                {
                    ViewBag.ErrorMsg = "只能查询当前用户下属代理的交易";
                    return(View("Error"));
                }
            }
            else
            {
                Users.Agent = this.BasicAgent.Id;
            }
            IList <SysAgent> SysAgentList = null;
            //没有"管理所有"权限的只能看到操作员自己的数据
            if (!IsAll)
            {
                p.SqlWhere.Add(f => f.AId == AdminUser.Id);//指定的操作员
            }
            else
            {
                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);//获取所有下级代理商信息
                    }
                    foreach (var s in SysAgentList)
                    {
                        UID.Add(s.Id);
                    }
                    p.SqlWhere.Add(f => UID.Contains(f.Agent));
                }
                else
                {
                    p.SqlWhere.Add(f => f.Agent == Users.Agent);//指定的代理
                }
            }
            if (Users.CardStae.IsNullOrEmpty())
            {
                Users.CardStae = 2;
            }
            if (!Users.RegAddress.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.RegAddress.Contains(Users.RegAddress));
            }
            if (!Users.UserName.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.UserName == Users.UserName);
            }
            if (!Users.TrueName.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TrueName == Users.TrueName || f.NeekName == Users.TrueName);
            }
            if (!Users.Mobile.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Mobile == Users.Mobile);
            }
            if (!Users.State.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.State == (Users.State == 99 ? 0 : Users.State));
            }
            if (!Users.CardNum.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.CardNum == Users.CardNum);
            }
            if (!Users.CardStae.IsNullOrEmpty())
            {
                int CardStae = Users.CardStae;
                if (CardStae == 99)
                {
                    CardStae = 0;
                }
                if (CardStae != 88)
                {
                    p.SqlWhere.Add(f => f.CardStae == CardStae);
                }
            }
            #endregion
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <Users> UsersList = null;
            if (IsFirst == 0)
            {
                UsersList = new PageOfItems <Users>(new List <Users>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                UsersList = Entity.Selects <Users>(p);
            }

            foreach (var item in UsersList)
            {
                item.Address = item.QRCode();
            }
            ViewBag.UsersList = UsersList;
            ViewBag.Users     = Users;
            SysSet SysSet = Entity.SysSet.FirstOrNew();
            ViewBag.SysSet         = SysSet;
            ViewBag.IsShowSupAgent = IsShowSupAgent;
            ViewBag.SysAgentList   = SysAgentList;
            ViewBag.LowerLevel     = LowerLevel;
            ViewBag.Entity         = Entity;
            ViewBag.IsAssureImg    = checkPower("SaveAssureImg");
            ViewBag.IsFrozen       = this.checkPower("Frozen");
            ViewBag.IsUnFrozen     = this.checkPower("UnFrozen");
            ViewBag.MyUsers        = this.checkPower("MyUsers");

            return(View());
        }
 private EFPagingInfo <OrderCash> Condition(OrderCash OrderCash, EFPagingInfo <OrderCash> p, bool?IsShowSupAgent, int IsFirst = 0, int TimeType = 1)
 {
     if (IsShowSupAgent == null)
     {
         IsShowSupAgent = false;
     }
     p.SqlWhere.Add(f => f.OrderState == 2);
     p.SqlWhere.Add(f => f.PayState == 3 || f.PayState == 4);
     //if (!OrderCash.UId.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.UId == OrderCash.UId); }
     if (!OrderCash.Owner.IsNullOrEmpty())
     {
         IList <Users> UList = Entity.Users.Where(n => n.TrueName.Contains(OrderCash.Owner) || n.NeekName.Contains(OrderCash.Owner) || n.UserName == OrderCash.Owner).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 (!OrderCash.OId.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.OId == OrderCash.OId);
     }
     if (!OrderCash.Agent.IsNullOrEmpty())
     {
         //是否要显示下级
         if ((bool)IsShowSupAgent)
         {
             SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == OrderCash.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 == OrderCash.Agent);
         }
     }
     if (!OrderCash.PayState.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.PayState == OrderCash.PayState);
     }
     if (!OrderCash.AId.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.AId == OrderCash.AId);
     }
     if (!OrderCash.FId.IsNullOrEmpty())
     {
         p.SqlWhere.Add(f => f.FId == OrderCash.FId);
     }
     if (TimeType == 1)
     {
         if (!OrderCash.AddTime.IsNullOrEmpty() && !OrderCash.FTime.IsNullOrEmpty())
         {
             // DateTime FTime = ((DateTime)OrderCash.FTime).AddDays(1);
             DateTime FTime = OrderCash.FTime.Value.AddMilliseconds(999);
             p.SqlWhere.Add(f => f.AddTime > OrderCash.AddTime && f.AddTime < FTime);
         }
     }
     else
     {
         if (!OrderCash.AddTime.IsNullOrEmpty() && !OrderCash.FTime.IsNullOrEmpty())
         {
             DateTime FTime = OrderCash.FTime.Value.AddMilliseconds(999);
             p.SqlWhere.Add(f => f.RefundTime > OrderCash.AddTime && f.RefundTime < FTime);
         }
     }
     return(p);
 }
Ejemplo n.º 20
0
        public ActionResult Index(OrderHouse OrderHouse, EFPagingInfo <OrderHouse> p, bool?IsShowSupAgent, int IsFirst = 0)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            if (Request.QueryString["PageSize"].IsNullOrEmpty())
            {
                p.PageSize = 30;
            }
            p.SqlWhere.Add(f => f.OrderState == 2);
            p.SqlWhere.Add(f => f.PayState == 1 || f.PayState == 2);
            //if (OrderHouse.AddTime.IsNullOrEmpty())
            //{
            //    OrderHouse.AddTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            //}
            //if (OrderHouse.FTime.IsNullOrEmpty())
            //{
            //    OrderHouse.FTime = DateTime.Now;
            //}
            if (IsFirst == 0)
            {
                PageOfItems <OrderHouse> OrderHouseList1 = new PageOfItems <OrderHouse>(new List <OrderHouse>(), 0, 10, 0, new Hashtable());
                ViewBag.OrderHouseList = OrderHouseList1;
                ViewBag.OrderHouse     = OrderHouse;
                ViewBag.UsersList      = new List <Users>();
                ViewBag.SysAgentList   = Entity.SysAgent.Where(n => n.State == 1 && n.Tier == 1).ToList();
                ViewBag.IsShowSupAgent = IsShowSupAgent;
                ViewBag.Edit           = this.checkPower("Edit");
                ViewBag.Cancel         = this.checkPower("Cancel");
                ViewBag.Save           = this.checkPower("Save");
                return(View());
            }
            //if (!OrderHouse.UId.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.UId == OrderHouse.UId); }
            if (!OrderHouse.HouseOwner.IsNullOrEmpty())
            {
                IList <Users> UList = Entity.Users.Where(n => n.TrueName.Contains(OrderHouse.HouseOwner) || n.NeekName.Contains(OrderHouse.HouseOwner) || n.UserName == OrderHouse.HouseOwner).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 (!OrderHouse.OId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.OId == OrderHouse.OId);
            }
            if (!OrderHouse.Agent.IsNullOrEmpty())
            {
                //是否要显示下级
                if ((bool)IsShowSupAgent)
                {
                    SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == OrderHouse.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 == OrderHouse.Agent);
                }
            }
            if (!OrderHouse.FState.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.FState == (OrderHouse.FState == 99 ? 0 : OrderHouse.FState));
            }
            if (!OrderHouse.TrunType.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TrunType == (OrderHouse.TrunType == 99 ? 0 : OrderHouse.TrunType));
            }
            if (!OrderHouse.AId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AId == OrderHouse.AId);
            }
            if (!OrderHouse.FId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.FId == OrderHouse.FId);
            }
            if (!OrderHouse.AgentState.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AgentState == OrderHouse.AgentState);
            }
            if (!OrderHouse.AddTime.IsNullOrEmpty() && !OrderHouse.FTime.IsNullOrEmpty())
            {
                // DateTime FTime = ((DateTime)OrderHouse.FTime).AddDays(1);
                DateTime FTime = OrderHouse.FTime.Value;
                p.SqlWhere.Add(f => f.PayTime > OrderHouse.AddTime && f.PayTime < FTime);
            }
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <OrderHouse> OrderHouseList = null;

            if (IsFirst == 0)
            {
                OrderHouseList = new PageOfItems <OrderHouse>(new List <OrderHouse>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                OrderHouseList = Entity.Selects <OrderHouse>(p);
            }
            ViewBag.OrderHouseList = OrderHouseList;
            ViewBag.OrderHouse     = OrderHouse;
            IList <OrderHouse> List = OrderHouseList.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.SysAgentList   = Entity.SysAgent.Where(n => n.Tier == 1).ToList();
            ViewBag.IsShowSupAgent = IsShowSupAgent;
            ViewBag.Edit           = this.checkPower("Edit");
            ViewBag.Cancel         = this.checkPower("Cancel");
            ViewBag.Save           = this.checkPower("Save");
            return(View());
        }
        private EFPagingInfo <FastOrder> Condition(FastOrder FastOrder, EFPagingInfo <FastOrder> p, bool IsShowSupAgent)
        {
            #region 筛选条件
            if (!FastOrder.PayWay.IsNullOrEmpty())
            {
                p.SqlWhere.Add(o => o.PayWay == FastOrder.PayWay);
            }

            if (!FastOrder.TNum.IsNullOrEmpty())
            {
                if (FastOrder.UId == 1)
                {
                    p.SqlWhere.Add(f => f.TNum == FastOrder.TNum);
                }
                else
                {
                    IList <Users> UList = Entity.Users.Where(n => n.TrueName.Contains(FastOrder.TNum) || n.NeekName.Contains(FastOrder.TNum) || n.UserName == FastOrder.TNum).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 (!FastOrder.UserState.IsNullOrEmpty())
            {
                var value = FastOrder.UserState == 99 ? 0 : FastOrder.UserState;
                p.SqlWhere.Add(o => o.UserState == value);
            }
            if (!FastOrder.AgentState.IsNullOrEmpty())
            {
                var value = FastOrder.AgentState == 99 ? 0 : FastOrder.AgentState;
                p.SqlWhere.Add(o => o.AgentState == value);
            }
            //是否选择了分支机构
            if (!FastOrder.Agent.IsNullOrEmpty())
            {
                //是否要显示下级
                if ((bool)IsShowSupAgent)
                {
                    SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == FastOrder.Agent).FirstOrNew();
                    IList <SysAgent> SysAgentList    = LowerLevelAgent.GetSupAgent(Entity, true);
                    IList <int>      UID             = SysAgentList.Select(o => o.Id).ToList();
                    p.SqlWhere.Add(f => UID.Contains(f.Agent));
                }
                else
                {
                    p.SqlWhere.Add(f => f.Agent == FastOrder.Agent);
                }
            }

            if (!FastOrder.STime.IsNullOrEmpty() && !FastOrder.ETime.IsNullOrEmpty())
            {
                DateTime ETime = FastOrder.ETime;
                if (FastOrder.Bin == "1")
                {
                    p.SqlWhere.Add(f => f.AddTime > FastOrder.STime && f.AddTime < ETime);
                }
                else
                {
                    p.SqlWhere.Add(f => f.PayTime > FastOrder.STime && f.PayTime < ETime);
                }
            }

            #region 交易类型条件判断
            if (!FastOrder.OType.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.OType == FastOrder.OType);//读取对应的类型
            }

            if (!FastOrder.State.IsNullOrEmpty())
            {
                switch (FastOrder.State)
                {
                case 1:    //未付
                    p.SqlWhere.Add(f => f.State == 1 && f.PayState == 0);
                    break;

                case 2:    //已付
                    p.SqlWhere.Add(f => f.State == 1 && f.PayState == 1);
                    break;

                case 99:    //交易关闭
                    p.SqlWhere.Add(f => f.State == 0);
                    break;
                }
            }
            #endregion

            #endregion
            p.OrderByList.Add("Id", "DESC");

            return(p);
        }
        public ActionResult Index(Orders Orders, EFPagingInfo <Orders> p, bool?IsShowSupAgent, int?LowerLevel, int IsFirst = 0)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            if (IsFirst == 0)
            {
                if (checkPower("ALL"))
                {
                    IsAll = true;
                }
                ViewBag.IsAll = IsAll;
                PageOfItems <Orders> OrdersList1 = new PageOfItems <Orders>(new List <Orders>(), 0, 10, 0, new Hashtable());
                ViewBag.OrdersList = OrdersList1;
                ViewBag.Orders     = Orders;
                //查询对应的商户
                List <int> UId1 = OrdersList1.Select(o => o.UId).Distinct().ToList();
                ViewBag.UsersList      = Entity.Users.Where(n => n.State == 1 && UId1.Contains(n.Id)).ToList();
                ViewBag.PayConfigList  = Entity.PayConfig.Where(n => n.State == 1).ToList();
                ViewBag.IsShowSupAgent = false;
                ViewBag.BasicAgent     = BasicAgent;
                SysSet SysSet1 = Entity.SysSet.FirstOrNew();
                ViewBag.SysSet     = SysSet1;
                ViewBag.Entity     = Entity;
                ViewBag.LowerLevel = 0;
                ViewBag.Edit       = this.checkPower("Edit");
                return(View());
            }

            if (checkPower("ALL"))
            {
                IsAll = true;
            }
            ViewBag.IsAll = IsAll;

            /*有没有指定交易所属代理
             * 有:校验是否从属关系
             * 无:指定当前代理
             */
            if (!Orders.Agent.IsNullOrEmpty())
            {
                if (!IsBelongToAgent(Orders.Agent))
                {
                    ViewBag.ErrorMsg = "只能查询当前用户下属代理的交易";
                    return(View("Error"));
                }
            }
            else
            {
                Orders.Agent = this.BasicAgent.Id;
            }
            LowerLevel = LowerLevel == null ? 0 : LowerLevel;
            //没有"管理所有"权限的只能看到操作员自己的数据
            if (!IsAll)
            {
                p.SqlWhere.Add(f => f.AId == AdminUser.Id);//交易所属用户
            }
            else
            {
                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);//读取全部分支机构
                }
            }
            #region 筛选条件
            if (!Orders.OrderAddress.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.OrderAddress.Contains(Orders.OrderAddress));
            }
            if (!Orders.TNum.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TNum == Orders.TNum);
            }
            if (!Orders.LagEntryDay.IsNullOrEmpty())
            {
                if (Orders.LagEntryDay == 99)
                {
                    p.SqlWhere.Add(f => f.LagEntryDay == 0);
                }
                else
                {
                    p.SqlWhere.Add(f => f.LagEntryDay > 0);
                }
            }
            if (!Orders.TrunType.IsNullOrEmpty())
            {
                if (Orders.TrunType == 1)
                {
                    p.SqlWhere.Add(f => f.TrunType == 1);
                }
                else
                {
                    p.SqlWhere.Add(f => f.TrunType == 0);
                }
            }

            if (!Orders.TName.IsNullOrEmpty())
            {
                IList <Users> UList = Entity.Users.Where(n => n.TrueName.Contains(Orders.TName) || n.NeekName.Contains(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.PayWay.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.PayWay == Orders.PayWay);
            }
            if (!Orders.STime.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AddTime >= Orders.STime);
            }
            if (!Orders.ETime.IsNullOrEmpty())
            {
                DateTime ETime = Orders.ETime.AddHours(23).AddMinutes(59).AddSeconds(59);
                p.SqlWhere.Add(f => f.AddTime <= ETime);
            }
            #region 交易类型条件判断
            if (!Orders.TType.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TType == Orders.TType);//读取对应的类型
                if (Orders.TType == 1)
                {
                    if (!Orders.TState.IsNullOrEmpty())
                    {
                        switch (Orders.TState)
                        {
                        case 1:    //未付
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 0);
                            break;

                        case 2:    //已付
                            p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 1);
                            break;

                        case 3:    //待传证照
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 1);
                            break;

                        case 4:    //待审核
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 2);
                            break;

                        case 5:    //审核失败
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 4);
                            break;

                        case 6:    //退单
                            p.SqlWhere.Add(f => f.TState == 4);
                            break;

                        case 7:    //待入帐
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.InState == 0);
                            break;
                        }
                    }
                }
                if (Orders.TType == 2)
                {
                    if (!Orders.TState.IsNullOrEmpty())
                    {
                        p.SqlWhere.Add(f => f.TState == Orders.TState);
                    }
                }
                if (Orders.TType == 3)
                {
                    switch (Orders.TState)
                    {
                    case 1:    //未付
                        p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 0);
                        break;

                    case 2:    //已付
                        p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 1);
                        break;

                    case 3:    //待传证照
                        p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 1);
                        break;

                    case 4:    //待审核
                        p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 2);
                        break;

                    case 5:    //审核失败
                        p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 4);
                        break;
                    }
                }
                if (Orders.TType == 5)
                {
                    if (!Orders.TState.IsNullOrEmpty())
                    {
                        switch (Orders.TState)
                        {
                        case 99:    //未付
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 0);
                            break;

                        case 1:    //处理中
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 0);
                            break;

                        case 2:    //已汇出
                            p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 2);
                            break;

                        case 4:    //出款中
                            p.SqlWhere.Add(f => (f.TState == 2 && f.PayState == 2 && f.IdCardState == 0) || (f.TState == 2 && f.PayState == 1 && f.IdCardState == 3));
                            break;

                        case 3:    //审核失败
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 4);
                            break;

                        case 5:    //退款中
                            p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 3);
                            break;

                        case 6:    //已退款
                            p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 4);
                            break;

                        case 7:    //待传身份证
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 1);
                            break;

                        case 8:    //已传身份证
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 2);
                            break;
                        }
                    }
                }
                if (Orders.TType == 6)
                {
                    if (!Orders.TState.IsNullOrEmpty())
                    {
                        p.SqlWhere.Add(f => f.TState == Orders.TState);
                    }
                }
                if (Orders.TType == 7 || Orders.TType == 8 || Orders.TType == 9)
                {
                    if (!Orders.TState.IsNullOrEmpty())
                    {
                        if (Orders.TState == 99)
                        {
                            p.SqlWhere.Add(f => f.TState == 0);
                        }
                        if (Orders.TState == 1)
                        {
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 0);
                        }
                        if (Orders.TState == 2)
                        {
                            p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 1);
                        }
                        if (Orders.TState == 3)//退单
                        {
                            p.SqlWhere.Add(f => f.TState == 4);
                        }
                        if (Orders.TState == 4)//待入帐
                        {
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.InState == 0);
                        }
                        if (Orders.TState == 5)//待审核
                        {
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.InState == 1 && f.IdCardState == 2);
                        }
                        if (Orders.TState == 6)//待传证照
                        {
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.InState == 1 && f.IdCardState == 1);
                        }
                        if (Orders.TState == 7)//审核失败
                        {
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.InState == 1 && f.IdCardState == 4);
                        }
                    }
                }
                if (Orders.TType == 10)
                {
                    if (!Orders.TState.IsNullOrEmpty())
                    {
                        p.SqlWhere.Add(f => f.TState == Orders.TState);
                    }
                }
            }
            #endregion
            #endregion
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <Orders> OrdersList = Entity.Selects <Orders>(p);
            ViewBag.OrdersList = OrdersList;
            ViewBag.Orders     = Orders;
            //查询对应的商户
            List <int> UId = OrdersList.Select(o => o.UId).Distinct().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.IsShowSupAgent = IsShowSupAgent;
            ViewBag.BasicAgent     = BasicAgent;
            SysSet SysSet = Entity.SysSet.FirstOrNew();
            ViewBag.SysSet     = SysSet;
            ViewBag.Entity     = Entity;
            ViewBag.LowerLevel = LowerLevel;
            ViewBag.Edit       = this.checkPower("Edit");
            return(View());
        }
        public void Add(MsgAdmin MsgAdmin, int?IsObj, int?IsAdmin, int?IsPId, int?IsLevel)
        {
            string sendUsers = "";

            //获取发送对象
            if (IsObj.HasValue)
            {
                switch (IsObj)
                {
                case 0:    //管理员
                    MsgAdmin.IsAdmin = 0;
                    #region  给管理员发送
                    if (IsAdmin.HasValue)
                    {
                        if (IsAdmin.Value == 0)
                        {
                            //选择了所有的管理员
                            IList <SysAdmin> ListAdmin = BasicAgent.GetAgentAdmins(Entity);   //获取所有的管理员
                            if (ListAdmin.Count > 1)
                            {
                                MsgAdmin.AId = 0;
                                foreach (var item in ListAdmin)
                                {
                                    sendUsers += item.Id + ",";
                                }
                            }
                            else
                            {
                                MsgAdmin.AId = ListAdmin[0].Id;
                            }
                        }
                        else
                        {
                            //如果选择了单个管理员
                            MsgAdmin.AId = IsAdmin.Value;
                        }
                    }
                    #endregion
                    break;

                case 1:      //代理商
                    MsgAdmin.IsAdmin = 1;
                    #region 给代理商发送
                    int isLevel = IsLevel.HasValue ? IsLevel.Value : 0;

                    if (IsPId.HasValue)
                    {
                        if (IsPId.Value == 0)    //如果选择的所有代理商
                        {
                            IList <SysAgent> ListAgent = BasicAgent.GetSupAgent(Entity);
                            if (isLevel == 1)
                            {
                                //包含下级
                                ListAgent = ListAgent.GetSupAgent(Entity);
                            }
                            IList <SysAdmin> modelAdmin = ListAgent.GetAgentAdmins(Entity);
                            if (modelAdmin.Count > 1)
                            {
                                MsgAdmin.AId = 0;
                                foreach (var adminItem in modelAdmin)
                                {
                                    sendUsers += adminItem.Id + ",";
                                }
                            }
                            else
                            {
                                MsgAdmin.AId = modelAdmin[0].Id;
                            }
                        }
                        else      //如果选择的单个代理商
                        {
                            SysAgent         agentModel = Entity.SysAgent.FirstOrDefault(x => x.Id == IsPId);
                            IList <SysAdmin> modelAdmin = null;
                            if (isLevel == 0)      //不包含下级
                            {
                                modelAdmin = agentModel.GetAgentAdmins(Entity);
                            }
                            else      //包含下级
                            {
                                //获取下级代理商
                                IList <SysAgent> ListAgent = agentModel.GetSupAgent(Entity);
                                modelAdmin = ListAgent.GetAgentAdmins(Entity);
                            }
                            if (modelAdmin.Count > 1)
                            {
                                MsgAdmin.AId = 0;
                                foreach (var item in modelAdmin)
                                {
                                    sendUsers += item.Id + ",";
                                }
                            }
                            else
                            {
                                MsgAdmin.AId = modelAdmin[0].Id;
                            }
                        }
                    }
                    #endregion
                    break;
                }
            }
            MsgAdmin.PId       = AdminUser.Id;
            MsgAdmin.SendUsers = !string.IsNullOrWhiteSpace(sendUsers) ? "," + sendUsers : ",0,";
            MsgAdmin.Name      = MsgAdmin.Name;
            MsgAdmin.Info      = MsgAdmin.Info;
            MsgAdmin.State     = MsgAdmin.State;
            MsgAdmin.AddTime   = DateTime.Now;
            Entity.MsgAdmin.AddObject(MsgAdmin);
            Entity.SaveChanges();
            BaseRedirect();
        }
Ejemplo n.º 24
0
        public ActionResult Index(Orders Orders, EFPagingInfo <Orders> p, bool?IsShowSupAgent, int?LowerLevel, int IsFirst = 0)
        {
            if (IsFirst == 0)
            {
                if (IsShowSupAgent == null)
                {
                    IsShowSupAgent = false;
                }
                if (checkPower("ALL"))
                {
                    IsAll = true;
                }
                LowerLevel    = LowerLevel == null ? 0 : LowerLevel;
                ViewBag.IsAll = IsAll;
                PageOfItems <Orders> OrdersList1 = new PageOfItems <Orders>(new List <Orders>(), 0, 10, 0, new Hashtable());
                ViewBag.OrdersList = OrdersList1;
                ViewBag.Orders     = Orders;
                //查询对应的商户
                List <int> UId1 = OrdersList1.Select(o => o.UId).Distinct().ToList();
                ViewBag.UsersList      = Entity.Users.Where(n => n.State == 1 && UId1.Contains(n.Id)).ToList();
                ViewBag.PayConfigList  = Entity.PayConfig.Where(n => n.State == 1).ToList();
                ViewBag.IsShowSupAgent = IsShowSupAgent;
                ViewBag.BasicAgent     = BasicAgent;
                SysSet SysSet1 = Entity.SysSet.FirstOrNew();
                ViewBag.SysSet     = SysSet1;
                ViewBag.Entity     = Entity;
                ViewBag.LowerLevel = LowerLevel;
                return(View());
            }
            //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"));
            //}
            //if (!Orders.STime.IsNullOrEmpty() && !Orders.ETime.IsNullOrEmpty())
            //{
            //    DateTime ETime = Orders.ETime;
            //    p.SqlWhere.Add(f => f.PayTime > Orders.STime && f.PayTime < ETime);
            //}

            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            if (checkPower("ALL"))
            {
                IsAll = true;
            }
            ViewBag.IsAll = IsAll;

            /*有没有指定交易所属代理
             * 有:校验是否从属关系
             * 无:指定当前代理
             */
            if (!Orders.Agent.IsNullOrEmpty())
            {
                if (!IsBelongToAgent(Orders.Agent))
                {
                    ViewBag.ErrorMsg = "只能查询当前用户下属代理的交易";
                    return(View("Error"));
                }
            }
            else
            {
                Orders.Agent = this.BasicAgent.Id;
            }
            LowerLevel = LowerLevel == null ? 0 : LowerLevel;
            //没有"管理所有"权限的只能看到操作员自己的数据
            //if (!IsAll)
            //{
            //    p.SqlWhere.Add(f => f.AId == AdminUser.Id);//交易所属用户
            //}
            //else
            {
                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);
                    }
                    else
                    {
                        SysAgentList = BasicAgent.GetSupAgent(Entity);//获取所有下级代理商信息
                    }
                    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);//交易所属代理
                }
            }
            #region 筛选条件
            if (!Orders.OrderAddress.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.OrderAddress.Contains(Orders.OrderAddress));
            }
            if (!Orders.TNum.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TNum == Orders.TNum);
            }
            if (!Orders.LagEntryDay.IsNullOrEmpty())
            {
                if (Orders.LagEntryDay == 99)
                {
                    p.SqlWhere.Add(f => f.LagEntryDay == 0);
                }
                else
                {
                    p.SqlWhere.Add(f => f.LagEntryDay > 0);
                }
            }
            if (!Orders.TrunType.IsNullOrEmpty())
            {
                if (Orders.TrunType == 1)
                {
                    p.SqlWhere.Add(f => f.TrunType == 1);
                }
                else
                {
                    p.SqlWhere.Add(f => f.TrunType == 0);
                }
            }

            if (!Orders.TName.IsNullOrEmpty())
            {
                IList <Users> UList = Entity.Users.Where(n => n.TrueName.Contains(Orders.TName) || n.NeekName.Contains(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.PayWay.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.PayWay == Orders.PayWay);
            }
            if (!Orders.STime.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AddTime >= Orders.STime);
            }
            if (!Orders.ETime.IsNullOrEmpty())
            {
                DateTime ETime = Orders.ETime.AddHours(23).AddMinutes(59).AddSeconds(59);
                p.SqlWhere.Add(f => f.AddTime <= ETime);
            }
            #region 交易类型条件判断
            p.SqlWhere.Add(f => f.TType == 2);//读取对应的类型
            if (Orders.TType == 2)
            {
                if (!Orders.TState.IsNullOrEmpty())
                {
                    p.SqlWhere.Add(f => f.TState == Orders.TState);
                }
            }
            #endregion
            #endregion
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <Orders> OrdersList = Entity.Selects <Orders>(p);
            ViewBag.OrdersList = OrdersList;
            ViewBag.Orders     = Orders;
            //查询对应的商户
            List <int> UId = OrdersList.Select(o => o.UId).Distinct().ToList();
            ViewBag.UsersList = Entity.Users.Where(n => n.State == 1 && UId.Contains(n.Id)).ToList();
            //因为上面判段过了,这里其实是不用的
            //if (checkPower("ALL"))
            //{
            //    ViewBag.UsersList = Entity.Users.Where(n => n.State == 1 && n.Agent == AdminUser.AgentId && UId.Contains(n.Id)).ToList();
            //}
            //else
            //{
            //    ViewBag.UsersList = Entity.Users.Where(n => n.State == 1 && n.AId == AdminUser.Id && UId.Contains(n.Id)).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.Entity     = Entity;
            ViewBag.LowerLevel = LowerLevel;
            return(View());
        }
        public ActionResult Index(ApplyLoan ApplyLoan, EFPagingInfo <ApplyLoan> p, bool?IsShowSupAgent, int IsFirst = 0)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            if (ApplyLoan.STime.IsNullOrEmpty())
            {
                ApplyLoan.STime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            }
            if (ApplyLoan.ETime.IsNullOrEmpty())
            {
                //  ApplyLoan.ETime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                ApplyLoan.ETime = DateTime.Now;
            }
            if (IsFirst == 0)
            {
                PageOfItems <ApplyLoan> ApplyLoanList1 = new PageOfItems <ApplyLoan>(new List <ApplyLoan>(), 0, 10, 0, new Hashtable());
                ViewBag.ApplyLoanList  = ApplyLoanList1;
                ViewBag.ApplyLoan      = ApplyLoan;
                ViewBag.SysAgentList   = Entity.SysAgent.Where(n => n.Tier == 1).ToList();
                ViewBag.IsShowSupAgent = IsShowSupAgent;
                ViewBag.Xls            = this.checkPower("Xls");
                return(View());
            }

            if (!ApplyLoan.TrueName.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TrueName == ApplyLoan.TrueName);
            }
            if (!ApplyLoan.Education.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Education.Contains(ApplyLoan.Education));
            }
            if (!ApplyLoan.HasSheBao.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.HasSheBao == (ApplyLoan.HasSheBao == 99 ? 0 : ApplyLoan.HasSheBao));
            }
            if (!ApplyLoan.Marry.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Marry == ApplyLoan.Marry);
            }
            if (!ApplyLoan.HasCar.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.HasCar == (ApplyLoan.HasCar == 99 ? 0 : ApplyLoan.HasCar));
            }
            if (!ApplyLoan.House.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.House == ApplyLoan.House);
            }
            if (!ApplyLoan.HasCredit.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.HasCredit == ApplyLoan.HasCredit);
            }
            if (!ApplyLoan.State.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.State == ApplyLoan.State);
            }
            if (!ApplyLoan.AgentPay.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AgentPay == (ApplyLoan.AgentPay == 99 ? 0 : ApplyLoan.AgentPay));
            }
            if (!ApplyLoan.AgentAId.IsNullOrEmpty())
            {
                //是否要显示下级
                if ((bool)IsShowSupAgent)
                {
                    SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == ApplyLoan.AgentAId).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.AgentAId));
                }
                else
                {
                    p.SqlWhere.Add(f => f.AgentAId == ApplyLoan.AgentAId);
                }
            }
            if (!ApplyLoan.STime.IsNullOrEmpty() && !ApplyLoan.ETime.IsNullOrEmpty())
            {
                DateTime ETime = ApplyLoan.ETime;
                p.SqlWhere.Add(f => f.PayTime > ApplyLoan.STime && f.PayTime < ETime);
            }
            p.SqlWhere.Add(f => f.PayState == 1);
            p.PageSize = 99999999;
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <ApplyLoan> ApplyLoanList = Entity.Selects <ApplyLoan>(p);

            ViewBag.ApplyLoanList = ApplyLoanList;
            ViewBag.ApplyLoan     = ApplyLoan;
            IList <ApplyLoan> List    = ApplyLoanList.GroupBy(n => n.AgentId).Select(n => n.First()).ToList();
            List <int>        AgentId = new List <int>();

            foreach (var pp in List)
            {
                AgentId.Add(pp.AgentId);
            }
            ViewBag.SysAgentList   = Entity.SysAgent.Where(n => AgentId.Contains(n.Id) && n.Tier == 1).ToList();
            ViewBag.IsShowSupAgent = IsShowSupAgent;
            ViewBag.Xls            = this.checkPower("Xls");
            return(View());
        }
        public ActionResult Index(ApplyLoan ApplyLoan, EFPagingInfo <ApplyLoan> p, bool?IsShowSupAgent, int IsFirst = 0)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            if (!ApplyLoan.TrueName.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TrueName == ApplyLoan.TrueName);
            }
            if (!ApplyLoan.Education.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Education.Contains(ApplyLoan.Education));
            }
            if (!ApplyLoan.SheBao.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.SheBao == ApplyLoan.SheBao);
            }
            if (!ApplyLoan.Marry.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.Marry == ApplyLoan.Marry);
            }
            if (!ApplyLoan.HasCar.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.HasCar == (ApplyLoan.HasCar == 99 ? 0 : ApplyLoan.HasCar));
            }
            if (!ApplyLoan.House.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.House == ApplyLoan.House);
            }
            if (!ApplyLoan.HasCredit.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.HasCredit == ApplyLoan.HasCredit);
            }
            if (!ApplyLoan.State.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.State == ApplyLoan.State);
            }
            if (!ApplyLoan.AgentPay.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.AgentPay == (ApplyLoan.AgentPay == 99 ? 0 : ApplyLoan.AgentPay));
            }
            if (!ApplyLoan.AgentAId.IsNullOrEmpty())
            {
                //是否要显示下级
                if ((bool)IsShowSupAgent)
                {
                    SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == ApplyLoan.AgentAId).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.AgentAId));
                }
                else
                {
                    p.SqlWhere.Add(f => f.AgentAId == ApplyLoan.AgentAId);
                }
            }
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <ApplyLoan> ApplyLoanList = null;

            if (IsFirst == 0)
            {
                ApplyLoanList = new PageOfItems <ApplyLoan>(new List <ApplyLoan>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                ApplyLoanList = Entity.Selects <ApplyLoan>(p);
            }
            ViewBag.ApplyLoanList  = ApplyLoanList;
            ViewBag.ApplyLoan      = ApplyLoan;
            ViewBag.SysAgentList   = Entity.SysAgent.Where(n => n.Tier == 1).ToList();
            ViewBag.IsShowSupAgent = IsShowSupAgent;
            ViewBag.Save           = this.checkPower("Save");
            return(View());
        }
Ejemplo n.º 27
0
        private EFPagingInfo <Orders> Condition(Orders Orders, EFPagingInfo <Orders> p, bool?IsShowSupAgent, int TimeType = 1)
        {
            if (Orders.STime.IsNullOrEmpty())
            {
                Orders.STime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
            }
            if (Orders.ETime.IsNullOrEmpty())
            {
                Orders.ETime = DateTime.Now;
            }
            if (!Orders.TType.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.TType == Orders.TType);
            }
            if (!Orders.UId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.UId == Orders.UId);
            }
            //是否选择了一个分支机构
            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 (true)
            {
            }
            if (TimeType == 1)//交易时间
            {
                if (!Orders.STime.IsNullOrEmpty() && !Orders.ETime.IsNullOrEmpty())
                {
                    DateTime ETime = Orders.ETime.AddMilliseconds(999);
                    p.SqlWhere.Add(f => f.PayTime > Orders.STime && f.PayTime < ETime);
                }
                #region 交易类型条件判断
                if (!Orders.TType.IsNullOrEmpty())
                {
                    p.SqlWhere.Add(f => f.TType == Orders.TType);//读取对应的类型
                    if (Orders.TType == 1)
                    {
                        if (!Orders.TState.IsNullOrEmpty())
                        {
                            switch (Orders.TState)
                            {
                            case 1:    //未付
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 0);
                                break;

                            case 2:    //已付
                                p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 1);
                                break;

                            case 3:    //待传证照
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 1);
                                break;

                            case 4:    //待审核
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 2);
                                break;

                            case 5:    //审核失败
                                p.SqlWhere.Add(f => f.TState == 3 && f.PayState == 1 && f.IdCardState == 4);
                                break;

                            case 6:    //退单
                                p.SqlWhere.Add(f => f.TState == 4);
                                break;

                            case 7:    //待入帐
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.InState == 0);
                                break;
                            }
                        }
                    }
                    if (Orders.TType == 2)
                    {
                        //if (!Orders.TState.IsNullOrEmpty()) { p.SqlWhere.Add(f => f.TState == Orders.TState); }
                        switch (Orders.TState)
                        {
                        case 1:    //处理中
                            p.SqlWhere.Add(f => f.TState == 1);
                            break;

                        case 2:    //已汇出
                            p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 2);
                            break;

                        case 3:    //提现失败
                            p.SqlWhere.Add(f => f.TState == 3);
                            break;

                        case 4:    //出款中
                            p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 1);
                            break;
                        }
                    }
                    if (Orders.TType == 3)
                    {
                        switch (Orders.TState)
                        {
                        case 1:    //未付
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 0);
                            break;

                        case 2:    //已付
                            p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 1);
                            break;

                        case 3:    //待传证照
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 1);
                            break;

                        case 4:    //待审核
                            p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 2);
                            break;

                        case 5:    //审核失败
                            p.SqlWhere.Add(f => f.TState == 3 && f.PayState == 1 && f.IdCardState == 4);
                            break;
                        }
                    }
                    if (Orders.TType == 5)
                    {
                        if (!Orders.TState.IsNullOrEmpty())
                        {
                            switch (Orders.TState)
                            {
                            case 99:    //未付
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 0);
                                break;

                            case 1:    //处理中
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 0);
                                break;

                            case 2:    //已汇出
                                p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 2);
                                break;

                            case 4:    //出款中
                                p.SqlWhere.Add(f => (f.TState == 2 && f.PayState == 2 && f.IdCardState == 0) || (f.TState == 2 && f.PayState == 1 && f.IdCardState == 3));
                                break;

                            case 3:    //审核失败
                                p.SqlWhere.Add(f => (f.TState == 1 || f.TState == 3) && f.PayState == 1 && f.IdCardState == 4);
                                break;

                            case 5:    //退款中
                                p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 3);
                                break;

                            case 6:    //已退款
                                p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 4);
                                break;

                            case 7:    //待传身份证
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 1);
                                break;

                            case 8:    //已传身份证
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.IdCardState == 2);
                                break;
                            }
                        }
                    }
                    if (Orders.TType == 6)
                    {
                        if (!Orders.TState.IsNullOrEmpty())
                        {
                            p.SqlWhere.Add(f => f.TState == Orders.TState);
                        }
                    }
                    if (Orders.TType == 7 || Orders.TType == 8 || Orders.TType == 9)
                    {
                        if (!Orders.TState.IsNullOrEmpty())
                        {
                            if (Orders.TState == 99)
                            {
                                p.SqlWhere.Add(f => f.TState == 0);
                            }
                            if (Orders.TState == 1)
                            {
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 0);
                            }
                            if (Orders.TState == 2)
                            {
                                p.SqlWhere.Add(f => f.TState == 2 && f.PayState == 1);
                            }
                            if (Orders.TState == 3)//退单
                            {
                                p.SqlWhere.Add(f => f.TState == 4);
                            }
                            if (Orders.TState == 4)//待入帐
                            {
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.InState == 0);
                            }
                            if (Orders.TState == 5)//待审核
                            {
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.InState == 1 && f.IdCardState == 2);
                            }
                            if (Orders.TState == 6)//待传证照
                            {
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.InState == 1 && f.IdCardState == 1);
                            }
                            if (Orders.TState == 7)//审核失败
                            {
                                p.SqlWhere.Add(f => f.TState == 1 && f.PayState == 1 && f.InState == 1 && f.IdCardState == 4);
                            }
                        }
                    }
                    if (Orders.TType == 10)
                    {
                        if (!Orders.TState.IsNullOrEmpty())
                        {
                            p.SqlWhere.Add(f => f.TState == Orders.TState);
                        }
                    }
                }
                #endregion
            }
            else
            {
                if (!Orders.STime.IsNullOrEmpty() && !Orders.ETime.IsNullOrEmpty())
                {
                    DateTime ETime = Orders.ETime.AddMilliseconds(999);
                    p.SqlWhere.Add(f => f.InTimed > Orders.STime && f.InTimed < ETime);
                }
                if (!Orders.TType.IsNullOrEmpty())
                {
                    p.SqlWhere.Add(f => f.TType == Orders.TType && f.InState == 1);
                }
                else
                {
                    int[]      temp = { 1, 7, 8, 9 };
                    List <int> UID  = new List <int>(temp);
                    p.SqlWhere.Add(f => UID.Contains(f.TType) && f.InState == 1);
                }
            }
            return(p);
        }
        /// <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(UserPayChange UserPayChange, EFPagingInfo <UserPayChange> p, bool?IsShowSupAgent, int IsFirst = 0)
        {
            if (IsShowSupAgent == null)
            {
                IsShowSupAgent = false;
            }
            if (IsFirst == 0)
            {
                PageOfItems <UserPayChange> UserPayChangeList1 = new PageOfItems <UserPayChange>(new List <UserPayChange>(), 0, 10, 0, new Hashtable());
                ViewBag.UserPayChangeList = UserPayChangeList1;
                ViewBag.UserPayChange     = UserPayChange;
                ViewBag.UsersList         = null;
                ViewBag.SysAdminList      = Entity.SysAdmin.Where(n => n.State == 1).ToList();
                ViewBag.SysAgentList      = Entity.SysAgent.Where(n => n.State == 1).ToList();
                ViewBag.IsShowSupAgent    = IsShowSupAgent;//是否显示下级

                return(View());
            }
            //if (UserPayChange.State.IsNullOrEmpty())
            //{
            //    UserPayChange.State = 1;
            //}
            //if (UserPayChange.State == 99)
            //{
            //    UserPayChange.State = 0;
            //}
            if (!UserPayChange.Remark.IsNullOrEmpty())
            {
                IList <Users> UList = Entity.Users.Where(n => n.TrueName.Contains(UserPayChange.Remark) || n.NeekName.Contains(UserPayChange.Remark) || n.UserName == UserPayChange.Remark).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 (!UserPayChange.State.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.State == UserPayChange.State);
            }
            if (!UserPayChange.SId.IsNullOrEmpty())
            {
                //是否要显示下级
                if ((bool)IsShowSupAgent)
                {
                    SysAgent         LowerLevelAgent = Entity.SysAgent.Where(s => s.Id == UserPayChange.SId).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.SId));
                }
                else
                {
                    p.SqlWhere.Add(f => f.SId == UserPayChange.SId);
                }
            }
            if (!UserPayChange.SAId.IsNullOrEmpty())
            {
                p.SqlWhere.Add(f => f.SAId == UserPayChange.SAId);
            }
            p.OrderByList.Add("Id", "DESC");
            IPageOfItems <UserPayChange> UserPayChangeList = null;

            if (IsFirst == 0)
            {
                UserPayChangeList = new PageOfItems <UserPayChange>(new List <UserPayChange>(), 0, 10, 0, new Hashtable());
            }
            else
            {
                UserPayChangeList = Entity.Selects <UserPayChange>(p);
            }
            ViewBag.UserPayChangeList = UserPayChangeList;
            ViewBag.UserPayChange     = UserPayChange;
            IList <UserPayChange> List = UserPayChangeList.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.SysAdminList   = Entity.SysAdmin.Where(n => n.State == 1).ToList();
            ViewBag.SysAgentList   = Entity.SysAgent.Where(n => n.State == 1).ToList();
            ViewBag.IsShowSupAgent = IsShowSupAgent;//是否显示下级
            ViewBag.Edit           = this.checkPower("Edit");
            ViewBag.Save           = this.checkPower("Save");
            return(View());
        }