TaskController.cs 43 KB

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