Преглед на файлове

收入列表相关bug和业务调整;更改每日api调用次数统计的实现方法;

dodo hold преди 2 години
родител
ревизия
50f52452ca

+ 15 - 12
molilian.api/Controllers/admin/TaobaoController.cs

@@ -157,6 +157,7 @@ namespace molilian.api.Controllers
 
             var report_date = form.PathReadArray<string>("query_date[]");
             string dailys_accountName = "all";
+            int dailys_accountId = 0;
 
             string filter = string.Empty;
             DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
@@ -184,9 +185,9 @@ namespace molilian.api.Controllers
 
             var result = new DBContext.Table("v_tk_report_dailys")
                 .LeftJoin("daily_logs",
-                "B.log_date = A.report_date AND B.accountName=@dailys_accountName",
+                "B.log_date = A.report_date AND B.accountId=@dailys_accountId",
                 "total_count, B.abandon_count, B.success_count, B.abandon_percentage, B.success_percentage")
-                .Where(filter, new { dailys_accountName, stime, etime })
+                .Where(filter, new { dailys_accountId, dailys_accountName, stime, etime })
                 .Page(size, page)
                 .Order(orderBy)
                 .PageList<TkReportDTO>(getTotal);
@@ -219,12 +220,12 @@ namespace molilian.api.Controllers
             string order = form.Read<string>("order");
 
             var report_date = form.PathReadArray<string>("query_date[]");
-            var accountName = form.Read("accountName", string.Empty);
+            int accountId = form.Read("accountId", 0);
 
             string filter = string.Empty;
-            if (!string.IsNullOrEmpty(accountName))
+            if (accountId != 0)
             {
-                filter += $" AND A.accountName=@accountName";
+                filter += $" AND A.accountId=@accountId";
             }
 
             DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
@@ -252,9 +253,9 @@ namespace molilian.api.Controllers
 
             var result = new DBContext.Table("tk_report")
                 .LeftJoin("daily_logs",
-                "B.log_date = A.report_date AND B.accountName=A.accountName",
+                "B.log_date = A.report_date AND B.accountId=A.accountId",
                 "total_count, B.abandon_count, B.success_count, B.abandon_percentage, B.success_percentage")
-                .Where(filter, new { accountName, stime, etime })
+                .Where(filter, new { accountId, stime, etime })
                 .Page(size, page)
                 .Order(orderBy)
                 .PageList<TkReportDTO>(getTotal);
@@ -263,6 +264,8 @@ namespace molilian.api.Controllers
 
             foreach (var item in result.List)
             {
+                //var tk = TkPoolCore.GetOne(item.accountId);
+                //if (tk != null) item.accountName = tk.company;
 
                 if (item.total_count > 0) continue;
                 item.total_count = RedisHelper.Get<int>($":total:{item.accountName}:{item.report_date:yyyyMMdd}");
@@ -294,14 +297,14 @@ namespace molilian.api.Controllers
             string order = form.Read<string>("order");
 
             var report_date = form.PathReadArray<string>("query_date[]");
-            var accountName = form.Read("accountName", string.Empty);
+            int accountId = form.Read("accountId", 0);
 
             string filter = string.Empty;
-
-            if (!string.IsNullOrEmpty(accountName))
+            if (accountId != 0)
             {
-                filter += $" AND accountName=@accountName";
+                filter += $" AND accountId=@accountId";
             }
+
             DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
             if (report_date.Count == 2)
             {
@@ -328,7 +331,7 @@ namespace molilian.api.Controllers
 
             using var conn = DBContext.GetOpenConnection();
             var result = new DBContext.Table(conn, "tk_report_hourtrend")
-                .Where(filter, new { accountName, stime, etime })
+                .Where(filter, new { accountId, stime, etime })
                 .Page(size, page)
                 .Order(orderBy)
                 .PageList<TkReportDTO>(getTotal);

+ 7 - 0
molilian.api/Controllers/admin/TaobaoOrderController.cs

@@ -27,6 +27,7 @@ namespace molilian.api.Controllers
             string order = form.Read<string>("order");
             string name = form.Read<string>("keyword");
             int tkStatus = form.Read("tkStatus", 0);
+            int maxTotal = form.Read("maxTotal", 0);
 
             var time = form.PathReadArray<string>("query_date[]");
 
@@ -76,6 +77,12 @@ namespace molilian.api.Controllers
             //        item.accountName = "-";
             //    }
             //}
+
+            if (maxTotal != 0 && result.Count > maxTotal)
+            {
+                result.Count = maxTotal;
+                result.PageCount = maxTotal / size;
+            }
             return new APIResult(new { data = result });
         }
 

+ 1 - 0
molilian.api/Controllers/public/TkController.cs

@@ -156,6 +156,7 @@ namespace molilian.api.Controllers
                     });
                 }
 
+                result.accountId = account.id;
                 account_name = account.name;
                 alimama = new AlimamaPlus(account);
 

Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
molilian.api/Properties/PublishProfiles/https___ccr.ccs.tencentyun.com_shaobin.pubxml.user


+ 1 - 0
molilian.core/Core/ApiAccountCore.cs

