TaskController.cs 14 KB

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