TaskController.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  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. using System.Security.Cryptography;
  12. using System.Threading;
  13. using TencentCloud.Batch.V20170312.Models;
  14. namespace molilian.api.Controllers
  15. {
  16. [ApiController]
  17. [Route("[controller]_70160bd632/[action]")]
  18. public class TaskController : ControllerBase
  19. {
  20. protected IHttpContextAccessor _accessor;
  21. public TaskController(IHttpContextAccessor accessor)
  22. {
  23. _accessor = accessor;
  24. }
  25. [HttpGet]
  26. public async Task<ActionResult> BatchInsertLogDB(int limit = 100)
  27. {
  28. int total = await TkLogCore.BatchInsertLogDBAsync(limit);
  29. return new APIResult(new { success = true, message = "ok", limit, total });
  30. }
  31. [HttpGet]
  32. public async Task<ActionResult> GetSettleBills(int sleep = 2000)
  33. {
  34. var list = TkPoolCore.List();
  35. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  36. string message = string.Empty;
  37. int total = 0;
  38. foreach (var account in list)
  39. {
  40. if (!account.enable_sync_order) continue;
  41. #if DEBUG
  42. if (13 != account.id) continue;
  43. #endif
  44. try
  45. {
  46. var alimama = new AlimamaPlus(account);
  47. total += alimama.GetSettleBills(sleep);
  48. }
  49. catch (Exception ex)
  50. {
  51. message = $"【收益接口异常】\t{account.name}\n{ex.Message}\n{ex.StackTrace}";
  52. NotifyCore.Notify(new NifyMessage
  53. {
  54. message = message,
  55. priority = NifyMessagePriority.high,
  56. tags = ["red_circle"]
  57. });
  58. continue;
  59. }
  60. }
  61. return new APIResult(new { success = true, message = "ok", total });
  62. }
  63. [HttpGet]
  64. public async Task<ActionResult> GetHistoryOrders(int id, int sleep, DateTime startTime, DateTime endTime)
  65. {
  66. var list = TkPoolCore.List();
  67. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  68. if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
  69. string message = string.Empty;
  70. int total = 0;
  71. foreach (var account in list)
  72. {
  73. if (id != account.id) continue;
  74. try
  75. {
  76. //DateTime endTime = DateTime.Now;
  77. //DateTime startTime = endTime.AddDays(-90);
  78. if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
  79. var alimama = new AlimamaPlus(account);
  80. total += alimama.GetHistoryOrders(sleep, startTime, endTime);
  81. }
  82. catch (Exception ex)
  83. {
  84. message = $"【历史订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  85. NotifyCore.Notify(new NifyMessage
  86. {
  87. message = message,
  88. priority = NifyMessagePriority.high,
  89. tags = ["red_circle"]
  90. });
  91. continue;
  92. }
  93. }
  94. return new APIResult(new { success = true, message = "ok", total });
  95. }
  96. [HttpGet]
  97. public async Task<ActionResult> GetIncyOrders(int sleep = 2000)
  98. {
  99. var list = TkPoolCore.List();
  100. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  101. string message = string.Empty;
  102. int total = 0;
  103. foreach (var account in list)
  104. {
  105. #if DEBUG
  106. if (account.id != 17) continue;
  107. #endif
  108. if (!account.enable_sync_order) continue;
  109. try
  110. {
  111. var alimama = new AlimamaPlus(account);
  112. total += alimama.GetIncyOrders(sleep);
  113. }
  114. catch (Exception ex)
  115. {
  116. message = $"【新增订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  117. NotifyCore.Notify(new NifyMessage
  118. {
  119. message = message,
  120. priority = NifyMessagePriority.high,
  121. tags = ["red_circle"]
  122. });
  123. continue;
  124. }
  125. }
  126. return new APIResult(new { success = true, message = "ok", total });
  127. }
  128. [HttpGet]
  129. public async Task<ActionResult> GetOrdersByAdZone(int id, long adzoneId, int sleep, DateTime startTime, DateTime endTime)
  130. {
  131. var list = TkPoolCore.List();
  132. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  133. string message = string.Empty;
  134. int total = 0;
  135. foreach (var account in list)
  136. {
  137. #if DEBUG
  138. if (account.id != id) continue;
  139. #endif
  140. try
  141. {
  142. var alimama = new AlimamaPlus(account);
  143. total += alimama.GetOrdersByAdZone(adzoneId, startTime, endTime, sleep);
  144. }
  145. catch (Exception ex)
  146. {
  147. message = $"【新增订单接口异常adzone】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  148. NotifyCore.Notify(new NifyMessage
  149. {
  150. message = message,
  151. priority = NifyMessagePriority.high,
  152. tags = ["red_circle"]
  153. });
  154. continue;
  155. }
  156. }
  157. return new APIResult(new { success = true, message = "ok", total });
  158. }
  159. [HttpGet]
  160. public async Task<ActionResult> GetHistoryRefundOrders(int id, int sleep, DateTime startTime, DateTime endTime)
  161. {
  162. var list = TkPoolCore.List();
  163. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  164. if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
  165. string message = string.Empty;
  166. int total = 0;
  167. foreach (var account in list)
  168. {
  169. if (id != account.id) continue;
  170. try
  171. {
  172. //DateTime endTime = DateTime.Now;
  173. //DateTime startTime = endTime.AddDays(-90);
  174. if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
  175. var alimama = new AlimamaPlus(account);
  176. total += alimama.GetHistoryRefundOrders(sleep, startTime, endTime);
  177. }
  178. catch (Exception ex)
  179. {
  180. message = $"【维权订单接口异常】[{account.id}]{account.company}\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", total });
  191. }
  192. [HttpGet]
  193. public async Task<ActionResult> GetIncyRefundOrders(int sleep = 2000)
  194. {
  195. var list = TkPoolCore.List();
  196. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  197. string message = string.Empty;
  198. int total = 0;
  199. foreach (var account in list)
  200. {
  201. #if DEBUG
  202. if (account.id != 17) continue;
  203. #endif
  204. if (!account.enable_sync_order) continue;
  205. try
  206. {
  207. var alimama = new AlimamaPlus(account);
  208. total += alimama.GetIncyRefundOrders(sleep);
  209. }
  210. catch (Exception ex)
  211. {
  212. message = $"【维权订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  213. NotifyCore.Notify(new NifyMessage
  214. {
  215. message = message,
  216. priority = NifyMessagePriority.high,
  217. tags = ["red_circle"]
  218. });
  219. continue;
  220. }
  221. }
  222. return new APIResult(new { success = true, message = "ok", total });
  223. }
  224. [HttpGet]
  225. public async Task<ActionResult> GetViolationuWarning()
  226. {
  227. var list = TkPoolCore.List();
  228. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  229. string message = string.Empty;
  230. foreach (var account in list)
  231. {
  232. try
  233. {
  234. var alimama = new AlimamaPlus(account);
  235. alimama.GetViolationuWarning();
  236. }
  237. catch (Exception ex)
  238. {
  239. message = $"【报表接口异常】GetViolationuWarning\n{ex.Message}\n{ex.StackTrace}";
  240. NotifyCore.Notify(new NifyMessage
  241. {
  242. message = message,
  243. priority = NifyMessagePriority.high,
  244. tags = ["red_circle"]
  245. });
  246. continue;
  247. }
  248. }
  249. return new APIResult(new { success = true, message = "ok" });
  250. }
  251. [HttpGet]
  252. public async Task<ActionResult> DailyLogs(int intervalDay = 1)
  253. {
  254. try
  255. {
  256. //本节点统计
  257. AlimamaPlus.NodeDailyLogs(intervalDay, "parse_", "tb");
  258. AlimamaPlus.NodeDailyLogs(intervalDay, "coupon_", "tb");
  259. AlimamaPlus.NodeDailyLogs(intervalDay); //第三方老的统计
  260. if (CenterHub.IsCenter)
  261. {
  262. JdUnionPlus.DailyLogs(intervalDay);
  263. ToolParsePlus.DailyLogs(intervalDay);
  264. //中心服务器统计
  265. AlimamaPlus.AllDailyLogs(intervalDay, "parse_", "tb");
  266. AlimamaPlus.AllDailyLogs(intervalDay, "coupon_", "tb");
  267. KsUnionPlus.DailyLogs(intervalDay);
  268. PddUnionPlus.DailyLogs(intervalDay);
  269. AlimamaPlus.AllDailyLogs(intervalDay);
  270. }
  271. }
  272. catch (Exception ex)
  273. {
  274. string message = $"【报表接口异常】DailyLogs\n{ex.Message}\n{ex.StackTrace}";
  275. NotifyCore.Notify(new NifyMessage
  276. {
  277. message = message,
  278. priority = NifyMessagePriority.high,
  279. tags = ["red_circle"]
  280. });
  281. }
  282. return new APIResult(new { success = true, message = "ok" });
  283. }
  284. [HttpGet]
  285. public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
  286. {
  287. try
  288. {
  289. AlimamaPlus.ApiCallStatistics(1, intervalDay, TkChannelEnum.tb);
  290. AlimamaPlus.ApiCallStatistics(2, intervalDay, TkChannelEnum.tb);
  291. }
  292. catch (Exception ex)
  293. {
  294. string message = $"【API报表更新异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  295. NotifyCore.Notify(new NifyMessage
  296. {
  297. message = message,
  298. priority = NifyMessagePriority.high,
  299. tags = ["red_circle"]
  300. });
  301. }
  302. return new APIResult(new { success = true, message = "ok" });
  303. }
  304. [HttpGet]
  305. public async Task<ActionResult> DailyTable(int days = 3)
  306. {
  307. try
  308. {
  309. for (int i = 0; i < days; i++)
  310. {
  311. if (CenterHub.IsCenter)
  312. {
  313. }
  314. else
  315. {
  316. }
  317. string table_suffix = DateTime.Now.AddDays(i).ToString("yyyyMMdd");
  318. string sql = $"CREATE TABLE IF NOT EXISTS tk_parse_logs_{table_suffix} LIKE tk_parse_logs;";
  319. DBContext.Execute(sql, null);
  320. sql = $"CREATE TABLE IF NOT EXISTS jd_parse_logs_{table_suffix} LIKE jd_parse_logs;";
  321. DBContext.Execute(sql, null);
  322. sql = $"CREATE TABLE IF NOT EXISTS ks_parse_logs_{table_suffix} LIKE ks_parse_logs;";
  323. DBContext.Execute(sql, null);
  324. sql = $"CREATE TABLE IF NOT EXISTS tk_promotion_logs_{table_suffix} LIKE tk_promotion_logs;";
  325. DBContext.Execute(sql, null);
  326. sql = $"CREATE TABLE IF NOT EXISTS deeplink_parse_logs_{table_suffix} LIKE deeplink_parse_logs;";
  327. DBContext.Execute(sql, null);
  328. sql = $"CREATE TABLE IF NOT EXISTS pdd_parse_logs_{table_suffix} LIKE pdd_parse_logs;";
  329. DBContext.Execute(sql, null);
  330. }
  331. TkLogCore.save_dailys_log = true;
  332. RedisHelper.Set("turn:save_dailys_log", 1, 86400);
  333. }
  334. catch (Exception ex)
  335. {
  336. string message = $"【创建数据标错误】\n{ex.Message}\n{ex.StackTrace}";
  337. NotifyCore.Notify(new NifyMessage
  338. {
  339. message = message,
  340. priority = NifyMessagePriority.high,
  341. tags = ["red_circle"]
  342. });
  343. }
  344. return new APIResult(new { success = true, message = "ok" });
  345. }
  346. //[HttpGet]
  347. //public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
  348. //{
  349. // try
  350. // {
  351. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb);
  352. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "parse_");
  353. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "coupon_");
  354. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.wemeet, "parse_");
  355. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.bdpan, "parse_");
  356. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.dy, "parse_");
  357. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.jd, "parse_");
  358. // }
  359. // catch (Exception ex)
  360. // {
  361. // string message = $"【报表接口异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  362. // NotifyCore.Notify(new NifyMessage
  363. // {
  364. // message = message,
  365. // priority = NifyMessagePriority.high,
  366. // tags = ["red_circle"]
  367. // });
  368. // }
  369. // return new APIResult(new { success = true, message = "ok" });
  370. //}
  371. [HttpGet]
  372. public async Task<ActionResult> GetDrawBalance()
  373. {
  374. var list = TkPoolCore.List();
  375. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  376. string message = string.Empty;
  377. foreach (var account in list)
  378. {
  379. if (!account.enable_sync_order) continue;
  380. try
  381. {
  382. var alimama = new AlimamaPlus(account);
  383. alimama.GetDrawBalance();
  384. }
  385. catch (Exception ex)
  386. {
  387. message = $"【报表接口异常】GetDrawBalance\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. }
  397. return new APIResult(new { success = true, message = "ok" });
  398. }
  399. [HttpGet]
  400. public async Task<ActionResult> FastReport()
  401. {
  402. string message = string.Empty;
  403. var list = TkPoolCore.List();
  404. if (list != null)
  405. {
  406. foreach (var account in list)
  407. {
  408. try
  409. {
  410. account.current_daily_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.tb, account.id, DateTime.Now.ToString("yyyyMMdd"));
  411. account.current_hourly_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.tb, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  412. new DBContext.Table("tk_pool")
  413. .Add("current_hourly_calls", account.current_hourly_calls)
  414. .Add("current_daily_calls", account.current_daily_calls)
  415. .Where("id=@id", new { account.id })
  416. .Update();
  417. }
  418. catch (Exception ex)
  419. {
  420. message = $"【TB计数异常】SaveCalls\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. if (!account.enable_sync_order) continue;
  430. try
  431. {
  432. var alimama = new AlimamaPlus(account);
  433. alimama.SaveReportOverview();
  434. }
  435. catch (Exception ex)
  436. {
  437. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  438. NotifyCore.Notify(new NifyMessage
  439. {
  440. message = message,
  441. priority = NifyMessagePriority.high,
  442. tags = ["red_circle"]
  443. });
  444. continue;
  445. }
  446. }
  447. }
  448. string filter = "";
  449. var jd_list = new DBContext.Table("jd_pool").Where(filter, null).Select<JdPoolDTO>();
  450. if (jd_list != null)
  451. {
  452. bool any_jd_changed = false;
  453. foreach (var account in jd_list)
  454. {
  455. bool changed = false;
  456. try
  457. {
  458. account.current_daily_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.jd, account.id, DateTime.Now.ToString("yyyyMMdd"));
  459. account.current_hourly_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.jd, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  460. changed = true;
  461. any_jd_changed = true;
  462. }
  463. catch (Exception ex)
  464. {
  465. message = $"【JD计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  466. NotifyCore.Notify(new NifyMessage
  467. {
  468. message = message,
  469. priority = NifyMessagePriority.high,
  470. tags = ["red_circle"]
  471. });
  472. continue;
  473. }
  474. if (!account.status) continue;
  475. if (!string.IsNullOrEmpty(account.cookies))
  476. {
  477. try
  478. {
  479. var plus = new JdUnionPlus(account);
  480. var data = await plus.queryTodaySpreadEffectData();
  481. account.today_clickNum = data.clickNum;
  482. account.today_cosFee = data.cosFee;
  483. account.today_cosPrice = data.cosPrice;
  484. account.today_finishCosFee = data.finishCosFee;
  485. account.today_finishCosPrice = data.finishCosPrice;
  486. account.today_finishOrderNum = data.finishOrderNum;
  487. account.today_orderNum = data.orderNum;
  488. changed = true;
  489. any_jd_changed = true;
  490. }
  491. catch (Exception ex)
  492. {
  493. if (ex.Message.Contains("no login"))
  494. {
  495. account.status = false;
  496. JdPoolCore.Disabled(account.id, account.name, ex.Message);
  497. }
  498. message = $"【JD报表接口异常】{account.id}:{account.name}\tqueryTodaySpreadEffectData\n{account.Convert2Json()}\n{ex.Message}\n{ex.StackTrace}";
  499. NotifyCore.Notify(new NifyMessage
  500. {
  501. message = message,
  502. priority = NifyMessagePriority.high,
  503. tags = ["red_circle"]
  504. });
  505. continue;
  506. }
  507. }
  508. if (changed) JdPoolCore.Update(account);
  509. }
  510. if (any_jd_changed) JdPoolCore.Refresh();
  511. }
  512. var pdd_list = new DBContext.Table("pdd_pool").Where(filter, null).Select<PddPoolDTO>();
  513. if (pdd_list != null)
  514. {
  515. bool any_pdd_changed = false;
  516. foreach (var account in pdd_list)
  517. {
  518. bool changed = false;
  519. try
  520. {
  521. account.current_daily_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.pdd, account.id, DateTime.Now.ToString("yyyyMMdd"));
  522. account.current_hourly_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.pdd, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  523. changed = true;
  524. any_pdd_changed = true;
  525. }
  526. catch (Exception ex)
  527. {
  528. message = $"【Pdd计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  529. NotifyCore.Notify(new NifyMessage
  530. {
  531. message = message,
  532. priority = NifyMessagePriority.high,
  533. tags = ["red_circle"]
  534. });
  535. continue;
  536. }
  537. if (changed) PddPoolCore.Update(account);
  538. }
  539. if (any_pdd_changed) PddPoolCore.Refresh();
  540. }
  541. await EndPointCore.NotifyReload(true);
  542. return new APIResult(new { success = true, message = "ok" });
  543. }
  544. [HttpGet]
  545. public async Task<ActionResult> SaveReport()
  546. {
  547. string message = string.Empty;
  548. var list = TkPoolCore.List();
  549. if (list != null)
  550. {
  551. foreach (var account in list)
  552. {
  553. if (!account.enable_sync_order) continue;
  554. #if DEBUG
  555. if (account.id != 5) continue;
  556. #endif
  557. try
  558. {
  559. var alimama = new AlimamaPlus(account);
  560. alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
  561. alimama.SaveReportHourtrend(DateTime.Now);
  562. if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
  563. {
  564. DateTime date = DateTime.Now.AddDays(-1);
  565. alimama.FixReport(date);
  566. }
  567. }
  568. catch (Exception ex)
  569. {
  570. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  571. NotifyCore.Notify(new NifyMessage
  572. {
  573. message = message,
  574. priority = NifyMessagePriority.high,
  575. tags = ["red_circle"]
  576. });
  577. continue;
  578. }
  579. }
  580. }
  581. return new APIResult(new { success = true, message = "ok" });
  582. }
  583. [HttpGet]
  584. public async Task<ActionResult> JdSaveReport()
  585. {
  586. string message = string.Empty;
  587. var jd_list = new DBContext.Table("jd_pool").Where("", null).Select<JdPoolDTO>();
  588. if (jd_list != null)
  589. {
  590. DateTime startDate = DateTime.Now.AddDays(-89);
  591. DateTime endDate = DateTime.Now.AddDays(-1);
  592. foreach (var account in jd_list)
  593. {
  594. if (!account.status) continue;
  595. #if DEBUG
  596. if (account.id != 10) continue;
  597. #endif
  598. if (account.is_hide) continue;
  599. if (!string.IsNullOrEmpty(account.cookies))
  600. {
  601. try
  602. {
  603. var plus = new JdUnionPlus(account);
  604. _ = await plus.querySpreadEffectData(startDate, endDate);
  605. _ = await plus.queryEstimateCommList();
  606. }
  607. catch (Exception ex)
  608. {
  609. if (ex.Message.Contains("no login"))
  610. {
  611. JdPoolCore.Disabled(account.id, account.name, ex.Message);
  612. }
  613. message = $"【JD报表接口异常】{account.id}:{account.name}\tquerySpreadEffectData\n{ex.Message}\n{ex.StackTrace}";
  614. NotifyCore.Notify(new NifyMessage
  615. {
  616. message = message,
  617. priority = NifyMessagePriority.high,
  618. tags = ["red_circle"]
  619. });
  620. continue;
  621. }
  622. }
  623. }
  624. }
  625. return new APIResult(new { success = true, message = "ok" });
  626. }
  627. [HttpGet]
  628. public async Task<ActionResult> FixReport(int id, string dt)
  629. {
  630. if (!DateTime.TryParse(dt, out DateTime date))
  631. {
  632. return new APIResult(new { success = false, message = "日期错误", });
  633. }
  634. var list = TkPoolCore.List();
  635. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  636. string message = string.Empty;
  637. foreach (var account in list)
  638. {
  639. if (id != account.id) continue;
  640. try
  641. {
  642. var alimama = new AlimamaPlus(account);
  643. while (date.Date < DateTime.Now.Date)
  644. {
  645. alimama.FixReport(date);
  646. date = date.AddDays(1);
  647. }
  648. }
  649. catch (Exception ex)
  650. {
  651. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  652. NotifyCore.Notify(new NifyMessage
  653. {
  654. message = message,
  655. priority = NifyMessagePriority.high,
  656. tags = ["red_circle"]
  657. });
  658. continue;
  659. }
  660. }
  661. return new APIResult(new { success = true, message = "ok" });
  662. }
  663. [HttpGet]
  664. public ActionResult RenewCookie(string name)
  665. {
  666. var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
  667. if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
  668. var alimama = new AlimamaPlus(account);
  669. (bool success, string message) = alimama.RenewCookie();
  670. return new APIResult(new { success, message });
  671. }
  672. [HttpGet]
  673. public ActionResult Reload()
  674. {
  675. RiskControlCore.Refresh();
  676. TkConfigCore.Refresh();
  677. EndPointCore.Refresh();
  678. ProxyNodesCore.Refresh();
  679. TkPoolCore.Refresh();
  680. VeapiPoolCore.Refresh();
  681. ApiAccountCore.Refresh();
  682. DataokeCore.Refresh();
  683. JdPoolCore.Refresh();
  684. PddPoolCore.Refresh();
  685. PangolinPoolCore.Refresh();
  686. //ElePoolCore.Refresh();
  687. //MeituanPoolCore.Refresh();
  688. CpsPoolCore.Refresh();
  689. DeeplinkParseRuleCore.Refresh();
  690. return new APIResult(new
  691. {
  692. success = true,
  693. message = "ok",
  694. });
  695. }
  696. [HttpGet]
  697. public ActionResult ReloadAccount()
  698. {
  699. RiskControlCore.Refresh();
  700. EndPointCore.Refresh();
  701. ProxyNodesCore.Refresh();
  702. TkPoolCore.Refresh();
  703. VeapiPoolCore.Refresh();
  704. JdPoolCore.Refresh();
  705. PddPoolCore.Refresh();
  706. //ElePoolCore.Refresh();
  707. //MeituanPoolCore.Refresh();
  708. CpsPoolCore.Refresh();
  709. return new APIResult(new
  710. {
  711. success = true,
  712. message = "ok",
  713. });
  714. }
  715. [HttpGet]
  716. public async Task<ActionResult> CheckDeepUrl(int accountid)
  717. {
  718. var postContent = "88✔7Fi43dJwWpV£ https://m.tb.cn/h.g92hfR4JLgn7yvG MF7997 我分享给你了一个超赞的内容,快来看看吧";
  719. var channel = "tb";
  720. var ip = "127.0.0.1";
  721. var oaid = "test-oaid";
  722. bool success = false;
  723. string message;
  724. //============================== 放弃转链-没有匹配账号 ==============================
  725. TkPoolDTO? account = TkPoolCore.GetOne(accountid);
  726. if (account == null)
  727. {
  728. return new APIResult(new
  729. {
  730. success = false,
  731. message = "没有匹配账号",
  732. });
  733. }
  734. var alimama = new AlimamaPlus(account);
  735. TkDataDTO result = new TkDataDTO();
  736. string url = AlimamaPlus.GetLink(postContent);
  737. if (string.IsNullOrEmpty(url))
  738. {
  739. return new APIResult(new
  740. {
  741. success = false,
  742. message = "无效URL",
  743. });
  744. }
  745. (success, string content) = await alimama.GetDesiredUrlAsync(url);
  746. if (content.Contains("霸下通用 web 页面-验证码"))
  747. {
  748. message = "霸下验证码";
  749. }
  750. else
  751. {
  752. message = content;
  753. }
  754. return new APIResult(new
  755. {
  756. success = true,
  757. message,
  758. });
  759. }
  760. }
  761. }