@@ -35,6 +35,7 @@ namespace molilian.core
             return list.Where(e => e.api_key == api_key).FirstOrDefault();
         }
 
+
         public static IEnumerable<ApiAccountDTO> List(bool force = false)
         {
             if (!force && _cached != null) return _cached;

+ 6 - 0
molilian.core/Core/taoke/OrderTrackingCore.cs

@@ -28,6 +28,12 @@ namespace molilian.core
 
             cacheKey = $":cache:order_summary:{item.accountName}:{item.itemName}";
             RedisHelper.Set(cacheKey, item, ttl);
+
+            //cacheKey = $":cache:order_summary:{item.accountId}:{item.itemId}";
+            //RedisHelper.Set(cacheKey, item, ttl);
+
+            //cacheKey = $":cache:order_summary:{item.accountId}:{item.itemName}";
+            //RedisHelper.Set(cacheKey, item, ttl);
         }
         public static TkDataDTO GetLinkSummary(string accountName, string name)
         {

+ 10 - 175
molilian.core/Core/taoke/TkLogCore.cs

@@ -40,6 +40,7 @@ namespace molilian.core
                     if (data == null) break;
                     data.id = new DBContext.Table(connection, "tk_logs")
                         .Add("channel", (int)data.channel)
+                        .Add("accountId", data.accountId)
                         .Add("accountName", data.accountName)
                         .Add("rawContent", data.rawContent)
                         .Add("rawContent2", data.rawContent2)
@@ -70,6 +71,7 @@ namespace molilian.core
                     if (data == null) break;
                     new DBContext.Table(connection, "tk_logs")
                        .Add("channel", (int)data.channel)
+                       .Add("accountId", data.accountId)
                        .Add("accountName", data.accountName)
                        .Add("rawContent", data.rawContent)
                        .Add("rawContent2", data.rawContent2)
@@ -92,6 +94,7 @@ namespace molilian.core
 
                     data.id = new DBContext.Table(connection, "tk_parse_logs")
                         .Add("channel", (int)data.channel)
+                        .Add("accountId", data.accountId)
                         .Add("accountName", data.accountName)
                         .Add("rawContent", data.rawContent)
                         .Add("success", data.success)
@@ -121,6 +124,7 @@ namespace molilian.core
                     if (data == null) break;
                     new DBContext.Table(connection, "tk_parse_logs")
                         .Add("channel", (int)data.channel)
+                        .Add("accountId", data.accountId)
                         .Add("accountName", data.accountName)
                         .Add("rawContent", data.rawContent)
                         .Add("success", data.success)
@@ -147,6 +151,7 @@ namespace molilian.core
                     if (data == null) break;
                     new DBContext.Table(connection, "tk_parse_logs")
                         .Add("channel", (int)data.channel)
+                        .Add("accountId", data.accountId)
                         .Add("accountName", data.accountName)
                         .Add("rawContent", data.rawContent)
                         .Add("success", data.success)
@@ -217,6 +222,7 @@ namespace molilian.core
                 var ts = DateTime.Now - response.create_time;
                 response.elapsedTime = (int)ts.TotalMilliseconds;
                 RedisHelper.RPush(queue_jd_key, response);
+                saveCache(response.channel.ToString(), response.accountId.ToString(), response.success, response.message, response.reason);
                 saveCache(response.channel.ToString(), response.accountName, response.success, response.message, response.reason);
             }
             catch (Exception ex) { }
@@ -229,6 +235,7 @@ namespace molilian.core
                 var ts = DateTime.Now - response.create_time;
                 response.elapsedTime = (int)ts.TotalMilliseconds;
                 RedisHelper.RPush(queue_tb_key, response);
+                saveCache(response.channel.ToString(), response.accountId.ToString(), response.success, response.message, response.reason);
                 saveCache(response.channel.ToString(), response.accountName, response.success, response.message, response.reason);
 
                 if (!response.success && "nologin".Equals(response.message))
@@ -271,6 +278,7 @@ namespace molilian.core
                 var ts = DateTime.Now - response.create_time;
                 response.elapsedTime = (int)ts.TotalMilliseconds;
                 RedisHelper.RPush(queue_parse_tb_key, response);
+                saveCache(response.channel.ToString(), response.accountId.ToString(), response.success, response.message, response.reason);
                 saveCache(response.channel.ToString(), response.accountName, response.success, response.message, response.reason);
                 if (!string.IsNullOrEmpty(response.itemId)) TkOrderTrackingCore.SaveLinkSummary(response);
 
@@ -307,6 +315,7 @@ namespace molilian.core
                 var ts = DateTime.Now - response.create_time;
                 response.elapsedTime = (int)ts.TotalMilliseconds;
                 RedisHelper.RPush(queue_parse_jd_key, response);
+                saveCache(response.channel.ToString(), response.accountId.ToString(), response.success, response.message, response.reason);
                 saveCache(response.channel.ToString(), response.accountName, response.success, response.message, response.reason);
 
             }
