2
0

2 Sitoutukset dd9d4a3a5d ... 0299a4709c

Tekijä SHA1 Viesti Päivämäärä
  dodo hold 0299a4709c 搜同款增加useCouponLinkFirst支持 2 kuukautta sitten
  dodo hold 0d4fc1f70a 0623 2 kuukautta sitten

+ 8 - 6
molilian.api/Controllers/public/ApiController.cs

@@ -86,6 +86,7 @@ namespace molilian.api.Controllers
             var oaid = form.Read("oaid", string.Empty);
             var scene = form.Read("scene", string.Empty);
             var recommand = form.Read("recommand", true);
+            var useCouponLinkFirst = form.Read("useCouponLinkFirst", true);
             var aid = form.Read("aid", 0);
 
             //验证签名
@@ -116,7 +117,7 @@ namespace molilian.api.Controllers
                 var bytes = new WebClientUtility().Request(url).ResponseBody;
                 img = Convert.ToBase64String(bytes);
             }
-            return await core.PromotionQueryAsync(img, oaid, ip, scene, recommand, false, aid);
+            return await core.PromotionQueryAsync(img, oaid, ip, scene, recommand, false, aid, useCouponLinkFirst);
         }
 
 
@@ -132,6 +133,7 @@ namespace molilian.api.Controllers
             var scene = form.Read("scene", string.Empty);
             var recommand = form.Read("recommand", true);
             var debug = form.Read("debug", false);
+            var useCouponLinkFirst = form.Read("useCouponLinkFirst", true);
             var aid = form.Read("aid", 0);
 
             int count = form.Read("count", 0);
@@ -152,7 +154,7 @@ namespace molilian.api.Controllers
             {
                 for (int i = 0; i < count; i++)
                 {
-                    _ = core.PromotionQueryAsync(img, oaid, ip, scene, recommand, debug, aid);
+                    _ = core.PromotionQueryAsync(img, oaid, ip, scene, recommand, debug, aid, useCouponLinkFirst);
                 }
                 return new APIResult(new { msg = "ok" });
             }
@@ -166,7 +168,7 @@ namespace molilian.api.Controllers
                 {
                     itemid = AlimamaPlus.ExtractItemId(itemUrl);
                     (APIResult target, PromotionQueryDTO data) = await core.PromotionQueryByItemIdAsync(itemid, oaid, ip, scene, recommand, debug, aid);
-                     
+
 
                     if (data != null)
                     {
@@ -177,16 +179,16 @@ namespace molilian.api.Controllers
                             img = Convert.ToBase64String(bytes);
                         }
                     }
-                    return await core.PromotionQueryAsync(img, oaid, ip, scene, recommand, debug, aid);
+                    return await core.PromotionQueryAsync(img, oaid, ip, scene, recommand, debug, aid, useCouponLinkFirst);
                 }
 
                 if (!string.IsNullOrEmpty(itemid))
                 {
-                    (APIResult result, PromotionQueryDTO data) = await core.PromotionQueryByItemIdAsync(itemid, oaid, ip, scene, recommand, debug, aid);
+                    (APIResult result, PromotionQueryDTO data) = await core.PromotionQueryByItemIdAsync(itemid, oaid, ip, scene, recommand, debug, aid, useCouponLinkFirst);
                     return result;
                 }
             }
-            return await core.PromotionQueryAsync(img, oaid, ip, scene, recommand, debug, aid);
+            return await core.PromotionQueryAsync(img, oaid, ip, scene, recommand, debug, aid, useCouponLinkFirst);
 
         }
 

+ 470 - 18
molilian.api/Controllers/public/TestController.cs

@@ -1,12 +1,14 @@
-using molilian.core;
-using dodohold.core;
-using Microsoft.AspNetCore.Mvc;
-using Org.BouncyCastle.Ocsp;
-using System.Text.Json;
-using System.Runtime.InteropServices;
-using System.Net;
-using System.Threading;
-using Microsoft.AspNetCore.Mvc.RazorPages;
+using molilian.core;
+using dodohold.core;
+using Dapper;
+using Microsoft.AspNetCore.Mvc;
+using Org.BouncyCastle.Ocsp;
+using System.Text.Json;
+using System.Runtime.InteropServices;
+using System.Net;
+using System.Threading;
+using System.Data;
+using Microsoft.AspNetCore.Mvc.RazorPages;
 using TencentCloud.Soe.V20180724.Models;
 using static dodohold.core.ZTOExpress.CreateOrderArgs;
 using static Spire.Xls.Core.Spreadsheet.HTMLOptions;
