TaskController.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  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. AlimamaPlus.ApiCallStatistics(1, intervalDay, TkChannelEnum.pdd);
  303. #endif
  304. }
  305. catch (Exception ex)
  306. {
  307. string message = $"【API报表更新异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  308. NotifyCore.Notify(new NifyMessage
  309. {
  310. message = message,
  311. priority = NifyMessagePriority.high,
  312. tags = ["red_circle"]
  313. });
  314. }
  315. return new APIResult(new { success = true, message = "ok" });
  316. }
  317. [HttpGet]
  318. public async Task<ActionResult> DailyTable(int days = 3)
  319. {
  320. try
  321. {
  322. for (int i = 0; i < days; i++)
  323. {
  324. if (CenterHub.IsCenter)
  325. {
  326. string table_suffix = DateTime.Now.AddDays(i).ToString("yyyyMMdd");
  327. string sql = $"CREATE TABLE IF NOT EXISTS tk_parse_logs_{table_suffix} LIKE tk_parse_logs;";
  328. DBContext.Execute(sql, null);
  329. sql = $"CREATE TABLE IF NOT EXISTS jd_parse_logs_{table_suffix} LIKE jd_parse_logs;";
  330. DBContext.Execute(sql, null);
  331. sql = $"CREATE TABLE IF NOT EXISTS ks_parse_logs_{table_suffix} LIKE ks_parse_logs;";
  332. DBContext.Execute(sql, null);
  333. sql = $"CREATE TABLE IF NOT EXISTS dy_parse_logs_{table_suffix} LIKE dy_parse_logs;";
  334. DBContext.Execute(sql, null);
  335. sql = $"CREATE TABLE IF NOT EXISTS tk_promotion_logs_{table_suffix} LIKE tk_promotion_logs;";
  336. DBContext.Execute(sql, null);
  337. sql = $"CREATE TABLE IF NOT EXISTS deeplink_parse_logs_{table_suffix} LIKE deeplink_parse_logs;";
  338. DBContext.Execute(sql, null);
  339. sql = $"CREATE TABLE IF NOT EXISTS pdd_parse_logs_{table_suffix} LIKE pdd_parse_logs;";
  340. DBContext.Execute(sql, null);
  341. }
  342. else
  343. {
  344. string table_suffix = DateTime.Now.AddDays(i).ToString("yyyyMMdd");
  345. string sql = $"CREATE TABLE IF NOT EXISTS tk_cps_logs_{table_suffix} LIKE tk_cps_logs;";
  346. DBContext.Execute(sql, null);
  347. }
  348. }
  349. TkLogCore.save_dailys_log = true;
  350. RedisHelper.Set("turn:save_dailys_log", 1, 86400);
  351. }
  352. catch (Exception ex)
  353. {
  354. string message = $"【创建数据标错误】\n{ex.Message}\n{ex.StackTrace}";
  355. NotifyCore.Notify(new NifyMessage
  356. {
  357. message = message,
  358. priority = NifyMessagePriority.high,
  359. tags = ["red_circle"]
  360. });
  361. }
  362. return new APIResult(new { success = true, message = "ok" });
  363. }
  364. //[HttpGet]
  365. //public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
  366. //{
  367. // try
  368. // {
  369. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb);
  370. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "parse_");
  371. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "coupon_");
  372. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.wemeet, "parse_");
  373. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.bdpan, "parse_");
  374. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.dy, "parse_");
  375. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.jd, "parse_");
  376. // }
  377. // catch (Exception ex)
  378. // {
  379. // string message = $"【报表接口异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  380. // NotifyCore.Notify(new NifyMessage
  381. // {
  382. // message = message,
  383. // priority = NifyMessagePriority.high,
  384. // tags = ["red_circle"]
  385. // });
  386. // }
  387. // return new APIResult(new { success = true, message = "ok" });
  388. //}
  389. [HttpGet]
  390. public async Task<ActionResult> GetDrawBalance()
  391. {
  392. var list = TkPoolCore.List();
  393. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  394. string message = string.Empty;
  395. foreach (var account in list)
  396. {
  397. if (!account.enable_sync_order) continue;
  398. try
  399. {
  400. var alimama = new AlimamaPlus(account);
  401. alimama.GetDrawBalance();
  402. }
  403. catch (Exception ex)
  404. {
  405. message = $"【报表接口异常】GetDrawBalance\n{ex.Message}\n{ex.StackTrace}";
  406. NotifyCore.Notify(new NifyMessage
  407. {
  408. message = message,
  409. priority = NifyMessagePriority.high,
  410. tags = ["red_circle"]
  411. });
  412. continue;
  413. }
  414. }
  415. return new APIResult(new { success = true, message = "ok" });
  416. }
  417. [HttpGet]
  418. public async Task<ActionResult> FastReport()
  419. {
  420. string message = string.Empty;
  421. var list = TkPoolCore.List();
  422. if (list != null)
  423. {
  424. foreach (var account in list)
  425. {
  426. try
  427. {
  428. account.current_daily_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.tb, account.id, DateTime.Now.ToString("yyyyMMdd"));
  429. account.current_hourly_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.tb, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  430. new DBContext.Table("tk_pool")
  431. .Add("current_hourly_calls", account.current_hourly_calls)
  432. .Add("current_daily_calls", account.current_daily_calls)
  433. .Where("id=@id", new { account.id })
  434. .Update();
  435. }
  436. catch (Exception ex)
  437. {
  438. message = $"【TB计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  439. NotifyCore.Notify(new NifyMessage
  440. {
  441. message = message,
  442. priority = NifyMessagePriority.high,
  443. tags = ["red_circle"]
  444. });
  445. continue;
  446. }
  447. if (!account.enable_sync_order) continue;
  448. try
  449. {
  450. var alimama = new AlimamaPlus(account);
  451. alimama.SaveReportOverview();
  452. }
  453. catch (Exception ex)
  454. {
  455. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  456. NotifyCore.Notify(new NifyMessage
  457. {
  458. message = message,
  459. priority = NifyMessagePriority.high,
  460. tags = ["red_circle"]
  461. });
  462. continue;
  463. }
  464. }
  465. }
  466. string filter = "";
  467. var jd_list = new DBContext.Table("jd_pool").Where(filter, null).Select<JdPoolDTO>();
  468. if (jd_list != null)
  469. {
  470. bool any_jd_changed = false;
  471. foreach (var account in jd_list)
  472. {
  473. bool changed = false;
  474. try
  475. {
  476. account.current_daily_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.jd, account.id, DateTime.Now.ToString("yyyyMMdd"));
  477. account.current_hourly_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.jd, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  478. changed = true;
  479. any_jd_changed = true;
  480. }
  481. catch (Exception ex)
  482. {
  483. message = $"【JD计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  484. NotifyCore.Notify(new NifyMessage
  485. {
  486. message = message,
  487. priority = NifyMessagePriority.high,
  488. tags = ["red_circle"]
  489. });
  490. continue;
  491. }
  492. if (!account.status) continue;
  493. if (!string.IsNullOrEmpty(account.cookies))
  494. {
  495. try
  496. {
  497. var plus = new JdUnionPlus(account);
  498. var data = await plus.queryTodaySpreadEffectData();
  499. account.today_clickNum = data.clickNum;
  500. account.today_cosFee = data.cosFee;
  501. account.today_cosPrice = data.cosPrice;
  502. account.today_finishCosFee = data.finishCosFee;
  503. account.today_finishCosPrice = data.finishCosPrice;
  504. account.today_finishOrderNum = data.finishOrderNum;
  505. account.today_orderNum = data.orderNum;
  506. changed = true;
  507. any_jd_changed = true;
  508. }
  509. catch (Exception ex)
  510. {
  511. if (ex.Message.Contains("no login"))
  512. {
  513. account.status = false;
  514. JdPoolCore.Disabled(account.id, account.name, ex.Message);
  515. }
  516. message = $"【JD报表接口异常】{account.id}:{account.name}\tqueryTodaySpreadEffectData\n{ex.Message}\n{ex.StackTrace}";
  517. NotifyCore.Notify(message);
  518. continue;
  519. }
  520. }
  521. if (changed) JdPoolCore.Update(account);
  522. }
  523. if (any_jd_changed) JdPoolCore.Refresh();
  524. }
  525. var pdd_list = new DBContext.Table("pdd_pool").Where(filter, null).Select<PddPoolDTO>();
  526. if (pdd_list != null)
  527. {
  528. bool any_pdd_changed = false;
  529. foreach (var account in pdd_list)
  530. {
  531. bool changed = false;
  532. try
  533. {
  534. account.current_daily_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.pdd, account.id, DateTime.Now.ToString("yyyyMMdd"));
  535. account.current_hourly_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.pdd, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  536. changed = true;
  537. any_pdd_changed = true;
  538. }
  539. catch (Exception ex)
  540. {
  541. message = $"【Pdd计数异常】SaveCalls\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. if (changed) PddPoolCore.Update(account);
  551. }
  552. if (any_pdd_changed) PddPoolCore.Refresh();
  553. }
  554. var cps_list = new DBContext.Table("cps_links")
  555. .Where("status=@status", new { status = 1 })
  556. .Select<CpsLinksDTO>();
  557. if (cps_list != null)
  558. {
  559. bool any_cps_changed = false;
  560. foreach (var link in cps_list)
  561. {
  562. bool changed = false;
  563. try
  564. {
  565. link.current_daily_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.cps, link.id, DateTime.Now.ToString("yyyyMMdd"));
  566. link.current_hourly_calls = RiskControlCore.GetAllNodesCalls(TkChannelEnum.cps, link.id, DateTime.Now.ToString("yyyyMMddHH"));
  567. changed = true;
  568. any_cps_changed = true;
  569. }
  570. catch (Exception ex)
  571. {
  572. message = $"【Cps计数异常】SaveCalls\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. if (changed) CpsPoolCore.Update(link);
  582. }
  583. if (any_cps_changed) CpsPoolCore.Refresh();
  584. }
  585. await EndPointCore.NotifyReload(true);
  586. return new APIResult(new { success = true, message = "ok" });
  587. }
  588. [HttpGet]
  589. public async Task<ActionResult> SaveReport()
  590. {
  591. string message = string.Empty;
  592. var list = TkPoolCore.List();
  593. if (list != null)
  594. {
  595. foreach (var account in list)
  596. {
  597. if (!account.enable_sync_order) continue;
  598. #if DEBUG
  599. if (account.id != 5) continue;
  600. #endif
  601. try
  602. {
  603. var alimama = new AlimamaPlus(account);
  604. alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
  605. alimama.SaveReportHourtrend(DateTime.Now);
  606. if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
  607. {
  608. DateTime date = DateTime.Now.AddDays(-1);
  609. alimama.FixReport(date);
  610. }
  611. }
  612. catch (Exception ex)
  613. {
  614. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  615. NotifyCore.Notify(new NifyMessage
  616. {
  617. message = message,
  618. priority = NifyMessagePriority.high,
  619. tags = ["red_circle"]
  620. });
  621. continue;
  622. }
  623. }
  624. }
  625. return new APIResult(new { success = true, message = "ok" });
  626. }
  627. [HttpGet]
  628. public async Task<ActionResult> JdSaveReport()
  629. {
  630. string message = string.Empty;
  631. var jd_list = new DBContext.Table("jd_pool").Where("", null).Select<JdPoolDTO>();
  632. if (jd_list != null)
  633. {
  634. DateTime startDate = DateTime.Now.AddDays(-89);
  635. DateTime endDate = DateTime.Now.AddDays(-1);
  636. foreach (var account in jd_list)
  637. {
  638. if (!account.status) continue;
  639. #if DEBUG
  640. startDate = DateTime.Parse("2024-07-31");
  641. endDate = DateTime.Parse("2024-07-31");
  642. if (account.id != 15) continue;
  643. #endif
  644. if (account.is_hide) continue;
  645. if (!string.IsNullOrEmpty(account.cookies))
  646. {
  647. try
  648. {
  649. var plus = new JdUnionPlus(account);
  650. _ = await plus.querySpreadEffectData(startDate, endDate);
  651. _ = await plus.queryEstimateCommList();
  652. }
  653. catch (Exception ex)
  654. {
  655. if (ex.Message.Contains("no login"))
  656. {
  657. JdPoolCore.Disabled(account.id, account.name, ex.Message);
  658. }
  659. message = $"【JD报表接口异常】{account.id}:{account.name}\tquerySpreadEffectData\n{ex.Message}\n{ex.StackTrace}";
  660. NotifyCore.Notify(message);
  661. continue;
  662. }
  663. }
  664. }
  665. }
  666. return new APIResult(new { success = true, message = "ok" });
  667. }
  668. [HttpGet]
  669. public async Task<ActionResult> PddSaveReport()
  670. {
  671. string message = string.Empty;
  672. var pdd_list = new DBContext.Table("pdd_pool").Where("cookie_status=1", new { }).Select<PddPoolDTO>();
  673. if (pdd_list != null)
  674. {
  675. DateTime startDate = DateTime.Now.AddDays(-91);
  676. DateTime endDate = DateTime.Now.AddDays(-1);
  677. foreach (var account in pdd_list)
  678. {
  679. if (account.is_hide) continue;
  680. if (!string.IsNullOrEmpty(account.cookies))
  681. {
  682. try
  683. {
  684. var plus = new PddUnionPlus(account);
  685. await plus.queryEstimateRevenueList(startDate, endDate);
  686. }
  687. catch (Exception ex)
  688. {
  689. if (ex.Message.Contains("43001:会话已过期"))
  690. {
  691. PddPoolCore.CookieDisabled(account.id);
  692. }
  693. message = $"【PDD报表接口异常】{account.id}:{account.name}\tqueryEstimateRevenueList\n{ex.Message}\n{ex.StackTrace}";
  694. NotifyCore.Notify(new NifyMessage
  695. {
  696. message = message,
  697. priority = NifyMessagePriority.high,
  698. tags = ["red_circle"]
  699. });
  700. continue;
  701. }
  702. }
  703. }
  704. }
  705. return new APIResult(new { success = true, message = "ok" });
  706. }
  707. [HttpGet]
  708. public async Task<ActionResult> FixReport(int id, string dt)
  709. {
  710. if (!DateTime.TryParse(dt, out DateTime date))
  711. {
  712. return new APIResult(new { success = false, message = "日期错误", });
  713. }
  714. var list = TkPoolCore.List();
  715. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  716. string message = string.Empty;
  717. foreach (var account in list)
  718. {
  719. if (id != account.id) continue;
  720. try
  721. {
  722. var alimama = new AlimamaPlus(account);
  723. while (date.Date < DateTime.Now.Date)
  724. {
  725. alimama.FixReport(date);
  726. date = date.AddDays(1);
  727. }
  728. }
  729. catch (Exception ex)
  730. {
  731. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  732. NotifyCore.Notify(new NifyMessage
  733. {
  734. message = message,
  735. priority = NifyMessagePriority.high,
  736. tags = ["red_circle"]
  737. });
  738. continue;
  739. }
  740. }
  741. return new APIResult(new { success = true, message = "ok" });
  742. }
  743. [HttpGet]
  744. public ActionResult RenewCookie(string name)
  745. {
  746. var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
  747. if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
  748. var alimama = new AlimamaPlus(account);
  749. (bool success, string message) = alimama.RenewCookie();
  750. return new APIResult(new { success, message });
  751. }
  752. [HttpGet]
  753. public ActionResult Reload()
  754. {
  755. RiskControlCore.Refresh();
  756. TkConfigCore.Refresh();
  757. EndPointCore.Refresh();
  758. ProxyNodesCore.Refresh();
  759. TkPoolCore.Refresh();
  760. VeapiPoolCore.Refresh();
  761. ApiAccountCore.Refresh();
  762. DataokeCore.Refresh();
  763. JdPoolCore.Refresh();
  764. PddPoolCore.Refresh();
  765. PangolinPoolCore.Refresh();
  766. ReduPoolCore.Refresh();
  767. //ElePoolCore.Refresh();
  768. //MeituanPoolCore.Refresh();
  769. CpsPoolCore.Refresh();
  770. DeeplinkParseRuleCore.Refresh();
  771. return new APIResult(new
  772. {
  773. success = true,
  774. message = "ok",
  775. });
  776. }
  777. [HttpGet]
  778. public ActionResult ReloadAccount()
  779. {
  780. RiskControlCore.Refresh();
  781. EndPointCore.Refresh();
  782. ProxyNodesCore.Refresh();
  783. TkPoolCore.Refresh();
  784. VeapiPoolCore.Refresh();
  785. JdPoolCore.Refresh();
  786. PddPoolCore.Refresh();
  787. //ElePoolCore.Refresh();
  788. //MeituanPoolCore.Refresh();
  789. CpsPoolCore.Refresh();
  790. return new APIResult(new
  791. {
  792. success = true,
  793. message = "ok",
  794. });
  795. }
  796. [HttpGet]
  797. public async Task<ActionResult> CheckDeepUrl(int accountid)
  798. {
  799. var postContent = "88✔7Fi43dJwWpV£ https://m.tb.cn/h.g92hfR4JLgn7yvG MF7997 我分享给你了一个超赞的内容,快来看看吧";
  800. var channel = "tb";
  801. var ip = "127.0.0.1";
  802. var oaid = "test-oaid";
  803. bool success = false;
  804. string message;
  805. //============================== 放弃转链-没有匹配账号 ==============================
  806. TkPoolDTO? account = TkPoolCore.GetOne(accountid);
  807. if (account == null)
  808. {
  809. return new APIResult(new
  810. {
  811. success = false,
  812. message = "没有匹配账号",
  813. });
  814. }
  815. var alimama = new AlimamaPlus(account);
  816. TkDataDTO result = new TkDataDTO();
  817. string url = AlimamaPlus.GetLink(postContent);
  818. if (string.IsNullOrEmpty(url))
  819. {
  820. return new APIResult(new
  821. {
  822. success = false,
  823. message = "无效URL",
  824. });
  825. }
  826. WebProxy proxy = ProxyNodesCore.RandomOne(account.nodeName);
  827. (success, string content) = await alimama.GetDesiredUrlAsync(proxy, url);
  828. if (content.Contains("霸下通用 web 页面-验证码"))
  829. {
  830. message = "霸下验证码";
  831. }
  832. else
  833. {
  834. message = content;
  835. }
  836. return new APIResult(new
  837. {
  838. success = true,
  839. message,
  840. });
  841. }
  842. }
  843. }