ApiReportCore.cs 13 KB

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