@@ -457,8 +459,8 @@ namespace molilian.api.Controllers
         }
 
         [HttpPost]
-        public async Task<ActionResult> test1([FromBody] JsonElement form)
-        {
+        public async Task<ActionResult> test1([FromBody] JsonElement form)
+        {
 
             NotifyCore.Notify(new NifyMessage
             {
@@ -472,12 +474,462 @@ namespace molilian.api.Controllers
             {
                 success = true,
                 message = "ok"
-            });
-        }
-
-        [HttpGet]
-        public async Task<ActionResult> xxx()
-        {
+            });
+        }
+
+        [HttpGet]
+        public async Task<ActionResult> RepairTkDailyAccountStats(
+            DateTime startDate = default,
+            DateTime endDate = default,
+            string accountIds = "129,140",
+            string extraNames = "搜同款_楚颜_128众杰科技,搜同款_广哲2",
+            bool dryRun = false,
+            bool repairDailyLogs = true,
+            bool repairRedis = true,
+            bool repairRedisNameKeys = true,
+            int commandTimeoutSeconds = 600)
+        {
+            if (startDate == default) startDate = new DateTime(2026, 6, 16);
+            if (endDate == default) endDate = DateTime.Now.Date;
+            commandTimeoutSeconds = Math.Clamp(commandTimeoutSeconds, 30, 3600);
+
+            startDate = startDate.Date;
+            endDate = endDate.Date;
+            if (endDate < startDate)
+            {
+                return new APIResult(new { success = false, message = "endDate 不能早于 startDate" });
+            }
+
+            var ids = (accountIds ?? string.Empty)
+                .Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
+                .Select(item => int.TryParse(item, out int id) ? id : 0)
+                .Where(id => id > 0)
+                .Distinct()
+                .ToArray();
+
+            if (ids.Length == 0)
+            {
+                return new APIResult(new { success = false, message = "accountIds 不能为空" });
+            }
+
+            using var conn = CenterHub.GetOpenConnection();
+            if (conn.State != ConnectionState.Open) conn.Open();
+
+            var errors = new List<object>();
+            var affectedNames = new HashSet<string>(StringComparer.Ordinal);
+            var accounts = SqlMapper.Query<TkDailyRepairCountRow>(
+                conn,
+                "SELECT id accountId, company accountName FROM tk_pool WHERE id IN @ids",
+                new { ids },
+                commandTimeout: commandTimeoutSeconds).ToList();
+
+            foreach (string name in accounts.Select(item => item.accountName).Where(item => !string.IsNullOrWhiteSpace(item)))
+            {
+                affectedNames.Add(name);
+            }
+
+            extraNames ??= string.Empty;
+            foreach (string name in extraNames
+                .Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
+                .Where(item => !string.IsNullOrWhiteSpace(item)))
+            {
+                affectedNames.Add(name);
+            }
+
+            foreach (string name in SqlMapper.Query<string>(
+                conn,
+                @"
+SELECT DISTINCT accountName
+FROM center_daily_logs
+WHERE channel = 0
+  AND accountId IN @ids
+  AND log_date BETWEEN @startDate AND @endDate
+  AND COALESCE(accountName,'')<>''",
+                new { ids, startDate, endDate },
+                commandTimeout: commandTimeoutSeconds))
+            {
+                affectedNames.Add(name);
+            }
+
+            var days = EachDay(startDate, endDate).ToList();
+            var dailyReports = new List<object>();
+            var endpointCountsByDate = new Dictionary<string, List<TkDailyRepairEndpointCountRow>>();
+            foreach (var date in days)
+            {
+                try
+                {
+                    string tableName = $"tk_parse_logs_{date:yyyyMMdd}";
+                    if (!TableExists(conn, tableName, commandTimeoutSeconds))
+                    {
+                        dailyReports.Add(new { date = date.ToString("yyyy-MM-dd"), tableName, skipped = true, reason = "table not exists" });
+                        continue;
+                    }
+
+                    var endpointCounts = SqlMapper.Query<TkDailyRepairEndpointCountRow>(
+                        conn,
+                        $@"
+SELECT
+    l.accountId,
+    COALESCE(p.company, MAX(l.accountName), '') accountName,
+    COALESCE(l.end_point, '') end_point,
+    COUNT(*) total_count,
+    CAST(COALESCE(SUM(l.success = 1), 0) AS SIGNED) success_count,
+    CAST(COALESCE(SUM(l.success = 0), 0) AS SIGNED) fail_count,
+    CAST(COALESCE(SUM(l.message = '放弃转链' OR l.reason = '放弃转链'), 0) AS SIGNED) abandon_count
+FROM {tableName} l
+LEFT JOIN tk_pool p ON p.id = l.accountId
+WHERE l.accountId IN @ids
+GROUP BY l.accountId, p.company, l.end_point
+ORDER BY l.accountId, l.end_point",
+                        new { ids },
+                        commandTimeout: commandTimeoutSeconds).ToList();
+                    endpointCountsByDate[date.ToString("yyyyMMdd")] = endpointCounts;
+
+                    var accountCounts = endpointCounts
+                        .GroupBy(item => item.accountId)
+                        .Select(group => new TkDailyRepairCountRow
+                        {
+                            accountId = group.Key,
+                            accountName = accounts.FirstOrDefault(item => item.accountId == group.Key)?.accountName
+                                ?? group.FirstOrDefault()?.accountName
+                                ?? string.Empty,
+                            total_count = group.Sum(item => item.total_count),
+                            success_count = group.Sum(item => item.success_count),
+                            fail_count = group.Sum(item => item.fail_count),
+                            abandon_count = group.Sum(item => item.abandon_count)
+                        })
+                        .ToList();
+
+                    int dailyLogRows = 0;
+                    var allAccountCounts = ids
+                        .Select(accountId => accountCounts.FirstOrDefault(item => item.accountId == accountId)
+                            ?? new TkDailyRepairCountRow
+                            {
+                                accountId = accountId,
+                                accountName = accounts.FirstOrDefault(item => item.accountId == accountId)?.accountName ?? string.Empty
+                            })
+                        .ToList();
+
+                    foreach (var counts in allAccountCounts)
+                    {
+                        if (!dryRun && repairDailyLogs)
+                        {
+                            dailyLogRows += UpsertCenterDailyLog(conn, date, counts, commandTimeoutSeconds);
+                        }
+                    }
+
+                    dailyReports.Add(new
+                    {
+                        date = date.ToString("yyyy-MM-dd"),
+                        tableName,
+                        skipped = false,
+                        dailyLogRows,
+                        source = "mysql:tk_parse_logs_yyyyMMdd",
+                        counts = allAccountCounts,
+                        endpointCounts
+                    });
+                }
+                catch (Exception ex)
+                {
+                    var error = new { scope = "daily_log", date = date.ToString("yyyy-MM-dd"), error = FormatRepairError(ex) };
+                    errors.Add(error);
+                    dailyReports.Add(new { date = date.ToString("yyyy-MM-dd"), skipped = true, reason = "error", error });
+                }
+            }
+
+            var endpointReports = new List<object>();
+            if (repairRedis || repairRedisNameKeys)
+            {
+                var endpoints = EndPointCore.List(true)
+                    .Where(node => node.status && node.is_public_api && !string.IsNullOrEmpty(EndPointCore.GetRedisServer(node)))
+                    .ToList();
+
+                foreach (var endpoint in endpoints)
+                {
+                    var redisServer = EndPointCore.GetRedisServer(endpoint);
+                    var endpointReport = new List<object>();
+
+                    try
+                    {
+                        await using var scope = await RedisClientFactory.CreateScopeAsync(redisServer);
+                        var redis = scope.Client;
+
+                        foreach (var date in days)
+                        {
+                            string dateKey = date.ToString("yyyyMMdd");
+                            if (!endpointCountsByDate.TryGetValue(dateKey, out var endpointCounts))
+                            {
+                                continue;
+                            }
+
+                            foreach (int accountId in ids)
+                            {
+                                var counts = endpointCounts.FirstOrDefault(item =>
+                                    item.accountId == accountId &&
+                                    string.Equals(item.end_point, endpoint.name, StringComparison.Ordinal))
+                                    ?? new TkDailyRepairEndpointCountRow
+                                    {
+                                        accountId = accountId,
+                                        accountName = accounts.FirstOrDefault(item => item.accountId == accountId)?.accountName ?? string.Empty,
+                                        end_point = endpoint.name
+                                    };
+
+                                if (!dryRun && repairRedis)
+                                {
+                                    await WriteParseCountKeysAsync(redis, $"tb_{accountId}", dateKey, counts);
+                                }
+
+                                endpointReport.Add(new
+                                {
+                                    date = date.ToString("yyyy-MM-dd"),
+                                    bucket = $"tb_{accountId}",
+                                    counts
+                                });
+                            }
+
+                            if (repairRedisNameKeys)
+                            {
+                                foreach (string name in affectedNames)
+                                {
+                                    var before = await ReadParseCountKeysAsync(redis, name, dateKey);
+
+                                    if (!dryRun)
+                                    {
+                                        await DeleteParseBucketKeysAsync(redis, name, dateKey);
+                                    }
+
+                                    endpointReport.Add(new
+                                    {
+                                        date = date.ToString("yyyy-MM-dd"),
+                                        deletedBucket = name,
+                                        before
+                                    });
+                                }
+                            }
+                        }
+                    }
+                    catch (Exception ex)
+                    {
+                        errors.Add(new { scope = "redis_endpoint", endpoint = endpoint.name, error = FormatRepairError(ex) });
+                    }
+
+                    endpointReports.Add(new
+                    {
+                        endpoint = endpoint.name,
+                        endpoint.description,
+                        dryRun,
+                        deletedBuckets = endpointReport
+                    });
+                }
+            }
+
+            return new APIResult(new
+            {
+                success = errors.Count == 0,
+                dryRun,
+                accountIds = ids,
+                extraNames,
+                repairDailyLogs,
+                repairRedis,
+                repairRedisNameKeys,
+                commandTimeoutSeconds,
+                startDate = startDate.ToString("yyyy-MM-dd"),
+                endDate = endDate.ToString("yyyy-MM-dd"),
+                affectedNames = affectedNames.OrderBy(item => item).ToList(),
+                mysql = dailyReports,
+                redis = endpointReports,
+                errors
+            });
+        }
+
+        private static IEnumerable<DateTime> EachDay(DateTime startDate, DateTime endDate)
+        {
+            for (var date = startDate.Date; date <= endDate.Date; date = date.AddDays(1))
+            {
+                yield return date;
+            }
+        }
+
+        private static bool TableExists(IDbConnection conn, string tableName, int commandTimeoutSeconds)
+        {
+            const string sql = @"
+SELECT COUNT(*)
+FROM information_schema.tables
+WHERE table_schema = DATABASE()
+  AND table_name = @tableName";
+            return SqlMapper.ExecuteScalar<int>(
+                conn,
+                sql,
+                new { tableName },
+                commandTimeout: commandTimeoutSeconds) > 0;
+        }
+
+        private static int UpsertCenterDailyLog(IDbConnection conn, DateTime date, TkDailyRepairCountRow counts, int commandTimeoutSeconds)
+        {
+            if (string.IsNullOrWhiteSpace(counts.accountName)) return 0;
+
+            string successPercentage = counts.total_count > 0 ? $"{counts.success_count / (double)counts.total_count * 100:f2}%" : string.Empty;
+            string abandonPercentage = counts.total_count > 0 ? $"{counts.abandon_count / (double)counts.total_count * 100:f2}%" : string.Empty;
+
+            var existingIds = SqlMapper.Query<int>(
+                conn,
+                @"
+SELECT id
+FROM center_daily_logs
+WHERE channel = 0
+  AND log_date = @date
+  AND accountId = @accountId
+ORDER BY id",
+                new { date, counts.accountId },
+                commandTimeout: commandTimeoutSeconds).ToList();
+
+            if (existingIds.Count > 0)
+            {
+                int affectedRows = SqlMapper.Execute(
+                    conn,
+                    @"
+UPDATE center_daily_logs
+SET accountName = @accountName,
+    parse_total_count = @totalCount,
+    parse_success_count = @successCount,
+    parse_abandon_count = @abandonCount,
+    parse_success_percentage = @successPercentage,
+    parse_abandon_percentage = @abandonPercentage,
+    last_time = NOW()
+WHERE id = @id",
+                    new
+                    {
+                        id = existingIds[0],
+                        counts.accountName,
+                        totalCount = counts.total_count,
+                        successCount = counts.success_count,
+                        abandonCount = counts.abandon_count,
+                        successPercentage,
+                        abandonPercentage
+                    },
+                    commandTimeout: commandTimeoutSeconds);
+
+                if (existingIds.Count > 1)
+                {
+                    affectedRows += SqlMapper.Execute(
+                        conn,
+                        "DELETE FROM center_daily_logs WHERE id IN @ids",
+                        new { ids = existingIds.Skip(1).ToArray() },
+                        commandTimeout: commandTimeoutSeconds);
+                }
+
+                return affectedRows;
+            }
+
+            if (counts.total_count <= 0) return 0;
+
+            return SqlMapper.Execute(
+                conn,
+                @"
+INSERT INTO center_daily_logs
+    (channel, accountId, accountName, log_date, create_time, last_time,
+     parse_total_count, parse_success_count, parse_abandon_count,
+     parse_success_percentage, parse_abandon_percentage)
+VALUES
+    (0, @accountId, @accountName, @date, NOW(), NOW(),
+     @totalCount, @successCount, @abandonCount,
+     @successPercentage, @abandonPercentage)",
+                new
+                {
+                    date,
+                    counts.accountId,
+                    counts.accountName,
+                    totalCount = counts.total_count,
+                    successCount = counts.success_count,
+                    abandonCount = counts.abandon_count,
+                    successPercentage,
+                    abandonPercentage
+                },
+                commandTimeout: commandTimeoutSeconds);
+        }
+
+        private static async Task<TkDailyRepairCountRow> ReadParseCountKeysAsync(YunhuiKit.RedisClient redis, string bucket, string dateKey)
+        {
+            return new TkDailyRepairCountRow
+            {
+                accountName = bucket,
+                total_count = await redis.GetAsync<int>($":parse_total:{bucket}:{dateKey}"),
+                success_count = await redis.GetAsync<int>($":parse_total:{bucket}:success:{dateKey}"),
+                fail_count = await redis.GetAsync<int>($":parse_total:{bucket}:fail:{dateKey}"),
+                abandon_count = await redis.GetAsync<int>($":parse_total:{bucket}:放弃转链:{dateKey}")
+            };
+        }
+
+        private static async Task DeleteParseBucketKeysAsync(YunhuiKit.RedisClient redis, string bucket, string dateKey)
+        {
+            var keys = new List<string>
+            {
+                $":parse_total:{bucket}:{dateKey}",
+                $":parse_total:{bucket}:success:{dateKey}",
+                $":parse_total:{bucket}:fail:{dateKey}",
+                $":parse_total:{bucket}:放弃转链:{dateKey}",
+                $":parse_total:{bucket}:message:{dateKey}",
+                $":parse_total:{bucket}:reason:{dateKey}"
+            };
+
+            foreach (string dpBucket in new[] { "dp_none", "dp_home", "dp_success", "dp_fail" })
+            {
+                keys.Add($":parse_total:{dpBucket}:{bucket}:{dateKey}");
+                keys.Add($":parse_total:{dpBucket}:{bucket}:success:{dateKey}");
+                keys.Add($":parse_total:{dpBucket}:{bucket}:fail:{dateKey}");
+                keys.Add($":parse_total:{dpBucket}:{bucket}:放弃转链:{dateKey}");
+                keys.Add($":parse_total:{dpBucket}:{bucket}:message:{dateKey}");
+                keys.Add($":parse_total:{dpBucket}:{bucket}:reason:{dateKey}");
+            }
+
+            await redis.DelAsync(keys.ToArray());
+        }
+
+        private static string FormatRepairError(Exception ex)
+        {
+            return ex.InnerException == null ? ex.Message : $"{ex.Message} | {ex.InnerException.Message}";
+        }
+
+        private static async Task WriteParseCountKeysAsync(YunhuiKit.RedisClient redis, string bucket, string dateKey, TkDailyRepairCountRow counts)
+        {
+            var keys = new[]
+            {
+                $":parse_total:{bucket}:{dateKey}",
+                $":parse_total:{bucket}:success:{dateKey}",
+                $":parse_total:{bucket}:fail:{dateKey}",
+                $":parse_total:{bucket}:放弃转链:{dateKey}"
+            };
+
+            if (counts.total_count <= 0)
+            {
+                await redis.DelAsync(keys);
+                return;
+            }
+
+            await redis.SetAsync(keys[0], counts.total_count, 90 * 86400);
+            await redis.SetAsync(keys[1], counts.success_count, 90 * 86400);
+            await redis.SetAsync(keys[2], counts.fail_count, 90 * 86400);
+            await redis.SetAsync(keys[3], counts.abandon_count, 90 * 86400);
+        }
+
+        private class TkDailyRepairCountRow
+        {
+            public int accountId { get; set; }
+            public string accountName { get; set; } = string.Empty;
+            public long total_count { get; set; }
+            public long success_count { get; set; }
+            public long fail_count { get; set; }
+            public long abandon_count { get; set; }
+        }
+
+        private sealed class TkDailyRepairEndpointCountRow : TkDailyRepairCountRow
+        {
+            public string end_point { get; set; } = string.Empty;
+        }
+
+        [HttpGet]
+        public async Task<ActionResult> xxx()
+        {
             var list = await TkPoolCore.ListAsync();
             if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
             string message = string.Empty;
@@ -506,4 +958,4 @@ namespace molilian.api.Controllers
 
 
     }
