TaskController.cs 38 KB

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