TaskController.cs 36 KB

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