TaskController.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. namespace molilian.api.Controllers
  10. {
  11. [ApiController]
  12. [Route("[controller]_70160bd632/[action]")]
  13. public class TaskController : ControllerBase
  14. {
  15. protected IHttpContextAccessor _accessor;
  16. public TaskController(IHttpContextAccessor accessor)
  17. {
  18. _accessor = accessor;
  19. }
  20. [HttpGet]
  21. public ActionResult BatchInsertLogDB(int limit = 100)
  22. {
  23. int total = TkLogCore.BatchInsertLogDB(limit);
  24. return new APIResult(new { success = true, message = "ok", limit, total });
  25. }
  26. [HttpGet]
  27. public async Task<ActionResult> GetSettleBills(int sleep = 2000)
  28. {
  29. var list = TkPoolCore.List();
  30. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  31. string message = string.Empty;
  32. int total = 0;
  33. foreach (var account in list)
  34. {
  35. if (!account.enable_sync_order) continue;
  36. #if DEBUG
  37. if (13 != account.id) continue;
  38. #endif
  39. try
  40. {
  41. var alimama = new AlimamaPlus(account);
  42. total += alimama.GetSettleBills(sleep);
  43. }
  44. catch (Exception ex)
  45. {
  46. message = $"【收益接口异常】\t{account.name}\n{ex.Message}\n{ex.StackTrace}";
  47. NotifyCore.Notify(new NifyMessage
  48. {
  49. message = message,
  50. priority = NifyMessagePriority.high,
  51. tags = ["red_circle"]
  52. });
  53. continue;
  54. }
  55. }
  56. return new APIResult(new { success = true, message = "ok", total });
  57. }
  58. [HttpGet]
  59. public async Task<ActionResult> GetHistoryOrders(int id, int sleep, DateTime startTime, DateTime endTime)
  60. {
  61. var list = TkPoolCore.List();
  62. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  63. if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
  64. string message = string.Empty;
  65. int total = 0;
  66. foreach (var account in list)
  67. {
  68. if (id != account.id) continue;
  69. try
  70. {
  71. //DateTime endTime = DateTime.Now;
  72. //DateTime startTime = endTime.AddDays(-90);
  73. if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
  74. var alimama = new AlimamaPlus(account);
  75. total += alimama.GetHistoryOrders(sleep, startTime, endTime);
  76. }
  77. catch (Exception ex)
  78. {
  79. message = $"【历史订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  80. NotifyCore.Notify(new NifyMessage
  81. {
  82. message = message,
  83. priority = NifyMessagePriority.high,
  84. tags = ["red_circle"]
  85. });
  86. continue;
  87. }
  88. }
  89. return new APIResult(new { success = true, message = "ok", total });
  90. }
  91. [HttpGet]
  92. public async Task<ActionResult> GetIncyOrders(int sleep = 2000)
  93. {
  94. var list = TkPoolCore.List();
  95. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  96. string message = string.Empty;
  97. int total = 0;
  98. foreach (var account in list)
  99. {
  100. #if DEBUG
  101. if (account.id != 17) continue;
  102. #endif
  103. if (!account.enable_sync_order) continue;
  104. try
  105. {
  106. var alimama = new AlimamaPlus(account);
  107. total += alimama.GetIncyOrders(sleep);
  108. }
  109. catch (Exception ex)
  110. {
  111. message = $"【新增订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  112. NotifyCore.Notify(new NifyMessage
  113. {
  114. message = message,
  115. priority = NifyMessagePriority.high,
  116. tags = ["red_circle"]
  117. });
  118. continue;
  119. }
  120. }
  121. return new APIResult(new { success = true, message = "ok", total });
  122. }
  123. [HttpGet]
  124. public async Task<ActionResult> GetHistoryRefundOrders(int id, int sleep, DateTime startTime, DateTime endTime)
  125. {
  126. var list = TkPoolCore.List();
  127. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  128. if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
  129. string message = string.Empty;
  130. int total = 0;
  131. foreach (var account in list)
  132. {
  133. if (id != account.id) continue;
  134. try
  135. {
  136. //DateTime endTime = DateTime.Now;
  137. //DateTime startTime = endTime.AddDays(-90);
  138. if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
  139. var alimama = new AlimamaPlus(account);
  140. total += alimama.GetHistoryRefundOrders(sleep, startTime, endTime);
  141. }
  142. catch (Exception ex)
  143. {
  144. message = $"【维权订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  145. NotifyCore.Notify(new NifyMessage
  146. {
  147. message = message,
  148. priority = NifyMessagePriority.high,
  149. tags = ["red_circle"]
  150. });
  151. continue;
  152. }
  153. }
  154. return new APIResult(new { success = true, message = "ok", total });
  155. }
  156. [HttpGet]
  157. public async Task<ActionResult> GetIncyRefundOrders(int sleep = 2000)
  158. {
  159. var list = TkPoolCore.List();
  160. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  161. string message = string.Empty;
  162. int total = 0;
  163. foreach (var account in list)
  164. {
  165. #if DEBUG
  166. if (account.id != 17) continue;
  167. #endif
  168. if (!account.enable_sync_order) continue;
  169. try
  170. {
  171. var alimama = new AlimamaPlus(account);
  172. total += alimama.GetIncyRefundOrders(sleep);
  173. }
  174. catch (Exception ex)
  175. {
  176. message = $"【维权订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  177. NotifyCore.Notify(new NifyMessage
  178. {
  179. message = message,
  180. priority = NifyMessagePriority.high,
  181. tags = ["red_circle"]
  182. });
  183. continue;
  184. }
  185. }
  186. return new APIResult(new { success = true, message = "ok", total });
  187. }
  188. [HttpGet]
  189. public async Task<ActionResult> GetViolationuWarning()
  190. {
  191. var list = TkPoolCore.List();
  192. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  193. string message = string.Empty;
  194. foreach (var account in list)
  195. {
  196. try
  197. {
  198. var alimama = new AlimamaPlus(account);
  199. alimama.GetViolationuWarning();
  200. }
  201. catch (Exception ex)
  202. {
  203. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  204. NotifyCore.Notify(new NifyMessage
  205. {
  206. message = message,
  207. priority = NifyMessagePriority.high,
  208. tags = ["red_circle"]
  209. });
  210. continue;
  211. }
  212. }
  213. return new APIResult(new { success = true, message = "ok" });
  214. }
  215. [HttpGet]
  216. public async Task<ActionResult> DailyLogs(int intervalDay = 1)
  217. {
  218. try
  219. {
  220. //第三方老的统计
  221. JdUnionPlus.DailyLogs(intervalDay);
  222. ToolParsePlus.DailyLogs(intervalDay);
  223. //本节点统计
  224. AlimamaPlus.NodeDailyLogs(intervalDay, "parse_", "tb");
  225. AlimamaPlus.NodeDailyLogs(intervalDay, "coupon_", "tb");
  226. AlimamaPlus.NodeDailyLogs(intervalDay); //第三方老的统计
  227. if (CenterHub.IsCenter)
  228. {
  229. //中心服务器统计
  230. AlimamaPlus.AllDailyLogs(intervalDay, "parse_", "tb");
  231. AlimamaPlus.AllDailyLogs(intervalDay, "coupon_", "tb");
  232. AlimamaPlus.AllDailyLogs(intervalDay);
  233. }
  234. }
  235. catch (Exception ex)
  236. {
  237. string message = $"【报表接口异常】DailyLogs\n{ex.Message}\n{ex.StackTrace}";
  238. NotifyCore.Notify(new NifyMessage
  239. {
  240. message = message,
  241. priority = NifyMessagePriority.high,
  242. tags = ["red_circle"]
  243. });
  244. }
  245. return new APIResult(new { success = true, message = "ok" });
  246. }
  247. [HttpGet]
  248. public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
  249. {
  250. try
  251. {
  252. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb);
  253. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "parse_");
  254. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "coupon_");
  255. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.wemeet, "parse_");
  256. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.bdpan, "parse_");
  257. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.dy, "parse_");
  258. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.jd, "parse_");
  259. }
  260. catch (Exception ex)
  261. {
  262. string message = $"【报表接口异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  263. NotifyCore.Notify(new NifyMessage
  264. {
  265. message = message,
  266. priority = NifyMessagePriority.high,
  267. tags = ["red_circle"]
  268. });
  269. }
  270. return new APIResult(new { success = true, message = "ok" });
  271. }
  272. [HttpGet]
  273. public async Task<ActionResult> GetDrawBalance()
  274. {
  275. var list = TkPoolCore.List();
  276. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  277. string message = string.Empty;
  278. foreach (var account in list)
  279. {
  280. if (!account.enable_sync_order) continue;
  281. try
  282. {
  283. var alimama = new AlimamaPlus(account);
  284. alimama.GetDrawBalance();
  285. }
  286. catch (Exception ex)
  287. {
  288. message = $"【报表接口异常】GetDrawBalance\n{ex.Message}\n{ex.StackTrace}";
  289. NotifyCore.Notify(new NifyMessage
  290. {
  291. message = message,
  292. priority = NifyMessagePriority.high,
  293. tags = ["red_circle"]
  294. });
  295. continue;
  296. }
  297. }
  298. return new APIResult(new { success = true, message = "ok" });
  299. }
  300. [HttpGet]
  301. public async Task<ActionResult> FastReport()
  302. {
  303. var list = TkPoolCore.List();
  304. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  305. string message = string.Empty;
  306. foreach (var account in list)
  307. {
  308. if (!account.enable_sync_order) continue;
  309. #if DEBUG
  310. if (account.id != 5) continue;
  311. #endif
  312. try
  313. {
  314. var alimama = new AlimamaPlus(account);
  315. alimama.SaveReportOverview();
  316. }
  317. catch (Exception ex)
  318. {
  319. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  320. NotifyCore.Notify(new NifyMessage
  321. {
  322. message = message,
  323. priority = NifyMessagePriority.high,
  324. tags = ["red_circle"]
  325. });
  326. continue;
  327. }
  328. }
  329. await EndPointCore.NotifyReload(true);
  330. return new APIResult(new { success = true, message = "ok" });
  331. }
  332. [HttpGet]
  333. public async Task<ActionResult> SaveReport()
  334. {
  335. var list = TkPoolCore.List();
  336. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  337. string message = string.Empty;
  338. foreach (var account in list)
  339. {
  340. if (!account.enable_sync_order) continue;
  341. #if DEBUG
  342. if (account.id != 5) continue;
  343. #endif
  344. try
  345. {
  346. var alimama = new AlimamaPlus(account);
  347. alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
  348. alimama.SaveReportHourtrend(DateTime.Now);
  349. if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
  350. {
  351. DateTime date = DateTime.Now.AddDays(-1);
  352. alimama.FixReport(date);
  353. }
  354. }
  355. catch (Exception ex)
  356. {
  357. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  358. NotifyCore.Notify(new NifyMessage
  359. {
  360. message = message,
  361. priority = NifyMessagePriority.high,
  362. tags = ["red_circle"]
  363. });
  364. continue;
  365. }
  366. }
  367. return new APIResult(new { success = true, message = "ok" });
  368. }
  369. [HttpGet]
  370. public async Task<ActionResult> FixReport(int id, string dt)
  371. {
  372. if (!DateTime.TryParse(dt, out DateTime date))
  373. {
  374. return new APIResult(new { success = false, message = "日期错误", });
  375. }
  376. var list = TkPoolCore.List();
  377. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  378. string message = string.Empty;
  379. foreach (var account in list)
  380. {
  381. if (id != account.id) continue;
  382. try
  383. {
  384. var alimama = new AlimamaPlus(account);
  385. while (date.Date < DateTime.Now.Date)
  386. {
  387. alimama.FixReport(date);
  388. date = date.AddDays(1);
  389. }
  390. }
  391. catch (Exception ex)
  392. {
  393. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  394. NotifyCore.Notify(new NifyMessage
  395. {
  396. message = message,
  397. priority = NifyMessagePriority.high,
  398. tags = ["red_circle"]
  399. });
  400. continue;
  401. }
  402. }
  403. return new APIResult(new { success = true, message = "ok" });
  404. }
  405. [HttpGet]
  406. public ActionResult RenewCookie(string name)
  407. {
  408. var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
  409. if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
  410. var alimama = new AlimamaPlus(account);
  411. (bool success, string message) = alimama.RenewCookie();
  412. return new APIResult(new { success, message });
  413. }
  414. [HttpGet]
  415. public ActionResult Reload()
  416. {
  417. TkConfigCore.Refresh();
  418. EndPointCore.Refresh();
  419. ProxyNodesCore.Refresh();
  420. TkPoolCore.Refresh();
  421. VeapiPoolCore.Refresh();
  422. ApiAccountCore.Refresh();
  423. DataokeCore.Refresh();
  424. JdPoolCore.Refresh();
  425. PddPoolCore.Refresh();
  426. PangolinPoolCore.Refresh();
  427. return new APIResult(new
  428. {
  429. success = true,
  430. message = "ok",
  431. });
  432. }
  433. [HttpGet]
  434. public ActionResult ReloadAccount()
  435. {
  436. EndPointCore.Refresh();
  437. ProxyNodesCore.Refresh();
  438. TkPoolCore.Refresh();
  439. VeapiPoolCore.Refresh();
  440. JdPoolCore.Refresh();
  441. return new APIResult(new
  442. {
  443. success = true,
  444. message = "ok",
  445. });
  446. }
  447. }
  448. }