【优化】调整运费计算逻辑为异步处理。

This commit is contained in:
jianweie code
2023-04-03 02:30:16 +08:00
parent a87569c36d
commit 8b7377de63
5 changed files with 19 additions and 17 deletions

View File

@@ -99,7 +99,7 @@ namespace CoreCms.Net.IServices
/// <param name="cartDto">购物车信息</param> /// <param name="cartDto">购物车信息</param>
/// <param name="areaId">收货地址id</param> /// <param name="areaId">收货地址id</param>
/// <returns></returns> /// <returns></returns>
bool CartFreight(CartDto cartDto, int areaId); Task<bool> CartFreight(CartDto cartDto, int areaId);
/// <summary> /// <summary>

View File

@@ -59,7 +59,7 @@ namespace CoreCms.Net.IServices
/// <param name="weight">重量,单位g</param> /// <param name="weight">重量,单位g</param>
/// <param name="totalmoney">商品总价</param> /// <param name="totalmoney">商品总价</param>
/// <returns></returns> /// <returns></returns>
decimal GetShipCost(int areaId = 0, decimal weight = 0, decimal totalmoney = 0); Task<decimal> GetShipCost(int areaId = 0, decimal weight = 0, decimal totalmoney = 0);
/// <summary> /// <summary>
@@ -75,7 +75,7 @@ namespace CoreCms.Net.IServices
/// <summary> /// <summary>
/// 根据地区获取配送方式 /// 根据地区获取配送方式
/// </summary> /// </summary>
CoreCmsShip GetShip(int areaId = 0); Task<CoreCmsShip> GetShip(int areaId = 0);
#region =========================================================== #region ===========================================================

View File

@@ -600,7 +600,8 @@ namespace CoreCms.Net.Services
else if (deliveryType == (int)GlobalEnumVars.OrderReceiptType.Logistics) else if (deliveryType == (int)GlobalEnumVars.OrderReceiptType.Logistics)
{ {
// 运费判断 // 运费判断
if (CartFreight(cartDto, areaId) == false) var blFreight = await CartFreight(cartDto, areaId);
if (blFreight == false)
{ {
jm.data = cartDto; jm.data = cartDto;
jm.msg = "运费判断"; jm.msg = "运费判断";
@@ -665,17 +666,18 @@ namespace CoreCms.Net.Services
#endregion #endregion
#region #region
/// <summary> /// <summary>
/// 算运费 /// 算运费
/// </summary> /// </summary>
/// <param name="cartDto">购物车信息</param> /// <param name="cartDto">购物车信息</param>
/// <param name="areaId">收货地址id</param> /// <param name="areaId">收货地址id</param>
/// <returns></returns> /// <returns></returns>
public bool CartFreight(CartDto cartDto, int areaId) public async Task<bool> CartFreight(CartDto cartDto, int areaId)
{ {
if (areaId > 0) if (areaId > 0)
{ {
cartDto.costFreight = _shipServices.GetShipCost(areaId, cartDto.weight, cartDto.goodsAmount); cartDto.costFreight =await _shipServices.GetShipCost(areaId, cartDto.weight, cartDto.goodsAmount);
cartDto.amount = Math.Round(cartDto.amount + cartDto.costFreight, 2); cartDto.amount = Math.Round(cartDto.amount + cartDto.costFreight, 2);
} }
return true; return true;

View File

@@ -583,7 +583,7 @@ namespace CoreCms.Net.Services
order.shipName = userShipInfo.name; order.shipName = userShipInfo.name;
order.shipMobile = userShipInfo.mobile; order.shipMobile = userShipInfo.mobile;
var ship = _shipServices.GetShip(userShipInfo.areaId); var ship = await _shipServices.GetShip(userShipInfo.areaId);
if (ship != null) if (ship != null)
{ {
order.logisticsId = ship.id; order.logisticsId = ship.id;

View File

@@ -116,24 +116,24 @@ namespace CoreCms.Net.Services
/// <param name="weight">重量,单位g</param> /// <param name="weight">重量,单位g</param>
/// <param name="totalmoney">商品总价</param> /// <param name="totalmoney">商品总价</param>
/// <returns></returns> /// <returns></returns>
public decimal GetShipCost(int areaId = 0, decimal weight = 0, decimal totalmoney = 0) public async Task<decimal> GetShipCost(int areaId = 0, decimal weight = 0, decimal totalmoney = 0)
{ {
decimal postfee = 0; decimal postfee = 0;
var idStr = areaId.ToString(); var idStr = areaId.ToString();
//先判断是否子地区满足条件 //先判断是否子地区满足条件
var def = base.QueryByClause(p => var def = await _dal.QueryByClauseAsync(p =>
p.status == (int)GlobalEnumVars.ShipStatus.Yes && p.status == (int)GlobalEnumVars.ShipStatus.Yes &&
p.areaType == (int)GlobalEnumVars.ShipAreaType.Part && p.areaFee.Contains(idStr)); p.areaType == (int)GlobalEnumVars.ShipAreaType.Part && p.areaFee.Contains(idStr));
//没有子地区取默认 //没有子地区取默认
if (def == null) if (def == null)
{ {
def = base.QueryByClause(p => p.isDefault == true && p.status == (int)GlobalEnumVars.ShipStatus.Yes); def = await _dal.QueryByClauseAsync(p => p.isDefault == true && p.status == (int)GlobalEnumVars.ShipStatus.Yes);
} }
//没有默认取启用状态 //没有默认取启用状态
if (def == null) if (def == null)
{ {
def = base.QueryByClause(p => p.status == (int)GlobalEnumVars.ShipStatus.Yes); def = await _dal.QueryByClauseAsync(p => p.status == (int)GlobalEnumVars.ShipStatus.Yes);
if (def == null) if (def == null)
{//没有配送方式返回0 {//没有配送方式返回0
return postfee; return postfee;
@@ -226,22 +226,22 @@ namespace CoreCms.Net.Services
/// <summary> /// <summary>
/// 根据地区获取配送方式 /// 根据地区获取配送方式
/// </summary> /// </summary>
public CoreCmsShip GetShip(int areaId = 0) public async Task<CoreCmsShip> GetShip(int areaId = 0)
{ {
var idStr = areaId.ToString(); var idStr = areaId.ToString();
//先判断是否子地区满足条件 //先判断是否子地区满足条件
var def = base.QueryByClause(p => var def = await _dal.QueryByClauseAsync(p =>
p.status == (int)GlobalEnumVars.ShipStatus.Yes && p.status == (int)GlobalEnumVars.ShipStatus.Yes &&
p.areaType == (int)GlobalEnumVars.ShipAreaType.Part && p.areaFee.Contains(idStr)); p.areaType == (int)GlobalEnumVars.ShipAreaType.Part && p.areaFee.Contains(idStr));
//没有子地区取默认 //没有子地区取默认
if (def == null) if (def == null)
{ {
def = base.QueryByClause(p => p.isDefault == true && p.status == (int)GlobalEnumVars.ShipStatus.Yes); def = await _dal.QueryByClauseAsync(p => p.isDefault == true && p.status == (int)GlobalEnumVars.ShipStatus.Yes);
} }
//没有默认取启用状态 //没有默认取启用状态
if (def == null) if (def == null)
{ {
def = base.QueryByClause(p => p.status == (int)GlobalEnumVars.ShipStatus.Yes); def = await _dal.QueryByClauseAsync(p => p.status == (int)GlobalEnumVars.ShipStatus.Yes);
return def; return def;
} }
return def; return def;