Explorar o código

新增优惠券接口

dodo hold %!s(int64=2) %!d(string=hai) anos
pai
achega
4db8d5e1f5

+ 42 - 41
molilian.api/Controllers/admin/TaobaoController.cs

@@ -46,6 +46,8 @@ namespace molilian.api.Controllers
             switch (name)
             {
                 case "enable_fake_click":
+                case "enable_parse":
+                case "enable_coupon":
                 case "status":
                     bool bVal = val.Equals("True");
                     result = new DBContext.Table("tk_pool")
@@ -196,11 +198,24 @@ namespace molilian.api.Controllers
             foreach (var item in result.List)
             {
                 if (item.total_count > 0) continue;
+
+
                 item.total_count = RedisHelper.Get<int>($":total:all:{item.report_date:yyyyMMdd}");
                 if (item.total_count == 0) continue;
                 item.success_count = RedisHelper.Get<int>($":total:all:success:{item.report_date:yyyyMMdd}");
                 item.abandon_count = RedisHelper.Get<int>($":total:all:放弃转链:{item.report_date:yyyyMMdd}");
 
+
+#if DEBUG
+                //if (item.report_date == DateTime.Now.Date)
+                //{
+                //    RedisHelper.Set($":total:all:{item.report_date:yyyyMMdd}", item.total_count / 2);
+                //    RedisHelper.Set($":total:all:success:{item.report_date:yyyyMMdd}", item.total_count / 2);
+                //    RedisHelper.Set($":total:all:放弃转链:{item.report_date:yyyyMMdd}", item.abandon_count / 2);
+                //}
+#endif
+
+
                 if (item.total_count > 0)
                 {
                     item.success_percentage = $"{item.success_count / (double)item.total_count * 100:f2}%";
@@ -268,10 +283,19 @@ namespace molilian.api.Controllers
                 //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}");
+
+                string accountName = $"{TkChannelEnum.tb}_{item.accountId}";
+
+                item.total_count = RedisHelper.Get<int>($":total:{accountName}:{item.report_date:yyyyMMdd}");
+                if (item.total_count == 0)
+                {
+                    //todo  过度用, 0613 跑两天就可以删掉
+                    accountName = item.accountName;
+                    item.total_count = RedisHelper.Get<int>($":total:{accountName}:{item.report_date:yyyyMMdd}");
+                }
                 if (item.total_count == 0) continue;
-                item.success_count = RedisHelper.Get<int>($":total:{item.accountName}:success:{item.report_date:yyyyMMdd}");
-                item.abandon_count = RedisHelper.Get<int>($":total:{item.accountName}:放弃转链:{item.report_date:yyyyMMdd}");
+                item.success_count = RedisHelper.Get<int>($":total:{accountName}:success:{item.report_date:yyyyMMdd}");
+                item.abandon_count = RedisHelper.Get<int>($":total:{accountName}:放弃转链:{item.report_date:yyyyMMdd}");
 
                 if (item.total_count > 0)
                 {
@@ -339,7 +363,15 @@ namespace molilian.api.Controllers
             foreach (var item in result.List)
             {
                 if (item.total_count > 0) continue;
-                item.total_count = RedisHelper.Get<int>($":total:{item.accountName}:{item.report_date:yyyyMMddHH}");
+
+                string accountName = $"{TkChannelEnum.tb}_{item.accountId}";
+                item.total_count = RedisHelper.Get<int>($":total:{accountName}:{item.report_date:yyyyMMddHH}");
+                if (item.total_count == 0)
+                {
+                    //todo  过度用, 0613 跑两天就可以删掉
+                    accountName = item.accountName;
+                    item.total_count = RedisHelper.Get<int>($":total:{accountName}:{item.report_date:yyyyMMddHH}");
+                }
                 if (item.total_count == 0) continue;
                 item.success_count = RedisHelper.Get<int>($":total:{item.accountName}:success:{item.report_date:yyyyMMddHH}");
                 item.abandon_count = RedisHelper.Get<int>($":total:{item.accountName}:放弃转链:{item.report_date:yyyyMMddHH}");
@@ -380,7 +412,6 @@ namespace molilian.api.Controllers
                 cacheKey = $":total:{accountName}:message:{_report_date}";
                 string[] message_keys = RedisHelper.SMembers(cacheKey);
 
-
                 string[] combinedKeys = keys.Union(message_keys).ToArray();
 
                 foreach (var keyname in combinedKeys)
@@ -388,11 +419,13 @@ namespace molilian.api.Controllers
                     cacheKey = $":total:{accountName}:{keyname}:{_report_date}";
                     int value = RedisHelper.Get<int>(cacheKey);
                     if (value == 0) continue;
+#if DEBUG
+                    //RedisHelper.Set(cacheKey, value / 2);
+#endif
                     result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
                 }
                 result = result.OrderByDescending(item => item.value).ToList();
 
-
                 cacheKey = $":total:{accountName}:reason:{_report_date}";
                 string[] reason_keys = RedisHelper.SMembers(cacheKey);
 
@@ -401,48 +434,16 @@ namespace molilian.api.Controllers
                     cacheKey = $":total:{accountName}:{keyname}:{_report_date}";
                     int value = RedisHelper.Get<int>(cacheKey);
                     if (value == 0) continue;
+#if DEBUG
+                    //RedisHelper.Set(cacheKey, value / 2);
+#endif
                     reason_result.Add(new { name = keyname, value, increases = Math.Round(value / total * 100, 2) });
                 }
                 reason_result = reason_result.OrderByDescending(item => item.value).ToList();
             }
             return new APIResult(new { total, data = result, data2 = reason_result });
-
-
-
-            //RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMM}");
-            //RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMMdd}");
-            //RedisHelper.IncrBy($":total:{accountName}:{DateTime.Now:yyyyMMddHH}");
-
-
-            //string result = success ? "success" : "fail";
-            //RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
-            //RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
-            //RedisHelper.IncrBy($":total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
-
-
-            //if (!string.IsNullOrEmpty(message))
-            //{
-            //    RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
-            //    RedisHelper.SAdd($":total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
-
-            //    RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
-            //    RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
-            //    RedisHelper.IncrBy($":total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
-            //}
-
-            //if (!string.IsNullOrEmpty(reason))
-            //{
-            //    RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
-            //    RedisHelper.SAdd($":total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
-
-            //    RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
-            //    RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
-            //    RedisHelper.IncrBy($":total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
-            //}
         }
 
-
-
         [HttpPost]
         public ActionResult settle_bills_total([FromBody] JsonElement form)
         {

+ 8 - 2
molilian.api/Controllers/admin/TaobaoOrderController.cs

@@ -26,6 +26,7 @@ namespace molilian.api.Controllers
             string sort = form.Read<string>("sort");
             string order = form.Read<string>("order");
             string name = form.Read<string>("keyword");
+            string query_type = form.Read<string>("query_type", "tbPaidTime");
             var tkStatus = form.PathReadArray<int>("tkStatus[]");
             int maxTotal = form.Read("maxTotal", 0);
 
@@ -47,13 +48,18 @@ namespace molilian.api.Controllers
                 if (DateTime.TryParse(time[0], out stime) && DateTime.TryParse(time[1], out etime))
                 {
                     etime = etime.AddDays(1).AddSeconds(-1);
-                    filter += $" AND tkPaidTime BETWEEN @stime AND @etime";
+
+                    filter += query_type switch
+                    {
+                        "tkEarningTime" or "tkCreateTime" => $" AND {query_type} BETWEEN @stime AND @etime",
+                        _ => $" AND tbPaidTime BETWEEN @stime AND @etime",
+                    };
                 }
             }
             filter = filter.StringTrimStart(" AND ");
 
             //排序
-            string orderBy = "tkPaidTime DESC";
+            string orderBy = $"{query_type} DESC";
             if (!string.IsNullOrEmpty(order))
             {
                 order = "descending".Equals(order) ? "DESC" : "ASC";

+ 50 - 18
molilian.api/Controllers/public/TkController.cs

@@ -79,24 +79,56 @@ namespace molilian.api.Controllers
             var channel = form.Read("c", string.Empty);
             var ip = form.Read("ip", string.Empty);
             var oaid = form.Read("oaid", string.Empty);
-            //            var count = form.Read<int>("i", 1);
-
-            //#if DEBUG
-            //            ActionResult result = null;
-            //            for (var i = 0; i < count; i++)
-            //            {
-            //                result = await UnionParseCore.UnionParseAsync(content, channel, ip, oaid);
-            //            }
-            //            if (result != null) return result;
-            //            return new APIResult(new
-            //            {
-            //                success = true,
-            //                message = "ok"
-            //            });
-            //#else
             return await UnionParseCore.UnionParseAsync(content, channel, ip, oaid);
-            //#endif
         }
+
+
+        [HttpPost]
+        public async Task<ActionResult> unionCoupon([FromBody] JsonElement form, [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
+        {
+            //正文
+            var content = form.Read("s", string.Empty);
+            var channel = form.Read("c", string.Empty);
+            var ip = form.Read("ip", string.Empty);
+            var oaid = form.Read("oaid", string.Empty);
+
+            //验证签名
+            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);
+            }
+            return await UnionCouponCore.UnionCouponAsync(content, channel, ip, oaid);
+        }
+
+
+        [HttpPost]
+        public async Task<ActionResult> unsafeCoupon([FromBody] JsonElement form)
+        {
+            var content = form.Read("s", string.Empty);
+            var channel = form.Read("c", string.Empty);
+            var ip = form.Read("ip", string.Empty);
+            var oaid = form.Read("oaid", string.Empty);
+            return await UnionCouponCore.UnionCouponAsync(content, channel, ip, oaid);
+        }
+
+
         /// <summary>
         /// 第三方调用
         /// </summary>
@@ -137,7 +169,7 @@ namespace molilian.api.Controllers
                     });
                 }
 