@@ -319,6 +328,7 @@ namespace molilian.core
                 var ts = DateTime.Now - response.create_time;
                 response.elapsedTime = (int)ts.TotalMilliseconds;
                 RedisHelper.RPush(queue_parse_dy_key, response);
+                saveCache(response.channel.ToString(), response.accountId.ToString(), response.success, response.message, response.reason);
                 saveCache(response.channel.ToString(), response.accountName, response.success, response.message, response.reason);
 
             }
@@ -336,181 +346,6 @@ namespace molilian.core
             catch (Exception ex) { }
         }
 
-
-        public static async Task Log2(JdDataDTO response)
-        {
-            await Task.Run(() =>
-            {
-                try
-                {
-                    new DBContext.Table("tk_logs")
-                    .Add("channel", (int)response.channel)
-                    .Add("accountName", response.accountName)
-                    .Add("rawContent", response.rawContent)
-                    .Add("rawContent2", response.rawContent2)
-                    .Add("ip", response.ip)
-                    .Add("oaid", response.oaid)
-                    .Add("success", response.success)
-                    .Add("message", response.message)
-                    .Add("reason", response.reason)
-                    .Add("shortLinkurl", response.shortLinkurl)
-                    .Add("deeplink_url", response.deeplink_url)
-                    .Add("ip", response.ip)
-                    .Add("oaid", response.oaid)
-                    .Add("create_time", response.create_time)
-                    .Add("elapsedTime", response.elapsedTime)
-                    .Create();
-
-                }
-                catch (Exception ex)
-                {
-                    new LoggerLibrary("database_error")
-                    .Info(response.rawContent, response.rawContent2)
-                    .Info(response.Convert2Json())
-                    .Info(ex.Message, ex.StackTrace)
-                    .Save();
-                }
-            });
-        }
-
-        public static async Task Log2(TkDataDTO response, AlimamaPlus? alimamaPlus = null)
-        {
-            await Task.Run(() =>
-            {
-                try
-                {
-                    new DBContext.Table("tk_logs")
-                    .Add("channel", (int)response.channel)
-                    .Add("accountName", response.accountName)
-                    .Add("rawContent", response.rawContent)
-                    .Add("rawContent2", response.rawContent2)
-                    .Add("success", response.success)
-                    .Add("message", response.message)
-                    .Add("reason", response.reason)
-                    .Add("content", response.content)
-                    .Add("couponAmount", response.couponAmount)
-                    .Add("taoToken", response.taoToken)
-                    .Add("shortLinkurl", response.shortLinkurl)
-                    .Add("deeplink_url", response.deeplink_url)
-                    .Add("num_iid", response.num_iid)
-                    .Add("elapsedTime", response.elapsedTime)
-                    .Add("ip", response.ip)
-                    .Add("oaid", response.oaid)
-                    .Add("create_time", response.create_time)
-                    .Create();
-
-                    if (!response.success && "nologin".Equals(response.message))
-                    {
-                        switch (response.channel)
-                        {
-                            case TkChannelEnum.tb:
-                                if (alimamaPlus != null)
-                                {
-                                    (bool success, string message) = alimamaPlus.RenewCookie();
-                                    if (success) return;
-                                }
-                                TkPoolCore.Disabled(response.accountName, $"{response.rawContent}\n{response.rawContent2}");
-                                break;
-                                //case TkChannelEnum.jdUnion:
-                                //    VeapiPoolCore.Disabled(response.accountName);
-                                //    break;
-                        }
-                    }
-                }
-                catch (Exception ex)
-                {
-                    new LoggerLibrary("database_error")
-                    .Info(response.rawContent, response.rawContent2)
-                    .Info(response.Convert2Json())
-                    .Info(ex.Message, ex.StackTrace)
-                    .Save();
-                }
-            });
-        }
-
-
-        public static async Task ParseLog2(TkDataDTO response, AlimamaPlus? alimamaPlus = null)
-        {
-            await Task.Run(() =>
-            {
-                try
-                {
-                    new DBContext.Table("tk_parse_logs")
-                    .Add("channel", (int)response.channel)
-                    .Add("accountName", response.accountName)
-                    .Add("rawContent", response.rawContent)
-                    .Add("success", response.success)
-                    .Add("message", response.message)
-                    .Add("reason", response.reason)
-                    .Add("content", response.content)
-                    .Add("couponAmount", response.couponAmount)
-                    .Add("taoToken", response.taoToken)
-                    .Add("shortLinkurl", response.shortLinkurl)
-                    .Add("deeplink_url", response.deeplink_url)
-                    .Add("num_iid", response.num_iid)
-                    .Add("elapsedTime", response.elapsedTime)
-                    .Add("ip", response.ip)
-                    .Add("oaid", response.oaid)
-                    .Add("create_time", response.create_time)
-                    .Create();
-
-                    if (!response.success && "nologin".Equals(response.message))
-                    {
-                        switch (response.channel)
-                        {
-                            case TkChannelEnum.tb:
-                                if (alimamaPlus != null)
-                                {
-                                    (bool success, string message) = alimamaPlus.RenewCookie();
-                                    if (success) return;
-                                }
-                                TkPoolCore.Disabled(response.accountName, $"{response.rawContent}");
-                                break;
-                        }
-                    }
-                }
-                catch (Exception ex)
-                {
-                    new LoggerLibrary("unionParse", "database_error")
-                    .Info(response.rawContent)
-                    .Info(response.Convert2Json())
-                    .Info(ex.Message, ex.StackTrace)
-                    .Save();
-                }
-            });
-        }
-        public static async Task ParseLog2(JdDataDTO response)
-        {
-            await Task.Run(() =>
-            {
-                try
-                {
-                    new DBContext.Table("tk_parse_logs")
-                    .Add("channel", (int)response.channel)
-                    .Add("accountName", response.accountName)
-                    .Add("rawContent", response.rawContent)
-                    .Add("success", response.success)
-                    .Add("message", response.message)
-                    .Add("reason", response.reason)
-                    .Add("content", response.content)
-                    .Add("shortLinkurl", response.shortLinkurl)
-                    .Add("deeplink_url", response.deeplink_url)
-                    .Add("elapsedTime", response.elapsedTime)
-                    .Add("ip", response.ip)
-                    .Add("oaid", response.oaid)
-                    .Add("create_time", response.create_time)
-                    .Create();
-                }
-                catch (Exception ex)
-                {
-                    new LoggerLibrary("unionParse", "database_error")
-                    .Info(response.rawContent)
-                    .Info(response.Convert2Json())
-                    .Info(ex.Message, ex.StackTrace)
-                    .Save();
-                }
-            });
-        }
         private static void saveCache(string channel, string accountName, bool success, string message, string reason)
         {
             saveAccountCache("all", success, message, reason);

+ 6 - 0
molilian.core/Core/taoke/TkPoolCore.cs

@@ -31,6 +31,12 @@ namespace molilian.core
             if (!list.Any()) return null;
             return list.Where(IsNotExceedDailyIncomeLimit).OrderBy(l => Guid.NewGuid()).FirstOrDefault();
         }
