public HttpResponseMessage GetBrokeAccountByUserId(string userId = null)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据错误!")));
            }

            var brokeaccountcon = new BrokeAccountSearchCondition
            {
                Brokers = _brokerService.GetBrokerByUserId(Convert.ToInt32(userId)),
                State   = 0
            };
            var PointDetailList = _brokeaccountService.GetBrokeAccountsByCondition(brokeaccountcon).Select(p => new
            {
                Id = p.Id,
                p.Balancenum,
                p.Type,
                p.Addtime
            }).ToList().Select(p => new
            {
                Id = p.Id,
                p.Balancenum,
                p.Type,
                Addtime = p.Addtime.ToString("yyyy-MM-dd")
            });

            return(PageHelper.toJson(new { List = PointDetailList, Condition = brokeaccountcon }));
        }
        public HttpResponseMessage GetPointDetailListByUserId(string userId = null, int page = 1, int pageSize = 10)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return(PageHelper.toJson(PageHelper.ReturnValue(false, "数据错误!")));
            }

            var brokeaccountcon = new BrokeAccountSearchCondition
            {
                Brokers   = _brokerService.GetBrokerById(Convert.ToInt32(userId)),
                Page      = Convert.ToInt32(page),
                PageCount = pageSize
            };
            var PointDetailList = _brokeaccountService.GetBrokeAccountsByCondition(brokeaccountcon).Select(p => new
            {
                Id = p.Id,
                p.Balancenum,
                p.MoneyDesc,
                brokername = p.Broker.Brokername,
                p.Addtime
            }).ToList().Select(p => new {
                Id = p.Id,
                p.Balancenum,
                p.MoneyDesc,
                brokername = p.brokername,
                Addtime    = p.Addtime.ToString("yyyy-MM-dd")
            });
            var PointDetailListCount = _brokeaccountService.GetBrokeAccountCount(brokeaccountcon);

            return(PageHelper.toJson(new { List = PointDetailList, Condition = brokeaccountcon, totalCount = PointDetailListCount }));
        }
        public string GetBrokerAmount()
        {
            var user = (UserBase)_workContext.CurrentUser;

            if (user != null)
            {
                var broker = _brokerService.GetBrokerByUserId(user.Id);//获取当前经纪人
                if (broker != null)
                {
                    BrokeAccountSearchCondition broconditon = new BrokeAccountSearchCondition
                    {
                        Brokers = broker,
                        State   = 0
                    };
                    //BrokerWithdrawDetailSearchCondition browithdetailcon = new BrokerWithdrawDetailSearchCondition
                    //{
                    //    Brokers = broker,
                    //    Type = "1"

                    //};
                    //decimal AddMoneys = _brokeaccountService.GetBrokeAccountsByCondition(broconditon).Count() > 0 ? _brokeaccountService.GetBrokeAccountsByCondition(broconditon).Sum(o => o.Balancenum) : 0;//新增的金额总和
                    //decimal TxMoneys = _brokerwithdrawdetailService.GetBrokerWithdrawDetailsByCondition(browithdetailcon).Count() > 0 ? _brokerwithdrawdetailService.GetBrokerWithdrawDetailsByCondition(browithdetailcon).Sum(o => o.Withdrawnum) : 0;//提现的总金额
                    //return (AddMoneys - TxMoneys).ToString();

                    return(_brokeaccountService.GetBrokeAccountsByCondition(broconditon).Count() > 0 ? _brokeaccountService.GetBrokeAccountsByCondition(broconditon).Sum(o => o.Balancenum).ToString() : "0");//金额总和
                }
            }
            return("");
        }
        public IQueryable <BrokeAccountEntity> GetBrokeAccountsByCondition(BrokeAccountSearchCondition condition)
        {
            var query = _brokeaccountRepository.Table;

            try
            {
                if (condition.AddtimeBegin.HasValue)
                {
                    query = query.Where(q => q.Addtime >= condition.AddtimeBegin.Value);
                }
                if (condition.Type.HasValue)
                {
                    query = query.Where(q => q.Type == condition.Type);
                }
                //if (condition.Brokers!=null)
                //{
                //    query = query.Where(q => q.Broker == condition.Brokers);
                //}
                if (condition.State.HasValue)
                {
                    query = query.Where(q => q.State == condition.State.Value);
                }
                if (condition.AddtimeEnd.HasValue)
                {
                    query = query.Where(q => q.Addtime < condition.AddtimeEnd.Value);
                }
                if (condition.UptimeBegin.HasValue)
                {
                    query = query.Where(q => q.Uptime >= condition.UptimeBegin.Value);
                }
                if (condition.UptimeEnd.HasValue)
                {
                    query = query.Where(q => q.Uptime < condition.UptimeEnd.Value);
                }
                if (condition.Balancenum.HasValue)
                {
                    query = query.Where(q => q.Balancenum == condition.Balancenum.Value);
                }
                if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }
                if (condition.Brokers != null)
                {
                    query = query.Where(q => q.Broker.Id == condition.Brokers.Id);
                }
                if (condition.Addusers != null && condition.Addusers.Any())
                {
                    query = query.Where(q => condition.Addusers.Contains(q.Adduser));
                }
                if (condition.Upusers != null && condition.Upusers.Any())
                {
                    query = query.Where(q => condition.Upusers.Contains(q.Upuser));
                }
                if (condition.OrderBy.HasValue)
                {
                    switch (condition.OrderBy.Value)
                    {
                    case EnumBrokeAccountSearchOrderBy.OrderById:
                        query = condition.isDescending?query.OrderByDescending(q => q.Id):query.OrderBy(q => q.Id);
                        break;
                    }
                }
                else
                {
                    query = query.OrderBy(q => q.Id);
                }

                if (condition.Page.HasValue && condition.PageCount.HasValue)
                {
                    query = query.Skip((condition.Page.Value - 1) * condition.PageCount.Value).Take(condition.PageCount.Value);
                }
                return(query);
            }
            catch (Exception e)
            {
                _log.Error(e, "数据库操作出错");
                return(null);
            }
        }
        public int GetBrokeAccountCount(BrokeAccountSearchCondition condition)
        {
            var query = _brokeaccountRepository.Table;

            try
            {
                if (condition.AddtimeBegin.HasValue)
                {
                    query = query.Where(q => q.Addtime >= condition.AddtimeBegin.Value);
                }
                if (condition.AddtimeEnd.HasValue)
                {
                    query = query.Where(q => q.Addtime < condition.AddtimeEnd.Value);
                }
                if (condition.Type.HasValue)
                {
                    query = query.Where(q => q.Type == condition.Type);
                }
                //if (condition.Brokers != null)
                //{
                //    query = query.Where(q => q.Broker == condition.Brokers);
                //}
                if (condition.UptimeBegin.HasValue)
                {
                    query = query.Where(q => q.Uptime >= condition.UptimeBegin.Value);
                }
                if (condition.UptimeEnd.HasValue)
                {
                    query = query.Where(q => q.Uptime < condition.UptimeEnd.Value);
                }
                if (condition.Balancenum.HasValue)
                {
                    query = query.Where(q => q.Balancenum == condition.Balancenum.Value);
                }
                if (condition.State.HasValue)
                {
                    query = query.Where(q => q.State == condition.State.Value);
                }
                if (condition.Ids != null && condition.Ids.Any())
                {
                    query = query.Where(q => condition.Ids.Contains(q.Id));
                }
                if (condition.Brokers != null)
                {
                    query = query.Where(q => condition.Brokers.Id == (q.Broker.Id));
                }
                if (condition.Addusers != null && condition.Addusers.Any())
                {
                    query = query.Where(q => condition.Addusers.Contains(q.Adduser));
                }
                if (condition.Upusers != null && condition.Upusers.Any())
                {
                    query = query.Where(q => condition.Upusers.Contains(q.Upuser));
                }
                return(query.Count());
            }
            catch (Exception e)
            {
                _log.Error(e, "数据库操作出错");
                return(-1);
            }
        }