pdd.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. using dodohold.core;
  2. using CSRedis;
  3. using System.Data;
  4. using YunhuiKit;
  5. namespace molilian.core
  6. {
  7. public partial class TkLogCore
  8. {
  9. static string queue_parse_pdd_key = "queue:parse_logs:pdd";
  10. public static async Task<int> InsertParsePddLogAsync(int limit, YunhuiKit.RedisClient redis)
  11. {
  12. int total = 0;
  13. using var connection = DBContext.GetOpenConnection();
  14. connection.Open();
  15. using var transaction = connection.BeginTransaction();
  16. try
  17. {
  18. for (int i = 0; i < limit; i++)
  19. {
  20. var data = await redis.LPopAsync<PddDataDTO>(queue_parse_pdd_key);
  21. if (data == null) break;
  22. if (TestParseCore.InWhitelist(data.ip, data.oaid))
  23. {
  24. save_pdd_parse_logs(data, "pdd_parse_logs_test", connection, transaction);
  25. }
  26. else
  27. {
  28. string daily_table;
  29. if ("dp".Equals(data.parse_type))
  30. {
  31. daily_table = $"pdd_dp_logs_{data.create_time:yyyyMMdd}";
  32. save_pdd_parse_logs(data, daily_table, connection, transaction);
  33. }
  34. daily_table = $"pdd_parse_logs_{data.create_time:yyyyMMdd}";
  35. save_pdd_parse_logs(data, daily_table, connection, transaction);
  36. if (!data.success)
  37. {
  38. save_pdd_parse_logs(data, "pdd_parse_logs_fail", connection, transaction);
  39. }
  40. }
  41. total++;
  42. }
  43. transaction.Commit();
  44. }
  45. catch (Exception ex)
  46. {
  47. transaction.Rollback();
  48. new LoggerLibrary("TkLogCore_error", "task_insert_parse_pdd_logs")
  49. .Info(ex.Message, ex.StackTrace)
  50. .SaveAsync();
  51. throw;
  52. }
  53. finally
  54. {
  55. connection.Close();
  56. }
  57. return total;
  58. }
  59. public static int task_insert_parse_pdd_logs(int limit, CSRedisClient redis)
  60. {
  61. int total = 0;
  62. using var connection = DBContext.GetOpenConnection();
  63. connection.Open();
  64. using var transaction = connection.BeginTransaction();
  65. try
  66. {
  67. for (int i = 0; i < limit; i++)
  68. {
  69. var data = redis.LPop<PddDataDTO>(queue_parse_pdd_key);
  70. if (data == null) break;
  71. if (TestParseCore.InWhitelist(data.ip, data.oaid))
  72. {
  73. save_pdd_parse_logs(data, "pdd_parse_logs_test", connection, transaction);
  74. }
  75. else
  76. {
  77. //save_pdd_parse_logs(data, "pdd_parse_logs", connection, transaction);
  78. //if (save_dailys_log)
  79. {
  80. string daily_table = $"pdd_parse_logs_{data.create_time:yyyyMMdd}";
  81. save_pdd_parse_logs(data, daily_table, connection, transaction);
  82. }
  83. if (!data.success)
  84. {
  85. save_pdd_parse_logs(data, "pdd_parse_logs_fail", connection, transaction);
  86. }
  87. }
  88. total++;
  89. }
  90. transaction.Commit();
  91. }
  92. catch (Exception ex)
  93. {
  94. transaction.Rollback();
  95. new LoggerLibrary("TkLogCore_error", "task_insert_parse_pdd_logs")
  96. .Info(ex.Message, ex.StackTrace)
  97. .SaveAsync();
  98. throw;
  99. }
  100. finally
  101. {
  102. connection.Close();
  103. }
  104. return total;
  105. }
  106. public static async Task ParseLogAsync(PddDataDTO response)
  107. {
  108. try
  109. {
  110. var ts = DateTime.Now - response.create_time;
  111. response.elapsedTime = (int)ts.TotalMilliseconds;
  112. _ = RedisKit.RPushAsync(queue_parse_pdd_key, response);
  113. if (!TestParseCore.InWhitelist(response.ip, response.oaid))
  114. {
  115. await SaveParseCacheAsync(response.channel.ToString(), response.accountId,
  116. response.accountName, response.success, response.message, response.reason,
  117. response.deeplink_url);
  118. }
  119. //if (response.success) saveClientRequestTotal(response.channel, response.ip, response.oaid);
  120. if (response.success || response.message.Equals("转链失败"))
  121. {
  122. await RiskControlCore.CallsIncrByAsync(response.channel, response.accountId);
  123. await saveClientRequestTotalAsync(response.channel, response.ip, response.oaid);
  124. }
  125. //30007:检测到您推广行为异常,链接生成失败
  126. if (response.reason.Equals("您的调用次数过高"))
  127. {
  128. PddPoolCore.TempSuspend(response.accountId);
  129. }
  130. if (!response.success && ("nologin".Equals(response.reason) ||
  131. "方法不存在".Equals(response.reason) ||
  132. "43001:会话已过期".Equals(response.reason) ||
  133. "未登录".Equals(response.reason)))
  134. {
  135. PddPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
  136. }
  137. if (response.reason.Contains("当前账号被禁止使用转链功能"))
  138. {
  139. PddPoolCore.Disabled(response.accountId, response.accountName, response.reason);
  140. }
  141. if (response.reason.Contains("没有匹配账号"))
  142. {
  143. PddPoolCore.AccountExhausted();
  144. }
  145. }
  146. catch (Exception ex) { }
  147. }
  148. private static int save_pdd_parse_logs(PddDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
  149. {
  150. return new DBContext.Table(connection, tablename)
  151. .Add("end_point", data.end_point)
  152. .Add("channel", (int)data.channel)
  153. .Add("accountId", data.accountId)
  154. .Add("accountName", data.accountName)
  155. .Add("proxy_node", data.proxy_node)
  156. .Add("rawContent", data.rawContent)
  157. .Add("rawContent2", data.rawContent2)
  158. .Add("success", data.success)
  159. .Add("message", data.message)
  160. .Add("reason", data.reason)
  161. .Add("content", data.content)
  162. .Add("itemId", data.itemId)
  163. .Add("itemName", data.itemName)
  164. .Add("pic", data.pic)
  165. .Add("couponAmount", data.couponAmount)
  166. .Add("promotionPrice", data.promotionPrice)
  167. .Add("taoToken", data.taoToken)
  168. .Add("shortLinkurl", data.shortLinkurl)
  169. .Add("deeplink_url", data.deeplink_url)
  170. .Add("elapsedTime", data.elapsedTime)
  171. .Add("elapsedTime2", data.elapsedTime2)
  172. .Add("elapsedTime3", data.elapsedTime3)
  173. .Add("subCode", data.subCode)
  174. .Add("ip", data.ip)
  175. .Add("oaid", data.oaid)
  176. .Add("riskStrategy", data.riskStrategy)
  177. .Add("launchScene", data.launchScene)
  178. .Add("create_time", data.create_time)
  179. .Add("parse_type", data.parse_type)
  180. .Create(DBContext.InsertType.NORMAL, transaction);
  181. }
  182. }
  183. }