TaskController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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. namespace molilian.api.Controllers
  10. {
  11. [ApiController]
  12. [Route("[controller]_70160bd632/[action]")]
  13. public class TaskController : ControllerBase
  14. {
  15. protected IHttpContextAccessor _accessor;
  16. public TaskController(IHttpContextAccessor accessor)
  17. {
  18. _accessor = accessor;
  19. }
  20. [HttpGet]
  21. public ActionResult BatchInsertLogDB(int limit = 100)
  22. {
  23. int total = TkLogCore.BatchInsertLogDB(limit);
  24. return new APIResult(new { success = true, message = "ok", limit, total });
  25. }
  26. [HttpGet]
  27. public async Task<ActionResult> GetSettleBills(int sleep = 2000)
  28. {
  29. var list = TkPoolCore.List();
  30. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  31. string message = string.Empty;
  32. int total = 0;
  33. foreach (var account in list)
  34. {
  35. if (!account.enable_sync_order) continue;
  36. #if DEBUG
  37. if (13 != account.id) continue;
  38. #endif
  39. try
  40. {
  41. var alimama = new AlimamaPlus(account);
  42. total += alimama.GetSettleBills(sleep);
  43. }
  44. catch (Exception ex)
  45. {
  46. message = $"【收益接口异常】\t{account.name}\n{ex.Message}\n{ex.StackTrace}";
  47. NotifyCore.Notify(new NifyMessage
  48. {
  49. message = message,
  50. priority = NifyMessagePriority.high,
  51. tags = ["red_circle"]
  52. });
  53. continue;
  54. }
  55. }
  56. return new APIResult(new { success = true, message = "ok", total });
  57. }
  58. [HttpGet]
  59. public async Task<ActionResult> GetHistoryOrders(int id, int sleep, DateTime startTime, DateTime endTime)
  60. {
  61. var list = TkPoolCore.List();
  62. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  63. if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
  64. string message = string.Empty;
  65. int total = 0;
  66. foreach (var account in list)
  67. {
  68. if (id != account.id) continue;
  69. try
  70. {
  71. //DateTime endTime = DateTime.Now;
  72. //DateTime startTime = endTime.AddDays(-90);
  73. if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
  74. var alimama = new AlimamaPlus(account);
  75. total += alimama.GetHistoryOrders(sleep, startTime, endTime);
  76. }
  77. catch (Exception ex)
  78. {
  79. message = $"【订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  80. NotifyCore.Notify(new NifyMessage
  81. {
  82. message = message,
  83. priority = NifyMessagePriority.high,
  84. tags = ["red_circle"]
  85. });
  86. continue;
  87. }
  88. }
  89. return new APIResult(new { success = true, message = "ok", total });
  90. }
  91. [HttpGet]
  92. public async Task<ActionResult> GetIncyOrders(int sleep = 2000)
  93. {
  94. var list = TkPoolCore.List();
  95. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  96. string message = string.Empty;
  97. int total = 0;
  98. foreach (var account in list)
  99. {
  100. #if DEBUG
  101. if (account.id != 17) continue;
  102. #endif
  103. if (!account.enable_sync_order) continue;
  104. try
  105. {
  106. var alimama = new AlimamaPlus(account);
  107. total += alimama.GetIncyOrders(sleep);
  108. }
  109. catch (Exception ex)
  110. {
  111. message = $"【订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  112. NotifyCore.Notify(new NifyMessage
  113. {
  114. message = message,
  115. priority = NifyMessagePriority.high,
  116. tags = ["red_circle"]
  117. });
  118. continue;
  119. }
  120. }
  121. return new APIResult(new { success = true, message = "ok", total });
  122. }
  123. [HttpGet]
  124. public async Task<ActionResult> GetViolationuWarning()
  125. {
  126. var list = TkPoolCore.List();
  127. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  128. string message = string.Empty;
  129. foreach (var account in list)
  130. {
  131. try
  132. {
  133. var alimama = new AlimamaPlus(account);
  134. alimama.GetViolationuWarning();
  135. }
  136. catch (Exception ex)
  137. {
  138. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  139. NotifyCore.Notify(new NifyMessage
  140. {
  141. message = message,
  142. priority = NifyMessagePriority.high,
  143. tags = ["red_circle"]
  144. });
  145. continue;
  146. }
  147. }
  148. return new APIResult(new { success = true, message = "ok" });
  149. }
  150. [HttpGet]
  151. public async Task<ActionResult> DailyLogs(int intervalDay = 1)
  152. {
  153. try
  154. {
  155. //第三方老的统计
  156. AlimamaPlus.DailyLogs(intervalDay);
  157. //产商统计
  158. AlimamaPlus.DailyLogs(intervalDay, "parse_", "tb");
  159. AlimamaPlus.DailyLogs(intervalDay, "coupon_", "tb");
  160. AlimamaPlus.DailyLogs(intervalDay, "parse_", "tool");
  161. }
  162. catch (Exception ex)
  163. {
  164. string message = $"【报表接口异常】DailyLogs\n{ex.Message}\n{ex.StackTrace}";
  165. NotifyCore.Notify(new NifyMessage
  166. {
  167. message = message,
  168. priority = NifyMessagePriority.high,
  169. tags = ["red_circle"]
  170. });
  171. }
  172. return new APIResult(new { success = true, message = "ok" });
  173. }
  174. [HttpGet]
  175. public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
  176. {
  177. try
  178. {
  179. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb);
  180. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "parse_");
  181. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "coupon_");
  182. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.wemeet, "parse_");
  183. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.bdpan, "parse_");
  184. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.dy, "parse_");
  185. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.jd, "parse_");
  186. }
  187. catch (Exception ex)
  188. {
  189. string message = $"【报表接口异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  190. NotifyCore.Notify(new NifyMessage
  191. {
  192. message = message,
  193. priority = NifyMessagePriority.high,
  194. tags = ["red_circle"]
  195. });
  196. }
  197. return new APIResult(new { success = true, message = "ok" });
  198. }
  199. [HttpGet]
  200. public async Task<ActionResult> GetDrawBalance()
  201. {
  202. var list = TkPoolCore.List();
  203. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  204. string message = string.Empty;
  205. foreach (var account in list)
  206. {
  207. if (!account.enable_sync_order) continue;
  208. try
  209. {
  210. var alimama = new AlimamaPlus(account);
  211. alimama.GetDrawBalance();
  212. }
  213. catch (Exception ex)
  214. {
  215. message = $"【报表接口异常】GetDrawBalance\n{ex.Message}\n{ex.StackTrace}";
  216. NotifyCore.Notify(new NifyMessage
  217. {
  218. message = message,
  219. priority = NifyMessagePriority.high,
  220. tags = ["red_circle"]
  221. });
  222. continue;
  223. }
  224. }
  225. return new APIResult(new { success = true, message = "ok" });
  226. }
  227. [HttpGet]
  228. public async Task<ActionResult> FastReport()
  229. {
  230. var list = TkPoolCore.List();
  231. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  232. string message = string.Empty;
  233. foreach (var account in list)
  234. {
  235. if (!account.enable_sync_order) continue;
  236. #if DEBUG
  237. if (account.id != 5) continue;
  238. #endif
  239. try
  240. {
  241. var alimama = new AlimamaPlus(account);
  242. alimama.SaveReportOverview();
  243. }
  244. catch (Exception ex)
  245. {
  246. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  247. NotifyCore.Notify(new NifyMessage
  248. {
  249. message = message,
  250. priority = NifyMessagePriority.high,
  251. tags = ["red_circle"]
  252. });
  253. continue;
  254. }
  255. }
  256. await EndPointCore.NotifyReload(true);
  257. return new APIResult(new { success = true, message = "ok" });
  258. }
  259. [HttpGet]
  260. public async Task<ActionResult> SaveReport()
  261. {
  262. var list = TkPoolCore.List();
  263. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  264. string message = string.Empty;
  265. foreach (var account in list)
  266. {
  267. if (!account.enable_sync_order) continue;
  268. #if DEBUG
  269. if (account.id != 5) continue;
  270. #endif
  271. try
  272. {
  273. var alimama = new AlimamaPlus(account);
  274. alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
  275. alimama.SaveReportHourtrend(DateTime.Now);
  276. if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
  277. {
  278. DateTime date = DateTime.Now.AddDays(-1);
  279. alimama.FixReport(date);
  280. }
  281. }
  282. catch (Exception ex)
  283. {
  284. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  285. NotifyCore.Notify(new NifyMessage
  286. {
  287. message = message,
  288. priority = NifyMessagePriority.high,
  289. tags = ["red_circle"]
  290. });
  291. continue;
  292. }
  293. }
  294. return new APIResult(new { success = true, message = "ok" });
  295. }
  296. [HttpGet]
  297. public async Task<ActionResult> FixReport(int id, string dt)
  298. {
  299. if (!DateTime.TryParse(dt, out DateTime date))
  300. {
  301. return new APIResult(new { success = false, message = "日期错误", });
  302. }
  303. var list = TkPoolCore.List();
  304. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  305. string message = string.Empty;
  306. foreach (var account in list)
  307. {
  308. if (id != account.id) continue;
  309. try
  310. {
  311. var alimama = new AlimamaPlus(account);
  312. while (date.Date < DateTime.Now.Date)
  313. {
  314. alimama.FixReport(date);
  315. date = date.AddDays(1);
  316. }
  317. }
  318. catch (Exception ex)
  319. {
  320. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  321. NotifyCore.Notify(new NifyMessage
  322. {
  323. message = message,
  324. priority = NifyMessagePriority.high,
  325. tags = ["red_circle"]
  326. });
  327. continue;
  328. }
  329. }
  330. return new APIResult(new { success = true, message = "ok" });
  331. }
  332. [HttpGet]
  333. public ActionResult RenewCookie(string name)
  334. {
  335. var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
  336. if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
  337. var alimama = new AlimamaPlus(account);
  338. (bool success, string message) = alimama.RenewCookie();
  339. return new APIResult(new { success, message });
  340. }
  341. [HttpGet]
  342. public ActionResult Reload()
  343. {
  344. TkConfigCore.Refresh();
  345. EndPointCore.Refresh();
  346. ProxyNodesCore.Refresh();
  347. TkPoolCore.Refresh();
  348. VeapiPoolCore.Refresh();
  349. ApiAccountCore.Refresh();
  350. DataokeCore.Refresh();
  351. JdPoolCore.Refresh();
  352. PddPoolCore.Refresh();
  353. PangolinPoolCore.Refresh();
  354. return new APIResult(new
  355. {
  356. success = true,
  357. message = "ok",
  358. });
  359. }
  360. [HttpGet]
  361. public ActionResult ReloadAccount()
  362. {
  363. EndPointCore.Refresh();
  364. ProxyNodesCore.Refresh();
  365. TkPoolCore.Refresh();
  366. VeapiPoolCore.Refresh();
  367. return new APIResult(new
  368. {
  369. success = true,
  370. message = "ok",
  371. });
  372. }
  373. }
  374. }