TaskController.cs 38 KB

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