/// <summary> /// 获取区间的日期订单统计[周、月] /// </summary> /// <param name="merchantId"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <returns></returns> public List <OrderDayStat> GetOrderStatInDay(Guid merchantId, DateTime startDate, DateTime endDate) { startDate = new DateTime(startDate.Year, startDate.Month, startDate.Day, 0, 0, 0); endDate = new DateTime(endDate.Year, endDate.Month, endDate.Day, 23, 59, 59); OrderDAC dac = new OrderDAC(); List <OrderDayStat> list = dac.GetTradingStatInDay(merchantId, startDate, endDate); return(list); }
public TradingReportDTO MonthlyTrading(Guid merchantAccountId) { //if (!new ProfileComponent().ValidateLv1(merchantAccountId)) // throw new CommonException(ReasonCode.NOT_VERIFY_LV1, Resources.需要Lv1认证才能使用相关功能); var date = DateTime.UtcNow.Date; var startDate = date.AddDays(-31); var endDate = date.AddDays(-1); var account = new MerchantAccountDAC().GetById(merchantAccountId); var country = new CountryComponent().GetById(account.CountryId); OrderDAC dac = new OrderDAC(); List <OrderDayStat> list = dac.GetTradingStatInDay(merchantAccountId, startDate, date); var volume = list.Sum(e => e.OrderCount); var sum = list.Sum(e => e.OrderAmount); var avg = volume == 0 ? 0 : sum / volume; var result = new TradingReportDTO { FormDate = startDate.ToUnixTime(), ToDate = endDate.ToUnixTime(), Volume = volume, SumAmount = sum.ToString("F"), AvgAmount = avg.ToString("F"), FiatCurrency = country.FiatCurrency ?? "USD", Stats = new List <Stat>() }; var cusorDate = startDate; while (cusorDate <= endDate) { var item = list.FirstOrDefault(e => DateTime.Parse(e.OrderDay) == cusorDate); var stat = new Stat { Date = cusorDate.ToUnixTime(), Count = item?.OrderCount ?? 0, Amount = item?.OrderAmount ?? 0M }; result.Stats.Add(stat); cusorDate = cusorDate.AddDays(1); } return(result); }