Browse Source

批量下单

qianyi
shanji 2 years ago
parent
commit
f71e439330
  1. 11
      BBWY.Server.API/Controllers/BatchPurchaseController.cs
  2. 18
      BBWY.Server.Business/PlatformSDK/QuanTanBusiness.cs
  3. 180
      BBWY.Server.Business/PurchaseOrderV2/BatchPurchase/BatchPurchaseBusiness.cs
  4. 6
      BBWY.Server.Model/Db/PurchaseOrder/PurchaseOrderV2.cs
  5. 5
      BBWY.Server.Model/Dto/Request/PurchaseOrder/OnlinePurchase/CreateOnlinePurchaseOrderRequest.cs
  6. 9
      BBWY.Server.Model/Dto/Request/PurchaseOrderV2/BatchPurchase/BatchPurchaseCreateOrderRequest.cs
  7. 15
      BBWY.Server.Model/Dto/Request/PurchaseOrderV2/BatchPurchase/BatchPurchasePreviewOrderRequest.cs
  8. 5
      BBWY.Server.Model/Dto/Response/PurchaseOrder/OnlinePurchase/CreateOnlinePurchaseOrderResponse.cs
  9. 21
      BBWY.Server.Model/Dto/Response/PurchaseOrderV2/BatchPurchase/BatchCreareOrderResponse.cs
  10. 2
      QuanTan.SDK/Model/Request/Order/QuanTanCreateOrderRequest.cs

11
BBWY.Server.API/Controllers/BatchPurchaseController.cs

@ -36,5 +36,16 @@ namespace BBWY.Server.API.Controllers
{ {
return batchPurchaseBusiness.PreviewOrder(request); return batchPurchaseBusiness.PreviewOrder(request);
} }
/// <summary>
/// 批量创建采购单
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost]
public BatchCreareOrderResponse BatchCreateOrder([FromBody] BatchPurchaseCreateOrderRequest request)
{
return batchPurchaseBusiness.BatchCreateOrder(request);
}
} }
} }

18
BBWY.Server.Business/PlatformSDK/QuanTanBusiness.cs

@ -3,6 +3,7 @@ using BBWY.Common.Models;
using BBWY.Server.Model; using BBWY.Server.Model;
using BBWY.Server.Model.Dto; using BBWY.Server.Model.Dto;
using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json;
using QuanTan.SDK.Client; using QuanTan.SDK.Client;
using QuanTan.SDK.Model; using QuanTan.SDK.Model;
using System; using System;
@ -74,20 +75,27 @@ namespace BBWY.Server.Business
address = createOnlinePurchaseOrderRequest.Consignee.Address, address = createOnlinePurchaseOrderRequest.Consignee.Address,
phone = createOnlinePurchaseOrderRequest.Consignee.Mobile, phone = createOnlinePurchaseOrderRequest.Consignee.Mobile,
realName = createOnlinePurchaseOrderRequest.Consignee.ContactName realName = createOnlinePurchaseOrderRequest.Consignee.ContactName
} },
extended = JsonConvert.SerializeObject(new
{
BuyerAccount = createOnlinePurchaseOrderRequest.AppToken,
createOnlinePurchaseOrderRequest.SourceSku,
createOnlinePurchaseOrderRequest.SourceShopName
})
}; };
var qtResponse = quanTanOrderClient.CreateOrder(quantanCreateOrderRequest, createOnlinePurchaseOrderRequest.AppKey, createOnlinePurchaseOrderRequest.AppSecret); var qtResponse = quanTanOrderClient.CreateOrder(quantanCreateOrderRequest, createOnlinePurchaseOrderRequest.AppKey, createOnlinePurchaseOrderRequest.AppSecret);
if (qtResponse.Status != 200) if (qtResponse.Status != 200)
throw new BusinessException(qtResponse.Message); throw new BusinessException(qtResponse.Message);
var payStatus = !string.IsNullOrEmpty(qtResponse.Data.PayStatus) ? qtResponse.Data.PayStatus.ToLower() : string.Empty; var payStatus = !string.IsNullOrEmpty(qtResponse.Data.PayStatus) ? qtResponse.Data.PayStatus.ToLower() : string.Empty;
if (payStatus != "success") //if (payStatus != "success")
throw new BusinessException($"拳探账户余额不足,支付失败,请前往拳探进行手动支付"); // throw new BusinessException($"拳探账户余额不足,支付失败,请前往拳探进行手动支付");
//对接支付接口
return new CreateOnlinePurchaseOrderResponse() return new CreateOnlinePurchaseOrderResponse()
{ {
PurchaseOrderId = qtResponse.Data.OrderId PurchaseOrderId = qtResponse.Data.OrderId,
IsPay = payStatus == "success"
}; };
} }

