TaskController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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> GetHistoryRefundOrders(int id, int sleep, DateTime startTime, DateTime endTime)
  125. {
  126. var list = TkPoolCore.List();
  127. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  128. if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
  129. string message = string.Empty;
  130. int total = 0;
  131. foreach (var account in list)
  132. {
  133. if (id != account.id) continue;
  134. try
  135. {
  136. //DateTime endTime = DateTime.Now;
  137. //DateTime startTime = endTime.AddDays(-90);
  138. if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
  139. var alimama = new AlimamaPlus(account);
  140. total += alimama.GetHistoryRefundOrders(sleep, startTime, endTime);
  141. }
  142. catch (Exception ex)
  143. {
  144. message = $"【维权订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  145. NotifyCore.Notify(new NifyMessage
  146. {
  147. message = message,
  148. priority = NifyMessagePriority.high,
  149. tags = ["red_circle"]
  150. });
  151. continue;
  152. }
  153. }
  154. return new APIResult(new { success = true, message = "ok", total });
  155. }
  156. [HttpGet]
  157. public async Task<ActionResult> GetIncyRefundOrders(int sleep = 2000)
  158. {
  159. var list = TkPoolCore.List();
  160. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  161. string message = string.Empty;
  162. int total = 0;
  163. foreach (var account in list)
  164. {
  165. #if DEBUG
  166. if (account.id != 17) continue;
  167. #endif
  168. if (!account.enable_sync_order) continue;
  169. try
  170. {
  171. var alimama = new AlimamaPlus(account);
  172. total += alimama.GetIncyRefundOrders(sleep);
  173. }
  174. catch (Exception ex)
  175. {
  176. message = $"【维权订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
  177. NotifyCore.Notify(new NifyMessage
  178. {
  179. message = message,
  180. priority = NifyMessagePriority.high,
  181. tags = ["red_circle"]
  182. });
  183. continue;
  184. }
  185. }
  186. return new APIResult(new { success = true, message = "ok", total });
  187. }
  188. [HttpGet]
  189. public async Task<ActionResult> GetViolationuWarning()
  190. {
  191. var list = TkPoolCore.List();
  192. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  193. string message = string.Empty;
  194. foreach (var account in list)
  195. {
  196. try
  197. {
  198. var alimama = new AlimamaPlus(account);
  199. alimama.GetViolationuWarning();
  200. }
  201. catch (Exception ex)
  202. {
  203. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  204. NotifyCore.Notify(new NifyMessage
  205. {
  206. message = message,
  207. priority = NifyMessagePriority.high,
  208. tags = ["red_circle"]
  209. });
  210. continue;
  211. }
  212. }
  213. return new APIResult(new { success = true, message = "ok" });
  214. }
  215. [HttpGet]
  216. public async Task<ActionResult> DailyLogs(int intervalDay = 1)
  217. {
  218. try
  219. {
  220. //第三方老的统计
  221. AlimamaPlus.DailyLogs(intervalDay);
  222. //产商统计
  223. AlimamaPlus.DailyLogs(intervalDay, "parse_", "tb");
  224. AlimamaPlus.DailyLogs(intervalDay, "coupon_", "tb");
  225. AlimamaPlus.DailyLogs(intervalDay, "parse_", "tool");
  226. }
  227. catch (Exception ex)
  228. {
  229. string message = $"【报表接口异常】DailyLogs\n{ex.Message}\n{ex.StackTrace}";
  230. NotifyCore.Notify(new NifyMessage
  231. {
  232. message = message,
  233. priority = NifyMessagePriority.high,
  234. tags = ["red_circle"]
  235. });
  236. }
  237. return new APIResult(new { success = true, message = "ok" });
  238. }
  239. [HttpGet]
  240. public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
  241. {
  242. try
  243. {
  244. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb);
  245. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "parse_");
  246. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "coupon_");
  247. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.wemeet, "parse_");
  248. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.bdpan, "parse_");
  249. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.dy, "parse_");
  250. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.jd, "parse_");
  251. }
  252. catch (Exception ex)
  253. {
  254. string message = $"【报表接口异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  255. NotifyCore.Notify(new NifyMessage
  256. {
  257. message = message,
  258. priority = NifyMessagePriority.high,
  259. tags = ["red_circle"]
  260. });
  261. }
  262. return new APIResult(new { success = true, message = "ok" });
  263. }
  264. [HttpGet]
  265. public async Task<ActionResult> GetDrawBalance()
  266. {
  267. var list = TkPoolCore.List();
  268. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  269. string message = string.Empty;
  270. foreach (var account in list)
  271. {
  272. if (!account.enable_sync_order) continue;
  273. try
  274. {
  275. var alimama = new AlimamaPlus(account);
  276. alimama.GetDrawBalance();
  277. }
  278. catch (Exception ex)
  279. {
  280. message = $"【报表接口异常】GetDrawBalance\n{ex.Message}\n{ex.StackTrace}";
  281. NotifyCore.Notify(new NifyMessage
  282. {
  283. message = message,
  284. priority = NifyMessagePriority.high,
  285. tags = ["red_circle"]
  286. });
  287. continue;
  288. }
  289. }
  290. return new APIResult(new { success = true, message = "ok" });
  291. }
  292. [HttpGet]
  293. public async Task<ActionResult> FastReport()
  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 (!account.enable_sync_order) continue;
  301. #if DEBUG
  302. if (account.id != 5) continue;
  303. #endif
  304. try
  305. {
  306. var alimama = new AlimamaPlus(account);
  307. alimama.SaveReportOverview();
  308. }
  309. catch (Exception ex)
  310. {
  311. message = $"【报表接口异常】FastReport\n{ex.Message}\n{ex.StackTrace}";
  312. NotifyCore.Notify(new NifyMessage
  313. {
  314. message = message,
  315. priority = NifyMessagePriority.high,
  316. tags = ["red_circle"]
  317. });
  318. continue;
  319. }
  320. }
  321. await EndPointCore.NotifyReload(true);
  322. return new APIResult(new { success = true, message = "ok" });
  323. }
  324. [HttpGet]
  325. public async Task<ActionResult> SaveReport()
  326. {
  327. var list = TkPoolCore.List();
  328. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  329. string message = string.Empty;
  330. foreach (var account in list)
  331. {
  332. if (!account.enable_sync_order) continue;
  333. #if DEBUG
  334. if (account.id != 5) continue;
  335. #endif
  336. try
  337. {
  338. var alimama = new AlimamaPlus(account);
  339. alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
  340. alimama.SaveReportHourtrend(DateTime.Now);
  341. if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
  342. {
  343. DateTime date = DateTime.Now.AddDays(-1);
  344. alimama.FixReport(date);
  345. }
  346. }
  347. catch (Exception ex)
  348. {
  349. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  350. NotifyCore.Notify(new NifyMessage
  351. {
  352. message = message,
  353. priority = NifyMessagePriority.high,
  354. tags = ["red_circle"]
  355. });
  356. continue;
  357. }
  358. }
  359. return new APIResult(new { success = true, message = "ok" });
  360. }
  361. [HttpGet]
  362. public async Task<ActionResult> FixReport(int id, string dt)
  363. {
  364. if (!DateTime.TryParse(dt, out DateTime date))
  365. {
  366. return new APIResult(new { success = false, message = "日期错误", });
  367. }
  368. var list = TkPoolCore.List();
  369. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  370. string message = string.Empty;
  371. foreach (var account in list)
  372. {
  373. if (id != account.id) continue;
  374. try
  375. {
  376. var alimama = new AlimamaPlus(account);
  377. while (date.Date < DateTime.Now.Date)
  378. {
  379. alimama.FixReport(date);
  380. date = date.AddDays(1);
  381. }
  382. }
  383. catch (Exception ex)
  384. {
  385. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  386. NotifyCore.Notify(new NifyMessage
  387. {
  388. message = message,
  389. priority = NifyMessagePriority.high,
  390. tags = ["red_circle"]
  391. });
  392. continue;
  393. }
  394. }
  395. return new APIResult(new { success = true, message = "ok" });
  396. }
  397. [HttpGet]
  398. public ActionResult RenewCookie(string name)
  399. {
  400. var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
  401. if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
  402. var alimama = new AlimamaPlus(account);
  403. (bool success, string message) = alimama.RenewCookie();
  404. return new APIResult(new { success, message });
  405. }
  406. [HttpGet]
  407. public ActionResult Reload()
  408. {
  409. TkConfigCore.Refresh();
  410. EndPointCore.Refresh();
  411. ProxyNodesCore.Refresh();
  412. TkPoolCore.Refresh();
  413. VeapiPoolCore.Refresh();
  414. ApiAccountCore.Refresh();
  415. DataokeCore.Refresh();
  416. JdPoolCore.Refresh();
  417. PddPoolCore.Refresh();
  418. PangolinPoolCore.Refresh();
  419. return new APIResult(new
  420. {
  421. success = true,
  422. message = "ok",
  423. });
  424. }
  425. [HttpGet]
  426. public ActionResult ReloadAccount()
  427. {
  428. EndPointCore.Refresh();
  429. ProxyNodesCore.Refresh();
  430. TkPoolCore.Refresh();
  431. VeapiPoolCore.Refresh();
  432. return new APIResult(new
  433. {
  434. success = true,
  435. message = "ok",
  436. });
  437. }
  438. }
  439. }