dodo hold 1 년 전
부모
커밋
582d645dc2

+ 8 - 0
molilian.api/Controllers/admin/PddUnionController.cs

@@ -229,6 +229,14 @@ namespace molilian.api.Controllers
         }
 
 
+        [HttpGet]
+        public ActionResult RechargeAllOnlineAccountUsage()
+        {
+            int count = PddPoolCore.RechargeAllOnlineAccountUsage();
+            return new APIResult(new { msg = "ok", count });
+        }
+
+
         [HttpPost]
         public ActionResult estimate_revenue([FromBody] JsonElement form)
         {

+ 9 - 5
molilian.api/Controllers/public/TaskController.cs

@@ -235,6 +235,9 @@ namespace molilian.api.Controllers
             {
                 if (!account.enable_sync_order) continue;
 
+#if DEBUG
+                if (account.id != 113) continue;
+#endif
                 try
                 {
                     var alimama = new AlimamaPlus(account);
@@ -665,7 +668,7 @@ namespace molilian.api.Controllers
 
                 string filter = "";
 #if DEBUG
-                filter = "id IN (37, 15)";
+                filter = "id IN (44)";
 #endif
                 var jd_list = new DBContext.Table("jd_pool").Where(filter, null).Select<JdPoolDTO>();
 
@@ -910,11 +913,12 @@ namespace molilian.api.Controllers
         }
 
         [HttpGet]
-        public async Task<ActionResult> JdSaveReport()
+        public async Task<ActionResult> JdSaveReport(int id = 0)
         {
             string message = string.Empty;
-
-            var jd_list = new DBContext.Table("jd_pool").Where("", null).Select<JdPoolDTO>();
+            string filter = string.Empty;
+            if (id > 0) filter = "id=@id";
+            var jd_list = new DBContext.Table("jd_pool").Where(filter, new { id }).Select<JdPoolDTO>();
             if (jd_list != null)
             {
                 DateTime startDate = DateTime.Now.AddDays(-89);
@@ -928,7 +932,7 @@ namespace molilian.api.Controllers
                     if (account.id != 15) continue;
 #endif
                     if (account.is_hide) continue;
-                    if (!account.enable_sync_report) continue;
+                    if (id == 0 && !account.enable_sync_report) continue;
 
                     if (!string.IsNullOrEmpty(account.union_cookies))
                     {

+ 4 - 6
molilian.api/Controllers/public/TkActivityController.cs

@@ -40,6 +40,7 @@ namespace molilian.api.Controllers
             //正文
             var page_id = form.Read("page_id", string.Empty);
             var item_id = form.Read("item_id", string.Empty);
+            var strategy_id = form.Read("strategy_id", string.Empty);
             var ip = form.Read("ip", string.Empty);
             var oaid = form.Read("oaid", string.Empty);
 
@@ -72,7 +73,7 @@ namespace molilian.api.Controllers
                 _ => "top",
             };
 
-            return await TkActivityCore.ParseAsync(page_id, prefix, item_id, ip, oaid);
+            return await TkActivityCore.ParseAsync(page_id, prefix, item_id, ip, oaid, strategy_id);
         }
 
 
@@ -83,11 +84,8 @@ namespace molilian.api.Controllers
             var item_id = form.Read("item_id", string.Empty);
             var ip = form.Read("ip", string.Empty);
             var oaid = form.Read("oaid", string.Empty);
+            var strategy_id = form.Read("strategy_id", string.Empty);
 
-#if  DEBUG
-            page_id = "20150318020016140";
-            item_id = "pJZdQkbf2C6Zrxn0KxT5aAIptm-kPVnNrKI8PQmnQxXFk2";
-#endif
 
             string prefix = page_id switch
             {
@@ -95,7 +93,7 @@ namespace molilian.api.Controllers
                 _ => "top",
             };
 
-            return await TkActivityCore.ParseAsync(page_id, prefix, item_id, ip, oaid);
+            return await TkActivityCore.ParseAsync(page_id, prefix, item_id, strategy_id, ip, oaid);
         }
 
 

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
molilian.api/Properties/PublishProfiles/latest.pubxml.user


+ 2 - 1
molilian.core/Core/log/tkActivity.cs

@@ -25,7 +25,8 @@ namespace molilian.core
                     if (TestParseCore.InWhitelist(data.ip, data.oaid))
                     {
                         // For test environment, could create a test version if needed
-                        connection.Insert(data);
+                        string daily_table = $"tk_activity_logs_test";
+                        save_activity_logs(data, daily_table, connection, transaction);
                     }
                     else
                     {

+ 42 - 2
molilian.core/Core/pdd/PddPoolCore.cs

@@ -14,7 +14,6 @@ using TencentCloud.Tcm.V20210413.Models;
 using System.Security.Cryptography;
 using System.Collections.Concurrent;
 using YunhuiKit;
-using Microsoft.AspNetCore.Components.RenderTree;
 
 
 namespace molilian.core
@@ -56,7 +55,7 @@ namespace molilian.core
 
             return list.Where(e => IsMatch(e, mode, accountid))
                 .OrderBy(account => GetCurrentDayUsageFromRedis(account.id))
-                .ThenBy(account => account.id) // 相同使用次数时按ID排序,确保稳定性
+                .ThenBy(account => Guid.NewGuid()) // 相同使用次数时随机排序
                 .FirstOrDefault();
         }
 
@@ -122,6 +121,47 @@ namespace molilian.core
             }
         }
 
