コード例 #1
0
        /// <summary>
        /// 首页数据
        /// </summary>
        /// <param name="days"></param>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public MainData GetMainData(int days, Pagination pagination)
        {
            var currentTime   = DateTime.Now.ToCstTime().ToString("yyyy-MM-dd");
            var yesterdayTime = DateTime.Now.ToCstTime().AddDays(-1).ToString("yyyy-MM-dd");
            var data          = new MainData();

            var listPays    = new payBusiness().GetIQueryable().Where(x => x.status == 1).ToList();                                                                       //支付记录
            var listProduct = new ProductBusiness().GetIQueryable().ToList();                                                                                             //产品清单
            var listMembers = new membersBusiness().GetIQueryable().ToList();                                                                                             //用户记录
            var listOrders  = new orderBusiness().GetIQueryable().Where(x => x.status == 1).ToList().Where(x => listPays.Find(a => a.order_id == x.Id) != null).ToList(); //订单 -支付完成的订单

            //浏览数
            data.T_VisitsNum = 0;
            data.Y_VisitsNum = 0;
            data.A_VisitsNum = 0;
            //注册用户数
            data.T_RegisteredUsers = listMembers.Where(x => x.registration_time?.ToString("yyyy-MM-dd") == currentTime).Count();
            data.Y_RegisteredUsers = listMembers.Where(x => x.registration_time?.ToString("yyyy-MM-dd") == yesterdayTime).Count();
            data.A_RegisteredUsers = listMembers.Where(x => x.registration_time != null).Count();
            //团长新增数
            data.T_NewHead = listMembers.Where(x => x.header_time?.ToString("yyyy-MM-dd") == currentTime).Count();
            data.Y_NewHead = listMembers.Where(x => x.header_time?.ToString("yyyy-MM-dd") == yesterdayTime).Count();
            data.A_NewHead = listMembers.Where(x => x.header_time != null).Count();
            //参团数
            data.T_Participants = listOrders.Where(x => x.create_time.ToString("yyyy-MM-dd") == currentTime).Sum(x => x.num);
            data.Y_Participants = listOrders.Where(x => x.create_time.ToString("yyyy-MM-dd") == yesterdayTime).Sum(x => x.num);
            data.A_Participants = listOrders.Where(x => x.create_time != null).Sum(x => x.num);
            //交易额
            data.T_TradingVolume = listPays.Where(x => x.pay_time?.ToString("yyyy-MM-dd") == currentTime).Sum(x => x.money);
            data.Y_TradingVolume = listPays.Where(x => x.pay_time?.ToString("yyyy-MM-dd") == yesterdayTime).Sum(x => x.money);
            data.A_TradingVolume = listPays.Where(x => x.pay_time != null).Sum(x => x.money);

            decimal value = 0;

            for (int i = days - 1; i >= 0; i--)
            {
                value += listPays.Where(x => x.pay_time?.ToString("yyyy-MM-dd") == DateTime.Now.ToCstTime().AddDays(-i).ToString("yyyy-MM-dd")).Sum(x => x.money);
                data.xAxisData.Add(DateTime.Now.ToCstTime().AddDays(-i).ToString("MM/dd"));
                data.yAxisData.Add(value);
            }

            List <SaleRank> ProductSaleRank     = new List <SaleRank>();
            var             listProductSaleRank = listOrders.GroupBy(x => x.product_id);

            foreach (var item in listProductSaleRank)
            {
                ProductSaleRank.Add(new SaleRank()
                {
                    name = listProduct.Find(x => x.Id == int.Parse(item.Key))?.title, num = item.Sum(x => x.num)
                });
            }
            data.ProductSaleRank = pagination.BuildTableResult_DataGrid(ProductSaleRank.GetPagination(pagination).ToList());

            List <SaleRank> TeamSaleRank     = new List <SaleRank>();
            var             listTeamSaleRank = listOrders.Where(x => x.share_id != null).GroupBy(x => x.share_id);

            foreach (var item in listTeamSaleRank)
            {
                TeamSaleRank.Add(new SaleRank()
                {
                    name = listMembers.Find(x => x.oppen_id == item.Key)?.nick_name, num = item.Sum(x => x.num)
                });
            }
            data.TeamSaleRank = pagination.BuildTableResult_DataGrid(TeamSaleRank.GetPagination(pagination).ToList());
            return(data);
        }
コード例 #2
0
 public ProductRepBusiness()
 {
     _payBusiness               = new payBusiness();
     _orderBusiness             = new orderBusiness();
     _product_marketingBusiness = new product_marketingBusiness();
 }