Explorar el Código

签名增加referer

dodo hold hace 2 años
padre
commit
81f9b39d33

+ 4 - 10
molilian.api/Controllers/admin/TaobaoController.cs

@@ -306,7 +306,7 @@ namespace molilian.api.Controllers
             string filter = string.Empty;
             if (accountId != 0)
             {
-                filter += $" AND A.accountId=@accountId";
+                filter += $" AND accountId=@accountId";
             }
 
             DateTime stime = DateTime.MinValue, etime = DateTime.MinValue;
@@ -315,30 +315,24 @@ namespace molilian.api.Controllers
                 if (DateTime.TryParse(report_date[0], out stime) && DateTime.TryParse(report_date[1], out etime))
                 {
                     etime = etime.AddDays(1).AddSeconds(-1);
-                    filter += $" AND A.report_date BETWEEN @stime AND @etime";
+                    filter += $" AND report_date BETWEEN @stime AND @etime";
                 }
             }
 
             filter = filter.StringTrimStart(" AND ");
 
             //排序
-            string orderBy = "A.id DESC";
+            string orderBy = "id DESC";
             if (!string.IsNullOrEmpty(order))
             {
                 order = "descending".Equals(order) ? "DESC" : "ASC";
                 orderBy = sort switch
                 {
-                    _ => $"A.{sort} {order}",
+                    _ => $"{sort} {order}",
                 };
             }
 
             var result = new DBContext.Table("tk_report")
-                .LeftJoin("daily_logs",
-                "B.log_date = A.report_date AND B.channel=0 AND B.accountId=A.accountId",
-                "total_count, B.abandon_count, B.success_count, B.abandon_percentage, B.success_percentage," +
-                "B.parse_total_count, B.parse_abandon_count, B.parse_success_count, B.parse_abandon_percentage, B.parse_success_percentage," +
-                "B.coupon_total_count, B.coupon_abandon_count, B.coupon_success_count, B.coupon_abandon_percentage, B.coupon_success_percentage," +
-                "B.tool_total_count, B.tool_abandon_count, B.tool_success_count, B.tool_abandon_percentage, B.tool_success_percentage")
                 .Where(filter, new { accountId, stime, etime })
                 .Page(size, page)
                 .Order(orderBy)

+ 93 - 0
molilian.api/Controllers/public/CpsController.cs

@@ -0,0 +1,93 @@
+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.Security.Cryptography;
+using Microsoft.AspNetCore.Authentication;
+using TencentCloud.Ecm.V20190719.Models;
+using COSXML.Network;
+using System.Linq;
+using static dodohold.core.ZTOExpress.CreateOrderArgs;
+using MySqlX.XDevAPI;
+
+namespace molilian.api.Controllers
+{
+    [ApiController]
+    [Route("[controller]/[action]")]
+    public class CpsController : ControllerBase
+    {
+
+        protected IHttpContextAccessor _accessor;
+        public CpsController(IHttpContextAccessor accessor)
+        {
+            _accessor = accessor;
+        }
+
+        /// <summary>
+        /// oppo调用
+        /// </summary>
+        /// <param name="s">正文</param>
+        /// <param name="c">渠道。tb/jd</param>
+        /// <param name="a">分配的客户端账号</param>
+        /// <param name="t">11位时间戳</param>
+        /// <param name="sign">签名</param>
+        /// <param name="ip">客户的IP</param>
+        /// <param name="oaid">客户的唯一ID</param>
+        /// <returns></returns>
+        [HttpPost]
+        public async Task<ActionResult> getLink([FromBody] JsonElement form, [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
+        {
+            var channel = form.Read("c", string.Empty);
+            var ip = form.Read("ip", string.Empty);
+            var oaid = form.Read("oaid", string.Empty);
+
+#if DEBUG
+#else
+
+            //验证签名
+            if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(sign))
+            {
+                return new APIResult(new { success = false, message = "验证错误" }, APIResultCodeEnum.Unauthorized);
+            }
+
+            DateTime time1 = t.Convert2Datetime();
+            if (time1 < DateTime.Now.AddMinutes(-10))
+            {
+                return new APIResult(new { success = false, message = "验证错误2" }, APIResultCodeEnum.Unauthorized);
+            }
+
+            var account = ApiAccountCore.GetOne(a);
+            if (account == null)
+            {
+                return new APIResult(new { success = false, message = "验证错误3" }, APIResultCodeEnum.Unauthorized);
+            }
+            string app_sign = $"{account.api_secret}@{t}".MD5();
+            if (sign != app_sign)
+            {
+                return new APIResult(new { success = false, message = "验证错误4" }, APIResultCodeEnum.Unauthorized);
+            }
+
+
+#endif
+            return await UnionCPSCore.GetLinkAsync(channel, ip, oaid);
+        }
+
+        [HttpPost]
+        public async Task<ActionResult> unsafeGetLink([FromBody] JsonElement form)
+        {
+            var channel = form.Read("c", string.Empty);
+            var ip = form.Read("ip", string.Empty);
+            var oaid = form.Read("oaid", string.Empty);
+#if DEBUG
+            ip = "127.0.0.1";
+            oaid = "test-oaid";
+#endif
+            return await UnionCPSCore.GetLinkAsync(channel, ip, oaid);
+        }
+
+
+    }
+}

+ 2 - 1
molilian.api/Controllers/public/H5Controller.cs

@@ -28,8 +28,9 @@ namespace molilian.api.Controllers
         [HttpGet]
         public ActionResult sign()
         {
+            string referer = _accessor.HttpContext.Request.Referer();
 
-            var api = DataokeCore.GetOne();
+            var api = DataokeCore.GetOne(referer);
             if (api == null)
             {
                 return new APIResult(new

+ 30 - 0
molilian.api/Controllers/public/TaskController.cs

@@ -278,6 +278,7 @@ namespace molilian.api.Controllers
                 });
             }
 
+
             if (intervalDay > 0)
             {
                 try
@@ -299,6 +300,35 @@ namespace molilian.api.Controllers
             return new APIResult(new { success = true, message = "ok" });
         }
 
+        [HttpGet]
+        public async Task<ActionResult> DailyTable(int days = 7)
+        {
+            try
+            {
+                for (int i = 0; i < days; i++)
+                {
+                    string table_suffix = DateTime.Now.AddDays(i).ToString("yyyyMMdd");
+                    string sql = $"CREATE TABLE IF NOT EXISTS tk_parse_logs_{table_suffix} LIKE tk_parse_logs;";
+                    DBContext.Execute(sql, null);
+                    sql = $"CREATE TABLE IF NOT EXISTS jd_parse_logs_{table_suffix} LIKE jd_parse_logs;";
+                    DBContext.Execute(sql, null);
+                }
+                TkLogCore.save_dailys_log = true;
+                RedisHelper.Set("turn:save_dailys_log", 1, 86400);
+            }
+            catch (Exception ex)
+            {
+                string message = $"【创建数据标错误】\n{ex.Message}\n{ex.StackTrace}";
+                NotifyCore.Notify(new NifyMessage
+                {
+                    message = message,
+                    priority = NifyMessagePriority.high,
+                    tags = ["red_circle"]
+                });
+            }
+            return new APIResult(new { success = true, message = "ok" });
+        }
+
 
         [HttpGet]
 

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
molilian.api/Properties/PublishProfiles/https___ccr.ccs.tencentyun.com_shaobin.pubxml.user


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

@@ -4,7 +4,7 @@
       "commandName": "Project",
       "launchBrowser": true,
       "launchUrl": "swagger",
-      "environmentVariables2": {
+      "environmentVariables": {
         "ASPNETCORE_ENVIRONMENT": "Development",
         "EndPoint": "admin",
         "NtfyServer": "https://ntfy.yunhui800.com/5Sq9BytXXM5WDY3G",
@@ -15,7 +15,7 @@
         "CenterDB": "",
         "CenterRedis": "",
       },
-      "environmentVariables": {
+      "environmentVariables2": {
         "ASPNETCORE_ENVIRONMENT": "Development",
         "EndPoint": "cadmin",
         "NtfyServer": "https://ntfy.yunhui800.com/5Sq9BytXXM5WDY3G",

+ 190 - 0
molilian.core/Core/Cps/UnionCPSCore.cs

@@ -0,0 +1,190 @@
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc.Controllers;
+using Microsoft.AspNetCore.Mvc.Filters;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using dodohold.core;
+using Spire.Pdf.Exporting.XPS.Schema;
+using System.Xml.Linq;
+using System.Net;
+using TencentCloud.Mrs.V20200910.Models;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Authentication;
+using Spire.Pdf.Graphics;
+using Google.Protobuf.WellKnownTypes;
+using System.Threading.Channels;
+using TencentCloud.Weilingwith.V20230427.Models;
+using System.Threading;
+using static dodohold.core.ZTOExpress.CreateOrderArgs;
+
+
+namespace molilian.core
+{
+    public partial class UnionCPSCore
+    {
+
+        private static string _end_point;
+        static UnionCPSCore()
+        {
+            _end_point = Environment.GetEnvironmentVariable("EndPoint");
+        }
+
+        public static async Task<ActionResult> GetLinkAsync(string channel, string ip, string oaid)
+        {
+            return channel switch
+            {
+                "eleme" => await EleAsync(ip, oaid),
+                "meituan" => await MeituanAsync(ip, oaid),
+                _ => await InvalidChannelAsync(ip, oaid),
+            };
+        }
+
+        private static async Task<APIResult> InvalidChannelAsync(string ip, string oaid)
+        {
+            UnionCpsDTO result = new()
+            {
+                channel = CpsChannelEnum.invalid,
+                end_point = _end_point,
+                ip = ip,
+                oaid = oaid
+            };
+
+            result.success = false;
+            result.message = "无效渠道";
+            _ = TkLogCore.CpsLogAsync(result);
+            return new APIResult(new
+            {
+                result.success,
+                result.message,
+                channel = result.channel.ToString(),
+            });
+        }
+
+        public static bool ShouldIgnoreRequest(TkConfigDTO config, CpsChannelEnum channel, string ip, string oaid, out string reason)
+        {
+            reason = string.Empty;
+            try
+            {
+                // IP和流量控制
+                string ignorePercentageCity = config.cpsIgnorePercentageCity;
+                string? ipInfo = IP2RegionPlus.Search(ip);
+                if (AlimamaPlus.IgnoreRegionIncluded(ignorePercentageCity, ipInfo, out string regionInfo))
+                {
+                    reason = $"地区控制:{regionInfo}";
+                    return true;
+                }
+
+                int limit_num = config.cps_limit_per_ip_24h;
+                if (limit_num > 0)
+                {
+                    int num = TkLogCore.getClientRequestTotalByIp(channel, ip);
+                    if (num > limit_num)
+                    {
+                        reason = "IP控制";
+                        return true;
+                    }
+                    num = TkLogCore.getClientRequestTotalByOAID(channel, oaid);
+                    if (num > limit_num)
+                    {
+                        reason = "OAID控制";
+                        return true;
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                reason = "配置异常";
+            }
+            return false;
+        }
+        public static async Task<APIResult> EleAsync(string ip, string oaid)
+        {
+            UnionCpsDTO result = new()
+            {
+                channel = CpsChannelEnum.eleme,
+                end_point = _end_point,
+                ip = ip,
+                oaid = oaid
+            };
+
+
+            var config = TkConfigCore.Get();
+
+            //============================== 放弃转链-地区过滤 ==============================
+            if (ShouldIgnoreRequest(config, result.channel, ip, oaid, out string reason))
+            {
+                result.success = false;
+                result.message = "流量控制";
+                result.reason = reason;
+                _ = TkLogCore.CpsLogAsync(result);
+                return new APIResult(new
+                {
+                    result.success,
+                    result.message,
+                    result.reason,
+                    channel = result.channel.ToString(),
+                });
+            }
+
+            result.deeplink_url = "eleme://web?action=ali.open.nav&module=h5&packageName=me.ele&bc_fl_src=locallife_wtzt_0-0-ADGROUPID-__REQID__-2&url=https%3A%2F%2Ffc.ele.me%2Fa%2FMWJhZDM1OTY5ZTg5MTFlYzllYWEwMDE2M2UxM2FkMTE%3D%3Fscene%3D8d6c64c7f62c48ea83e88383530edd2b%26o2i_1st_clk%3D__CLICK_ID__&fastmode=1";
+            result.success = true;
+            result.message = "OK";
+
+            _ = TkLogCore.CpsLogAsync(result);
+            return new APIResult(new
+            {
+                result.success,
+                result.message,
+                result.deeplink_url,
+                channel = result.channel.ToString(),
+            });
+        }
+
+        public static async Task<APIResult> MeituanAsync(string ip, string oaid)
+        {
+            UnionCpsDTO result = new()
+            {
+                channel = CpsChannelEnum.meituan,
+                end_point = _end_point,
+                ip = ip,
+                oaid = oaid
+            };
+
+
+            var config = TkConfigCore.Get();
+
+            //============================== 放弃转链-地区过滤 ==============================
+            if (ShouldIgnoreRequest(config, result.channel, ip, oaid, out string reason))
+            {
+                result.success = false;
+                result.message = "流量控制";
+                result.reason = reason;
+                _ = TkLogCore.CpsLogAsync(result);
+                return new APIResult(new
+                {
+                    result.success,
+                    result.message,
+                    result.reason,
+                    channel = result.channel.ToString(),
+                });
+            }
+
+            result.deeplink_url = "imeituan://www.meituan.com/web?lch=cps:waimai:3:0f860c7cc90569fb14bc1fc4a4d8c057:001:33:445029&url=https%3A%2F%2Fclick.meituan.com%2Ft%3Ft%3D1%26c%3D2%26p%3DnvaI7r5zjmJB";
+            result.success = true;
+            result.message = "OK";
+
+            _ = TkLogCore.CpsLogAsync(result);
+            return new APIResult(new
+            {
+                result.success,
+                result.message,
+                result.deeplink_url,
+                channel = result.channel.ToString(),
+            });
+        }
+
+    }
+
+}

+ 16 - 2
molilian.core/Core/taoke/DataokeCore.cs

@@ -19,11 +19,12 @@ namespace molilian.core
     {
         private static readonly object _lockObj = new();
         private static IEnumerable<DataokeDTO> _cached;
-        public static DataokeDTO? GetOne()
+        public static DataokeDTO? GetOne(string domain = "")
         {
             var list = List();
             if (!list.Any()) return null;
-            return list.OrderBy(l => Guid.NewGuid()).FirstOrDefault();
+            domain = domain.ToLower();
+            return list.Where(e => FilterReferer(e, domain)).OrderBy(l => Guid.NewGuid()).FirstOrDefault();
         }
 
         public static IEnumerable<DataokeDTO> List(bool force = false)
@@ -46,6 +47,19 @@ namespace molilian.core
             _cached = list;
             return list;
         }
+
+
+        private static bool FilterReferer(DataokeDTO item, string domain)
+        {
+            if (string.IsNullOrEmpty(domain)) return true;
+            if (string.IsNullOrEmpty(item.domain)) return true;
+
+            if (domain.Contains(item.domain)) return true;
+            return false;
+        }
+
+
+
         public static void Refresh()
         {
             _ = List(true);

+ 155 - 0
molilian.core/Core/taoke/TkLogCore.cs

@@ -34,7 +34,14 @@ namespace molilian.core
         static string queue_coupon_key = "queue:coupon_logs";
         static string promotion_img_key = "queue:promotion:img";
 
+        static string queue_cps_key = "queue:cps_logs";
+        public static bool save_dailys_log = false;
 
+        static TkLogCore()
+        {
+            int flag = RedisHelper.Get<int>("turn:save_dailys_log");
+            if (flag == 1) save_dailys_log = true;
+        }
         public static int BatchInsertLogDB(int limit)
         {
             var result = EndPointCore.ProcessEndPointNodes<int>(node =>
@@ -223,6 +230,14 @@ namespace molilian.core
                     else
                     {
                         data.id = save_tk_parse_logs(data, "tk_parse_logs", connection, transaction);
+
+                        //每日分表
+                        if (save_dailys_log)
+                        {
+                            string daily_table = $"tk_parse_logs_{DateTime.Now:yyyyMMdd}";
+                            save_tk_parse_logs(data, daily_table, connection, transaction);
+                        }
+
                         if (data.elapsedTime > 1000)
                         {
                             save_tk_parse_logs(data, "tk_parse_logs_test", connection, transaction);
@@ -265,6 +280,13 @@ namespace molilian.core
                     else
                     {
                         save_jd_parse_logs(data, "jd_parse_logs", connection, transaction);
+
+                        if (save_dailys_log)
+                        {
+                            string daily_table = $"jd_parse_logs_{DateTime.Now:yyyyMMdd}";
+                            save_jd_parse_logs(data, daily_table, connection, transaction);
+                        }
+
                         if (data.elapsedTime > 1000)
                         {
                             save_jd_parse_logs(data, "jd_parse_logs_test", connection, transaction);
@@ -353,6 +375,29 @@ namespace molilian.core
                     total++;
                 }
 
+
+                for (int i = 0; i < limit; i++)
+                {
+                    var data = redis.LPop<UnionCpsDTO>(queue_cps_key);
+                    if (data == null) break;
+
+                    if (data.ip.Contains("127.0.0"))
+                    {
+                        var test_data = data.Convert2Json().Convert2Object<TestUnionCpsDTO>();
+                        connection.Insert(test_data);
+                    }
+                    else
+                    {
+                        connection.Insert(data);
+                        if (data.success)
+                        {
+                            var success_data = data.Convert2Json().Convert2Object<SuccessUnionCpsDTO>();
+                            connection.Insert(success_data);
+                        }
+                    }
+                    total++;
+                }
+
                 for (int i = 0; i < limit; i++)
                 {
                     var data = redis.LPop<PromotionQueryDTO>(promotion_img_key);
@@ -548,6 +593,30 @@ namespace molilian.core
                 .SaveAsync();
             }
         }
+        public static async Task CpsLogAsync(UnionCpsDTO response, AlimamaPlus? alimamaPlus = null)
+        {
+            try
+            {
+                var ts = DateTime.Now - response.create_time;
+                response.elapsedTime = (int)ts.TotalMilliseconds;
+                _ = RedisHelper.RPushAsync(queue_cps_key, response);
+
+                if (response.success) saveClientRequestTotal(response.channel, response.ip, response.oaid);
+
+                if (!response.ip.Contains("127.0.0"))
+                {
+                    saveCpsCache(response.channel.ToString(), response.accountId, response.success, response.message, response.reason);
+                }
+            }
+            catch (Exception ex)
+            {
+                _ = new LoggerLibrary("unionCps", "database_error")
+                .Info(response.rawContent)
+                .Info(response.Convert2Json())
+                .Info(ex.Message, ex.StackTrace)
+                .SaveAsync();
+            }
+        }
         public static async Task ParseLogAsync(JdDataDTO response)
         {
             try
@@ -729,6 +798,37 @@ namespace molilian.core
             return RedisHelper.Get<int>(cacheKey);
         }
 
+
+        private static void saveClientRequestTotal(CpsChannelEnum channel, string ip, string oaid)
+        {
+            string cacheKey = $":cache:cps_{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
+            RedisHelper.IncrBy(cacheKey);
+            RedisHelper.Expire(cacheKey, 86400);
+
+            if (!string.IsNullOrEmpty(oaid))
+            {
+                cacheKey = $":cache:cps_{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
+                RedisHelper.IncrBy(cacheKey);
+                RedisHelper.Expire(cacheKey, 86400);
+            }
+        }
+        public static int getClientRequestTotalByOAID(CpsChannelEnum channel, string oaid)
+        {
+            if (string.IsNullOrEmpty(oaid)) return 0;
+            string cacheKey = $":cache:cps_{channel}:oaid:{DateTime.Now:yyyyMMdd}:{oaid}";
+            return RedisHelper.Get<int>(cacheKey);
+        }
+        public static int getClientRequestTotalByIp(CpsChannelEnum channel, string ip)
+        {
+            if (string.IsNullOrEmpty(ip)) return 0;
+            string cacheKey = $":cache:cps_{channel}:ip:{DateTime.Now:yyyyMMdd}:{ip}";
+            return RedisHelper.Get<int>(cacheKey);
+        }
+
+
+
+
+
         private static void saveParseCache(string channel, int accountId, string accountName, bool success, string message, string reason)
         {
             saveParseAccountCache("all", success, message, reason);
@@ -886,6 +986,61 @@ namespace molilian.core
 
         }
 
+
+
+        private static void saveCpsCache(string channel, int accountId, bool success, string message, string reason)
+        {
+            saveAccountCpsCache("all", success, message, reason);
+            saveAccountCpsCache($"{channel}", success, message, reason);
+            if (accountId != 0)
+            {
+                saveAccountCpsCache($"{channel}_{accountId}", success, message, reason);
+            }
+        }
+
+        private static void saveAccountCpsCache(string flagName, bool success, string message, string reason)
+        {
+            RedisHelper.IncrBy($":cps_total:{flagName}:{DateTime.Now:yyyyMM}");
+            RedisHelper.IncrBy($":cps_total:{flagName}:{DateTime.Now:yyyyMMdd}");
+            RedisHelper.IncrBy($":cps_total:{flagName}:{DateTime.Now:yyyyMMddHH}");
+
+
+            string result = success ? "success" : "fail";
+            RedisHelper.IncrBy($":cps_total:{flagName}:{result}:{DateTime.Now:yyyyMM}");
+            RedisHelper.IncrBy($":cps_total:{flagName}:{result}:{DateTime.Now:yyyyMMdd}");
+            RedisHelper.IncrBy($":cps_total:{flagName}:{result}:{DateTime.Now:yyyyMMddHH}");
+
+
+            if (!string.IsNullOrEmpty(message))
+            {
+                RedisHelper.SAdd($":cps_total:{flagName}:message:{DateTime.Now:yyyyMM}", message);
+                RedisHelper.SAdd($":cps_total:{flagName}:message:{DateTime.Now:yyyyMMdd}", message);
+                RedisHelper.SAdd($":cps_total:{flagName}:message:{DateTime.Now:yyyyMMddHH}", message);
+
+                RedisHelper.IncrBy($":cps_total:{flagName}:{message}:{DateTime.Now:yyyyMM}");
+                RedisHelper.IncrBy($":cps_total:{flagName}:{message}:{DateTime.Now:yyyyMMdd}");
+                RedisHelper.IncrBy($":cps_total:{flagName}:{message}:{DateTime.Now:yyyyMMddHH}");
+                RedisHelper.IncrBy($":cps_total:{flagName}:message:{message}:{DateTime.Now:yyyyMM}");
+                RedisHelper.IncrBy($":cps_total:{flagName}:message:{message}:{DateTime.Now:yyyyMMdd}");
+                RedisHelper.IncrBy($":cps_total:{flagName}:message:{message}:{DateTime.Now:yyyyMMddHH}");
+            }
+
+            if (!string.IsNullOrEmpty(reason))
+            {
+                RedisHelper.SAdd($":cps_total:{flagName}:reason:{DateTime.Now:yyyyMM}", reason);
+                RedisHelper.SAdd($":cps_total:{flagName}:reason:{DateTime.Now:yyyyMMdd}", reason);
+                RedisHelper.SAdd($":cps_total:{flagName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
+
+                RedisHelper.IncrBy($":cps_total:{flagName}:{reason}:{DateTime.Now:yyyyMM}");
+                RedisHelper.IncrBy($":cps_total:{flagName}:{reason}:{DateTime.Now:yyyyMMdd}");
+                RedisHelper.IncrBy($":cps_total:{flagName}:{reason}:{DateTime.Now:yyyyMMddHH}");
+                RedisHelper.IncrBy($":cps_total:{flagName}:reason:{reason}:{DateTime.Now:yyyyMM}");
+                RedisHelper.IncrBy($":cps_total:{flagName}:reason:{reason}:{DateTime.Now:yyyyMMdd}");
+                RedisHelper.IncrBy($":cps_total:{flagName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}");
+            }
+
+        }
+
         public static int GetTotal(string keyname, bool all_node = true)
         {
             //:coupon_total:tb:20240706

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

@@ -27,7 +27,6 @@ namespace molilian.core
 {
     public partial class UnionParseCore
     {
-
         public static async Task<ActionResult> UnionParseAsync(string content, string channel, string ip, string oaid, int accountid = 0)
         {
             content = content.Trim();

+ 1 - 0
molilian.core/DTO/DataokeDTO.cs

@@ -4,6 +4,7 @@
     {
         public int id { get; set; }
         public string name { get; set; } = string.Empty;
+        public string domain { get; set; } = string.Empty;
         public string description { get; set; } = string.Empty;
         public string app_key { get; set; } = string.Empty;
         public string app_secret { get; set; } = string.Empty;

+ 6 - 1
molilian.core/DTO/Emun/TkChannelEnum.cs

@@ -10,5 +10,10 @@
         wemeet = 101,
         bdpan = 102,
     }
-
+    public enum CpsChannelEnum
+    {
+        invalid = 0,
+        meituan = 1,
+        eleme = 2,
+    }
 }

+ 2 - 0
molilian.core/DTO/alimama/TkConfigDTO.cs

@@ -28,5 +28,7 @@ namespace molilian.core
 
         public int jd_limit_per_ip_24h { get; set; } = 0;
         public int tk_limit_per_ip_24h { get; set; } = 0;
+        public string cpsIgnorePercentageCity { get; set; } = string.Empty;
+        public int cps_limit_per_ip_24h { get; set; } = 0; 
     }
 }

+ 37 - 0
molilian.core/DTO/cps/UnionCpsDTO.cs

@@ -0,0 +1,37 @@
+
+using dodohold.core;
+
+namespace molilian.core
+{
+
+    [Table("tk_cps_logs")]
+
+    public class UnionCpsDTO : BaseUnionCpsDTO;
+
+    [Table("tk_cps_logs_test")]
+    public class TestUnionCpsDTO : BaseUnionCpsDTO;
+
+
+    [Table("tk_cps_logs_success")]
+    public class SuccessUnionCpsDTO : BaseUnionCpsDTO;
+
+
+    public class BaseUnionCpsDTO
+    {
+        [Key]
+        public long id { get; set; }
+        public CpsChannelEnum channel { get; set; }
+        public int accountId { get; set; } = 0;
+        public string accountName { get; set; } = string.Empty;
+        public string rawContent { get; set; } = string.Empty;
+        public bool success { get; set; } = false;
+        public string reason { get; set; } = string.Empty;
+        public string message { get; set; } = string.Empty;
+        public string deeplink_url { get; set; } = string.Empty;
+        public int elapsedTime { get; set; } = 0;
+        public string ip { get; set; } = string.Empty;
+        public string oaid { get; set; } = string.Empty;
+        public DateTime create_time { get; set; } = DateTime.Now;
+        public string end_point { get; set; } = string.Empty;
+    }
+}

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

@@ -257,7 +257,7 @@ namespace molilian.core
         {
             DateTime log_date = DateTime.Now.AddDays(-intervalDay).Date;
 
-            var endpoint = data_type == 1 ? EndPointCore.GetParseAdmin () : EndPointCore.GetCouponAdmin();
+            var endpoint = data_type == 1 ? EndPointCore.GetParseAdmin() : EndPointCore.GetCouponAdmin();
             if (string.IsNullOrEmpty(endpoint.db_server)) return;
 
             using var conn = EndPointCore.GetDbConnection(endpoint.db_server);
@@ -480,13 +480,16 @@ namespace molilian.core
                 DateTime report_date = date.Date;
                 if (report_date == DateTime.Now.Date)
                 {
+#if DEBUG
+#else
                     TkPoolCore.SaveIncomeAmt($"{_accountId}", result.eff_tk_disp_tfee);
+#endif
                     //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);
                 }
             }
-            catch (Exception ex) { }
+            catch (Exception ex) { throw; }
         }
         private void EachSaveReportOverview(DateTime report_date, string tableName, TkReportDTO data)
         {
@@ -513,6 +516,91 @@ namespace molilian.core
                 .Add("eff_ord_amt", data.eff_ord_amt)
                 .Add("eff_tk_disp_tfee", data.eff_tk_disp_tfee);
 
+            string data_suffix = report_date.ToString("yyyyMMdd");
+            if ("tk_report_hourtrend".Equals(tableName))
+            {
+                data_suffix = report_date.ToString("yyyyMMddHH");
+            }
+
+            string accountName = $"{TkChannelEnum.tb}_{_accountId}";
+            int total_count = TkLogCore.GetTotal($":total:{accountName}:{data_suffix}");
+            int success_count = 0, abandon_count = 0;
+            string success_percentage = string.Empty, abandon_percentage = string.Empty;
+            if (total_count > 0)
+            {
+                success_count = TkLogCore.GetTotal($":total:{accountName}:success:{data_suffix}");
+                abandon_count = TkLogCore.GetTotal($":total:{accountName}:放弃转链:{data_suffix}");
+                if (total_count > 0)
+                {
+                    success_percentage = $"{success_count / (double)total_count * 100:f2}%";
+                    abandon_percentage = $"{abandon_count / (double)total_count * 100:f2}%";
+                }
+            }
+            createArgs.Add("total_count", total_count);
+            createArgs.Add("success_count", success_count);
+            createArgs.Add("abandon_count", abandon_count);
+            createArgs.Add("success_percentage", success_percentage);
+            createArgs.Add("abandon_percentage", abandon_percentage);
+
+            int parse_total_count = TkLogCore.GetTotal($":parse_total:{accountName}:{data_suffix}");
+            int parse_success_count = 0, parse_abandon_count = 0;
+            string parse_success_percentage = string.Empty, parse_abandon_percentage = string.Empty;
+            if (parse_total_count > 0)
+            {
+                parse_success_count = TkLogCore.GetTotal($":parse_total:{accountName}:success:{data_suffix}");
+                parse_abandon_count = TkLogCore.GetTotal($":parse_total:{accountName}:放弃转链:{data_suffix}");
+                if (parse_total_count > 0)
+                {
+                    parse_success_percentage = $"{parse_success_count / (double)parse_total_count * 100:f2}%";
+                    parse_abandon_percentage = $"{parse_abandon_count / (double)parse_total_count * 100:f2}%";
+                }
+            }
+            createArgs.Add("parse_total_count", parse_total_count);
+            createArgs.Add("parse_success_count", parse_success_count);
+            createArgs.Add("parse_abandon_count", parse_abandon_count);
+            createArgs.Add("parse_success_percentage", parse_success_percentage);
+            createArgs.Add("parse_abandon_percentage", parse_abandon_percentage);
+
+
+            int coupon_total_count = TkLogCore.GetTotal($":coupon_total:{accountName}:{data_suffix}", false);
+            int coupon_success_count = 0, coupon_abandon_count = 0;
+            string coupon_success_percentage = string.Empty, coupon_abandon_percentage = string.Empty;
+            if (coupon_total_count > 0)
+            {
+                coupon_success_count = TkLogCore.GetTotal($":coupon_total:{accountName}:success:{data_suffix}", false);
+                coupon_abandon_count = TkLogCore.GetTotal($":coupon_total:{accountName}:放弃转链:{data_suffix}", false);
+                if (coupon_total_count > 0)
+                {
+                    coupon_success_percentage = $"{coupon_success_count / (double)coupon_total_count * 100:f2}%";
+                    coupon_abandon_percentage = $"{coupon_abandon_count / (double)coupon_total_count * 100:f2}%";
+                }
+            }
+            createArgs.Add("coupon_total_count", coupon_total_count);
+            createArgs.Add("coupon_success_count", coupon_success_count);
+            createArgs.Add("coupon_abandon_count", coupon_abandon_count);
+            createArgs.Add("coupon_success_percentage", coupon_success_percentage);
+            createArgs.Add("coupon_abandon_percentage", coupon_abandon_percentage);
+
+
+            int tool_total_count = TkLogCore.GetTotal($":tool_total:{accountName}:{data_suffix}");
+            int tool_success_count = 0, tool_abandon_count = 0;
+            string tool_success_percentage = string.Empty, tool_abandon_percentage = string.Empty;
+            if (tool_total_count > 0)
+            {
+                tool_success_count = TkLogCore.GetTotal($":tool_total:{accountName}:success:{data_suffix}");
+                tool_abandon_count = TkLogCore.GetTotal($":tool_total:{accountName}:放弃转链:{data_suffix}");
+                if (tool_total_count > 0)
+                {
+                    tool_success_percentage = $"{tool_success_count / (double)tool_total_count * 100:f2}%";
+                    tool_abandon_percentage = $"{tool_abandon_count / (double)tool_total_count * 100:f2}%";
+                }
+            }
+            createArgs.Add("tool_total_count", tool_total_count);
+            createArgs.Add("tool_success_count", tool_success_count);
+            createArgs.Add("tool_abandon_count", tool_abandon_count);
+            createArgs.Add("tool_success_percentage", tool_success_percentage);
+            createArgs.Add("tool_abandon_percentage", tool_abandon_percentage);
+
             if (exist == null)
             {
                 createArgs.Add("accountId", _accountId)
@@ -528,10 +616,8 @@ namespace molilian.core
                     .Where("id=@id", new { exist.id })
                     .Update();
             }
-
         }
 
-
         /// <summary>
         /// 修正点击数
         /// </summary>

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio