TaskController.cs 39 KB

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