JDTaskController.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using molilian.core;
  2. using dodohold.core;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Org.BouncyCastle.Ocsp;
  5. using System.Text.Json;
  6. using System.Runtime.InteropServices;
  7. using System.Net;
  8. using System.Threading.Channels;
  9. using TencentCloud.Cdwch.V20200915.Models;
  10. using COSXML.Network;
  11. using System.Security.Cryptography;
  12. using System.Threading;
  13. using TencentCloud.Batch.V20170312.Models;
  14. namespace molilian.api.Controllers
  15. {
  16. [ApiController]
  17. [Route("[controller]_70160bd632/[action]")]
  18. public class JDTaskController : ControllerBase
  19. {
  20. protected IHttpContextAccessor _accessor;
  21. public JDTaskController(IHttpContextAccessor accessor)
  22. {
  23. _accessor = accessor;
  24. }
  25. [HttpGet]
  26. public async Task<ActionResult> GetHistoryOrders(int id, int sleep, int h = 0)
  27. {
  28. var list = JdPoolCore.List();
  29. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  30. string message = string.Empty;
  31. int total = 0;
  32. foreach (var account in list)
  33. {
  34. if (id != 0 && id != account.id) continue;
  35. if (account.is_hide) continue;
  36. try
  37. {
  38. DateTime endTime = DateTime.Now.Date;
  39. DateTime startTime = endTime.AddDays(-90);
  40. var plus = new JdUnionPlus(account);
  41. //for (int i = 89; i >= 0; i--)
  42. //{
  43. // DateTime dayStartTime = startTime.AddDays(i);
  44. // DateTime dayEndTime = dayStartTime.AddDays(1);
  45. // total += await plus.GetHistoryOrders(sleep, dayStartTime, dayEndTime);
  46. //}
  47. if (h == 1)
  48. {
  49. for (int i = 24 * 90 - 1; i >= 0; i--)
  50. {
  51. DateTime hourStartTime = startTime.AddHours(i);
  52. DateTime hourEndTime = hourStartTime.AddHours(1);
  53. total += await plus.GetHistoryOrders(sleep, hourStartTime, hourEndTime);
  54. }
  55. }
  56. else
  57. {
  58. for (int i = 89; i >= 0; i--)
  59. {
  60. DateTime dayStartTime = startTime.AddDays(i);
  61. DateTime dayEndTime = dayStartTime.AddDays(1);
  62. total += await plus.GetHistoryOrders(sleep, dayStartTime, dayEndTime);
  63. }
  64. }
  65. //total += await plus.GetHistoryOrders(sleep, startTime, endTime);
  66. }
  67. catch (Exception ex)
  68. {
  69. message = $"【JD历史订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  70. NotifyCore.Notify(new NifyMessage
  71. {
  72. message = message,
  73. priority = NifyMessagePriority.high,
  74. tags = ["red_circle"]
  75. });
  76. continue;
  77. }
  78. }
  79. return new APIResult(new { success = true, message = "ok", total });
  80. }
  81. [HttpGet]
  82. public async Task<ActionResult> GetIncyOrders(int sleep = 2000)
  83. {
  84. var list = JdPoolCore.List();
  85. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  86. string message = string.Empty;
  87. int total = 0;
  88. foreach (var account in list)
  89. {
  90. if (!account.enable_sync_order) continue;
  91. try
  92. {
  93. var plus = new JdUnionPlus(account);
  94. total += await plus.GetIncyOrders(sleep);
  95. }
  96. catch (Exception ex)
  97. {
  98. message = $"【JD新增订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  99. NotifyCore.Notify(new NifyMessage
  100. {
  101. message = message,
  102. priority = NifyMessagePriority.high,
  103. tags = ["red_circle"]
  104. });
  105. continue;
  106. }
  107. }
  108. return new APIResult(new { success = true, message = "ok", total });
  109. }
  110. }
  111. }