180
BBWY.Server.Business/PurchaseOrderV2/BatchPurchase/BatchPurchaseBusiness.cs

@ -1,4 +1,5 @@
using BBWY.Common.Models; using BBWY.Common.Models;
using BBWY.Server.Model;
using BBWY.Server.Model.Db; using BBWY.Server.Model.Db;
using BBWY.Server.Model.Dto; using BBWY.Server.Model.Dto;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -104,6 +105,12 @@ namespace BBWY.Server.Business
return list; return list;
} }
/// <summary>
/// 预览订单
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
/// <exception cref="BusinessException"></exception>
public PreviewOrderResponse PreviewOrder(BatchPurchasePreviewOrderRequest request) public PreviewOrderResponse PreviewOrder(BatchPurchasePreviewOrderRequest request)
{ {
/* /*
@ -120,7 +127,7 @@ namespace BBWY.Server.Business
if (request.PurchaseAccountList == null || request.PurchaseAccountList.Count() == 0) if (request.PurchaseAccountList == null || request.PurchaseAccountList.Count() == 0)
throw new BusinessException("缺少采购账号"); throw new BusinessException("缺少采购账号");
var purchaserGroups = request.ProductParamList.GroupBy(p => p.PurchaserId); var skuGroups = request.ProductParamList.GroupBy(p => p.BelongSkuId);
var carIds = new List<object>(); var carIds = new List<object>();
var errorBuilder = new StringBuilder(); var errorBuilder = new StringBuilder();
var freightAmount = 0M; var freightAmount = 0M;
@ -128,9 +135,9 @@ namespace BBWY.Server.Business
var totalAmount = 0M; var totalAmount = 0M;
foreach (var purchaserGroup in purchaserGroups) foreach (var skuGroup in skuGroups)
{ {
var productParamList = purchaserGroup.ToList(); var productParamList = skuGroup.ToList();
try try
{ {
var purchasePlatform = productParamList.FirstOrDefault().PurchasePlatform; var purchasePlatform = productParamList.FirstOrDefault().PurchasePlatform;
@ -154,10 +161,10 @@ namespace BBWY.Server.Business
}).ToList() }).ToList()
}); });
if (purchasePlatform == Model.Enums.Platform.) if (purchasePlatform == Enums.Platform.)
carIds.Add(new { PurchaserId = purchaserGroup.Key, CardId = previewOrderResponse.Extensions }); carIds.Add(new { BelongSkuId = skuGroup.Key, CardId = previewOrderResponse.Extensions });
else if (purchasePlatform == Model.Enums.Platform.) else if (purchasePlatform == Enums.Platform.)
carIds.Add(new { PurchaserId = purchaserGroup.Key, OrderTradeTypeCode = previewOrderResponse.OrderTradeType?.Code }); carIds.Add(new { BelongSkuId = skuGroup.Key, OrderTradeTypeCode = previewOrderResponse.OrderTradeType?.Code });
freightAmount += previewOrderResponse.FreightAmount; freightAmount += previewOrderResponse.FreightAmount;
productAmount += previewOrderResponse.ProductAmount; productAmount += previewOrderResponse.ProductAmount;
@ -166,7 +173,7 @@ namespace BBWY.Server.Business
catch (Exception ex) catch (Exception ex)
{ {
errorBuilder.AppendLine($"采购商:{productParamList.FirstOrDefault().PurchaserName}"); errorBuilder.AppendLine($"采购商:{productParamList.FirstOrDefault().PurchaserName}");
errorBuilder.AppendLine($"店铺SkuId:{string.Join(",", productParamList.Select(p => p.BelongSkuId))}"); errorBuilder.AppendLine($"店铺SkuId:{skuGroup.Key}");
errorBuilder.AppendLine(ex.Message); errorBuilder.AppendLine(ex.Message);
throw new BusinessException(errorBuilder.ToString()); throw new BusinessException(errorBuilder.ToString());
} }
@ -181,9 +188,160 @@ namespace BBWY.Server.Business
}; };
} }
public void BatchCreateOrder() /// <summary>
{ /// 创建订单
/// </summary>
/// <param name="request"></param>
public BatchCreareOrderResponse BatchCreateOrder(BatchPurchaseCreateOrderRequest request)
{
/*
*/
if (request.ProductParamList == null || request.ProductParamList.Count() == 0)
throw new BusinessException("缺少商品参数");
if (request.Consignee == null ||
string.IsNullOrEmpty(request.Consignee.Address) ||
string.IsNullOrEmpty(request.Consignee.Mobile) ||
string.IsNullOrEmpty(request.Consignee.ContactName))
throw new BusinessException("缺少收货人信息");
if (request.PurchaseAccountList == null || request.PurchaseAccountList.Count() == 0)
throw new BusinessException("缺少采购账号");
var successSkuIdList = new List<string>();
var failSkuList = new List<BatchCreareOrderFailDetail>();
var extJArray = JsonConvert.DeserializeObject<JArray>(request.Extensions);
var skuGroups = request.ProductParamList.GroupBy(p => p.BelongSkuId);
foreach (var skuGroup in skuGroups)
{
var productParamList = skuGroup.ToList();
try
{
var firstProductParam = productParamList.FirstOrDefault();
var purchaseAccount = request.PurchaseAccountList.FirstOrDefault(pa => pa.PurchasePlatformId == firstProductParam.PurchasePlatform);
var platformSDKBusiness = platformSDKBusinessList.FirstOrDefault(p => p.Platform == v.PurchasePlatform);
string tradeMode = "", cardId = "";
var extJson = extJArray.FirstOrDefault(j => j.Value<string>("BelongSkuId") == skuGroup.Key);
if (firstProductParam.PurchasePlatform == Enums.Platform.)
cardId = extJson.Value<string>("CardId");
else if (firstProductParam.PurchasePlatform == Enums.Platform.)
tradeMode = extJson.Value<string>("OrderTradeTypeCode");
var createOrderResponse = platformSDKBusinessList.FirstOrDefault(p => p.Platform == firstProductParam.PurchasePlatform)
.FastCreateOrder(new CreateOnlinePurchaseOrderRequest()
{
AppKey = purchaseAccount.AppKey,
AppSecret = purchaseAccount.AppSecret,
AppToken = purchaseAccount.AppToken,
Platform = firstProductParam.PurchasePlatform,
Consignee = request.Consignee,
PurchaseOrderMode = request.PurchaseOrderMode,
Remark = request.Remark,
SourceShopName = request.ShopName,
SourceSku = skuGroup.Key,
CargoParamList = productParamList.Select(p => new CargoParamRequest()
{
ProductId = p.PurchaseProductId,
SkuId = p.PurchaseSkuId,
Quantity = p.Quantity,
SpecId = p.PurchaseSpecId
}).ToList(),
TradeMode = tradeMode,
Extensions = cardId
});
var purchaseOrderSimpleInfo = platformSDKBusinessList.FirstOrDefault(p => p.Platform == firstProductParam.PurchasePlatform).GetOrderSimpleInfo(new GetOrderInfoRequest()
{
AppKey = purchaseAccount.AppKey,
AppSecret = purchaseAccount.AppSecret,
AppToken = purchaseAccount.AppToken,
OrderId = createOrderResponse.PurchaseOrderId,
Platform = firstProductParam.PurchasePlatform
});
var purchaseOrderV2 = new PurchaseOrderV2()
{
Id = createOrderResponse.PurchaseOrderId,
ShopId = request.ShopId,
OrderState = createOrderResponse.IsPay ? Enums.PurchaseOrderState. : Enums.PurchaseOrderState.,
PurchasePlatform = firstProductParam.PurchasePlatform,
ConsigneeContactName = request.Consignee.ContactName,
ConsigneeMobile = request.Consignee.Mobile,
ConsigneeProvince = request.Consignee.Province,
ConsigneeCity = request.Consignee.City,
ConsigneeCounty = request.Consignee.County,
ConsigneeTown = request.Consignee.Town,
ConsigneeAddress = request.Consignee.Address,
PurchaserId = firstProductParam.PurchaserId,
PurchaserName = firstProductParam.PurchaserName,
PurchaseAccountId = purchaseAccount.Id,
PurchaseAmount = purchaseOrderSimpleInfo.TotalAmount,
ProductAmount = purchaseOrderSimpleInfo.ProductAmount,
PurchaseFreight = purchaseOrderSimpleInfo.FreightAmount,
Remark = request.Remark,
CreateTime = DateTime.Now,
PurchaseMethod = Enums.PurchaseMethod.线,
PurchaseOrderMode = request.PurchaseOrderMode
};
if (createOrderResponse.IsPay)
purchaseOrderV2.PayTime = DateTime.Now;
var purchaseOrderSku = new PurchaseOrderSku()
{
Id = idGenerator.NewLong(),
ShopId = request.ShopId,
PurchaseOrderId = createOrderResponse.PurchaseOrderId,
ProductId = firstProductParam.BelongProductId,
SkuId = firstProductParam.BelongSkuId,
Price = firstProductParam.BelongPrice,
SkuTitle = firstProductParam.BelongSkuTitle,
Logo = firstProductParam.BelongLogo,
Quantity = firstProductParam.BelongQuantity,
PurchaseSchemeId = firstProductParam.BelongPurchaseSchemeId,
PurchaseSkuIds = string.Join(",", productParamList.Select(p => p.PurchaseSkuId).ToList()),
PurchaseAmount = purchaseOrderSimpleInfo.TotalAmount,
ProductAmount = purchaseOrderSimpleInfo.ProductAmount,
PurchaseFreight = purchaseOrderSimpleInfo.FreightAmount,
CreateTime = DateTime.Now
};
fsql.Transaction(() =>
{
fsql.Insert(purchaseOrderV2).ExecuteAffrows();
fsql.Insert(purchaseOrderSku).ExecuteAffrows();
});
successSkuIdList.Add(skuGroup.Key);
}
catch (Exception ex)
{
//var errorBuilder = new StringBuilder();
//errorBuilder.AppendLine($"采购商:{productParamList.FirstOrDefault().PurchaserName}");
//errorBuilder.AppendLine($"店铺SkuId:{skuGroup.Key}");
//errorBuilder.AppendLine(ex.Message);
failSkuList.Add(new BatchCreareOrderFailDetail()
{
SkuId = skuGroup.Key,
ErrorMsg = ex.Message
});
//throw new BusinessException(errorBuilder.ToString());
}
}
return new BatchCreareOrderResponse()
{
FailSkuList = failSkuList,
SuccessSkuIdList = successSkuIdList
};
} }
} }
} }

