TaskController.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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. AlimamaPlus.NodeDailyLogs(intervalDay, "parse_", "tb");
  222. AlimamaPlus.NodeDailyLogs(intervalDay, "coupon_", "tb");
  223. AlimamaPlus.NodeDailyLogs(intervalDay); //第三方老的统计
  224. if (CenterHub.IsCenter)
  225. {
  226. JdUnionPlus.DailyLogs(intervalDay);
  227. ToolParsePlus.DailyLogs(intervalDay);
  228. //中心服务器统计
  229. AlimamaPlus.AllDailyLogs(intervalDay, "parse_", "tb");
  230. AlimamaPlus.AllDailyLogs(intervalDay, "coupon_", "tb");
  231. AlimamaPlus.AllDailyLogs(intervalDay);
  232. }
  233. }
  234. catch (Exception ex)
  235. {
  236. string message = $"【报表接口异常】DailyLogs\n{ex.Message}\n{ex.StackTrace}";
  237. NotifyCore.Notify(new NifyMessage
  238. {
  239. message = message,
  240. priority = NifyMessagePriority.high,
  241. tags = ["red_circle"]
  242. });
  243. }
  244. return new APIResult(new { success = true, message = "ok" });
  245. }
  246. [HttpGet]
  247. public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
  248. {
  249. try
  250. {
  251. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb);
  252. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "parse_");
  253. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "coupon_");
  254. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.wemeet, "parse_");
  255. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.bdpan, "parse_");
  256. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.dy, "parse_");
  257. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.jd, "parse_");
  258. }
  259. catch (Exception ex)
  260. {
  261. string message = $"【报表接口异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  262. NotifyCore.Notify(new NifyMessage
  263. {
  264. message = message,
  265. priority = NifyMessagePriority.high,
  266. tags = ["red_circle"]
  267. });
  268. }
  269. return new APIResult(new { success = true, message = "ok" });
  270. }
  271. [HttpGet]
  272. public async Task<ActionResult> GetDrawBalance()
  273. {
  274. var list = TkPoolCore.List();
  275. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  276. string message = string.Empty;
  277. foreach (var account in list)
  278. {
  279. if (!account.enable_sync_order) continue;
  280. try
  281. {
  282. var alimama = new AlimamaPlus(account);
  283. alimama.GetDrawBalance();
  284. }
  285. catch (Exception ex)
  286. {
  287. message = $"【报表接口异常】GetDrawBalance\n{ex.Message}\n{ex.StackTrace}";
  288. NotifyCore.Notify(new NifyMessage
  289. {
  290. message = message,
  291. priority = NifyMessagePriority.high,
  292. tags = ["red_circle"]
  293. });
  294. continue;
  295. }
  296. }
  297. return new APIResult(new { success = true, message = "ok" });
  298. }
  299. [HttpGet]
  300. public async Task<ActionResult> FastReport()
  301. {
  302. string message = string.Empty;
  303. var list = TkPoolCore.List();
  304. if (list != null)
  305. {
  306. foreach (var account in list)
  307. {
  308. if (!account.enable_sync_order) continue;
  309. try
  310. {
  311. var alimama = new AlimamaPlus(account);
  312. alimama.SaveReportOverview();
  313. }
  314. catch (Exception ex)
  315. {
  316. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  317. NotifyCore.Notify(new NifyMessage
  318. {
  319. message = message,
  320. priority = NifyMessagePriority.high,
  321. tags = ["red_circle"]
  322. });
  323. continue;
  324. }
  325. }
  326. }
  327. var jd_list = new DBContext.Table("jd_pool").Where("", null).Select<JdPoolDTO>();
  328. if (jd_list != null)
  329. {
  330. foreach (var account in jd_list)
  331. {
  332. try
  333. {
  334. account.current_daily_calls = JdPoolCore.SaveCalls(account.id, DateTime.Now.ToString("yyyyMMdd"));
  335. account.current_hourly_calls = JdPoolCore.SaveCalls(account.id, DateTime.Now.ToString("yyyyMMddHH"));
  336. JdPoolCore.Update(account);
  337. }
  338. catch (Exception ex)
  339. {
  340. message = $"【JD计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  341. NotifyCore.Notify(new NifyMessage
  342. {
  343. message = message,
  344. priority = NifyMessagePriority.high,
  345. tags = ["red_circle"]
  346. });
  347. continue;
  348. }
  349. }
  350. JdPoolCore.Refresh();
  351. }
  352. await EndPointCore.NotifyReload(true);
  353. return new APIResult(new { success = true, message = "ok" });
  354. }
  355. [HttpGet]
  356. public async Task<ActionResult> SaveReport()
  357. {
  358. var list = TkPoolCore.List();
  359. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  360. string message = string.Empty;
  361. foreach (var account in list)
  362. {
  363. if (!account.enable_sync_order) continue;
  364. #if DEBUG
  365. if (account.id != 5) continue;
  366. #endif
  367. try
  368. {
  369. var alimama = new AlimamaPlus(account);
  370. alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
  371. alimama.SaveReportHourtrend(DateTime.Now);
  372. if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
  373. {
  374. DateTime date = DateTime.Now.AddDays(-1);
  375. alimama.FixReport(date);
  376. }
  377. }
  378. catch (Exception ex)
  379. {
  380. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  381. NotifyCore.Notify(new NifyMessage
  382. {
  383. message = message,
  384. priority = NifyMessagePriority.high,
  385. tags = ["red_circle"]
  386. });
  387. continue;
  388. }
  389. }
  390. return new APIResult(new { success = true, message = "ok" });
  391. }
  392. [HttpGet]
  393. public async Task<ActionResult> FixReport(int id, string dt)
  394. {
  395. if (!DateTime.TryParse(dt, out DateTime date))
  396. {
  397. return new APIResult(new { success = false, message = "日期错误", });
  398. }
  399. var list = TkPoolCore.List();
  400. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  401. string message = string.Empty;
  402. foreach (var account in list)
  403. {
  404. if (id != account.id) continue;
  405. try
  406. {
  407. var alimama = new AlimamaPlus(account);
  408. while (date.Date < DateTime.Now.Date)
  409. {
  410. alimama.FixReport(date);
  411. date = date.AddDays(1);
  412. }
  413. }
  414. catch (Exception ex)
  415. {
  416. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  417. NotifyCore.Notify(new NifyMessage
  418. {
  419. message = message,
  420. priority = NifyMessagePriority.high,
  421. tags = ["red_circle"]
  422. });
  423. continue;
  424. }
  425. }
  426. return new APIResult(new { success = true, message = "ok" });
  427. }
  428. [HttpGet]
  429. public ActionResult RenewCookie(string name)
  430. {
  431. var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
  432. if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
  433. var alimama = new AlimamaPlus(account);
  434. (bool success, string message) = alimama.RenewCookie();
  435. return new APIResult(new { success, message });
  436. }
  437. [HttpGet]
  438. public ActionResult Reload()
  439. {
  440. TkConfigCore.Refresh();
  441. EndPointCore.Refresh();
  442. ProxyNodesCore.Refresh();
  443. TkPoolCore.Refresh();
  444. VeapiPoolCore.Refresh();
  445. ApiAccountCore.Refresh();
  446. DataokeCore.Refresh();
  447. JdPoolCore.Refresh();
  448. PddPoolCore.Refresh();
  449. PangolinPoolCore.Refresh();
  450. return new APIResult(new
  451. {
  452. success = true,
  453. message = "ok",
  454. });
  455. }
  456. [HttpGet]
  457. public ActionResult ReloadAccount()
  458. {
  459. EndPointCore.Refresh();
  460. ProxyNodesCore.Refresh();
  461. TkPoolCore.Refresh();
  462. VeapiPoolCore.Refresh();
  463. JdPoolCore.Refresh();
  464. return new APIResult(new
  465. {
  466. success = true,
  467. message = "ok",
  468. });
  469. }
  470. }
  471. }