PlatformDataService.Commerce.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. IFNULL(SUM(Price),0)
  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. IFNULL(SUM(Price),0)
  42. FROM
  43. tede_order
  44. WHERE
  45. IsVip = 1 and CreatedDate>'{nowTime}') AS VipAmount,
  46. (SELECT
  47. COUNT(1)
  48. FROM
  49. tede_order
  50. WHERE
  51. IsVip = 1 and CreatedDate>'{nowTime}') AS VipOrderCount";
  52. var connectionString = ConfigHelper.GetValue("Database:ConnectionString");
  53. var database = new Database(DatabaseType.MySql, connectionString);
  54. var connection = database.GetConnection();
  55. return await connection.QueryFirstAsync<PlatformCommerceResult>(sql);
  56. }
  57. }
  58. }