| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166 |
- using molilian.core;
- using dodohold.core;
- using Microsoft.AspNetCore.Mvc;
- using Org.BouncyCastle.Ocsp;
- using System.Text.Json;
- using System.Runtime.InteropServices;
- using System.Net;
- using System.Threading.Channels;
- using TencentCloud.Cdwch.V20200915.Models;
- using COSXML.Network;
- using System.Security.Cryptography;
- using System.Threading;
- using TencentCloud.Batch.V20170312.Models;
- using Org.BouncyCastle.Bcpg.OpenPgp;
- using Microsoft.VisualBasic;
- using static System.Runtime.InteropServices.JavaScript.JSType;
- namespace molilian.api.Controllers
- {
- [ApiController]
- [Route("[controller]_70160bd632/[action]")]
- public class TaskController : ControllerBase
- {
- protected IHttpContextAccessor _accessor;
- public TaskController(IHttpContextAccessor accessor)
- {
- _accessor = accessor;
- }
- [HttpGet]
- public ActionResult NotifyNotPushed()
- {
- PushDataReportCore core = new();
- int count = core.NotifyNotPushed();
- return new APIResult(new { success = true, count });
- }
- [HttpGet]
- public async Task<ActionResult> FillPushReortData(DateTime date = default)
- {
- PushDataReportCore core = new();
- if (date == default) date = DateTime.Now.AddDays(-1);
- int count = await core.FillData(date.Date);
- return new APIResult(new { success = true, count });
- }
- [HttpGet]
- public async Task<ActionResult> testReloadPushReortData()
- {
- PushDataReportCore core = new();
- DateTime sdate = DateTime.Parse("2025-01-01");
- DateTime edate = DateTime.Now.Date;
- int count = 0;
- while (sdate < edate)
- {
- count += await core.FillParseData(sdate.Date);
- sdate = sdate.AddDays(1);
- }
- return new APIResult(new { success = true, count });
- }
- [HttpGet]
- public async Task<ActionResult> testPushReportData()
- {
- PushDataReportCore core = new();
- DateTime sdate = DateTime.Parse("2025-01-01");
- DateTime edate = DateTime.Parse("2025-03-24");
- int count = 0;
- while (sdate < edate)
- {
- count += await core.PushReportData(sdate, true);
- sdate = sdate.AddDays(1);
- }
- return new APIResult(new { success = true, count });
- }
- [HttpGet]
- public async Task<ActionResult> PushReportData(int repush = 0, DateTime date = default)
- {
- PushDataReportCore core = new();
- if (date == default) date = DateTime.Now.AddDays(-1);
- int count = await core.PushReportData(date, repush == 1);
- return new APIResult(new { success = true, count });
- }
- [HttpGet]
- public async Task<ActionResult> GetRawItemIdTask(int limit = 100)
- {
- var list = await TkPoolCore.ListAsync();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- int total = 0;
- foreach (var account in list)
- {
- if (!account.enable_sync_order) continue;
- int accountId = account.id;
- DateTime create_time = DateTime.Now.AddDays(-2);
- string filter = "accountId=@accountId AND create_time>@create_time AND (itemId IS NULL OR itemId = '')";
- var order_list = new DBContext.Table("tk_order_details")
- .Where(filter, new { accountId, create_time })
- .Order("create_time")
- .Limit(limit)
- .Select<TkOrderDetailDTO>();
- if (!order_list.Any()) continue;
- var alimama = new AlimamaPlus(account);
- foreach (var item in order_list)
- {
- string mktId = item.mktId;
- //进行订单和转链匹配
- (int state, string itemId) = alimama.GetRawItemId(mktId);
- if (state == -1) return new APIResult(new { success = false, message = "有账号掉线了", });
- if (string.IsNullOrEmpty(itemId)) continue;
- item.itemId = itemId;
- new DBContext.Table("tk_order_details")
- .Add("itemId", itemId)
- .Where("id=@id", new { item.id })
- .Update();
- TkOrderTrackingCore.MatchOrder(account, item);
- }
- }
- return new APIResult(new { success = true, message = "ok", limit, total });
- }
- [HttpGet]
- public async Task<ActionResult> BatchInsertLogDB(int limit = 100)
- {
- int total = await TkLogCore.BatchInsertLogDBAsync(limit);
- return new APIResult(new { success = true, message = "ok", limit, total });
- }
- [HttpGet]
- public async Task<ActionResult> GetAaliyunBlance()
- {
- AliyunPoolCore core = new AliyunPoolCore();
- core.GetBlances();
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> GetSettleBills(int sleep = 2000)
- {
- var list = await TkPoolCore.ListAsync();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- int total = 0;
- foreach (var account in list)
- {
- if (!account.enable_sync_order) continue;
- #if DEBUG
- if (13 != account.id) continue;
- #endif
- if (account.is_hide) continue;
- try
- {
- var alimama = new AlimamaPlus(account);
- total += await alimama.GetSettleBillsAsync(sleep);
- }
- catch (Exception ex)
- {
- message = $"【收益接口异常】\t{account.name}\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- }
- return new APIResult(new { success = true, message = "ok", total });
- }
- [HttpGet]
- public async Task<ActionResult> GetHistoryOrders(int id, int sleep, DateTime startTime, DateTime endTime)
- {
- var list = await TkPoolCore.ListAsync();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- int total = 0;
- foreach (var account in list)
- {
- if (id != account.id) continue;
- try
- {
- //DateTime endTime = DateTime.Now;
- //DateTime startTime = endTime.AddDays(-90);
- if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
- var alimama = new AlimamaPlus(account);
- total = await alimama.GetHistoryOrdersAsync(sleep, startTime, endTime);
- }
- catch (Exception ex)
- {
- message = $"【历史订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- }
- return new APIResult(new { success = true, message = "ok", total });
- }
- [HttpGet]
- public async Task<ActionResult> GetIncyOrders(int sleep = 2000)
- {
- var list = await TkPoolCore.ListAsync();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- int total = 0;
- foreach (var account in list)
- {
- if (!account.enable_sync_order) continue;
- #if DEBUG
- if (account.id != 113) continue;
- #endif
- try
- {
- var alimama = new AlimamaPlus(account);
- total = await alimama.GetIncyOrdersAsync(sleep);
- }
- catch (Exception ex)
- {
- message = $"【新增订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- }
- return new APIResult(new { success = true, message = "ok", total });
- }
- [HttpGet]
- public async Task<ActionResult> GetOrdersByAdZone(int id, long adzoneId, int sleep, DateTime startTime, DateTime endTime)
- {
- var list = await TkPoolCore.ListAsync();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- int total = 0;
- foreach (var account in list)
- {
- #if DEBUG
- if (account.id != id) continue;
- #endif
- try
- {
- var alimama = new AlimamaPlus(account);
- total += await alimama.GetOrdersByAdZoneAsync(adzoneId, startTime, endTime, sleep);
- }
- catch (Exception ex)
- {
- message = $"【新增订单接口异常adzone】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- }
- return new APIResult(new { success = true, message = "ok", total });
- }
- [HttpGet]
- public async Task<ActionResult> GetHistoryRefundOrders(int id, int sleep, DateTime startTime, DateTime endTime)
- {
- var list = await TkPoolCore.ListAsync();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- int total = 0;
- foreach (var account in list)
- {
- if (id != account.id) continue;
- try
- {
- //DateTime endTime = DateTime.Now;
- //DateTime startTime = endTime.AddDays(-90);
- if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
- var alimama = new AlimamaPlus(account);
- total += await alimama.GetHistoryRefundOrdersAsync(sleep, startTime, endTime);
- }
- catch (Exception ex)
- {
- message = $"【维权订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- }
- return new APIResult(new { success = true, message = "ok", total });
- }
- [HttpGet]
- public async Task<ActionResult> GetIncyRefundOrders(int sleep = 2000)
- {
- var list = await TkPoolCore.ListAsync();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- int total = 0;
- foreach (var account in list)
- {
- #if DEBUG
- if (account.id != 17) continue;
- #endif
- if (!account.enable_sync_order) continue;
- try
- {
- var alimama = new AlimamaPlus(account);
- total += await alimama.GetIncyRefundOrdersAsync(sleep);
- }
- catch (Exception ex)
- {
- message = $"【维权订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- }
- return new APIResult(new { success = true, message = "ok", total });
- }
- [HttpGet]
- public async Task<ActionResult> GetViolationuWarning()
- {
- var list = await TkPoolCore.ListAsync();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- foreach (var account in list)
- {
- try
- {
- var alimama = new AlimamaPlus(account);
- alimama.GetViolationuWarning();
- }
- catch (Exception ex)
- {
- message = $"【报表接口异常】GetViolationuWarning\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- }
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> DailyLogs(int intervalDay = 1)
- {
- try
- {
- //本节点统计
- await AlimamaPlus.NodeDailyLogsAsync(intervalDay, "parse_", "tb");
- await AlimamaPlus.NodeDailyLogsAsync(intervalDay, "coupon_", "tb");
- await AlimamaPlus.NodeDailyLogsAsync(intervalDay); //第三方老的统计
- if (CenterHub.IsCenter)
- {
- await JdUnionPlus.DailyLogsAsync(intervalDay);
- await ToolParsePlus.DailyLogsAsync(intervalDay);
- //中心服务器统计
- await AlimamaPlus.AllDailyLogsAsync(intervalDay, "parse_", "tb");
- await AlimamaPlus.AllDailyLogsAsync(intervalDay, "coupon_", "tb");
- await KsUnionPlus.DailyLogsAsync(intervalDay);
- await PddUnionPlus.DailyLogsAsync(intervalDay);
- await AlimamaPlus.AllDailyLogsAsync(intervalDay);
- }
- }
- catch (Exception ex)
- {
- string message = $"【报表接口异常】DailyLogs\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- }
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1, int? chanel = null)
- {
- try
- {
- if (chanel == null)
- {
- #if DEBUG
- await AlimamaPlus.ApiCallStatisticsAsync(1, intervalDay, TkChannelEnum.pdd);
- #else
- await AlimamaPlus.ApiCallStatisticsAsync(1, intervalDay, TkChannelEnum.tb);
- await AlimamaPlus.ApiCallStatisticsAsync(2, intervalDay, TkChannelEnum.tb);
- await AlimamaPlus.ApiCallStatisticsAsync(1, intervalDay, TkChannelEnum.jd);
- await AlimamaPlus.ApiCallStatisticsAsync(1, intervalDay, TkChannelEnum.pdd);
- #endif
- }
- else
- {
- TkChannelEnum _chanel = (TkChannelEnum)chanel;
- await AlimamaPlus.ApiCallStatisticsAsync(1, intervalDay, _chanel);
- }
- }
- catch (Exception ex)
- {
- string message = $"【API报表更新异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- }
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> DailyTable(int days = 3)
- {
- try
- {
- for (int i = 0; i < days; i++)
- {
- if (CenterHub.IsCenter)
- {
- string table_suffix = DateTime.Now.AddDays(i).ToString("yyyyMMdd");
- string sql = $"CREATE TABLE IF NOT EXISTS tk_parse_logs_{table_suffix} LIKE tk_parse_logs;";
- DBContext.Execute(sql, null);
- sql = $"CREATE TABLE IF NOT EXISTS jd_parse_logs_{table_suffix} LIKE jd_parse_logs;";
- DBContext.Execute(sql, null);
- sql = $"CREATE TABLE IF NOT EXISTS ks_parse_logs_{table_suffix} LIKE ks_parse_logs;";
- DBContext.Execute(sql, null);
- sql = $"CREATE TABLE IF NOT EXISTS dy_parse_logs_{table_suffix} LIKE dy_parse_logs;";
- DBContext.Execute(sql, null);
- sql = $"CREATE TABLE IF NOT EXISTS tk_promotion_logs_{table_suffix} LIKE tk_promotion_logs;";
- DBContext.Execute(sql, null);
- sql = $"CREATE TABLE IF NOT EXISTS deeplink_parse_logs_{table_suffix} LIKE deeplink_parse_logs;";
- DBContext.Execute(sql, null);
- sql = $"CREATE TABLE IF NOT EXISTS pdd_parse_logs_{table_suffix} LIKE pdd_parse_logs;";
- DBContext.Execute(sql, null);
- sql = $"CREATE TABLE IF NOT EXISTS tool_parse_logs_{table_suffix} LIKE tool_parse_logs_template;";
- DBContext.Execute(sql, null);
- sql = $"CREATE TABLE IF NOT EXISTS tk_dp_logs_{table_suffix} LIKE tk_dp_logs;";
- DBContext.Execute(sql, null);
- sql = $"CREATE TABLE IF NOT EXISTS pdd_dp_logs_{table_suffix} LIKE pdd_dp_logs;";
- DBContext.Execute(sql, null);
- sql = $"CREATE TABLE IF NOT EXISTS jd_dp_logs_{table_suffix} LIKE jd_dp_logs;";
- DBContext.Execute(sql, null);
- }
- else
- {
- string table_suffix = DateTime.Now.AddDays(i).ToString("yyyyMMdd");
- string sql = $"CREATE TABLE IF NOT EXISTS tk_cps_logs_{table_suffix} LIKE tk_cps_logs;";
- DBContext.Execute(sql, null);
- sql = $"CREATE TABLE IF NOT EXISTS tk_activity_logs_{table_suffix} LIKE tk_activity_logs;";
- DBContext.Execute(sql, null);
- }
- }
- TkLogCore.save_dailys_log = true;
- RedisHelper.Set("turn:save_dailys_log", 1, 86400);
- }
- catch (Exception ex)
- {
- string message = $"【创建数据标错误】\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- }
- return new APIResult(new { success = true, message = "ok" });
- }
- //[HttpGet]
- //public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
- //{
- // try
- // {
- // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb);
- // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "parse_");
- // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "coupon_");
- // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.wemeet, "parse_");
- // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.bdpan, "parse_");
- // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.dy, "parse_");
- // AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.jd, "parse_");
- // }
- // catch (Exception ex)
- // {
- // string message = $"【报表接口异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
- // NotifyCore.Notify(new NifyMessage
- // {
- // message = message,
- // priority = NifyMessagePriority.high,
- // tags = ["red_circle"]
- // });
- // }
- // return new APIResult(new { success = true, message = "ok" });
- //}
- [HttpGet]
- public async Task<ActionResult> GetDrawBalance()
- {
- var list = await TkPoolCore.ListAsync();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- foreach (var account in list)
- {
- if (!account.enable_sync_order) continue;
- try
- {
- var alimama = new AlimamaPlus(account);
- alimama.GetDrawBalance();
- }
- catch (Exception ex)
- {
- message = $"【报表接口异常】GetDrawBalance\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- }
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> FastReport(string ignore = "")
- {
- string lockKey = "lock:FastReport";
- if (!RedisHelper.Set(lockKey, "1", 300))
- {
- string message = "【FastReport】任务正在执行中,跳过本次调用";
- _ = new LoggerLibrary("task_lock", "skip")
- .Info(message)
- .SaveAsync();
- return new APIResult(new { success = false, message = "任务正在执行中" });
- }
- var startTimestamp = DateTime.Now;
- try
- {
- string message = string.Empty;
- var list = await TkPoolCore.ListAsync();
- if (!ignore.Contains("tb") && list != null)
- {
- foreach (var account in list)
- {
- try
- {
- account.current_daily_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.tb, account.id, DateTime.Now.ToString("yyyyMMdd"));
- account.current_hourly_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.tb, account.id, DateTime.Now.ToString("yyyyMMddHH"));
- new DBContext.Table("tk_pool")
- .Add("current_hourly_calls", account.current_hourly_calls)
- .Add("current_daily_calls", account.current_daily_calls)
- .Where("id=@id", new { account.id })
- .Update();
- }
- catch (Exception ex)
- {
- message = $"【TB计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- if (!account.enable_sync_order) continue;
- try
- {
- var alimama = new AlimamaPlus(account);
- _ = alimama.SaveReportOverview();
- }
- catch (Exception ex)
- {
- message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- }
- }
- string filter = "";
- #if DEBUG
- filter = "id IN (44)";
- #endif
- var jd_list = new DBContext.Table("jd_pool").Where(filter, null).Select<JdPoolDTO>();
- if (!ignore.Contains("jd") && jd_list != null)
- {
- bool any_jd_changed = false;
- foreach (var account in jd_list)
- {
- bool changed = false;
- try
- {
- account.current_daily_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.jd, account.id, DateTime.Now.ToString("yyyyMMdd"));
- account.current_hourly_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.jd, account.id, DateTime.Now.ToString("yyyyMMddHH"));
- changed = true;
- any_jd_changed = true;
- }
- catch (Exception ex)
- {
- message = $"【JD计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- if (!account.status) continue;
- string sleepLockKey = $"lock:exception:sleep:jd_{account.id}";
- if (!string.IsNullOrEmpty(RedisHelper.Get(sleepLockKey))) continue;
- if (changed) JdPoolCore.Update(account);
- }
- if (any_jd_changed) JdPoolCore.Refresh();
- }
- var pdd_list = new DBContext.Table("pdd_pool").Where(filter, null).Select<PddPoolDTO>();
- if (!ignore.Contains("pdd") && pdd_list != null)
- {
- bool any_pdd_changed = false;
- foreach (var account in pdd_list)
- {
- bool changed = false;
- try
- {
- account.current_daily_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.pdd, account.id, DateTime.Now.ToString("yyyyMMdd"));
- account.current_hourly_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.pdd, account.id, DateTime.Now.ToString("yyyyMMddHH"));
- changed = true;
- any_pdd_changed = true;
- }
- catch (Exception ex)
- {
- message = $"【Pdd计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- if (changed) PddPoolCore.Update(account);
- }
- if (any_pdd_changed) PddPoolCore.Refresh();
- }
- var cps_list = new DBContext.Table("cps_links")
- .Where("status=@status", new { status = 1 })
- .Select<CpsLinksDTO>();
- if (!ignore.Contains("cps") && cps_list != null)
- {
- bool any_cps_changed = false;
- foreach (var link in cps_list)
- {
- bool changed = false;
- try
- {
- link.current_daily_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.cps, link.id, DateTime.Now.ToString("yyyyMMdd"));
- link.current_hourly_calls = await RiskControlCore.GetAllNodesCallsAsync(TkChannelEnum.cps, link.id, DateTime.Now.ToString("yyyyMMddHH"));
- changed = true;
- any_cps_changed = true;
- }
- catch (Exception ex)
- {
- message = $"【Cps计数异常】SaveCalls\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- if (changed) CpsPoolCore.Update(link);
- }
- if (any_cps_changed) CpsPoolCore.Refresh();
- }
- await EndPointCore.NotifyReload(true);
- return new APIResult(new { success = true, message = "ok" });
- }
- catch (Exception ex)
- {
- string errorMessage = $"【FastReport】执行异常: {ex.Message}";
- _ = new LoggerLibrary("task_error", "FastReport")
- .Info(errorMessage, ex.StackTrace)
- .SaveAsync();
- NotifyCore.Notify(new NifyMessage
- {
- message = errorMessage,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- return new APIResult(new { success = false, message = errorMessage });
- }
- finally
- {
- var executionTime = DateTime.Now - startTimestamp;
- string logMessage = $"【FastReport】执行完成,耗时: {executionTime.TotalSeconds:F2}秒";
- _ = new LoggerLibrary("task_performance", "FastReport")
- .Info(logMessage)
- .SaveAsync();
- RedisHelper.Del(lockKey);
- }
- }
- [HttpGet]
- public async Task<ActionResult> jdQuerySpreadEffectData(string ignore = "")
- {
- string message = string.Empty;
- string filter = "";
- #if DEBUG
- filter = "id IN (37, 15)";
- #endif
- var jd_list = new DBContext.Table("jd_pool").Where(filter, null).Select<JdPoolDTO>();
- if (!ignore.Contains("jd") && jd_list != null)
- {
- bool any_jd_changed = false;
- foreach (var account in jd_list)
- {
- bool changed = false;
- if (!account.status) continue;
- if (!account.enable_sync_report) continue;
- string lockKey = $"lock:exception:sleep:jd_{account.id}";
- if (!string.IsNullOrEmpty(RedisHelper.Get(lockKey))) continue;
- if (!string.IsNullOrEmpty(account.union_cookies))
- {
- try
- {
- var plus = new JdUnionPlus(account);
- var data = await plus.queryTodaySpreadEffectData();
- account.today_clickNum = data.clickNum;
- account.today_cosFee = data.cosFee;
- account.today_cosPrice = data.cosPrice;
- account.today_finishCosFee = data.finishCosFee;
- account.today_finishCosPrice = data.finishCosPrice;
- account.today_finishOrderNum = data.finishOrderNum;
- account.today_orderNum = data.orderNum;
- changed = true;
- any_jd_changed = true;
- }
- catch (Exception ex)
- {
- if (ex.Message.Contains("no login"))
- {
- account.status = false;
- _ = JdPoolCore.DisabledAsync(account.id, account.name, ex.Message);
- }
- else
- {
- RedisHelper.Set(lockKey, 1, 3600);
- }
- message = $"【JD报表接口异常】{account.id}:{account.name}\tqueryTodaySpreadEffectData\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(message);
- continue;
- }
- }
- if (changed) JdPoolCore.Update(account);
- }
- if (any_jd_changed) JdPoolCore.Refresh();
- }
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> SaveReport()
- {
- string message = string.Empty;
- var list = await TkPoolCore.ListAsync();
- if (list != null)
- {
- foreach (var account in list)
- {
- if (!account.enable_sync_order) continue;
- #if DEBUG
- if (account.id != 5) continue;
- #endif
- if (account.is_hide) continue;
- try
- {
- var alimama = new AlimamaPlus(account);
- alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
- alimama.SaveReportHourtrend(DateTime.Now);
- if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
- {
- DateTime date = DateTime.Now.AddDays(-1);
- await alimama.FixReport(date);
- }
- }
- catch (Exception ex)
- {
- message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- }
- }
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> JdSaveReport(int id = 0)
- {
- string message = string.Empty;
- string filter = string.Empty;
- if (id > 0) filter = "id=@id";
- var jd_list = new DBContext.Table("jd_pool").Where(filter, new { id }).Select<JdPoolDTO>();
- if (jd_list != null)
- {
- DateTime startDate = DateTime.Now.AddDays(-89);
- DateTime endDate = DateTime.Now.AddDays(-1);
- foreach (var account in jd_list)
- {
- if (!account.status) continue;
- #if DEBUG
- startDate = DateTime.Parse("2024-07-31");
- endDate = DateTime.Parse("2024-07-31");
- if (account.id != 15) continue;
- #endif
- if (account.is_hide) continue;
- if (id == 0 && !account.enable_sync_report) continue;
- if (!string.IsNullOrEmpty(account.union_cookies))
- {
- try
- {
- var plus = new JdUnionPlus(account);
- _ = await plus.querySpreadEffectData(startDate, endDate);
- _ = await plus.queryEstimateCommList();
- }
- catch (Exception ex)
- {
- if (ex.Message.Contains("no login"))
- {
- _ = JdPoolCore.DisabledAsync(account.id, account.name, ex.Message);
- }
- message = $"【JD报表接口异常】{account.id}:{account.name}\tquerySpreadEffectData\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(message);
- continue;
- }
- }
- }
- }
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> PddSaveReport()
- {
- string message = string.Empty;
- var pdd_list = new DBContext.Table("pdd_pool").Where("cookie_status=1", new { }).Select<PddPoolDTO>();
- if (pdd_list != null)
- {
- DateTime startDate = DateTime.Now.AddDays(-91);
- DateTime endDate = DateTime.Now.AddDays(-1);
- foreach (var account in pdd_list)
- {
- if (account.is_hide) continue;
- if (!account.enable_sync_revenue) continue;
- if (!string.IsNullOrEmpty(account.cookies))
- {
- try
- {
- var plus = new PddUnionPlus(account);
- await plus.queryEstimateRevenueList(startDate, endDate);
- }
- catch (Exception ex)
- {
- if (ex.Message.Contains("43001:会话已过期"))
- {
- PddPoolCore.CookieDisabled(account.id);
- }
- message = $"【PDD报表接口异常】{account.id}:{account.name}\tqueryEstimateRevenueList\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- }
- }
- }
- //更新前一天的pdd统计表
- await AlimamaPlus.ApiCallStatisticsAsync(1, 1, TkChannelEnum.pdd);
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> FixReport(int id, string dt)
- {
- if (!DateTime.TryParse(dt, out DateTime date))
- {
- return new APIResult(new { success = false, message = "日期错误", });
- }
- var list = await TkPoolCore.ListAsync();
- if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
- string message = string.Empty;
- foreach (var account in list)
- {
- if (id != account.id) continue;
- if (account.is_hide) continue;
- try
- {
- var alimama = new AlimamaPlus(account);
- while (date.Date < DateTime.Now.Date)
- {
- await alimama.FixReport(date);
- date = date.AddDays(1);
- }
- }
- catch (Exception ex)
- {
- message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
- NotifyCore.Notify(new NifyMessage
- {
- message = message,
- priority = NifyMessagePriority.high,
- tags = ["red_circle"]
- });
- continue;
- }
- }
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public ActionResult RenewCookie(string name)
- {
- var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
- if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
- var alimama = new AlimamaPlus(account);
- (bool success, string message) = alimama.RenewCookie();
- return new APIResult(new { success, message });
- }
- [HttpGet]
- public ActionResult Reload()
- {
- RiskControlCore.Refresh();
- TkConfigCore.Refresh();
- EndPointCore.Refresh();
- ProxyNodesCore.Refresh();
- TkPoolCore.Refresh();
- OtherApiPoolCore.Refresh();
- TkEndpointCore.Refresh();
- TkEndpointManager.Refresh();
- ApiAccountCore.Refresh();
- DataokeCore.Refresh();
- JdPoolCore.Refresh();
- PddPoolCore.Refresh();
- PangolinPoolCore.Refresh();
- ReduPoolCore.Refresh();
- //ElePoolCore.Refresh();
- //MeituanPoolCore.Refresh();
- CpsPoolCore.Refresh();
- DeeplinkParseRuleCore.Refresh();
- return new APIResult(new
- {
- success = true,
- message = "ok",
- });
- }
- [HttpGet]
- public ActionResult ReloadAccount()
- {
- RiskControlCore.Refresh();
- EndPointCore.Refresh();
- ProxyNodesCore.Refresh();
- TkPoolCore.Refresh();
- OtherApiPoolCore.Refresh();
- JdPoolCore.Refresh();
- PddPoolCore.Refresh();
- //ElePoolCore.Refresh();
- //MeituanPoolCore.Refresh();
- CpsPoolCore.Refresh();
- return new APIResult(new
- {
- success = true,
- message = "ok",
- });
- }
- [HttpGet]
- public async Task<ActionResult> CheckDeepUrl(int accountid)
- {
- var postContent = "88✔7Fi43dJwWpV£ https://m.tb.cn/h.g92hfR4JLgn7yvG MF7997 我分享给你了一个超赞的内容,快来看看吧";
- var channel = "tb";
- var ip = "127.0.0.1";
- var oaid = "test-oaid";
- bool success = false;
- string message;
- //============================== 放弃转链-没有匹配账号 ==============================
- TkPoolDTO? account = await TkPoolCore.GetOneAsync(accountid);
- if (account == null)
- {
- return new APIResult(new
- {
- success = false,
- message = "没有匹配账号",
- });
- }
- var alimama = new AlimamaPlus(account);
- TkDataDTO result = new TkDataDTO();
- string url = AlimamaPlus.GetLink(postContent);
- if (string.IsNullOrEmpty(url))
- {
- return new APIResult(new
- {
- success = false,
- message = "无效URL",
- });
- }
- WebProxy proxy = ProxyNodesCore.RandomOne(account.nodeName);
- (success, string content) = await alimama.GetDesiredUrlAsync(proxy, url);
- if (content.Contains("霸下通用 web 页面-验证码"))
- {
- message = "霸下验证码";
- }
- else
- {
- message = content;
- }
- return new APIResult(new
- {
- success = true,
- message,
- });
- }
- }
- }
|