| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
-
- using dodohold.core;
- using System.Text.Json;
- namespace molilian.core
- {
- public partial class ApiReportCore
- {
- public class RecordDTO
- {
- public int id { get; set; }
- public int data_type { get; set; }
- public DateTime report_date { get; set; }
- public int uclk_uv { get; set; } = 0;
- public int uclk_pv { get; set; } = 0;
- public int pay_ord_num { get; set; } = 0;
- public int order_ord_num { get; set; } = 0;
- public decimal pay_ord_amt { get; set; } = 0;
- public decimal pay_tk_disp_tfee { get; set; } = 0;
- public int pay_ord_uv { get; set; } = 0;
- public int eff_ord_num { get; set; } = 0;
- public decimal eff_ord_amt { get; set; } = 0;
- public decimal eff_tk_disp_tfee { get; set; } = 0;
- public int total_count { get; set; } = 0;
- public int abandon_count { get; set; } = 0;
- public int success_count { get; set; } = 0;
- public int req_other_aff_num { get; set; } = 0;
- public int req_goods_num { get; set; } = 0;
- public int req_live_num { get; set; } = 0;
- public int req_video_num { get; set; } = 0;
- public int req_shop_num { get; set; } = 0;
- public int req_base_num { get; set; } = 0;
- public int req_note_num { get; set; } = 0;
- public int resp_deeplink_num { get; set; } = 0;
- }
- public static async Task<List<dynamic>> ReportDailysAsync(JsonElement form, string clientIp, bool debug = false)
- {
- List<dynamic> list = [];
- //那就是入参日期和type
- //我们给出指定日期的:点击 付款 有效付款 转链API调用
- //type可以不入参,留空就两个场景的数据都显示就行了
- //先只要成功的就行了,,到时候他们要明细再加就行了
- //0:全分销类型;-1:各分销类型,1:goods 2: live 3:video 4: profile 5: unknown
- int distributiontype = form.Read("distributiontype", 0);
- //0:全平台;-1:各平台;1:淘宝 2:京东
- int platform = form.Read("platform", 0);
- int data_type = form.Read("type", 0);
- var report_date = form.PathReadArray<string>("query_date[]");
- DateTime stime = DateTime.Now.AddDays(-1).Date, etime = stime;
- if (report_date.Count == 2)
- {
- if (DateTime.TryParse(report_date[0], out stime) && DateTime.TryParse(report_date[1], out etime))
- {
- stime = stime.Date;
- etime = etime.Date;
- }
- }
- switch (data_type)
- {
- case 1:
- case 2:
- {
- var data = await DataTypeReportDailysAsync(platform, distributiontype, data_type, stime, etime, clientIp, debug);
- list.AddRange(data);
- }
- break;
- default:
- {
- int[] types = { 1, 2 };
- foreach (var type in types)
- {
- var data = await DataTypeReportDailysAsync(platform, distributiontype, type, stime, etime, clientIp, debug);
- list.AddRange(data);
- }
- }
- break;
- }
- return list;
- }
- public static async Task<List<dynamic>> DataTypeReportDailysAsync(int platform, int distributiontype, int data_type, DateTime stime, DateTime etime, string clientIp, bool debug = false)
- {
- string filter = "`is_show`=@is_show AND data_type=@data_type AND report_date>=@stime AND report_date<=@etime";
- string orderBy = "report_date DESC";
- var list = new DBContext.Table("api_call_report_dailys")
- .Where(filter, new { is_show = true, data_type, stime, etime })
- .Order(orderBy)
- .Select<RecordDTO>().ToList();
- if (!debug)
- {
- if (list.Count != 0)
- {
- var ids = list.Select(o => o.id).ToList();
- new DBContext.Table("api_call_report_dailys")
- .Add("read_num:", "read_num+1")
- .Where("id IN @ids", new { ids })
- .Update();
- }
- }
- List<dynamic> data;
- if (distributiontype == 0)
- {
- data = list.Select(e => new
- {
- report_date = e.report_date.ToString("yyyy-MM-dd"),
- type = e.data_type,
- e.uclk_uv,
- e.uclk_pv,
- e.pay_ord_num,
- e.order_ord_num,
- pay_ord_amt = e.pay_ord_amt * 100,
- pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
- e.pay_ord_uv,
- e.eff_ord_num,
- eff_ord_amt = e.eff_ord_amt * 100,
- eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
- e.total_count,
- //e.abandon_count,
- e.success_count,
- e.req_other_aff_num,
- e.req_goods_num,
- e.req_live_num,
- e.req_video_num,
- e.req_shop_num,
- e.req_base_num,
- e.req_note_num,
- e.resp_deeplink_num
- }).ToList<dynamic>();
- }
- else
- {
- data = list.SelectMany(e =>
- {
- var results = new List<dynamic>();
- if (distributiontype == -1 || distributiontype == 1) // 全分类或 goods
- {
- results.Add(new
- {
- //metric_type = "req_goods_num",
- //metric_value = e.req_goods_num,
- report_date = e.report_date.ToString("yyyy-MM-dd"),
- type = e.data_type,
- e.uclk_uv,
- e.uclk_pv,
- e.pay_ord_num,
- e.order_ord_num,
- pay_ord_amt = e.pay_ord_amt * 100,
- pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
- e.pay_ord_uv,
- e.eff_ord_num,
- eff_ord_amt = e.eff_ord_amt * 100,
- eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
- e.total_count,
- e.success_count,
- e.req_goods_num,
- e.resp_deeplink_num
- });
- }
- if (distributiontype == -1 || distributiontype == 2) // 全分类或 live
- {
- results.Add(new
- {
- report_date = e.report_date.ToString("yyyy-MM-dd"),
- type = e.data_type,
- e.uclk_uv,
- e.uclk_pv,
- e.pay_ord_num,
- e.order_ord_num,
- pay_ord_amt = e.pay_ord_amt * 100,
- pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
- e.pay_ord_uv,
- e.eff_ord_num,
- eff_ord_amt = e.eff_ord_amt * 100,
- eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
- e.total_count,
- e.success_count,
- e.req_live_num,
- e.resp_deeplink_num
- });
- }
- if (distributiontype == -1 || distributiontype == 3) // 全分类或 video
- {
- results.Add(new
- {
- report_date = e.report_date.ToString("yyyy-MM-dd"),
- type = e.data_type,
- e.uclk_uv,
- e.uclk_pv,
- e.pay_ord_num,
- e.order_ord_num,
- pay_ord_amt = e.pay_ord_amt * 100,
- pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
- e.pay_ord_uv,
- e.eff_ord_num,
- eff_ord_amt = e.eff_ord_amt * 100,
- eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
- e.total_count,
- e.success_count,
- e.req_video_num,
- e.resp_deeplink_num
- });
- }
- if (distributiontype == -1 || distributiontype == 4) // 全分类或 req_shop_num
- {
- results.Add(new
- {
- report_date = e.report_date.ToString("yyyy-MM-dd"),
- type = e.data_type,
- e.uclk_uv,
- e.uclk_pv,
- e.pay_ord_num,
- e.order_ord_num,
- pay_ord_amt = e.pay_ord_amt * 100,
- pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
- e.pay_ord_uv,
- e.eff_ord_num,
- eff_ord_amt = e.eff_ord_amt * 100,
- eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
- e.total_count,
- e.success_count,
- e.req_shop_num,
- e.resp_deeplink_num
- });
- }
- if (distributiontype == -1 || distributiontype == 5) // 全分类或 req_base_num
- {
- results.Add(new
- {
- report_date = e.report_date.ToString("yyyy-MM-dd"),
- type = e.data_type,
- e.uclk_uv,
- e.uclk_pv,
- e.pay_ord_num,
- e.order_ord_num,
- pay_ord_amt = e.pay_ord_amt * 100,
- pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
- e.pay_ord_uv,
- e.eff_ord_num,
- eff_ord_amt = e.eff_ord_amt * 100,
- eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
- e.total_count,
- e.success_count,
- e.req_base_num,
- e.resp_deeplink_num
- });
- }
- if (distributiontype == -1 || distributiontype == 6) // 全分类或 req_other_aff_num
- {
- results.Add(new
- {
- report_date = e.report_date.ToString("yyyy-MM-dd"),
- type = e.data_type,
- e.uclk_uv,
- e.uclk_pv,
- e.pay_ord_num,
- e.order_ord_num,
- pay_ord_amt = e.pay_ord_amt * 100,
- pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
- e.pay_ord_uv,
- e.eff_ord_num,
- eff_ord_amt = e.eff_ord_amt * 100,
- eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
- e.total_count,
- e.success_count,
- e.req_other_aff_num,
- e.resp_deeplink_num
- });
- }
- if (distributiontype == -1 || distributiontype == 7) // 全分类或 req_note_num
- {
- results.Add(new
- {
- report_date = e.report_date.ToString("yyyy-MM-dd"),
- type = e.data_type,
- e.uclk_uv,
- e.uclk_pv,
- e.pay_ord_num,
- e.order_ord_num,
- pay_ord_amt = e.pay_ord_amt * 100,
- pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
- e.pay_ord_uv,
- e.eff_ord_num,
- eff_ord_amt = e.eff_ord_amt * 100,
- eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
- e.total_count,
- e.success_count,
- e.req_note_num,
- e.resp_deeplink_num
- });
- }
- return results;
- }).ToList<dynamic>();
- }
- return data;
- }
- }
- }
|