ApiReportCore.cs 4.3 KB

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