TaskController.cs 43 KB

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