TaskController.cs 38 KB

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