+        public static TkPoolDTO? GetOne(int id)
+        {
+            var list = List();
+            if (!list.Any()) return null;
+            return list.Where(e => e.id == id).FirstOrDefault();
+        }
 
         internal static void SaveIncomeAmt(string accountName, decimal income_amt)
         {

+ 1 - 0
molilian.core/Core/taoke/UnionParseCore.cs

@@ -168,6 +168,7 @@ namespace molilian.core
                         result.deeplink_url,
                     });
                 }
+                result.accountId = account.id;
                 result.accountName = account.name;
                 alimama = new AlimamaPlus(account);
                 result = await alimama.UnionParse2Async(content, result);

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

@@ -9,6 +9,7 @@ namespace molilian.core
         public TkChannelEnum channel { get; set; }
         public LinkTypeEnum link_type { get; set; }
         public ChannelTypeEnum channel_type { get; set; } = ChannelTypeEnum.none;
+        public int accountId { get; set; } = 0;
         public string accountName { get; set; } = string.Empty;
         public bool success { get; set; } = true;
         public string message { get; set; } = string.Empty;

+ 16 - 1
molilian.core/DTO/alimama/TkReportDTO.cs

@@ -10,7 +10,7 @@
         /// </summary>
         public int Id { get; set; } = 0;
 
-
+        public int accountId { get; set; } = 0;
         public string accountName { get; set; } = string.Empty;
         public DateTime report_date { get; set; }
         public DateTime create_time { get; set; }
@@ -100,6 +100,21 @@
         public decimal sett_tk_disp_tfee_56 { get; set; } = 0;
 
 
+        /// <summary>
+        /// 所属订单结算金额
+        /// </summary>
+        public decimal order_ord_amt { get; set; } = 0;
+        /// <summary>
+        /// 所属订单结算收入
+        /// </summary>
+        public decimal order_ord_tfee { get; set; } = 0;
+        public decimal order_ord_amt_12 { get; set; } = 0;
+        public decimal order_ord_tfee_12 { get; set; } = 0;
+        public decimal order_ord_amt_13 { get; set; } = 0;
+        public decimal order_ord_tfee_13 { get; set; } = 0;
+        public decimal order_ord_amt_14 { get; set; } = 0;
+        public decimal order_ord_tfee_14 { get; set; } = 0;
+
         public int total_count { get; set; } = 0;
         public int abandon_count { get; set; } = 0;
         public int success_count { get; set; } = 0;

+ 1 - 0
molilian.core/DTO/dy/DyDataDTO.cs

@@ -6,6 +6,7 @@
         public LinkTypeEnum link_type { get; set; }
         public ChannelTypeEnum channel_type { get; set; } = ChannelTypeEnum.none;
         public string title { get; set; } = string.Empty;
+        public int accountId { get; set; } = 0;
         public string accountName { get; set; } = string.Empty;
         public bool success { get; set; } = true;
         public string message { get; set; } = string.Empty;

+ 1 - 0
molilian.core/DTO/jd/JdDataDTO.cs

@@ -5,6 +5,7 @@
         public TkChannelEnum channel { get; set; }
         public LinkTypeEnum link_type { get; set; }
         public ChannelTypeEnum channel_type { get; set; } = ChannelTypeEnum.none;
