EstimateComm.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using dodohold.core;
  2. using Sayaka.Common;
  3. namespace molilian.core
  4. {
  5. public partial class JdUnionPlus
  6. {
  7. public class EstimateCommDTO
  8. {
  9. public int id { get; set; } = 0;
  10. public int accountId { get; set; } = 0;
  11. public string accountName { get; set; } = string.Empty;
  12. public DateTime report_date { get; set; } = DateTime.MinValue;
  13. public DateTime create_time { get; set; } = DateTime.Now;
  14. public DateTime last_time { get; set; } = DateTime.MinValue;
  15. public decimal cosFee { get; set; }
  16. public int downloadDetail { get; set; }
  17. public int feeType { get; set; }
  18. public string feeTypeStr { get; set; } = string.Empty;
  19. public string payMonth { get; set; } = string.Empty;
  20. public int platform { get; set; }
  21. public string platformStr { get; set; } = string.Empty;
  22. public int showDetail { get; set; }
  23. public int status { get; set; }
  24. public int unionType { get; set; }
  25. public string unionTypeStr { get; set; } = string.Empty;
  26. }
  27. public async Task<List<DateTime>> queryEstimateCommList(CancellationToken cancellationToken = default)
  28. {
  29. List<DateTime> changed_dates = new List<DateTime>();
  30. var ts = DateTime.Now.Convert2UnixTimestamp(true);
  31. string cookies = _account.cookies;
  32. string useragent = _account.user_agent;
  33. if (string.IsNullOrEmpty(useragent)) useragent = ProviderFakeUserAgent.RandomComputer;
  34. bool hasNext = true;
  35. int pageNo = 1;
  36. while (hasNext)
  37. {
  38. var args = new
  39. {
  40. funName = "queryEstimateCommList",
  41. param = new
  42. {
  43. startTime = "",
  44. endTime = "",
  45. unionType = "",
  46. status = "",
  47. pageNo,
  48. pageSize = 20
  49. },
  50. //,"param":{"endTime":"","startTime":"","unionType":"","status":null,"pageNo":1,"pageSize":20}}
  51. };
  52. string data = args.Convert2Json().UrlEncode();
  53. string url = $"https://api.m.jd.com/api?functionId=union_balance_service&appid=unionpc&loginType=3&body={data}";
  54. WebClientUtility client = new WebClientUtility();
  55. client.Proxy = _proxy;
  56. #if DEBUG
  57. client.Proxy = null;
  58. #endif
  59. client.SetContentType("application/x-www-form-urlencoded");
  60. client.AddHeaders("X-Referer-Page", "https://union.jd.com/proManager/index");
  61. client.AddHeaders("X-Rp-Client", "h5_1.0.0");
  62. client.AddHeaders("Referer", "https://union.jd.com/");
  63. client.AddHeaders("Origin", "https://union.jd.com");
  64. client.UserAgent = useragent;
  65. client.AddHeaders("Cookie", cookies);
  66. client.Post($"body={data}");
  67. DateTime stime = DateTime.Now;
  68. var response = await client.RequestAsync(url, "POST", cancellationToken);
  69. TimeSpan ts2 = DateTime.Now - stime;
  70. string xx = ts2.TotalSeconds.ToString();
  71. string body = response.Body();
  72. var root = body.Convert2JsonElement();
  73. int code = root.Read<int>("code");
  74. string message = root.Read<string>("message");
  75. hasNext = root.Read<bool>("hasNext", false);
  76. pageNo++;
  77. if (code == 200 && "success".Equals(message))
  78. {
  79. var list = root.ElementRead("result");
  80. string filter = "report_date=@report_date AND accountId=@accountId" +
  81. " AND unionType=@unionType AND feeType=@feeType AND platform=@platform";
  82. foreach (var item in list.EnumerateArray())
  83. {
  84. var report = item.GetRawText().Convert2Object<EstimateCommDTO>();
  85. if (DateTime.TryParseExact(report.payMonth, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime report_date))
  86. {
  87. changed_dates.Add(report_date.Date);
  88. var exist = new DBContext.Table("jd_estimate_comm")
  89. .Fields("id")
  90. .Get<dynamic>(filter,
  91. new
  92. {
  93. report_date = report_date.Date,
  94. accountId = _account.id,
  95. report.unionType,
  96. report.feeType,
  97. report.platform
  98. }
  99. );
  100. var update = new DBContext.Table("jd_estimate_comm")
  101. .Add("accountId", _account.id)
  102. .Add("accountName", _account.name)
  103. .Add("cosFee", report.cosFee)
  104. .Add("feeType", report.feeType)
  105. .Add("feeTypeStr", report.feeTypeStr)
  106. .Add("platform", report.platform)
  107. .Add("platformStr", report.platformStr)
  108. .Add("status", report.status)
  109. .Add("unionType", report.unionType)
  110. .Add("unionTypeStr", report.unionTypeStr)
  111. .Add("last_time", DateTime.Now);
  112. if (exist == null)
  113. {
  114. update.Add("report_date", report_date.Date)
  115. .Add("create_time", DateTime.Now)
  116. .Create(DBContext.InsertType.REPLACE);
  117. }
  118. else
  119. {
  120. update.Where("id=@id", new { exist.id }).Update();
  121. }
  122. }
  123. }
  124. }
  125. else
  126. {
  127. throw new APIException(body);
  128. }
  129. }
  130. return changed_dates;
  131. }
  132. }
  133. }