6
BBWY.Server.Model/Db/PurchaseOrder/PurchaseOrderV2.cs

@ -147,8 +147,8 @@ namespace BBWY.Server.Model.Db
/// <summary> /// <summary>
/// 采购平台 /// 采购平台
/// </summary> /// </summary>
[Column(MapType = typeof(int?))]
public int? PurchasePlatform { get; set; } public Enums.Platform? PurchasePlatform { get; set; }
/// <summary> /// <summary>
/// 商家Id /// 商家Id
@ -178,7 +178,7 @@ namespace BBWY.Server.Model.Db
/// 店铺Id /// 店铺Id
/// </summary> /// </summary>
public string ShopId { get; set; } public long ShopId { get; set; }
/// <summary> /// <summary>
/// 签收时间 /// 签收时间

5
BBWY.Server.Model/Dto/Request/PurchaseOrder/OnlinePurchase/CreateOnlinePurchaseOrderRequest.cs

@ -46,5 +46,10 @@
/// 扩展数据 /// 扩展数据
/// </summary> /// </summary>
public string Extensions { get; set; } public string Extensions { get; set; }
public string SourceSku { get; set; }
public string SourceShopName { get; set; }
} }
} }

9
BBWY.Server.Model/Dto/Request/PurchaseOrderV2/BatchPurchase/BatchPurchaseCreateOrderRequest.cs