+        public int accountId { get; set; } = 0;
         public string accountName { get; set; } = string.Empty;
         public bool success { get; set; } = true;
         public string message { get; set; } = string.Empty;

+ 116 - 17
molilian.core/Plus/Alimama/crawler.cs

@@ -31,10 +31,105 @@ namespace molilian.core
         /// <param name="intervalDay"></param>
         public static void DailyLogs(int intervalDay)
         {
+
+            DateTime log_date = DateTime.Now.AddDays(-intervalDay).Date;
+
+            var accounts = TkPoolCore.List();
+
+            foreach (var account in accounts)
+            {
+                int accountId = account.id;
+                string accountName = $"{account.id}";
+
+                int total_count = RedisHelper.Get<int>($":total:{accountName}:{log_date:yyyyMMdd}");
+                if (total_count == 0) accountName = account.name;
+
+                total_count = RedisHelper.Get<int>($":total:{accountName}:{log_date:yyyyMMdd}");
+                if (total_count == 0) continue;
+
+                var success_count = RedisHelper.Get<int>($":total:{accountName}:success:{log_date:yyyyMMdd}");
+                var abandon_count = RedisHelper.Get<int>($":total:{accountName}:放弃转链:{log_date:yyyyMMdd}");
+                string success_percentage = string.Empty;
+                string abandon_percentage = string.Empty;
+
+                if (total_count > 0)
+                { 
+                    success_percentage = $"{success_count / (double)total_count * 100:f2}%";
+                    abandon_percentage = $"{abandon_count / (double)total_count * 100:f2}%";
+                }
+
+                var exist = new DBContext.Table("daily_logs")
+                     .Fields("id,log_date")
+                     .Get<dynamic>("log_date=@log_date AND accountId=@accountId", new { log_date, accountId });
+
+                var createArgs = new DBContext.Table("daily_logs")
+
+                    .Add("total_count", total_count)
+                    .Add("abandon_count", abandon_count)
+                    .Add("abandon_percentage", abandon_percentage)
+                    .Add("success_count", success_count)
+                    .Add("success_percentage", success_percentage)
+                    .Add("last_time", DateTime.Now);
+
+                if (exist == null)
+                {
+                    createArgs.Add("channel", 0)
+                        .Add("accountId", accountId)
+                        .Add("accountName", account.company)
+                        .Add("log_date", log_date)
+                        .Add("create_time", DateTime.Now)
+                        .Create();
+                }
+                else
+                {
+                    createArgs.Where("id=@id", new { exist.id }).Update();
+                }
+            }
+
+
+            int all_total_count = RedisHelper.Get<int>($":total:all:{log_date:yyyyMMdd}");
+            var all_success_count = RedisHelper.Get<int>($":total:all:success:{log_date:yyyyMMdd}");
+            var all_abandon_count = RedisHelper.Get<int>($":total:all:放弃转链:{log_date:yyyyMMdd}");
+
+            string all_success_percentage = string.Empty;
+            string all_abandon_percentage = string.Empty;
+            if (all_total_count > 0)
+            {
+                all_success_percentage = $"{all_success_count / (double)all_total_count * 100:f2}%";
+                all_abandon_percentage = $"{all_abandon_count / (double)all_total_count * 100:f2}%";
+            }
+
+            var exist2 = new DBContext.Table("daily_logs")
+                 .Fields("id,log_date")
+                 .Get<dynamic>("log_date=@log_date AND accountId=@accountId", new { log_date, accountId=0 });
+
+            var createArgs2 = new DBContext.Table("daily_logs")
+                .Add("total_count", all_total_count)
+                .Add("abandon_count", all_abandon_count)
+                .Add("abandon_percentage", all_abandon_percentage)
+                .Add("success_count", all_success_count)
+                .Add("success_percentage", all_success_percentage)
+                .Add("last_time", DateTime.Now);
+
+            if (exist2 == null)
+            {
+                createArgs2.Add("channel", 0)
+                    .Add("accountId", 0)
+                    .Add("accountName", "all")
+                    .Add("log_date", log_date)
+                    .Add("create_time", DateTime.Now)
+                    .Create();
+            }
+            else
+            {
+                createArgs2.Where("id=@id", new { exist2.id }).Update();
+            }
+
+
             string sql = @$"
-INSERT INTO daily_logs (channel, accountName, log_date, total_count, abandon_count, abandon_percentage, success_count, success_percentage, create_time, last_time)
+INSERT INTO daily_logs (channel, accountId, accountName, log_date, total_count, abandon_count, abandon_percentage, success_count, success_percentage, create_time, last_time)
 SELECT
-    0 AS channel, 'all' AS accountName,
+    0 AS channel, 0 AS accountId, 'all' AS accountName,
     DATE_SUB(CURDATE(), INTERVAL {intervalDay} DAY) AS log_date,
     COUNT(*) AS total_count,
     COALESCE(SUM(CASE WHEN message = '放弃转链' THEN 1 ELSE 0 END), 0) AS abandon_count,
@@ -56,9 +151,9 @@ ON DUPLICATE KEY UPDATE
 ";
 
             string sql2 = @$"
-INSERT INTO daily_logs (channel, accountName, log_date, total_count, abandon_count, abandon_percentage, success_count, success_percentage, create_time, last_time)
+INSERT INTO daily_logs (channel, accountId, accountName, log_date, total_count, abandon_count, abandon_percentage, success_count, success_percentage, create_time, last_time)
 SELECT
-    channel, accountName, DATE_SUB(CURDATE(), INTERVAL {intervalDay} DAY) AS log_date,
+    channel, accountId, accountName, DATE_SUB(CURDATE(), INTERVAL {intervalDay} DAY) AS log_date,
     COUNT(*) AS total_count,
     COALESCE(SUM(CASE WHEN message = '放弃转链' THEN 1 ELSE 0 END), 0) AS abandon_count,
     COALESCE(CONCAT(ROUND((SUM(CASE WHEN message = '放弃转链' THEN 1 ELSE 0 END) / COUNT(*)) * 100, 2), '%'), 0) AS abandon_percentage,
@@ -68,7 +163,7 @@ SELECT
     NOW() AS last_time
 FROM tk_logs
 WHERE DATE(create_time) = DATE_SUB(CURDATE(), INTERVAL {intervalDay} DAY)
-GROUP BY channel, accountName
+GROUP BY channel, accountId, accountName
 ON DUPLICATE KEY UPDATE
     log_date = VALUES(log_date),
     total_count = VALUES(total_count),
@@ -79,8 +174,8 @@ ON DUPLICATE KEY UPDATE
     last_time = NOW();
 ";
 
-            DBContext.Execute(sql, new { });
-            DBContext.Execute(sql2, new { });
+            //DBContext.Execute(sql, new { });
+            //DBContext.Execute(sql2, new { });
         }
 
 
