TaskController.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 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. return new APIResult(new { success = true, message = "ok" });
  250. }
  251. [HttpGet]
  252. public async Task<ActionResult> SaveReport()
  253. {
  254. var list = TkPoolCore.List();
  255. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  256. string message = string.Empty;
  257. foreach (var account in list)
  258. {
  259. #if DEBUG
  260. if (account.id != 5) continue;
  261. #endif
  262. try
  263. {
  264. var alimama = new AlimamaPlus(account);
  265. alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
  266. alimama.SaveReportHourtrend(DateTime.Now);
  267. if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
  268. {
  269. DateTime date = DateTime.Now.AddDays(-1);
  270. alimama.FixReport(date);
  271. }
  272. }
  273. catch (Exception ex)
  274. {
  275. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  276. NotifyCore.Notify(new NifyMessage
  277. {
  278. message = message,
  279. priority = NifyMessagePriority.high,
  280. tags = ["red_circle"]
  281. });
  282. continue;
  283. }
  284. }
  285. return new APIResult(new { success = true, message = "ok" });
  286. }
  287. [HttpGet]
  288. public async Task<ActionResult> FixReport(string dt)
  289. {
  290. if (!DateTime.TryParse(dt, out DateTime date))
  291. {
  292. return new APIResult(new { success = false, message = "日期错误", });
  293. }
  294. var list = TkPoolCore.List();
  295. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  296. string message = string.Empty;
  297. foreach (var account in list)
  298. {
  299. #if DEBUG
  300. if (account.id != 5) continue;
  301. #endif
  302. try
  303. {
  304. var alimama = new AlimamaPlus(account);
  305. while (date.Date < DateTime.Now.Date)
  306. {
  307. alimama.FixReport(date);
  308. date = date.AddDays(1);
  309. }
  310. }
  311. catch (Exception ex)
  312. {
  313. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  314. NotifyCore.Notify(new NifyMessage
  315. {
  316. message = message,
  317. priority = NifyMessagePriority.high,
  318. tags = ["red_circle"]
  319. });
  320. continue;
  321. }
  322. }
  323. return new APIResult(new { success = true, message = "ok" });
  324. }
  325. [HttpGet]
  326. public ActionResult RenewCookie(string name)
  327. {
  328. var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
  329. if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
  330. var alimama = new AlimamaPlus(account);
  331. (bool success, string message) = alimama.RenewCookie();
  332. return new APIResult(new { success, message });
  333. }
  334. [HttpGet]
  335. public ActionResult Reload()
  336. {
  337. TkConfigCore.Refresh();
  338. EndPointCore.Refresh();
  339. ProxyNodesCore.Refresh();
  340. TkPoolCore.Refresh();
  341. VeapiPoolCore.Refresh();
  342. ApiAccountCore.Refresh();
  343. DataokeCore.Refresh();
  344. JdPoolCore.Refresh();
  345. PangolinPoolCore.Refresh();
  346. return new APIResult(new
  347. {
  348. success = true,
  349. message = "ok",
  350. });
  351. }
  352. [HttpGet]
  353. public ActionResult ReloadAccount()
  354. {
  355. EndPointCore.Refresh();
  356. ProxyNodesCore.Refresh();
  357. TkPoolCore.Refresh();
  358. VeapiPoolCore.Refresh();
  359. return new APIResult(new
  360. {
  361. success = true,
  362. message = "ok",
  363. });
  364. }
  365. }
  366. }