第三方旧接口.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. 
  2. using CSRedis;
  3. using dodohold.core;
  4. using System.Data;
  5. namespace molilian.core
  6. {
  7. public partial class TkLogCore
  8. {
  9. static string queue_tb_key = "queue:logs:tb";
  10. static string queue_jd_key = "queue:logs:jd";
  11. public static int task_insert_tk_logs(int limit, CSRedisClient redis)
  12. {
  13. int total = 0;
  14. using var connection = DBContext.GetOpenConnection();
  15. connection.Open();
  16. using var transaction = connection.BeginTransaction();
  17. try
  18. {
  19. for (int i = 0; i < limit; i++)
  20. {
  21. var data = redis.LPop<TkDataDTO>(queue_tb_key);
  22. if (data == null) break;
  23. if (_test_oaid.Equals(data.oaid) ||
  24. data.ip.Contains("127.0.0"))
  25. {
  26. save_tk_log(data, "tk_logs_test", connection, transaction);
  27. }
  28. else
  29. {
  30. data.id = save_tk_log(data, "tk_logs", connection, transaction);
  31. if (data.elapsedTime > 1000)
  32. {
  33. save_tk_log(data, "tk_logs_test", connection, transaction);
  34. }
  35. if (data.success)
  36. {
  37. save_tk_log(data, "tk_success_logs", connection, transaction);
  38. }
  39. if (!string.IsNullOrEmpty(data.itemId)) TkOrderTrackingCore.SaveLinkSummary(data);
  40. }
  41. total++;
  42. }
  43. for (int i = 0; i < limit; i++)
  44. {
  45. var data = redis.LPop<JdDataDTO>(queue_jd_key);
  46. if (data == null) break;
  47. new DBContext.Table(connection, "tk_logs")
  48. .Add("end_point", data.end_point)
  49. .Add("channel", (int)data.channel)
  50. .Add("accountId", data.accountId)
  51. .Add("accountName", data.accountName)
  52. .Add("rawContent", data.rawContent)
  53. .Add("rawContent2", data.rawContent2)
  54. .Add("success", data.success)
  55. .Add("message", data.message)
  56. .Add("reason", data.reason)
  57. .Add("shortLinkurl", data.shortLinkurl)
  58. .Add("deeplink_url", data.deeplink_url)
  59. .Add("elapsedTime", data.elapsedTime)
  60. .Add("ip", data.ip)
  61. .Add("oaid", data.oaid)
  62. .Add("create_time", data.create_time)
  63. .Create(DBContext.InsertType.NORMAL, transaction);
  64. total++;
  65. }
  66. transaction.Commit();
  67. }
  68. catch
  69. {
  70. transaction.Rollback();
  71. throw;
  72. }
  73. finally
  74. {
  75. connection.Close();
  76. }
  77. return total;
  78. }
  79. public static async Task LogAsync(JdDataDTO response)
  80. {
  81. try
  82. {
  83. var ts = DateTime.Now - response.create_time;
  84. response.elapsedTime = (int)ts.TotalMilliseconds;
  85. _ = RedisHelper.RPushAsync(queue_jd_key, response);
  86. if (!response.ip.Contains("127.0.0"))
  87. {
  88. saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  89. }
  90. }
  91. catch (Exception ex) { }
  92. }
  93. public static async Task LogAsync(TkDataDTO response, AlimamaPlus? alimamaPlus = null)
  94. {
  95. try
  96. {
  97. var ts = DateTime.Now - response.create_time;
  98. response.elapsedTime = (int)ts.TotalMilliseconds;
  99. _ = RedisHelper.RPushAsync(queue_tb_key, response);
  100. if (!response.ip.Contains("127.0.0"))
  101. {
  102. saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
  103. }
  104. if (!response.success && "nologin".Equals(response.message))
  105. {
  106. switch (response.channel)
  107. {
  108. case TkChannelEnum.tb:
  109. await Task.Run(() =>
  110. {
  111. if (alimamaPlus != null)
  112. {
  113. (bool success, string message) = alimamaPlus.RenewCookie();
  114. if (success) return;
  115. }
  116. TkPoolCore.Disabled(response.accountId, response.accountName, $"{response.rawContent}\n{response.rawContent2}");
  117. });
  118. break;
  119. }
  120. }
  121. if ("没有匹配账号".Equals(response.reason))
  122. {
  123. TkPoolCore.AccountExhausted();
  124. }
  125. }
  126. catch (Exception ex)
  127. {
  128. _ = new LoggerLibrary("unionParse", "database_error")
  129. .Info(response.rawContent, response.rawContent2)
  130. .Info(response.Convert2Json())
  131. .Info(ex.Message, ex.StackTrace)
  132. .SaveAsync();
  133. }
  134. }
  135. private static int save_tk_log(TkDataDTO data, string tablename, IDbConnection connection, IDbTransaction transaction)
  136. {
  137. return new DBContext.Table(connection, tablename)
  138. .Add("end_point", data.end_point)
  139. .Add("channel", (int)data.channel)
  140. .Add("accountId", data.accountId)
  141. .Add("accountName", data.accountName)
  142. .Add("rawContent", data.rawContent)
  143. .Add("rawContent2", data.rawContent2)
  144. .Add("success", data.success)
  145. .Add("message", data.message)
  146. .Add("reason", data.reason)
  147. .Add("content", data.content)
  148. .Add("couponAmount", data.couponAmount)
  149. .Add("itemId", data.itemId)
  150. .Add("itemName", data.itemName)
  151. .Add("pic", data.pic)
  152. .Add("promotionPrice", data.promotionPrice)
  153. .Add("taoToken", data.taoToken)
  154. .Add("shortLinkurl", data.shortLinkurl)
  155. .Add("deeplink_url", data.deeplink_url)
  156. .Add("num_iid", data.num_iid)
  157. .Add("elapsedTime", data.elapsedTime)
  158. .Add("subCode", data.subCode)
  159. .Add("ip", data.ip)
  160. .Add("oaid", data.oaid)
  161. .Add("create_time", data.create_time)
  162. .Create(DBContext.InsertType.NORMAL, transaction);
  163. }
  164. }
  165. }