TaskController.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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. namespace molilian.api.Controllers
  11. {
  12. [ApiController]
  13. [Route("[controller]_70160bd632/[action]")]
  14. public class TaskController : ControllerBase
  15. {
  16. protected IHttpContextAccessor _accessor;
  17. public TaskController(IHttpContextAccessor accessor)
  18. {
  19. _accessor = accessor;
  20. }
  21. [HttpGet]
  22. public ActionResult BatchInsertLogDB(int limit = 100)
  23. {
  24. int total = TkLogCore.BatchInsertLogDB(limit);
  25. return new APIResult(new { success = true, message = "ok", limit, total });
  26. }
  27. [HttpGet]
  28. public async Task<ActionResult> GetSettleBills(int sleep = 2000)
  29. {
  30. var list = TkPoolCore.List();
  31. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  32. string message = string.Empty;
  33. int total = 0;
  34. foreach (var account in list)
  35. {
  36. if (!account.enable_sync_order) continue;
  37. #if DEBUG
  38. if (13 != account.id) continue;
  39. #endif
  40. try
  41. {
  42. var alimama = new AlimamaPlus(account);
  43. total += alimama.GetSettleBills(sleep);
  44. }
  45. catch (Exception ex)
  46. {
  47. message = $"【收益接口异常】\t{account.name}\n{ex.Message}\n{ex.StackTrace}";
  48. NotifyCore.Notify(new NifyMessage
  49. {
  50. message = message,
  51. priority = NifyMessagePriority.high,
  52. tags = ["red_circle"]
  53. });
  54. continue;
  55. }
  56. }
  57. return new APIResult(new { success = true, message = "ok", total });
  58. }
  59. [HttpGet]
  60. public async Task<ActionResult> GetHistoryOrders(int id, int sleep, DateTime startTime, DateTime endTime)
  61. {
  62. var list = TkPoolCore.List();
  63. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  64. if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
  65. string message = string.Empty;
  66. int total = 0;
  67. foreach (var account in list)
  68. {
  69. if (id != account.id) continue;
  70. try
  71. {
  72. //DateTime endTime = DateTime.Now;
  73. //DateTime startTime = endTime.AddDays(-90);
  74. if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
  75. var alimama = new AlimamaPlus(account);
  76. total += alimama.GetHistoryOrders(sleep, startTime, endTime);
  77. }
  78. catch (Exception ex)
  79. {
  80. message = $"【历史订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  81. NotifyCore.Notify(new NifyMessage
  82. {
  83. message = message,
  84. priority = NifyMessagePriority.high,
  85. tags = ["red_circle"]
  86. });
  87. continue;
  88. }
  89. }
  90. return new APIResult(new { success = true, message = "ok", total });
  91. }
  92. [HttpGet]
  93. public async Task<ActionResult> GetIncyOrders(int sleep = 2000)
  94. {
  95. var list = TkPoolCore.List();
  96. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  97. string message = string.Empty;
  98. int total = 0;
  99. foreach (var account in list)
  100. {
  101. #if DEBUG
  102. if (account.id != 17) continue;
  103. #endif
  104. if (!account.enable_sync_order) continue;
  105. try
  106. {
  107. var alimama = new AlimamaPlus(account);
  108. total += alimama.GetIncyOrders(sleep);
  109. }
  110. catch (Exception ex)
  111. {
  112. message = $"【新增订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  113. NotifyCore.Notify(new NifyMessage
  114. {
  115. message = message,
  116. priority = NifyMessagePriority.high,
  117. tags = ["red_circle"]
  118. });
  119. continue;
  120. }
  121. }
  122. return new APIResult(new { success = true, message = "ok", total });
  123. }
  124. [HttpGet]
  125. public async Task<ActionResult> GetHistoryRefundOrders(int id, int sleep, DateTime startTime, DateTime endTime)
  126. {
  127. var list = TkPoolCore.List();
  128. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  129. if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
  130. string message = string.Empty;
  131. int total = 0;
  132. foreach (var account in list)
  133. {
  134. if (id != account.id) continue;
  135. try
  136. {
  137. //DateTime endTime = DateTime.Now;
  138. //DateTime startTime = endTime.AddDays(-90);
  139. if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
  140. var alimama = new AlimamaPlus(account);
  141. total += alimama.GetHistoryRefundOrders(sleep, startTime, endTime);
  142. }
  143. catch (Exception ex)
  144. {
  145. message = $"【维权订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  146. NotifyCore.Notify(new NifyMessage
  147. {
  148. message = message,
  149. priority = NifyMessagePriority.high,
  150. tags = ["red_circle"]
  151. });
  152. continue;
  153. }
  154. }
  155. return new APIResult(new { success = true, message = "ok", total });
  156. }
  157. [HttpGet]
  158. public async Task<ActionResult> GetIncyRefundOrders(int sleep = 2000)
  159. {
  160. var list = TkPoolCore.List();
  161. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  162. string message = string.Empty;
  163. int total = 0;
  164. foreach (var account in list)
  165. {
  166. #if DEBUG
  167. if (account.id != 17) continue;
  168. #endif
  169. if (!account.enable_sync_order) continue;
  170. try
  171. {
  172. var alimama = new AlimamaPlus(account);
  173. total += alimama.GetIncyRefundOrders(sleep);
  174. }
  175. catch (Exception ex)
  176. {
  177. message = $"【维权订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  178. NotifyCore.Notify(new NifyMessage
  179. {
  180. message = message,
  181. priority = NifyMessagePriority.high,
  182. tags = ["red_circle"]
  183. });
  184. continue;
  185. }
  186. }
  187. return new APIResult(new { success = true, message = "ok", total });
  188. }
  189. [HttpGet]
  190. public async Task<ActionResult> GetViolationuWarning()
  191. {
  192. var list = TkPoolCore.List();
  193. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  194. string message = string.Empty;
  195. foreach (var account in list)
  196. {
  197. try
  198. {
  199. var alimama = new AlimamaPlus(account);
  200. alimama.GetViolationuWarning();
  201. }
  202. catch (Exception ex)
  203. {
  204. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  205. NotifyCore.Notify(new NifyMessage
  206. {
  207. message = message,
  208. priority = NifyMessagePriority.high,
  209. tags = ["red_circle"]
  210. });
  211. continue;
  212. }
  213. }
  214. return new APIResult(new { success = true, message = "ok" });
  215. }
  216. [HttpGet]
  217. public async Task<ActionResult> DailyLogs(int intervalDay = 1)
  218. {
  219. try
  220. {
  221. //本节点统计
  222. AlimamaPlus.NodeDailyLogs(intervalDay, "parse_", "tb");
  223. AlimamaPlus.NodeDailyLogs(intervalDay, "coupon_", "tb");
  224. AlimamaPlus.NodeDailyLogs(intervalDay); //第三方老的统计
  225. if (CenterHub.IsCenter)
  226. {
  227. JdUnionPlus.DailyLogs(intervalDay);
  228. ToolParsePlus.DailyLogs(intervalDay);
  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. if (intervalDay > 0)
  246. {
  247. try
  248. {
  249. AlimamaPlus.ApiCallStatistics(1, intervalDay, TkChannelEnum.tb);
  250. AlimamaPlus.ApiCallStatistics(2, intervalDay, TkChannelEnum.tb);
  251. }
  252. catch (Exception ex)
  253. {
  254. string message = $"【API报表更新异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  255. NotifyCore.Notify(new NifyMessage
  256. {
  257. message = message,
  258. priority = NifyMessagePriority.high,
  259. tags = ["red_circle"]
  260. });
  261. }
  262. }
  263. return new APIResult(new { success = true, message = "ok" });
  264. }
  265. [HttpGet]
  266. public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
  267. {
  268. try
  269. {
  270. AlimamaPlus.ApiCallStatistics(1, intervalDay, TkChannelEnum.tb);
  271. AlimamaPlus.ApiCallStatistics(2, intervalDay, TkChannelEnum.tb);
  272. }
  273. catch (Exception ex)
  274. {
  275. string message = $"【API报表更新异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  276. NotifyCore.Notify(new NifyMessage
  277. {
  278. message = message,
  279. priority = NifyMessagePriority.high,
  280. tags = ["red_circle"]
  281. });
  282. }
  283. return new APIResult(new { success = true, message = "ok" });
  284. }
  285. //[HttpGet]
  286. //public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
  287. //{
  288. // try
  289. // {
  290. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb);
  291. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "parse_");
  292. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "coupon_");
  293. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.wemeet, "parse_");
  294. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.bdpan, "parse_");
  295. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.dy, "parse_");
  296. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.jd, "parse_");
  297. // }
  298. // catch (Exception ex)
  299. // {
  300. // string message = $"【报表接口异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  301. // NotifyCore.Notify(new NifyMessage
  302. // {
  303. // message = message,
  304. // priority = NifyMessagePriority.high,
  305. // tags = ["red_circle"]
  306. // });
  307. // }
  308. // return new APIResult(new { success = true, message = "ok" });
  309. //}
  310. [HttpGet]
  311. public async Task<ActionResult> GetDrawBalance()
  312. {
  313. var list = TkPoolCore.List();
  314. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  315. string message = string.Empty;
  316. foreach (var account in list)
  317. {
  318. if (!account.enable_sync_order) continue;
  319. try
  320. {
  321. var alimama = new AlimamaPlus(account);
  322. alimama.GetDrawBalance();
  323. }
  324. catch (Exception ex)
  325. {
  326. message = $"【报表接口异常】GetDrawBalance\n{ex.Message}\n{ex.StackTrace}";
  327. NotifyCore.Notify(new NifyMessage
  328. {
  329. message = message,
  330. priority = NifyMessagePriority.high,
  331. tags = ["red_circle"]
  332. });
  333. continue;
  334. }
  335. }
  336. return new APIResult(new { success = true, message = "ok" });
  337. }
  338. [HttpGet]
  339. public async Task<ActionResult> FastReport()
  340. {
  341. string message = string.Empty;
  342. var list = TkPoolCore.List();
  343. if (list != null)
  344. {
  345. foreach (var account in list)
  346. {
  347. if (!account.enable_sync_order) continue;
  348. try
  349. {
  350. var alimama = new AlimamaPlus(account);
  351. alimama.SaveReportOverview();
  352. }
  353. catch (Exception ex)
  354. {
  355. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  356. NotifyCore.Notify(new NifyMessage
  357. {
  358. message = message,
  359. priority = NifyMessagePriority.high,
  360. tags = ["red_circle"]
  361. });
  362. continue;
  363. }
  364. }
  365. }
  366. var jd_list = new DBContext.Table("jd_pool").Where("", null).Select<JdPoolDTO>();
  367. if (jd_list != null)
  368. {
  369. bool any_jd_changed = false;
  370. foreach (var account in jd_list)
  371. {
  372. bool changed = false;
  373. try
  374. {
  375. account.current_daily_calls = JdPoolCore.SaveCalls(account.id, DateTime.Now.ToString("yyyyMMdd"));
  376. account.current_hourly_calls = JdPoolCore.SaveCalls(account.id, DateTime.Now.ToString("yyyyMMddHH"));
  377. changed = true;
  378. any_jd_changed = true;
  379. }
  380. catch (Exception ex)
  381. {
  382. message = $"【JD计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  383. NotifyCore.Notify(new NifyMessage
  384. {
  385. message = message,
  386. priority = NifyMessagePriority.high,
  387. tags = ["red_circle"]
  388. });
  389. continue;
  390. }
  391. if (!account.status) continue;
  392. if (!string.IsNullOrEmpty(account.cookies))
  393. {
  394. try
  395. {
  396. var plus = new JdUnionPlus(account);
  397. var data = await plus.queryTodaySpreadEffectData();
  398. account.today_clickNum = data.clickNum;
  399. account.today_cosFee = data.cosFee;
  400. account.today_cosPrice = data.cosPrice;
  401. account.today_finishCosFee = data.finishCosFee;
  402. account.today_finishCosPrice = data.finishCosPrice;
  403. account.today_finishOrderNum = data.finishOrderNum;
  404. account.today_orderNum = data.orderNum;
  405. changed = true;
  406. any_jd_changed = true;
  407. }
  408. catch (Exception ex)
  409. {
  410. message = $"【JD报表接口异常】{account.id}:{account.name}\tqueryTodaySpreadEffectData\n{ex.Message}\n{ex.StackTrace}";
  411. NotifyCore.Notify(new NifyMessage
  412. {
  413. message = message,
  414. priority = NifyMessagePriority.high,
  415. tags = ["red_circle"]
  416. });
  417. continue;
  418. }
  419. }
  420. if (changed) JdPoolCore.Update(account);
  421. }
  422. if (any_jd_changed) JdPoolCore.Refresh();
  423. }
  424. await EndPointCore.NotifyReload(true);
  425. return new APIResult(new { success = true, message = "ok" });
  426. }
  427. [HttpGet]
  428. public async Task<ActionResult> SaveReport()
  429. {
  430. string message = string.Empty;
  431. var jd_list = new DBContext.Table("jd_pool").Where("", null).Select<JdPoolDTO>();
  432. if (jd_list != null)
  433. {
  434. foreach (var account in jd_list)
  435. {
  436. if (!account.status) continue;
  437. #if DEBUG
  438. if (account.id != 10) continue;
  439. #endif
  440. if (!string.IsNullOrEmpty(account.cookies))
  441. {
  442. try
  443. {
  444. var plus = new JdUnionPlus(account);
  445. _ = await plus.querySpreadEffectData(DateTime.Now.AddDays(-1));
  446. _ = await plus.queryEstimateCommList();
  447. }
  448. catch (Exception ex)
  449. {
  450. message = $"【JD报表接口异常】{account.id}:{account.name}\tquerySpreadEffectData\n{ex.Message}\n{ex.StackTrace}";
  451. NotifyCore.Notify(new NifyMessage
  452. {
  453. message = message,
  454. priority = NifyMessagePriority.high,
  455. tags = ["red_circle"]
  456. });
  457. continue;
  458. }
  459. }
  460. }
  461. }
  462. var list = TkPoolCore.List();
  463. if (list != null)
  464. {
  465. foreach (var account in list)
  466. {
  467. if (!account.enable_sync_order) continue;
  468. #if DEBUG
  469. if (account.id != 5) continue;
  470. #endif
  471. try
  472. {
  473. var alimama = new AlimamaPlus(account);
  474. alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
  475. alimama.SaveReportHourtrend(DateTime.Now);
  476. if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
  477. {
  478. DateTime date = DateTime.Now.AddDays(-1);
  479. alimama.FixReport(date);
  480. }
  481. }
  482. catch (Exception ex)
  483. {
  484. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  485. NotifyCore.Notify(new NifyMessage
  486. {
  487. message = message,
  488. priority = NifyMessagePriority.high,
  489. tags = ["red_circle"]
  490. });
  491. continue;
  492. }
  493. }
  494. }
  495. return new APIResult(new { success = true, message = "ok" });
  496. }
  497. [HttpGet]
  498. public async Task<ActionResult> FixReport(int id, string dt)
  499. {
  500. if (!DateTime.TryParse(dt, out DateTime date))
  501. {
  502. return new APIResult(new { success = false, message = "日期错误", });
  503. }
  504. var list = TkPoolCore.List();
  505. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  506. string message = string.Empty;
  507. foreach (var account in list)
  508. {
  509. if (id != account.id) continue;
  510. try
  511. {
  512. var alimama = new AlimamaPlus(account);
  513. while (date.Date < DateTime.Now.Date)
  514. {
  515. alimama.FixReport(date);
  516. date = date.AddDays(1);
  517. }
  518. }
  519. catch (Exception ex)
  520. {
  521. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  522. NotifyCore.Notify(new NifyMessage
  523. {
  524. message = message,
  525. priority = NifyMessagePriority.high,
  526. tags = ["red_circle"]
  527. });
  528. continue;
  529. }
  530. }
  531. return new APIResult(new { success = true, message = "ok" });
  532. }
  533. [HttpGet]
  534. public ActionResult RenewCookie(string name)
  535. {
  536. var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
  537. if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
  538. var alimama = new AlimamaPlus(account);
  539. (bool success, string message) = alimama.RenewCookie();
  540. return new APIResult(new { success, message });
  541. }
  542. [HttpGet]
  543. public ActionResult Reload()
  544. {
  545. TkConfigCore.Refresh();
  546. EndPointCore.Refresh();
  547. ProxyNodesCore.Refresh();
  548. TkPoolCore.Refresh();
  549. VeapiPoolCore.Refresh();
  550. ApiAccountCore.Refresh();
  551. DataokeCore.Refresh();
  552. JdPoolCore.Refresh();
  553. PddPoolCore.Refresh();
  554. PangolinPoolCore.Refresh();
  555. return new APIResult(new
  556. {
  557. success = true,
  558. message = "ok",
  559. });
  560. }
  561. [HttpGet]
  562. public ActionResult ReloadAccount()
  563. {
  564. EndPointCore.Refresh();
  565. ProxyNodesCore.Refresh();
  566. TkPoolCore.Refresh();
  567. VeapiPoolCore.Refresh();
  568. JdPoolCore.Refresh();
  569. return new APIResult(new
  570. {
  571. success = true,
  572. message = "ok",
  573. });
  574. }
  575. }
  576. }