TaskController.cs 41 KB

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