ApiReportCore.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. 
  2. using dodohold.core;
  3. using System.Text.Json;
  4. namespace molilian.core
  5. {
  6. public partial class ApiReportCore
  7. {
  8. public class RecordDTO
  9. {
  10. public int id { get; set; }
  11. public int data_type { get; set; }
  12. public DateTime report_date { get; set; }
  13. public int uclk_uv { get; set; } = 0;
  14. public int uclk_pv { get; set; } = 0;
  15. public int pay_ord_num { get; set; } = 0;
  16. public int order_ord_num { get; set; } = 0;
  17. public decimal pay_ord_amt { get; set; } = 0;
  18. public decimal pay_tk_disp_tfee { get; set; } = 0;
  19. public int pay_ord_uv { get; set; } = 0;
  20. public int eff_ord_num { get; set; } = 0;
  21. public decimal eff_ord_amt { get; set; } = 0;
  22. public decimal eff_tk_disp_tfee { get; set; } = 0;
  23. public int total_count { get; set; } = 0;
  24. public int abandon_count { get; set; } = 0;
  25. public int success_count { get; set; } = 0;
  26. public int req_other_aff_num { get; set; } = 0;
  27. public int req_goods_num { get; set; } = 0;
  28. public int req_live_num { get; set; } = 0;
  29. public int req_video_num { get; set; } = 0;
  30. public int req_shop_num { get; set; } = 0;
  31. public int req_base_num { get; set; } = 0;
  32. public int req_note_num { get; set; } = 0;
  33. public int resp_deeplink_num { get; set; } = 0;
  34. }
  35. public static async Task<List<dynamic>> ReportDailysAsync(JsonElement form, string clientIp, bool debug = false)
  36. {
  37. List<dynamic> list = [];
  38. //那就是入参日期和type
  39. //我们给出指定日期的:点击 付款 有效付款 转链API调用
  40. //type可以不入参,留空就两个场景的数据都显示就行了
  41. //先只要成功的就行了,,到时候他们要明细再加就行了
  42. int data_type = form.Read("type", 0);
  43. var report_date = form.PathReadArray<string>("query_date[]");
  44. DateTime stime = DateTime.Now.AddDays(-1).Date, etime = stime;
  45. if (report_date.Count == 2)
  46. {
  47. if (DateTime.TryParse(report_date[0], out stime) && DateTime.TryParse(report_date[1], out etime))
  48. {
  49. stime = stime.Date;
  50. etime = etime.Date;
  51. }
  52. }
  53. switch (data_type)
  54. {
  55. case 1:
  56. case 2:
  57. {
  58. var data = await DataTypeReportDailysAsync(data_type, stime, etime, clientIp, debug);
  59. list.AddRange(data);
  60. }
  61. break;
  62. default:
  63. {
  64. int[] types = { 1, 2 };
  65. foreach (var type in types)
  66. {
  67. var data = await DataTypeReportDailysAsync(type, stime, etime, clientIp, debug);
  68. list.AddRange(data);
  69. }
  70. }
  71. break;
  72. }
  73. return list;
  74. }
  75. public static async Task<List<dynamic>> DataTypeReportDailysAsync(int data_type, DateTime stime, DateTime etime, string clientIp, bool debug = false)
  76. {
  77. string filter = "`is_show`=@is_show AND data_type=@data_type AND report_date>=@stime AND report_date<=@etime";
  78. string orderBy = "report_date DESC";
  79. var list = new DBContext.Table("api_call_report_dailys")
  80. .Where(filter, new { is_show = true, data_type, stime, etime })
  81. .Order(orderBy)
  82. .Select<RecordDTO>().ToList();
  83. if (!debug)
  84. {
  85. if (list.Count != 0)
  86. {
  87. var ids = list.Select(o => o.id).ToList();
  88. new DBContext.Table("api_call_report_dailys")
  89. .Add("read_num:", "read_num+1")
  90. .Where("id IN @ids", new { ids })
  91. .Update();
  92. }
  93. }
  94. List<dynamic> data = list.Select(e => new
  95. {
  96. report_date = e.report_date.ToString("yyyy-MM-dd"),
  97. type = e.data_type,
  98. e.uclk_uv,
  99. e.uclk_pv,
  100. e.pay_ord_num,
  101. e.order_ord_num,
  102. e.pay_ord_amt,
  103. e.pay_tk_disp_tfee,
  104. e.pay_ord_uv,
  105. e.eff_ord_num,
  106. e.eff_ord_amt,
  107. e.eff_tk_disp_tfee,
  108. e.total_count,
  109. //e.abandon_count,
  110. e.success_count,
  111. e.req_other_aff_num,
  112. e.req_goods_num,
  113. e.req_live_num,
  114. e.req_video_num,
  115. e.req_shop_num,
  116. e.req_base_num,
  117. e.req_note_num,
  118. e.resp_deeplink_num
  119. }).ToList<dynamic>();
  120. return data;
  121. }
  122. }
  123. }