JDTaskController.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 = await JdPoolCore.ListAsync();
  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. try
  36. {
  37. DateTime endTime = DateTime.Now.Date;
  38. DateTime startTime = endTime.AddDays(-90);
  39. var plus = new JdUnionPlus(account);
  40. //for (int i = 89; i >= 0; i--)
  41. //{
  42. // DateTime dayStartTime = startTime.AddDays(i);
  43. // DateTime dayEndTime = dayStartTime.AddDays(1);
  44. // total += await plus.GetHistoryOrders(sleep, dayStartTime, dayEndTime);
  45. //}
  46. if (h == 1)
  47. {
  48. for (int i = 24 * 90 - 1; i >= 0; i--)
  49. {
  50. DateTime hourStartTime = startTime.AddHours(i);
  51. DateTime hourEndTime = hourStartTime.AddHours(1);
  52. total += await plus.GetHistoryOrders(sleep, hourStartTime, hourEndTime);
  53. }
  54. }
  55. else
  56. {
  57. for (int i = 89; i >= 0; i--)
  58. {
  59. DateTime dayStartTime = startTime.AddDays(i);
  60. DateTime dayEndTime = dayStartTime.AddDays(1);
  61. total += await plus.GetHistoryOrders(sleep, dayStartTime, dayEndTime);
  62. }
  63. }
  64. //total += await plus.GetHistoryOrders(sleep, startTime, endTime);
  65. }
  66. catch (Exception ex)
  67. {
  68. message = $"【JD历史订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  69. NotifyCore.Notify(new NifyMessage
  70. {
  71. message = message,
  72. priority = NifyMessagePriority.high,
  73. tags = ["red_circle"]
  74. });
  75. continue;
  76. }
  77. }
  78. return new APIResult(new { success = true, message = "ok", total });
  79. }
  80. [HttpGet]
  81. public async Task<ActionResult> GetIncyOrders(int sleep = 2000)
  82. {
  83. var list = await JdPoolCore.ListAsync();
  84. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  85. string message = string.Empty;
  86. int total = 0;
  87. foreach (var account in list)
  88. {
  89. if (!account.enable_sync_order) continue;
  90. try
  91. {
  92. var plus = new JdUnionPlus(account);
  93. total += await plus.GetIncyOrders(sleep);
  94. }
  95. catch (Exception ex)
  96. {
  97. message = $"【JD新增订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  98. NotifyCore.Notify(new NifyMessage
  99. {
  100. message = message,
  101. priority = NifyMessagePriority.high,
  102. tags = ["red_circle"]
  103. });
  104. continue;
  105. }
  106. }
  107. return new APIResult(new { success = true, message = "ok", total });
  108. }
  109. }
  110. }