-                var account = TkPoolCore.GetOne();
+                var account = TkPoolCore.GetOne(TkPoolCore.TkAction.parse);
                 if (account == null)
                 {
                     result.success = false;
@@ -254,7 +286,7 @@ namespace molilian.api.Controllers
                     });
                 }
 
-                var account = TkPoolCore.GetOne();
+                var account = TkPoolCore.GetOne(TkPoolCore.TkAction.parse);
                 if (account == null)
                 {
                     result.success = false;

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 0 - 0
molilian.api/Properties/PublishProfiles/https___ccr.ccs.tencentyun.com_shaobin.pubxml.user


+ 23 - 0
molilian.core/Core/taoke/DataokeCore.cs

@@ -140,5 +140,28 @@ namespace molilian.core
             return result;
         }
 
+        public static GoodsDetailDTO? GetCoupon(DataokeDTO api, JdPoolDTO account, string url, string itemId)
+        {
+            var plus = new DataokePlus(api.app_key, api.app_secret);
+            var item = plus.GetDetails([itemId]);
+            if (item != null)
+            {
+                try
+                {
+                    string body = plus.JDParse(account.unionid, url, item.couponLink);
+                    JsonElement root = body.Convert2JsonElement();
+                    int code = root.Read("code", -1);
+                    if (code != 0) return null;
+
+                    item.couponLink = root.PathRead("data.shortUrl", string.Empty);
+                }
+                catch
+                {
+                    return null;
+                }
+            }
+            return item;
+        }
+
     }
 }

+ 26 - 7
molilian.core/Core/taoke/OrderTrackingCore.cs

@@ -29,29 +29,45 @@ 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.itemId}";
+            RedisHelper.Set(cacheKey, item, ttl);
 
-            //cacheKey = $":cache:order_summary:{item.accountId}:{item.itemName}";
-            //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)
         {
             string cacheKey = $":cache:order_summary:{accountName}:{name}";
             return RedisHelper.Get<TkDataDTO>(cacheKey);
         }
+        //过时待删
         public static void RemoveLinkSummary(string accountName, string itemId)
         {
             string cacheKey = $":cache:order_summary:{accountName}:{itemId}";
             RedisHelper.Del(cacheKey);
         }
+        public static TkDataDTO GetLinkSummary(int accountId, string name)
+        {
+            string cacheKey = $":cache:order_summary:{accountId}:{name}";
+            return RedisHelper.Get<TkDataDTO>(cacheKey);
+        }
+        public static void RemoveLinkSummary(int accountId, string itemId)
+        {
+            string cacheKey = $":cache:order_summary:{accountId}:{itemId}";
+            RedisHelper.Del(cacheKey);
+        }
 
         public static bool MatchOrder(TkOrderDetailDTO item, IDbConnection conn)
         {
             if (item.tbPaidTime < DateTime.Now.AddDays(-1)) return false;
 
-            var summary = GetLinkSummary(item.accountName, item.itemTitle);
-            if (summary == null) return false;
+            var summary = GetLinkSummary(item.accountId, item.itemTitle);
+            if (summary == null)
+            {
+                summary = GetLinkSummary(item.accountName, item.itemTitle);
+                if (summary == null) return false;
+            }
 
             var config = TkConfigCore.Get();
             Random rand = new();
@@ -64,12 +80,14 @@ namespace molilian.core
             DateTime rounded = new(paidTime.Year, paidTime.Month, paidTime.Day, paidTime.Hour, minutes, 0);
             string batchId = rounded.ToString("yyyyMMddHHmm");
 
+            string accountName = item.accountName;
+
             DateTime expTime = item.tbPaidTime.Hour >= 21 ? item.tbPaidTime.AddHours(3) : item.tbPaidTime.Date.AddDays(1);
             var data = new TkOrderTrackingDTO()
             {
                 channel = summary.channel,
                 accountId = item.accountId,
-                accountName = item.accountName,
+                accountName = accountName,
                 batchId = batchId,
                 ip = summary.ip,
                 oaid = summary.oaid,
@@ -91,6 +109,7 @@ namespace molilian.core
             };
 
             conn.Replace(data);
+            RemoveLinkSummary(item.accountId, item.itemTitle);
             RemoveLinkSummary(item.accountName, item.itemTitle);
             return true;
         }

