ApiReportCore.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 distributiontype = form.Read("distributiontype", 0);
  43. int data_type = form.Read("type", 0);
  44. var report_date = form.PathReadArray<string>("query_date[]");
  45. DateTime stime = DateTime.Now.AddDays(-1).Date, etime = stime;
  46. if (report_date.Count == 2)
  47. {
  48. if (DateTime.TryParse(report_date[0], out stime) && DateTime.TryParse(report_date[1], out etime))
  49. {
  50. stime = stime.Date;
  51. etime = etime.Date;
  52. }
  53. }
  54. switch (data_type)
  55. {
  56. case 1:
  57. case 2:
  58. {
  59. var data = await DataTypeReportDailysAsync(distributiontype, data_type, stime, etime, clientIp, debug);
  60. list.AddRange(data);
  61. }
  62. break;
  63. default:
  64. {
  65. int[] types = { 1, 2 };
  66. foreach (var type in types)
  67. {
  68. var data = await DataTypeReportDailysAsync(distributiontype, type, stime, etime, clientIp, debug);
  69. list.AddRange(data);
  70. }
  71. }
  72. break;
  73. }
  74. return list;
  75. }
  76. public static async Task<List<dynamic>> DataTypeReportDailysAsync(int distributiontype, int data_type, DateTime stime, DateTime etime, string clientIp, bool debug = false)
  77. {
  78. string filter = "`is_show`=@is_show AND data_type=@data_type AND report_date>=@stime AND report_date<=@etime";
  79. string orderBy = "report_date DESC";
  80. var list = new DBContext.Table("api_call_report_dailys")
  81. .Where(filter, new { is_show = true, data_type, stime, etime })
  82. .Order(orderBy)
  83. .Select<RecordDTO>().ToList();
  84. if (!debug)
  85. {
  86. if (list.Count != 0)
  87. {
  88. var ids = list.Select(o => o.id).ToList();
  89. new DBContext.Table("api_call_report_dailys")
  90. .Add("read_num:", "read_num+1")
  91. .Where("id IN @ids", new { ids })
  92. .Update();
  93. }
  94. }
  95. //List<dynamic> data = list.Select(e => new
  96. //{
  97. // report_date = e.report_date.ToString("yyyy-MM-dd"),
  98. // type = e.data_type,
  99. // e.uclk_uv,
  100. // e.uclk_pv,
  101. // e.pay_ord_num,
  102. // e.order_ord_num,
  103. // e.pay_ord_amt,
  104. // e.pay_tk_disp_tfee,
  105. // e.pay_ord_uv,
  106. // e.eff_ord_num,
  107. // e.eff_ord_amt,
  108. // e.eff_tk_disp_tfee,
  109. // e.total_count,
  110. // //e.abandon_count,
  111. // e.success_count,
  112. // e.req_other_aff_num,
  113. // e.req_goods_num,
  114. // e.req_live_num,
  115. // e.req_video_num,
  116. // e.req_shop_num,
  117. // e.req_base_num,
  118. // e.req_note_num,
  119. // e.resp_deeplink_num
  120. //}).ToList<dynamic>();
  121. List<dynamic> data = list.SelectMany(e =>
  122. {
  123. var results = new List<dynamic>();
  124. if (distributiontype == 0 || distributiontype == 1) // 全分类或 goods
  125. {
  126. results.Add(new
  127. {
  128. //metric_type = "req_goods_num",
  129. //metric_value = e.req_goods_num,
  130. report_date = e.report_date.ToString("yyyy-MM-dd"),
  131. type = e.data_type,
  132. e.uclk_uv,
  133. e.uclk_pv,
  134. e.pay_ord_num,
  135. e.order_ord_num,
  136. e.pay_ord_amt,
  137. e.pay_tk_disp_tfee,
  138. e.pay_ord_uv,
  139. e.eff_ord_num,
  140. e.eff_ord_amt,
  141. e.eff_tk_disp_tfee,
  142. e.total_count,
  143. e.success_count,
  144. e.req_goods_num,
  145. e.resp_deeplink_num
  146. });
  147. }
  148. if (distributiontype == 0 || distributiontype == 2) // 全分类或 live
  149. {
  150. results.Add(new
  151. {
  152. report_date = e.report_date.ToString("yyyy-MM-dd"),
  153. type = e.data_type,
  154. e.uclk_uv,
  155. e.uclk_pv,
  156. e.pay_ord_num,
  157. e.order_ord_num,
  158. e.pay_ord_amt,
  159. e.pay_tk_disp_tfee,
  160. e.pay_ord_uv,
  161. e.eff_ord_num,
  162. e.eff_ord_amt,
  163. e.eff_tk_disp_tfee,
  164. e.total_count,
  165. e.success_count,
  166. e.req_live_num,
  167. e.resp_deeplink_num
  168. });
  169. }
  170. if (distributiontype == 0 || distributiontype == 3) // 全分类或 video
  171. {
  172. results.Add(new
  173. {
  174. report_date = e.report_date.ToString("yyyy-MM-dd"),
  175. type = e.data_type,
  176. e.uclk_uv,
  177. e.uclk_pv,
  178. e.pay_ord_num,
  179. e.order_ord_num,
  180. e.pay_ord_amt,
  181. e.pay_tk_disp_tfee,
  182. e.pay_ord_uv,
  183. e.eff_ord_num,
  184. e.eff_ord_amt,
  185. e.eff_tk_disp_tfee,
  186. e.total_count,
  187. e.success_count,
  188. e.req_video_num,
  189. e.resp_deeplink_num
  190. });
  191. }
  192. if (distributiontype == 0 || distributiontype == 4) // 全分类或 req_shop_num
  193. {
  194. results.Add(new
  195. {
  196. report_date = e.report_date.ToString("yyyy-MM-dd"),
  197. type = e.data_type,
  198. e.uclk_uv,
  199. e.uclk_pv,
  200. e.pay_ord_num,
  201. e.order_ord_num,
  202. e.pay_ord_amt,
  203. e.pay_tk_disp_tfee,
  204. e.pay_ord_uv,
  205. e.eff_ord_num,
  206. e.eff_ord_amt,
  207. e.eff_tk_disp_tfee,
  208. e.total_count,
  209. e.success_count,
  210. e.req_shop_num,
  211. e.resp_deeplink_num
  212. });
  213. }
  214. if (distributiontype == 0 || distributiontype == 5) // 全分类或 req_base_num
  215. {
  216. results.Add(new
  217. {
  218. report_date = e.report_date.ToString("yyyy-MM-dd"),
  219. type = e.data_type,
  220. e.uclk_uv,
  221. e.uclk_pv,
  222. e.pay_ord_num,
  223. e.order_ord_num,
  224. e.pay_ord_amt,
  225. e.pay_tk_disp_tfee,
  226. e.pay_ord_uv,
  227. e.eff_ord_num,
  228. e.eff_ord_amt,
  229. e.eff_tk_disp_tfee,
  230. e.total_count,
  231. e.success_count,
  232. e.req_base_num,
  233. e.resp_deeplink_num
  234. });
  235. }
  236. if (distributiontype == 0 || distributiontype == 6) // 全分类或 req_other_aff_num
  237. {
  238. results.Add(new
  239. {
  240. report_date = e.report_date.ToString("yyyy-MM-dd"),
  241. type = e.data_type,
  242. e.uclk_uv,
  243. e.uclk_pv,
  244. e.pay_ord_num,
  245. e.order_ord_num,
  246. e.pay_ord_amt,
  247. e.pay_tk_disp_tfee,
  248. e.pay_ord_uv,
  249. e.eff_ord_num,
  250. e.eff_ord_amt,
  251. e.eff_tk_disp_tfee,
  252. e.total_count,
  253. e.success_count,
  254. e.req_other_aff_num,
  255. e.resp_deeplink_num
  256. });
  257. }
  258. if (distributiontype == 0 || distributiontype == 7) // 全分类或 req_note_num
  259. {
  260. results.Add(new
  261. {
  262. report_date = e.report_date.ToString("yyyy-MM-dd"),
  263. type = e.data_type,
  264. e.uclk_uv,
  265. e.uclk_pv,
  266. e.pay_ord_num,
  267. e.order_ord_num,
  268. e.pay_ord_amt,
  269. e.pay_tk_disp_tfee,
  270. e.pay_ord_uv,
  271. e.eff_ord_num,
  272. e.eff_ord_amt,
  273. e.eff_tk_disp_tfee,
  274. e.total_count,
  275. e.success_count,
  276. e.req_note_num,
  277. e.resp_deeplink_num
  278. });
  279. }
  280. return results;
  281. }).ToList<dynamic>();
  282. return data;
  283. return data;
  284. }
  285. }
  286. }