Quellcode durchsuchen

增加同步维权订单数据;
京东转链增加 bysubunionid;

dodo hold vor 2 Jahren
Ursprung
Commit
f0691db71f

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

@@ -29,11 +29,12 @@ namespace molilian.api.Controllers
 
 
             string cookie = form.Read<string>("cookie", string.Empty);
-            var success = TkPoolCore.UpdateCookies(cookie, user_agent);
+            var accountId = TkPoolCore.UpdateCookies(cookie, user_agent);
+            bool success = accountId > 0;
             if (success)
             {
                 //string desc = ObjectComparer.PrintCompareToString(old, form).Trim();
-                OperationLogCore.LogOperation(token.AccessKey, clientIp, "tk_pool:cookie", string.Empty, cookie);
+                OperationLogCore.LogOperation(token.AccessKey, clientIp, $"tk_pool:{accountId}:cookie", string.Empty, cookie);
             }
             return new APIResult(new
             {
@@ -80,7 +81,7 @@ namespace molilian.api.Controllers
             if (success)
             {
                 //string desc = ObjectComparer.PrintCompareToString(old, form).Trim();
-                OperationLogCore.LogOperation(token.AccessKey, clientIp, $"tk_pool:{name}", string.Empty, val);
+                OperationLogCore.LogOperation(token.AccessKey, clientIp, $"tk_pool:{id}:{name}", string.Empty, val);
                 await EndPointCore.NotifyReload(true);
 
             }

+ 0 - 4
molilian.api/Controllers/public/RootController.cs

@@ -73,10 +73,6 @@ namespace molilian.api.Controllers
             var url = form.Read("url", string.Empty);
             var ip = form.Read("ip", string.Empty);
             var oaid = form.Read("oaid", string.Empty);
-#if DEBUG
-            ip = "127.0.0.1";
-            oaid = "test-oaid";
-#endif
 
             if (!string.IsNullOrEmpty(url))
             {

+ 77 - 2
molilian.api/Controllers/public/TaskController.cs

@@ -62,6 +62,7 @@ namespace molilian.api.Controllers
             return new APIResult(new { success = true, message = "ok", total });
         }
 
+
         [HttpGet]
         public async Task<ActionResult> GetHistoryOrders(int id, int sleep, DateTime startTime, DateTime endTime)
         {
@@ -88,7 +89,7 @@ namespace molilian.api.Controllers
                 }
                 catch (Exception ex)
                 {
-                    message = $"【订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
+                    message = $"【历史订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
                     NotifyCore.Notify(new NifyMessage
                     {
                         message = message,
@@ -122,7 +123,81 @@ namespace molilian.api.Controllers
                 }
                 catch (Exception ex)
                 {
-                    message = $"【订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
+                    message = $"【新增订单接口异常】[{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> GetHistoryRefundOrders(int id, int sleep, DateTime startTime, DateTime endTime)
+        {
+            var list = TkPoolCore.List();
+            if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
+            if (id == 0) return new APIResult(new { success = false, message = "没有有效账号", });
+
+            string message = string.Empty;
+            int total = 0;
+            foreach (var account in list)
+            {
+
+                if (id != account.id) continue;
+
+                try
+                {
+                    //DateTime endTime = DateTime.Now;
+                    //DateTime startTime = endTime.AddDays(-90);
+                    if (account.id == 3) endTime = DateTime.Parse("2024-04-07");
+
+
+                    var alimama = new AlimamaPlus(account);
+                    total += alimama.GetHistoryRefundOrders(sleep, startTime, endTime);
+                }
+                catch (Exception ex)
+                {
+                    message = $"【维权订单接口异常】[{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> GetIncyRefundOrders(int sleep = 2000)
+        {
+            var list = TkPoolCore.List();
+            if (list == null) return new APIResult(new { success = false, message = "没有有效账号", });
+            string message = string.Empty;
+            int total = 0;
+            foreach (var account in list)
+            {
+#if DEBUG
+                if (account.id != 17) continue;
+#endif
+                if (!account.enable_sync_order) continue;
+
+                try
+                {
+                    var alimama = new AlimamaPlus(account);
+                    total += alimama.GetIncyRefundOrders(sleep);
+                }
+                catch (Exception ex)
+                {
+                    message = $"【维权订单接口异常】[{account.id}]{account.company}\n{ex.Message}\n{ex.StackTrace}";
                     NotifyCore.Notify(new NifyMessage
                     {
                         message = message,

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

@@ -25,70 +25,6 @@ namespace molilian.api.Controllers
             _accessor = accessor;
         }
 
-
-        [HttpPost]
-        [Route("/[action]")]
-        public async Task<ActionResult> PromotionQuery([FromBody] JsonElement form, [FromQuery] string a = "", [FromQuery] int t = 0, [FromQuery] string sign = "")
-        {
-            var img = form.Read("img", string.Empty);
-            var url = form.Read("url", 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);
-            }
-
-            if (!string.IsNullOrEmpty(url))
-            {
-                var bytes = new WebClientUtility().Request(url).ResponseBody;
-                img = Convert.ToBase64String(bytes);
-            }
-            return await TaokeOpenCore.PromotionQueryAsync(img, oaid, ip);
-        }
-
-
-        [HttpPost]
-        [Route("/[action]")]
-        public async Task<ActionResult> unsafePromotionQuery([FromBody] JsonElement form)
-        {
-            var img = form.Read("img", string.Empty);
-            var url = form.Read("url", string.Empty);
-            var ip = form.Read("ip", string.Empty);
-            var oaid = form.Read("oaid", string.Empty);
-#if DEBUG
-            ip = "127.0.0.1";
-            oaid = "test-oaid";
-#endif
-
-            if (!string.IsNullOrEmpty(url))
-            { 
-                var bytes = new WebClientUtility().Request(url).ResponseBody;
-                img = Convert.ToBase64String(bytes);
-            }
-            return await TaokeOpenCore.PromotionQueryAsync(img, oaid, ip);
-        }
-
-
         /// <summary>
         /// oppo调用
         /// </summary>

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

@@ -131,8 +131,8 @@ namespace molilian.core
                     result.success,
                     result.message,
                     result.reason,
-                    result.SimilarPromotion,
-                    result.PromotionImg,
+                    similarPromotion = result.SimilarPromotion,
+                    promotionImg = result.PromotionImg,
                     result.url,
                 }, APIResultCodeEnum.OK, new JsonSerializerOptions
                 {

+ 4 - 4
molilian.core/Core/taoke/TkPoolCore.cs

@@ -170,15 +170,15 @@ namespace molilian.core
             EndPointCore.NotifyReload(true);
         }
 
-        public static bool UpdateCookies(string cookies, string user_agent)
+        public static int UpdateCookies(string cookies, string user_agent)
         {
-            if (string.IsNullOrEmpty(cookies)) return false;
+            if (string.IsNullOrEmpty(cookies)) return 0;
             cookies += ";";
             string dnk = cookies.GetContentPart("dnk=", ";");
             string company = dnk;
             int accountId = 0;
             string tb_token = cookies.GetContentPart("_tb_token_=", ";");
-            if (string.IsNullOrEmpty(dnk) || string.IsNullOrEmpty(tb_token)) return false;
+            if (string.IsNullOrEmpty(dnk) || string.IsNullOrEmpty(tb_token)) return 0;
             var exist = new DBContext.Table("tk_pool").Fields("id, name, company, refpid, status").Get<dynamic>("name=@dnk", new { dnk });
             if (exist != null)
             {
@@ -222,7 +222,7 @@ namespace molilian.core
             });
             EndPointCore.NotifyReload(true);
             //NotifyCore.AnPushNotify("上线", $"【淘宝联盟:{dnk}】cookie 上报更新");
-            return true;
+            return accountId;
         }
 
         internal static void AccountExhausted()

+ 62 - 0
molilian.core/DTO/alimama/TkRefundOrderDetailDTO.cs

@@ -0,0 +1,62 @@
+using dodohold.core;
+using System.Text.Json.Serialization;
+
+namespace molilian.core
+{
+    [Table("tk_refund_order_details")]
+    public class TkRefundOrderDetailDTO
+    {
+
+        [Key]
+        public int id { get; set; }
+        public int accountId { get; set; } = 0;
+
+        public string accountName { get; set; } = string.Empty;
+
+        public string TkOrderRole { get; set; } = string.Empty;
+        public decimal RefundFee { get; set; } = 0;
+        [JsonConverter(typeof(DateTimeConverterUsingDateTimeParse))]
+        public DateTime ModifiedTime { get; set; } = DateTime.MinValue;
+        public decimal TkServiceReturnFee { get; set; } = 0;
+        public string ItemTitle { get; set; } = string.Empty;
+        [JsonConverter(typeof(DateTimeConverterUsingDateTimeParse))]
+        public DateTime EarningTime { get; set; } = DateTime.MinValue;
+        public int RefundStatus { get; set; } = 0;
+        public decimal AlimamaRate { get; set; } = 0;
+        public string ItemImg { get; set; } = string.Empty;
+        public decimal PubShareFee { get; set; } = 0;
+
+        [JsonConverter(typeof(DateTimeConverterUsingDateTimeParse))]
+        public DateTime TbTradeCreateTime { get; set; } = DateTime.MinValue;
+        public decimal RefundServiceFee { get; set; } = 0;
+        [JsonConverter(typeof(DateTimeConverterUsingDateTimeParse))]
+        public DateTime RefundCreateTime { get; set; } = DateTime.MinValue;
+
+        public string TbTradeId { get; set; } = string.Empty;
+        public decimal TkSubsidyFeeRefund { get; set; } = 0;
+        public decimal TkCommissionAlimmReturnFee { get; set; } = 0;
+        public string MktId { get; set; } = string.Empty;
+        public string SellerShopTitle { get; set; } = string.Empty;
+        public decimal TkCommissionFeeRefund { get; set; } = 0;
+        public string ShowRefundStatus { get; set; } = string.Empty;
+        public decimal TkSubsidyAgentReturnFee { get; set; } = 0;
+        public decimal ShowReturnFee { get; set; } = 0;
+        public string TbTradeParentId { get; set; } = string.Empty;
+        public long RefundSuitId { get; set; } = 0;
+        public decimal TkSubsidyAlimmReturnFee { get; set; } = 0;
+        public decimal AlipayTotalPrice { get; set; } = 0;
+        public bool SupportItemClick { get; set; } = false;
+        public decimal AlimamaShareFee { get; set; } = 0;
+        public decimal TkCommissionAgentReturnFee { get; set; } = 0;
+        public string MktItemLink { get; set; } = string.Empty;
+        [JsonConverter(typeof(DateTimeConverterUsingDateTimeParse))]
+        public DateTime RefundFinishTime { get; set; } = DateTime.MinValue;
+        public int TkBizTag { get; set; } = 0;
+
+        [IgnoreUpdate]
+        public DateTime create_time { get; set; } = DateTime.Now;
+        public DateTime last_time { get; set; } = DateTime.Now;
+
+    }
+
+}

+ 371 - 0
molilian.core/Plus/Alimama/RefundOrders.cs

@@ -0,0 +1,371 @@
+using dodohold.core;
+using Spire.Pdf.Xmp;
+using System.Data;
+using System.Drawing.Printing;
+using System.Runtime.InteropServices;
+using System.Text.Json;
+using System.Text.RegularExpressions;
+using static System.Runtime.InteropServices.JavaScript.JSType;
+
+namespace molilian.core
+{
+    public partial class AlimamaPlus
+    {
+        private const string base_refund_orders_url = "https://pub.alimama.com/openapi/param2/1/gateway.unionpub/report.publisher.getRefundOrderDetail.json";
+
+        public int GetHistoryRefundOrders(int sleep, DateTime startTime, DateTime endTime)
+        {
+
+            //DateTime endTime = DateTime.Now;
+            //DateTime startTime = endTime.AddDays(-90);
+            //if (_accountId == 3) endTime = DateTime.Parse("2024-04-07");
+            //#if DEBUG
+
+            //            startTime = DateTime.Parse("2024-05-01");
+            //            endTime = DateTime.Parse("2024-06-01");
+
+
+            //            int total = 0;
+
+            //            List<DateTime> orderTimes = new List<DateTime>();
+
+            //            for (DateTime date = startTime; date <= endTime; date = date.AddDays(1))
+            //            {
+            //                orderTimes.Add(date);
+            //            }
+
+
+            //#else
+            //当日往前查询
+            (int total, DateTime max_modifiedTime, List<DateTime> orderTimes) = GetTkRefundOrders(startTime, endTime, DateTime.MinValue, false, sleep);
+
+
+            //#endif       
+
+            //            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 = _accountId, 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 = _accountId, 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 = _accountId, 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 = _accountId, 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 = _accountId, orderTimes });
+
+            return total;
+
+        }
+        public int GetIncyRefundOrders(int sleep)
+        {
+            string cacheKey = $":cache:GetIncyRefundOrders:{_accountId}";
+            DateTime endTime = DateTime.Now;
+            DateTime startTime = endTime.AddDays(-1);
+
+
+            DateTime last_modifiedTime = RedisHelper.Get<DateTime>(cacheKey);
+            ////找出数据库最新的一天
+            //var last = new DBContext.Table("tk_order_details")
+            //     .Order("modifiedTime DESC")
+            //     .Get<TkRefundOrderDetailDTO>("accountId=@accountId", new { accountId = _accountId });
+
+
+            if (last_modifiedTime != DateTime.MinValue)
+            {
+                startTime = last_modifiedTime;
+            }
+            else
+            {
+                last_modifiedTime = startTime;
+            }
+
+            //当日往前查询
+            (int total, DateTime max_modifiedTime, List<DateTime> orderTimes) = GetTkRefundOrders(startTime, endTime, last_modifiedTime, true, sleep);
+            if (max_modifiedTime != DateTime.MinValue)
+            {
+                RedisHelper.Set(cacheKey, max_modifiedTime);
+            }
+
+            //todo 根据orderTimes、settlementTimes 更新被影响的相关行 
+
+            //            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 = _accountId, 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 = _accountId, 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 = _accountId, 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 = _accountId, 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 = _accountId, orderTimes });
+
+            return total;
+        }
+
+        public (int, DateTime, List<DateTime>) GetTkRefundOrders(DateTime startTime, DateTime endTime, DateTime last_modifiedTime, bool desc = true, int sleep = 100)
+        {
+            List<DateTime> orderTimes = [];
+
+            // 确保 startTime 小于 endTime
+            if (startTime > endTime)
+            {
+                (startTime, endTime) = (endTime, startTime);
+            }
+
+            DateTime max_modifiedTime = last_modifiedTime;
+
+            int pageNo = 1;
+            string positionIndex = string.Empty;
+            int pageSize = 100;
+
+            bool hasNext = true;
+            int total = 0;
+            while (hasNext)
+            {
+                var ts = DateTime.Now.Convert2UnixTimestamp(true);
+                //string jumpType = desc ? pageNo == 1 ? "0" : "1" : "-1";
+                string jumpType = pageNo == 1 ? "0" : "1";
+
+                //string queryType = "1";
+                //1 创建时间;3结算时间 2付款时间 4更新时间
+                //string queryType = "2";
+                string queryType = desc ? "4" : "2";
+
+                string url = $"{base_refund_orders_url}?t={ts}&_tb_token_={_tb_token}&pageNo={pageNo}&pageSize={pageSize}&startTime={startTime:yyyy-MM-dd}&endTime={endTime:yyyy-MM-dd}&payStatus=&queryType={queryType}&toPage=1&perPageSize={pageSize * 2}&jumpType={jumpType}&isFullRefund=0&memberType=&positionIndex={positionIndex.UrlEncode()}";
+
+                string body = "";
+
+                JsonElement data;
+                try
+                {
+                    for (var i = 1; i <= 5; i++)
+                    {
+                        var client = new WebClientUtility().SetContentType("application/json;charset=utf-8")
+                              .AddHeaders("X-Requested-With", "XMLHttpRequest")
+                              .AddHeaders("Cookie", _cookies);
+#if DEBUG
+#else
+                        client.Proxy = _proxy;
+#endif
+                        if (!string.IsNullOrEmpty(_user_agent)) client.UserAgent = _user_agent;
+                        var response = client.Request(url);
+
+                        if (response.ResponseException != null)
+                        {
+                            _ = new LoggerLibrary("api_error", "fail")
+                                .Info(response.ResponseException.Message, response.ResponseException.StackTrace)
+                                .SaveAsync();
+                            throw response.ResponseException;
+                        }
+                        body = response.Body();
+                        if (body.Contains("{\"action\":\"captcha\""))
+                        {
+                            string message = $"【GetTkRefundOrders】【{_accountId}:{_accountName}】第 {i} 次出现滑动验证码";
+                            NotifyCore.Notify(new NifyMessage
+                            {
+                                message = message,
+                                priority = NifyMessagePriority.high,
+                                tags = ["red_circle"]
+                            });
+                            Thread.Sleep(i * 60 * 1000);
+                            continue;
+                        }
+
+                        if (body.Contains("\"resultCode\":500"))
+                        {
+                            string message = $"【GetTkRefundOrders】【{_accountId}:{_accountName}】第 {i} 次出现错误\n{body}";
+                            NotifyCore.Notify(new NifyMessage
+                            {
+                                message = message,
+                                priority = NifyMessagePriority.high,
+                                tags = ["red_circle"]
+                            });
+                            Thread.Sleep(i * 60 * 1000);
+                            continue;
+                        }
+                        break;
+                    }
+                    var root = body.Convert2JsonElement();
+                    var success = root.Read<bool>("success");
+                    data = root.ElementRead("data");
+
+
+                    //{"code":601,"info":{"ok":false,"message":"nologin"}}
+                    if (!success && body.Contains("nologin"))
+                    {
+                        (success, string message) = RenewCookie();
+                        if (!success)
+                        {
+                            TkPoolCore.Disabled(_accountId, _accountName, $"{body}");
+                        }
+                        return (0, DateTime.MinValue, new List<DateTime>());
+                    }
+
+                    if (!success)
+                    {
+                        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())
+                    {
+                        TkRefundOrderDetailDTO item = order.GetRawText().Convert2Object<TkRefundOrderDetailDTO>();
+                        // 处理每个订单数据 
+
+                        item.accountId = _accountId;
+                        item.accountName = _company;
+
+                        if (item.ModifiedTime > max_modifiedTime) max_modifiedTime = item.ModifiedTime;
+
+                        if (last_modifiedTime != DateTime.MinValue && last_modifiedTime >= item.ModifiedTime)
+                        {
+                            return (total, max_modifiedTime, orderTimes);
+                        }
+
+                        //进行订单和转链匹配
+                        orderTimes.Add(item.RefundCreateTime.Date);
+                        int? id = conn.Replace(item);
+                        if (id != null)
+                        {
+                            item.id = (int)id;
+                        }
+                        total++;
+                    }
+                }
+                catch (Exception ex)
+                {
+                    throw;
+                }
+                finally
+                {
+                    conn.Dispose();
+                }
+                pageNo++;
+                hasNext = data.Read<bool>("hasNext");
+                positionIndex = data.Read<string>("positionIndex");
+
+                if (sleep > 0) Thread.Sleep(sleep);
+            }
+            return (total, max_modifiedTime, orderTimes);
+        }
+
+
+    }
+}

+ 3 - 1
molilian.core/Plus/Alimama/orders.cs

@@ -20,7 +20,7 @@ namespace molilian.core
             //if (_accountId == 3) endTime = DateTime.Parse("2024-04-07");
 #if DEBUG
 
-            startTime = DateTime.Parse("2024-03-21");
+            startTime = DateTime.Parse("2024-05-01");
             endTime = DateTime.Parse("2024-06-01");
 
 
@@ -112,6 +112,7 @@ SET  order_ord_num = order_ord_num_3 + order_ord_num_12 + order_ord_num_13 + ord
         public int GetIncyOrders(int sleep)
         {
             string cacheKey = $":cache:GetIncyOrders:{_accountName}";
+            string cacheKey2 = $":cache:GetIncyOrders:{_accountId}";
             DateTime endTime = DateTime.Now;
             DateTime startTime = endTime.AddDays(-1);
 
@@ -137,6 +138,7 @@ SET  order_ord_num = order_ord_num_3 + order_ord_num_12 + order_ord_num_13 + ord
             if (max_modifiedTime != DateTime.MinValue)
             {
                 RedisHelper.Set(cacheKey, max_modifiedTime);
+                RedisHelper.Set(cacheKey2, max_modifiedTime);
             }
 
             //todo 根据orderTimes、settlementTimes 更新被影响的相关行 

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

@@ -34,7 +34,7 @@ namespace molilian.core
             if (string.IsNullOrEmpty(content)) return content;
             string result = content;
             //string pattern = @"https?:\/\/?([\da-z\.-]+)\.([a-z]{2,6})(:\d{1,5})?([\/\w\.-]*)*\/?(#[\S]+)?(\?[\S]+)?";
-             Regex regex = new(AlimamaPlus._url_pattern);
+            Regex regex = new(AlimamaPlus._url_pattern);
             MatchCollection matches = regex.Matches(content);
 
             foreach (Match m in matches.Cast<Match>())
@@ -243,6 +243,7 @@ namespace molilian.core
                 return result;
             }
             result.shortLinkurl = await plus.GetPromotionAsync(account.site_id, url, cancellationToken);
+
             var success = !string.IsNullOrEmpty(result.shortLinkurl);
             if (!success)
             {

+ 9 - 13
molilian.core/Plus/JDUnion/goods.cs

@@ -26,14 +26,12 @@ namespace molilian.core
 {
     public partial class JdUnionPlus
     {
-        /// <summary>
-        /// 网站/APP获取推广链接接口
-        /// </summary>
-        /// <param name="unionId"></param>
-        /// <param name="materialId"></param>
-        /// <returns></returns>
-        public string promotion_get(string siteId, string materialId)
+        public async Task<string> GetPromotionAsync(string siteId, string materialId, CancellationToken cancellationToken = default)
         {
+            if (string.IsNullOrEmpty(siteId))
+            {
+                return await GetPromotionAsync(materialId, cancellationToken);
+            }
 
             string method = "jd.union.open.promotion.common.get";
             string version = "1.0";
@@ -47,7 +45,7 @@ namespace molilian.core
                     chainType = 2,
                 }
             };
-            var body = Request(method, version, data.Convert2Json());
+            var body = await RequestAsync(method, version, data.Convert2Json(), cancellationToken);
             var root = body.Convert2Object<JdUnionResponse>();
             string code = root.jd_union_open_promotion_common_get_responce.code;
             if ("0".Equals(code))
@@ -64,17 +62,15 @@ namespace molilian.core
             return null;
         }
 
-
-        public async Task<string> GetPromotionAsync(string siteId, string materialId, CancellationToken cancellationToken = default)
+        public async Task<string> GetPromotionAsync(string materialId, CancellationToken cancellationToken = default)
         {
 
-            string method = "jd.union.open.promotion.common.get";
+            string method = "jd.union.open.promotion.bysubunionid.get";
             string version = "1.0";
             var data = new
             {
                 promotionCodeReq = new
                 {
-                    siteId,
                     materialId,
                     command = 1,
                     chainType = 2,
@@ -93,7 +89,7 @@ namespace molilian.core
                     return url;
                 }
             }
-            _ = new LoggerLibrary("JdUnion", "promotion_get_error").Info(body).SaveAsync();
+            _ = new LoggerLibrary("JdUnion", "bysubunionid_get_error").Info(body).SaveAsync();
             return null;
         }