+        /// <summary>
+        /// 重置所有在线账号的当日调用次数Redis计数器
+        /// 随机排序账号后,每个账号间隔1递增value
+        /// </summary>
+        public static int RechargeAllOnlineAccountUsage()
+        {
+            try
+            {
+                var onlineAccounts = List()?.Where(a => a.status && a.enable_parse).ToList();
+                if (onlineAccounts == null || !onlineAccounts.Any())
+                {
+                    return 0;
+                }
+
+                var today = DateTime.Now.ToString("yyyyMMdd");
+
+                // 随机排序账号
+                var random = new Random();
+                var shuffledAccounts = onlineAccounts.OrderBy(x => random.Next()).ToList();
+
+                int incrementValue = 1;
+                int rechargedCount = 0;
+
+                foreach (var account in shuffledAccounts)
+                {
+                    string key = $"pdd_daily_usage:{account.id}:{today}";
+
+                    // 设置递增的value并设置24小时过期时间
+                    RedisHelper.Set(key, incrementValue, 86400);
+                    RedisHelper.Set(key, 0, 86400);
+                    incrementValue++;
+                    rechargedCount++;
+                }
+                return rechargedCount;
+            }
+            catch (Exception ex)
+            {
+            }
+            return 0;
+        }
+
         /// <summary>
         /// 为新上线的账号设置平均使用次数,避免流量集中
         /// </summary>

+ 13 - 9
molilian.core/Core/taoke/OrderTrackingCore.cs

@@ -15,6 +15,7 @@ using System.Security.Cryptography;
 using System.Data;
 using System.Threading.Channels;
 using YunhuiKit;
+using System.IO;
 
 
 namespace molilian.core
@@ -33,6 +34,7 @@ namespace molilian.core
                 channel = item.channel,
                 ip = item.ip,
                 oaid = item.oaid,
+                mktId = item.mktId,
                 itemId = item.itemId,
                 itemName = item.itemName,
                 taoToken = item.taoToken,
@@ -59,7 +61,7 @@ namespace molilian.core
         }
 
 
