EstimateComm.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. var response = await client.RequestAsync(url, "POST", cancellationToken);
  68. string body = response.Body();
  69. var root = body.Convert2JsonElement();
  70. int code = root.Read<int>("code");
  71. string message = root.Read<string>("message");
  72. hasNext = root.Read<bool>("hasNext", false);
  73. if (code == 200 && "success".Equals(message))
  74. {
  75. var list = root.ElementRead("result");
  76. string filter = "report_date=@report_date AND accountId=@accountId" +
  77. " AND unionType=@unionType AND feeType=@feeType AND platform=@platform";
  78. foreach (var item in list.EnumerateArray())
  79. {
  80. var report = item.GetRawText().Convert2Object<EstimateCommDTO>();
  81. if (DateTime.TryParseExact(report.payMonth, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime report_date))
  82. {
  83. changed_dates.Add(report_date.Date);
  84. var exist = new DBContext.Table("jd_estimate_comm")
  85. .Fields("id")
  86. .Get<dynamic>(filter,
  87. new { report_date = report_date.Date, accountId = _account.id, report.unionType, report.feeType, report.platform }
  88. );
  89. var update = new DBContext.Table("jd_estimate_comm")
  90. .Add("accountId", _account.id)
  91. .Add("accountName", _account.name)
  92. .Add("cosFee", report.cosFee)
  93. .Add("feeType", report.feeType)
  94. .Add("feeTypeStr", report.feeTypeStr)
  95. .Add("platform", report.platform)
  96. .Add("platformStr", report.platformStr)
  97. .Add("status", report.status)
  98. .Add("unionType", report.unionType)
  99. .Add("unionTypeStr", report.unionTypeStr)
  100. .Add("last_time", DateTime.Now);
  101. if (exist == null)
  102. {
  103. update.Add("report_date", report_date.Date)
  104. .Add("create_time", DateTime.Now)
  105. .Create();
  106. }
  107. else
  108. {
  109. update.Where("id=@id", new { exist.id }).Update();
  110. }
  111. }
  112. }
  113. }
  114. else
  115. {
  116. throw new APIException(body);
  117. }
  118. }
  119. return changed_dates;
  120. }
  121. }
  122. }