TaskController.cs 24 KB

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