TaskController.cs 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  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. sql = $"CREATE TABLE IF NOT EXISTS tool_parse_logs_{table_suffix} LIKE tool_parse_logs_template;";
  432. DBContext.Execute(sql, null);
  433. sql = $"CREATE TABLE IF NOT EXISTS tk_dp_logs_{table_suffix} LIKE tk_dp_logs;";
  434. DBContext.Execute(sql, null);
  435. sql = $"CREATE TABLE IF NOT EXISTS pdd_dp_logs_{table_suffix} LIKE pdd_dp_logs;";
  436. DBContext.Execute(sql, null);
  437. sql = $"CREATE TABLE IF NOT EXISTS jd_dp_logs_{table_suffix} LIKE jd_dp_logs;";
  438. DBContext.Execute(sql, null);
  439. }
  440. else
  441. {
  442. string table_suffix = DateTime.Now.AddDays(i).ToString("yyyyMMdd");
  443. string sql = $"CREATE TABLE IF NOT EXISTS tk_cps_logs_{table_suffix} LIKE tk_cps_logs;";
  444. DBContext.Execute(sql, null);
  445. }
  446. }
  447. TkLogCore.save_dailys_log = true;
  448. RedisHelper.Set("turn:save_dailys_log", 1, 86400);
  449. }
  450. catch (Exception ex)
  451. {
  452. string message = $"【创建数据标错误】\n{ex.Message}\n{ex.StackTrace}";
  453. NotifyCore.Notify(new NifyMessage
  454. {
  455. message = message,
  456. priority = NifyMessagePriority.high,
  457. tags = ["red_circle"]
  458. });
  459. }
  460. return new APIResult(new { success = true, message = "ok" });
  461. }
  462. //[HttpGet]
  463. //public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
  464. //{
  465. // try
  466. // {
  467. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb);
  468. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "parse_");
  469. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "coupon_");
  470. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.wemeet, "parse_");
  471. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.bdpan, "parse_");
  472. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.dy, "parse_");
  473. // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.jd, "parse_");
  474. // }
  475. // catch (Exception ex)
  476. // {
  477. // string message = $"【报表接口异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  478. // NotifyCore.Notify(new NifyMessage
  479. // {
  480. // message = message,
  481. // priority = NifyMessagePriority.high,
  482. // tags = ["red_circle"]
  483. // });
  484. // }
  485. // return new APIResult(new { success = true, message = "ok" });
  486. //}
  487. [HttpGet]
  488. public async Task<ActionResult> GetDrawBalance()
  489. {
  490. var list = await TkPoolCore.ListAsync();
  491. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  492. string message = string.Empty;
  493. foreach (var account in list)
  494. {
  495. if (!account.enable_sync_order) continue;
  496. try
  497. {
  498. var alimama = new AlimamaPlus(account);
  499. alimama.GetDrawBalance();
  500. }
  501. catch (Exception ex)
  502. {
  503. message = $"【报表接口异常】GetDrawBalance\n{ex.Message}\n{ex.StackTrace}";
  504. NotifyCore.Notify(new NifyMessage
  505. {
  506. message = message,
  507. priority = NifyMessagePriority.high,
  508. tags = ["red_circle"]
  509. });
  510. continue;
  511. }
  512. }
  513. return new APIResult(new { success = true, message = "ok" });
  514. }
  515. [HttpGet]
  516. public async Task<ActionResult> FastReport(string ignore = "")
  517. {
  518. string message = string.Empty;
  519. var list = await TkPoolCore.ListAsync();
  520. if (!ignore.Contains("tb") && list != null)
  521. {
  522. foreach (var account in list)
  523. {
  524. #if DEBUG
  525. if (account.id != 38) continue;
  526. #endif
  527. try
  528. {
  529. account.current_daily_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.tb, account.id, DateTime.Now.ToString("yyyyMMdd"));
  530. account.current_hourly_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.tb, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  531. new DBContext.Table("tk_pool")
  532. .Add("current_hourly_calls", account.current_hourly_calls)
  533. .Add("current_daily_calls", account.current_daily_calls)
  534. .Where("id=@id", new { account.id })
  535. .Update();
  536. }
  537. catch (Exception ex)
  538. {
  539. message = $"【TB计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  540. NotifyCore.Notify(new NifyMessage
  541. {
  542. message = message,
  543. priority = NifyMessagePriority.high,
  544. tags = ["red_circle"]
  545. });
  546. continue;
  547. }
  548. if (!account.enable_sync_order) continue;
  549. try
  550. {
  551. var alimama = new AlimamaPlus(account);
  552. alimama.SaveReportOverview();
  553. }
  554. catch (Exception ex)
  555. {
  556. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  557. NotifyCore.Notify(new NifyMessage
  558. {
  559. message = message,
  560. priority = NifyMessagePriority.high,
  561. tags = ["red_circle"]
  562. });
  563. continue;
  564. }
  565. }
  566. }
  567. string filter = "";
  568. #if DEBUG
  569. filter = "id IN (37, 15)";
  570. #endif
  571. var jd_list = new DBContext.Table("jd_pool").Where(filter, null).Select<JdPoolDTO>();
  572. if (!ignore.Contains("jd") && jd_list != null)
  573. {
  574. bool any_jd_changed = false;
  575. foreach (var account in jd_list)
  576. {
  577. bool changed = false;
  578. try
  579. {
  580. account.current_daily_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.jd, account.id, DateTime.Now.ToString("yyyyMMdd"));
  581. account.current_hourly_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.jd, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  582. changed = true;
  583. any_jd_changed = true;
  584. }
  585. catch (Exception ex)
  586. {
  587. message = $"【JD计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  588. NotifyCore.Notify(new NifyMessage
  589. {
  590. message = message,
  591. priority = NifyMessagePriority.high,
  592. tags = ["red_circle"]
  593. });
  594. continue;
  595. }
  596. if (!account.status) continue;
  597. string lockKey = $"lock:exception:sleep:jd_{account.id}";
  598. if (!string.IsNullOrEmpty(RedisHelper.Get(lockKey))) continue;
  599. if (changed) JdPoolCore.Update(account);
  600. }
  601. if (any_jd_changed) JdPoolCore.Refresh();
  602. }
  603. var pdd_list = new DBContext.Table("pdd_pool").Where(filter, null).Select<PddPoolDTO>();
  604. if (!ignore.Contains("pdd") && pdd_list != null)
  605. {
  606. bool any_pdd_changed = false;
  607. foreach (var account in pdd_list)
  608. {
  609. bool changed = false;
  610. try
  611. {
  612. account.current_daily_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.pdd, account.id, DateTime.Now.ToString("yyyyMMdd"));
  613. account.current_hourly_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.pdd, account.id, DateTime.Now.ToString("yyyyMMddHH"));
  614. changed = true;
  615. any_pdd_changed = true;
  616. }
  617. catch (Exception ex)
  618. {
  619. message = $"【Pdd计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  620. NotifyCore.Notify(new NifyMessage
  621. {
  622. message = message,
  623. priority = NifyMessagePriority.high,
  624. tags = ["red_circle"]
  625. });
  626. continue;
  627. }
  628. if (changed) PddPoolCore.Update(account);
  629. }
  630. if (any_pdd_changed) PddPoolCore.Refresh();
  631. }
  632. var cps_list = new DBContext.Table("cps_links")
  633. .Where("status=@status", new { status = 1 })
  634. .Select<CpsLinksDTO>();
  635. if (!ignore.Contains("cps") && cps_list != null)
  636. {
  637. bool any_cps_changed = false;
  638. foreach (var link in cps_list)
  639. {
  640. bool changed = false;
  641. try
  642. {
  643. link.current_daily_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.cps, link.id, DateTime.Now.ToString("yyyyMMdd"));
  644. link.current_hourly_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.cps, link.id, DateTime.Now.ToString("yyyyMMddHH"));
  645. changed = true;
  646. any_cps_changed = true;
  647. }
  648. catch (Exception ex)
  649. {
  650. message = $"【Cps计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
  651. NotifyCore.Notify(new NifyMessage
  652. {
  653. message = message,
  654. priority = NifyMessagePriority.high,
  655. tags = ["red_circle"]
  656. });
  657. continue;
  658. }
  659. if (changed) CpsPoolCore.Update(link);
  660. }
  661. if (any_cps_changed) CpsPoolCore.Refresh();
  662. }
  663. await EndPointCore.NotifyReload(true);
  664. return new APIResult(new { success = true, message = "ok" });
  665. }
  666. [HttpGet]
  667. public async Task<ActionResult> jdQuerySpreadEffectData(string ignore = "")
  668. {
  669. string message = string.Empty;
  670. string filter = "";
  671. #if DEBUG
  672. filter = "id IN (37, 15)";
  673. #endif
  674. var jd_list = new DBContext.Table("jd_pool").Where(filter, null).Select<JdPoolDTO>();
  675. if (!ignore.Contains("jd") && jd_list != null)
  676. {
  677. bool any_jd_changed = false;
  678. foreach (var account in jd_list)
  679. {
  680. bool changed = false;
  681. if (!account.status) continue;
  682. string lockKey = $"lock:exception:sleep:jd_{account.id}";
  683. if (!string.IsNullOrEmpty(RedisHelper.Get(lockKey))) continue;
  684. if (!string.IsNullOrEmpty(account.union_cookies))
  685. {
  686. try
  687. {
  688. var plus = new JdUnionPlus(account);
  689. var data = await plus.queryTodaySpreadEffectData();
  690. account.today_clickNum = data.clickNum;
  691. account.today_cosFee = data.cosFee;
  692. account.today_cosPrice = data.cosPrice;
  693. account.today_finishCosFee = data.finishCosFee;
  694. account.today_finishCosPrice = data.finishCosPrice;
  695. account.today_finishOrderNum = data.finishOrderNum;
  696. account.today_orderNum = data.orderNum;
  697. changed = true;
  698. any_jd_changed = true;
  699. }
  700. catch (Exception ex)
  701. {
  702. if (ex.Message.Contains("no login"))
  703. {
  704. account.status = false;
  705. _ = JdPoolCore.DisabledAsync(account.id, account.name, ex.Message);
  706. }
  707. else
  708. {
  709. RedisHelper.Set(lockKey, 1, 3600);
  710. }
  711. message = $"【JD报表接口异常】{account.id}:{account.name}\tqueryTodaySpreadEffectData\n{ex.Message}\n{ex.StackTrace}";
  712. NotifyCore.Notify(message);
  713. continue;
  714. }
  715. }
  716. if (changed) JdPoolCore.Update(account);
  717. }
  718. if (any_jd_changed) JdPoolCore.Refresh();
  719. }
  720. return new APIResult(new { success = true, message = "ok" });
  721. }
  722. [HttpGet]
  723. public async Task<ActionResult> SaveReport()
  724. {
  725. string message = string.Empty;
  726. var list = await TkPoolCore.ListAsync();
  727. if (list != null)
  728. {
  729. foreach (var account in list)
  730. {
  731. if (!account.enable_sync_order) continue;
  732. #if DEBUG
  733. if (account.id != 5) continue;
  734. #endif
  735. if (account.is_hide) continue;
  736. try
  737. {
  738. var alimama = new AlimamaPlus(account);
  739. alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
  740. alimama.SaveReportHourtrend(DateTime.Now);
  741. if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
  742. {
  743. DateTime date = DateTime.Now.AddDays(-1);
  744. await alimama.FixReport(date);
  745. }
  746. }
  747. catch (Exception ex)
  748. {
  749. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  750. NotifyCore.Notify(new NifyMessage
  751. {
  752. message = message,
  753. priority = NifyMessagePriority.high,
  754. tags = ["red_circle"]
  755. });
  756. continue;
  757. }
  758. }
  759. }
  760. return new APIResult(new { success = true, message = "ok" });
  761. }
  762. [HttpGet]
  763. public async Task<ActionResult> JdSaveReport()
  764. {
  765. string message = string.Empty;
  766. var jd_list = new DBContext.Table("jd_pool").Where("", null).Select<JdPoolDTO>();
  767. if (jd_list != null)
  768. {
  769. DateTime startDate = DateTime.Now.AddDays(-89);
  770. DateTime endDate = DateTime.Now.AddDays(-1);
  771. foreach (var account in jd_list)
  772. {
  773. if (!account.status) continue;
  774. #if DEBUG
  775. startDate = DateTime.Parse("2024-07-31");
  776. endDate = DateTime.Parse("2024-07-31");
  777. if (account.id != 15) continue;
  778. #endif
  779. if (account.is_hide) continue;
  780. if (!string.IsNullOrEmpty(account.union_cookies))
  781. {
  782. try
  783. {
  784. var plus = new JdUnionPlus(account);
  785. _ = await plus.querySpreadEffectData(startDate, endDate);
  786. _ = await plus.queryEstimateCommList();
  787. }
  788. catch (Exception ex)
  789. {
  790. if (ex.Message.Contains("no login"))
  791. {
  792. _ = JdPoolCore.DisabledAsync(account.id, account.name, ex.Message);
  793. }
  794. message = $"【JD报表接口异常】{account.id}:{account.name}\tquerySpreadEffectData\n{ex.Message}\n{ex.StackTrace}";
  795. NotifyCore.Notify(message);
  796. continue;
  797. }
  798. }
  799. }
  800. }
  801. return new APIResult(new { success = true, message = "ok" });
  802. }
  803. [HttpGet]
  804. public async Task<ActionResult> PddSaveReport()
  805. {
  806. string message = string.Empty;
  807. var pdd_list = new DBContext.Table("pdd_pool").Where("cookie_status=1", new { }).Select<PddPoolDTO>();
  808. if (pdd_list != null)
  809. {
  810. DateTime startDate = DateTime.Now.AddDays(-91);
  811. DateTime endDate = DateTime.Now.AddDays(-1);
  812. foreach (var account in pdd_list)
  813. {
  814. if (account.is_hide) continue;
  815. if (!account.enable_sync_revenue) continue;
  816. if (!string.IsNullOrEmpty(account.cookies))
  817. {
  818. try
  819. {
  820. var plus = new PddUnionPlus(account);
  821. await plus.queryEstimateRevenueList(startDate, endDate);
  822. }
  823. catch (Exception ex)
  824. {
  825. if (ex.Message.Contains("43001:会话已过期"))
  826. {
  827. PddPoolCore.CookieDisabled(account.id);
  828. }
  829. message = $"【PDD报表接口异常】{account.id}:{account.name}\tqueryEstimateRevenueList\n{ex.Message}\n{ex.StackTrace}";
  830. NotifyCore.Notify(new NifyMessage
  831. {
  832. message = message,
  833. priority = NifyMessagePriority.high,
  834. tags = ["red_circle"]
  835. });
  836. continue;
  837. }
  838. }
  839. }
  840. }
  841. //更新前一天的pdd统计表
  842. await AlimamaPlus.ApiCallStatisticsAsync(1, 1, TkChannelEnum.pdd);
  843. return new APIResult(new { success = true, message = "ok" });
  844. }
  845. [HttpGet]
  846. public async Task<ActionResult> FixReport(int id, string dt)
  847. {
  848. if (!DateTime.TryParse(dt, out DateTime date))
  849. {
  850. return new APIResult(new { success = false, message = "日期错误", });
  851. }
  852. var list = await TkPoolCore.ListAsync();
  853. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  854. string message = string.Empty;
  855. foreach (var account in list)
  856. {
  857. if (id != account.id) continue;
  858. if (account.is_hide) continue;
  859. try
  860. {
  861. var alimama = new AlimamaPlus(account);
  862. while (date.Date < DateTime.Now.Date)
  863. {
  864. await alimama.FixReport(date);
  865. date = date.AddDays(1);
  866. }
  867. }
  868. catch (Exception ex)
  869. {
  870. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  871. NotifyCore.Notify(new NifyMessage
  872. {
  873. message = message,
  874. priority = NifyMessagePriority.high,
  875. tags = ["red_circle"]
  876. });
  877. continue;
  878. }
  879. }
  880. return new APIResult(new { success = true, message = "ok" });
  881. }
  882. [HttpGet]
  883. public ActionResult RenewCookie(string name)
  884. {
  885. var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
  886. if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
  887. var alimama = new AlimamaPlus(account);
  888. (bool success, string message) = alimama.RenewCookie();
  889. return new APIResult(new { success, message });
  890. }
  891. [HttpGet]
  892. public ActionResult Reload()
  893. {
  894. RiskControlCore.Refresh();
  895. TkConfigCore.Refresh();
  896. EndPointCore.Refresh();
  897. ProxyNodesCore.Refresh();
  898. TkPoolCore.Refresh();
  899. OtherApiPoolCore.Refresh();
  900. TkEndpointCore.Refresh();
  901. TkEndpointManager.Refresh();
  902. ApiAccountCore.Refresh();
  903. DataokeCore.Refresh();
  904. JdPoolCore.Refresh();
  905. PddPoolCore.Refresh();
  906. PangolinPoolCore.Refresh();
  907. ReduPoolCore.Refresh();
  908. //ElePoolCore.Refresh();
  909. //MeituanPoolCore.Refresh();
  910. CpsPoolCore.Refresh();
  911. DeeplinkParseRuleCore.Refresh();
  912. return new APIResult(new
  913. {
  914. success = true,
  915. message = "ok",
  916. });
  917. }
  918. [HttpGet]
  919. public ActionResult ReloadAccount()
  920. {
  921. RiskControlCore.Refresh();
  922. EndPointCore.Refresh();
  923. ProxyNodesCore.Refresh();
  924. TkPoolCore.Refresh();
  925. OtherApiPoolCore.Refresh();
  926. JdPoolCore.Refresh();
  927. PddPoolCore.Refresh();
  928. //ElePoolCore.Refresh();
  929. //MeituanPoolCore.Refresh();
  930. CpsPoolCore.Refresh();
  931. return new APIResult(new
  932. {
  933. success = true,
  934. message = "ok",
  935. });
  936. }
  937. [HttpGet]
  938. public async Task<ActionResult> CheckDeepUrl(int accountid)
  939. {
  940. var postContent = "88✔7Fi43dJwWpV£ https://m.tb.cn/h.g92hfR4JLgn7yvG MF7997 我分享给你了一个超赞的内容,快来看看吧";
  941. var channel = "tb";
  942. var ip = "127.0.0.1";
  943. var oaid = "test-oaid";
  944. bool success = false;
  945. string message;
  946. //============================== 放弃转链-没有匹配账号 ==============================
  947. TkPoolDTO? account = await TkPoolCore.GetOneAsync(accountid);
  948. if (account == null)
  949. {
  950. return new APIResult(new
  951. {
  952. success = false,
  953. message = "没有匹配账号",
  954. });
  955. }
  956. var alimama = new AlimamaPlus(account);
  957. TkDataDTO result = new TkDataDTO();
  958. string url = AlimamaPlus.GetLink(postContent);
  959. if (string.IsNullOrEmpty(url))
  960. {
  961. return new APIResult(new
  962. {
  963. success = false,
  964. message = "无效URL",
  965. });
  966. }
  967. WebProxy proxy = ProxyNodesCore.RandomOne(account.nodeName);
  968. (success, string content) = await alimama.GetDesiredUrlAsync(proxy, url);
  969. if (content.Contains("霸下通用 web 页面-验证码"))
  970. {
  971. message = "霸下验证码";
  972. }
  973. else
  974. {
  975. message = content;
  976. }
  977. return new APIResult(new
  978. {
  979. success = true,
  980. message,
  981. });
  982. }
  983. }
  984. }