TaskController.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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. JdUnionPlus.DailyLogs(intervalDay);
  224. ToolParsePlus.DailyLogs(intervalDay);
  225. //产商统计
  226. AlimamaPlus.DailyLogs(intervalDay, "parse_", "tb");
  227. AlimamaPlus.DailyLogs(intervalDay, "coupon_", "tb");
  228. }
  229. catch (Exception ex)
  230. {
  231. string message = $"【报表接口异常】DailyLogs\n{ex.Message}\n{ex.StackTrace}";
  232. NotifyCore.Notify(new NifyMessage
  233. {
  234. message = message,
  235. priority = NifyMessagePriority.high,
  236. tags = ["red_circle"]
  237. });
  238. }
  239. return new APIResult(new { success = true, message = "ok" });
  240. }
  241. [HttpGet]
  242. public async Task<ActionResult> ApiCallStatistics(int intervalDay = 1)
  243. {
  244. try
  245. {
  246. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb);
  247. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "parse_");
  248. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.tb, "coupon_");
  249. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.wemeet, "parse_");
  250. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.bdpan, "parse_");
  251. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.dy, "parse_");
  252. AlimamaPlus.ApiCallStatistics(intervalDay, TkChannelEnum.jd, "parse_");
  253. }
  254. catch (Exception ex)
  255. {
  256. string message = $"【报表接口异常】ApiCallStatistics\n{ex.Message}\n{ex.StackTrace}";
  257. NotifyCore.Notify(new NifyMessage
  258. {
  259. message = message,
  260. priority = NifyMessagePriority.high,
  261. tags = ["red_circle"]
  262. });
  263. }
  264. return new APIResult(new { success = true, message = "ok" });
  265. }
  266. [HttpGet]
  267. public async Task<ActionResult> GetDrawBalance()
  268. {
  269. var list = TkPoolCore.List();
  270. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  271. string message = string.Empty;
  272. foreach (var account in list)
  273. {
  274. if (!account.enable_sync_order) continue;
  275. try
  276. {
  277. var alimama = new AlimamaPlus(account);
  278. alimama.GetDrawBalance();
  279. }
  280. catch (Exception ex)
  281. {
  282. message = $"【报表接口异常】GetDrawBalance\n{ex.Message}\n{ex.StackTrace}";
  283. NotifyCore.Notify(new NifyMessage
  284. {
  285. message = message,
  286. priority = NifyMessagePriority.high,
  287. tags = ["red_circle"]
  288. });
  289. continue;
  290. }
  291. }
  292. return new APIResult(new { success = true, message = "ok" });
  293. }
  294. [HttpGet]
  295. public async Task<ActionResult> FastReport()
  296. {
  297. var list = TkPoolCore.List();
  298. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  299. string message = string.Empty;
  300. foreach (var account in list)
  301. {
  302. if (!account.enable_sync_order) continue;
  303. #if DEBUG
  304. if (account.id != 5) continue;
  305. #endif
  306. try
  307. {
  308. var alimama = new AlimamaPlus(account);
  309. alimama.SaveReportOverview();
  310. }
  311. catch (Exception ex)
  312. {
  313. message = $"【报表接口异常】FastReport\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. await EndPointCore.NotifyReload(true);
  324. return new APIResult(new { success = true, message = "ok" });
  325. }
  326. [HttpGet]
  327. public async Task<ActionResult> SaveReport()
  328. {
  329. var list = TkPoolCore.List();
  330. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  331. string message = string.Empty;
  332. foreach (var account in list)
  333. {
  334. if (!account.enable_sync_order) continue;
  335. #if DEBUG
  336. if (account.id != 5) continue;
  337. #endif
  338. try
  339. {
  340. var alimama = new AlimamaPlus(account);
  341. alimama.SaveReportHourtrend(DateTime.Now.AddDays(-1));
  342. alimama.SaveReportHourtrend(DateTime.Now);
  343. if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 16)
  344. {
  345. DateTime date = DateTime.Now.AddDays(-1);
  346. alimama.FixReport(date);
  347. }
  348. }
  349. catch (Exception ex)
  350. {
  351. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  352. NotifyCore.Notify(new NifyMessage
  353. {
  354. message = message,
  355. priority = NifyMessagePriority.high,
  356. tags = ["red_circle"]
  357. });
  358. continue;
  359. }
  360. }
  361. return new APIResult(new { success = true, message = "ok" });
  362. }
  363. [HttpGet]
  364. public async Task<ActionResult> FixReport(int id, string dt)
  365. {
  366. if (!DateTime.TryParse(dt, out DateTime date))
  367. {
  368. return new APIResult(new { success = false, message = "日期错误", });
  369. }
  370. var list = TkPoolCore.List();
  371. if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
  372. string message = string.Empty;
  373. foreach (var account in list)
  374. {
  375. if (id != account.id) continue;
  376. try
  377. {
  378. var alimama = new AlimamaPlus(account);
  379. while (date.Date < DateTime.Now.Date)
  380. {
  381. alimama.FixReport(date);
  382. date = date.AddDays(1);
  383. }
  384. }
  385. catch (Exception ex)
  386. {
  387. message = $"【报表接口异常】SaveReport\n{ex.Message}\n{ex.StackTrace}";
  388. NotifyCore.Notify(new NifyMessage
  389. {
  390. message = message,
  391. priority = NifyMessagePriority.high,
  392. tags = ["red_circle"]
  393. });
  394. continue;
  395. }
  396. }
  397. return new APIResult(new { success = true, message = "ok" });
  398. }
  399. [HttpGet]
  400. public ActionResult RenewCookie(string name)
  401. {
  402. var account = new DBContext.Table("tk_pool").Get<TkPoolDTO>("name=@name", new { name });
  403. if (account == null) return new APIResult(new { success = false, message = "没有有效账号", });
  404. var alimama = new AlimamaPlus(account);
  405. (bool success, string message) = alimama.RenewCookie();
  406. return new APIResult(new { success, message });
  407. }
  408. [HttpGet]
  409. public ActionResult Reload()
  410. {
  411. TkConfigCore.Refresh();
  412. EndPointCore.Refresh();
  413. ProxyNodesCore.Refresh();
  414. TkPoolCore.Refresh();
  415. VeapiPoolCore.Refresh();
  416. ApiAccountCore.Refresh();
  417. DataokeCore.Refresh();
  418. JdPoolCore.Refresh();
  419. PddPoolCore.Refresh();
  420. PangolinPoolCore.Refresh();
  421. return new APIResult(new
  422. {
  423. success = true,
  424. message = "ok",
  425. });
  426. }
  427. [HttpGet]
  428. public ActionResult ReloadAccount()
  429. {
  430. EndPointCore.Refresh();
  431. ProxyNodesCore.Refresh();
  432. TkPoolCore.Refresh();
  433. VeapiPoolCore.Refresh();
  434. return new APIResult(new
  435. {
  436. success = true,
  437. message = "ok",
  438. });
  439. }
  440. }
  441. }