OrderTrackingCore.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. namespace molilian.core
  17. {
  18. public partial class TkOrderTrackingCore
  19. {
  20. public static void SaveLinkSummary(TkDataDTO item)
  21. {
  22. var config = TkConfigCore.Get();
  23. var ttl = config.fake_click_ttl * 3600;
  24. string cacheKey = $":cache:order_summary:{item.accountName}:{item.itemId}";
  25. RedisHelper.Set(cacheKey, item, ttl);
  26. cacheKey = $":cache:order_summary:{item.accountName}:{item.itemName}";
  27. RedisHelper.Set(cacheKey, item, ttl);
  28. cacheKey = $":cache:order_summary:{item.accountId}:{item.itemId}";
  29. RedisHelper.Set(cacheKey, item, ttl);
  30. cacheKey = $":cache:order_summary:{item.accountId}:{item.itemName}";
  31. RedisHelper.Set(cacheKey, item, ttl);
  32. }
  33. //过时待删
  34. public static TkDataDTO GetLinkSummary(string accountName, string name)
  35. {
  36. string cacheKey = $":cache:order_summary:{accountName}:{name}";
  37. return RedisHelper.Get<TkDataDTO>(cacheKey);
  38. }
  39. //过时待删
  40. public static void RemoveLinkSummary(string accountName, string itemId)
  41. {
  42. string cacheKey = $":cache:order_summary:{accountName}:{itemId}";
  43. RedisHelper.Del(cacheKey);
  44. }
  45. public static TkDataDTO GetLinkSummary(int accountId, string name)
  46. {
  47. string cacheKey = $":cache:order_summary:{accountId}:{name}";
  48. return RedisHelper.Get<TkDataDTO>(cacheKey);
  49. }
  50. public static void RemoveLinkSummary(int accountId, string itemId)
  51. {
  52. string cacheKey = $":cache:order_summary:{accountId}:{itemId}";
  53. RedisHelper.Del(cacheKey);
  54. }
  55. public static bool MatchOrder(TkOrderDetailDTO item, IDbConnection conn)
  56. {
  57. if (item.tbPaidTime < DateTime.Now.AddDays(-1)) return false;
  58. var summary = GetLinkSummary(item.accountId, item.itemTitle);
  59. if (summary == null)
  60. {
  61. summary = GetLinkSummary(item.accountName, item.itemTitle);
  62. if (summary == null) return false;
  63. }
  64. var config = TkConfigCore.Get();
  65. Random rand = new();
  66. int click_num = rand.Next(config.fake_click_min, config.fake_click_max + 1);
  67. DateTime paidTime = item.tbPaidTime;
  68. if (paidTime < summary.create_time) return false;
  69. int minutes = paidTime.Minute / 10 * 10;
  70. DateTime rounded = new(paidTime.Year, paidTime.Month, paidTime.Day, paidTime.Hour, minutes, 0);
  71. string batchId = rounded.ToString("yyyyMMddHHmm");
  72. string accountName = item.accountName;
  73. DateTime expTime = item.tbPaidTime.Hour >= 21 ? item.tbPaidTime.AddHours(3) : item.tbPaidTime.Date.AddDays(1);
  74. var data = new TkOrderTrackingDTO()
  75. {
  76. channel = summary.channel,
  77. accountId = item.accountId,
  78. accountName = accountName,
  79. batchId = batchId,
  80. ip = summary.ip,
  81. oaid = summary.oaid,
  82. itemId = summary.itemId,
  83. itemName = summary.itemName,
  84. taoToken = summary.taoToken,
  85. shortLinkUrl = summary.shortLinkurl,
  86. deeplinkUrl = summary.deeplink_url,
  87. tradeId = item.tradeId,
  88. tradeParentId = item.tradeParentId,
  89. create_time = summary.create_time,
  90. click_time = item.clickTime,
  91. paid_time = item.tbPaidTime,
  92. exp_time = expTime,
  93. click_num = click_num,
  94. };
  95. conn.Replace(data);
  96. RemoveLinkSummary(item.accountId, item.itemTitle);
  97. RemoveLinkSummary(item.accountName, item.itemTitle);
  98. return true;
  99. }
  100. }
  101. }