TaskController.cs 45 KB

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