-        public static async Task<TkDataDTO> GetLinkSummaryAsync(TkPoolDTO account, string itemId, string mktId, string itemTitle)
+        public static async Task<(int, TkDataDTO)> GetLinkSummaryAsync(TkPoolDTO account, string itemId, string mktId, string itemTitle)
         {
             try
             {
@@ -86,7 +88,7 @@ namespace molilian.core
                         try
                         {
                             var redisServer = EndPointCore.GetRedisServer(node);
-                            if (string.IsNullOrEmpty(redisServer)) return null;
+                            if (string.IsNullOrEmpty(redisServer)) return (0, null);
 
 
                             using var scope = await RedisClientFactory.CreateScopeAsync(redisServer);
@@ -102,18 +104,18 @@ namespace molilian.core
                                 if (!string.IsNullOrEmpty(mktId))
                                 {
                                     result = await redis.GetAsync<TkDataDTO>($":cache:order_summary:{relatedId}:mktId:{mktId}");
-                                    if (result != null) return result;
+                                    if (result != null) return (1, result);
                                 }
 
                                 if (!string.IsNullOrEmpty(itemId))
                                 {
                                     result = await redis.GetAsync<TkDataDTO>($":cache:order_summary:{relatedId}:{itemId}");
-                                    if (result != null) return result;
+                                    if (result != null) return (2, result);
 
                                     if (!string.IsNullOrEmpty(itemTitle))
                                     {
                                         result = await redis.GetAsync<TkDataDTO>($":cache:order_summary:{relatedId}:{itemTitle}");
-                                        if (result != null) return result;
+                                        if (result != null) return (3, result);
                                     }
                                 }
                             }
@@ -121,16 +123,16 @@ namespace molilian.core
                         catch (Exception ex)
                         {
                         }
-                        return null;
+                        return (0, null);
                     });
 
                 var results = await Task.WhenAll(tasks);
-                return results.FirstOrDefault(r => r != null);
+                return results.FirstOrDefault(r => r != (0, null));
             }
             catch (Exception)
             {
                 // TODO: 添加日志记录
-                return null;
+                return (0, null);
             }
         }
 
@@ -201,7 +203,7 @@ namespace molilian.core
             DateTime now = DateTime.Now;
             if (item.tbPaidTime < now.AddDays(-24)) return false;
 
-            var summary = await GetLinkSummaryAsync(account, item.itemId, item.mktId, item.itemTitle);
+            (int match_type, var summary) = await GetLinkSummaryAsync(account, item.itemId, item.mktId, item.itemTitle);
             if (summary == null) return false;
 
 
@@ -239,6 +241,8 @@ namespace molilian.core
             DateTime expTime = now.Hour >= 21 ? now.AddHours(3) : now.Date.AddDays(1);
             var data = new TkOrderTrackingDTO()
             {
+                match_type = match_type,
+
                 channel = summary.channel,
                 accountId = item.accountId,
                 accountName = accountName,

+ 2 - 1
molilian.core/Core/taoke/RiskControlCore.cs

@@ -97,7 +97,8 @@ namespace molilian.core
 
                             var cacheKey = $"RiskControl:{key}:calls:{flag}";
                             using var scope = await RedisClientFactory.CreateScopeAsync(redisServer);
-                            return await scope.Client.GetAsync<int>(cacheKey);
+                            int count = await scope.Client.GetAsync<int>(cacheKey);
+                            return count;
                         }
                         catch (Exception ex) { }
                         return 0;

+ 2 - 2
molilian.core/Core/taoke/TkActivityCore.cs

@@ -15,7 +15,7 @@ namespace molilian.core
         }
 
 
-        public static async Task<ActionResult> ParseAsync(string page_id, string prefix, string item_id, string ip, string oaid)
+        public static async Task<ActionResult> ParseAsync(string page_id, string prefix, string item_id, string strategy_id, string ip, string oaid)
         {
             AlimamaPlus alimama = null;
 
@@ -64,7 +64,7 @@ namespace molilian.core
                     });
                 }
 
-                var account = await TkPoolCore.GetOneAsync(TkPoolCore.TkAction.activity, false, string.Empty, 0);
+                var account = await TkPoolCore.GetOneAsync(TkPoolCore.TkAction.activity, false, string.Empty, 0, string.Empty, strategy_id);
                 if (account == null)
                 {
                     result.success = false;

+ 27 - 11
molilian.core/Core/taoke/TkPoolCore.cs

@@ -1,4 +1,5 @@
 using dodohold.core;
+using Org.BouncyCastle.Bcpg.OpenPgp;
 using YunhuiKit;
 
 
@@ -55,7 +56,7 @@ namespace molilian.core
             }
             return null;
         }
-        public static async Task<TkPoolDTO> GetOneAsync(TkAction action, bool isTaobaoUrl, string riskStrategy, int launchScene, string parse_type = "")
+        public static async Task<TkPoolDTO> GetOneAsync(TkAction action, bool isTaobaoUrl, string riskStrategy, int launchScene, string parse_type = "", string strategy_id = "")
         {
             var list = await ListAsync().ConfigureAwait(false);
             if (!list.Any())
@@ -66,6 +67,17 @@ namespace molilian.core
             if (allAccounts == null)
                 allAccounts = list; // 如果获取失败,至少使用在线账号列表
 
+            if (!string.IsNullOrEmpty(strategy_id))
+            {
+                list = list.Where(item => strategy_id.Equals(item.strategy_id)).ToList();
+            }
+            else
+            {
+                list = list.Where(item => string.IsNullOrEmpty(item.strategy_id)).ToList();
+            }
+            if (!list.Any()) return null;
+
+
             if ("dp".Equals(parse_type))
             {
                 list = list.Where(item => "dp".Equals(item.parse_type)).ToList();
@@ -73,17 +85,21 @@ namespace molilian.core
             }
             else
             {
-                if (!string.IsNullOrEmpty(riskStrategy) && !"os".Equals(riskStrategy) && launchScene != -1)
-                {
-                    list = list.Where(item => string.IsNullOrEmpty(item.parse_type) && riskStrategy.Equals(item.riskStrategy) && item.launchScene == launchScene).ToList();
-                    if (!list.Any()) return null;
-                }
-                else
-                {
-                    list = list.Where(item => string.IsNullOrEmpty(item.parse_type) && string.IsNullOrEmpty(item.riskStrategy)).ToList();
-                    if (!list.Any()) return null;
-                }
+                list = list.Where(item => string.IsNullOrEmpty(item.parse_type)).ToList();
+            }
+            if (!list.Any()) return null;
+
+
+            if (!string.IsNullOrEmpty(riskStrategy) && !"os".Equals(riskStrategy) && launchScene != -1)
+            {
+                list = list.Where(item => riskStrategy.Equals(item.riskStrategy) && item.launchScene == launchScene).ToList();
             }
+            else
+            {
+                list = list.Where(item => string.IsNullOrEmpty(item.riskStrategy)).ToList();
+            }
+            if (!list.Any()) return null;
+
 
 
             var filteredList = new List<TkPoolDTO>();

+ 35 - 14
molilian.core/Core/taoke/UnionParseCore/UnionParseCore.cs

@@ -797,17 +797,46 @@ namespace molilian.core
 
                 for (int i = 0; i < 3; i++)
                 {
-                    account = PddPoolCore.GetOne(PddUnionWorkMode.All, accountid);
-                    if (account == null) continue;
+                    for (int j = 0; j < 3; j++)
+                    {
+                        account = PddPoolCore.GetOne(PddUnionWorkMode.All, accountid);
+                        if (account == null) continue;
+
+                        if (account.cis_limit > 0)
+                        {
+                            lockKey = $"pdd_cis_limit_{result.accountId}";
+                            cis_num = RedisHelper.Get<long>(lockKey);
+                            if (cis_num > 0) continue;
+                        }
+                        break;
+                    }
+                    if (account == null)
+                    {
+                        result.success = false;
+                        result.message = "放弃转链";
+                        result.reason = "没有匹配账号";
+                        result.deeplink_url = PddUnionPlus.GetDeeplink(result.rawContent);
+                        _ = TkLogCore.ParseLogAsync(result);
+                        return PddParseOutput(result);
+                    }
+                    result.accountId = account.id;
+                    result.accountName = account.name;
+                    result.proxy_node = account.nodeName;
 
                     if (account.cis_limit > 0)
                     {
+                        // 更新当前分钟的使用统计
+                        PddPoolCore.UpdateAccountUsage(account.id);
+
                         lockKey = $"pdd_cis_limit_{result.accountId}";
-                        cis_num = RedisHelper.Get<long>(lockKey);
-                        if (cis_num > 0) continue;
+                        cis_num = RedisHelper.IncrBy(lockKey);
+                        if (cis_num > 1) continue;
+
+                        RedisHelper.Expire(lockKey, TimeSpan.FromMilliseconds(account.cis_limit));
                     }
                     break;
                 }
+
                 if (account == null)
                 {
                     result.success = false;
@@ -817,17 +846,10 @@ namespace molilian.core
                     _ = TkLogCore.ParseLogAsync(result);
                     return PddParseOutput(result);
                 }
-                result.accountId = account.id;
-                result.accountName = account.name;
-                result.proxy_node = account.nodeName;
-
-                if (account.cis_limit > 0)
+                if (account?.cis_limit > 0)
                 {
-                    // 更新当前分钟的使用统计
-                    PddPoolCore.UpdateAccountUsage(account.id);
-
                     lockKey = $"pdd_cis_limit_{result.accountId}";
-                    cis_num = RedisHelper.IncrBy(lockKey);
+                    cis_num = RedisHelper.Get<int>(lockKey);
                     if (cis_num > 1)
                     {
                         result.success = false;
@@ -837,7 +859,6 @@ namespace molilian.core
                         _ = TkLogCore.ParseLogAsync(result);
                         return PddParseOutput(result);
                     }
-                    RedisHelper.Expire(lockKey, TimeSpan.FromMilliseconds(account.cis_limit));
                 }
                 var plus = new PddUnionPlus(account);
                 result = await plus.PddParseAsync(content, commerceType, result, cancellationToken);

+ 35 - 16
molilian.core/Core/taoke/UnionParseCore/dp2dp.cs

@@ -678,17 +678,46 @@ namespace molilian.core
 
                 for (int i = 0; i < 3; i++)
                 {
-                    account = PddPoolCore.GetOne(PddUnionWorkMode.All, accountid, "dp");
-                    if (account == null) continue;
+                    for (int j = 0; j < 3; j++)
+                    {
+                        account = PddPoolCore.GetOne(PddUnionWorkMode.All, accountid, "dp");
+                        if (account == null) continue;
+
+                        if (account.cis_limit > 0)
+                        {
+                            lockKey = $"pdd_cis_limit_{result.accountId}";
+                            cis_num = RedisHelper.Get<long>(lockKey);
+                            if (cis_num > 0) continue;
+                        }
+                        break;
+                    }
+                    if (account == null)
+                    {
+                        result.success = false;
+                        result.message = "放弃转链";
+                        result.reason = "没有匹配账号";
+                        result.deeplink_url = PddUnionPlus.GetDeeplink(result.rawContent);
+                        _ = TkLogCore.ParseLogAsync(result);
+                        return PddParseOutput(result);
+                    }
+                    result.accountId = account.id;
+                    result.accountName = account.name;
+                    result.proxy_node = account.nodeName;
 
                     if (account.cis_limit > 0)
                     {
+                        // 更新当前分钟的使用统计
+                        PddPoolCore.UpdateAccountUsage(account.id);
+
                         lockKey = $"pdd_cis_limit_{result.accountId}";
-                        cis_num = RedisHelper.Get<long>(lockKey);
-                        if (cis_num > 0) continue;
+                        cis_num = RedisHelper.IncrBy(lockKey);
+                        if (cis_num > 1) continue;
+
+                        RedisHelper.Expire(lockKey, TimeSpan.FromMilliseconds(account.cis_limit));
                     }
                     break;
                 }
+
                 if (account == null)
                 {
                     result.success = false;
@@ -698,17 +727,10 @@ namespace molilian.core
                     _ = TkLogCore.ParseLogAsync(result);
                     return PddParseOutput(result);
                 }
-                result.accountId = account.id;
-                result.accountName = account.name;
-                result.proxy_node = account.nodeName;
-
-                if (account.cis_limit > 0)
+                if (account?.cis_limit > 0)
                 {
-                    // 更新当前分钟的使用统计
-                    PddPoolCore.UpdateAccountUsage(account.id);
-
                     lockKey = $"pdd_cis_limit_{result.accountId}";
-                    cis_num = RedisHelper.IncrBy(lockKey);
+                    cis_num = RedisHelper.Get<int>(lockKey);
                     if (cis_num > 1)
                     {
                         result.success = false;
@@ -718,10 +740,7 @@ namespace molilian.core
                         _ = TkLogCore.ParseLogAsync(result);
                         return PddParseOutput(result);
                     }
-                    RedisHelper.Expire(lockKey, TimeSpan.FromMilliseconds(account.cis_limit));
-
                 }
-
                 var plus = new PddUnionPlus(account);
 
                 result = await plus.PddParseAsync(content, commerceType, result, cancellationToken);

+ 1 - 0
molilian.core/DTO/alimama/TkOrderTrackingDTO.cs

@@ -30,6 +30,7 @@ namespace molilian.core
         public DateTime paid_time { get; set; } = DateTime.MinValue;
         public int click_num { get; set; } = 0;
         public int clicked_num { get; set; } = 0;
+        public int match_type { get; set; } = 0;
     }
 
 }

+ 1 - 0
molilian.core/DTO/alimama/TkPoolDTO.cs

@@ -71,6 +71,7 @@
         public int launchScene { get; set; } = -1;
         public bool useCouponLinkFirst { get; set; } = true;
         public string parse_type { get; set; } = string.Empty;
+        public string strategy_id { get; set; } = string.Empty;
 
     }
 }

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 6
molilian.core/Plus/Alimama/orders.cs


+ 3 - 4
molilian.core/Plus/Alimama/tkActivity.cs

@@ -35,7 +35,7 @@ namespace molilian.core
                 result.reason = "接口异常";
                 return result;
             }
-            string cps_short_url = response?.Data?.EventUrlList?[0]?.LinkInfoDto?.CpsShortUrl;
+            Topsdk.Top.Defaultability.Domain.TaobaoTbkDgGeneralLinkConvertEventUrlList urlList = response?.Data?.EventUrlList?[0];
 
             //-----
             result.channel = data.channel;
@@ -43,7 +43,8 @@ namespace molilian.core
             result.reason = data.reason;
             result.message = data.success ? "OK" : data.message;
 
-            if (result.success)
+            string cps_short_url = urlList?.LinkInfoDto?.CpsShortUrl;
+            if (result.success && urlList != null && urlList.Code == null)
             {
                 result.deeplink_url = GetDeeplink(cps_short_url);
 
@@ -51,8 +52,6 @@ namespace molilian.core
 
                 result = await aliyun_same(result.raw_item_id, result, cancellationToken);
 
-
-
                 //if (data.couponAmount == 0)
                 //{
                 //    result.success = false;

+ 4 - 1
molilian.core/Plus/JDUnion/SpreadEffect.cs

@@ -1,4 +1,5 @@
 using dodohold.core;
+using Microsoft.AspNetCore.Components.Server;
 using Sayaka.Common;
 
 
@@ -12,7 +13,7 @@ namespace molilian.core
 
             var ts = DateTime.Now.Convert2UnixTimestamp(true);
             string cookies = _account.union_cookies;
-
+       
             string useragent = _account.user_agent;
             if (string.IsNullOrEmpty(useragent)) useragent = ProviderFakeUserAgent.RandomComputer;
 
@@ -39,6 +40,8 @@ namespace molilian.core
                 string data = args.Convert2Json().UrlEncode();
                 string url = $"https://api.m.jd.com/api?functionId=union_report&appid=unionpc&loginType=3&body={data}";
 
+
+
                 WebClientUtility client = new WebClientUtility();
                 client.Proxy = _proxy;
 #if DEBUG

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.