ApiReportCore.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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;
  96. if (distributiontype == 0)
  97. {
  98. data = list.Select(e => new
  99. {
  100. report_date = e.report_date.ToString("yyyy-MM-dd"),
  101. type = e.data_type,
  102. e.uclk_uv,
  103. e.uclk_pv,
  104. e.pay_ord_num,
  105. e.order_ord_num,
  106. pay_ord_am = e.pay_ord_amt * 100,
  107. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  108. e.pay_ord_uv,
  109. e.eff_ord_num,
  110. eff_ord_amt = e.eff_ord_amt * 100,
  111. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  112. e.total_count,
  113. //e.abandon_count,
  114. e.success_count,
  115. e.req_other_aff_num,
  116. e.req_goods_num,
  117. e.req_live_num,
  118. e.req_video_num,
  119. e.req_shop_num,
  120. e.req_base_num,
  121. e.req_note_num,
  122. e.resp_deeplink_num
  123. }).ToList<dynamic>();
  124. }
  125. else
  126. {
  127. data = list.SelectMany(e =>
  128. {
  129. var results = new List<dynamic>();
  130. if (distributiontype == -1 || distributiontype == 1) // 全分类或 goods
  131. {
  132. results.Add(new
  133. {
  134. //metric_type = "req_goods_num",
  135. //metric_value = e.req_goods_num,
  136. report_date = e.report_date.ToString("yyyy-MM-dd"),
  137. type = e.data_type,
  138. e.uclk_uv,
  139. e.uclk_pv,
  140. e.pay_ord_num,
  141. e.order_ord_num,
  142. pay_ord_am = e.pay_ord_amt * 100,
  143. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  144. e.pay_ord_uv,
  145. e.eff_ord_num,
  146. eff_ord_amt = e.eff_ord_amt * 100,
  147. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  148. e.total_count,
  149. e.success_count,
  150. e.req_goods_num,
  151. e.resp_deeplink_num
  152. });
  153. }
  154. if (distributiontype == -1 || distributiontype == 2) // 全分类或 live
  155. {
  156. results.Add(new
  157. {
  158. report_date = e.report_date.ToString("yyyy-MM-dd"),
  159. type = e.data_type,
  160. e.uclk_uv,
  161. e.uclk_pv,
  162. e.pay_ord_num,
  163. e.order_ord_num,
  164. pay_ord_am = e.pay_ord_amt * 100,
  165. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  166. e.pay_ord_uv,
  167. e.eff_ord_num,
  168. eff_ord_amt = e.eff_ord_amt * 100,
  169. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  170. e.total_count,
  171. e.success_count,
  172. e.req_live_num,
  173. e.resp_deeplink_num
  174. });
  175. }
  176. if (distributiontype == -1 || distributiontype == 3) // 全分类或 video
  177. {
  178. results.Add(new
  179. {
  180. report_date = e.report_date.ToString("yyyy-MM-dd"),
  181. type = e.data_type,
  182. e.uclk_uv,
  183. e.uclk_pv,
  184. e.pay_ord_num,
  185. e.order_ord_num,
  186. pay_ord_am = e.pay_ord_amt * 100,
  187. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  188. e.pay_ord_uv,
  189. e.eff_ord_num,
  190. eff_ord_amt = e.eff_ord_amt * 100,
  191. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  192. e.total_count,
  193. e.success_count,
  194. e.req_video_num,
  195. e.resp_deeplink_num
  196. });
  197. }
  198. if (distributiontype == -1 || distributiontype == 4) // 全分类或 req_shop_num
  199. {
  200. results.Add(new
  201. {
  202. report_date = e.report_date.ToString("yyyy-MM-dd"),
  203. type = e.data_type,
  204. e.uclk_uv,
  205. e.uclk_pv,
  206. e.pay_ord_num,
  207. e.order_ord_num,
  208. pay_ord_am = e.pay_ord_amt * 100,
  209. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  210. e.pay_ord_uv,
  211. e.eff_ord_num,
  212. eff_ord_amt = e.eff_ord_amt * 100,
  213. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  214. e.total_count,
  215. e.success_count,
  216. e.req_shop_num,
  217. e.resp_deeplink_num
  218. });
  219. }
  220. if (distributiontype == -1 || distributiontype == 5) // 全分类或 req_base_num
  221. {
  222. results.Add(new
  223. {
  224. report_date = e.report_date.ToString("yyyy-MM-dd"),
  225. type = e.data_type,
  226. e.uclk_uv,
  227. e.uclk_pv,
  228. e.pay_ord_num,
  229. e.order_ord_num,
  230. pay_ord_am = e.pay_ord_amt * 100,
  231. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  232. e.pay_ord_uv,
  233. e.eff_ord_num,
  234. eff_ord_amt = e.eff_ord_amt * 100,
  235. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  236. e.total_count,
  237. e.success_count,
  238. e.req_base_num,
  239. e.resp_deeplink_num
  240. });
  241. }
  242. if (distributiontype == -1 || distributiontype == 6) // 全分类或 req_other_aff_num
  243. {
  244. results.Add(new
  245. {
  246. report_date = e.report_date.ToString("yyyy-MM-dd"),
  247. type = e.data_type,
  248. e.uclk_uv,
  249. e.uclk_pv,
  250. e.pay_ord_num,
  251. e.order_ord_num,
  252. pay_ord_am = e.pay_ord_amt * 100,
  253. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  254. e.pay_ord_uv,
  255. e.eff_ord_num,
  256. eff_ord_amt = e.eff_ord_amt * 100,
  257. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  258. e.total_count,
  259. e.success_count,
  260. e.req_other_aff_num,
  261. e.resp_deeplink_num
  262. });
  263. }
  264. if (distributiontype == -1 || distributiontype == 7) // 全分类或 req_note_num
  265. {
  266. results.Add(new
  267. {
  268. report_date = e.report_date.ToString("yyyy-MM-dd"),
  269. type = e.data_type,
  270. e.uclk_uv,
  271. e.uclk_pv,
  272. e.pay_ord_num,
  273. e.order_ord_num,
  274. pay_ord_am = e.pay_ord_amt * 100,
  275. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  276. e.pay_ord_uv,
  277. e.eff_ord_num,
  278. eff_ord_amt = e.eff_ord_amt * 100,
  279. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  280. e.total_count,
  281. e.success_count,
  282. e.req_note_num,
  283. e.resp_deeplink_num
  284. });
  285. }
  286. return results;
  287. }).ToList<dynamic>();
  288. }
  289. return data;
  290. }
  291. }
  292. }