ApiReportCore.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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 platform { get; set; }
  12. public int data_type { get; set; }
  13. public DateTime report_date { get; set; }
  14. public int uclk_uv { get; set; } = 0;
  15. public int uclk_pv { get; set; } = 0;
  16. public int pay_ord_num { get; set; } = 0;
  17. public int order_ord_num { get; set; } = 0;
  18. public decimal pay_ord_amt { get; set; } = 0;
  19. public decimal pay_tk_disp_tfee { get; set; } = 0;
  20. public int pay_ord_uv { get; set; } = 0;
  21. public int eff_ord_num { get; set; } = 0;
  22. public decimal eff_ord_amt { get; set; } = 0;
  23. public decimal eff_tk_disp_tfee { get; set; } = 0;
  24. public int total_count { get; set; } = 0;
  25. public int abandon_count { get; set; } = 0;
  26. public int success_count { get; set; } = 0;
  27. public int req_other_aff_num { get; set; } = 0;
  28. public int req_goods_num { get; set; } = 0;
  29. public int req_live_num { get; set; } = 0;
  30. public int req_video_num { get; set; } = 0;
  31. public int req_shop_num { get; set; } = 0;
  32. public int req_base_num { get; set; } = 0;
  33. public int req_note_num { get; set; } = 0;
  34. public int resp_deeplink_num { get; set; } = 0;
  35. }
  36. public static async Task<List<dynamic>> ReportDailysAsync(JsonElement form, string clientIp, bool debug = false)
  37. {
  38. List<dynamic> list = [];
  39. //那就是入参日期和type
  40. //我们给出指定日期的:点击 付款 有效付款 转链API调用
  41. //type可以不入参,留空就两个场景的数据都显示就行了
  42. //先只要成功的就行了,,到时候他们要明细再加就行了
  43. //0:全分销类型;-1:各分销类型,1:goods 2: live 3:video 4: profile 5: unknown
  44. int distributiontype = form.Read("distributiontype", 0);
  45. //0:全平台;-1:各平台;1:淘宝 2:京东 3:多多
  46. int platform = form.Read("platform", 0);
  47. int data_type = form.Read("type", 0);
  48. var report_date = form.PathReadArray<string>("query_date[]");
  49. DateTime stime = DateTime.Now.AddDays(-1).Date, etime = stime;
  50. if (report_date.Count == 2)
  51. {
  52. if (DateTime.TryParse(report_date[0], out stime) && DateTime.TryParse(report_date[1], out etime))
  53. {
  54. stime = stime.Date;
  55. etime = etime.Date;
  56. }
  57. }
  58. switch (data_type)
  59. {
  60. case 1:
  61. case 2:
  62. case 3:
  63. {
  64. var data = await DataTypeReportDailysAsync(platform, distributiontype, data_type, stime, etime, clientIp, debug);
  65. list.AddRange(data);
  66. }
  67. break;
  68. default:
  69. {
  70. int[] types = { 1, 2, 3 };
  71. foreach (var type in types)
  72. {
  73. var data = await DataTypeReportDailysAsync(platform, distributiontype, type, stime, etime, clientIp, debug);
  74. list.AddRange(data);
  75. }
  76. }
  77. break;
  78. }
  79. return list;
  80. }
  81. public static async Task<List<dynamic>> DataTypeReportDailysAsync(int platform, int distributiontype, int data_type, DateTime stime, DateTime etime, string clientIp, bool debug = false)
  82. {
  83. string filter = "`is_show`=@is_show AND data_type=@data_type AND report_date>=@stime AND report_date<=@etime";
  84. if (platform > 0)
  85. {
  86. filter = "`is_show`=@is_show AND data_type=@data_type AND platform=@platform AND report_date>=@stime AND report_date<=@etime";
  87. platform -= 1;
  88. }
  89. string orderBy = "report_date DESC";
  90. var list = new DBContext.Table("api_call_report_dailys")
  91. .Where(filter, new { is_show = true, platform, data_type, stime, etime })
  92. .Order(orderBy)
  93. .Select<RecordDTO>().ToList();
  94. if (!debug)
  95. {
  96. if (list.Count != 0)
  97. {
  98. var ids = list.Select(o => o.id).ToList();
  99. new DBContext.Table("api_call_report_dailys")
  100. .Add("read_num:", "read_num+1")
  101. .Where("id IN @ids", new { ids })
  102. .Update();
  103. }
  104. }
  105. List<dynamic> data;
  106. if (distributiontype == 0)
  107. {
  108. data = list.Select(e => new
  109. {
  110. platform = e.platform + 1,
  111. report_date = e.report_date.ToString("yyyy-MM-dd"),
  112. type = e.data_type,
  113. e.uclk_uv,
  114. e.uclk_pv,
  115. e.pay_ord_num,
  116. e.order_ord_num,
  117. pay_ord_amt = e.pay_ord_amt * 100,
  118. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  119. e.pay_ord_uv,
  120. e.eff_ord_num,
  121. eff_ord_amt = e.eff_ord_amt * 100,
  122. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  123. e.total_count,
  124. //e.abandon_count,
  125. e.success_count,
  126. e.req_other_aff_num,
  127. e.req_goods_num,
  128. e.req_live_num,
  129. e.req_video_num,
  130. e.req_shop_num,
  131. e.req_base_num,
  132. e.req_note_num,
  133. e.resp_deeplink_num
  134. }).ToList<dynamic>();
  135. }
  136. else
  137. {
  138. data = list.SelectMany(e =>
  139. {
  140. var results = new List<dynamic>();
  141. if (distributiontype == -1 || distributiontype == 1) // 全分类或 goods
  142. {
  143. results.Add(new
  144. {
  145. platform = e.platform + 1,
  146. //metric_type = "req_goods_num",
  147. //metric_value = e.req_goods_num,
  148. report_date = e.report_date.ToString("yyyy-MM-dd"),
  149. type = e.data_type,
  150. e.uclk_uv,
  151. e.uclk_pv,
  152. e.pay_ord_num,
  153. e.order_ord_num,
  154. pay_ord_amt = e.pay_ord_amt * 100,
  155. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  156. e.pay_ord_uv,
  157. e.eff_ord_num,
  158. eff_ord_amt = e.eff_ord_amt * 100,
  159. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  160. e.total_count,
  161. e.success_count,
  162. e.req_goods_num,
  163. e.resp_deeplink_num
  164. });
  165. }
  166. if (distributiontype == -1 || distributiontype == 2) // 全分类或 live
  167. {
  168. results.Add(new
  169. {
  170. platform = e.platform + 1,
  171. report_date = e.report_date.ToString("yyyy-MM-dd"),
  172. type = e.data_type,
  173. e.uclk_uv,
  174. e.uclk_pv,
  175. e.pay_ord_num,
  176. e.order_ord_num,
  177. pay_ord_amt = e.pay_ord_amt * 100,
  178. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  179. e.pay_ord_uv,
  180. e.eff_ord_num,
  181. eff_ord_amt = e.eff_ord_amt * 100,
  182. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  183. e.total_count,
  184. e.success_count,
  185. e.req_live_num,
  186. e.resp_deeplink_num
  187. });
  188. }
  189. if (distributiontype == -1 || distributiontype == 3) // 全分类或 video
  190. {
  191. results.Add(new
  192. {
  193. platform = e.platform + 1,
  194. report_date = e.report_date.ToString("yyyy-MM-dd"),
  195. type = e.data_type,
  196. e.uclk_uv,
  197. e.uclk_pv,
  198. e.pay_ord_num,
  199. e.order_ord_num,
  200. pay_ord_amt = e.pay_ord_amt * 100,
  201. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  202. e.pay_ord_uv,
  203. e.eff_ord_num,
  204. eff_ord_amt = e.eff_ord_amt * 100,
  205. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  206. e.total_count,
  207. e.success_count,
  208. e.req_video_num,
  209. e.resp_deeplink_num
  210. });
  211. }
  212. if (distributiontype == -1 || distributiontype == 4) // 全分类或 req_shop_num
  213. {
  214. results.Add(new
  215. {
  216. platform = e.platform + 1,
  217. report_date = e.report_date.ToString("yyyy-MM-dd"),
  218. type = e.data_type,
  219. e.uclk_uv,
  220. e.uclk_pv,
  221. e.pay_ord_num,
  222. e.order_ord_num,
  223. pay_ord_amt = e.pay_ord_amt * 100,
  224. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  225. e.pay_ord_uv,
  226. e.eff_ord_num,
  227. eff_ord_amt = e.eff_ord_amt * 100,
  228. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  229. e.total_count,
  230. e.success_count,
  231. e.req_shop_num,
  232. e.resp_deeplink_num
  233. });
  234. }
  235. if (distributiontype == -1 || distributiontype == 5) // 全分类或 req_base_num
  236. {
  237. results.Add(new
  238. {
  239. platform = e.platform + 1,
  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. pay_ord_amt = e.pay_ord_amt * 100,
  247. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  248. e.pay_ord_uv,
  249. e.eff_ord_num,
  250. eff_ord_amt = e.eff_ord_amt * 100,
  251. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  252. e.total_count,
  253. e.success_count,
  254. e.req_base_num,
  255. e.resp_deeplink_num
  256. });
  257. }
  258. if (distributiontype == -1 || distributiontype == 6) // 全分类或 req_other_aff_num
  259. {
  260. results.Add(new
  261. {
  262. platform = e.platform + 1,
  263. report_date = e.report_date.ToString("yyyy-MM-dd"),
  264. type = e.data_type,
  265. e.uclk_uv,
  266. e.uclk_pv,
  267. e.pay_ord_num,
  268. e.order_ord_num,
  269. pay_ord_amt = e.pay_ord_amt * 100,
  270. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  271. e.pay_ord_uv,
  272. e.eff_ord_num,
  273. eff_ord_amt = e.eff_ord_amt * 100,
  274. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  275. e.total_count,
  276. e.success_count,
  277. e.req_other_aff_num,
  278. e.resp_deeplink_num
  279. });
  280. }
  281. if (distributiontype == -1 || distributiontype == 7) // 全分类或 req_note_num
  282. {
  283. results.Add(new
  284. {
  285. platform = e.platform + 1,
  286. report_date = e.report_date.ToString("yyyy-MM-dd"),
  287. type = e.data_type,
  288. e.uclk_uv,
  289. e.uclk_pv,
  290. e.pay_ord_num,
  291. e.order_ord_num,
  292. pay_ord_amt = e.pay_ord_amt * 100,
  293. pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
  294. e.pay_ord_uv,
  295. e.eff_ord_num,
  296. eff_ord_amt = e.eff_ord_amt * 100,
  297. eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
  298. e.total_count,
  299. e.success_count,
  300. e.req_note_num,
  301. e.resp_deeplink_num
  302. });
  303. }
  304. return results;
  305. }).ToList<dynamic>();
  306. }
  307. return data;
  308. }
  309. }
  310. }