165 lines
4.0 KiB
C#
165 lines
4.0 KiB
C#
using MAX.Core.Commons;
|
|
using MAX.Core.DependencyInjection;
|
|
using MAX.Core.Logger;
|
|
using Store.Contracts.Order.Entitys;
|
|
using Store.VirtualLogistics.Apis;
|
|
using Store.VirtualLogistics.Entitys;
|
|
using Store.VirtualLogistics.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Store.VirtualLogistics.Services;
|
|
|
|
|
|
public class VirtualLogisticsService : ITransientDependency
|
|
{
|
|
private IFreeSql _freeSql;
|
|
private readonly ILoggerFacade _logger;
|
|
private readonly VirtualLogisticsApi _api;
|
|
|
|
public VirtualLogisticsService(VirtualLogisticsApi api, IFreeSql freeSql, ILoggerFacade logger)
|
|
{
|
|
_freeSql = freeSql ?? throw new ArgumentNullException(nameof(freeSql));
|
|
_logger = logger;
|
|
_api = api;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取账户余额
|
|
/// </summary>
|
|
public decimal GetUserMoney()
|
|
{
|
|
var user = _api.GetUserMoney();
|
|
return user.Money;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取快递列表
|
|
/// </summary>
|
|
public List<ExpressItem> GetExpressList()
|
|
{
|
|
return _api.GetExpressList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取仓库列表及价格
|
|
/// </summary>
|
|
public List<CangItem> GetCangList()
|
|
{
|
|
return _api.GetCangList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取礼品列表及价格
|
|
/// </summary>
|
|
/// <param name="kuaidiId">快递ID,可选</param>
|
|
public List<GoodsItem> GetGoodsList(string kuaidiId = null)
|
|
{
|
|
return _api.GetGoodsList(kuaidiId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 购买快递
|
|
/// </summary>
|
|
public List<YhSyncLogisticsEntity> Buy(string orderId, string ds_orderId)
|
|
{
|
|
var item = _freeSql.Select<OrderPddBuyerOrderEntity>()
|
|
.Where(a => a.OrderSn == orderId)
|
|
.First();
|
|
if (item == null) throw new Exception("错误的订单号");
|
|
|
|
var w_order = _freeSql.Select<WeiOrderEntity>()
|
|
.Where(a => a.OrderId == item.WxOrderId)
|
|
.First();
|
|
|
|
if (w_order == null) throw new Exception("错误的订单号");
|
|
var productItem = _freeSql.Select<WeiOrderItemEntity>()
|
|
.Where(a => a.OrderId == w_order.OrderId)
|
|
.First();
|
|
if (productItem == null) throw new Exception("错误的订单详情号");
|
|
|
|
BuyRequest request = new BuyRequest()
|
|
{
|
|
KuaidiId = "874",
|
|
GoodsId = "8473",
|
|
CangId = "914",
|
|
Platform = 6,
|
|
Auth = 1,
|
|
SendName = RandomNameHelper.GetRandomName(),
|
|
SendMobile = "13024622251",
|
|
SendProvince = "上海市",
|
|
SendCity = "上海市",
|
|
SendDistrict = "普陀区",
|
|
SendAddress = "真如镇街道真北路2653弄F区808号楼",
|
|
RecList = [
|
|
new RecItem
|
|
{
|
|
OrderSn = orderId,
|
|
RecName = w_order.UserName,
|
|
RecMobile = w_order.TelNumber,
|
|
RecProvince = w_order.ProvinceName,
|
|
RecCity = w_order.CityName,
|
|
RecDistrict = w_order.CountyName,
|
|
RecAddress = w_order.DetailInfo,
|
|
EncryptDatas=new EncryptDatas
|
|
{
|
|
DsOrderId=ds_orderId,
|
|
SkuId = productItem.SkuId,
|
|
ProductId = productItem.ProductId,
|
|
SkuCnt = productItem.SkuCnt.ToString(),
|
|
},
|
|
OtherKuaidiSn= "6738192431"//item.TrackingNumber,
|
|
|
|
}
|
|
]
|
|
};
|
|
Result<List<BuyResultItem>> ret = _api.Buy(request);
|
|
if (ret.Success == false)
|
|
{
|
|
_logger.Error($"购买同步单错误:{ret.Msg}");
|
|
throw new Exception("购买同步单失败");
|
|
}
|
|
|
|
|
|
List<YhSyncLogisticsEntity> yhSyncs = new List<YhSyncLogisticsEntity>();
|
|
foreach (var sync in ret.Data)
|
|
{
|
|
yhSyncs.Add(new YhSyncLogisticsEntity
|
|
{
|
|
OrderId = sync.OrderSn,
|
|
TrackingNumber = sync.KuaidiSn,
|
|
SourceTrackingNumber = sync.OtherKuaidiSn
|
|
});
|
|
}
|
|
|
|
var count = _freeSql.Insert<YhSyncLogisticsEntity>(yhSyncs).ExecuteAffrows();
|
|
if (count != yhSyncs.Count)
|
|
{
|
|
_logger.Error("购买同步单提交到数据库错误");
|
|
throw new Exception("记录同步单失败");
|
|
}
|
|
return yhSyncs;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 上传取件码
|
|
/// </summary>
|
|
public Result<List<PickupResultItem>> UploadPickup(List<PickupItem> data)
|
|
{
|
|
return _api.UploadPickup(data);
|
|
}
|
|
|
|
public YhSyncLogisticsEntity GetSyncLogistics(string orderId)
|
|
{
|
|
var item = _freeSql.Select<YhSyncLogisticsEntity>()
|
|
.Where(a => a.OrderId == orderId).First();
|
|
|
|
return item;
|
|
}
|
|
|
|
}
|