TaskController.cs 48 KB

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