pdd.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using dodohold.core;
  2. using CSRedis;
  3. using System.Data;
  4. namespace molilian.core
  5. {
  6. public partial class TkLogCore
  7. {
  8. static string queue_parse_pdd_key = "queue:parse_logs:pdd";
  9. public static int task_insert_parse_pdd_logs(int limit, CSRedisClient redis)
  10. {
  11. int total = 0;
  12. using var connection = DBContext.GetOpenConnection();
  13. connection.Open();
  14. using var transaction = connection.BeginTransaction();
  15. try
  16. {
  17. for (int i = 0; i < limit; i++)
  18. {
  19. var data = redis.LPop<PddDataDTO>(queue_parse_pdd_key);
  20. if (data == null) break;
  21. if (_test_oaid.Equals(data.oaid) ||
  22. data.ip.Contains("127.0.0"))
  23. {
  24. save_pdd_parse_logs(data, "pdd_parse_logs_test", connection, transaction);
  25. }
  26. else
  27. {
  28. //save_pdd_parse_logs(data, "pdd_parse_logs", connection, transaction);
  29. //if (save_dailys_log)
  30. {
  31. string daily_table = $"pdd_parse_logs_{data.create_time:yyyyMMdd}";
  32. save_pdd_parse_logs(data, daily_table, connection, transaction);
  33. }
  34. if (!data.success)
  35. {
  36. save_pdd_parse_logs(data, "pdd_parse_logs_fail", connection, transaction);
  37. }
  38. }
  39. total++;
  40. }
  41. transaction.Commit();
  42. }
  43. catch (Exception ex)
  44. {
  45. transaction.Rollback();
  46. new LoggerLibrary("TkLogCore_error", "task_insert_parse_pdd_logs")
  47. .Info(ex.Message, ex.StackTrace)
  48. .SaveAsync();
  49. throw;
  50. }
  51. finally
  52. {
  53. connection.Close();
  54. }
  55. return total;
  56. }
  57. public static async Task ParseLogAsync(PddDataDTO response)
  58. {
  59. try
  60. {
  61. var ts = DateTime.Now - response.create_time;
  62. response.elapsedTime = (int)ts.TotalMilliseconds;
  63. _ = RedisHelper.RPushAsync(queue_parse_pdd_key, response);
  64. if (!response.ip.Contains("127.0.0"))
  65. {
  66. saveParseCache(response.channel.ToString(), response.accountId,
  67. response.accountName, response.success, response.message, response.reason,
  68. response.deeplink_url);
  69. }
  70. if (response.success || response.message.Equals("转链失败"))
  71. {
  72. RiskControlCore.CallsIncrBy(response.channel, response.accountId);
  73. saveClientRequestTotal(response.channel, response.ip, response.oaid);
  74. }
  75. if (response.reason.Equals("您的调用次数过高"))
  76. {
  77. PddPoolCore.TempSuspend(response.accountId);
  78. }
  79. if (!response.success && ("nologin".Equals(response.reason) ||
  80. "方法不存在".Equals(response.reason) ||
  81. "未登录".Equals(response.reason)))
  82. {
  83. await Task.Run(() =>
  84. {
  85. PddPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
  86. });
  87. }
  88. if (response.reason.Contains("当前账号被禁止使用转链功能"))
  89. {
  90. PddPoolCore.Disabled(response.accountId, response.accountName, response.reason);
  91. }
  92. if ("没有匹配账号".Equals(response.reason))
  93. {
  94. PddPoolCore.AccountExhausted();
  95. }
  96. }
  97. catch (Exception ex) { }
  98. }
  99. private static int save_pdd_parse_logs(PddDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
  100. {
  101. return new DBContext.Table(connection, tablename)
  102. .Add("end_point", data.end_point)
  103. .Add("channel", (int)data.channel)
  104. .Add("accountId", data.accountId)
  105. .Add("accountName", data.accountName)
  106. .Add("rawContent", data.rawContent)
  107. .Add("rawContent2", data.rawContent2)
  108. .Add("success", data.success)
  109. .Add("message", data.message)
  110. .Add("reason", data.reason)
  111. .Add("content", data.content)
  112. .Add("itemId", data.itemId)
  113. .Add("itemName", data.itemName)
  114. .Add("pic", data.pic)
  115. .Add("couponAmount", data.couponAmount)
  116. .Add("promotionPrice", data.promotionPrice)
  117. .Add("taoToken", data.taoToken)
  118. .Add("shortLinkurl", data.shortLinkurl)
  119. .Add("deeplink_url", data.deeplink_url)
  120. .Add("elapsedTime", data.elapsedTime)
  121. .Add("elapsedTime2", data.elapsedTime2)
  122. .Add("elapsedTime3", data.elapsedTime3)
  123. .Add("subCode", data.subCode)
  124. .Add("ip", data.ip)
  125. .Add("oaid", data.oaid)
  126. .Add("create_time", data.create_time)
  127. .Create(DBContext.InsertType.NORMAL, transaction);
  128. }
  129. }
  130. }