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; 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 BatchInsertLogDB(int limit = 100) { int total = TkLogCore.BatchInsertLogDB(limit); return new APIResult(new { success = true, message = "ok", limit, total }); } [HttpGet] public async Task GetSettleBills(int sleep = 2000) { var list = TkPoolCore.List(); 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 try { var alimama = new AlimamaPlus(account); total += alimama.GetSettleBills(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 GetHistoryOrders(int id, int sleep, DateTime startTime, DateTime endTime) { var list = TkPoolCore.List(); 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 += alimama.GetHistoryOrders(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 GetIncyOrders(int sleep = 2000) { var list = TkPoolCore.List(); 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 += alimama.GetIncyOrders(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 GetHistoryRefundOrders(int id, int sleep, DateTime startTime, DateTime endTime) { var list = TkPoolCore.List(); 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 += alimama.GetHistoryRefundOrders(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 GetIncyRefundOrders(int sleep = 2000) { var list = TkPoolCore.List(); 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 += alimama.GetIncyRefundOrders(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 GetViolationuWarning() { var list = TkPoolCore.List(); 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 = $"【报表接口异常】FastReport\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 DailyLogs(int intervalDay = 1) { try { //第三方老的统计 JdUnionPlus.DailyLogs(intervalDay); ToolParsePlus.DailyLogs(intervalDay); //本节点统计 AlimamaPlus.NodeDailyLogs(intervalDay, "parse_", "tb"); AlimamaPlus.NodeDailyLogs(intervalDay, "coupon_", "tb"); AlimamaPlus.NodeDailyLogs(intervalDay); //第三方老的统计 if (CenterHub.IsCenter) { //中心服务器统计 AlimamaPlus.AllDailyLogs(intervalDay, "parse_", "tb"); AlimamaPlus.AllDailyLogs(intervalDay, "coupon_", "tb"); AlimamaPlus.AllDailyLogs(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 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 GetDrawBalance() { var list = TkPoolCore.List(); 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 FastReport() { var list = TkPoolCore.List(); 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; #if DEBUG if (account.id != 5) continue; #endif 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; } } await EndPointCore.NotifyReload(true); return new APIResult(new { success = true, message = "ok" }); } [HttpGet] public async Task SaveReport() { var list = TkPoolCore.List(); 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; #if DEBUG if (account.id != 5) continue; #endif 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); 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 FixReport(int id, string dt) { if (!DateTime.TryParse(dt, out DateTime date)) { return new APIResult(new { success = false, message = "日期错误", }); } var list = TkPoolCore.List(); if (list == null) return new APIResult(new { success = false, message = "没有有效账号", }); string message = string.Empty; foreach (var account in list) { if (id != account.id) continue; try { var alimama = new AlimamaPlus(account); while (date.Date < DateTime.Now.Date) { 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("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() { TkConfigCore.Refresh(); EndPointCore.Refresh(); ProxyNodesCore.Refresh(); TkPoolCore.Refresh(); VeapiPoolCore.Refresh(); ApiAccountCore.Refresh(); DataokeCore.Refresh(); JdPoolCore.Refresh(); PddPoolCore.Refresh(); PangolinPoolCore.Refresh(); return new APIResult(new { success = true, message = "ok", }); } [HttpGet] public ActionResult ReloadAccount() { EndPointCore.Refresh(); ProxyNodesCore.Refresh(); TkPoolCore.Refresh(); VeapiPoolCore.Refresh(); JdPoolCore.Refresh(); return new APIResult(new { success = true, message = "ok", }); } } }