| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- 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<bool>("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<PddEstimateRevenueDTO>();
- var exist = new DBContext.Table("pdd_estimate_revenue")
- .Fields("id")
- .Get<dynamic>(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<JsonElement> 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<bool>("success");
- if (!success)
- {
- var errorCode = root.Read<int>("errorCode");
- var errorMsg = root.Read<string>("errorMsg");
- _ = new LoggerLibrary("PddUnion", "unsuccessful").Info(url, data).Info(body).SaveAsync();
- throw new APIException($"{errorCode}:{errorMsg}");
- }
- return root;
- }
- }
- }
|