订单列表增加 同步订单

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

+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
}
}