소스 검색

1、市场部销售额 整合接口(团组列表、客户类型、客户等级、接单排名)

amigotrip 11 달 전
부모
커밋
0653fbd101
1개의 변경된 파일171개의 추가작업 그리고 6개의 파일을 삭제
  1. 171 6
      OASystem/OASystem.Api/Controllers/StatisticsController.cs

+ 171 - 6
OASystem/OASystem.Api/Controllers/StatisticsController.cs

@@ -2476,11 +2476,20 @@ FROM
             }
             else
             {
-                return Ok(JsonView(true, "操作成功!", new
+                if (_dto.PortType == 2 || _dto.PortType == 3)
                 {
-                    customerTypeData = new List<object> { },
-                    clientGradeData = new List<object> { }
-                }));
+                    return Ok(JsonView(true, "操作成功!", new List<object> { }));
+                }
+                else
+                {
+                    return Ok(JsonView(true, "操作成功!", new
+                    {
+                        customerTypeData = new List<object> { },
+                        clientGradeData = new List<object> { }
+                    }));
+                }
+
+                
             }
 
             string sql = "";
@@ -2526,7 +2535,6 @@ And VisitDate Between '{beginDt}' And  '{endDt}'
 Group By [Name]
 Order By Count Desc");
 
-
                 var customerTypeData = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql1).ToListAsync();
 
                 string sql2 = string.Format(@$"Select 
@@ -2606,7 +2614,6 @@ Order By Count Desc");
 	And VisitDate Between '{beginDt}' And  '{endDt}'
 	Group By CnName");
 
-
             RefAsync<int> total = 0;
 
             var rankingData = await _sqlSugar.SqlQueryable<MarketingSalesOrderRankingView>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
@@ -2614,6 +2621,164 @@ Order By Count Desc");
             return Ok(JsonView(true, "操作成功!", rankingData, total));
         }
 
+
+        /// <summary>
+        ///  市场部销售额
+        ///  团组列表、客户类型、客户等级、接单排名
+        ///  (增加团组查询条件 IsSure=1)
+        /// </summary>
+        /// <param name="_dto">市场部销售额请求dto</param>
+        /// <returns></returns>
+        [HttpPost("PostMarketingSalesGroupItem")]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> PostMarketingSalesGroupItem(MarketingSalesGroupListDto _dto)
+        {
+            #region  参数验证
+
+            MarketingSalesStatisticsDtoFoalidator validationRules = new MarketingSalesStatisticsDtoFoalidator();
+            var validResult = await validationRules.ValidateAsync(_dto);
+            if (!validResult.IsValid)
+            {
+                var errors = new StringBuilder();
+                foreach (var error in validResult.Errors) errors.AppendLine(error.ErrorMessage);
+                return Ok(JsonView(false, errors.ToString()));
+            }
+
+            PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
+
+            #region 页面操作权限验证
+            pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(_dto.UserId, _dto.PageId);
+
+            if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, MsgTips.CheckAuth));
+            #endregion
+
+            #endregion
+
+            string userSql = "";
+            List<int> userIds = new List<int>();
+            userIds = await GetUserIds(_dto.CompanyId, _dto.GroupPickupUserId);
+
+            if (userIds.Count <= 0)
+            {
+                return Ok(JsonView(true, "操作成功!", new List<object> { }, 0));
+            }
+            else userSql = @$" And di.JietuanOperator In ({string.Join(",", userIds)})";
+
+
+            if (!string.IsNullOrEmpty(_dto.SearchCriteria))
+            {
+                userSql += string.Format(@$" AND di.TeamName Like '%{_dto.SearchCriteria}%'");
+            }
+
+            string beginDt = $"{_dto.BeginDt} 00:00:00", endDt = $"{_dto.EndDt} 23:59:59";
+
+
+            #region 团组List
+
+            string sql = string.Format(@$"SELECT
+  ROW_NUMBER() OVER (
+    ORDER BY
+      CollectionDays
+  ) AS RowNumber,
+  *
+FROM
+  (
+    SELECT
+      di.Id,
+      di.TeamName,
+      di.ClientUnit,
+      di.ClientName,
+      di.VisitDate,
+      di.VisitPNumber,
+      di.JietuanOperator,
+      di.VisitEndDate,
+      (
+        SELECT
+          CAST(
+            COALESCE(SUM(ItemSumPrice * Rate), 0) AS DECIMAL(12, 2)
+          ) AS GroupSales
+        FROM
+          Fin_ForeignReceivables
+        WHERE
+          IsDel = 0
+          AND di.Id = Diid
+          AND AddingWay IN (0, 1, 2)
+      ) AS GroupSales,
+      u.CnName AS GroupPickupUser,
+      DATEADD(DAY, 7, di.VisitEndDate) AS CollectionDays
+    FROM
+      Grp_DelegationInfo di
+    WITH
+      (NoLock)
+      LEFT JOIN Sys_Users u ON di.JietuanOperator = u.Id
+    WHERE
+      di.Isdel = 0
+	  AND di.IsSure = 1 {userSql} 
+      AND VisitDate Between '{beginDt}' And  '{endDt}'
+  ) Temp ");
+            RefAsync<int> total = 0;
+            var groupData = await _sqlSugar.SqlQueryable<MarketingSalesGroupList>(sql).ToPageListAsync(_dto.PageIndex, _dto.PageSize, total);
+            #endregion
+
+            #region 客户类型、客户等级 统计
+
+            string sql1 = string.Format(@$"Select 
+	sd.[Name],
+	Count(*) As [Count]
+From Grp_DelegationInfo di
+Left Join Sys_SetData sd On di.TeamDid = sd.Id
+Where di.Isdel = 0 
+And IsSure = 1 {userSql} 
+And VisitDate Between '{beginDt}' And  '{endDt}'
+Group By [Name]
+Order By Count Desc");
+
+            var customerTypeData = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql1).ToListAsync();
+
+            string sql2 = string.Format(@$"Select 
+	sd.[Name],
+	Count(*) As [Count]
+From Grp_DelegationInfo di
+Left Join Sys_SetData sd On di.TeamLevSId = sd.Id
+Where di.Isdel = 0 
+And IsSure = 1 {userSql} 
+And VisitDate Between '{beginDt}' And  '{endDt}'
+Group By [Name]
+Order By Count Desc");
+            var clientGradeData = await _sqlSugar.SqlQueryable<MarketingSalesGroupStatisticsView>(sql2).ToListAsync();
+            #endregion
+
+            #region 接单排名
+
+            string sql4 = string.Format(@$"Select 
+	ROW_NUMBER() Over(Order By Count(*) Desc) As RowNumber,
+	u.CnName As UserName,
+	Count(*) As [Count]
+	From Grp_DelegationInfo di
+	Left Join Sys_Users u On di.JietuanOperator = u.Id
+	Where di.Isdel = 0 
+    AND IsSure = 1 {userSql} 
+	And VisitDate Between '{beginDt}' And  '{endDt}'
+	Group By CnName");
+
+            var rankingData = await _sqlSugar.SqlQueryable<MarketingSalesOrderRankingView>(sql4).ToListAsync();
+
+            #endregion
+
+            var viewData = new {
+                groupData = groupData,
+                groupTotal = total,
+                customerTypeData = customerTypeData,
+                clientGradeData = clientGradeData,
+                rankingData = rankingData
+            };
+
+
+            return Ok(JsonView(true, "操作成功!", viewData, total));
+        }
+
+
+
         /// <summary>
         ///  市场部销售额
         ///  客户拜访列表