TkLogCore.cs 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Mvc.Controllers;
  3. using Microsoft.AspNetCore.Mvc.Filters;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using dodohold.core;
  9. using static dodohold.core.ZTOExpress.CreateOrderArgs;
  10. using System.Net;
  11. using System.Security.Cryptography;
  12. using Spire.Pdf.Exporting.XPS.Schema;
  13. using System.Xml.Linq;
  14. using static QRCoder.PayloadGenerator;
  15. using TencentCloud.Ssl.V20191205.Models;
  16. using CSRedis;
  17. using System.Data;
  18. using TencentCloud.Omics.V20221128.Models;
  19. using TencentCloud.Csip.V20221121.Models;
  20. using COSXML.Network;
  21. namespace molilian.core
  22. {
  23. public class TkLogCore
  24. {
  25. static string queue_tb_key = "queue:logs:tb";
  26. static string queue_jd_key = "queue:logs:jd";
  27. static string queue_parse_tb_key = "queue:parse_logs:tb";
  28. static string queue_parse_jd_key = "queue:parse_logs:jd";
  29. static string queue_parse_pdd_key = "queue:parse_logs:pdd";
  30. static string queue_parse_dy_key = "queue:parse_logs:dy";
  31. static string queue_parse_tool_key = "queue:parse_logs:tool";
  32. static string queue_coupon_key = "queue:coupon_logs";
  33. static string promotion_img_key = "queue:promotion:img";
  34. static string queue_cps_key = "queue:cps_logs";
  35. public static bool save_dailys_log = false;
  36. static TkLogCore()
  37. {
  38. int flag = RedisHelper.Get<int>("turn:save_dailys_log");
  39. if (flag == 1) save_dailys_log = true;
  40. }
  41. public static int BatchInsertLogDB(int limit)
  42. {
  43. var result = EndPointCore.ProcessEndPointNodes<int>(node =>
  44. {
  45. if (!node.is_public_api) return 0;
  46. if (CenterHub.IsCenter)
  47. {
  48. if (node.is_coupon_api) return 0;
  49. }
  50. else
  51. {
  52. if (!node.is_coupon_api) return 0;
  53. }
  54. if (string.IsNullOrEmpty(node.redis_server)) return 0;
  55. var redis = RedisClientManager.GetRedisClient(node.redis_server);
  56. return BatchInsertLogDB(limit, redis);
  57. });
  58. return result.Sum();
  59. }
  60. private static int save_tk_log(TkDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
  61. {
  62. return new DBContext.Table(connection, tablename)
  63. .Add("end_point", data.end_point)
  64. .Add("channel", (int)data.channel)
  65. .Add("accountId", data.accountId)
  66. .Add("accountName", data.accountName)
  67. .Add("rawContent", data.rawContent)
  68. .Add("rawContent2", data.rawContent2)
  69. .Add("success", data.success)
  70. .Add("message", data.message)
  71. .Add("reason", data.reason)
  72. .Add("content", data.content)
  73. .Add("couponAmount", data.couponAmount)
  74. .Add("itemId", data.itemId)
  75. .Add("itemName", data.itemName)
  76. .Add("pic", data.pic)
  77. .Add("promotionPrice", data.promotionPrice)
  78. .Add("taoToken", data.taoToken)
  79. .Add("shortLinkurl", data.shortLinkurl)
  80. .Add("deeplink_url", data.deeplink_url)
  81. .Add("num_iid", data.num_iid)
  82. .Add("elapsedTime", data.elapsedTime)
  83. .Add("subCode", data.subCode)
  84. .Add("ip", data.ip)
  85. .Add("oaid", data.oaid)
  86. .Add("create_time", data.create_time)
  87. .Create(DBContext.InsertType.NORMAL, transaction);
  88. }
  89. private static int save_tk_parse_logs(TkDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
  90. {
  91. return new DBContext.Table(connection, tablename)
  92. .Add("end_point", data.end_point)
  93. .Add("channel", (int)data.channel)
  94. .Add("linkType", (int)data.link_type)
  95. .Add("accountId", data.accountId)
  96. .Add("accountName", data.accountName)
  97. .Add("rawContent", data.rawContent)
  98. .Add("success", data.success)
  99. .Add("message", data.message)
  100. .Add("reason", data.reason)
  101. .Add("content", data.content)
  102. .Add("itemId", data.itemId)
  103. .Add("itemName", data.itemName)
  104. .Add("pic", data.pic)
  105. .Add("couponAmount", data.couponAmount)
  106. .Add("promotionPrice", data.promotionPrice)
  107. .Add("taoToken", data.taoToken)
  108. .Add("shortLinkurl", data.shortLinkurl)
  109. .Add("deeplink_url", data.deeplink_url)
  110. .Add("num_iid", data.num_iid)
  111. .Add("elapsedTime", data.elapsedTime)
  112. .Add("elapsedTime2", data.elapsedTime2)
  113. .Add("elapsedTime3", data.elapsedTime3)
  114. .Add("subCode", data.subCode)
  115. .Add("ip", data.ip)
  116. .Add("oaid", data.oaid)
  117. .Add("create_time", data.create_time)
  118. .Create(DBContext.InsertType.NORMAL, transaction);
  119. }
  120. private static int save_jd_parse_logs(JdDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
  121. {
  122. return new DBContext.Table(connection, tablename)
  123. .Add("end_point", data.end_point)
  124. .Add("channel", (int)data.channel)
  125. .Add("accountId", data.accountId)
  126. .Add("accountName", data.accountName)
  127. .Add("rawContent", data.rawContent)
  128. .Add("success", data.success)
  129. .Add("message", data.message)
  130. .Add("reason", data.reason)
  131. .Add("content", data.content)
  132. .Add("itemId", data.itemId)
  133. .Add("itemName", data.itemName)
  134. .Add("pic", data.pic)
  135. .Add("couponAmount", data.couponAmount)
  136. .Add("promotionPrice", data.promotionPrice)
  137. .Add("taoToken", data.taoToken)
  138. .Add("shortLinkurl", data.shortLinkurl)
  139. .Add("deeplink_url", data.deeplink_url)
  140. .Add("elapsedTime", data.elapsedTime)
  141. .Add("subCode", data.subCode)
  142. .Add("ip", data.ip)
  143. .Add("oaid", data.oaid)
  144. .Add("create_time", data.create_time)
  145. .Create(DBContext.InsertType.NORMAL, transaction);
  146. }
  147. private static int save_pdd_parse_logs(PddDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
  148. {
  149. return new DBContext.Table(connection, tablename)
  150. .Add("end_point", data.end_point)
  151. .Add("channel", (int)data.channel)
  152. .Add("accountId", data.accountId)
  153. .Add("accountName", data.accountName)
  154. .Add("rawContent", data.rawContent)
  155. .Add("success", data.success)
  156. .Add("message", data.message)
  157. .Add("reason", data.reason)
  158. .Add("content", data.content)
  159. .Add("itemId", data.itemId)
  160. .Add("itemName", data.itemName)
  161. .Add("pic", data.pic)
  162. .Add("couponAmount", data.couponAmount)
  163. .Add("promotionPrice", data.promotionPrice)
  164. .Add("taoToken", data.taoToken)
  165. .Add("shortLinkurl", data.shortLinkurl)
  166. .Add("deeplink_url", data.deeplink_url)
  167. .Add("elapsedTime", data.elapsedTime)
  168. .Add("subCode", data.subCode)
  169. .Add("ip", data.ip)
  170. .Add("oaid", data.oaid)
  171. .Add("create_time", data.create_time)
  172. .Create(DBContext.InsertType.NORMAL, transaction);
  173. }
  174. public static int BatchInsertLogDB(int limit, CSRedisClient redis)
  175. {
  176. int total = 0;
  177. using var connection = DBContext.GetOpenConnection();
  178. connection.Open();
  179. using var transaction = connection.BeginTransaction();
  180. string cacheKey = ":lock_key:start_comparison_tk";
  181. bool start_comparison_tk = RedisHelper.Get<int>(cacheKey) > 0;
  182. try
  183. {
  184. for (int i = 0; i < limit; i++)
  185. {
  186. var data = redis.LPop<TkDataDTO>(queue_tb_key);
  187. if (data == null) break;
  188. if ("3JDaxNfPy83okP3kLScwCkGiuMcyC4PcyntF424979CC9C51BCAD0C245B1C7BA2".Equals(data.oaid) ||
  189. data.ip.Contains("127.0.0"))
  190. {
  191. save_tk_log(data, "tk_logs_test", connection, transaction);
  192. }
  193. else
  194. {
  195. data.id = save_tk_log(data, "tk_logs", connection, transaction);
  196. if (data.elapsedTime > 1000)
  197. {
  198. save_tk_log(data, "tk_logs_test", connection, transaction);
  199. }
  200. if (data.success)
  201. {
  202. save_tk_log(data, "tk_success_logs", connection, transaction);
  203. }
  204. if (!string.IsNullOrEmpty(data.itemId)) TkOrderTrackingCore.SaveLinkSummary(data);
  205. }
  206. total++;
  207. }
  208. for (int i = 0; i < limit; i++)
  209. {
  210. var data = redis.LPop<JdDataDTO>(queue_jd_key);
  211. if (data == null) break;
  212. new DBContext.Table(connection, "tk_logs")
  213. .Add("end_point", data.end_point)
  214. .Add("channel", (int)data.channel)
  215. .Add("accountId", data.accountId)
  216. .Add("accountName", data.accountName)
  217. .Add("rawContent", data.rawContent)
  218. .Add("rawContent2", data.rawContent2)
  219. .Add("success", data.success)
  220. .Add("message", data.message)
  221. .Add("reason", data.reason)
  222. .Add("shortLinkurl", data.shortLinkurl)
  223. .Add("deeplink_url", data.deeplink_url)
  224. .Add("elapsedTime", data.elapsedTime)
  225. .Add("ip", data.ip)
  226. .Add("oaid", data.oaid)
  227. .Add("create_time", data.create_time)
  228. .Create(DBContext.InsertType.NORMAL, transaction);
  229. total++;
  230. }
  231. for (int i = 0; i < limit; i++)
  232. {
  233. var data = redis.LPop<TkDataDTO>(queue_parse_tb_key);
  234. if (data == null) break;
  235. if ("3JDaxNfPy83okP3kLScwCkGiuMcyC4PcyntF424979CC9C51BCAD0C245B1C7BA2".Equals(data.oaid) ||
  236. data.ip.Contains("127.0.0"))
  237. {
  238. save_tk_parse_logs(data, "tk_parse_logs_test", connection, transaction);
  239. }
  240. else
  241. {
  242. data.id = save_tk_parse_logs(data, "tk_parse_logs", connection, transaction);
  243. //每日分表
  244. if (save_dailys_log)
  245. {
  246. string daily_table = $"tk_parse_logs_{DateTime.Now:yyyyMMdd}";
  247. save_tk_parse_logs(data, daily_table, connection, transaction);
  248. }
  249. if (data.elapsedTime > 1000)
  250. {
  251. save_tk_parse_logs(data, "tk_parse_logs_test", connection, transaction);
  252. }
  253. if (data.success)
  254. {
  255. save_tk_parse_logs(data, "tk_success_parse_logs", connection, transaction);
  256. }
  257. if (!string.IsNullOrEmpty(data.itemId)) TkOrderTrackingCore.SaveLinkSummary(data);
  258. }
  259. if (data.reason.Contains("初步筛选2") && !data.rawContent.Contains("I:/kWqN5t623Hx"))
  260. {
  261. save_tk_parse_logs(data, "tk_parse_logs_test2", connection, transaction);
  262. }
  263. if (data.reason.Contains("初步筛选1.5"))
  264. {
  265. save_tk_parse_logs(data, "tk_parse_logs_multi_token", connection, transaction);
  266. }
  267. if (data.reason.Contains("霸下验证码"))
  268. {
  269. save_tk_parse_logs(data, "tk_parse_logs_captcha", connection, transaction);
  270. }
  271. total++;
  272. }
  273. for (int i = 0; i < limit; i++)
  274. {
  275. var data = redis.LPop<JdDataDTO>(queue_parse_jd_key);
  276. if (data == null) break;
  277. if ("3JDaxNfPy83okP3kLScwCkGiuMcyC4PcyntF424979CC9C51BCAD0C245B1C7BA2".Equals(data.oaid) ||
  278. data.ip.Contains("127.0.0"))
  279. {
  280. save_jd_parse_logs(data, "jd_parse_logs_test", connection, transaction);
  281. }
  282. else
  283. {
  284. save_jd_parse_logs(data, "jd_parse_logs", connection, transaction);
  285. if (save_dailys_log)
  286. {
  287. string daily_table = $"jd_parse_logs_{DateTime.Now:yyyyMMdd}";
  288. save_jd_parse_logs(data, daily_table, connection, transaction);
  289. }
  290. if (data.elapsedTime > 1000)
  291. {
  292. save_jd_parse_logs(data, "jd_parse_logs_test", connection, transaction);
  293. }
  294. if (data.success)
  295. {
  296. save_jd_parse_logs(data, "jd_parse_logs_success", connection, transaction);
  297. }
  298. }
  299. total++;
  300. }
  301. for (int i = 0; i < limit; i++)
  302. {
  303. var data = redis.LPop<PddDataDTO>(queue_parse_pdd_key);
  304. if (data == null) break;
  305. if (data.ip.Contains("127.0.0"))
  306. {
  307. save_pdd_parse_logs(data, "pdd_parse_logs_test", connection, transaction);
  308. }
  309. else
  310. {
  311. save_pdd_parse_logs(data, "pdd_parse_logs", connection, transaction);
  312. if (data.elapsedTime > 1000)
  313. {
  314. save_pdd_parse_logs(data, "pdd_parse_logs_test", connection, transaction);
  315. }
  316. if (data.success)
  317. {
  318. save_pdd_parse_logs(data, "pdd_parse_logs_success", connection, transaction);
  319. }
  320. }
  321. total++;
  322. }
  323. for (int i = 0; i < limit; i++)
  324. {
  325. var data = redis.LPop<DyDataDTO>(queue_parse_dy_key);
  326. if (data == null) break;
  327. new DBContext.Table(connection, "tk_parse_logs")
  328. .Add("end_point", data.end_point)
  329. .Add("channel", (int)data.channel)
  330. .Add("accountId", data.accountId)
  331. .Add("accountName", data.accountName)
  332. .Add("rawContent", data.rawContent)
  333. .Add("success", data.success)
  334. .Add("message", data.message)
  335. .Add("reason", data.reason)
  336. .Add("content", data.content)
  337. .Add("itemId", data.itemId)
  338. .Add("itemName", data.itemName)
  339. .Add("pic", data.pic)
  340. .Add("couponAmount", data.couponAmount)
  341. .Add("promotionPrice", data.promotionPrice)
  342. .Add("taoToken", data.taoToken)
  343. .Add("shortLinkurl", data.shortLinkurl)
  344. .Add("deeplink_url", data.deeplink_url)
  345. .Add("elapsedTime", data.elapsedTime)
  346. .Add("subCode", data.subCode)
  347. .Add("ip", data.ip)
  348. .Add("oaid", data.oaid)
  349. .Add("create_time", data.create_time)
  350. .Create(DBContext.InsertType.NORMAL, transaction);
  351. total++;
  352. }
  353. for (int i = 0; i < limit; i++)
  354. {
  355. var data = redis.LPop<ToolParseDataDTO>(queue_parse_tool_key);
  356. if (data == null) break;
  357. new DBContext.Table(connection, "tool_parse_logs")
  358. .Add("end_point", data.end_point)
  359. .Add("channel", (int)data.channel)
  360. .Add("rawContent", data.rawContent)
  361. .Add("success", data.success)
  362. .Add("message", data.message)
  363. .Add("reason", data.reason)
  364. .Add("content", data.content)
  365. .Add("taoToken", data.taoToken)
  366. .Add("shortLinkurl", data.shortLinkurl)
  367. .Add("deeplink_url", data.deeplink_url)
  368. .Add("elapsedTime", data.elapsedTime)
  369. .Add("ip", data.ip)
  370. .Add("oaid", data.oaid)
  371. .Add("create_time", data.create_time)
  372. .Create(DBContext.InsertType.NORMAL, transaction);
  373. total++;
  374. }
  375. for (int i = 0; i < limit; i++)
  376. {
  377. var data = redis.LPop<UnionCouponDTO>(queue_coupon_key);
  378. if (data == null) break;
  379. if ("3JDaxNfPy83okP3kLScwCkGiuMcyC4PcyntF424979CC9C51BCAD0C245B1C7BA2".Equals(data.oaid) ||
  380. data.ip.Contains("127.0.0"))
  381. {
  382. var test_data = data.Convert2Json().Convert2Object<TestUnionCouponDTO>();
  383. connection.Insert(test_data);
  384. }
  385. else
  386. {
  387. connection.Insert(data);
  388. if (data.success)
  389. {
  390. var success_data = data.Convert2Json().Convert2Object<SuccessUnionCouponDTO>();
  391. connection.Insert(success_data);
  392. }
  393. }
  394. total++;
  395. }
  396. for (int i = 0; i < limit; i++)
  397. {
  398. var data = redis.LPop<UnionCpsDTO>(queue_cps_key);
  399. if (data == null) break;
  400. if (data.ip.Contains("127.0.0"))
  401. {
  402. var test_data = data.Convert2Json().Convert2Object<TestUnionCpsDTO>();
  403. connection.Insert(test_data);
  404. }
  405. else
  406. {
  407. connection.Insert(data);
  408. if (data.success)
  409. {
  410. var success_data = data.Convert2Json().Convert2Object<SuccessUnionCpsDTO>();
  411. connection.Insert(success_data);
  412. }
  413. }
  414. total++;
  415. }
  416. for (int i = 0; i < limit; i++)
  417. {
  418. var data = redis.LPop<PromotionQueryDTO>(promotion_img_key);
  419. if (data == null) break;
  420. if (data.success)
  421. {
  422. data.similarPromotion = string.Empty;
  423. data.promotionImg = string.Empty;
  424. }
  425. connection.Insert(data);
  426. total++;
  427. }
  428. transaction.Commit();
  429. }
  430. catch (Exception ex)
  431. {
  432. transaction.Rollback();
  433. _ = new LoggerLibrary("database_error", "parse_log")
  434. .Info(ex.Message, ex.StackTrace)
  435. .SaveAsync();
  436. NotifyCore.Notify(new NifyMessage
  437. {
  438. message = $"【写入日志异常】\n{ex.Message}\n{ex.StackTrace}",
  439. priority = NifyMessagePriority.high,
  440. tags = ["red_circle"]
  441. });
  442. }
  443. finally
  444. {
  445. connection.Close();
  446. }
  447. return total;
  448. }
  449. public static async Task PromotionImgLogAsync(PromotionQueryDTO response)
  450. {
  451. try
  452. {
  453. var ts = DateTime.Now - response.create_time;
  454. response.elapsedTime = (int)ts.TotalMilliseconds;
  455. _ = RedisHelper.RPushAsync(promotion_img_key, response);
  456. //using var connection = DBContext.GetOpenConnection();
  457. //connection.Insert(response);
  458. savePromotionCache(response.accountId, response.accountName, response.success, response.message, response.reason);
  459. }
  460. catch (Exception ex) { }
  461. }
  462. public static async Task LogAsync(JdDataDTO response)
  463. {
  464. try
  465. {
  466. var ts = DateTime.Now - response.create_time;
  467. response.elapsedTime = (int)ts.TotalMilliseconds;
  468. _ = RedisHelper.RPushAsync(queue_jd_key, response);
  469. if (!response.ip.Contains("127.0.0"))
  470. {
  471. saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  472. }
  473. }
  474. catch (Exception ex) { }
  475. }
  476. public static async Task LogAsync(TkDataDTO response, AlimamaPlus? alimamaPlus = null)
  477. {
  478. try
  479. {
  480. var ts = DateTime.Now - response.create_time;
  481. response.elapsedTime = (int)ts.TotalMilliseconds;
  482. _ = RedisHelper.RPushAsync(queue_tb_key, response);
  483. if (!response.ip.Contains("127.0.0"))
  484. {
  485. saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  486. }
  487. if (!response.success && "nologin".Equals(response.message))
  488. {
  489. switch (response.channel)
  490. {
  491. case TkChannelEnum.tb:
  492. await Task.Run(() =>
  493. {
  494. if (alimamaPlus != null)
  495. {
  496. (bool success, string message) = alimamaPlus.RenewCookie();
  497. if (success) return;
  498. }
  499. TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
  500. });
  501. break;
  502. }
  503. }
  504. if ("没有匹配账号".Equals(response.reason))
  505. {
  506. TkPoolCore.AccountExhausted();
  507. }
  508. }
  509. catch (Exception ex)
  510. {
  511. _ = new LoggerLibrary("unionParse", "database_error")
  512. .Info(response.rawContent, response.rawContent2)
  513. .Info(response.Convert2Json())
  514. .Info(ex.Message, ex.StackTrace)
  515. .SaveAsync();
  516. }
  517. }
  518. public static async Task ParseLogAsync(TkDataDTO response, AlimamaPlus? alimamaPlus = null)
  519. {
  520. #if DEBUG
  521. //return;
  522. #endif
  523. try
  524. {
  525. var ts = DateTime.Now - response.create_time;
  526. response.elapsedTime = (int)ts.TotalMilliseconds;
  527. _ = RedisHelper.RPushAsync(queue_parse_tb_key, response);
  528. if (response.success)
  529. {
  530. _ = saveUnionCouponParseCacheAsync(response);
  531. }
  532. if (!response.ip.Contains("127.0.0"))
  533. {
  534. saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  535. }
  536. if (!string.IsNullOrEmpty(response.itemId)) TkOrderTrackingCore.SaveLinkSummary(response);
  537. if (!response.success && "nologin".Equals(response.message))
  538. {
  539. switch (response.channel)
  540. {
  541. case TkChannelEnum.tb:
  542. await Task.Run(() =>
  543. {
  544. if (alimamaPlus != null)
  545. {
  546. (bool success, string message) = alimamaPlus.RenewCookie();
  547. if (success) return;
  548. }
  549. TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}");
  550. }); break;
  551. }
  552. }
  553. if (response.subCode == TkSubCodeEnum.Captcha || "霸下验证码".Equals(response.reason))
  554. {
  555. TkPoolCore.Suspend(response.end_point, response.accountId, response.accountName, "霸下验证码");
  556. }
  557. }
  558. catch (Exception ex)
  559. {
  560. _ = new LoggerLibrary("unionParse", "database_error")
  561. .Info(response.rawContent)
  562. .Info(response.Convert2Json())
  563. .Info(ex.Message, ex.StackTrace)
  564. .SaveAsync();
  565. }
  566. }
  567. public static async Task CouponLogAsync(UnionCouponDTO response, AlimamaPlus? alimamaPlus = null)
  568. {
  569. try
  570. {
  571. var ts = DateTime.Now - response.create_time;
  572. response.elapsedTime = (int)ts.TotalMilliseconds;
  573. _ = RedisHelper.RPushAsync(queue_coupon_key, response);
  574. if (!response.ip.Contains("127.0.0"))
  575. {
  576. saveCouponCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  577. }
  578. if (!response.success && "nologin".Equals(response.message))
  579. {
  580. switch (response.channel)
  581. {
  582. case TkChannelEnum.tb:
  583. await Task.Run(() =>
  584. {
  585. if (alimamaPlus != null)
  586. {
  587. (bool success, string message) = alimamaPlus.RenewCookie();
  588. if (success) return;
  589. }
  590. TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}");
  591. }); break;
  592. }
  593. }
  594. }
  595. catch (Exception ex)
  596. {
  597. _ = new LoggerLibrary("unionCoupon", "database_error")
  598. .Info(response.rawContent)
  599. .Info(response.Convert2Json())
  600. .Info(ex.Message, ex.StackTrace)
  601. .SaveAsync();
  602. }
  603. }
  604. public static async Task CpsLogAsync(UnionCpsDTO response, AlimamaPlus? alimamaPlus = null)
  605. {
  606. try
  607. {
  608. var ts = DateTime.Now - response.create_time;
  609. response.elapsedTime = (int)ts.TotalMilliseconds;
  610. _ = RedisHelper.RPushAsync(queue_cps_key, response);
  611. if (response.success) saveClientRequestTotal(response.channel, response.ip, response.oaid);
  612. if (!response.ip.Contains("127.0.0"))
  613. {
  614. saveCpsCache(response.channel.ToString(), response.accountId, response.success, response.message, response.reason);
  615. }
  616. }
  617. catch (Exception ex)
  618. {
  619. _ = new LoggerLibrary("unionCps", "database_error")
  620. .Info(response.rawContent)
  621. .Info(response.Convert2Json())
  622. .Info(ex.Message, ex.StackTrace)
  623. .SaveAsync();
  624. }
  625. }
  626. public static async Task ParseLogAsync(JdDataDTO response)
  627. {
  628. try
  629. {
  630. var ts = DateTime.Now - response.create_time;
  631. response.elapsedTime = (int)ts.TotalMilliseconds;
  632. _ = RedisHelper.RPushAsync(queue_parse_jd_key, response);
  633. if (!response.ip.Contains("127.0.0"))
  634. {
  635. saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  636. }
  637. if (response.success || response.message.Equals("转链失败"))
  638. {
  639. JdPoolCore.CallsIncrBy(response.accountId);
  640. }
  641. //CallsIncrBy
  642. if (response.success) saveClientRequestTotal(response.channel, response.ip, response.oaid);
  643. if (!response.success && ("nologin".Equals(response.reason) ||
  644. "方法不存在".Equals(response.reason) ||
  645. "未登录".Equals(response.reason)))
  646. {
  647. await Task.Run(() =>
  648. {
  649. JdPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
  650. });
  651. //switch (response.channel)
  652. //{
  653. // case TkChannelEnum.tb:
  654. // //await Task.Run(() =>
  655. // //{
  656. // // if (alimamaPlus != null)
  657. // // {
  658. // // (bool success, string message) = alimamaPlus.RenewCookie();
  659. // // if (success) return;
  660. // // }
  661. // // TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
  662. // //});
  663. // break;
  664. //}
  665. }
  666. if ("没有匹配账号".Equals(response.reason))
  667. {
  668. JdPoolCore.AccountExhausted();
  669. }
  670. }
  671. catch (Exception ex) { }
  672. }
  673. public static async Task ParseLogAsync(PddDataDTO response)
  674. {
  675. try
  676. {
  677. var ts = DateTime.Now - response.create_time;
  678. response.elapsedTime = (int)ts.TotalMilliseconds;
  679. _ = RedisHelper.RPushAsync(queue_parse_pdd_key, response);
  680. #if DEBUG
  681. for (int i = 0; i < 100; i++)
  682. {
  683. var data = RedisHelper.LPop<PddDataDTO>(queue_parse_pdd_key);
  684. if (data == null) break;
  685. if (data.ip.Contains("127.0.0"))
  686. {
  687. save_pdd_parse_logs(data, "pdd_parse_logs_test", null, null);
  688. }
  689. else
  690. {
  691. save_pdd_parse_logs(data, "pdd_parse_logs", null, null);
  692. if (data.elapsedTime > 1000)
  693. {
  694. save_pdd_parse_logs(data, "pdd_parse_logs_test", null, null);
  695. }
  696. if (data.success)
  697. {
  698. save_pdd_parse_logs(data, "pdd_parse_logs_success", null, null);
  699. }
  700. }
  701. }
  702. #endif
  703. if (!response.ip.Contains("127.0.0"))
  704. {
  705. saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  706. }
  707. if (response.success || response.message.Equals("转链失败"))
  708. {
  709. PddPoolCore.CallsIncrBy(response.accountId);
  710. }
  711. if (response.reason.Equals("您的调用次数过高"))
  712. {
  713. PddPoolCore.TempSuspend(response.accountId);
  714. }
  715. if (response.success) saveClientRequestTotal(response.channel, response.ip, response.oaid);
  716. if (!response.success && ("nologin".Equals(response.reason) ||
  717. "方法不存在".Equals(response.reason) ||
  718. "未登录".Equals(response.reason)))
  719. {
  720. await Task.Run(() =>
  721. {
  722. PddPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
  723. });
  724. }
  725. if ("没有匹配账号".Equals(response.reason))
  726. {
  727. PddPoolCore.AccountExhausted();
  728. }
  729. }
  730. catch (Exception ex) { }
  731. }
  732. public static async Task ParseLogAsync(DyDataDTO response)
  733. {
  734. try
  735. {
  736. var ts = DateTime.Now - response.create_time;
  737. response.elapsedTime = (int)ts.TotalMilliseconds;
  738. _ = RedisHelper.RPushAsync(queue_parse_dy_key, response);
  739. if (!response.ip.Contains("127.0.0"))
  740. {
  741. saveParseCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  742. }
  743. }
  744. catch (Exception ex) { }
  745. }
  746. public static async Task ParseLogAsync(ToolParseDataDTO response)
  747. {
  748. try
  749. {
  750. var ts = DateTime.Now - response.create_time;
  751. response.elapsedTime = (int)ts.TotalMilliseconds;
  752. _ = RedisHelper.RPushAsync(queue_parse_tool_key, response);
  753. if (!response.ip.Contains("127.0.0"))
  754. {
  755. saveParseCache(response.channel.ToString(), 0, "tool", response.success, response.message, response.reason);
  756. }
  757. }
  758. catch (Exception ex) { }
  759. }
  760. private static void saveCache(string channel, int accountId, string accountName, bool success, string message, string reason)
  761. {
  762. saveAccountCache("all", success, message, reason);
  763. saveAccountCache($"{channel}", success, message, reason);
  764. saveAccountCache($"{accountName}", success, message, reason);
  765. if (accountId != 0)
  766. {
  767. //todo 放着跑两天,要将读取的地方改成读取accountid
  768. saveAccountCache($"{channel}_{accountId}", success, message, reason);
  769. }
  770. }
  771. private static void saveAccountCache(string accountName, bool success, string message, string reason)
  772. {
  773. RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMM}");
  774. RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMMdd}");
  775. RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  776. string result = success ? "success" : "fail";
  777. RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  778. RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  779. RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  780. if (!string.IsNullOrEmpty(message))
  781. {
  782. RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  783. RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  784. RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  785. RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  786. RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  787. RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  788. RedisHelper.IncrBy($":total:{accountName}:message:{message}:{DateTime.Now:yyyyMM}");
  789. RedisHelper.IncrBy($":total:{accountName}:message:{message}:{DateTime.Now:yyyyMMdd}");
  790. RedisHelper.IncrBy($":total:{accountName}:message:{message}:{DateTime.Now:yyyyMMddHH}");
  791. }
  792. if (!string.IsNullOrEmpty(reason))
  793. {
  794. RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  795. RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  796. RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  797. RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  798. RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  799. RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  800. RedisHelper.IncrBy($":total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMM}");
  801. RedisHelper.IncrBy($":total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
  802. RedisHelper.IncrBy($":total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
  803. }
  804. }
  805. private static async Task saveUnionCouponParseCacheAsync(TkDataDTO data)
  806. {
  807. string cacheKey = $":cache:parse:{data.ip}_{data.oaid}_{data.itemId}";
  808. await EndPointCore.ProcessEndPointNodesAsync(node =>
  809. {
  810. if (!node.is_coupon_api) return Task.CompletedTask;
  811. if (string.IsNullOrEmpty(node.redis_server)) return Task.CompletedTask;
  812. var redis = RedisClientManager.GetRedisClient(node.redis_server);
  813. redis.Set(cacheKey, 1, 2 * 86400);
  814. return Task.CompletedTask;
  815. });
  816. }
  817. private static void saveClientRequestTotal(TkChannelEnum channel, string ip, string oaid)
  818. {
  819. string cacheKey = $":cache:{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
  820. RedisHelper.IncrBy(cacheKey);
  821. RedisHelper.Expire(cacheKey, 86400);
  822. if (!string.IsNullOrEmpty(oaid))
  823. {
  824. cacheKey = $":cache:{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
  825. RedisHelper.IncrBy(cacheKey);
  826. RedisHelper.Expire(cacheKey, 86400);
  827. }
  828. }
  829. public static int getClientRequestTotalByOAID(TkChannelEnum channel, string oaid)
  830. {
  831. if (string.IsNullOrEmpty(oaid)) return 0;
  832. string cacheKey = $":cache:{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
  833. return RedisHelper.Get<int>(cacheKey);
  834. }
  835. public static int getClientRequestTotalByIp(TkChannelEnum channel, string ip)
  836. {
  837. if (string.IsNullOrEmpty(ip)) return 0;
  838. string cacheKey = $":cache:{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
  839. return RedisHelper.Get<int>(cacheKey);
  840. }
  841. private static void saveClientRequestTotal(CpsChannelEnum channel, string ip, string oaid)
  842. {
  843. string cacheKey = $":cache:cps_{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
  844. RedisHelper.IncrBy(cacheKey);
  845. RedisHelper.Expire(cacheKey, 86400);
  846. if (!string.IsNullOrEmpty(oaid))
  847. {
  848. cacheKey = $":cache:cps_{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
  849. RedisHelper.IncrBy(cacheKey);
  850. RedisHelper.Expire(cacheKey, 86400);
  851. }
  852. }
  853. public static int getClientRequestTotalByOAID(CpsChannelEnum channel, string oaid)
  854. {
  855. if (string.IsNullOrEmpty(oaid)) return 0;
  856. string cacheKey = $":cache:cps_{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
  857. return RedisHelper.Get<int>(cacheKey);
  858. }
  859. public static int getClientRequestTotalByIp(CpsChannelEnum channel, string ip)
  860. {
  861. if (string.IsNullOrEmpty(ip)) return 0;
  862. string cacheKey = $":cache:cps_{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
  863. return RedisHelper.Get<int>(cacheKey);
  864. }
  865. private static void saveParseCache(string channel, int accountId, string accountName, bool success, string message, string reason)
  866. {
  867. saveParseAccountCache("all", success, message, reason);
  868. saveParseAccountCache($"{channel}", success, message, reason);
  869. saveParseAccountCache($"{accountName}", success, message, reason);
  870. if (accountId != 0)
  871. {
  872. //todo 放着跑两天,要将读取的地方改成读取accountid
  873. saveParseAccountCache($"{channel}_{accountId}", success, message, reason);
  874. }
  875. }
  876. private static void saveParseAccountCache(string accountName, bool success, string message, string reason)
  877. {
  878. RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMM}");
  879. RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMMdd}");
  880. RedisHelper.IncrBy($":parse_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  881. string result = success ? "success" : "fail";
  882. RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  883. RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  884. RedisHelper.IncrBy($":parse_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  885. if (!string.IsNullOrEmpty(message))
  886. {
  887. RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  888. RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  889. RedisHelper.SAdd($":parse_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  890. RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  891. RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  892. RedisHelper.IncrBy($":parse_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  893. RedisHelper.IncrBy($":parse_total:{accountName}:message:{message}:{DateTime.Now:yyyyMM}");
  894. RedisHelper.IncrBy($":parse_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMdd}");
  895. RedisHelper.IncrBy($":parse_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMddHH}");
  896. }
  897. if (!string.IsNullOrEmpty(reason))
  898. {
  899. RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  900. RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  901. RedisHelper.SAdd($":parse_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  902. RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  903. RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  904. RedisHelper.IncrBy($":parse_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  905. RedisHelper.IncrBy($":parse_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMM}");
  906. RedisHelper.IncrBy($":parse_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
  907. RedisHelper.IncrBy($":parse_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
  908. }
  909. }
  910. private static void savePromotionCache(int accountId, string accountName, bool success, string message, string reason)
  911. {
  912. savePromotionAccountCache("all", success, message, reason);
  913. savePromotionAccountCache($"{accountId}", success, message, reason);
  914. }
  915. private static void savePromotionAccountCache(string accountName, bool success, string message, string reason)
  916. {
  917. RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMM}");
  918. RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMMdd}");
  919. RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  920. string result = success ? "success" : "fail";
  921. RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  922. RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  923. RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  924. if (!string.IsNullOrEmpty(message))
  925. {
  926. RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  927. RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  928. RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  929. RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  930. RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  931. RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  932. RedisHelper.IncrBy($":promotion_total:{accountName}:message:{message}:{DateTime.Now:yyyyMM}");
  933. RedisHelper.IncrBy($":promotion_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMdd}");
  934. RedisHelper.IncrBy($":promotion_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMddHH}");
  935. }
  936. if (!string.IsNullOrEmpty(reason))
  937. {
  938. RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  939. RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  940. RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  941. RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  942. RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  943. RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  944. RedisHelper.IncrBy($":promotion_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMM}");
  945. RedisHelper.IncrBy($":promotion_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
  946. RedisHelper.IncrBy($":promotion_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
  947. }
  948. }
  949. private static void saveCouponCache(string channel, int accountId, string accountName, bool success, string message, string reason)
  950. {
  951. saveAccountCouponCache("all", success, message, reason);
  952. saveAccountCouponCache($"{channel}", success, message, reason);
  953. if (accountId != 0)
  954. {
  955. saveAccountCouponCache($"{channel}_{accountId}", success, message, reason);
  956. }
  957. }
  958. private static void saveAccountCouponCache(string accountName, bool success, string message, string reason)
  959. {
  960. RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMM}");
  961. RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMMdd}");
  962. RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
  963. string result = success ? "success" : "fail";
  964. RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
  965. RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
  966. RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
  967. if (!string.IsNullOrEmpty(message))
  968. {
  969. RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
  970. RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
  971. RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
  972. RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
  973. RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
  974. RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
  975. RedisHelper.IncrBy($":coupon_total:{accountName}:message:{message}:{DateTime.Now:yyyyMM}");
  976. RedisHelper.IncrBy($":coupon_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMdd}");
  977. RedisHelper.IncrBy($":coupon_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMddHH}");
  978. }
  979. if (!string.IsNullOrEmpty(reason))
  980. {
  981. RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
  982. RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  983. RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  984. RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
  985. RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
  986. RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  987. RedisHelper.IncrBy($":coupon_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMM}");
  988. RedisHelper.IncrBy($":coupon_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
  989. RedisHelper.IncrBy($":coupon_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
  990. }
  991. }
  992. private static void saveCpsCache(string channel, int accountId, bool success, string message, string reason)
  993. {
  994. saveAccountCpsCache("all", success, message, reason);
  995. saveAccountCpsCache($"{channel}", success, message, reason);
  996. if (accountId != 0)
  997. {
  998. saveAccountCpsCache($"{channel}_{accountId}", success, message, reason);
  999. }
  1000. }
  1001. private static void saveAccountCpsCache(string flagName, bool success, string message, string reason)
  1002. {
  1003. RedisHelper.IncrBy($":cps_total:{flagName}:{DateTime.Now:yyyyMM}");
  1004. RedisHelper.IncrBy($":cps_total:{flagName}:{DateTime.Now:yyyyMMdd}");
  1005. RedisHelper.IncrBy($":cps_total:{flagName}:{DateTime.Now:yyyyMMddHH}");
  1006. string result = success ? "success" : "fail";
  1007. RedisHelper.IncrBy($":cps_total:{flagName}:{result}:{DateTime.Now:yyyyMM}");
  1008. RedisHelper.IncrBy($":cps_total:{flagName}:{result}:{DateTime.Now:yyyyMMdd}");
  1009. RedisHelper.IncrBy($":cps_total:{flagName}:{result}:{DateTime.Now:yyyyMMddHH}");
  1010. if (!string.IsNullOrEmpty(message))
  1011. {
  1012. RedisHelper.SAdd($":cps_total:{flagName}:message:{DateTime.Now:yyyyMM}", message);
  1013. RedisHelper.SAdd($":cps_total:{flagName}:message:{DateTime.Now:yyyyMMdd}", message);
  1014. RedisHelper.SAdd($":cps_total:{flagName}:message:{DateTime.Now:yyyyMMddHH}", message);
  1015. RedisHelper.IncrBy($":cps_total:{flagName}:{message}:{DateTime.Now:yyyyMM}");
  1016. RedisHelper.IncrBy($":cps_total:{flagName}:{message}:{DateTime.Now:yyyyMMdd}");
  1017. RedisHelper.IncrBy($":cps_total:{flagName}:{message}:{DateTime.Now:yyyyMMddHH}");
  1018. RedisHelper.IncrBy($":cps_total:{flagName}:message:{message}:{DateTime.Now:yyyyMM}");
  1019. RedisHelper.IncrBy($":cps_total:{flagName}:message:{message}:{DateTime.Now:yyyyMMdd}");
  1020. RedisHelper.IncrBy($":cps_total:{flagName}:message:{message}:{DateTime.Now:yyyyMMddHH}");
  1021. }
  1022. if (!string.IsNullOrEmpty(reason))
  1023. {
  1024. RedisHelper.SAdd($":cps_total:{flagName}:reason:{DateTime.Now:yyyyMM}", reason);
  1025. RedisHelper.SAdd($":cps_total:{flagName}:reason:{DateTime.Now:yyyyMMdd}", reason);
  1026. RedisHelper.SAdd($":cps_total:{flagName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
  1027. RedisHelper.IncrBy($":cps_total:{flagName}:{reason}:{DateTime.Now:yyyyMM}");
  1028. RedisHelper.IncrBy($":cps_total:{flagName}:{reason}:{DateTime.Now:yyyyMMdd}");
  1029. RedisHelper.IncrBy($":cps_total:{flagName}:{reason}:{DateTime.Now:yyyyMMddHH}");
  1030. RedisHelper.IncrBy($":cps_total:{flagName}:reason:{reason}:{DateTime.Now:yyyyMM}");
  1031. RedisHelper.IncrBy($":cps_total:{flagName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
  1032. RedisHelper.IncrBy($":cps_total:{flagName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
  1033. }
  1034. }
  1035. public static int GetTotal(string keyname, bool all_node = true)
  1036. {
  1037. //:coupon_total:tb:20240706
  1038. //:coupon_total:tb:success:20240706
  1039. //:coupon_total:tb:放弃转链:20240706
  1040. var result = EndPointCore.ProcessEndPointNodes<int>(node =>
  1041. {
  1042. if (!node.is_public_api) return 0;
  1043. if (string.IsNullOrEmpty(node.redis_server)) return 0;
  1044. if (!all_node)
  1045. {
  1046. if (CenterHub.IsCenter)
  1047. {
  1048. if (node.is_coupon_api) { return 0; }
  1049. }
  1050. else
  1051. {
  1052. if (!node.is_coupon_api) { return 0; }
  1053. }
  1054. }
  1055. #if DEBUG
  1056. switch (node.name)
  1057. {
  1058. case "bj":
  1059. node.redis_server = "101.200.46.46:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
  1060. break;
  1061. case "gz":
  1062. node.redis_server = "8.138.110.158:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
  1063. break;
  1064. case "coupon1":
  1065. node.redis_server = "c1api.molilian.com:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=coupon";
  1066. break;
  1067. default: return 0;
  1068. }
  1069. #endif
  1070. var redis = RedisClientManager.GetRedisClient(node.redis_server);
  1071. int count = redis.Get<int>(keyname);
  1072. return count;
  1073. });
  1074. return result.Sum();
  1075. }
  1076. public static string[] GetTotalKeys(string keyname, bool all_node = true)
  1077. {
  1078. var result = EndPointCore.ProcessEndPointNodes<string[]>(node =>
  1079. {
  1080. if (!node.is_public_api) return [];
  1081. if (string.IsNullOrEmpty(node.redis_server)) return [];
  1082. if (!all_node)
  1083. {
  1084. if (CenterHub.IsCenter)
  1085. {
  1086. if (node.is_coupon_api) { return []; }
  1087. }
  1088. else
  1089. {
  1090. if (!node.is_coupon_api) { return []; }
  1091. }
  1092. }
  1093. #if DEBUG
  1094. switch (node.name)
  1095. {
  1096. case "bj":
  1097. node.redis_server = "101.200.46.46:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
  1098. break;
  1099. case "gz":
  1100. node.redis_server = "8.138.110.158:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook";
  1101. break;
  1102. case "coupon1":
  1103. node.redis_server = "c1api.molilian.com:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=coupon";
  1104. break;
  1105. default: return [];
  1106. }
  1107. #endif
  1108. var redis = RedisClientManager.GetRedisClient(node.redis_server);
  1109. string[] message_keys = redis.SMembers(keyname);
  1110. return message_keys;
  1111. });
  1112. string[] message_keys = [];
  1113. foreach (var arr in result)
  1114. {
  1115. message_keys = message_keys.Union(arr).ToArray();
  1116. }
  1117. return message_keys;
  1118. }
  1119. //if (item.total_count > 0) continue;
  1120. //item.total_count = RedisHelper.Get<int>($":total:all:{item.report_date:yyyyMMdd}");
  1121. //if (item.total_count == 0) continue;
  1122. //item.success_count = RedisHelper.Get<int>($":total:all:success:{item.report_date:yyyyMMdd}");
  1123. //item.abandon_count = RedisHelper.Get<int>($":total:all:放弃转链:{item.report_date:yyyyMMdd}");
  1124. }
  1125. }