TaskController.cs 45 KB

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