| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334 |
- 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;
- namespace molilian.api.Controllers
- {
- [ApiController]
- [Route("[controller]/[action]")]
- public class TaskController : ControllerBase
- {
- protected IHttpContextAccessor _accessor;
- public TaskController(IHttpContextAccessor accessor)
- {
- _accessor = accessor;
- }
- [HttpGet]
- public ActionResult BatchInsertLogDB()
- {
- TkLogCore.BatchInsertLogDB();
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> 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 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<ActionResult> GetHistoryOrders(int id, int sleep = 2000)
- {
- 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
- {
- var alimama = new AlimamaPlus(account);
- total += alimama.GetHistoryOrders(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> 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
- 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<ActionResult> 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<ActionResult> DailyLogs(int intervalDay = 1)
- {
- try
- {
- AlimamaPlus.DailyLogs(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> GetDrawBalance()
- {
- 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.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 ActionResult 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 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;
- }
- }
- return new APIResult(new { success = true, message = "ok" });
- }
- [HttpGet]
- public async Task<ActionResult> 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 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<ActionResult> FixReport(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 DEBUG
- if (account.id != 5) continue;
- #endif
- 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<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 });
- }
- }
- }
|