TaskController.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. namespace molilian.api.Controllers
  9. {
  10. [ApiController]
  11. [Route("[controller]_70160bd632/[action]")]
  12. public class TaskController : ControllerBase
  13. {
  14. protected IHttpContextAccessor _accessor;
  15. public TaskController(IHttpContextAccessor accessor)
  16. {
  17. _accessor = accessor;
  18. }
  19. [HttpGet]
  20. public ActionResult BatchInsertLogDB(int limit = 100)
  21. {
  22. int total = TkLogCore.BatchInsertLogDB(limit);
  23. return new APIResult(new { success = true, message = "ok", limit, total });
  24. }
  25. [HttpGet]
  26. public async Task<ActionResult> GetSettleBills(int sleep = 2000)
  27. {
  28. var list = TkPoolCore.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 DEBUG
  35. if (13 != account.id) continue;
  36. #endif
  37. try
  38. {
  39. var alimama = new AlimamaPlus(account);
  40. total += alimama.GetSettleBills(sleep);
  41. }
  42. catch (Exception ex)
  43. {
  44. message = $"【收益接口异常】\t{account.name}\n{ex.Message}\n{ex.StackTrace}";
  45. NotifyCore.Notify(new NifyMessage
  46. {
  47. message = message,
  48. priority = NifyMessagePriority.high,
  49. tags = ["red_circle"]
  50. });
  51. continue;
  52. }
  53. }
  54. return new APIResult(new { success = true, message = "ok", total });
  55. }
  56. [HttpGet]
  57. public async Task<ActionResult> GetHistoryOrders(int id, int sleep = 2000)
  58. {
  59. var list = TkPoolCore.List();
  60. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  61. if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
  62. string message = string.Empty;
  63. int total = 0;
  64. foreach (var account in list)
  65. {
  66. if (id != account.id) continue;
  67. try
  68. {
  69. var alimama = new AlimamaPlus(account);
  70. total += alimama.GetHistoryOrders(sleep);
  71. }
  72. catch (Exception ex)
  73. {
  74. message = $"【订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  75. NotifyCore.Notify(new NifyMessage
  76. {
  77. message = message,
  78. priority = NifyMessagePriority.high,
  79. tags = ["red_circle"]
  80. });
  81. continue;
  82. }
  83. }
  84. return new APIResult(new { success = true, message = "ok", total });
  85. }
  86. [HttpGet]
  87. public async Task<ActionResult> GetIncyOrders(int sleep = 2000)
  88. {
  89. var list = TkPoolCore.List();
  90. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  91. string message = string.Empty;
  92. int total = 0;
  93. foreach (var account in list)
  94. {
  95. #if DEBUG
  96. if (account.id != 17) continue;
  97. #endif
  98. try
  99. {
  100. var alimama = new AlimamaPlus(account);
  101. total += alimama.GetIncyOrders(sleep);
  102. }
  103. catch (Exception ex)
  104. {
  105. message = $"【订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  106. NotifyCore.Notify(new NifyMessage
  107. {
  108. message = message,
  109. priority = NifyMessagePriority.high,
  110. tags = ["red_circle"]
  111. });
  112. continue;
  113. }
  114. }
  115. return new APIResult(new { success = true, message = "ok", total });
  116. }
  117. [HttpGet]
  118. public async Task<ActionResult> GetViolationuWarning()
  119. {
  120. var list = TkPoolCore.List();
  121. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  122. string message = string.Empty;
  123. foreach (var account in list)
  124. {
  125. try
  126. {
  127. var alimama = new AlimamaPlus(account);
  128. alimama.GetViolationuWarning();
  129. }
  130. catch (Exception ex)
  131. {
  132. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  133. NotifyCore.Notify(new NifyMessage
  134. {
  135. message = message,
  136. priority = NifyMessagePriority.high,
  137. tags = ["red_circle"]
  138. });
  139. continue;
  140. }
  141. }
  142. return new APIResult(new { success = true, message = "ok" });
  143. }
  144. [HttpGet]
  145. public async Task<ActionResult> DailyLogs(int intervalDay = 1)
  146. {
  147. try
  148. {
  149. AlimamaPlus.DailyLogs(intervalDay);
  150. AlimamaPlus.DailyLogs(intervalDay, "parse_");
  151. AlimamaPlus.DailyLogs(intervalDay, "coupon_");
  152. }
  153. catch (Exception ex)
  154. {
  155. string message = $"【报表接口异常】DailyLogs\n{ex.Message}\n{ex.StackTrace}";
  156. NotifyCore.Notify(new NifyMessage
  157. {
  158. message = message,
  159. priority = NifyMessagePriority.high,
  160. tags = ["red_circle"]
  161. });
  162. }
  163. return new APIResult(new { success = true, message = "ok" });
  164. }
  165. [HttpGet]
  166. public async Task<ActionResult> GetDrawBalance()
  167. {
  168. var list = TkPoolCore.List();
  169. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  170. string message = string.Empty;
  171. foreach (var account in list)
  172. {
  173. try
  174. {
  175. var alimama = new AlimamaPlus(account);
  176. alimama.GetDrawBalance();
  177. }
  178. catch (Exception ex)
  179. {
  180. message = $"【报表接口异常】GetDrawBalance\n{ex.Message}\n{ex.StackTrace}";
  181. NotifyCore.Notify(new NifyMessage
  182. {
  183. message = message,
  184. priority = NifyMessagePriority.high,
  185. tags = ["red_circle"]
  186. });
  187. continue;
  188. }
  189. }
  190. return new APIResult(new { success = true, message = "ok" });
  191. }
  192. [HttpGet]
  193. public ActionResult FastReport()
  194. {
  195. var list = TkPoolCore.List();
  196. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  197. string message = string.Empty;
  198. foreach (var account in list)
  199. {
  200. #if DEBUG
  201. if (account.id != 5) continue;
  202. #endif
  203. try
  204. {
  205. var alimama = new AlimamaPlus(account);
  206. alimama.SaveReportOverview();
  207. }
  208. catch (Exception ex)
  209. {
  210. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  211. NotifyCore.Notify(new NifyMessage
  212. {
  213. message = message,
  214. priority = NifyMessagePriority.high,
  215. tags = ["red_circle"]
  216. });
  217. continue;
  218. }
  219. }
  220. return new APIResult(new { success = true, message = "ok" });
  221. }
  222. [HttpGet]
  223. public async Task<ActionResult> SaveReport()
  224. {
  225. var list = TkPoolCore.List();
  226. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  227. string message = string.Empty;
  228. foreach (var account in list)
  229. {
  230. #if DEBUG
  231. if (account.id != 5) continue;
  232. #endif
  233. try
  234. {
  235. var alimama = new AlimamaPlus(account);
  236. alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
  237. alimama.SaveReportHourtrend(DateTime.Now);
  238. if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
  239. {
  240. DateTime date = DateTime.Now.AddDays(-1);
  241. alimama.FixReport(date);
  242. }
  243. }
  244. catch (Exception ex)
  245. {
  246. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  247. NotifyCore.Notify(new NifyMessage
  248. {
  249. message = message,
  250. priority = NifyMessagePriority.high,
  251. tags = ["red_circle"]
  252. });
  253. continue;
  254. }
  255. }
  256. return new APIResult(new { success = true, message = "ok" });
  257. }
  258. [HttpGet]
  259. public async Task<ActionResult> FixReport(string dt)
  260. {
  261. if (!DateTime.TryParse(dt, out DateTime date))
  262. {
  263. return new APIResult(new { success = false, message = "日期错误", });
  264. }
  265. var list = TkPoolCore.List();
  266. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  267. string message = string.Empty;
  268. foreach (var account in list)
  269. {
  270. #if DEBUG
  271. if (account.id != 5) continue;
  272. #endif
  273. try
  274. {
  275. var alimama = new AlimamaPlus(account);
  276. while (date.Date < DateTime.Now.Date)
  277. {
  278. alimama.FixReport(date);
  279. date = date.AddDays(1);
  280. }
  281. }
  282. catch (Exception ex)
  283. {
  284. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  285. NotifyCore.Notify(new NifyMessage
  286. {
  287. message = message,
  288. priority = NifyMessagePriority.high,
  289. tags = ["red_circle"]
  290. });
  291. continue;
  292. }
  293. }
  294. return new APIResult(new { success = true, message = "ok" });
  295. }
  296. [HttpGet]
  297. public ActionResult RenewCookie(string name)
  298. {
  299. var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
  300. if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
  301. var alimama = new AlimamaPlus(account);
  302. (bool success, string message) = alimama.RenewCookie();
  303. return new APIResult(new { success, message });
  304. }
  305. [HttpGet]
  306. public ActionResult Reload()
  307. {
  308. TkConfigCore.Refresh();
  309. EndPointCore.Refresh();
  310. ProxyNodesCore.Refresh();
  311. TkPoolCore.Refresh();
  312. VeapiPoolCore.Refresh();
  313. ApiAccountCore.Refresh();
  314. DataokeCore.Refresh();
  315. JdPoolCore.Refresh();
  316. PangolinPoolCore.Refresh();
  317. return new APIResult(new
  318. {
  319. success = true,
  320. message = "ok",
  321. });
  322. }
  323. [HttpGet]
  324. public ActionResult ReloadAccount()
  325. {
  326. EndPointCore.Refresh();
  327. ProxyNodesCore.Refresh();
  328. TkPoolCore.Refresh();
  329. VeapiPoolCore.Refresh();
  330. return new APIResult(new
  331. {
  332. success = true,
  333. message = "ok",
  334. });
  335. }
  336. }
  337. }