增加上传取件码

This commit is contained in:
chfei committed 2026-09-23 18:41:51 +08:00
1 parent cfe606eac4
commit 472d052631
7 files changed
+80 -30

No files matched your search

@@ -136,30 +136,18 @@ public class VirtualLogisticsApi : ISingletonDependency
/// </summary>
public Result<List<PickupResultItem>> UploadPickup(List<PickupItem> data)
{
string postdata = $"username={UserName}&data={WebUtility.UrlEncode(Serialize(data))}";
return ServerRequest<List<PickupResultItem>>(new HttpItem
{
URL = "/api/lipin/uploadPickup",
Postdata = postdata,
Postdata = JsonConvert.SerializeObject(new
{
data = data
}),
Method = MethodType.Post
});
}
/// <summary>
/// 使用蛇形命名序列化对象,忽略空值,用于拼接表单参数
/// </summary>
private static string Serialize(object obj)
{
var settings = new JsonSerializerSettings
{
ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
},
NullValueHandling = NullValueHandling.Ignore
};
return JsonConvert.SerializeObject(obj, settings);
}
/// <summary>
@@ -177,7 +165,7 @@ public class VirtualLogisticsApi : ISingletonDependency
}
item.Encoding = Encoding.UTF8;
//item.ProxyIp = "127.0.0.1:8080";
item.ProxyIp = "127.0.0.1:8080";
long unix = DateHelper.GetCurrentUnixTimestampInSeconds();
@@ -119,14 +119,12 @@ public class LogisticsController : ApiControllerBase
/// 上传取件码
/// </summary>
[HttpPost]
public IHttpActionResult UploadPickup(List<PickupItem> data)
public IHttpActionResult UploadPickup(PickupRequest request)
{
try
{
var result = _logisticsService.UploadPickup(data);
return Ok(result.Success
? ApiResult<List<PickupResultItem>>.Success(result.Data, result.Msg)
: ApiResult<List<PickupResultItem>>.Fail(result.Msg, ResultCode.BusinessError, result.Data));
var result = _logisticsService.UploadPickup(request.UserName, request.OrderId, request.PickupCode);
return Ok(ApiResult.Success(result));
}
catch (Exception ex)
{
+17
View File
@@ -0,0 +1,17 @@
using Store.Framework.Dtos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Store.SyncLogistics.Dtos;
public class PickupRequest:SignRequestBase
{
public string OrderId { get; set; }
/// <summary>
/// 取件码
/// </summary>
public string PickupCode { get; set; }
}
@@ -38,4 +38,11 @@ public class YhSyncLogisticsEntity
/// </summary>
[Column(Name = "source_tracking_number")]
public string SourceTrackingNumber { get; set; }
public string pickup_code { get; set; }
public bool? upload_pickup_status { get; set; }
public DateTime? upload_pickup_Time { get; set; }
[Column(Name = "remark")]
public string Remark { get; set; }
}
@@ -12,16 +12,19 @@ public class PickupItem
/// <summary>
/// 上家快递单号
/// </summary>
[JsonProperty("bufa_sn")]
public string BufaSn { get; set; }
/// <summary>
/// 取件码
/// </summary>
[JsonProperty("pickup_code")]
public string PickupCode { get; set; }
/// <summary>
/// 驿站地址
/// </summary>
[JsonProperty("address")]
public string Address { get; set; }
}
@@ -181,9 +181,46 @@ public class VirtualLogisticsService : ITransientDependency
/// <summary>
/// 上传取件码
/// </summary>
public Result<List<PickupResultItem>> UploadPickup(List<PickupItem> data)
public bool UploadPickup(string userName, string orderId, string pickupCode)
{
return _api.UploadPickup(data);
var user = _userService.GetUserByUserName(userName);
if (user == null) throw new Exception("错误的账号");
var syncLogistics = _freeSql.Select<YhSyncLogisticsEntity>()
.Where(a => a.OrderId == orderId)
.First();
if (syncLogistics == null) throw new Exception("错误的订单号");
var ret = _api.UploadPickup(new List<PickupItem>
{
new PickupItem
{
BufaSn = syncLogistics.SourceTrackingNumber,
PickupCode = pickupCode
}
});
syncLogistics.pickup_code = pickupCode;
syncLogistics.upload_pickup_Time = DateTime.Now;
syncLogistics.upload_pickup_status = ret.Success;
if (ret.Success == false)
{
string msg = $"推送取件码失败:{ret.Msg}";
syncLogistics.Remark = msg;
_logger.Error(msg);
throw new Exception("推送取件码失败");
}
var affrows = _freeSql.Update<YhSyncLogisticsEntity>()
.Set(a => a.pickup_code, syncLogistics.pickup_code)
.Set(a => a.upload_pickup_Time, syncLogistics.upload_pickup_Time)
.Set(a => a.upload_pickup_status, syncLogistics.upload_pickup_status)
.Set(a => a.Remark, syncLogistics.Remark)
.Where(a => a.Id == syncLogistics.Id)
.ExecuteAffrows();
if (affrows != 1)
{
_logger.Error("取件码保存错误");
throw new Exception("取件码保存错误");
}
return true;
}
public YhSyncLogisticsEntity GetSyncLogistics(string orderId)
+5 -5
View File
@@ -111,16 +111,16 @@ internal class GiftLogisticsTest
{
new PickupItem
{
BufaSn = "SF1234567890",
BufaSn = "YT0709726946568",
PickupCode = "1-2-3",
Address = "菜鸟驿站"
}
};
var ret = logisticsApi.UploadPickup(data);
Console.WriteLine($"{ret.Code} {ret.Msg}");
if (ret.Data != null)
var logisticsService = _container.Resolve<VirtualLogisticsService>();
var ret = logisticsService.UploadPickup("15222220006","260923-573109716621688","1-2-3");
if (ret)
{
Console.WriteLine(string.Join(" ", ret.Data.Select(a => $"{a.BufaSn}:{a.Success}")));
}
}
}