TaskController.cs 40 KB

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