ApiReportCore.cs 14 KB

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