|
@@ -1173,7 +1173,6 @@ namespace OASystem.API.Controllers
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
-
|
|
|
#region 报表/折线图统计
|
|
|
//企业利润-团组利润
|
|
|
//企业利润-会务利润
|
|
@@ -2210,85 +2209,36 @@ namespace OASystem.API.Controllers
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
+ //TODO:sugar 报错
|
|
|
+ //Invalid attempt to call FieldCount when reader is closed
|
|
|
+ //Invalid operation.The connection is closed.
|
|
|
//今年销售额
|
|
|
string beginDt = $"{_dto.BeginDt} 00:00:00",endDt = $"{_dto.EndDt} 23:59:59";
|
|
|
- decimal thisYearSales = await GroupSales(_dto.CompanyId, _dto.GroupPickupUserId, beginDt, endDt);
|
|
|
-
|
|
|
- //去年销售额
|
|
|
- string lastYearBeginDt = $"{DateTime.Parse(_dto.BeginDt).AddYears(-1).ToString("yyyy-MM-dd")} 00:00:00";
|
|
|
- string lastYearEndDt = $"{DateTime.Parse(_dto.EndDt).AddYears(-1).ToString("yyyy-MM-dd")} 23:59:59";
|
|
|
- decimal lastYearSales = await GroupSales(_dto.CompanyId, _dto.GroupPickupUserId, lastYearBeginDt, lastYearEndDt);
|
|
|
-
|
|
|
- //同比
|
|
|
- decimal yoy = 0.00M;
|
|
|
- if (thisYearSales > 0.00M) yoy = (thisYearSales - lastYearSales) / lastYearSales;
|
|
|
+ var paras = new SugarParameter[]{
|
|
|
+ new SugarParameter("@companyId", _dto.CompanyId),
|
|
|
+ new SugarParameter("@groupPickupUserId", _dto.GroupPickupUserId),
|
|
|
+ new SugarParameter("@beginDt", beginDt),
|
|
|
+ new SugarParameter("@endDt", endDt),
|
|
|
+ new SugarParameter("@thisSales", null, true),
|
|
|
+ new SugarParameter("@lastSales", null, true),
|
|
|
+ new SugarParameter("@yoy", null, true)
|
|
|
+ };
|
|
|
+ var dt = await _sqlSugar.Ado.UseStoredProcedure().GetDataTableAsync("CalculateSales", paras);
|
|
|
+
|
|
|
+ decimal thisSales = 0.00M, lastSales = 0.00M, yoy = 0.00M;
|
|
|
+ if (dt.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ thisSales = decimal.Parse( dt.Rows[0]["ThisSales"].ToString() ?? "0.00");
|
|
|
+ lastSales = decimal.Parse(dt.Rows[0]["LastSales"].ToString() ?? "0.00");
|
|
|
+ yoy = decimal.Parse(dt.Rows[0]["YOY"].ToString() ?? "0.00");
|
|
|
+ }
|
|
|
|
|
|
return Ok(JsonView(true, "操作成功!", new {
|
|
|
- thisYearSales = decimal.Parse(thisYearSales.ToString("#0.00")),
|
|
|
- lastYearSales = decimal.Parse(lastYearSales.ToString("#0.00")),
|
|
|
+ thisYearSales = decimal.Parse(thisSales.ToString("#0.00")),
|
|
|
+ lastYearSales = decimal.Parse(lastSales.ToString("#0.00")),
|
|
|
yoy = decimal.Parse(yoy.ToString("#0.00")) }));
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 计算团组销售额
|
|
|
- /// </summary>
|
|
|
- /// <param name="companyId"></param>
|
|
|
- /// <param name="groupPickupUserId"></param>
|
|
|
- /// <param name="beginDt"></param>
|
|
|
- /// <param name="endDt"></param>
|
|
|
- /// <returns></returns>
|
|
|
- private async Task<decimal> GroupSales(int companyId,int groupPickupUserId,string beginDt,string endDt)
|
|
|
- {
|
|
|
- decimal sales = 0.00M;
|
|
|
- string userSqlWhere = "";
|
|
|
- if (companyId > 0) userSqlWhere += string.Format($" And CompanyId={companyId}");
|
|
|
- if (groupPickupUserId > 0) userSqlWhere += string.Format($" And Id={groupPickupUserId}");
|
|
|
- string sql = string.Format($@"SELECT
|
|
|
- SUM(Sales) AS Sales
|
|
|
-FROM
|
|
|
- (
|
|
|
- SELECT
|
|
|
- YEAR(di.VisitDate) AS [Year],
|
|
|
- (
|
|
|
- SELECT
|
|
|
- SUM(ItemSumPrice * Rate)
|
|
|
- FROM
|
|
|
- Fin_ForeignReceivables
|
|
|
- WHERE
|
|
|
- IsDel = 0
|
|
|
- AND AddingWay IN (0, 1, 2)
|
|
|
- AND di.Id = Diid
|
|
|
- ) AS Sales
|
|
|
- FROM
|
|
|
- Grp_DelegationInfo di
|
|
|
- WHERE
|
|
|
- di.IsDel = 0
|
|
|
- AND di.JietuanOperator IN (
|
|
|
- SELECT
|
|
|
- Id
|
|
|
- FROM
|
|
|
- Sys_Users
|
|
|
- WITH
|
|
|
- (NoLock)
|
|
|
- WHERE
|
|
|
- IsDel = 0 {userSqlWhere}
|
|
|
- )
|
|
|
- AND di.VisitDate BETWEEN '{beginDt}' AND '{endDt}'
|
|
|
- ) temp");
|
|
|
-
|
|
|
- var salesData = await _sqlSugar.SqlQueryable<SalesView>(sql).FirstAsync();
|
|
|
-
|
|
|
- sales = salesData?.Sales ?? 0.00M;
|
|
|
-
|
|
|
- return sales;
|
|
|
- }
|
|
|
-
|
|
|
- private class SalesView
|
|
|
- {
|
|
|
- public decimal Sales { get; set; }
|
|
|
- }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 市场部销售额
|