李昊 4 anni fa
parent
commit
137ad88cae

+ 5 - 5
gx_api/GxPress/Api/GxPress.Api/AdminControllers/AdminPlatformDataController.cs

@@ -34,13 +34,13 @@ namespace GxPress.Api.AdminControllers
             result.UserVipProportionResult = await platformDataService.GetUserVipProportionResult();
             result.OnlineUserResult = await platformDataService.GetOnlineUserResult();
             result.PlatformContentDataResult = await platformDataService.GetPlatformContentDataResult();
-            result.ContentTypeDistributingResult = new List<ContentTypeDistributingResult>();
+            result.ContentTypeDistributingResult = await platformDataService.GetContentTypeDistributingResults();
             result.ContentOlogyDistributingResult = new List<ContentOlogyDistributingResult>();
-            result.PayContentstatisticsResult = new PayContentstatisticsResult();
-            result.ContentIncreaseResult = new ContentIncreaseResult();
-            result.PlatformAccumulativeVisitResult = new PlatformAccumulativeVisitResult();
+            result.PayContentstatisticsResult = await platformDataService.GetPayContentstatisticsResult();
+            result.ContentIncreaseResult = await platformDataService.GetContentIncreaseResult();
+            result.PlatformAccumulativeVisitResult = await platformDataService.GetPlatformAccumulativeVisitResult();
             result.VisitPortResult = new List<VisitPortResult>();
-            result.PlatformCommerceResult = new PlatformCommerceResult();
+            result.PlatformCommerceResult =await platformDataService.GetPlatformCommerceResult();
             result.ContentSaleRankingResults = new List<ContentSaleRankingResult>();
             result.ContentSaleProportionResults = new List<ContentSaleProportionResult>();
             return result;

+ 6 - 0
gx_api/GxPress/Model/GxPress.Entity/Order/Order.cs

@@ -74,5 +74,11 @@ namespace GxPress.Entity.Order
         /// <value></value>
         [DataColumn]
         public int OrderType { get; set; }
+        /// <summary>
+        /// 是否会员支付
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public bool IsVip { get; set; }
     }
 }

+ 10 - 10
gx_api/GxPress/Model/GxPress.EnumConst/VipTypeConst.cs

@@ -42,22 +42,22 @@ namespace GxPress.EnumConst
         AliyPay = 2
     }
     /// <summary>
-    /// 资源类型 文章、书籍、视频、音频、期刊
+    /// 资源类型 文章100书籍20,课程30,音频40,期刊50,视频60,名栏90,公众号110,刊期120
     /// </summary>
     public enum ResourceTypeConst
     {
         [Description("文章")]
-        Article = 1,
+        Article = 100,
         [Description("书籍")]
-        Book = 2,
+        Book = 20,
         [Description("课程")]
-        Curriculum = 3,
+        Curriculum = 30,
         [Description("音频")]
-        Audio = 4,
+        Audio = 40,
         [Description("期刊")]
-        Journal = 5,
+        Journal = 50,
         [Description("视频")]
-        Video = 6
+        Video = 60
 
     }
     /// <summary>
@@ -66,10 +66,10 @@ namespace GxPress.EnumConst
     public enum AttachTypeConst
     {
         [Description("名栏")]
-        StarColumn = 1,
+        StarColumn = 90,
         [Description("公众号")]
-        PublicNumber = 2,
+        PublicNumber = 110,
         [Description("刊期")]
-        Magazine = 3
+        Magazine = 120
     }
 }

+ 5 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/Media/MediaRepository.cs

@@ -300,5 +300,10 @@ namespace GxPress.Repository.Implement.Media
 
             return true;
         }
+        public async Task<int> CountAsync(string beginTime, string endTime)
+        {
+            return await _repository.CountAsync(Q.WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), ">=", beginTime).WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), "<=", endTime));
+
+        }
     }
 }

+ 1 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/Media/IMediaRepository.cs

@@ -26,5 +26,6 @@ namespace GxPress.Repository.Interface.Media
        Task<bool> UpdateAsync(SqlKata.Query query);
 
         Task<PagedList<Entity.tede2.Media.Media>> GetAllAsync(MediaSearchRequest request);
+        Task<int> CountAsync(string beginTime, string endTiem);
     }
 }

+ 145 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/PlatformData/PlatformDataService.cs

@@ -5,7 +5,9 @@ using System.Threading.Tasks;
 using Dapper;
 using Datory;
 using GxPress.Common.Tools;
+using GxPress.EnumConst;
 using GxPress.Repository.Interface;
+using GxPress.Repository.Interface.Media;
 using GxPress.Result.DataCenter;
 using GxPress.Service.Interface.PlatformData;
 
@@ -15,10 +17,13 @@ namespace GxPress.Service.Implement.PlatformData
     {
         private readonly IUserRepository userRepository;
 
-        public PlatformDataService(IUserRepository userRepository)
+        private readonly IMediaRepository mediaRepository;
+
+        public PlatformDataService(IUserRepository userRepository, IMediaRepository mediaRepository)
         {
 
             this.userRepository = userRepository;
+            this.mediaRepository = mediaRepository;
         }
         /// <summary>
         /// 平台运营数据
@@ -170,5 +175,144 @@ namespace GxPress.Service.Implement.PlatformData
                                 FreeProportion>0) AS PayContentCount";
             return await connection.QueryFirstAsync<PlatformContentDataResult>(sql);
         }
+        /// <summary>
+        /// 内容类型分布图
+        /// </summary>
+        /// <returns></returns>
+        public async Task<List<ContentTypeDistributingResult>> GetContentTypeDistributingResults()
+        {
+            var result = new List<ContentTypeDistributingResult>();
+            var connectionString = ConfigHelper.GetValue("Database:ConnectionString");
+            var database = new Database(DatabaseType.MySql, connectionString);
+            var connection = database.GetConnection();
+            foreach (ResourceTypeConst item in Enum.GetValues(typeof(ResourceTypeConst)))
+            {
+                var model = new ContentTypeDistributingResult();
+                model.Name = item.GetDescriptionOriginal();
+
+                var sql = $"select count(1) from tede_media where MediaType={item.GetHashCode()}";
+                model.Value = await connection.ExecuteScalarAsync<int>(sql);
+                result.Add(model);
+            }
+            foreach (ResourceTypeConst item in Enum.GetValues(typeof(AttachTypeConst)))
+            {
+                var model = new ContentTypeDistributingResult();
+                model.Name = item.GetDescriptionOriginal();
+                var sql = $"select count(1) from tede_media where AttachId={item.GetHashCode()}";
+                model.Value = await connection.ExecuteScalarAsync<int>(sql);
+                result.Add(model);
+            }
+            return result;
+        }
+        /// <summary>
+        /// 收费内容统计图
+        /// </summary>
+        /// <returns></returns>
+        public async Task<PayContentstatisticsResult> GetPayContentstatisticsResult()
+        {
+            var result = new PayContentstatisticsResult();
+            result.PageAdata = new List<int>();
+            result.PageBdata = new List<int>();
+            result.Title = new List<string>();
+            var connectionString = ConfigHelper.GetValue("Database:ConnectionString");
+            var database = new Database(DatabaseType.MySql, connectionString);
+            var connection = database.GetConnection();
+            foreach (ResourceTypeConst item in Enum.GetValues(typeof(ResourceTypeConst)))
+            {
+
+                result.Title.Add(item.GetDescriptionOriginal());
+                var sql = $"select count(1) from tede_media where MediaType={item.GetHashCode()} and FreeProportion>0";
+                result.PageAdata.Add(await connection.ExecuteScalarAsync<int>(sql));
+                sql = $"select count(1) from tede_media where MediaType={item.GetHashCode()} and FreeProportion=0";
+                result.PageBdata.Add(await connection.ExecuteScalarAsync<int>(sql));
+            }
+            foreach (ResourceTypeConst item in Enum.GetValues(typeof(AttachTypeConst)))
+            {
+                result.Title.Add(item.GetDescriptionOriginal());
+                var sql = $"select count(1) from tede_media where AttachId={item.GetHashCode()} and FreeProportion>0";
+                result.PageAdata.Add(await connection.ExecuteScalarAsync<int>(sql));
+                sql = $"select count(1) from tede_media where MediaType={item.GetHashCode()} and FreeProportion=0";
+
+                result.PageBdata.Add(await connection.ExecuteScalarAsync<int>(sql));
+            }
+            return result;
+        }
+        /// <summary>
+        /// 内容增长情况图
+        /// </summary>
+        /// <returns></returns>
+        public async Task<ContentIncreaseResult> GetContentIncreaseResult()
+        {
+            var result = new ContentIncreaseResult();
+            result.MonthData = new List<string>();
+            result.ExpectedData = new List<int>();
+            var nowTime = DateTime.Now;
+            for (int i = 0; i < 12; i++)
+            {
+                result.MonthData.Add(nowTime.AddMonths(-i).Month + "月");
+                result.ExpectedData.Add(await mediaRepository.CountAsync(nowTime.AddMonths(-i).ToString("yyyy-MM-01"), nowTime.AddMonths(-i + 1).ToString("yyyy-MM-01")));
+            }
+            return result;
+        }
+        /// <summary>
+        ///  平台累计访问数据(次)
+        /// </summary>
+        /// <returns></returns>
+        public async Task<PlatformAccumulativeVisitResult> GetPlatformAccumulativeVisitResult()
+        {
+
+            var sql = @"
+                        SELECT 
+                            (SELECT 
+                                    SUM(ReadCount)
+                                FROM
+                                    tede_media) AS VisitCount,
+                            (SELECT 
+                                    SUM(CommentCount)
+                                FROM
+                                    tede_media) AS CommentCount,
+                            (SELECT 
+                                    SUM(RetransmissionCount)
+                                FROM
+                                    tede_media) AS RetransmissionCount,
+                                    (SELECT 
+                                    SUM(CollectCount)
+                                FROM
+                                    tede_media) AS CollctionCount";
+            var connectionString = ConfigHelper.GetValue("Database:ConnectionString");
+            var database = new Database(DatabaseType.MySql, connectionString);
+            var connection = database.GetConnection();
+            return await connection.QueryFirstAsync<PlatformAccumulativeVisitResult>(sql);
+        }
+        /// <summary>
+        /// 平台商务数据
+        /// </summary>
+        /// <returns></returns>
+        public async Task<PlatformCommerceResult> GetPlatformCommerceResult()
+        {
+            var sql = @"SELECT 
+                        (SELECT 
+                                SUM(Price)
+                            FROM
+                                tede_order) AS Amount,
+                        (SELECT 
+                                COUNT(1)
+                            FROM
+                                tede_order) AS OrderCount,
+                        (SELECT 
+                                COUNT(1)
+                            FROM
+                                tede_user) AS VipUserCount,
+                        (SELECT 
+                                SUM(Price)
+                            FROM
+                                tede_order
+                            WHERE
+                                IsVip = 1) AS VipAmount";
+            var connectionString = ConfigHelper.GetValue("Database:ConnectionString");
+            var database = new Database(DatabaseType.MySql, connectionString);
+            var connection = database.GetConnection();
+            return await connection.QueryFirstAsync<PlatformCommerceResult>(sql);
+        }
     }
 }

+ 25 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/PlatformData/IPlatformDataService.cs

@@ -36,5 +36,30 @@ namespace GxPress.Service.Interface.PlatformData
         /// </summary>
         /// <returns></returns>
         Task<PlatformContentDataResult> GetPlatformContentDataResult();
+        /// <summary>
+        /// 内容类型分布图
+        /// </summary>
+        /// <returns></returns>
+        Task<List<ContentTypeDistributingResult>> GetContentTypeDistributingResults();
+        /// <summary>
+        /// 收费内容统计图
+        /// </summary>
+        /// <returns></returns>
+        Task<PayContentstatisticsResult> GetPayContentstatisticsResult();
+          /// <summary>
+        /// 内容增长情况图
+        /// </summary>
+        /// <returns></returns>
+        Task<ContentIncreaseResult> GetContentIncreaseResult();
+        /// <summary>
+        ///  平台累计访问数据(次)
+        /// </summary>
+        /// <returns></returns>
+        Task<PlatformAccumulativeVisitResult> GetPlatformAccumulativeVisitResult();
+        /// <summary>
+        /// 平台商务数据
+        /// </summary>
+        /// <returns></returns>
+        Task<PlatformCommerceResult> GetPlatformCommerceResult();
     }
 }