public static SalesStatistics GetReturnSales(DateTime startTime, int mode, string machineSn = "", string uid = "")
        {
            var result = new SalesStatistics();

            if (mode == 2)
            {
                startTime = new DateTime(startTime.Year, startTime.Month, 1);
            }
            var endDate = (mode == 1 ? startTime.AddDays(1) : startTime.AddMonths(1));

            var list = CurrentRepository.Entities.Where(o => o.CreateDT >= startTime && o.CreateDT <= endDate && (o.ReturnType == 0 || o.ReturnType == 2) && (o.MachineSN == machineSn || string.IsNullOrEmpty(machineSn)) && (o.CreateUID == uid || string.IsNullOrEmpty(uid))).ToList().Distinct();

            result.Amount = list.Sum(o => o.ReturnPrice);
            result.Count  = list.Count();
            result.Title  = "退货合计";
            return(result);
        }
        public static SalesStatistics GetChangingSalesStatistics(DateTime startTime, int mode, string machineSn = "", string uid = "")
        {
            if (mode == 2)
            {
                startTime = new DateTime(startTime.Year, startTime.Month, 1);
            }
            var endDate = (mode == 1 ? startTime.AddDays(1) : startTime.AddMonths(1));

            var result = new SalesStatistics()
            {
                Title = "换货合计"
            };

            var list = CurrentRepository.FindList(o => o.CreateDT >= startTime && o.CreateDT <= endDate && (o.CreateUID == uid || string.IsNullOrEmpty(uid)) && (o.MachineSN == machineSn || string.IsNullOrEmpty(machineSn)) && o.Type == 1)
                       .Select(o => (decimal?)o.TotalAmount).ToList().Distinct();

            result.Amount = list.Sum() ?? 0;
            result.Count  = list.Count();
            return(result);
        }
        public static SalesStatistics GetSalesStatistics(DateTime data, int mode, string machineSn = "", string uid = "")
        {
            if (mode == 2)
            {
                data = new DateTime(data.Year, data.Month, 1);
            }
            var endDate = (mode == 1 ? data.AddDays(1) : data.AddMonths(1));
            var result  = new SalesStatistics()
            {
                Title = "销售小计"
            };
            var list = CurrentRepository.Entities.Where(o => o.CreateDT >= data && o.CreateDT <= endDate && (o.MachineSN == machineSn || string.IsNullOrEmpty(machineSn)) && (o.CreateUID == uid || string.IsNullOrEmpty(uid))).ToList().Distinct();

            result.Amount = list.Sum(o => o.TotalAmount);
            result.Count  = list.Count();
            if (result.Count > 0)
            {
                result.FristSale = list.Min(o => o.CreateDT);
                result.LastSale  = list.Max(o => o.CreateDT);
            }
            return(result);
        }
        public static SalesStatistics GetSalesStatistics(DateTime date, int mode, string machineSn, int type = 1, string uid = "")
        {
            if (mode == 2)
            {
                date = new DateTime(date.Year, date.Month, 1);
            }
            var endDate = (mode == 1 ? date.AddDays(1) : date.AddMonths(1));
            var list    = CurrentRepository.FindList(o => (o.MachineSN == machineSn || string.IsNullOrEmpty(machineSn)) && o.CreateDT >= date && o.CreateDT <= endDate && o.CreateUID == uid && o.Type == type).ToList();
            var result  = new SalesStatistics();

            if (type == 1)
            {
                result.Title = "入款合计";
            }
            else
            {
                result.Title = "出款合计";
            }
            result.Amount = list.Select(o => o.Amount).Sum();
            result.Count  = list.Count;
            return(result);
        }
        public static SalesStatistics GetSalesStatistics(DateTime date, int mode, string machineSn = "", string uid = "")
        {
            var result = new SalesStatistics()
            {
                Title = "赠送合计"
            };

            if (mode == 2)
            {
                date = new DateTime(date.Year, date.Month, 1);
            }
            var enddate = (mode == 1 ? date.AddDays(1) : date.AddMonths(1));

            var list = (from a in CurrentRepository.Entities
                        from b in SaleOrdersLocalService.CurrentRepository.Entities
                        where a.PaySN == b.PaySN && b.Type == 0 && b.CreateDT >= date && b.CreateDT <= enddate && (b.MachineSN == machineSn || string.IsNullOrEmpty(machineSn)) && (b.CreateUID == uid || string.IsNullOrEmpty(uid)) && a.ActualPrice == 0
                        select a
                        ).ToList();

            result.Amount = list.Sum(o => o.SysPrice * o.PurchaseNumber);
            result.Count  = list.Select(o => o.PaySN).Distinct().Count();
            return(result);
        }