using dodohold.core; using Sayaka.Common; using System.Drawing.Printing; using System.Text.Json; namespace molilian.core { public partial class PddUnionPlus { public async Task queryEstimateRevenueList(DateTime startTime, DateTime endTime, CancellationToken cancellationToken = default) { var ts = DateTime.Now.Convert2UnixTimestamp(true); string cookies = _account.cookies; bool hasNext = true; int pageNo = 1; int pageSize = 100; while (hasNext) { var args = new { startTime = startTime.ToString("yyyy-MM-dd"), endTime = endTime.ToString("yyyy-MM-dd"), orderPromotionType = 0, pageNumber = pageNo, pageSize }; DateTime stime = DateTime.Now; string url = "https://jinbao.pinduoduo.com/network/api/order/stat/overall/list"; var root = await this.RequestAsync(url, args.Convert2Json()); TimeSpan ts2 = DateTime.Now - stime; string xx = ts2.TotalSeconds.ToString(); var success = root.Read("success"); if (!success) break; var list = root.ElementRead("result").ElementRead("list"); string filter = "accountId=@accountId AND report_date=@report_date AND pid=@pid"; var len = list.GetArrayLength(); if (len == 0) break; foreach (var item in list.EnumerateArray()) { var report = item.GetRawText().Convert2Object(); var exist = new DBContext.Table("pdd_estimate_revenue") .Fields("id") .Get(filter, new { report_date = report.calcDate, accountId = _account.id, report.pid }); var update = new DBContext.Table("pdd_estimate_revenue") .Add("accountId", _account.id) .Add("accountName", _account.name) .Add("report_date", report.calcDate) .Add("pid", report.pid) .Add("pidName", report.pidName) .Add("orderNum", report.orderNum) .Add("orderAmount", report.orderAmount) .Add("feeAmount", report.feeAmount) .Add("avgPrice", report.avgPrice) .Add("mallRelFeeAmount", report.mallRelFeeAmount) .Add("lockFeeAmount", report.lockFeeAmount) .Add("last_time", DateTime.Now); if (exist == null) { update.Add("report_date", report.calcDate) .Add("create_time", DateTime.Now) .Create(DBContext.InsertType.REPLACE); } else { update.Where("id=@id", new { exist.id }).Update(); } } pageNo++; } } public async Task RequestAsync(string url, string data, CancellationToken cancellationToken = default) { string cookies = _account.cookies.Trim(); string useragent = ProviderFakeUserAgent.RandomComputer; WebClientUtility client = new WebClientUtility(); client.Proxy = _proxy; #if DEBUG client.Proxy = null; #endif client.SetContentType("application/json"); client.AddHeaders("Referer", "https://jinbao.pinduoduo.com/data/data-analysis"); client.AddHeaders("Origin", "https://jinbao.pinduoduo.com"); client.UserAgent = useragent; client.AddHeaders("Cookie", cookies); client.Post(data); var response = await client.RequestAsync(url, "POST", cancellationToken); string body = response.Body(); var root = body.Convert2JsonElement(); //string message = string.Empty; // todo 这里我会做一些 日志 处理 var success = root.Read("success"); if (!success) { var errorCode = root.Read("errorCode"); var errorMsg = root.Read("errorMsg"); _ = new LoggerLibrary("PddUnion", "unsuccessful").Info(url, data).Info(body).SaveAsync(); throw new APIException($"{errorCode}:{errorMsg}"); } return root; } } }