TaskController.cs 39 KB

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