/// <summary> /// 计算某段时间内的分润 /// </summary> /// <param name="startTime">开始时间</param> /// <param name="endTime">结束时间</param> public async Task <ShareProfit> GetShareProfitAsync(string startTime, string endTime) { string sql = $"select sum(cash) as 'cashs' from profit where " + $"create_time BETWEEN '{startTime}' AND '{endTime}'"; ShareProfit result = null; var data = await DapperHelper.GetListAsync <ShareProfit>(sql, this._conn); foreach (var item in data) { result = new ShareProfit { Cashs = item.Cashs ?? "0.00" }; } return(result ?? null); }
/// <summary> /// 数据对比,rjy 时间计算修改 /// </summary> /// <param name="time">前端传递时间,用于和服务器时间对比,判断自然周,自然月,自然季度</param> /// <param name="timeType">1:自然周,2:自然月,3:季度,4:天</param> /// <param name="upAndDown">0:当前, 1:前,2:后</param> /// <returns></returns> public async Task <DetailsResult> GetOrderDetailsAsync(DateTime time, string timeType, string upAndDown) { DetailsResult result = null; string startTime = string.Empty; //显示数据开始时间 string endTime = string.Empty; //显示数据结束时间 string lastStartTime = string.Empty; //对比数据开始时间 string lastEndTime = string.Empty; //对比数据结束时间 string retStartTime = string.Empty; //返回的开始时间 string retEndTime = string.Empty; //返回的结束时间 String retQuarter = string.Empty; //不管时间是什么时间啊,原始数据始终需要和前一次的数据比较,找出当前时间段,和对比时间段的开始时间和结束时间 switch (timeType) { case "1": { if (upAndDown == "0") { startTime = DateTimeExtensions.GetMondayDate(time).ToString("yyyy-MM-dd"); endTime = DateTimeExtensions.GetSundayDate(time).AddDays(+1).ToString("yyyy-MM-dd"); } if (upAndDown == "1") //上 { startTime = DateTimeExtensions.GetMondayDate(DateTimeExtensions.GetMondayDate(time).AddDays(-1)).ToString("yyyy-MM-dd"); endTime = DateTimeExtensions.GetSundayDate(DateTime.Parse(startTime)).AddDays(+1).ToString("yyyy-MM-dd"); } if (upAndDown == "2") //下 { startTime = DateTimeExtensions.GetMondayDate(DateTimeExtensions.GetSundayDate(time).AddDays(+1)).ToString("yyyy-MM-dd"); endTime = DateTimeExtensions.GetSundayDate(DateTime.Parse(startTime)).AddDays(+1).ToString("yyyy-MM-dd"); } lastStartTime = DateTimeExtensions.GetMondayDate(DateTime.Parse(startTime).AddDays(-1)).ToString("yyyy-MM-dd"); lastEndTime = startTime; retStartTime = startTime; retEndTime = DateTime.Parse(endTime).AddDays(-1).ToString("yyyy-MM-dd"); } break; case "2": { if (upAndDown == "0") { startTime = DateTimeExtensions.FirstDayOfMonth(time).ToString("yyyy-MM-dd"); endTime = DateTimeExtensions.LastDayOfMonth(time).AddDays(+1).ToString("yyyy-MM-dd"); } if (upAndDown == "1") //上 { startTime = DateTimeExtensions.FirstDayOfMonth(time.AddMonths(-1)).ToString("yyyy-MM-dd"); endTime = DateTimeExtensions.LastDayOfMonth(DateTime.Parse(startTime)).AddDays(+1).ToString("yyyy-MM-dd"); } if (upAndDown == "2") //下 { //计算逻辑错误 比九月下一月应该是十月 十月应该和九月比较 startTime = DateTimeExtensions.FirstDayOfMonth(time.AddMonths(+1)).ToString("yyyy-MM-dd"); endTime = DateTimeExtensions.LastDayOfMonth(DateTime.Parse(startTime)).AddDays(+1).ToString("yyyy-MM-dd"); } lastStartTime = DateTimeExtensions.FirstDayOfMonth(DateTime.Parse(startTime).AddMonths(-1)).ToString("yyyy-MM-dd"); lastEndTime = startTime; retStartTime = DateTime.Parse(lastStartTime).ToString("yyyy-MM"); retEndTime = DateTime.Parse(startTime).ToString("yyyy-MM"); } break; case "3": { if (upAndDown == "0") { startTime = DateTimeExtensions.TwoToFirstDayOfSeason(time).ToString("yyyy-MM-dd"); endTime = DateTimeExtensions.TwoToLastDayOfSeason(DateTime.Parse(startTime)).AddDays(+1).ToString("yyyy-MM-dd"); } if (upAndDown == "1") //上 { startTime = DateTimeExtensions.TwoToFirstDayOfSeason(DateTimeExtensions.TwoToFirstDayOfSeason(time).AddDays(-1)).ToString("yyyy-MM-dd"); endTime = DateTimeExtensions.TwoToLastDayOfSeason(DateTime.Parse(startTime)).AddDays(+1).ToString("yyyy-MM-dd"); } if (upAndDown == "2") //下 { startTime = DateTimeExtensions.TwoToFirstDayOfSeason(DateTimeExtensions.TwoToLastDayOfSeason(time).AddDays(+1)).ToString("yyyy-MM-dd"); endTime = DateTimeExtensions.TwoToLastDayOfSeason(DateTime.Parse(startTime)).AddDays(+1).ToString("yyyy-MM-dd"); } lastStartTime = DateTimeExtensions.TwoToFirstDayOfSeason(DateTime.Parse(startTime).AddDays(-1)).ToString("yyyy-MM-dd"); lastEndTime = startTime; retStartTime = lastStartTime; retEndTime = startTime; retQuarter = DateTimeExtensions.JudgeTimeIsToDiff(DateTime.Parse(startTime)); } break; case "4": { int day = 0; if (upAndDown == "0") { day = 0; } if (upAndDown == "1") //上 { day = -1; } if (upAndDown == "2") //下 { day = 1; } startTime = time.AddDays(day).ToString("yyyy-MM-dd"); endTime = time.AddDays(+(1 + day)).ToString("yyyy-MM-dd"); lastStartTime = time.AddDays(-(1 - day)).ToString("yyyy-MM-dd"); lastEndTime = time.AddDays(day).ToString("yyyy-MM-dd"); retStartTime = lastStartTime; retEndTime = startTime; } break; default: break; } //显示的数据源 Details showDetails = await LeadDataDataAccess.Instance.GetOrderDetailsAsync(startTime, endTime); //对比的数据源 Details trastDetails = await LeadDataDataAccess.Instance.GetOrderDetailsAsync(lastStartTime, lastEndTime); ShareProfit showShare = await LeadDataDataAccess.Instance.GetShareProfitAsync(startTime, endTime); ShareProfit trastShare = await LeadDataDataAccess.Instance.GetShareProfitAsync(lastStartTime, lastEndTime); bool isSuccess = false; //(今天-昨天)÷昨天×100% result = new DetailsResult(); { result.Sum = showDetails.Sum; result.Gross = showDetails.Gross; result.Profit = showDetails.Profit; result.Profits = showDetails.Profits; result.Average = showDetails.Average; result.Cashs = showShare.Cashs; result.SumRate = Contrast(showDetails.Sum, trastDetails.Sum, out isSuccess); result.SumTrend = isSuccess; result.GrossRate = Contrast(showDetails.Gross, trastDetails.Gross, out isSuccess); result.GrossTrend = isSuccess; result.ProfitRate = Contrast(showDetails.Profit, trastDetails.Profit, out isSuccess); result.ProfitTrend = isSuccess; result.ProfitsRate = Contrast(showDetails.Profits, trastDetails.Profits, out isSuccess); result.ProfitsTrend = isSuccess; result.AverageRate = Contrast(showDetails.Average, trastDetails.Average, out isSuccess); result.AverageTrend = isSuccess; result.CashsRate = Contrast(showShare.Cashs, trastShare.Cashs, out isSuccess); result.CashsTrend = isSuccess; result.StartTime = retStartTime; //lastStartTime; result.EndTime = retEndTime; //startTime;//(DateTime.Parse(endTime).AddDays(-1)).ToString("yyyy-MM-dd"); result.Quarter = retQuarter; }; return(result); }
/// <summary> /// Delete,根据实体对象删除 /// </summary> /// <returns>返回,成功:true,失败:false</returns> public bool Delete(ShareProfit entity) { return(dal.Update(entity)); }
/// <summary> /// 插入数据 /// </summary> /// <returns>返回,成功:true,失败:false</returns> public int Insert(ShareProfit entity) { return(dal.Insert(entity)); }