OrderTrackingCore.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 Dataoke;
  10. using Google.Protobuf.WellKnownTypes;
  11. using System.Diagnostics;
  12. using System.Text.Json;
  13. using TencentCloud.Tcm.V20210413.Models;
  14. using System.Security.Cryptography;
  15. using System.Data;
  16. using System.Threading.Channels;
  17. namespace molilian.core
  18. {
  19. public partial class TkOrderTrackingCore
  20. {
  21. public static void SaveLinkSummary(TkDataDTO item)
  22. {
  23. //清洗数据
  24. item.content = null;
  25. item.rawContent = null;
  26. item.rawContent2 = null;
  27. TkDataDTO newData = new()
  28. {
  29. channel = item.channel,
  30. ip = item.ip,
  31. oaid = item.oaid,
  32. itemId = item.itemId,
  33. itemName = item.itemName,
  34. taoToken = item.taoToken,
  35. shortLinkurl = item.shortLinkurl,
  36. deeplink_url = item.deeplink_url,
  37. create_time = item.create_time,
  38. };
  39. var config = TkConfigCore.Get();
  40. var ttl = config.fake_click_ttl * 3600;
  41. string cacheKey = $":cache:order_summary:{item.accountId}:{item.itemId}";
  42. RedisHelper.Set(cacheKey, newData, ttl);
  43. cacheKey = $":cache:order_summary:{item.accountId}:{item.itemName}";
  44. RedisHelper.Set(cacheKey, newData, ttl);
  45. }
  46. public static TkDataDTO GetLinkSummary(int accountId, string itemId, string itemTitle)
  47. {
  48. var result = EndPointCore.ProcessEndPointNodes<TkDataDTO>(node =>
  49. {
  50. if (!node.is_public_api) return null;
  51. if (string.IsNullOrEmpty(node.redis_server)) return null;
  52. var redis = RedisClientManager.GetRedisClient(node.redis_server);
  53. if (!string.IsNullOrEmpty(itemId))
  54. {
  55. string cacheKey = $":cache:order_summary:{accountId}:{itemId}";
  56. var result = redis.Get<TkDataDTO>(cacheKey);
  57. if (result != null) return result;
  58. }
  59. if (!string.IsNullOrEmpty(itemId))
  60. {
  61. string cacheKey = $":cache:order_summary:{accountId}:{itemTitle}";
  62. var result = redis.Get<TkDataDTO>(cacheKey);
  63. if (result != null) return result;
  64. }
  65. return null;
  66. });
  67. return result.Count > 0 ? result[0] : null;
  68. }
  69. public static async void RemoveLinkSummary(int accountId, string itemId)
  70. {
  71. string cacheKey = $":cache:order_summary:{accountId}:{itemId}";
  72. await EndPointCore.ProcessEndPointNodesAsync(node =>
  73. {
  74. if (!node.is_public_api) return Task.CompletedTask;
  75. if (string.IsNullOrEmpty(node.redis_server)) return Task.CompletedTask;
  76. var redis = RedisClientManager.GetRedisClient(node.redis_server);
  77. redis.Del(cacheKey);
  78. return Task.CompletedTask;
  79. });
  80. }
  81. public static bool MatchOrder(TkPoolDTO account, TkOrderDetailDTO item, IDbConnection conn)
  82. {
  83. if (item.tbPaidTime < DateTime.Now.AddDays(-1)) return false;
  84. var summary = GetLinkSummary(item.accountId, item.itemId, item.itemTitle);
  85. if (summary == null) return false;
  86. var config = TkConfigCore.Get();
  87. Random rand = new();
  88. int click_num = rand.Next(config.fake_click_min, config.fake_click_max + 1);
  89. if (account.fake_click_min != 0 && account.fake_click_max != 0)
  90. click_num = rand.Next(account.fake_click_min, account.fake_click_max + 1);
  91. DateTime paidTime = item.tbPaidTime;
  92. if (paidTime < summary.create_time) return false;
  93. int minutes = paidTime.Minute / 10 * 10;
  94. DateTime rounded = new(paidTime.Year, paidTime.Month, paidTime.Day, paidTime.Hour, minutes, 0);
  95. string batchId = rounded.ToString("yyyyMMddHHmm");
  96. string accountName = item.accountName;
  97. string shortLinkUrl = summary.shortLinkurl;
  98. string deeplinkUrl = summary.deeplink_url;
  99. switch (account.fake_click_link_type)
  100. {
  101. case FakeClickLinkType.Deeplink:
  102. shortLinkUrl = string.Empty;
  103. break;
  104. case FakeClickLinkType.H5:
  105. deeplinkUrl = string.Empty;
  106. break;
  107. }
  108. DateTime expTime = item.tbPaidTime.Hour >= 21 ? item.tbPaidTime.AddHours(3) : item.tbPaidTime.Date.AddDays(1);
  109. var data = new TkOrderTrackingDTO()
  110. {
  111. channel = summary.channel,
  112. accountId = item.accountId,
  113. accountName = accountName,
  114. batchId = batchId,
  115. ip = summary.ip,
  116. oaid = summary.oaid,
  117. itemId = summary.itemId,
  118. itemName = summary.itemName,
  119. taoToken = summary.taoToken,
  120. shortLinkUrl = shortLinkUrl,
  121. deeplinkUrl = deeplinkUrl,
  122. tradeId = item.tradeId,
  123. tradeParentId = item.tradeParentId,
  124. create_time = summary.create_time,
  125. click_time = item.clickTime,
  126. paid_time = item.tbPaidTime,
  127. exp_time = expTime,
  128. click_num = click_num,
  129. };
  130. conn.Replace(data);
  131. RemoveLinkSummary(item.accountId, item.itemTitle);
  132. return true;
  133. }
  134. }
  135. }