+ 106 - 13
molilian.core/Core/taoke/TkLogCore.cs

@@ -26,6 +26,7 @@ namespace molilian.core
         static string queue_parse_dy_key = "queue:parse_logs:dy";
         static string queue_parse_tool_key = "queue:parse_logs:tool";
 
+        static string queue_coupon_key = "queue:coupon_logs";
 
         public static void BatchInsertLogDB()
         {
@@ -192,6 +193,14 @@ namespace molilian.core
                         .Add("create_time", data.create_time)
                         .Create(DBContext.InsertType.NORMAL, transaction);
                 }
+
+
+                for (int i = 0; i < 100; i++)
+                {
+                    var data = RedisHelper.LPop<UnionCouponDTO>(queue_coupon_key);
+                    if (data == null) break;
+                    connection.Insert(data);
+                }
                 transaction.Commit();
             }
             catch (Exception ex)
@@ -222,8 +231,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);
+                saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
             }
             catch (Exception ex) { }
         }
@@ -235,8 +243,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);
+                saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
 
                 if (!response.success && "nologin".Equals(response.message))
                 {
@@ -278,8 +285,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);
+                saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
                 if (!string.IsNullOrEmpty(response.itemId)) TkOrderTrackingCore.SaveLinkSummary(response);
 
                 if (!response.success && "nologin".Equals(response.message))
@@ -308,6 +314,41 @@ namespace molilian.core
                 .Save();
             }
         }
+        public static async Task CouponLogAsync(UnionCouponDTO response, AlimamaPlus? alimamaPlus = null)
+        {
+            try
+            {
+                var ts = DateTime.Now - response.create_time;
+                response.elapsedTime = (int)ts.TotalMilliseconds;
+                RedisHelper.RPush(queue_coupon_key, response);
+                saveCouponCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
+
+                if (!response.success && "nologin".Equals(response.message))
+                {
+                    switch (response.channel)
+                    {
+                        case TkChannelEnum.tb:
+                            await Task.Run(() =>
+                            {
+                                if (alimamaPlus != null)
+                                {
+                                    (bool success, string message) = alimamaPlus.RenewCookie();
+                                    if (success) return;
+                                }
+                                TkPoolCore.Disabled(response.accountName, $"{response.rawContent}");
+                            }); break;
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                new LoggerLibrary("unionCoupon", "database_error")
+                .Info(response.rawContent)
+                .Info(response.Convert2Json())
+                .Info(ex.Message, ex.StackTrace)
+                .Save();
+            }
+        }
         public static async Task ParseLogAsync(JdDataDTO response)
         {
             try
@@ -315,8 +356,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);
+                saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
 
             }
             catch (Exception ex) { }
@@ -328,8 +368,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);
+                saveCache(response.channel.ToString(), response.accountId, response.accountName, response.success, response.message, response.reason);
 
             }
             catch (Exception ex) { }
@@ -341,17 +380,21 @@ namespace molilian.core
                 var ts = DateTime.Now - response.create_time;
                 response.elapsedTime = (int)ts.TotalMilliseconds;
                 RedisHelper.RPush(queue_parse_tool_key, response);
-                saveCache(response.channel.ToString(), "tool", response.success, response.message, response.reason);
+                saveCache(response.channel.ToString(), 0, "tool", response.success, response.message, response.reason);
             }
             catch (Exception ex) { }
         }
 
-        private static void saveCache(string channel, string accountName, bool success, string message, string reason)
+        private static void saveCache(string channel, int accountId, string accountName, bool success, string message, string reason)
         {
             saveAccountCache("all", success, message, reason);
             saveAccountCache($"{channel}", success, message, reason);
             saveAccountCache($"{accountName}", success, message, reason);
-
+            if (accountId != 0)
+            {
+                //todo 放着跑两天,要将读取的地方改成读取accountid
+                saveAccountCache($"{channel}_{accountId}", success, message, reason);
+            }
         }
 
         private static void saveAccountCache(string accountName, bool success, string message, string reason)
@@ -390,6 +433,56 @@ namespace molilian.core
             }
 
         }
+
+        private static void saveCouponCache(string channel, int accountId, string accountName, bool success, string message, string reason)
+        {
+            saveAccountCouponCache("all", success, message, reason);
+            saveAccountCouponCache($"{channel}", success, message, reason);
+            if (accountId != 0)
+            {
+                //todo 放着跑两天,要将读取的地方改成读取accountid
+                saveAccountCouponCache($"{channel}_{accountId}", success, message, reason);
+            }
+        }
+
+        private static void saveAccountCouponCache(string accountName, bool success, string message, string reason)
+        {
+            RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMM}");
+            RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMMdd}");
+            RedisHelper.IncrBy($":coupon_total:{accountName}:{DateTime.Now:yyyyMMddHH}");
+
+
+            string result = success ? "success" : "fail";
+            RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMM}");
+            RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}");
+            RedisHelper.IncrBy($":coupon_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}");
+
+
+            if (!string.IsNullOrEmpty(message))
+            {
+                RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMM}", message);
+                RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message);
+                RedisHelper.SAdd($":coupon_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message);
+
+                RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMM}");
+                RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}");
+                RedisHelper.IncrBy($":coupon_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}");
+            }
+
+            if (!string.IsNullOrEmpty(reason))
+            {
+                RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason);
+                RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason);
+                RedisHelper.SAdd($":coupon_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason);
+
+                RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}");
+                RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}");
+                RedisHelper.IncrBy($":coupon_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}");
+            }
+
+        }
+
+
     }
 
 }

+ 20 - 3
molilian.core/Core/taoke/TkPoolCore.cs