@ -6,5 +6,14 @@
/// 扩展字段 ,格式参考报价接口返回值 /// 扩展字段 ,格式参考报价接口返回值
/// </summary> /// </summary>
public string Extensions { get; set; } public string Extensions { get; set; }
/// <summary>
/// 下单备注
/// </summary>
public string Remark { get; set; }
public long ShopId { get; set; }
public string ShopName { get; set; }
} }
} }

15
BBWY.Server.Model/Dto/Request/PurchaseOrderV2/BatchPurchase/BatchPurchasePreviewOrderRequest.cs

@ -23,6 +23,21 @@ namespace BBWY.Server.Model.Dto
public string PurchaserId { get; set; } public string PurchaserId { get; set; }
public string PurchaserName { get; set; } public string PurchaserName { get; set; }
public Enums.Platform PurchasePlatform { get; set; } public Enums.Platform PurchasePlatform { get; set; }
public string BelongSkuId { get; set; } public string BelongSkuId { get; set; }
public string BelongProductId { get; set; }
public decimal BelongPrice { get; set; }
public string BelongSkuTitle { get; set; }
public string BelongLogo { get; set; }
public int BelongQuantity { get; set; }
public long BelongPurchaseSchemeId { get; set; }
} }
} }

5
BBWY.Server.Model/Dto/Response/PurchaseOrder/OnlinePurchase/CreateOnlinePurchaseOrderResponse.cs

@ -26,5 +26,10 @@ namespace BBWY.Server.Model.Dto
/// 下单失败的商品信息 /// 下单失败的商品信息
/// </summary> /// </summary>
public IList<string> FailProductMessageList { get; set; } public IList<string> FailProductMessageList { get; set; }
/// <summary>
/// 是否已支付
/// </summary>
public bool IsPay { get; set; }
} }
} }

21
BBWY.Server.Model/Dto/Response/PurchaseOrderV2/BatchPurchase/BatchCreareOrderResponse.cs

@ -0,0 +1,21 @@
using System.Collections.Generic;
namespace BBWY.Server.Model.Dto
{
public class BatchCreareOrderResponse
{
/// <summary>
/// 已经成功下单的SkuId集合
/// </summary>
public IList<string> SuccessSkuIdList { get; set; }
public IList<BatchCreareOrderFailDetail> FailSkuList { get; set; }
}
public class BatchCreareOrderFailDetail
{
public string SkuId { get; set; }
public string ErrorMsg { get; set; }
}
}

2
QuanTan.SDK/Model/Request/Order/QuanTanCreateOrderRequest.cs

@ -9,6 +9,8 @@
public string cartIds { get; set; } public string cartIds { get; set; }
public QuanTanCreateOrderReceipt receipt { get; set; } public QuanTanCreateOrderReceipt receipt { get; set; }
public string extended { get; set; }
} }
public class QuanTanCreateOrderReceipt : QuanTanPreviewOrderReceipt public class QuanTanCreateOrderReceipt : QuanTanPreviewOrderReceipt

Loading…
Cancel
Save