PlatformDataService.Commerce.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Threading.Tasks;
  3. using Dapper;
  4. using Datory;
  5. using GxPress.Common.Tools;
  6. using GxPress.Result.DataCenter;
  7. namespace GxPress.Service.Implement.PlatformData
  8. {
  9. public partial class PlatformDataService
  10. {
  11. /// <summary>
  12. /// 商务数据
  13. /// </summary>
  14. /// <returns></returns>
  15. public async Task<CommerceDataResult> GetCommerceDataResult()
  16. {
  17. var result = new CommerceDataResult();
  18. result.PlatformCommerceResult = await GetPlatformCommerceResult();
  19. result.ContentSaleRankingResults = await GetContentSaleRankingResults();
  20. result.ContentSaleProportionResults = await GetContentSaleProportionResults();
  21. result.PlatformTodayCommerceResult = await GetPlatformTodayCommerceResult();
  22. return result;
  23. }
  24. public async Task<PlatformCommerceResult> GetPlatformTodayCommerceResult()
  25. {
  26. var nowTime = DateTime.Now.ToString("yyyy-MM-dd");
  27. var sql = $@"SELECT
  28. (SELECT
  29. SUM(Price)
  30. FROM
  31. tede_order where CreatedDate>'{nowTime}') AS Amount,
  32. (SELECT
  33. COUNT(1)
  34. FROM
  35. tede_order where CreatedDate>'{nowTime}') AS OrderCount,
  36. (SELECT
  37. COUNT(1)
  38. FROM
  39. tede_user where CreatedDate>'{nowTime}') AS VipUserCount,
  40. (SELECT
  41. SUM(Price)
  42. FROM
  43. tede_order
  44. WHERE
  45. IsVip = 1 and CreatedDate>'{nowTime}') AS VipAmount";
  46. var connectionString = ConfigHelper.GetValue("Database: ConnectionString");
  47. var database = new Database(DatabaseType.MySql, connectionString);
  48. var connection = database.GetConnection();
  49. return await connection.QueryFirstAsync<PlatformCommerceResult>(sql);
  50. }
  51. }
  52. }