@@ -16,6 +16,13 @@ namespace molilian.core
 {
     public partial class TkPoolCore
     {
+        public enum TkAction
+        {
+            all,
+            parse,
+            coupon
+        }
+
         private static string _end_point;
         static TkPoolCore()
         {
@@ -25,11 +32,11 @@ namespace molilian.core
         private static readonly object _lockObj = new();
         private static IEnumerable<TkPoolDTO> _cached;
         private static Dictionary<string, decimal> _incomeAmt = new();
-        public static TkPoolDTO? GetOne()
+        public static TkPoolDTO? GetOne(TkAction action)
         {
             var list = List();
             if (!list.Any()) return null;
-            return list.Where(IsNotExceedDailyIncomeLimit).OrderBy(l => Guid.NewGuid()).FirstOrDefault();
+            return list.Where(e => IsNotExceedDailyIncomeLimit(e, action)).OrderBy(l => Guid.NewGuid()).FirstOrDefault();
         }
         public static TkPoolDTO? GetOne(int id)
         {
@@ -64,13 +71,23 @@ namespace molilian.core
             }
             catch (Exception ex) { return 0; }
         }
-        private static bool IsNotExceedDailyIncomeLimit(TkPoolDTO item)
+        private static bool IsNotExceedDailyIncomeLimit(TkPoolDTO item, TkAction action)
         {
 
             if (!string.IsNullOrEmpty(_end_point) && !string.IsNullOrEmpty(item.end_point))
             {
                 if (item.end_point != _end_point) return false;
             }
+            switch (action)
+            {
+                case TkAction.parse:
+                    if (!item.enable_parse) return false;
+                    break;
+                case TkAction.coupon:
+                    if (!item.enable_coupon) return false;
+                    break;
+            }
+
             if (item.daily_income_limit == 0) return true;
             decimal income_amt = GetIncomeAmt(item.name);
             return income_amt < item.daily_income_limit;

+ 237 - 0
molilian.core/Core/taoke/UnionCouponCore.cs

@@ -0,0 +1,237 @@
+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;
+
+
+namespace molilian.core
+{
+    public partial class UnionCouponCore
+    {
+
+        public static async Task<ActionResult> UnionCouponAsync(string content, string channel, string ip, string oaid)
+        {
+            return channel switch
+            {
+                "jd" => await JdCouponAsync(content, ip, oaid),
+                _ => await TaobaoCouponAsync(content, ip, oaid),
+            };
+        }
+
+        public static async Task<APIResult> TaobaoCouponAsync(string content, string ip = "", string oaid = "")
+        {
+            AlimamaPlus alimama = null;
+            content = content.UrlDecode();
+            UnionCouponDTO result = new()
+            {
+                channel = TkChannelEnum.tb,
+                rawContent = content
+            };
+            try
+            {
+                if (AlimamaPlus.ShouldIgnoreRequest(ip, oaid, out string reason))
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = reason;
+                    _ = TkLogCore.CouponLogAsync(result);
+                    return new APIResult(new
+                    {
+                        result.success,
+                        result.message,
+                        channel = result.channel.ToString(),
+                    });
+                }
+
+                var account = TkPoolCore.GetOne(TkPoolCore.TkAction.coupon);
+                if (account == null)
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = "没有匹配账号";
+                    _ = TkLogCore.CouponLogAsync(result);
+                    return new APIResult(new
+                    {
+                        result.success,
+                        result.message,
+                        channel = result.channel.ToString(),
+                    });
+                }
+                result.accountId = account.id;
+                result.accountName = account.name;
+                alimama = new AlimamaPlus(account);
+                result = await alimama.UnionCoupon2Async(content, result);
+
+                if (result.success && result.couponAmount == 0)
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = "没有优惠券";
+                }
+            }
+            catch (Exception ex)
+            {
+                if (ex.Message.Contains("A task was canceled"))
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = "请求超时";
+                }
+                else
+                {
+                    new LoggerLibrary("unionCoupon", "tb_error")
+                        .Info(ip, oaid)
+                        .Info(content)
+                        .Info(ex.Message, ex.StackTrace)
+                        .Save();
+
+                    NotifyCore.Notify(new NifyMessage
+                    {
+                        message = $"【转链异常TB】\n{content}\n\n{ex.Message}\n{ex.StackTrace}",
+                        priority = NifyMessagePriority.high,
+                        tags = ["red_circle"]
+                    });
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = "转链接口异常";
+                }
+            }
+            _ = TkLogCore.CouponLogAsync(result, alimama);
+            if (!result.success)
+            {
+                return new APIResult(new
+                {
+                    result.success,
+                    result.message,
+                    channel = result?.channel.ToString(),
+                });
+            }
+            return new APIResult(new
+            {
+                result.success,
+                result.message,
+                channel = result?.channel.ToString(),
+                result?.itemId,
+                result?.couponAmount,
+                result?.deeplink_url,
+                result?.pic,
+                result?.couponEffectiveStartTime,
+                result?.couponEffectiveEndTime,
+            });
+        }
+
+        public static async Task<APIResult> JdCouponAsync(string content, string ip, string oaid)
+        {
+            content = content.UrlDecode();
+            UnionCouponDTO result = new()
+            {
+                channel = TkChannelEnum.jd,
+                rawContent = content
+            };
+
+            try
+            {
+                if (JdUnionPlus.ShouldIgnoreRequest(ip, oaid, out string reason))
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = reason;
+                    _ = TkLogCore.CouponLogAsync(result);
+                    return new APIResult(result);
+                }
+
+                var api = DataokeCore.GetOne();
+                if (api == null)
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = "没有匹配账号";
+                    result.rawContent = content;
+                    _ = TkLogCore.CouponLogAsync(result);
+                    return new APIResult(result);
+                }
+
+                var account = JdPoolCore.GetOne();
+                if (account == null)
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = "没有匹配账号";
+                    _ = TkLogCore.CouponLogAsync(result);
+                    return new APIResult(result);
+                }
+                result = await JdUnionPlus.JdCouponAsync(account, api, content, result);
+                if (result.success && result.couponAmount == 0)
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = "没有优惠券";
+                }
+            }
+            catch (Exception ex)
+            {
+                if (ex.Message.Contains("A task was canceled"))
+                {
+                    result.success = false;
+                    result.message = "放弃转链";
+                    result.reason = "请求超时";
+                }
+                else
+                {
+                    new LoggerLibrary("unionCoupon", "jd_error")
+                        .Info(ip, oaid)
+                        .Info(content)
+                        .Info(ex.Message, ex.StackTrace)
+                        .Save();
+                    NotifyCore.Notify(new NifyMessage
+                    {
+                        message = $"【转链异常JD】\n{content}\n\n{ex.Message}\n{ex.StackTrace}",
+                        priority = NifyMessagePriority.high,
+                        tags = ["red_circle"]
+                    });
+                    result.success = false;
+                    result.message = "内部错误";
+                    result.reason = "转链接口异常";
+                }
+            }
+            _ = TkLogCore.CouponLogAsync(result);
+            if (!result.success)
+            {
+                return new APIResult(new
+                {
+                    result.success,
+                    result.message,
+                    channel = result?.channel.ToString(),
+                });
+            }
+            return new APIResult(new
+            {
+                result.success,
+                result.message,
+                channel = result?.channel.ToString(),
+                result?.itemId,
+                result?.couponAmount,
+                result?.deeplink_url,
+                result?.pic,
+                result?.couponEffectiveStartTime,
+                result?.couponEffectiveEndTime,
+            });
+        }
+
+    }
+
+}

+ 7 - 72
molilian.core/Core/taoke/UnionParseCore.cs

@@ -36,7 +36,7 @@ namespace molilian.core
 
         public static APIResult WemeetParse(string content, string ip, string oaid)
         {
-            var result = ToolParsePlus.GetFormattedObject(content, ip, oaid);
+            var result = ToolParsePlus.GetFormattedObject(TkChannelEnum.wemeet, content, ip, oaid);
             content = content.UrlDecode();
             result.rawContent = content;
             try
@@ -68,12 +68,13 @@ namespace molilian.core
                 channel = result?.channel.ToString(),
                 result.shortLinkurl,
                 result.deeplink_url,
+                result.itemName,
             }, result.success ? APIResultCodeEnum.OK : APIResultCodeEnum.NotAcceptable);
         }
 
         public static APIResult PanParse(string content, string ip, string oaid)
         {
-            var result = ToolParsePlus.GetFormattedObject(content, ip, oaid);
+            var result = ToolParsePlus.GetFormattedObject(TkChannelEnum.bdpan, content, ip, oaid);
             content = content.UrlDecode();
             result.rawContent = content;
             try
@@ -105,6 +106,7 @@ namespace molilian.core
                 channel = result?.channel.ToString(),
                 result.shortLinkurl,
                 result.deeplink_url,
+                result.itemName,
             }, result.success ? APIResultCodeEnum.OK : APIResultCodeEnum.NotAcceptable);
         }
 
@@ -150,7 +152,7 @@ namespace molilian.core
                     });
                 }
 
-                var account = TkPoolCore.GetOne();
+                var account = TkPoolCore.GetOne(TkPoolCore.TkAction.parse);
                 if (account == null)
                 {
                     result.success = false;
@@ -173,40 +175,6 @@ namespace molilian.core
                 alimama = new AlimamaPlus(account);
                 result = await alimama.UnionParse2Async(content, result);
             }
-            //catch (TaskCanceledException)
-            //{
-            //    result.success = false;
-            //    result.message = "放弃转链";
-            //    result.reason = "请求超时";
-            //}
-            //catch (AggregateException ae)
-            //{
-            //    foreach (var innerEx in ae.InnerExceptions)
-            //    {
-            //        if (innerEx is TaskCanceledException)
-            //        {
-            //            result.success = false;
-            //            result.message = "放弃转链";
-            //            result.reason = "请求超时";
-            //            break;
-            //        }
-            //        new LoggerLibrary("unionParse", "tb_error")
-            //            .Info(ip, oaid)
-            //            .Info(content)
-            //            .Info(innerEx.Message, innerEx.StackTrace)
-            //            .Save();
-
-            //        NotifyCore.Notify(new NifyMessage
-            //        {
-            //            message = $"【转链异常TB】\n{content}\n\n{innerEx.Message}\n{innerEx.StackTrace}",
-            //            priority = NifyMessagePriority.high,
-            //            tags = ["red_circle"]
-            //        });
-            //        result.success = false;
-            //        result.message = "内部错误";
-            //        result.reason = "转链接口异常";
-            //    }
-            //}
             catch (Exception ex)
             {
                 if (ex.Message.Contains("A task was canceled"))
@@ -284,40 +252,6 @@ namespace molilian.core
                 }
                 result = await JdUnionPlus.JdParseAsync(account, content, result);
             }
-            //catch (TaskCanceledException c)
-            //{
-            //    result.success = false;
-            //    result.message = "放弃转链";
-            //    result.reason = "请求超时";
-            //}
-            //catch (AggregateException ae)
-            //{
-            //    foreach (var innerEx in ae.InnerExceptions)
-            //    {
-            //        if (innerEx is TaskCanceledException)
-            //        {
-            //            result.success = false;
-            //            result.message = "放弃转链";
-            //            result.reason = "请求超时";
-            //            break;
-            //        }
-            //        new LoggerLibrary("unionParse", "jd_error")
-            //            .Info(ip, oaid)
-            //            .Info(content)
-            //            .Info(innerEx.Message, innerEx.StackTrace)
-            //            .Save();
-
-            //        NotifyCore.Notify(new NifyMessage
-            //        {
-            //            message = $"【转链异常JD】\n{content}\n\n{innerEx.Message}\n{innerEx.StackTrace}",
-            //            priority = NifyMessagePriority.high,
-            //            tags = ["red_circle"]
-            //        });
-            //        result.success = false;
-            //        result.message = "内部错误";
-            //        result.reason = "转链接口异常";
-            //    }
-            //}
             catch (Exception ex)
             {
                 if (ex.Message.Contains("A task was canceled"))
@@ -354,6 +288,7 @@ namespace molilian.core
                 channel = result?.channel.ToString(),
                 result.channel_type,
                 result.itemId,
+                result.itemName,
                 result.shortLinkurl,
                 result.deeplink_url,
             }, IfExceptional ? APIResultCodeEnum.NotAcceptable : APIResultCodeEnum.OK);
@@ -424,7 +359,7 @@ namespace molilian.core
                 content = result?.rawContent.ToString(),
                 taoToken = result?.taoToken.ToString(),
                 result.channel_type,
-                result.title,
+                result.itemName,
                 result.shortLinkurl,
                 result.deeplink_url,
             }, IfExceptional ? APIResultCodeEnum.NotAcceptable : APIResultCodeEnum.OK);

+ 29 - 0
molilian.core/DTO/UnionCouponDTO.cs

@@ -0,0 +1,29 @@
+
+using dodohold.core;
+
+namespace molilian.core
+{
+    [Table("tk_coupon_logs")]
+    public class UnionCouponDTO
+    {
+        [Key]
+        public int id { get; set; }
+        public TkChannelEnum 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 decimal couponAmount { get; set; } = 0.00M;
+        public string itemId { get; set; } = string.Empty;
+        public string pic { get; set; } = string.Empty;
+        public DateTime create_time { get; set; } = DateTime.Now;
+        public string couponEffectiveStartTime { get; set; } = string.Empty;
+        public string couponEffectiveEndTime { get; set; } = string.Empty;
+    }
+}

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

@@ -23,5 +23,7 @@
         public int api_id { get; set; } = 0;
         public string end_point { get; set; } = string.Empty;
         public bool enable_fake_click { get; set; } = false;
+        public bool enable_parse { get; set; } = false;
+        public bool enable_coupon { get; set; } = false;
     }
 }

+ 1 - 0
molilian.core/DTO/tool/ToolParseDataDTO.cs

@@ -13,6 +13,7 @@
         public string oaid { get; set; } = string.Empty;
         public string shortLinkurl { get; set; } = string.Empty;
         public string deeplink_url { get; set; } = string.Empty;
+        public string itemName { get; set; } = string.Empty;
         public int elapsedTime { get; set; } = 0;
         public DateTime create_time { get; set; } = DateTime.Now;
     }

+ 44 - 0
molilian.core/Plus/Alimama/coupon.cs

@@ -0,0 +1,44 @@
+using System.Text;
+using dodohold.core;
+using System.Text.RegularExpressions;
+using System.Net;
+using System.Security.Cryptography;
+using TencentCloud.Ecm.V20190719.Models;
+
+namespace molilian.core
+{
+    public partial class AlimamaPlus
+    {
+        internal async Task<UnionCouponDTO> UnionCoupon2Async(string content, UnionCouponDTO result)
+        {
+            TkDataDTO data = new();
+            data = await alimamaParseAsync(content, data);
+
+            result.channel = data.channel;
+            result.success = data.success;
+            result.reason = data.reason;
+            result.message = data.success ? "success" : data.message;
+            result.deeplink_url = data.deeplink_url;
+            result.couponAmount = data.couponAmount;
+            result.couponEffectiveStartTime = data.couponEffectiveStartTime;
+            result.couponEffectiveEndTime = data.couponEffectiveEndTime;
+            result.itemId = data.itemId;
+            result.pic = data.pic;
+
+            //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 decimal couponAmount { get; set; } = 0.00M;
+            //public string itemId { get; set; } = string.Empty;
+            //public string pic { get; set; } = string.Empty;
+            //public DateTime create_time { get; set; } = DateTime.Now;
+            return result;
+        }
+
+
+    }
+}

+ 3 - 3
molilian.core/Plus/Alimama/crawler.cs

@@ -39,7 +39,7 @@ namespace molilian.core
             foreach (var account in accounts)
             {
                 int accountId = account.id;
-                string accountName = $"{account.id}";
+                string accountName = $"{TkChannelEnum.tb}_{account.id}";
 
                 int total_count = RedisHelper.Get<int>($":total:{accountName}:{log_date:yyyyMMdd}");
                 if (total_count == 0) accountName = account.name;
@@ -53,7 +53,7 @@ namespace molilian.core
                 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}%";
                 }
@@ -101,7 +101,7 @@ namespace molilian.core
 
             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 });
+                 .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)

+ 16 - 16
molilian.core/Plus/Alimama/orders.cs

@@ -68,12 +68,12 @@ UPDATE tk_report tr
 JOIN (
     SELECT
         accountId,
-        DATE(tkPaidTime) AS date,
+        DATE(tbPaidTime) 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
+    GROUP BY DATE(tbPaidTime), accountId
 ) AS sub
 ON tr.accountId = sub.accountId AND tr.report_date = sub.date
 SET tr.order_ord_amt = sub.order_ord_amt,
@@ -83,10 +83,10 @@ SET tr.order_ord_amt = sub.order_ord_amt,
 UPDATE tk_report tr
 JOIN (
     SELECT
-        accountId, DATE(tkPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, SUM(pubShareFeeForCommission) AS order_ord_tfee
+        accountId, DATE(tbPaidTime) 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
+    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=3
+    GROUP BY DATE(tbPaidTime), 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;";
@@ -96,10 +96,10 @@ SET tr.order_ord_amt = sub.order_ord_amt, tr.order_ord_tfee = sub.order_ord_tfee
 UPDATE tk_report tr
 JOIN (
     SELECT
-        accountId, DATE(tkPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
+        accountId, DATE(tbPaidTime) 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
+    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=12
+    GROUP BY DATE(tbPaidTime), 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;";
@@ -109,10 +109,10 @@ SET tr.order_ord_amt_12 = sub.order_ord_amt, tr.order_ord_tfee_12 = sub.order_or
 UPDATE tk_report tr
 JOIN (
     SELECT
-        accountId, DATE(tkPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
+        accountId, DATE(tbPaidTime) 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
+    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=13
+    GROUP BY DATE(tbPaidTime), 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;";
@@ -122,10 +122,10 @@ SET tr.order_ord_amt_13 = sub.order_ord_amt, tr.order_ord_tfee_13 = sub.order_or
 UPDATE tk_report tr
 JOIN (
     SELECT
-        accountId, DATE(tkPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
+        accountId, DATE(tbPaidTime) 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
+    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=14
+    GROUP BY DATE(tbPaidTime), 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;";
@@ -204,7 +204,7 @@ SET tr.order_ord_amt_14 = sub.order_ord_amt, tr.order_ord_tfee_14 = sub.order_or
                         TkOrderDetailDTO item = order.GetRawText().Convert2Object<TkOrderDetailDTO>();
                         // 处理每个订单数据 
                         item.accountId = _accountId;
-                        item.accountName = _accountName;
+                        item.accountName = _company;
 
                         if (item.modifiedTime > max_modifiedTime) max_modifiedTime = item.modifiedTime;
 
@@ -215,7 +215,7 @@ SET tr.order_ord_amt_14 = sub.order_ord_amt, tr.order_ord_tfee_14 = sub.order_or
                         //进行订单和转链匹配
                         //string mktItemLink = $"https:{item.mktItemLink}";
                         //item.itemId = GetRawItemId(mktItemLink);
-                        if (item.tkStatus == 3 && item.tkPaidTime != DateTime.MinValue) orderTimes.Add(item.tkPaidTime.Date);
+                        if (item.tkStatus == 3 && item.tbPaidTime != DateTime.MinValue) orderTimes.Add(item.tbPaidTime.Date);
                         int? id = conn.Replace(item);
                         if (id != null)
                         {

+ 6 - 2
molilian.core/Plus/Alimama/parse.cs

@@ -77,6 +77,7 @@ namespace molilian.core
             result.link_type = result.link_type;
             return result;
         }
+
         public async Task<TkDataDTO> UnionParseAsync(string content, TkDataDTO result)
         {
             (result.success, result.content, result.link_type, result.shortLinkurl) = InternalTextProcessing(content);
@@ -100,9 +101,11 @@ namespace molilian.core
                 result = await alimamaParseAsync(result.content, result);
                 if (string.IsNullOrEmpty(result.itemName)) result.itemName = GetTitle(content);
             }
-
+            if (string.IsNullOrEmpty(result.itemName) || result.link_type == LinkTypeEnum.profile)
+            {
+                result.itemName = "点击打开淘宝APP";
+            }
             result.link_type = result.link_type;
-
             return result;
         }
 
@@ -269,6 +272,7 @@ namespace molilian.core
                 couponAmount = 0,
                 taoToken = string.Empty,
                 elapsedTime = 0,
+                itemName = "点击打开淘宝APP",
                 shortLinkurl = shortLinkurl,
                 deeplink_url = deeplink_url,
                 create_time = DateTime.Now,

+ 12 - 4
molilian.core/Plus/Alimama/parse_2.cs

@@ -507,8 +507,8 @@ namespace molilian.core
                 string couponLinkTaoToken = root.PathRead("data.couponLinkTaoToken", string.Empty);
                 string couponShortLinkUrl = root.PathRead("data.couponShortLinkUrl", string.Empty);
                 decimal couponAmount = root.PathRead<decimal>("data.couponAmount", 0);
-                string couponEffectiveEndTime = root.PathRead("data.couponEffectiveEndTime", string.Empty);
-                string couponEffectiveStartTime = root.PathRead("data.couponEffectiveStartTime", string.Empty);
+                long couponEffectiveEndTime = root.PathRead<long>("data.couponEffectiveEndTime", 0);
+                long couponEffectiveStartTime = root.PathRead<long>("data.couponEffectiveStartTime", 0);
 
                 string itemId = root.PathRead("data.itemId", string.Empty);
                 string itemName = root.PathRead("data.itemName", string.Empty);
@@ -610,8 +610,16 @@ namespace molilian.core
                 result.message = message;
                 result.content = content;
                 result.couponAmount = couponAmount;
-                result.couponEffectiveEndTime = couponEffectiveEndTime;
-                result.couponEffectiveStartTime = couponEffectiveStartTime;
+
+                if (couponEffectiveEndTime > 0)
+                {
+                    result.couponEffectiveEndTime = couponEffectiveEndTime.Convert2Datetime().ToString("yyyy-MM-dd HH:mm:ss");
+                }
+                if (couponEffectiveStartTime > 0)
+                {
+                    result.couponEffectiveStartTime = couponEffectiveStartTime.Convert2Datetime().ToString("yyyy-MM-dd HH:mm:ss");
+                }
+
                 result.taoToken = taoToken;
                 result.shortLinkurl = shortLinkurl;
                 result.deeplink_url = deeplink_url;

+ 29 - 13
molilian.core/Plus/DataokePlus.cs

@@ -3,6 +3,8 @@ using Dataoke;
 using TencentCloud.Scf.V20180416.Models;
 using System.Text.RegularExpressions;
 using TencentCloud.Teo.V20220901.Models;
+using static dodohold.core.ZTOExpress.CreateOrderArgs;
+using System.Xml.Linq;
 
 namespace molilian.core
 {
@@ -15,7 +17,7 @@ namespace molilian.core
     }
     public class GoodsDetailDTO
     {
-        public int actualPrice { get; set; }
+        public decimal actualPrice { get; set; }
         public int cid1 { get; set; }
         public string cid1Name { get; set; }
         public int cid2 { get; set; }
@@ -23,11 +25,11 @@ namespace molilian.core
         public int cid3 { get; set; }
         public string cid3Name { get; set; }
         public int comments { get; set; }
-        public double commission { get; set; }
+        public decimal commission { get; set; }
         public string commissionEndTime { get; set; }
-        public double commissionShare { get; set; }
+        public decimal commissionShare { get; set; }
         public string commissionStartTime { get; set; }
-        public int couponAmount { get; set; }
+        public decimal couponAmount { get; set; }
         public string couponConditions { get; set; }
         public string couponEndTime { get; set; }
         public string couponLink { get; set; }
@@ -50,17 +52,15 @@ namespace molilian.core
         public string itemId { get; set; }
         public int lowest { get; set; }
         public string materialUrl { get; set; }
-        public int originPrice { get; set; }
+        public decimal originPrice { get; set; }
         public string picMain { get; set; }
-        public double plusCommissionShare { get; set; }
+        public decimal plusCommissionShare { get; set; }
         public string productIntro { get; set; }
-        public object promotionLabelList { get; set; }
         public int shopId { get; set; }
         public string shopName { get; set; }
         public long skuId { get; set; }
         public string skuName { get; set; }
         public string[] smallImages { get; set; }
-        public object[] videoUrlList { get; set; }
     }
     public partial class DataokePlus
     {
@@ -72,7 +72,7 @@ namespace molilian.core
             _app_key = app_key;
             _app_secret = app_secret;
         }
-        public string JDParse(string unionId, string materialId)
+        public string JDParse(string unionId, string materialId, string couponUrl = null)
         {
             string version = "v1.0.0";
             string api = "https://openapi.dataoke.com/api/dels/jd/kit/promotion-union-convert";
@@ -80,6 +80,8 @@ namespace molilian.core
             ApiParameters apiParameters = new();
             apiParameters.Add("unionId", unionId);
             apiParameters.Add("materialId", materialId);
+            if (!string.IsNullOrEmpty(couponUrl)) apiParameters.Add("couponUrl", couponUrl);
+
             var log = new LoggerLibrary("dataoke", "promotion-union-convert").Info(unionId, materialId);
             string body = app.Get(api, version, apiParameters);
             log.Info(body).Save();
@@ -90,6 +92,7 @@ namespace molilian.core
         public GoodsDetailDTO? GetDetails(params string[] skuIds)
         {
             GoodsDetailDTO? result = null;
+            string body = string.Empty;
             try
             {
                 string version = "v1.0.0";
@@ -99,8 +102,8 @@ namespace molilian.core
                 apiParameters.Add("skuIds", string.Join(',', skuIds));
 
 
-                var log = new LoggerLibrary("dataoke", "parseUrl").Info(string.Join(',', skuIds));
-                string body = app.Get(api, version, apiParameters);
+                var log = new LoggerLibrary("dataoke", "details").Info(string.Join(',', skuIds));
+                body = app.Get(api, version, apiParameters);
                 log.Info(body).Save();
 
 
@@ -108,11 +111,24 @@ namespace molilian.core
                 int code = root.Read<int>("code", -1);
                 if (code == 0)
                 {
-                    var _goods = root.ElementRead("data")[0].Convert2Json();
+                    var _goods = root.ElementRead("data")[0].GetRawText();
                     result = _goods.Convert2Object<GoodsDetailDTO>();
                 }
             }
-            catch (Exception e) { }
+            catch (Exception ex)
+            {
+                new LoggerLibrary("dtk_error", "fail")
+                    .Info(string.Join(',', skuIds), body)
+                    .Info(ex.Message, ex.StackTrace)
+                    .Save();
+
+                NotifyCore.Notify(new NifyMessage
+                {
+                    message = $"【大淘客异常】\n\n{ex.Message}\n{ex.StackTrace}",
+                    priority = NifyMessagePriority.high,
+                    tags = ["red_circle"]
+                });
+            }
 
             return result;
         }

+ 1 - 0
molilian.core/Plus/DyUnion/DyUnionPlus.cs

@@ -47,6 +47,7 @@ namespace molilian.core
                 elapsedTime = 0,
                 shortLinkurl = shortLinkurl,
                 deeplink_url = deeplink_url,
+                itemName = "点击打开抖音APP",
                 create_time = DateTime.Now,
             };
         }

+ 1 - 2
molilian.core/Plus/JDUnion/JdUnionPlus.cs

@@ -80,6 +80,7 @@ namespace molilian.core
                 ip = ip,
                 oaid = oaid,
                 elapsedTime = 0,
+                itemName = "点击打开京东APP",
                 shortLinkurl = shortLinkurl,
                 deeplink_url = deeplink_url,
                 create_time = DateTime.Now,
@@ -210,8 +211,6 @@ namespace molilian.core
             url = out_url;
             result.itemId = itemId;
 
-
-
             if (result.link_type == LinkTypeEnum.other_aff)
             {
                 result.success = false;

+ 0 - 1
molilian.core/Plus/JDUnion/base.cs

@@ -133,6 +133,5 @@ namespace molilian.core
             }
         }
 
-
     }
 }

+ 86 - 0
molilian.core/Plus/JDUnion/coupon.cs

@@ -0,0 +1,86 @@
+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 Dataoke;
+using System.Text.RegularExpressions;
+using Org.BouncyCastle.Ocsp;
+using System.Diagnostics;
+using TencentCloud.Fmu.V20191213.Models;
+using Microsoft.VisualBasic;
+using System.Text.Json;
+using static System.Runtime.InteropServices.JavaScript.JSType;
+using System.Security.Cryptography;
+using Google.Protobuf.WellKnownTypes;
+using Microsoft.Extensions.FileSystemGlobbing.Internal;
+
+
+namespace molilian.core
+{
+    public partial class JdUnionPlus
+    {
+        internal static async Task<UnionCouponDTO> JdCouponAsync(JdPoolDTO account, DataokeDTO api, string content, UnionCouponDTO result)
+        {
+
+            //result.channel = data.channel;
+            //result.success = data.success;
+            //result.reason = data.reason;
+            //result.message = data.message;
+            //result.deeplink_url = data.deeplink_url;
+            //result.couponAmount = data.couponAmount;
+            //result.itemId = data.itemId;
+            //result.pic = data.pic;
+
+
+            string url = GetLink(content);
+            string itemId = GetItemId(url);
+
+            var dtkResult = DataokeCore.GetCoupon(api, account, url, itemId);
+            if (dtkResult == null)
+            {
+                result.success = false;
+                result.message = "放弃转链";
+                result.reason = "转链失败";
+                return result;
+            }
+
+            if (dtkResult.couponAmount == 0)
+            {
+                result.success = false;
+                result.message = "放弃转链";
+                result.reason = "没有优惠券";
+                return result;
+            }
+
+            result.channel = TkChannelEnum.jd;
+            result.success = true;
+            result.message = "success";
+            result.couponAmount = dtkResult.couponAmount;
+            result.deeplink_url = GetDeeplink(dtkResult.couponLink);
+            result.couponAmount = dtkResult.couponAmount;
+            result.itemId = dtkResult.skuId.ToString();
+            result.couponEffectiveStartTime = dtkResult.couponStartTime;
+            result.couponEffectiveEndTime = dtkResult.couponEndTime;
+            result.pic = dtkResult.picMain;
+
+            //2202076
+            //https://item.jd.com/2202076.html
+
+            //https://coupon.m.jd.com/coupons/show.action?linkKey=AAROH_xIpeffAs_-naABEFoenWURVae-88AobuUWD3IOE8_N_oOkCsUv63B3gneyzoFQPJsQBfdvIG52TqcOEuYv1tVKLg",
+
+            //result.channel = data.channel;
+            //result.success = data.success;
+            //result.reason = data.reason;
+            //result.message = data.message;
+            //result.deeplink_url = data.deeplink_url;
+            //result.couponAmount = data.couponAmount;
+            //result.itemId = data.itemId;
+            //result.pic = data.pic;
+            return result;
+        }
+    }
+}

+ 15 - 2
molilian.core/Plus/Tool/ToolParsePlus.cs

@@ -40,8 +40,20 @@ namespace molilian.core
             return string.Empty;
         }
 
-        public static ToolParseDataDTO GetFormattedObject(string content, string ip = "", string oaid = "")
+        public static ToolParseDataDTO GetFormattedObject(TkChannelEnum type, string content, string ip = "", string oaid = "")
         {
+            string itemName = string.Empty;
+            switch (type)
+            {
+                case TkChannelEnum.bdpan:
+                    itemName = "打开百度网盘";
+                    break;
+                case TkChannelEnum.wemeet:
+                    itemName = "加入腾讯会议";
+                    break;
+
+            }
+
             return new ToolParseDataDTO()
             {
                 message = string.Empty,
@@ -51,6 +63,7 @@ namespace molilian.core
                 oaid = oaid,
                 elapsedTime = 0,
                 create_time = DateTime.Now,
+                itemName = itemName,
             };
         }
 
@@ -62,7 +75,7 @@ namespace molilian.core
 
             string result = string.Empty;
             string linkPattern = @"(https://pan\.baidu\.com/s/[A-Za-z0-9?\-=]+)";
-            string codePattern = @"提取码:([A-Za-z0-9]{4})";
+            string codePattern = @"提取码[:]([A-Za-z0-9]{4})";
             Regex linkRegex = new(linkPattern);
             Regex codeRegex = new(codePattern);
 

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio