TaskController.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  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 dy_parse_logs_{table_suffix} LIKE dy_parse_logs;";
  325. DBContext.Execute(sql, null);
  326. sql = $"CREATE TABLE IF NOT EXISTS tk_promotion_logs_{table_suffix} LIKE tk_promotion_logs;";
  327. DBContext.Execute(sql, null);
  328. sql = $"CREATE TABLE IF NOT EXISTS deeplink_parse_logs_{table_suffix} LIKE deeplink_parse_logs;";
  329. DBContext.Execute(sql, null);
  330. sql = $"CREATE TABLE IF NOT EXISTS pdd_parse_logs_{table_suffix} LIKE pdd_parse_logs;";
  331. DBContext.Execute(sql, null);
  332. }
  333. TkLogCore.save_dailys_log = true;
  334. RedisHelper.Set("turn:save_dailys_log", 1, 86400);
  335. }
  336. catch (Exception ex)
  337. {
  338. string message = $"【创建数据标错误】\n{ex.Message}\n{ex.StackTrace}";
  339. NotifyCore.Notify(new NifyMessage
  340. {
  341. message = message,
  342. priority = NifyMessagePriority.high,
  343. tags = ["red_circle"]
  344. });
  345. }
  346. return new APIResult(new { success = true, message = "ok" });
  347. }
  348. //[HttpGet]
  349. //public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
  350. //{
  351. // try
  352. // {
  353. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb);
  354. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "parse_");
  355. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "coupon_");
  356. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.wemeet, "parse_");
  357. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.bdpan, "parse_");
  358. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.dy, "parse_");
  359. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.jd, "parse_");
  360. // }
  361. // catch (Exception ex)
  362. // {
  363. // string message = $"【报表接口异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  364. // NotifyCore.Notify(new NifyMessage
  365. // {
  366. // message = message,
  367. // priority = NifyMessagePriority.high,
  368. // tags = ["red_circle"]
  369. // });
  370. // }
  371. // return new APIResult(new { success = true, message = "ok" });
  372. //}
  373. [HttpGet]
  374. public async Task<ActionResult> GetDrawBalance()
  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 (!account.enable_sync_order) continue;
  382. try
  383. {
  384. var alimama = new AlimamaPlus(account);
  385. alimama.GetDrawBalance();
  386. }
  387. catch (Exception ex)
  388. {
  389. message = $"【报表接口异常】GetDrawBalance\n{ex.Message}\n{ex.StackTrace}";
  390. NotifyCore.Notify(new NifyMessage
  391. {
  392. message = message,
  393. priority = NifyMessagePriority.high,
  394. tags = ["red_circle"]
  395. });
  396. continue;
  397. }
  398. }
  399. return new APIResult(new { success = true, message = "ok" });
  400. }
  401. [HttpGet]
  402. public async Task<ActionResult> FastReport()
  403. {
  404. string message = string.Empty;
  405. var list = TkPoolCore.List();
  406. if (list != null)
  407. {
  408. foreach (var account in list)
  409. {
  410. try
  411. {
  412. account.current_daily_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.tb, account.id, DateTime.Now.ToString("yyyyMMdd"));
  413. account.current_hourly_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.tb, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  414. new DBContext.Table("tk_pool")
  415. .Add("current_hourly_calls", account.current_hourly_calls)
  416. .Add("current_daily_calls", account.current_daily_calls)
  417. .Where("id=@id", new { account.id })
  418. .Update();
  419. }
  420. catch (Exception ex)
  421. {
  422. message = $"【TB计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  423. NotifyCore.Notify(new NifyMessage
  424. {
  425. message = message,
  426. priority = NifyMessagePriority.high,
  427. tags = ["red_circle"]
  428. });
  429. continue;
  430. }
  431. if (!account.enable_sync_order) continue;
  432. try
  433. {
  434. var alimama = new AlimamaPlus(account);
  435. alimama.SaveReportOverview();
  436. }
  437. catch (Exception ex)
  438. {
  439. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  440. NotifyCore.Notify(new NifyMessage
  441. {
  442. message = message,
  443. priority = NifyMessagePriority.high,
  444. tags = ["red_circle"]
  445. });
  446. continue;
  447. }
  448. }
  449. }
  450. string filter = "";
  451. var jd_list = new DBContext.Table("jd_pool").Where(filter, null).Select<JdPoolDTO>();
  452. if (jd_list != null)
  453. {
  454. bool any_jd_changed = false;
  455. foreach (var account in jd_list)
  456. {
  457. bool changed = false;
  458. try
  459. {
  460. account.current_daily_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.jd, account.id, DateTime.Now.ToString("yyyyMMdd"));
  461. account.current_hourly_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.jd, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  462. changed = true;
  463. any_jd_changed = true;
  464. }
  465. catch (Exception ex)
  466. {
  467. message = $"【JD计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  468. NotifyCore.Notify(new NifyMessage
  469. {
  470. message = message,
  471. priority = NifyMessagePriority.high,
  472. tags = ["red_circle"]
  473. });
  474. continue;
  475. }
  476. if (!account.status) continue;
  477. if (!string.IsNullOrEmpty(account.cookies))
  478. {
  479. try
  480. {
  481. var plus = new JdUnionPlus(account);
  482. var data = await plus.queryTodaySpreadEffectData();
  483. account.today_clickNum = data.clickNum;
  484. account.today_cosFee = data.cosFee;
  485. account.today_cosPrice = data.cosPrice;
  486. account.today_finishCosFee = data.finishCosFee;
  487. account.today_finishCosPrice = data.finishCosPrice;
  488. account.today_finishOrderNum = data.finishOrderNum;
  489. account.today_orderNum = data.orderNum;
  490. changed = true;
  491. any_jd_changed = true;
  492. }
  493. catch (Exception ex)
  494. {
  495. if (ex.Message.Contains("no login"))
  496. {
  497. account.status = false;
  498. JdPoolCore.Disabled(account.id, account.name, ex.Message);
  499. }
  500. message = $"【JD报表接口异常】{account.id}:{account.name}\tqueryTodaySpreadEffectData\n{account.Convert2Json()}\n{ex.Message}\n{ex.StackTrace}";
  501. NotifyCore.Notify(new NifyMessage
  502. {
  503. message = message,
  504. priority = NifyMessagePriority.high,
  505. tags = ["red_circle"]
  506. });
  507. continue;
  508. }
  509. }
  510. if (changed) JdPoolCore.Update(account);
  511. }
  512. if (any_jd_changed) JdPoolCore.Refresh();
  513. }
  514. var pdd_list = new DBContext.Table("pdd_pool").Where(filter, null).Select<PddPoolDTO>();
  515. if (pdd_list != null)
  516. {
  517. bool any_pdd_changed = false;
  518. foreach (var account in pdd_list)
  519. {
  520. bool changed = false;
  521. try
  522. {
  523. account.current_daily_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.pdd, account.id, DateTime.Now.ToString("yyyyMMdd"));
  524. account.current_hourly_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.pdd, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  525. changed = true;
  526. any_pdd_changed = true;
  527. }
  528. catch (Exception ex)
  529. {
  530. message = $"【Pdd计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  531. NotifyCore.Notify(new NifyMessage
  532. {
  533. message = message,
  534. priority = NifyMessagePriority.high,
  535. tags = ["red_circle"]
  536. });
  537. continue;
  538. }
  539. if (changed) PddPoolCore.Update(account);
  540. }
  541. if (any_pdd_changed) PddPoolCore.Refresh();
  542. }
  543. await EndPointCore.NotifyReload(true);
  544. return new APIResult(new { success = true, message = "ok" });
  545. }
  546. [HttpGet]
  547. public async Task<ActionResult> SaveReport()
  548. {
  549. string message = string.Empty;
  550. var list = TkPoolCore.List();
  551. if (list != null)
  552. {
  553. foreach (var account in list)
  554. {
  555. if (!account.enable_sync_order) continue;
  556. #if DEBUG
  557. if (account.id != 5) continue;
  558. #endif
  559. try
  560. {
  561. var alimama = new AlimamaPlus(account);
  562. alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
  563. alimama.SaveReportHourtrend(DateTime.Now);
  564. if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
  565. {
  566. DateTime date = DateTime.Now.AddDays(-1);
  567. alimama.FixReport(date);
  568. }
  569. }
  570. catch (Exception ex)
  571. {
  572. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  573. NotifyCore.Notify(new NifyMessage
  574. {
  575. message = message,
  576. priority = NifyMessagePriority.high,
  577. tags = ["red_circle"]
  578. });
  579. continue;
  580. }
  581. }
  582. }
  583. return new APIResult(new { success = true, message = "ok" });
  584. }
  585. [HttpGet]
  586. public async Task<ActionResult> JdSaveReport()
  587. {
  588. string message = string.Empty;
  589. var jd_list = new DBContext.Table("jd_pool").Where("", null).Select<JdPoolDTO>();
  590. if (jd_list != null)
  591. {
  592. DateTime startDate = DateTime.Now.AddDays(-89);
  593. DateTime endDate = DateTime.Now.AddDays(-1);
  594. foreach (var account in jd_list)
  595. {
  596. if (!account.status) continue;
  597. #if DEBUG
  598. if (account.id != 10) continue;
  599. #endif
  600. if (account.is_hide) continue;
  601. if (!string.IsNullOrEmpty(account.cookies))
  602. {
  603. try
  604. {
  605. var plus = new JdUnionPlus(account);
  606. _ = await plus.querySpreadEffectData(startDate, endDate);
  607. _ = await plus.queryEstimateCommList();
  608. }
  609. catch (Exception ex)
  610. {
  611. if (ex.Message.Contains("no login"))
  612. {
  613. JdPoolCore.Disabled(account.id, account.name, ex.Message);
  614. }
  615. message = $"【JD报表接口异常】{account.id}:{account.name}\tquerySpreadEffectData\n{ex.Message}\n{ex.StackTrace}";
  616. NotifyCore.Notify(new NifyMessage
  617. {
  618. message = message,
  619. priority = NifyMessagePriority.high,
  620. tags = ["red_circle"]
  621. });
  622. continue;
  623. }
  624. }
  625. }
  626. }
  627. return new APIResult(new { success = true, message = "ok" });
  628. }
  629. [HttpGet]
  630. public async Task<ActionResult> FixReport(int id, string dt)
  631. {
  632. if (!DateTime.TryParse(dt, out DateTime date))
  633. {
  634. return new APIResult(new { success = false, message = "日期错误", });
  635. }
  636. var list = TkPoolCore.List();
  637. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  638. string message = string.Empty;
  639. foreach (var account in list)
  640. {
  641. if (id != account.id) continue;
  642. try
  643. {
  644. var alimama = new AlimamaPlus(account);
  645. while (date.Date < DateTime.Now.Date)
  646. {
  647. alimama.FixReport(date);
  648. date = date.AddDays(1);
  649. }
  650. }
  651. catch (Exception ex)
  652. {
  653. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  654. NotifyCore.Notify(new NifyMessage
  655. {
  656. message = message,
  657. priority = NifyMessagePriority.high,
  658. tags = ["red_circle"]
  659. });
  660. continue;
  661. }
  662. }
  663. return new APIResult(new { success = true, message = "ok" });
  664. }
  665. [HttpGet]
  666. public ActionResult RenewCookie(string name)
  667. {
  668. var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
  669. if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
  670. var alimama = new AlimamaPlus(account);
  671. (bool success, string message) = alimama.RenewCookie();
  672. return new APIResult(new { success, message });
  673. }
  674. [HttpGet]
  675. public ActionResult Reload()
  676. {
  677. RiskControlCore.Refresh();
  678. TkConfigCore.Refresh();
  679. EndPointCore.Refresh();
  680. ProxyNodesCore.Refresh();
  681. TkPoolCore.Refresh();
  682. VeapiPoolCore.Refresh();
  683. ApiAccountCore.Refresh();
  684. DataokeCore.Refresh();
  685. JdPoolCore.Refresh();
  686. PddPoolCore.Refresh();
  687. PangolinPoolCore.Refresh();
  688. ReduPoolCore.Refresh();
  689. //ElePoolCore.Refresh();
  690. //MeituanPoolCore.Refresh();
  691. CpsPoolCore.Refresh();
  692. DeeplinkParseRuleCore.Refresh();
  693. return new APIResult(new
  694. {
  695. success = true,
  696. message = "ok",
  697. });
  698. }
  699. [HttpGet]
  700. public ActionResult ReloadAccount()
  701. {
  702. RiskControlCore.Refresh();
  703. EndPointCore.Refresh();
  704. ProxyNodesCore.Refresh();
  705. TkPoolCore.Refresh();
  706. VeapiPoolCore.Refresh();
  707. JdPoolCore.Refresh();
  708. PddPoolCore.Refresh();
  709. //ElePoolCore.Refresh();
  710. //MeituanPoolCore.Refresh();
  711. CpsPoolCore.Refresh();
  712. return new APIResult(new
  713. {
  714. success = true,
  715. message = "ok",
  716. });
  717. }
  718. [HttpGet]
  719. public async Task<ActionResult> CheckDeepUrl(int accountid)
  720. {
  721. var postContent = "88✔7Fi43dJwWpV£ https://m.tb.cn/h.g92hfR4JLgn7yvG MF7997 我分享给你了一个超赞的内容,快来看看吧";
  722. var channel = "tb";
  723. var ip = "127.0.0.1";
  724. var oaid = "test-oaid";
  725. bool success = false;
  726. string message;
  727. //============================== 放弃转链-没有匹配账号 ==============================
  728. TkPoolDTO? account = TkPoolCore.GetOne(accountid);
  729. if (account == null)
  730. {
  731. return new APIResult(new
  732. {
  733. success = false,
  734. message = "没有匹配账号",
  735. });
  736. }
  737. var alimama = new AlimamaPlus(account);
  738. TkDataDTO result = new TkDataDTO();
  739. string url = AlimamaPlus.GetLink(postContent);
  740. if (string.IsNullOrEmpty(url))
  741. {
  742. return new APIResult(new
  743. {
  744. success = false,
  745. message = "无效URL",
  746. });
  747. }
  748. (success, string content) = await alimama.GetDesiredUrlAsync(url);
  749. if (content.Contains("霸下通用 web 页面-验证码"))
  750. {
  751. message = "霸下验证码";
  752. }
  753. else
  754. {
  755. message = content;
  756. }
  757. return new APIResult(new
  758. {
  759. success = true,
  760. message,
  761. });
  762. }
  763. }
  764. }