@@ -149,6 +244,7 @@ ON DUPLICATE KEY UPDATE
                 DateTime report_date = date.Date;
                 if (report_date == DateTime.Now.Date)
                 {
+                    TkPoolCore.SaveIncomeAmt(_accountId.ToString(), result.eff_tk_disp_tfee);
                     TkPoolCore.SaveIncomeAmt(_accountName, result.eff_tk_disp_tfee);
                     EachSaveReportOverview(report_date.AddHours(DateTime.Now.Hour), "tk_report_hourtrend", result);
                     EachSaveReportOverview(report_date, "tk_report", result);
@@ -160,8 +256,8 @@ ON DUPLICATE KEY UPDATE
         {
             var exist = new DBContext.Table(tableName)
                  .Fields("id,report_date")
-                 .Get<dynamic>("report_date=@report_date AND accountName=@accountName",
-                                 new { report_date, accountName = _accountName });
+                 .Get<dynamic>("report_date=@report_date AND accountId=@accountId",
+                                 new { report_date, accountId = _accountId });
 
             var createArgs = new DBContext.Table(tableName)
                 .Add("uclk_uv_56", data.uclk_uv_56)
@@ -183,7 +279,8 @@ ON DUPLICATE KEY UPDATE
 
             if (exist == null)
             {
-                createArgs.Add("accountName", _accountName)
+                createArgs.Add("accountId", _accountId)
+                    .Add("accountName", _company)
                     .Add("report_date", report_date)
                     .Add("create_time", DateTime.Now)
                     .Add("last_time", DateTime.Now)
@@ -241,14 +338,15 @@ ON DUPLICATE KEY UPDATE
 
                 var exist = new DBContext.Table("tk_report")
                      .Fields("id,report_date")
-                     .Get<dynamic>("report_date=@report_date AND accountName=@accountName",
-                                     new { report_date, accountName = _accountName });
+                     .Get<dynamic>("report_date=@report_date AND accountId=@accountId",
+                                     new { report_date, accountId = _accountId });
                 var createArgs = new DBContext.Table("tk_report")
                     .Add("fix_uclk_pv_56", result.fix_uclk_pv_56);
 
                 if (exist == null)
                 {
-                    createArgs.Add("accountName", _accountName)
+                    createArgs.Add("accountId", _accountId)
+                        .Add("accountName", _company)
                         .Add("report_date", report_date)
                         .Add("create_time", DateTime.Now)
                         .Add("last_time", DateTime.Now)
@@ -317,8 +415,8 @@ ON DUPLICATE KEY UPDATE
 
             var exist = new DBContext.Table(tableName)
                  .Fields("id,report_date")
-                 .Get<dynamic>("report_date=@report_date AND accountName=@accountName",
-                                 new { report_date, accountName = _accountName });
+                 .Get<dynamic>("report_date=@report_date AND accountId=@accountId",
+                                 new { report_date, accountId = _accountId });
             if (exist == null)
             {
                 new DBContext.Table(tableName)
@@ -336,7 +434,8 @@ ON DUPLICATE KEY UPDATE
                     .Loader<int>("sett_ord_num_56", 0)
                     .Loader<decimal>("sett_ord_amt_56", 0)
                     .Loader<decimal>("sett_tk_disp_tfee_56", 0)
-                    .Add("accountName", _accountName)
+                    .Add("accountId", _accountId)
+                    .Add("accountName", _company)
                     .Add("report_date", report_date)
                     .Add("create_time", DateTime.Now)
                     .Add("last_time", DateTime.Now)
@@ -430,7 +529,7 @@ ON DUPLICATE KEY UPDATE
                         .Loader<int>("status", 0, "ali_status")
                         .Loader<string>("warningText", string.Empty)
 
-                        .Add("accountName", _accountName)
+                        .Add("accountName", _company)
                         .Add("status", true)
                         .Add("create_time", DateTime.Now)
                         .Add("last_time", DateTime.Now)

+ 79 - 5
molilian.core/Plus/Alimama/orders.cs

@@ -27,7 +27,7 @@ namespace molilian.core
             //}
 
             //当日往前查询
-            (int total, _) = GetTkOrders(startTime, endTime, DateTime.MinValue, false, sleep);
+            (int total, _, _) = GetTkOrders(startTime, endTime, DateTime.MinValue, false, sleep);
             return total;
 
         }
@@ -55,16 +55,89 @@ namespace molilian.core
             }
 
             //当日往前查询
-            (int total, DateTime max_modifiedTime) = GetTkOrders(startTime, endTime, last_modifiedTime, true, sleep);
+            (int total, DateTime max_modifiedTime, List<DateTime> orderTimes) = GetTkOrders(startTime, endTime, last_modifiedTime, true, sleep);
             if (max_modifiedTime != DateTime.MinValue)
             {
                 RedisHelper.Set(cacheKey, max_modifiedTime);
             }
+
+            //todo 根据orderTimes、settlementTimes 更新被影响的相关行
+            /*		
+		
+UPDATE tk_report tr
+JOIN (
+    SELECT
+        accountId,
+        DATE(tkPaidTime) AS date,
+        SUM(alipayTotalPrice) AS order_ord_amt,
+        SUM(pubShareFeeForCommission) AS order_ord_tfee
+    FROM tk_order_details
+    WHERE  tkStatus=3
+    GROUP BY DATE(tkPaidTime), accountId
+) AS sub
+ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+SET tr.order_ord_amt = sub.order_ord_amt,
+    tr.order_ord_tfee = sub.order_ord_tfee;
+             */
+            string sql = @"
+UPDATE tk_report tr
+JOIN (
+    SELECT
+        accountId, DATE(tkPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, SUM(pubShareFeeForCommission) AS order_ord_tfee
+    FROM tk_order_details
+    WHERE DATE(tkPaidTime) IN @orderTimes AND tkStatus=3
+    GROUP BY DATE(tkPaidTime), accountId
+) AS sub
+ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+SET tr.order_ord_amt = sub.order_ord_amt, tr.order_ord_tfee = sub.order_ord_tfee;";
+            DBContext.Execute(sql, new { orderTimes });
+
+            sql = @"
+UPDATE tk_report tr
+JOIN (
+    SELECT
+        accountId, DATE(tkPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
+    FROM tk_order_details
+    WHERE DATE(tkPaidTime) IN @orderTimes AND tkStatus=12
+    GROUP BY DATE(tkPaidTime), accountId
+) AS sub
+ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+SET tr.order_ord_amt_12 = sub.order_ord_amt, tr.order_ord_tfee_12 = sub.order_ord_tfee;";
+            DBContext.Execute(sql, new { orderTimes });
+
+            sql = @"
+UPDATE tk_report tr
+JOIN (
+    SELECT
+        accountId, DATE(tkPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
+    FROM tk_order_details
+    WHERE DATE(tkPaidTime) IN @orderTimes AND tkStatus=13
+    GROUP BY DATE(tkPaidTime), accountId
+) AS sub
+ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+SET tr.order_ord_amt_13 = sub.order_ord_amt, tr.order_ord_tfee_13 = sub.order_ord_tfee;";
+            DBContext.Execute(sql, new { orderTimes });
+
+            sql = @"
+UPDATE tk_report tr
+JOIN (
+    SELECT
+        accountId, DATE(tkPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
+    FROM tk_order_details
+    WHERE DATE(tkPaidTime) IN @orderTimes AND tkStatus=14
+    GROUP BY DATE(tkPaidTime), accountId
+) AS sub
+ON tr.accountId = sub.accountId AND tr.report_date = sub.date
+SET tr.order_ord_amt_14 = sub.order_ord_amt, tr.order_ord_tfee_14 = sub.order_ord_tfee;";
+            DBContext.Execute(sql, new { orderTimes });
+
             return total;
         }
 
-        public (int, DateTime) GetTkOrders(DateTime startTime, DateTime endTime, DateTime last_modifiedTime, bool desc = true, int sleep = 100)
+        public (int, DateTime, List<DateTime>) GetTkOrders(DateTime startTime, DateTime endTime, DateTime last_modifiedTime, bool desc = true, int sleep = 100)
         {
+            List<DateTime> orderTimes = [];
+
             // 确保 startTime 小于 endTime
             if (startTime > endTime)
             {
@@ -137,11 +210,12 @@ namespace molilian.core
 
                         if (last_modifiedTime != DateTime.MinValue && last_modifiedTime >= item.modifiedTime)
                         {
-                            return (total, max_modifiedTime);
+                            return (total, max_modifiedTime, orderTimes);
                         }
                         //进行订单和转链匹配
                         //string mktItemLink = $"https:{item.mktItemLink}";
                         //item.itemId = GetRawItemId(mktItemLink);
+                        if (item.tkStatus == 3 && item.tkPaidTime != DateTime.MinValue) orderTimes.Add(item.tkPaidTime.Date);
                         int? id = conn.Replace(item);
                         if (id != null)
                         {
@@ -165,7 +239,7 @@ namespace molilian.core
 
                 if (sleep > 0) Thread.Sleep(sleep);
             }
-            return (total, max_modifiedTime);
+            return (total, max_modifiedTime, orderTimes);
         }
 
 

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

@@ -58,7 +58,6 @@ namespace molilian.core
             {
                 result.channel = TkChannelEnum.tb;
                 result.channel_type = ChannelTypeEnum.tb;
-                result.accountName = _accountName;
                 result.link_type = LinkTypeEnum.unknown;
                 result.success = false;
                 result.message = "其他推广链接";
@@ -66,7 +65,6 @@ namespace molilian.core
                 result.content = content;
                 result.deeplink_url = GetDeeplink(null);
                 result.itemName = GetTitle(content);
-                result.accountName = string.Empty;
             }
             else
             {
@@ -86,7 +84,6 @@ namespace molilian.core
             {
                 result.channel = TkChannelEnum.tb;
                 result.channel_type = ChannelTypeEnum.tb;
-                result.accountName = _accountName;
                 result.link_type = LinkTypeEnum.unknown;
                 result.success = false;
                 result.message = "其他推广链接";
@@ -154,6 +151,10 @@ namespace molilian.core
 
         public static string GetTitle(string content)
         {
+            if (string.IsNullOrEmpty(content)) return string.Empty;
+            string url = GetLink(content);
+            content = content.Replace(url, string.Empty);
+
             content = content.Replace("点击链接直接打开 或者 淘宝搜索直接打开", string.Empty).Trim();
             string[] words = Regex.Split(content, @"\s+");
             string word = words[^1];

+ 31 - 3
molilian.core/Plus/Alimama/parse_2.cs

@@ -294,6 +294,7 @@ namespace molilian.core
                 if (!response.Successed)
                 {
                     result.channel = TkChannelEnum.tb;
+                    result.accountId = _accountId;
                     result.accountName = _accountName;
                     result.link_type = LinkTypeEnum.unknown;
                     result.success = false;
@@ -395,6 +396,7 @@ namespace molilian.core
                 string deeplink_url = GetDeeplink(shortLinkurl);
 
                 result.channel = TkChannelEnum.tb;
+                result.accountId = _accountId;
                 result.accountName = _accountName;
                 result.link_type = success ? LinkTypeEnum.goods : result.link_type;
                 result.success = success;
@@ -471,6 +473,7 @@ namespace molilian.core
                 if (!response.Successed)
                 {
                     result.channel = TkChannelEnum.tb;
+                    result.accountId = _accountId;
                     result.accountName = _accountName;
                     result.link_type = LinkTypeEnum.unknown;
                     result.success = false;
@@ -515,7 +518,6 @@ namespace molilian.core
                 string pic = root.PathRead("data.pic", string.Empty);
                 string qrCodeUrl = root.PathRead("data.qrCodeUrl", string.Empty);
 
-
                 if (response.ResponseMessage != null)
                 {
 
@@ -573,11 +575,37 @@ namespace molilian.core
                             break;
                     }
                 }
+                if (success)
+                {
+                    if (string.IsNullOrEmpty(itemName))
+                    {
+                        itemName = GetTitle(taoToken);
+                    }
+                }
+                else
+                {
+                    itemName = GetTitle(content);
+                }
+
                 string deeplink_url = GetDeeplink(shortLinkurl);
 
                 result.channel = TkChannelEnum.tb;
+                result.accountId = _accountId;
                 result.accountName = _accountName;
-                result.link_type = success ? LinkTypeEnum.goods : result.link_type;
+
+                if (success)
+                {
+                    switch (result.link_type)
+                    {
+                        case LinkTypeEnum.profile:
+                        case LinkTypeEnum.goods:
+                            break;
+                        default:
+                            result.link_type = LinkTypeEnum.goods;
+                            break;
+                    }
+                }
+
                 result.success = success;
                 result.message = message;
                 result.content = content;
@@ -589,7 +617,7 @@ namespace molilian.core
                 result.deeplink_url = deeplink_url;
 
                 result.itemId = itemId;
-                result.itemName = success ? itemName : GetTitle(content);
+                result.itemName = itemName;
                 result.promotionPrice = promotionPrice;
                 result.sellerNickName = sellerNickName;
                 result.shopTitle = shopTitle;

Някои файлове не бяха показани, защото твърде много файлове са промени