-}
+}

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
molilian.api/Properties/PublishProfiles/latest.pubxml.user


+ 2 - 2
molilian.api/Properties/launchSettings.json

@@ -16,7 +16,7 @@
         "CenterDB": "",
         "CenterRedis": ""
       },
-      "environmentVariables222": {
+      "environmentVariables": {
         "ASPNETCORE_ENVIRONMENT": "Development",
         "EndPoint": "sh1",
         "NtfyServer": "https://ntfy.yunhui800.com/similar",
@@ -26,7 +26,7 @@
         "RedisConfig": "47.102.204.251:6379,password=pKBiS4ka2IpXayIdcx00,defaultDDB_REDISatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=similar",
         "DB_REDIS": "47.102.204.251:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=similar"
       },
-      "environmentVariables": {
+      "environmentVariables22": {
         "ASPNETCORE_ENVIRONMENT": "Development",
         "EndPoint": "bj",
         "NtfyServer": "https://ntfy.yunhui800.com/5Sq9BytXXM5WDY3G",

+ 3 - 3
molilian.core/Core/aliyun/AliyunCore.cs

@@ -47,7 +47,7 @@ namespace molilian.core
             return await plus.SearchByPicAsync(base64String, pid);
         }
 
-        public async Task<PromotionQueryDTO> picSimilaritemAsync(string pic, string pid, PromotionQueryDTO result)
+        public async Task<PromotionQueryDTO> picSimilaritemAsync(string pic, string pid, PromotionQueryDTO result, bool useCouponLinkFirst = true)
         {
             var response = await plus.SearchByPicAsync(pic, pid);
             if (response == null)
@@ -74,8 +74,8 @@ namespace molilian.core
                 PromotionQueryItemDTO newItem = new()
                 {
                     itemId = item.ItemId,
-                    h5_url = string.IsNullOrEmpty(item.CouponShareUrl) ? item.Url : item.CouponShareUrl,
-                    deeplink_url = string.IsNullOrEmpty(item.DeeplinkCouponShareUrl) ? item.DeeplinkUrl : item.DeeplinkCouponShareUrl,
+                    h5_url = useCouponLinkFirst && !string.IsNullOrEmpty(item.CouponShareUrl) ? item.CouponShareUrl : item.Url,
+                    deeplink_url = useCouponLinkFirst && !string.IsNullOrEmpty(item.DeeplinkCouponShareUrl) ? item.DeeplinkCouponShareUrl : item.DeeplinkUrl,
                     userType = $"{item.UserType}",
                     shopTitle = item.ShopTitle,
                     itemName = item.Title,

+ 45 - 35
molilian.core/Core/log/base.cs

@@ -336,23 +336,28 @@ namespace molilian.core
             };
 
             //关于dp的缓存
-            await SaveParseAccountCacheAsync($"dp_{dp_flag}:all", success, message, reason);
-            await SaveParseAccountCacheAsync($"dp_{dp_flag}:{channel}", success, message, reason);
-            await SaveParseAccountCacheAsync($"dp_{dp_flag}:{accountName}", success, message, reason);
-            if (accountId != 0)
-            {
-                await SaveParseAccountCacheAsync($"dp_{dp_flag}:{channel}_{accountId}", success, message, reason);
-            }
-
-            await SaveParseAccountCacheAsync("all", success, message, reason);
-            await SaveParseAccountCacheAsync($"dp_channel:{channel}", success, message, reason);
-            await SaveParseAccountCacheAsync($"{channel}", success, message, reason);
-            await SaveParseAccountCacheAsync($"{accountName}", success, message, reason);
-            if (accountId != 0)
-            {
-                //todo 放着跑两天,要将读取的地方改成读取accountid
-                await SaveParseAccountCacheAsync($"{channel}_{accountId}", success, message, reason);
-            }
+            await SaveParseAccountCacheAsync($"dp_{dp_flag}:all", success, message, reason);
+            await SaveParseAccountCacheAsync($"dp_{dp_flag}:{channel}", success, message, reason);
+            if (accountId == 0 && !string.IsNullOrEmpty(accountName))
+            {
+                await SaveParseAccountCacheAsync($"dp_{dp_flag}:{accountName}", success, message, reason);
+            }
+            if (accountId != 0)
+            {
+                await SaveParseAccountCacheAsync($"dp_{dp_flag}:{channel}_{accountId}", success, message, reason);
+            }
+
+            await SaveParseAccountCacheAsync("all", success, message, reason);
+            await SaveParseAccountCacheAsync($"dp_channel:{channel}", success, message, reason);
+            await SaveParseAccountCacheAsync($"{channel}", success, message, reason);
+            if (accountId == 0 && !string.IsNullOrEmpty(accountName))
+            {
+                await SaveParseAccountCacheAsync($"{accountName}", success, message, reason);
+            }
+            if (accountId != 0)
+            {
+                await SaveParseAccountCacheAsync($"{channel}_{accountId}", success, message, reason);
+            }
         }
 
         private static async Task SaveParseAccountCacheAsync(string accountName, bool success,
@@ -377,24 +382,29 @@ namespace molilian.core
                 _ => success ? "success" : "fail",
             };
 
-            //关于dp的缓存
-            saveParseAccountCache($"dp_{dp_flag}:all", success, message, reason);
-            saveParseAccountCache($"dp_{dp_flag}:{channel}", success, message, reason);
-            saveParseAccountCache($"dp_{dp_flag}:{accountName}", success, message, reason);
-            if (accountId != 0)
-            {
-                saveParseAccountCache($"dp_{dp_flag}:{channel}_{accountId}", success, message, reason);
-            }
-
-            saveParseAccountCache("all", success, message, reason);
-            saveParseAccountCache($"{channel}", success, message, reason);
-            saveParseAccountCache($"{accountName}", success, message, reason);
-            if (accountId != 0)
-            {
-                //todo 放着跑两天,要将读取的地方改成读取accountid
-                saveParseAccountCache($"{channel}_{accountId}", success, message, reason);
-            }
-        }
+            //关于dp的缓存
+            saveParseAccountCache($"dp_{dp_flag}:all", success, message, reason);
+            saveParseAccountCache($"dp_{dp_flag}:{channel}", success, message, reason);
+            if (accountId == 0 && !string.IsNullOrEmpty(accountName))
+            {
+                saveParseAccountCache($"dp_{dp_flag}:{accountName}", success, message, reason);
+            }
+            if (accountId != 0)
+            {
+                saveParseAccountCache($"dp_{dp_flag}:{channel}_{accountId}", success, message, reason);
+            }
+
+            saveParseAccountCache("all", success, message, reason);
+            saveParseAccountCache($"{channel}", success, message, reason);
+            if (accountId == 0 && !string.IsNullOrEmpty(accountName))
+            {
+                saveParseAccountCache($"{accountName}", success, message, reason);
+            }
+            if (accountId != 0)
+            {
+                saveParseAccountCache($"{channel}_{accountId}", success, message, reason);
+            }
+        }
         private static void saveParseAccountCache(string accountName, bool success,
             string message, string reason)
         {

+ 3 - 3
molilian.core/Core/taoke/TaokeOpenCore.cs

@@ -24,7 +24,7 @@ namespace molilian.core
             _config = TkConfigCore.Get();
         }
 
-        public async Task<(APIResult, PromotionQueryDTO)> PromotionQueryByItemIdAsync(string itemid, string oaid = "", string ip = "", string scene = "", bool recommand = true, bool debug = false, int aid = 0)
+        public async Task<(APIResult, PromotionQueryDTO)> PromotionQueryByItemIdAsync(string itemid, string oaid = "", string ip = "", string scene = "", bool recommand = true, bool debug = false, int aid = 0, bool useCouponLinkFirst = true)
         {
             PromotionQueryDTO result = new()
             {
@@ -185,7 +185,7 @@ namespace molilian.core
         }
 
 
-        public async Task<APIResult> PromotionQueryAsync(string img, string oaid = "", string ip = "", string scene = "", bool recommand = true, bool debug = false, int aid = 0)
+        public async Task<APIResult> PromotionQueryAsync(string img, string oaid = "", string ip = "", string scene = "", bool recommand = true, bool debug = false, int aid = 0, bool useCouponLinkFirst = true)
         {
             PromotionQueryDTO result = new()
             {
@@ -329,7 +329,7 @@ namespace molilian.core
                             }
 
                             var aliDelayTask = Task.Delay(1500, cts.Token);
-                            var aliRequestTask = api.picSimilaritemAsync(img, account.open_pid, result);
+                            var aliRequestTask = api.picSimilaritemAsync(img, account.open_pid, result, useCouponLinkFirst);
 
                             var aliCompletedTask = await Task.WhenAny(aliDelayTask, aliRequestTask);
                             if (aliCompletedTask == aliRequestTask)

+ 4 - 10
molilian.core/Plus/Alimama/crawler.cs

@@ -35,11 +35,8 @@ namespace molilian.core
                 int accountId = account.id;
                 string accountName = $"{TkChannelEnum.tb}_{account.id}";
 
-                int total_count = await TkLogCore.GetTotalAsync($":{prefix}total:{accountName}:{log_date:yyyyMMdd}");
-                if (total_count == 0) accountName = account.name;
-
-                total_count = await TkLogCore.GetTotalAsync($":{prefix}total:{accountName}:{log_date:yyyyMMdd}");
-                if (total_count == 0) continue;
+                int total_count = await TkLogCore.GetTotalAsync($":{prefix}total:{accountName}:{log_date:yyyyMMdd}");
+                if (total_count == 0) continue;
 
                 var success_count = await TkLogCore.GetTotalAsync($":{prefix}total:{accountName}:success:{log_date:yyyyMMdd}");
                 var abandon_count = await TkLogCore.GetTotalAsync($":{prefix}total:{accountName}:放弃转链:{log_date:yyyyMMdd}");
@@ -160,11 +157,8 @@ namespace molilian.core
                 int accountId = account.id;
                 string accountName = $"{TkChannelEnum.tb}_{account.id}";
 
-                int total_count = await TkLogCore.GetTotalAsync($":{prefix}total:{accountName}:{log_date:yyyyMMdd}", all_node);
-                if (total_count == 0) accountName = account.name;
-
-                total_count = await TkLogCore.GetTotalAsync($":{prefix}total:{accountName}:{log_date:yyyyMMdd}", all_node);
-                if (total_count == 0) continue;
+                int total_count = await TkLogCore.GetTotalAsync($":{prefix}total:{accountName}:{log_date:yyyyMMdd}", all_node);
+                if (total_count == 0) continue;
 
                 var success_count = await TkLogCore.GetTotalAsync($":{prefix}total:{accountName}:success:{log_date:yyyyMMdd}", all_node);
                 var abandon_count = await TkLogCore.GetTotalAsync($":{prefix}total:{accountName}:放弃转链:{log_date:yyyyMMdd}", all_node);

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

@@ -237,7 +237,7 @@ namespace molilian.core
             if (result.success && "brwsimilar".Equals(request.RiskStrategy))
             {
                 // 需要搜同款才进入这个逻辑
-                result.PromotionImg = await InternalCallPromotionQuery(result.pic, request.Oaid, request.Ip);
+                result.PromotionImg = await InternalCallPromotionQuery(result.pic, request.Oaid, request.Ip, _account.useCouponLinkFirst);
                 //	"pic": "https://img.alicdn.com/i4/6000000004750/O1CN01w4wgqa1kxYS1BadZp_!!6000000004750-0-sm.jpg",
                 //result.pic
                 //result.PromotionImg[*].pic
@@ -264,7 +264,7 @@ namespace molilian.core
             return result;
         }
 
-        private async Task<List<PromotionQueryItemDTO>> InternalCallPromotionQuery(string pic, string oaid, string ip)
+        private async Task<List<PromotionQueryItemDTO>> InternalCallPromotionQuery(string pic, string oaid, string ip, bool useCouponLinkFirst)
         {
             if (string.IsNullOrWhiteSpace(pic))
             {
@@ -310,7 +310,8 @@ namespace molilian.core
                 url = targetPic,
                 oaid,
                 ip,
-                recommand = false
+                recommand = false,
+                useCouponLinkFirst
             };
 
             string post = postData.Convert2Json();

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä