订单列表增加 同步订单

This commit is contained in:
chfei committed 2026-08-19 15:35:42 +08:00
1 parent 4f606c3561
commit cef6300e8e
24 files changed
+2674 -1211

No files matched your search

+12
View File
@@ -227,6 +227,11 @@
<Compile Include="BuyUsers\TaoBaoBuyUser.cs" />
<Compile Include="CheckHecker.cs" />
<Compile Include="CollectionClass.cs" />
<Compile Include="ERP.API\ERPConfig.cs" />
<Compile Include="ERP.API\ERPHttp.cs" />
<Compile Include="ERP.API\Orders\ShipGiftServiceApi.cs" />
<Compile Include="ERP.API\TaskStatus.cs" />
<Compile Include="ERP.API\Orders\PullWXOrderServiceApi.cs" />
<Compile Include="GetPostTaobaoHtml.cs" />
<Compile Include="DouYinHttpWebRequest.cs" />
<Compile Include="Helper\CEFHelper.cs" />
@@ -234,6 +239,7 @@
<Compile Include="Helper\WindowStyle.cs" />
<Compile Include="ImgConvertToIcon.cs" />
<Compile Include="Initialization.cs" />
<Compile Include="KJDServer.API\Models\OrderTask.cs" />
<Compile Include="Model\BaseModel.cs" />
<Compile Include="Model\ExpressBase.cs" />
<Compile Include="MulitServicerSet.cs" />
@@ -263,6 +269,8 @@
<DependentUpon>TokenForm.cs</DependentUpon>
</Compile>
<Compile Include="UserLogin.cs" />
<Compile Include="KJDServer.API\KJDServerHttp.cs" />
<Compile Include="KJDServer.API\WXOrder\WxOrderServiceApi.cs" />
<Compile Include="_29Tools\BLL\HttpResponseBLL.cs" />
<Compile Include="_29Tools\BLL\HttpResponseWXBLL.cs" />
<Compile Include="_29Tools\BLL\HttpResponseYkdBLL.cs" />
@@ -317,6 +325,10 @@
<Project>{6461d807-b1c8-45f0-b388-e0ca1a418de0}</Project>
<Name>29WxOrderAllBase</Name>
</ProjectReference>
<ProjectReference Include="..\WxOrder.Framework\WxOrder.Framework.csproj">
<Project>{3123963c-a0ec-4ad5-9916-dc063f73490b}</Project>
<Name>WxOrder.Framework</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\29wx.ico" />
+13
View File
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Work.ERP.API
{
public class ERPConfig
{
public const string Domain = "https://po.e57.cn";
}
}
+40
View File
@@ -0,0 +1,40 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Work._29Tools.BLL;
using WxOrder.Framework.Commons;
namespace Work.ERP.API
{
public class ERPHttp
{
public static string e57PostResponse(string _url, string _data)
{
return HttpResponseWXBLL.e57PostResponse(ERPConfig.Domain + _url, _data, "");
}
public static Task<string> e57PostResponseAsync(string _url, string _data)
{
return HttpResponseWXBLL.e57PostResponseAsync(ERPConfig.Domain + _url, _data);
}
public static async Task<T> e57PostResponseAsync<T>(string _url, string _data) where T : Result, new()
{
try
{
string content = await HttpResponseWXBLL.e57PostResponseAsync(ERPConfig.Domain + _url, _data);
return JsonConvert.DeserializeObject<T>(content);
}
catch (JsonException)
{
return new T { Code = 0, Msg = "数据解析失败" };
}
catch (Exception ex)
{
return new T { Code = 0, Msg = ex.Message };
}
}
}
}
@@ -0,0 +1,186 @@
using AllBase;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WxOrder.Framework.Commons;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace Work.ERP.API.Orders
{
class PullWXOrderResult : Result
{
public List<FailedItem> Data { get; set; }
public class FailedItem
{
public long shopId { get; set; }
public string shopName { get; set; }
public string message { get; set; }
}
}
/// <summary>
/// 拉取微信订单
/// </summary>
public class PullWXOrderServiceApi
{
/// <summary>
/// 拉取指定店铺的指定订单
/// </summary>
/// <param name="shopId">店铺ID</param>
/// <param name="orderId">订单号</param>
/// <returns>服务器异步任务ID;为 0 表示服务器已直接完成</returns>
/// <exception cref="Exception"></exception>
public async Task<bool> PullOrderDetail(long shopId, string orderId)
{
string data = JsonConvert.SerializeObject(new
{
platformCode = "WEISHOP",
shopId = shopId,
orderId = orderId,
clientUserName = BaseClass.UserName
});
var result = await PostAndGetTaskIdAsync("/prod-api/api/oms-api/client/sync/pull_order_detail", data);
return result.Code == 200;
}
/// <summary>
/// 拉取指定店铺的订单列表
/// </summary>
/// <param name="shopId">店铺ID</param>
/// <param name="orderIds">订单号列表</param>
/// <returns>服务器异步任务ID;为 0 表示服务器已直接完成</returns>
/// <exception cref="Exception"></exception>
public async Task<bool> PullOrdersDetail(long shopId, string[] orderIds)
{
string data = JsonConvert.SerializeObject(new
{
platformCode = "WEISHOP",
shopId = shopId,
orderId = string.Join(",", orderIds),
clientUserName = BaseClass.UserName,
});
var result = await PostAndGetTaskIdAsync("/prod-api/api/oms-api/client/sync/pull_order_detail/batch", data);
if (result.Code == 200)
{
return true;
}
else
{
string msg = string.Join("\n", result.Data.Select(a => $"{a.shopName},{a.message}"));
throw new Exception(msg);
}
}
/// <summary>
/// 拉取指定商铺列表时间范围内的数据
/// </summary>
/// <param name="shopIds">店铺ID列表</param>
/// <param name="startTime">开始时间</param>
/// <param name="endTime">结束时间</param>
/// <returns>服务器异步任务ID;为 0 表示服务器已直接完成</returns>
/// <exception cref="Exception"></exception>
public async Task<bool> PullOrderByShopIdsAndTimeRange(long[] shopIds, DateTime startTime, DateTime endTime)
{
TimeSpan time = endTime - startTime;
if (time.TotalDays > 7) throw new Exception("时间范围最大7天");
string data = JsonConvert.SerializeObject(new
{
platformCode = "WEISHOP",
shopIds = string.Join(",", shopIds),
startTime = startTime.ToString("yyyy-MM-dd HH:mm:ss"),
endTime = endTime.ToString("yyyy-MM-dd HH:mm:ss"),
clientUserName = BaseClass.UserName,
remark=$"同步 {startTime.ToString("yyyy-MM-dd")}/{endTime.ToString("dd")}"
});
var result = await PostAndGetTaskIdAsync("/prod-api/api/oms-api/client/sync/pull_order", data);
if (result.Code == 200)
{
return true;
}
else
{
string msg = string.Join("\n", result.Data.Select(a => $"{a.shopName},{a.message}"));
throw new Exception(msg);
}
}
/// <summary>
/// 拉取指定店铺的售后订单
/// </summary>
/// <param name="shopIds">店铺ID列表</param>
/// <returns>服务器异步任务ID;为 0 表示服务器已直接完成</returns>
/// <exception cref="Exception"></exception>
public async Task<bool> PullRefundOrder(long[] shopIds, DateTime startTime, DateTime endTime)
{
TimeSpan time = endTime - startTime;
if (time.TotalDays > 7) throw new Exception("时间范围最大7天");
string data = JsonConvert.SerializeObject(new
{
platformCode = "WEISHOP",
shopIdList = shopIds,
startTime = startTime.ToString("yyyy-MM-dd HH:mm:ss"),
endTime = endTime.ToString("yyyy-MM-dd HH:mm:ss"),
clientUserName = BaseClass.UserName,
remark = $"同步售后订单"
});
var result = await PostAndGetTaskIdAsync("/prod-api/api/oms-api/client/sync/oms/pull_refund_order", data);
if (result.Code == 200)
{
return true;
}
else
{
string msg = string.Join("\n", result.Data.Select(a => $"{a.shopName},{a.message}"));
throw new Exception(msg);
}
}
/// <summary>
/// 拉取指定商铺的售后订单
/// </summary>
/// <param name="shopId">店铺ID</param>
/// <param name="afterSaleOrderIds">售后订单号列表</param>
/// <returns>服务器异步任务ID;为 0 表示服务器已直接完成</returns>
/// <exception cref="Exception"></exception>
public async Task<bool> PullAfterSaleOrders(long shopId, string[] afterSaleOrderIds)
{
string data = JsonConvert.SerializeObject(new
{
platformCode = "WEISHOP",
shopId = shopId,
afterSaleOrderIds = afterSaleOrderIds,
clientUserName = BaseClass.UserName,
remark = $"同步售后订单"
});
var result = await PostAndGetTaskIdAsync("/prod-api/api/oms-api/client/sync/oms/pull_list/batch", data);
if (result.Code == 200)
{
return true;
}
else
{
string msg = string.Join("\n", result.Data.Select(a => $"{a.shopName},{a.message}"));
throw new Exception(msg);
}
}
/// <summary>
/// 提交拉取请求并从返回结果中解析服务器异步任务ID。
/// 兼容 data 为纯数字、数字字符串或对象(含 taskId/task_id/id 字段)等返回格式;
/// 无法解析时返回 0(视为服务器直接完成)。
/// </summary>
private async Task<PullWXOrderResult> PostAndGetTaskIdAsync(string url, string data)
{
var result = await ERPHttp.e57PostResponseAsync<PullWXOrderResult>(url, data);
if (result.Code != 200) throw new Exception(result.Msg);
return result;
}
}
}
+39
View File
@@ -0,0 +1,39 @@
using AllBase;
using CefSharp.DevTools.FedCm;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using Work.ERP.API.Orders;
using WxOrder.Framework.Commons;
namespace Work.ERP.API.Orders
{
public class ShipGiftServiceApi
{
public async Task<bool> SendShipGift(string[] orderIds, int giftType, decimal amount, decimal oemGiftAmount)
{
string data = JsonConvert.SerializeObject(new
{
platformCode = "WEISHOP",
orderIds = orderIds,
userId = BaseClass.UserId,
userName = BaseClass.UserName,
giftOrderType = (int)giftType,
amount = (int)(amount * 100),
oemAmount = (int)(oemGiftAmount * 100)
});
Debug.WriteLine($"礼品单:{data}");
var result = await ERPHttp.e57PostResponseAsync<Result>("/prod-api/api/oms-api/gift/order/deliveryFor29Erp", data);
if (result.Code != 200)
{
throw new Exception(result.Msg);
}
return true;
}
}
}
+26
View File
@@ -0,0 +1,26 @@
using System.ComponentModel;
namespace Work.ERP.API
{
/// <summary>
/// 服务器异步任务状态(与任务状态表字段一致:1=执行中,2=已完成,3=已人为中断)
/// </summary>
public enum TaskStatus
{
/// <summary>
/// 执行中
/// </summary>
[Description("执行中")]
Executing = 1,
/// <summary>
/// 已完成
/// </summary>
[Description("已完成")]
Completed = 2,
/// <summary>
/// 已人为中断
/// </summary>
[Description("已人为中断")]
ManuallyInterrupted = 3
}
}
+112
View File
@@ -0,0 +1,112 @@
using AllBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using WxOrder.Framework.Commons;
namespace Work.KJDServer.API
{
public class KJDServerHttp
{
public static async Task<string> PostAsync(string url, string data)
{
if (url.StartsWith("/"))
url = url.Substring(1);
url = BaseClass.LoginApiUrl + "/wxxd_" + url + "?obj=" + BaseClass.MainPath + "/wxxd_" + url;
string sign = UserLogin.GetSignaturex();
data = $"{sign}&{data}";
return await _postAsync(url, data);
}
public static async Task<T> PostAsync<T>(string url, string data) where T : Result, new()
{
try
{
string result = await PostAsync(url, data);
return JsonConvert.DeserializeObject<T>(result);
}
catch (JsonException)
{
return new T { Code = 0, Msg = "数据解析失败" };
}
catch (Exception ex)
{
return new T { Code = 0, Msg = ex.Message };
}
}
private static async Task<string> _postAsync(string url, string postData, int timeOut = -1)
{
HttpWebResponse response = null;
string result;
try
{
HttpWebRequest request;
request = (HttpWebRequest)WebRequest.Create(url);
request.KeepAlive = true;
request.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36";
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
request.Method = "POST";
request.ServicePoint.Expect100Continue = false;
string body = postData;
byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(body);
request.ContentLength = postBytes.Length;
Stream stream = request.GetRequestStream();
stream.Write(postBytes, 0, postBytes.Length);
stream.Close();
response = (HttpWebResponse)await request.GetResponseAsync();
}
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.ProtocolError)
{
response = (HttpWebResponse)ex.Response;
result = ReadResponse(response);
return result;
}
else return ex.Message;
}
catch (Exception e)
{
if (response != null) response.Close();
return e.Message;
}
result = ReadResponse(response);
return result;
}
public static string ReadResponse(HttpWebResponse response, Encoding encoding = null)
{
using (Stream responseStream = response.GetResponseStream())
{
Stream streamToRead = responseStream;
if (response.ContentEncoding.ToLower().Contains("gzip"))
{
streamToRead = new GZipStream(streamToRead, CompressionMode.Decompress);
}
else if (response.ContentEncoding.ToLower().Contains("deflate"))
{
streamToRead = new DeflateStream(streamToRead, CompressionMode.Decompress);
}
if (encoding == null) encoding = Encoding.UTF8;
using (StreamReader streamReader = new StreamReader(streamToRead, encoding))
{
return streamReader.ReadToEnd();
}
}
}
}
}
+43
View File
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Work.KJDServer.API.Models
{
public class OrderTask
{
public int Id { get; set; }
public int TaskType { get; set; }
public string TaskDescribe { get; set; }
public string ShopId { get; set; }
public string ShopName { get; set; }
public string ObjectIds { get; set; }
public int SubTaskNum { get; set; }
public int SuccessTaskNum { get; set; }
public int FailTaskNum { get; set; }
public int Status { get; set; }
public string CreateBy { get; set; }
public string UpdateBy { get; set; }
public string Remark { get; set; }
public string TaskFailReason { get; set; }
public DateTime CreateTime { get; set; }
public DateTime UpdateTime { get; set; }
}
}
@@ -0,0 +1,30 @@
using AllBase;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Work.KJDServer.API.Models;
using WxOrder.Framework.Commons;
namespace Work.KJDServer.API.WXOrder
{
public class WxOrderServiceApi
{
public WxOrderServiceApi()
{
}
public async Task<List<OrderTask>> GetWxTaskStatus()
{
var ret = await KJDServerHttp.PostAsync<Result<List<OrderTask>>>("order/wx_get_task_status_list", "");
if (ret.Code == 200)
{
return ret.Data;
}
return null;
}
}
}
+3 -18
View File
@@ -659,7 +659,7 @@ namespace Work._29Tools.BLL
return result;
}
public static async Task<string> e57PostResponseAsync(string _url, string _data, string referer)
public static async Task<string> e57PostResponseAsync(string _url, string _data)
{
//await Task.Delay(2000);
//return await Task.FromResult("<AjaxResult><msg>SUCCESS</msg><code>200</code></AjaxResult>");
@@ -694,26 +694,11 @@ namespace Work._29Tools.BLL
}
else
request = (HttpWebRequest)WebRequest.Create(url);
request.KeepAlive = true;
//request.Headers.Set(HttpRequestHeader.CacheControl, "max-age=0");
//request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36";
request.ContentType = "application/json";
//request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"; //request.Accept = "*/*";
//request.Referer = referer;
//request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
//request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
request.Headers.Add("sec-ch-ua", @"""Not(A:Brand"";v=""8"", ""Chromium"";v=""144"", ""Google Chrome"";v=""144""");
request.Headers.Add("sec-ch-ua-mobile", @"?0");
request.Headers.Add("sec-ch-ua-platform", @"""Windows""");
request.Headers.Add("Upgrade-Insecure-Requests", @"1");
request.Headers.Add("Authorization", "Bearer " + sAuthorization);
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7";
request.Headers.Add("Sec-Fetch-Site", @"none");
request.Headers.Add("Sec-Fetch-Mode", @"navigate");
request.Headers.Add("Sec-Fetch-User", @"?1");
request.Headers.Add("Sec-Fetch-Dest", @"document");
request.Accept = "application/json";
request.Headers.Set(HttpRequestHeader.Cookie, "Admin-Token=" + sAuthorization);
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");