|  | @@ -3004,11 +3004,11 @@ Order By Count Desc");
 | 
	
		
			
				|  |  |                                                                  .CreateRedisRepository()
 | 
	
		
			
				|  |  |                                                                  .StringGetAsync<List<int>>("DailypaymentTypeData") ?? new List<int>();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                var _view = await _sqlSugar.Queryable<DailypaymentParentTypeView>()
 | 
	
		
			
				|  |  | -                                           .Includes(x => x.SubData)
 | 
	
		
			
				|  |  | -                                           .Where(x => defaultParentIds.Contains(x.Id))
 | 
	
		
			
				|  |  | -                                           .ToListAsync();
 | 
	
		
			
				|  |  | -                _view.ForEach(x =>
 | 
	
		
			
				|  |  | +                var dailyTypeData = await _sqlSugar.Queryable<DailypaymentParentTypeView>()
 | 
	
		
			
				|  |  | +                                                   .Includes(x => x.SubData)
 | 
	
		
			
				|  |  | +                                                   .Where(x => defaultParentIds.Contains(x.Id))
 | 
	
		
			
				|  |  | +                                                   .ToListAsync();
 | 
	
		
			
				|  |  | +                dailyTypeData.ForEach(x =>
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  |                      x.SubData.ForEach(y =>
 | 
	
		
			
				|  |  |                      {
 | 
	
	
		
			
				|  | @@ -3017,7 +3017,13 @@ Order By Count Desc");
 | 
	
		
			
				|  |  |                      });
 | 
	
		
			
				|  |  |                  });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                return Ok(JsonView(true, "查询成功!", _view, _view.Count));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                var companyData = await _sqlSugar.Queryable<Sys_Company>()
 | 
	
		
			
				|  |  | +                                                 .Where(x => x.IsDel == 0)
 | 
	
		
			
				|  |  | +                                                 .Select(x => new { id = x.Id, name = x.CompanyName })
 | 
	
		
			
				|  |  | +                                                 .ToListAsync();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                return Ok(JsonView(true, "查询成功!", new { dailyTypeData = dailyTypeData, companyData = companyData }));
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              else
 | 
	
		
			
				|  |  |              {
 | 
	
	
		
			
				|  | @@ -3123,14 +3129,15 @@ Select
 | 
	
		
			
				|  |  |  	c.CompanyName,
 | 
	
		
			
				|  |  |  	dfp.CreateUserId As ApplicantId,
 | 
	
		
			
				|  |  |  	u.CnName As Applicant,
 | 
	
		
			
				|  |  | -	dfp.CreateTime As ApplicantDt
 | 
	
		
			
				|  |  | +	dfp.CreateTime As ApplicantDt,
 | 
	
		
			
				|  |  | +	dfp.Instructions+u.CnName As ViewStr
 | 
	
		
			
				|  |  |  From Fin_DailyFeePayment dfp  
 | 
	
		
			
				|  |  |  Left Join Sys_Users u On dfp.CreateUserId = u.Id 
 | 
	
		
			
				|  |  |  Left Join Sys_SetData sd1 On dfp.TransferTypeId = sd1.Id
 | 
	
		
			
				|  |  |  Left Join Sys_Company c On dfp.CompanyId = c.Id
 | 
	
		
			
				|  |  |  Left Join Sys_SetData sd2 On dfp.PriceTypeId = sd2.Id
 | 
	
		
			
				|  |  |  Where dfp.IsDel = 0 And dfp.IsPay = 1
 | 
	
		
			
				|  |  | -",sqlWhere);//--Order By dfp.CreateTime Desc
 | 
	
		
			
				|  |  | +", sqlWhere);//--Order By dfp.CreateTime Desc
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |                  
 | 
	
		
			
				|  |  |                  if (_dto.Type == 1) //data
 | 
	
	
		
			
				|  | @@ -3140,6 +3147,8 @@ Where dfp.IsDel = 0 And dfp.IsPay = 1
 | 
	
		
			
				|  |  |                                                 .Where(x => x.ApplicantDt >= _beginDt && x.ApplicantDt <= _endDt)
 | 
	
		
			
				|  |  |                                                 .WhereIF(dailypaymentTypeData.Count > 0,
 | 
	
		
			
				|  |  |                                                          x => dailypaymentTypeData.Contains(x.PriceTypeId))
 | 
	
		
			
				|  |  | +                                               .WhereIF(_dto.CompanyIds.Count > 0, x => _dto.CompanyIds.Contains(x.CompanyId))
 | 
	
		
			
				|  |  | +                                               .WhereIF(!string.IsNullOrEmpty(_dto.Filter), x => x.ViewStr.Contains(_dto.Filter))
 | 
	
		
			
				|  |  |                                                 .OrderByDescending(x => x.ApplicantDt)
 | 
	
		
			
				|  |  |                                                 .ToPageListAsync(
 | 
	
		
			
				|  |  |                                                      pageNumber: _dto.PageIndex,
 | 
	
	
		
			
				|  | @@ -3154,7 +3163,9 @@ Where dfp.IsDel = 0 And dfp.IsPay = 1
 | 
	
		
			
				|  |  |                                                .ToList();
 | 
	
		
			
				|  |  |                      });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    return Ok(JsonView(true, "操作成功!", new { data = _view ,total = _view.Sum(x => x.SumPrice) }  , total));
 | 
	
		
			
				|  |  | +                    //单独处理
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    return Ok(JsonView(true, "操作成功!", new { data = _view, total = _view.Sum(x => x.SumPrice) }, total));
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  else if (_dto.Type == 2) //view
 | 
	
		
			
				|  |  |                  {
 | 
	
	
		
			
				|  | @@ -3162,6 +3173,8 @@ Where dfp.IsDel = 0 And dfp.IsPay = 1
 | 
	
		
			
				|  |  |                                                 .Where(x => x.ApplicantDt >= _beginDt && x.ApplicantDt <= _endDt)
 | 
	
		
			
				|  |  |                                                 .WhereIF(dailypaymentTypeData.Count > 0,
 | 
	
		
			
				|  |  |                                                          x => dailypaymentTypeData.Contains(x.PriceTypeId))
 | 
	
		
			
				|  |  | +                                               .WhereIF(_dto.CompanyIds.Count > 0, x => _dto.CompanyIds.Contains(x.CompanyId))
 | 
	
		
			
				|  |  | +                                               .WhereIF(!string.IsNullOrEmpty(_dto.Filter), x => x.ViewStr.Contains(_dto.Filter))
 | 
	
		
			
				|  |  |                                                 .OrderByDescending(x => x.ApplicantDt)
 | 
	
		
			
				|  |  |                                                 .ToPageListAsync(
 | 
	
		
			
				|  |  |                                                      pageNumber: 1,
 | 
	
	
		
			
				|  | @@ -3217,6 +3230,181 @@ Where dfp.IsDel = 0 And dfp.IsPay = 1
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        #endregion
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        #region 统计模块
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        /// <summary>
 | 
	
		
			
				|  |  | +        ///  同比
 | 
	
		
			
				|  |  | +        ///  营业额(今年和去年的)、成本支出(今年和去年的)、毛利润(今年和去年的)
 | 
	
		
			
				|  |  | +        /// </summary>
 | 
	
		
			
				|  |  | +        /// <param name="_dto">市场部销售额请求dto</param>
 | 
	
		
			
				|  |  | +        /// <returns></returns>
 | 
	
		
			
				|  |  | +        [HttpPost("StatisticsYOY")]
 | 
	
		
			
				|  |  | +        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
 | 
	
		
			
				|  |  | +        public async Task<IActionResult> StatisticsYOY(YOYDto _dto)
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            if (_dto.Year < 1) return Ok(JsonView(false,"操作失败"));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            string thisBeginDt = $"{_dto.Year}-01-01 00:00:00",
 | 
	
		
			
				|  |  | +                   thisEndDt = $"{_dto.Year}-12-31 23:59:59";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            string lastBeginDt = $"{_dto.Year - 1}-01-01 00:00:00",
 | 
	
		
			
				|  |  | +                   lastEndDt = $"{_dto.Year - 1}-12-31 23:59:59";
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            #region 营业额
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            string thisSql = string.Format(@"
 | 
	
		
			
				|  |  | +SELECT
 | 
	
		
			
				|  |  | +  di.Id,
 | 
	
		
			
				|  |  | +  di.VisitDate,
 | 
	
		
			
				|  |  | +  YEAR(di.VisitDate) AS Year,
 | 
	
		
			
				|  |  | +  MONTH(di.VisitDate) AS Month,
 | 
	
		
			
				|  |  | +  (
 | 
	
		
			
				|  |  | +    SELECT
 | 
	
		
			
				|  |  | +      CAST(SUM(ItemSumPrice * Rate) AS DECIMAL(12, 2))
 | 
	
		
			
				|  |  | +    FROM
 | 
	
		
			
				|  |  | +      Fin_ForeignReceivables
 | 
	
		
			
				|  |  | +    WHERE
 | 
	
		
			
				|  |  | +      IsDel = 0
 | 
	
		
			
				|  |  | +      AND AddingWay IN (0, 1, 2)
 | 
	
		
			
				|  |  | +      AND di.Id = Diid
 | 
	
		
			
				|  |  | +  ) AS Amount
 | 
	
		
			
				|  |  | +FROM
 | 
	
		
			
				|  |  | +  Grp_DelegationInfo di
 | 
	
		
			
				|  |  | +WHERE
 | 
	
		
			
				|  |  | +  di.IsDel = 0
 | 
	
		
			
				|  |  | +  AND di.IsSure = 1
 | 
	
		
			
				|  |  | +  AND di.VisitDate BETWEEN '{0}' AND '{1}'
 | 
	
		
			
				|  |  | +", thisBeginDt,thisEndDt);
 | 
	
		
			
				|  |  | +            string lastSql = string.Format(@"
 | 
	
		
			
				|  |  | +SELECT
 | 
	
		
			
				|  |  | +  di.Id,
 | 
	
		
			
				|  |  | +  di.VisitDate,
 | 
	
		
			
				|  |  | +  YEAR(di.VisitDate) AS YEAR,
 | 
	
		
			
				|  |  | +  MONTH(di.VisitDate) AS MONTH,
 | 
	
		
			
				|  |  | +  (
 | 
	
		
			
				|  |  | +    SELECT
 | 
	
		
			
				|  |  | +      CAST(SUM(ItemSumPrice * Rate) AS DECIMAL(12, 2))
 | 
	
		
			
				|  |  | +    FROM
 | 
	
		
			
				|  |  | +      Fin_ForeignReceivables
 | 
	
		
			
				|  |  | +    WHERE
 | 
	
		
			
				|  |  | +      IsDel = 0
 | 
	
		
			
				|  |  | +      AND AddingWay IN (0, 1, 2)
 | 
	
		
			
				|  |  | +      AND di.Id = Diid
 | 
	
		
			
				|  |  | +  ) AS Amount
 | 
	
		
			
				|  |  | +FROM
 | 
	
		
			
				|  |  | +  Grp_DelegationInfo di
 | 
	
		
			
				|  |  | +WHERE
 | 
	
		
			
				|  |  | +  di.IsDel = 0
 | 
	
		
			
				|  |  | +  AND di.IsSure = 1
 | 
	
		
			
				|  |  | +  AND di.VisitDate BETWEEN '{0}' AND '{1}'
 | 
	
		
			
				|  |  | +", lastBeginDt, lastEndDt);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +           var thisSalesData = _sqlSugar.SqlQueryable<SalesSqlView>(thisSql).ToList();
 | 
	
		
			
				|  |  | +           var lastSalesData = _sqlSugar.SqlQueryable<SalesSqlView>(lastSql).ToList();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            List<SalesReturnView> salesData = new List<SalesReturnView>();
 | 
	
		
			
				|  |  | +            int salesMonth = 1;
 | 
	
		
			
				|  |  | +            while (salesMonth < 13)
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                var thisMonthData = thisSalesData.Where(x => x.Month == salesMonth).ToList();
 | 
	
		
			
				|  |  | +                var lastMonthData = lastSalesData.Where(x => x.Month == salesMonth).ToList();
 | 
	
		
			
				|  |  | +                decimal thisMonthSales = thisMonthData.Sum(x => x?.Amount ?? 0);
 | 
	
		
			
				|  |  | +                var thisIds = thisMonthData.Select(x => x.Id).ToList();
 | 
	
		
			
				|  |  | +                decimal lastMonthSales = lastMonthData.Sum(x => x?.Amount ?? 0);
 | 
	
		
			
				|  |  | +                var lastIds = lastMonthData.Select(x => x.Id).ToList();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                salesData.Add(new SalesReturnView( _dto.Year,salesMonth, thisMonthSales, lastMonthSales, thisIds, lastIds) );
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                salesMonth++;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            #endregion
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            #region 团组成本
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            string thisCostSql = string.Format(@"
 | 
	
		
			
				|  |  | +SELECT
 | 
	
		
			
				|  |  | +  di.Id,
 | 
	
		
			
				|  |  | +  di.VisitDate,
 | 
	
		
			
				|  |  | +  YEAR(di.VisitDate) AS YEAR,
 | 
	
		
			
				|  |  | +  MONTH(di.VisitDate) AS MONTH,
 | 
	
		
			
				|  |  | +  (
 | 
	
		
			
				|  |  | +    SELECT
 | 
	
		
			
				|  |  | +      CAST(SUM(PayMoney * DayRate) AS DECIMAL(12, 2))
 | 
	
		
			
				|  |  | +    FROM
 | 
	
		
			
				|  |  | +      Grp_CreditCardPayment
 | 
	
		
			
				|  |  | +    WHERE
 | 
	
		
			
				|  |  | +      IsDel = 0
 | 
	
		
			
				|  |  | +      AND di.Id = Diid
 | 
	
		
			
				|  |  | +      AND CTable IN(98, 81, 79, 85, 76, 80, 82)
 | 
	
		
			
				|  |  | +      AND IsPay = 1
 | 
	
		
			
				|  |  | +  ) AS Amount
 | 
	
		
			
				|  |  | +FROM
 | 
	
		
			
				|  |  | +  Grp_DelegationInfo di
 | 
	
		
			
				|  |  | +WHERE
 | 
	
		
			
				|  |  | +  di.IsDel = 0
 | 
	
		
			
				|  |  | +  AND di.IsSure = 1
 | 
	
		
			
				|  |  | +  AND di.VisitDate BETWEEN '{0}' AND '{1}'
 | 
	
		
			
				|  |  | +", thisBeginDt, thisEndDt);
 | 
	
		
			
				|  |  | +            string lastCostSql = string.Format(@"
 | 
	
		
			
				|  |  | +SELECT
 | 
	
		
			
				|  |  | +  di.Id,
 | 
	
		
			
				|  |  | +  di.VisitDate,
 | 
	
		
			
				|  |  | +  YEAR(di.VisitDate) AS YEAR,
 | 
	
		
			
				|  |  | +  MONTH(di.VisitDate) AS MONTH,
 | 
	
		
			
				|  |  | +  (
 | 
	
		
			
				|  |  | +    SELECT
 | 
	
		
			
				|  |  | +      CAST(SUM(PayMoney * DayRate) AS DECIMAL(12, 2))
 | 
	
		
			
				|  |  | +    FROM
 | 
	
		
			
				|  |  | +      Grp_CreditCardPayment
 | 
	
		
			
				|  |  | +    WHERE
 | 
	
		
			
				|  |  | +      IsDel = 0
 | 
	
		
			
				|  |  | +      AND di.Id = Diid
 | 
	
		
			
				|  |  | +      AND CTable IN(98, 81, 79, 85, 76, 80, 82)
 | 
	
		
			
				|  |  | +      AND IsPay = 1
 | 
	
		
			
				|  |  | +  ) AS Amount
 | 
	
		
			
				|  |  | +FROM
 | 
	
		
			
				|  |  | +  Grp_DelegationInfo di
 | 
	
		
			
				|  |  | +WHERE
 | 
	
		
			
				|  |  | +  di.IsDel = 0
 | 
	
		
			
				|  |  | +  AND di.IsSure = 1
 | 
	
		
			
				|  |  | +  AND di.VisitDate BETWEEN '{0}' AND '{1}'
 | 
	
		
			
				|  |  | +", lastBeginDt, lastEndDt);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            var thisCostData = _sqlSugar.SqlQueryable<SalesSqlView>(thisCostSql).ToList();
 | 
	
		
			
				|  |  | +            var lastCostData = _sqlSugar.SqlQueryable<SalesSqlView>(lastCostSql).ToList();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            List<SalesReturnView> costData = new List<SalesReturnView>();
 | 
	
		
			
				|  |  | +            int costMonth = 1;
 | 
	
		
			
				|  |  | +            while (costMonth < 13)
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                var thisMonthData = thisSalesData.Where(x => x.Month == costMonth).ToList();
 | 
	
		
			
				|  |  | +                var lastMonthData = lastSalesData.Where(x => x.Month == costMonth).ToList();
 | 
	
		
			
				|  |  | +                decimal thisMonthSales = thisMonthData.Sum(x => x?.Amount ?? 0);
 | 
	
		
			
				|  |  | +                var thisIds = thisMonthData.Select(x => x.Id).ToList();
 | 
	
		
			
				|  |  | +                decimal lastMonthSales = lastMonthData.Sum(x => x?.Amount ?? 0);
 | 
	
		
			
				|  |  | +                var lastIds = lastMonthData.Select(x => x.Id).ToList();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                costData.Add(new SalesReturnView(_dto.Year, costMonth, thisMonthSales, lastMonthSales, thisIds, lastIds));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                costMonth++;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            #endregion
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            return Ok(JsonView(true,"操作成功!", new { SalesData = salesData,CostData = costData }));
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          #endregion
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |