Browse Source

0903 pdd转链oauth授权模式

dodo hold 2 years ago
parent
commit
701d561a5e

+ 1 - 1
molilian.api/Controllers/admin/PddUnionController.cs

@@ -35,7 +35,7 @@ namespace molilian.api.Controllers
             cookie = cookie.Replace("\r", "").Replace("\n", "").Trim();
             if (!cookie.EndsWith(";")) cookie += ";";
 
-            var accountId = PddPoolCore.UpdateCookies(cookie, user_agent);
+            var accountId = await PddPoolCore.UpdateCookies(cookie, user_agent);
             bool success = accountId > 0;
             if (success)
             {

+ 124 - 0
molilian.api/Controllers/public/JDTaskController.cs

@@ -0,0 +1,124 @@
+using molilian.core;
+using dodohold.core;
+using Microsoft.AspNetCore.Mvc;
+using Org.BouncyCastle.Ocsp;
+using System.Text.Json;
+using System.Runtime.InteropServices;
+using System.Net;
+using System.Threading.Channels;
+using TencentCloud.Cdwch.V20200915.Models;
+using COSXML.Network;
+using System.Security.Cryptography;
+using System.Threading;
+using TencentCloud.Batch.V20170312.Models;
+
+namespace molilian.api.Controllers
+{
+    [ApiController]
+    [Route("[controller]_70160bd632/[action]")]
+    public class JDTaskController : ControllerBase
+    {
+
+        protected IHttpContextAccessor _accessor;
+        public JDTaskController(IHttpContextAccessor accessor)
+        {
+            _accessor = accessor;
+        }
+
+
+        [HttpGet]
+        public async Task<ActionResult> GetHistoryOrders(int id, int sleep, int h = 0)
+        {
+            var list = JdPoolCore.List();
+            if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
+
+            string message = string.Empty;
+            int total = 0;
+            foreach (var account in list)
+            {
+                if (id != 0 && id != account.id) continue;
+                if (account.is_hide) continue;
+                try
+                {
+                    DateTime endTime = DateTime.Now.Date;
+                    DateTime startTime = endTime.AddDays(-90);
+
+                    var plus = new JdUnionPlus(account);
+
+                    //for (int i = 89; i >= 0; i--)
+                    //{
+                    //    DateTime dayStartTime = startTime.AddDays(i);
+                    //    DateTime dayEndTime = dayStartTime.AddDays(1);
+                    //    total += await plus.GetHistoryOrders(sleep, dayStartTime, dayEndTime);
+                    //}
+
+                    if (h == 1)
+                    {
+                        for (int i = 24 * 90 - 1; i >= 0; i--)
+                        {
+                            DateTime hourStartTime = startTime.AddHours(i);
+                            DateTime hourEndTime = hourStartTime.AddHours(1);
+                            total += await plus.GetHistoryOrders(sleep, hourStartTime, hourEndTime);
+                        }
+                    }
+                    else
+                    {
+                        for (int i = 89; i >= 0; i--)
+                        {
+                            DateTime dayStartTime = startTime.AddDays(i);
+                            DateTime dayEndTime = dayStartTime.AddDays(1);
+                            total += await plus.GetHistoryOrders(sleep, dayStartTime, dayEndTime);
+                        }
+                    }
+
+                    //total += await plus.GetHistoryOrders(sleep, startTime, endTime);
+                }
+                catch (Exception ex)
+                {
+                    message = $"【JD历史订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
+                    NotifyCore.Notify(new NifyMessage
+                    {
+                        message = message,
+                        priority = NifyMessagePriority.high,
+                        tags = ["red_circle"]
+                    });
+                    continue;
+                }
+            }
+            return new APIResult(new { success = true, message = "ok", total });
+        }
+
+        [HttpGet]
+        public async Task<ActionResult> GetIncyOrders(int sleep = 2000)
+        {
+            var list = JdPoolCore.List();
+            if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
+            string message = string.Empty;
+            int total = 0;
+            foreach (var account in list)
+            {
+                if (!account.enable_sync_order) continue;
+
+                try
+                {
+                    var plus = new JdUnionPlus(account);
+                    total += await plus.GetIncyOrders(sleep);
+                }
+                catch (Exception ex)
+                {
+                    message = $"【JD新增订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
+                    NotifyCore.Notify(new NifyMessage
+                    {
+                        message = message,
+                        priority = NifyMessagePriority.high,
+                        tags = ["red_circle"]
+                    });
+                    continue;
+                }
+            }
+            return new APIResult(new { success = true, message = "ok", total });
+        }
+
+
+    }
+}

File diff suppressed because it is too large
+ 0 - 0
molilian.api/Properties/PublishProfiles/https___ccr.ccs.tencentyun.com_shaobin.pubxml.user


+ 190 - 185
molilian.core/Core/API/ApiReportCore.cs

@@ -106,213 +106,218 @@ namespace molilian.core
                 }
             }
 
-            //List<dynamic> data = list.Select(e => new
-            //{
-            //    report_date = e.report_date.ToString("yyyy-MM-dd"),
-            //    type = e.data_type,
-            //    e.uclk_uv,
-            //    e.uclk_pv,
-            //    e.pay_ord_num,
-            //    e.order_ord_num,
-            //    e.pay_ord_amt,
-            //    e.pay_tk_disp_tfee,
-            //    e.pay_ord_uv,
-            //    e.eff_ord_num,
-            //    e.eff_ord_amt,
-            //    e.eff_tk_disp_tfee,
-            //    e.total_count,
-            //    //e.abandon_count,
-            //    e.success_count,
-            //    e.req_other_aff_num,
-            //    e.req_goods_num,
-            //    e.req_live_num,
-            //    e.req_video_num,
-            //    e.req_shop_num,
-            //    e.req_base_num,
-            //    e.req_note_num,
-            //    e.resp_deeplink_num
-            //}).ToList<dynamic>();
-
-
-
-            List<dynamic> data = list.SelectMany(e =>
+            List<dynamic> data;
+
+
+
+            if (distributiontype == 0)
             {
-                var results = new List<dynamic>();
 
-                if (distributiontype == 0 || distributiontype == 1) // 全分类或 goods
+                data = list.Select(e => new
                 {
-                    results.Add(new
-                    {
-                        //metric_type = "req_goods_num",
-                        //metric_value = e.req_goods_num,
-                        report_date = e.report_date.ToString("yyyy-MM-dd"),
-                        type = e.data_type,
-                        e.uclk_uv,
-                        e.uclk_pv,
-                        e.pay_ord_num,
-                        e.order_ord_num,
-                        e.pay_ord_amt,
-                        e.pay_tk_disp_tfee,
-                        e.pay_ord_uv,
-                        e.eff_ord_num,
-                        e.eff_ord_amt,
-                        e.eff_tk_disp_tfee,
-                        e.total_count,
-                        e.success_count,
-                        e.req_goods_num,
-                        e.resp_deeplink_num
-                    });
-                }
+                    report_date = e.report_date.ToString("yyyy-MM-dd"),
+                    type = e.data_type,
+                    e.uclk_uv,
+                    e.uclk_pv,
+                    e.pay_ord_num,
+                    e.order_ord_num,
+                    pay_ord_am = e.pay_ord_amt * 100,
+                    pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
+                    e.pay_ord_uv,
+                    e.eff_ord_num,
+                    eff_ord_amt = e.eff_ord_amt * 100,
+                    eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
+                    e.total_count,
+                    //e.abandon_count,
+                    e.success_count,
+                    e.req_other_aff_num,
+                    e.req_goods_num,
+                    e.req_live_num,
+                    e.req_video_num,
+                    e.req_shop_num,
+                    e.req_base_num,
+                    e.req_note_num,
+                    e.resp_deeplink_num
+                }).ToList<dynamic>();
 
-                if (distributiontype == 0 || distributiontype == 2) // 全分类或 live
-                {
-                    results.Add(new
-                    {
-                        report_date = e.report_date.ToString("yyyy-MM-dd"),
-                        type = e.data_type,
-                        e.uclk_uv,
-                        e.uclk_pv,
-                        e.pay_ord_num,
-                        e.order_ord_num,
-                        e.pay_ord_amt,
-                        e.pay_tk_disp_tfee,
-                        e.pay_ord_uv,
-                        e.eff_ord_num,
-                        e.eff_ord_amt,
-                        e.eff_tk_disp_tfee,
-                        e.total_count,
-                        e.success_count,
-                        e.req_live_num,
-                        e.resp_deeplink_num
-                    });
-                }
+            }
+            else
+            {
 
-                if (distributiontype == 0 || distributiontype == 3) // 全分类或 video
+                data = list.SelectMany(e =>
                 {
-                    results.Add(new
-                    {
-                        report_date = e.report_date.ToString("yyyy-MM-dd"),
-                        type = e.data_type,
-                        e.uclk_uv,
-                        e.uclk_pv,
-                        e.pay_ord_num,
-                        e.order_ord_num,
-                        e.pay_ord_amt,
-                        e.pay_tk_disp_tfee,
-                        e.pay_ord_uv,
-                        e.eff_ord_num,
-                        e.eff_ord_amt,
-                        e.eff_tk_disp_tfee,
-                        e.total_count,
-                        e.success_count,
-                        e.req_video_num,
-                        e.resp_deeplink_num
-                    });
-                }
+                    var results = new List<dynamic>();
 
-                if (distributiontype == 0 || distributiontype == 4) // 全分类或 req_shop_num
-                {
-                    results.Add(new
+                    if (distributiontype == -1 || distributiontype == 1) // 全分类或 goods
                     {
-                        report_date = e.report_date.ToString("yyyy-MM-dd"),
-                        type = e.data_type,
-                        e.uclk_uv,
-                        e.uclk_pv,
-                        e.pay_ord_num,
-                        e.order_ord_num,
-                        e.pay_ord_amt,
-                        e.pay_tk_disp_tfee,
-                        e.pay_ord_uv,
-                        e.eff_ord_num,
-                        e.eff_ord_amt,
-                        e.eff_tk_disp_tfee,
-                        e.total_count,
-                        e.success_count,
-                        e.req_shop_num,
-                        e.resp_deeplink_num
-                    });
-                }
+                        results.Add(new
+                        {
+                            //metric_type = "req_goods_num",
+                            //metric_value = e.req_goods_num,
+                            report_date = e.report_date.ToString("yyyy-MM-dd"),
+                            type = e.data_type,
+                            e.uclk_uv,
+                            e.uclk_pv,
+                            e.pay_ord_num,
+                            e.order_ord_num,
+                            pay_ord_am = e.pay_ord_amt * 100,
+                            pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
+                            e.pay_ord_uv,
+                            e.eff_ord_num,
+                            eff_ord_amt = e.eff_ord_amt * 100,
+                            eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
+                            e.total_count,
+                            e.success_count,
+                            e.req_goods_num,
+                            e.resp_deeplink_num
+                        });
+                    }
 
-                if (distributiontype == 0 || distributiontype == 5) // 全分类或 req_base_num
-                {
-                    results.Add(new
+                    if (distributiontype == -1 || distributiontype == 2) // 全分类或 live
                     {
-                        report_date = e.report_date.ToString("yyyy-MM-dd"),
-                        type = e.data_type,
-                        e.uclk_uv,
-                        e.uclk_pv,
-                        e.pay_ord_num,
-                        e.order_ord_num,
-                        e.pay_ord_amt,
-                        e.pay_tk_disp_tfee,
-                        e.pay_ord_uv,
-                        e.eff_ord_num,
-                        e.eff_ord_amt,
-                        e.eff_tk_disp_tfee,
-                        e.total_count,
-                        e.success_count,
-                        e.req_base_num,
-                        e.resp_deeplink_num
-                    });
-                }
+                        results.Add(new
+                        {
+                            report_date = e.report_date.ToString("yyyy-MM-dd"),
+                            type = e.data_type,
+                            e.uclk_uv,
+                            e.uclk_pv,
+                            e.pay_ord_num,
+                            e.order_ord_num,
+                            pay_ord_am = e.pay_ord_amt * 100,
+                            pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
+                            e.pay_ord_uv,
+                            e.eff_ord_num,
+                            eff_ord_amt = e.eff_ord_amt * 100,
+                            eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
+                            e.total_count,
+                            e.success_count,
+                            e.req_live_num,
+                            e.resp_deeplink_num
+                        });
+                    }
 
+                    if (distributiontype == -1 || distributiontype == 3) // 全分类或 video
+                    {
+                        results.Add(new
+                        {
+                            report_date = e.report_date.ToString("yyyy-MM-dd"),
+                            type = e.data_type,
+                            e.uclk_uv,
+                            e.uclk_pv,
+                            e.pay_ord_num,
+                            e.order_ord_num,
+                            pay_ord_am = e.pay_ord_amt * 100,
+                            pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
+                            e.pay_ord_uv,
+                            e.eff_ord_num,
+                            eff_ord_amt = e.eff_ord_amt * 100,
+                            eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
+                            e.total_count,
+                            e.success_count,
+                            e.req_video_num,
+                            e.resp_deeplink_num
+                        });
+                    }
 
-                if (distributiontype == 0 || distributiontype == 6) // 全分类或 req_other_aff_num
-                {
-                    results.Add(new
+                    if (distributiontype == -1 || distributiontype == 4) // 全分类或 req_shop_num
                     {
-                        report_date = e.report_date.ToString("yyyy-MM-dd"),
-                        type = e.data_type,
-                        e.uclk_uv,
-                        e.uclk_pv,
-                        e.pay_ord_num,
-                        e.order_ord_num,
-                        e.pay_ord_amt,
-                        e.pay_tk_disp_tfee,
-                        e.pay_ord_uv,
-                        e.eff_ord_num,
-                        e.eff_ord_amt,
-                        e.eff_tk_disp_tfee,
-                        e.total_count,
-                        e.success_count,
-                        e.req_other_aff_num,
-                        e.resp_deeplink_num
-                    });
-                }
+                        results.Add(new
+                        {
+                            report_date = e.report_date.ToString("yyyy-MM-dd"),
+                            type = e.data_type,
+                            e.uclk_uv,
+                            e.uclk_pv,
+                            e.pay_ord_num,
+                            e.order_ord_num,
+                            pay_ord_am = e.pay_ord_amt * 100,
+                            pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
+                            e.pay_ord_uv,
+                            e.eff_ord_num,
+                            eff_ord_amt = e.eff_ord_amt * 100,
+                            eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
+                            e.total_count,
+                            e.success_count,
+                            e.req_shop_num,
+                            e.resp_deeplink_num
+                        });
+                    }
 
+                    if (distributiontype == -1 || distributiontype == 5) // 全分类或 req_base_num
+                    {
+                        results.Add(new
+                        {
+                            report_date = e.report_date.ToString("yyyy-MM-dd"),
+                            type = e.data_type,
+                            e.uclk_uv,
+                            e.uclk_pv,
+                            e.pay_ord_num,
+                            e.order_ord_num,
+                            pay_ord_am = e.pay_ord_amt * 100,
+                            pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
+                            e.pay_ord_uv,
+                            e.eff_ord_num,
+                            eff_ord_amt = e.eff_ord_amt * 100,
+                            eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
+                            e.total_count,
+                            e.success_count,
+                            e.req_base_num,
+                            e.resp_deeplink_num
+                        });
+                    }
 
 
-                if (distributiontype == 0 || distributiontype == 7) // 全分类或 req_note_num
-                {
-                    results.Add(new
+                    if (distributiontype == -1 || distributiontype == 6) // 全分类或 req_other_aff_num
                     {
-                        report_date = e.report_date.ToString("yyyy-MM-dd"),
-                        type = e.data_type,
-                        e.uclk_uv,
-                        e.uclk_pv,
-                        e.pay_ord_num,
-                        e.order_ord_num,
-                        e.pay_ord_amt,
-                        e.pay_tk_disp_tfee,
-                        e.pay_ord_uv,
-                        e.eff_ord_num,
-                        e.eff_ord_amt,
-                        e.eff_tk_disp_tfee,
-                        e.total_count,
-                        e.success_count,
-                        e.req_note_num,
-                        e.resp_deeplink_num
-                    });
-                }
-
+                        results.Add(new
+                        {
+                            report_date = e.report_date.ToString("yyyy-MM-dd"),
+                            type = e.data_type,
+                            e.uclk_uv,
+                            e.uclk_pv,
+                            e.pay_ord_num,
+                            e.order_ord_num,
+                            pay_ord_am = e.pay_ord_amt * 100,
+                            pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
+                            e.pay_ord_uv,
+                            e.eff_ord_num,
+                            eff_ord_amt = e.eff_ord_amt * 100,
+                            eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
+                            e.total_count,
+                            e.success_count,
+                            e.req_other_aff_num,
+                            e.resp_deeplink_num
+                        });
+                    }
 
-                return results;
-            }).ToList<dynamic>();
 
-            return data;
 
+                    if (distributiontype == -1 || distributiontype == 7) // 全分类或 req_note_num
+                    {
+                        results.Add(new
+                        {
+                            report_date = e.report_date.ToString("yyyy-MM-dd"),
+                            type = e.data_type,
+                            e.uclk_uv,
+                            e.uclk_pv,
+                            e.pay_ord_num,
+                            e.order_ord_num,
+                            pay_ord_am = e.pay_ord_amt * 100,
+                            pay_tk_disp_tfee = e.pay_tk_disp_tfee * 100,
+                            e.pay_ord_uv,
+                            e.eff_ord_num,
+                            eff_ord_amt = e.eff_ord_amt * 100,
+                            eff_tk_disp_tfee = e.eff_tk_disp_tfee * 100,
+                            e.total_count,
+                            e.success_count,
+                            e.req_note_num,
+                            e.resp_deeplink_num
+                        });
+                    }
 
 
+                    return results;
+                }).ToList<dynamic>();
+            }
             return data;
         }
 

+ 1 - 0
molilian.core/Core/cps/UnionCpsCore.cs

@@ -107,6 +107,7 @@ namespace molilian.core
             {
                 result.success,
                 result.message,
+                result.title,
                 result.deeplink_url,
                 result.token,
                 result.channel,

+ 37 - 10
molilian.core/Core/pdd/PddPoolCore.cs

@@ -243,18 +243,44 @@ namespace molilian.core
             NotifyCore.AnPushNotify("没账号", $"【多多】没有匹配账号");
         }
 
+        internal static async Task<JsonElement> GetUserInfo(string cookies)
+        {
+            JsonElement result = default;
+            try
+            {
+                string url = "https://jinbao.pinduoduo.com/network/api/account/userInfo";
+                WebClientUtility client = new WebClientUtility();
+                client.Post("{}");
+                client.SetCookies(cookies);
+                client.SetContentType("application/json");
+                var response = await client.RequestAsync(url, "POST");
+                var body = response.Body();
+                result = body.Convert2JsonElement();
+            }
+            catch (Exception ex)
+            {
+            }
+            return result;
+        }
+
+
 
 
-        public static int UpdateCookies(string cookies, string user_agent)
+        public static async Task<int> UpdateCookies(string cookies, string user_agent)
         {
             if (string.IsNullOrEmpty(cookies)) return 0;
-            string pin = cookies.GetContentPart("pin=", ";");
-            pin = pin.UrlDecode();
+            var userinfo = await GetUserInfo(cookies);
+            if (userinfo.ValueKind != JsonValueKind.Object) return 0;
+
+            int duoId = userinfo.PathRead<int>("result.duoId", 0);
+            string company = userinfo.PathRead<string>("result.mobile", string.Empty);
+            string lastPid = userinfo.PathRead<string>("result.lastPid", string.Empty);
 
-            string company = pin;
             int accountId = 0;
-            if (string.IsNullOrEmpty(pin)) return 0;
-            var exist = new DBContext.Table("pdd_pool").Get<JdPoolDTO>("pin=@pin", new { pin });
+            if (duoId == 0) return 0;
+
+
+            var exist = new DBContext.Table("pdd_pool").Get<JdPoolDTO>("duoId=@duoId", new { duoId });
             if (exist != null)
             {
                 var status = exist.status;
@@ -262,7 +288,7 @@ namespace molilian.core
                 accountId = exist.id;
                 if (work_mode == JdUnionWorkMode.Crawler) status = true;
                 new DBContext.Table("pdd_pool")
-                   .Add("pin", pin)
+                   .Add("duoId", duoId)
                    .Add("cookies", cookies)
                    .Add("user_agent", user_agent)
                    .Add("status", status)
@@ -275,12 +301,13 @@ namespace molilian.core
             else
             {
                 accountId = new DBContext.Table("pdd_pool")
-                    .Add("pin", pin)
-                    .Add("name", pin)
-                    .Add("company", pin)
+                    .Add("duoId", duoId)
+                    .Add("name", company)
+                    .Add("company", company)
                     .Add("description", "由cookies上报创建此记录")
                     .Add("cookies", cookies)
                     .Add("user_agent", user_agent)
+                    .Add("pid", lastPid)
                     .Add("create_time", DateTime.Now)
                     .Add("last_time", DateTime.Now)
                     .Add("login_time", DateTime.Now)

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

@@ -119,8 +119,17 @@ namespace molilian.core
                     list = new DBContext.Table("tk_pool")
                         .Where("status=@status", new { status = 1 })
                         .Select<TkPoolDTO>();
+#if DEBUG
+                    list = new DBContext.Table("tk_pool")
+                        .Where("id=@id", new { id=3 })
+                        .Select<TkPoolDTO>();
+#else
+                    list = new DBContext.Table("tk_pool")
+                        .Where("status=@status", new { status = 1 })
+                        .Select<TkPoolDTO>();
                     if (list == null) return default;
                     RedisHelper.Set(cache_key, list, 30 * 86400);
+#endif
                 }
             }
             _cached = list;

+ 70 - 0
molilian.core/DTO/jd/JdOrderDetailsDTO.cs

@@ -0,0 +1,70 @@
+using dodohold.core;
+using System.Runtime.CompilerServices;
+using System.Text.Json.Serialization;
+
+namespace molilian.core
+{
+    [Table("jd_order_details")]
+    public class JdOrderDetailsDTO
+    {
+        [Key]
+        public int id { get; set; }
+        public int accountId { get; set; }
+        public string accountName { get; set; }
+        public decimal actualCommission { get; set; } = 0;
+        public decimal actualCosPrice { get; set; } = 0;
+        public decimal actualFee { get; set; } = 0;
+        public long adId { get; set; } = 0;
+        public string adName { get; set; } = string.Empty;
+        public string balanceExt { get; set; } = string.Empty;
+        public long channelId { get; set; } = 0;
+        public decimal commissionRate { get; set; } = 0;
+        public long cpActId { get; set; } = 0;
+        public string cpActName { get; set; } = string.Empty;
+        public decimal estimateCommission { get; set; } = 0;
+        public decimal estimateCosPrice { get; set; } = 0;
+        public decimal estimateFee { get; set; } = 0;
+        public string exchangeRateAndUnit { get; set; } = string.Empty;
+        public decimal finalRate { get; set; } = 0;
+
+        [JsonConverter(typeof(DateTimeConverterUsingDateTimeParse))]
+        public DateTime finishTime { get; set; } = DateTime.MinValue;
+        public string jingfenValidCodeMsg { get; set; } = string.Empty;
+        public long orderId { get; set; } = 0;
+        public int orderStatus { get; set; } = 0;
+
+        [JsonConverter(typeof(DateTimeConverterUsingDateTimeParse))]
+        public DateTime orderTime { get; set; } = DateTime.MinValue;
+        public long parentId { get; set; } = 0;
+        public int payMonth { get; set; } = 0;
+        public decimal payPrice { get; set; } = 0;
+        public string pid { get; set; } = string.Empty;
+        public int plus { get; set; } = 0;
+        public decimal price { get; set; } = 0;
+        public decimal proPriceAmount { get; set; }
+        public string rateMsg { get; set; } = string.Empty;
+        public int sellingFlag { get; set; } = 0;
+        public long siteId { get; set; } = 0;
+        public int skuFrozenNum { get; set; } = 0;
+        public long skuId { get; set; } = 0;
+        public string skuImgUrl { get; set; } = string.Empty;
+        public string skuName { get; set; } = string.Empty;
+        public int skuNum { get; set; } = 0;
+        public int skuReturnNum { get; set; } = 0;
+        public string skuShopName { get; set; } = string.Empty;
+        public long spId { get; set; } = 0;
+        public string spName { get; set; } = string.Empty;
+        public int traceType { get; set; } = 0;
+        public long unionId { get; set; } = 0;
+        public int unionRole { get; set; } = 0;
+        public string unionTag { get; set; } = string.Empty;
+        public string validCodeMsg { get; set; } = string.Empty;
+        public decimal SettleAmount { get; set; } = 0;
+        public DateTime settle_time { get; set; } = DateTime.MinValue;
+
+        [IgnoreUpdate]
+        public DateTime create_time { get; set; } = DateTime.Now;
+        public DateTime last_time { get; set; } = DateTime.Now;
+    }
+
+}

+ 1 - 0
molilian.core/DTO/pdd/PddDataDTO.cs

@@ -29,6 +29,7 @@
         public DateTime create_time { get; set; } = DateTime.Now;
         public string end_point { get; set; } = string.Empty;
         public int subCode { get; set; } = 0;
+        public string accessto { get; set; } = string.Empty;
     }
 
 }

+ 5 - 0
molilian.core/DTO/pdd/PddPoolDTO.cs

@@ -13,12 +13,17 @@ namespace molilian.core
     public class PddPoolDTO
     {
         public int id { get; set; }
+        public int duoId { get; set; }
         public string name { get; set; } = string.Empty;
         public string nodeName { get; set; } = string.Empty;
         public string end_point { get; set; } = string.Empty;
         public string app_key { get; set; } = string.Empty;
         public string app_secret { get; set; } = string.Empty;
         public string pid { get; set; } = string.Empty;
+
+        public string access_token { get; set; } = string.Empty;
+
+        public string refresh_token { get; set; } = string.Empty;
         public string company { get; set; } = string.Empty;
         public string description { get; set; } = string.Empty;
         public DateTime create_time { get; set; } = DateTime.Now;

+ 5 - 1
molilian.core/Plus/Alimama/parse.cs

@@ -181,7 +181,9 @@ namespace molilian.core
                 if (url.Contains("https://s.tb.cn/") ||
                     url.Contains("http://s.tb.cn/") ||
                     url.Contains("http://m.tb.cn/") ||
-                    url.Contains("https://m.tb.cn/"))
+                    url.Contains("http://m.tb.cn/") ||
+                    url.Contains("http://e.tb.cn/") ||
+                    url.Contains("https://e.tb.cn/"))
                 {
                     result = result.Replace(url, shortLink);
                 }
@@ -221,6 +223,8 @@ namespace molilian.core
                 result = matches[^1].Value; // 返回第一个匹配到的 URL
             }
             result = result.Replace("&nbsp;", "");
+
+            if (result.StartsWith("http://e.tb.cn/")) result = result.Replace("http://", "https://");
             return result;
         }
 

+ 30 - 11
molilian.core/Plus/Alimama/parse_2.cs

@@ -109,6 +109,7 @@ namespace molilian.core
                 url.Contains("//tmallx.tmall.com/app/tmallx-src/goods-detail") ||
                 url.Contains("//detail.tmall.com/item.htm?") ||
                 url.Contains("//internal.tt.detail.taobao.com/item.htm?") ||
+                url.Contains("//internal.tt.detail.taobao.com/item.htm?") ||
                 url.Contains("//detail.tmall.hk/hk/item.htm?"))
             {
                 string? itemId = ExtractItemId(url);
@@ -183,7 +184,7 @@ namespace molilian.core
             string result;
             try
             {
-                if (!url.Contains("m.tb.cn") && !url.Contains("s.tb.cn"))
+                if (!url.Contains("m.tb.cn") && !url.Contains("e.tb.cn") && !url.Contains("s.tb.cn"))
                     return (false, "不是淘宝短网址");
 
                 if (!_account.enable_deep_url) return (true, url);
@@ -249,7 +250,7 @@ namespace molilian.core
             string result;
             try
             {
-                if (!url.Contains("m.tb.cn") && !url.Contains("s.tb.cn"))
+                if (!url.Contains("m.tb.cn") && !url.Contains("e.tb.cn") && !url.Contains("s.tb.cn"))
                     return (false, "不是淘宝短网址");
 
                 string desiredUrlPattern = "var url = '(.*?)'";
@@ -495,16 +496,34 @@ namespace molilian.core
                 }
                 else
                 {
-                    if (result.link_type == LinkTypeEnum.baseDomain)
-                    {
-                        result.content = content;
-                    }
-                    else
+                    switch (result.link_type)
                     {
-                        result.reason = "非标准链接";
-                        result.subCode = TkSubCodeEnum.NonStdLink;
+                        case LinkTypeEnum.profile:
+                        case LinkTypeEnum.live:
+                        case LinkTypeEnum.video:
+                        case LinkTypeEnum.note:
+                        case LinkTypeEnum.goods:
+                        case LinkTypeEnum.baseDomain:
+                            result.reason = string.Empty;
+                            result.content = content;
+                            break;
 
+                        default:
+                            result.reason = "非标准链接";
+                            result.subCode = TkSubCodeEnum.NonStdLink;
+                            break;
                     }
+
+                    //if (result.link_type == LinkTypeEnum.baseDomain)
+                    //{
+                    //    result.content = content;
+                    //}
+                    //else
+                    //{
+                    //    result.reason = "非标准链接";
+                    //    result.subCode = TkSubCodeEnum.NonStdLink;
+
+                    //}
                 }
                 result.success = false;
                 result.message = "放弃转链";
@@ -545,13 +564,13 @@ namespace molilian.core
         {
             if (string.IsNullOrEmpty(url)) return LinkTypeEnum.unknown;
 
-            if (url.Contains("m.tb.cn") || url.Contains("s.tb.cn")) return LinkTypeEnum.baseDomain;
+            if (url.Contains("m.tb.cn") || url.Contains("s.tb.cn") || url.Contains("e.tb.cn")) return LinkTypeEnum.baseDomain;
 
             if (url.StartsWith("https://huodong.m.taobao.com/act/talent/live.html")) return LinkTypeEnum.live;
             if (url.StartsWith("https://web.m.taobao.com/app/tnode/web/index")) return LinkTypeEnum.video;
             if (url.StartsWith("https://shop.m.taobao.com/shop/shopIndex.htm")) return LinkTypeEnum.profile;
 
-            string pattern = @"^https://shop\d+\.m\.taobao\.com";
+            string pattern = @"^https://shop\d+(\.m)*\.taobao\.com";
             if (Regex.IsMatch(url, pattern))
             {
                 return LinkTypeEnum.profile;

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

@@ -12,7 +12,7 @@ namespace molilian.core
         private WebProxy? _proxy = null;
 
         public TkConfigDTO _config;
-        private static JdPoolDTO _account;
+        private JdPoolDTO _account;
         private static string _end_point;
 
         static JdUnionPlus()

+ 335 - 70
molilian.core/Plus/JDUnion/order.cs

@@ -1,5 +1,7 @@
 using dodohold.core;
 using Sayaka.Common;
+using System.Text.Json;
+using System.Threading;
 
 
 namespace molilian.core
@@ -7,93 +9,356 @@ namespace molilian.core
     public partial class JdUnionPlus
     {
 
+        public async Task<int> GetHistoryOrders(int sleep, DateTime startTime, DateTime endTime)
+        {
+            //当日往前查询
+            (int total, DateTime max_modifiedTime, List<DateTime> orderTimes) = await GetTkOrdersAsync(startTime, endTime, DateTime.MinValue, optType: 2, sleep);
+
+            string sql = @"
+UPDATE tk_report tr
+JOIN (
+    SELECT
+        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
+        COUNT(*) AS order_ord_num, SUM(pubShareFeeForCommission) AS order_ord_tfee
+    FROM tk_order_details
+    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=3 AND accountId=@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, tr.order_ord_num_3 = sub.order_ord_num, 
+    tr.order_ord_tfee = sub.order_ord_tfee;";
+            //DBContext.Execute(sql, new { accountId = _account.id, orderTimes });
+
+            sql = @"
+UPDATE tk_report tr
+JOIN (
+    SELECT
+        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, 
+        COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
+    FROM tk_order_details
+    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=12 AND accountId=@accountId
+    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_num_12 = sub.order_ord_num, 
+    tr.order_ord_tfee_12 = sub.order_ord_tfee;";
+            //DBContext.Execute(sql, new { accountId = _account.id, orderTimes });
+
+            sql = @"
+UPDATE tk_report tr
+JOIN (
+    SELECT
+        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, 
+        COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
+    FROM tk_order_details
+    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=13 AND accountId=@accountId
+    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_num_13 = sub.order_ord_num, 
+    tr.order_ord_tfee_13 = sub.order_ord_tfee;";
+            //DBContext.Execute(sql, new { accountId = _account.id, orderTimes });
 
+            sql = @"
+UPDATE tk_report tr
+JOIN (
+    SELECT
+        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, 
+        COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
+    FROM tk_order_details
+    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=14 AND accountId=@accountId
+    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_num_14 = sub.order_ord_num, 
+    tr.order_ord_tfee_14 = sub.order_ord_tfee;";
+            //DBContext.Execute(sql, new { accountId = _account.id, orderTimes });
 
-        public async Task<JdDataDTO> listOrderSku(JdDataDTO result, string wareUrl, CancellationToken cancellationToken = default)
+            sql = @"UPDATE tk_report 
+SET  order_ord_num = order_ord_num_3 + order_ord_num_12 + order_ord_num_13 + order_ord_num_14
+ WHERE DATE(report_date) IN @orderTimes AND accountId=@accountId;";
+            //DBContext.Execute(sql, new { accountId = _account.id, orderTimes });
+
+            return total;
+
+        }
+        public async Task<int> GetIncyOrders(int sleep)
         {
-            string[] parts = wareUrl.Split(new string[] { ".html" }, StringSplitOptions.None);
-            if (parts.Length > 1)
+            string cacheKey = $":cache:GetIncyJDOrders:{_account.name}";
+            string cacheKey2 = $":cache:GetIncyJDOrders:{_account.id}";
+            DateTime endTime = DateTime.Now;
+            DateTime startTime = endTime.AddDays(-7);
+
+
+            DateTime last_modifiedTime = RedisHelper.Get<DateTime>(cacheKey);
+
+            if (last_modifiedTime != DateTime.MinValue)
             {
-                wareUrl = parts[0] + ".html";
+                startTime = last_modifiedTime;
+            }
+            else
+            {
+                last_modifiedTime = startTime;
             }
 
+            //当日往前查询
+            (int total, DateTime max_modifiedTime, List<DateTime> orderTimes) = await GetTkOrdersAsync(startTime, endTime, last_modifiedTime, optType: 1, sleep);
+            if (max_modifiedTime != DateTime.MinValue)
+            {
+                RedisHelper.Set(cacheKey, max_modifiedTime);
+                RedisHelper.Set(cacheKey2, max_modifiedTime);
+            }
 
-            var ts = DateTime.Now.Convert2UnixTimestamp(true);
-            string cookies = _account.cookies;
+            //todo 根据orderTimes、settlementTimes 更新被影响的相关行 
 
-            string uuid = cookies.GetContentPart("__jdu=", ";");
-            string __jda = cookies.GetContentPart("__jda=", ";");
-            if (__jda.Split('.').Length > 1)
+            string sql = @"
+UPDATE tk_report tr
+JOIN (
+    SELECT
+        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt,
+        COUNT(*) AS order_ord_num, SUM(pubShareFeeForCommission) AS order_ord_tfee
+    FROM tk_order_details
+    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=3 AND accountId=@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, tr.order_ord_num_3 = sub.order_ord_num, 
+    tr.order_ord_tfee = sub.order_ord_tfee;";
+            //DBContext.Execute(sql, new { accountId = _account.id, orderTimes });
+
+            sql = @"
+UPDATE tk_report tr
+JOIN (
+    SELECT
+        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, 
+        COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
+    FROM tk_order_details
+    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=12 AND accountId=@accountId
+    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_num_12 = sub.order_ord_num, 
+    tr.order_ord_tfee_12 = sub.order_ord_tfee;";
+            //DBContext.Execute(sql, new { accountId = _account.id, orderTimes });
+
+            sql = @"
+UPDATE tk_report tr
+JOIN (
+    SELECT
+        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, 
+        COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
+    FROM tk_order_details
+    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=13 AND accountId=@accountId
+    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_num_13 = sub.order_ord_num, 
+    tr.order_ord_tfee_13 = sub.order_ord_tfee;";
+            //DBContext.Execute(sql, new { accountId = _account.id, orderTimes });
+
+            sql = @"
+UPDATE tk_report tr
+JOIN (
+    SELECT
+        accountId, DATE(tbPaidTime) AS date, SUM(alipayTotalPrice) AS order_ord_amt, 
+        COUNT(*) AS order_ord_num, SUM(pubSharePreFeeForCommission) AS order_ord_tfee
+    FROM tk_order_details
+    WHERE DATE(tbPaidTime) IN @orderTimes AND tkStatus=14 AND accountId=@accountId
+    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_num_14 = sub.order_ord_num, 
+    tr.order_ord_tfee_14 = sub.order_ord_tfee;";
+            //DBContext.Execute(sql, new { accountId = _account.id, orderTimes });
+
+            sql = @"UPDATE tk_report 
+SET  order_ord_num = order_ord_num_3 + order_ord_num_12 + order_ord_num_13 + order_ord_num_14
+ WHERE DATE(report_date) IN @orderTimes AND accountId=@accountId;";
+            //DBContext.Execute(sql, new { accountId = _account.id, orderTimes });
+
+            return total;
+        }
+
+
+
+        public async Task<(int, DateTime, List<DateTime>)> GetTkOrdersAsync(DateTime startTime, DateTime endTime, DateTime last_modifiedTime, int optType, int sleep = 100)
+        {
+            List<DateTime> orderTimes = [];
+
+            // 确保 startTime 小于 endTime
+            if (startTime > endTime)
             {
-                uuid = __jda.Split('.')[1];
+                (startTime, endTime) = (endTime, startTime);
             }
 
-            string useragent = _account.user_agent;
-            if (string.IsNullOrEmpty(useragent)) useragent = ProviderFakeUserAgent.RandomComputer;
-            string url = $"https://api.m.jd.com/api?functionId=unionPromoteLinkService&" +
-                $"appid=unionpc&_={ts}&loginType=3&uuid={uuid}";
+            DateTime max_modifiedTime = last_modifiedTime;
 
-            var args = new
+            int pageNo = 1;
+            int pageSize = 100;
+
+            bool hasNext = true;
+            int total = 0;
+            while (hasNext)
             {
-                funName = "getCode",
-                param = new
+                string body = "";
+                JsonElement data;
+                try
                 {
-                    couponLink = "",
-                    isPinGou = 0,
-                    materialId = result.itemId,
-                    materialType = 1,
-                    planId = 3479956501,
-                    promotionType = 15,
-                    receiveType = "cps",
-                    wareUrl = wareUrl,
-                    isSmartGraphics = 0,
-                    command = 1,
-                    ext1 = "618|pc|".UrlEncode()
-                },
-                lientPageId = "jingfen_pc"
-            };
-            string data = args.Convert2Json().UrlEncode();
-
-            WebClientUtility client = new WebClientUtility();
-            client.Proxy = _proxy;
+                    for (var i = 1; i <= 5; i++)
+                    {
+
+                        var ts = DateTime.Now.Convert2UnixTimestamp(true);
+                        string cookies = _account.cookies;
+
+                        string uuid = cookies.GetContentPart("__jdu=", ";");
+                        string __jda = cookies.GetContentPart("__jda=", ";");
+                        if (__jda.Split('.').Length > 1)
+                        {
+                            uuid = __jda.Split('.')[1];
+                        }
+
+                        string useragent = _account.user_agent;
+                        if (string.IsNullOrEmpty(useragent)) useragent = ProviderFakeUserAgent.RandomComputer;
+                        string url = $"https://api.m.jd.com/api?functionId=listOrderSku&" +
+                            $"appid=unionpc&_={ts}&loginType=3&uuid={uuid}";
+
+
+                        var args = new
+                        {
+                            funName = "listOrderSku",
+                            page = new
+                            {
+                                pageNo,
+                                pageSize
+                            },
+                            param = new
+                            {
+                                unionRole = 1,
+                                startTime = startTime.ToString("yyyy-MM-dd HH:mm:ss"),
+                                endTime = endTime.ToString("yyyy-MM-dd HH:mm:ss"),
+                                orderStatus = 0,
+                                unionTags = new string[] { "0" },
+                                optType,
+                                spId = ""
+                            },
+                            lientPageId = "jingfen_pc"
+                        };
+
+                        string post = args.Convert2Json().UrlEncode();
+
+                        WebClientUtility client = new WebClientUtility();
+                        client.Proxy = _proxy;
 #if DEBUG
-            client.Proxy = null;
+                        client.Proxy = null;
 #endif
-            client.SetContentType("application/x-www-form-urlencoded");
-            client.AddHeaders("X-Referer-Page", "https://union.jd.com/proManager/index");
-            client.AddHeaders("X-Rp-Client", "h5_1.0.0");
-            client.AddHeaders("Referer", "https://union.jd.com/");
-            client.AddHeaders("Origin", "https://union.jd.com");
-            client.UserAgent = useragent;
-            client.AddHeaders("Cookie", cookies);
-            client.Post($"body={data}");
-            var response = await client.RequestAsync(url, "POST", cancellationToken);
-
-            string body = response.Body();
-            var root = body.Convert2JsonElement();
-            int code = root.Read<int>("code");
-            string message = root.Read<string>("message");
-            string shortCode = root.PathRead<string>("data.shortCode");
-
-            if (code == 200)
-            {
-                result.success = true;
-                result.message = "OK";
-                result.shortLinkurl = shortCode;
-                result.content = result.shortLinkurl;
-                result.deeplink_url = GetDeeplink(result.shortLinkurl);
-            }
-            else
-            {
-                if (string.IsNullOrEmpty(body)) message = "网络异常";
-                result.success = false;
-                result.message = "转链失败";
-                result.reason = message;
-                result.shortLinkurl = wareUrl;
-                result.deeplink_url = GetDeeplink(result.shortLinkurl);
-                _ = new LoggerLibrary("JdUnion", "GetPromotionByCrawlerAsync").Info(body).SaveAsync();
+                        client.SetContentType("application/x-www-form-urlencoded");
+                        client.AddHeaders("X-Referer-Page", "https://union.jd.com/proManager/index");
+                        client.AddHeaders("X-Rp-Client", "h5_1.0.0");
+                        client.AddHeaders("Referer", "https://union.jd.com/");
+                        client.AddHeaders("Origin", "https://union.jd.com");
+                        client.UserAgent = useragent;
+                        client.AddHeaders("Cookie", cookies);
+                        client.Post($"body={post}");
+                        var response = await client.RequestAsync(url, "POST");
+#if DEBUG
+#else
+                        client.Proxy = _proxy;
+#endif
+
+                        if (response.ResponseException != null)
+                        {
+                            _ = new LoggerLibrary("api_error", "fail")
+                                .Info(response.ResponseException.Message, response.ResponseException.StackTrace)
+                                .SaveAsync();
+                            throw response.ResponseException;
+                        }
+                        body = response.Body();
+#if DEBUG
+                        _ = new LoggerLibrary("debug", "GetJdOrders")
+                            .Info(body)
+                            .SaveAsync();
+#endif  
+                        break;
+                    }
+                    data = body.Convert2JsonElement();
+
+                    //{"code":452,"hasNext":false,"message":"单位时间内订单量太多,请缩短查询时间范围","totalNum":0}
+
+                    var code = data.Read<int>("code");
+
+                    if (code != 200)
+                    {
+                        if (body.Contains("no login"))
+                        {
+                            JdPoolCore.Disabled(_account.id, _account.name, $"{body}");
+                            return (0, DateTime.MinValue, new List<DateTime>());
+                        }
+                        throw new APIException(body);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    throw new APIException(body);
+                }
+                using var conn = DBContext.GetOpenConnection();
+                conn.Open();
+
+                try
+                {
+
+                    foreach (var order in data.ElementRead("result").EnumerateArray())
+                    {
+                        JdOrderDetailsDTO item;
+                        try
+                        {
+
+                            item = order.GetRawText().Convert2Object<JdOrderDetailsDTO>();
+                            //todo 处理结算时间和结算金额 balanceExt "{\"20240920\":100.539}"
+
+                        }
+                        catch (Exception ex)
+                        {
+                            throw;
+                        }
+
+                        //todo 处理结算时间和结算金额 balanceExt "{\"20240920\":100.539}"
+                        item.accountId = _account.id;
+                        item.accountName = _account.name;
+
+                        if (item.finishTime > max_modifiedTime) max_modifiedTime = item.finishTime;
+
+                        if (last_modifiedTime != DateTime.MinValue && last_modifiedTime >= item.finishTime)
+                        {
+                            return (total, max_modifiedTime, orderTimes);
+                        }
+
+                        var exist = new DBContext.Table("jd_order_details")
+                                   .Fields("id, orderId")
+                                   .Get<dynamic>("orderid=@orderid", new { item.orderId });
+                        if (exist != null)
+                        {
+                            var id = DBContext.Update<JdOrderDetailsDTO>(exist.id, item);
+                        }
+                        else
+                        {
+                            conn.Insert(item);
+                        }
+                        total++;
+                    }
+                }
+                catch (Exception ex)
+                {
+                    throw;
+                }
+                finally
+                {
+                    conn.Dispose();
+                }
+                pageNo++;
+                hasNext = data.Read<bool>("hasNext");
+                if (sleep > 0) Thread.Sleep(sleep);
             }
-            return result;
+            return (total, max_modifiedTime, orderTimes);
         }
 
     }

+ 13 - 2
molilian.core/Plus/pdd/open.cs

@@ -77,12 +77,19 @@ namespace molilian.core
         /// <returns></returns>
         public async Task<PddDataDTO> UnionGeneratelink(PddDataDTO result, string sourceUrl, CancellationToken cancellationToken = default)
         {
+            string api_type = "pdd.ddk.goods.zs.unit.url.gen";
+            if (!string.IsNullOrEmpty(_account.access_token))
+            {
+                api_type = "pdd.ddk.oauth.goods.zs.unit.url.gen";
+            }
+
             var ts = DateTime.Now.Convert2UnixTimestamp(true);
             var args = new Dictionary<string, string>
             {
-                { "type", "pdd.ddk.goods.zs.unit.url.gen" },
+                { "type",api_type},
                 { "data_type", "JSON" },
                 { "client_id", _account.app_key },
+                { "access_token", _account.access_token },
                 { "pid", _account.pid },
                 { "source_url", sourceUrl },
                 { "timestamp", ts.ToString() }
@@ -102,10 +109,14 @@ namespace molilian.core
             client.SetContentType("application/json");
             var response = await client.RequestAsync(urlWithQuery, "GET", cancellationToken);
 
+            //https://gw-api.pinduoduo.com/api/router?type=pdd.ddk.oauth.goods.zs.unit.url.gen&data_type=JSON&client_id=c8823690b47842649e4fee054317e0c1&access_token=5742da3542b94f86a29f1582e02cdfce76260f09&pid=41188561_292056956&source_url=https%3A%2F%2Fp.pinduoduo.com%2FbycsAB3L&timestamp=1725306430&sign=31EFD135B3530C639AAC32B9DFF1F2F4
+            //https://gw-api.pinduoduo.com/api/router?type=pdd.ddk.goods.zs.unit.url.gen&data_type=JSON&client_id=c8823690b47842649e4fee054317e0c1&access_token=5742da3542b94f86a29f1582e02cdfce76260f09&pid=41188561_292056956&source_url=https%3a%2f%2fp.pinduoduo.com%2fbycsAB3L&timestamp=1725306278417&sign=72D2F327C0199AC68C1CF1136C14FA4B
+
+
             string body = response.Body();
             var root = body.Convert2Object<UnionGeneratelinkDTO>();
             string message = string.Empty;
-            _ = new LoggerLibrary("PddUnion", "debug ").Info(urlWithQuery, body).SaveAsync();
+            _ = new LoggerLibrary("PddUnion", "debug").Info(urlWithQuery, body).SaveAsync();
 
             if (root.error_response != null || root.goods_zs_unit_generate_response == null)
             {

Some files were not shown because too many files changed in this diff