| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- using dodohold.core;
- using Microsoft.AspNetCore.Components.Server;
- using Sayaka.Common;
- namespace molilian.core
- {
- public partial class JdUnionPlus
- {
- public async Task<List<DateTime>> querySpreadEffectData(DateTime startDate, DateTime endDate, CancellationToken cancellationToken = default)
- {
- List<DateTime> changed_dates = new List<DateTime>();
- var ts = DateTime.Now.Convert2UnixTimestamp(true);
- string cookies = _account.union_cookies;
-
- string useragent = _account.user_agent;
- if (string.IsNullOrEmpty(useragent)) useragent = ProviderFakeUserAgent.RandomComputer;
- bool hasNext = true;
- int pageNo = 1;
- while (hasNext)
- {
- var args = new
- {
- funName = "querySpreadEffectData",
- param = new
- {
- startDate = startDate.ToString("yyyy-MM-dd"),
- endDate = endDate.ToString("yyyy-MM-dd"),
- mediaId = "",
- proCont = "",
- promotionId = "",
- sourceEmt = "",
- pageNo,
- pageSize = 20
- },
- };
- string data = args.Convert2Json().UrlEncode();
- string url = $"https://api.m.jd.com/api?functionId=union_report&appid=unionpc&loginType=3&body={data}";
- WebClientUtility client = new WebClientUtility();
- client.Proxy = _proxy;
- #if DEBUG
- client.Proxy = null;
- #endif
- client.SetContentType("application/x-www-form-urlencoded");
- client.AddHeaders("X-Referer-Page", "https://union.jd.com/proManager/index");
- client.AddHeaders("X-Rp-Client", "h5_1.0.0");
- client.AddHeaders("Referer", "https://union.jd.com/");
- client.AddHeaders("Origin", "https://union.jd.com");
- client.UserAgent = useragent;
- client.AddHeaders("Cookie", cookies);
- client.Post($"body={data}");
- DateTime stime = DateTime.Now;
- var response = await client.RequestAsync(url, "POST", cancellationToken);
- TimeSpan ts2 = stime - DateTime.Now;
- string xx = ts2.TotalSeconds.ToString();
- if (!client.Successed) throw client.ResponseException;
- string body = response.Body();
- var root = body.Convert2JsonElement();
- int code = root.Read<int>("code");
- string message = root.Read<string>("message");
- hasNext = root.Read<bool>("hasNext", false);
- pageNo++;
- if (code == 200 && "success".Equals(message))
- {
- var list = root.ElementRead("result").ElementRead("spreadReportInfoChatList");
- foreach (var item in list.EnumerateArray())
- {
- var report = item.GetRawText().Convert2Object<SpreadReportInfoDTO>();
- if (report.clickNum == 0 && report.orderNum == 0 &&
- report.cosFee == 0 && report.finishOrderNum == 0) continue;
- if (DateTime.TryParse(report.accountDate, out DateTime report_date))
- {
- changed_dates.Add(report_date.Date);
- bool data_changed = false;
- var exist = new DBContext.Table("jd_spread_report")
- .Get<dynamic>("report_date=@report_date AND accountId=@accountId",
- new { report_date = report_date.Date, accountId = _account.id });
- var update = new DBContext.Table("jd_spread_report")
- .Add("accountId", _account.id)
- .Add("accountName", _account.name)
- .Add("is_hide", _account.is_hide)
- .Add("clickNum", report.clickNum)
- .Add("cosFee", report.cosFee)
- .Add("cosPrice", report.cosPrice)
- .Add("finishCosFee", report.finishCosFee)
- .Add("finishCosPrice", report.finishCosPrice)
- .Add("finishOrderNum", report.finishOrderNum)
- .Add("orderNum", report.orderNum)
- .Add("last_time", DateTime.Now);
- if (exist == null)
- {
- update.Add("report_date", report_date.Date)
- .Add("create_time", DateTime.Now)
- .Create(DBContext.InsertType.REPLACE);
- data_changed = true;
- }
- else
- {
- update.Where("id=@id", new { exist.id }).Update();
- if (report.clickNum != exist.clickNum) data_changed = true;
- if (report.cosFee != exist.cosFee) data_changed = true;
- if (report.cosPrice != exist.cosPrice) data_changed = true;
- if (report.finishCosFee != exist.finishCosFee) data_changed = true;
- if (report.finishCosPrice != exist.finishCosPrice) data_changed = true;
- if (report.finishOrderNum != exist.finishOrderNum) data_changed = true;
- if (report.orderNum != exist.orderNum) data_changed = true;
- }
- if (data_changed)
- {
- //每次变动日志
- new DBContext.Table("jd_spread_report_log")
- .Add("accountId", _account.id)
- .Add("accountName", _account.name)
- .Add("clickNum", report.clickNum)
- .Add("cosFee", report.cosFee)
- .Add("cosPrice", report.cosPrice)
- .Add("finishCosFee", report.finishCosFee)
- .Add("finishCosPrice", report.finishCosPrice)
- .Add("finishOrderNum", report.finishOrderNum)
- .Add("orderNum", report.orderNum)
- .Add("last_time", DateTime.Now)
- .Add("report_date", report_date.Date)
- .Add("create_time", DateTime.Now)
- .Create();
- }
- }
- }
- }
- else
- {
- throw new APIException(body);
- }
- }
- return changed_dates;
- }
- }
- }
|