From 04f2ff5d36ac191360653853c77424ce553f5932 Mon Sep 17 00:00:00 2001 From: jianweie code Date: Fri, 30 Aug 2024 21:28:50 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=90=8C=E5=9F=8E=E9=85=8D=E9=80=81=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Cart/CoreCmsCartServices.cs | 48 +++++++++++++++---- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/CoreCms.Net.Services/Cart/CoreCmsCartServices.cs b/CoreCms.Net.Services/Cart/CoreCmsCartServices.cs index beef4e23..d4034d3c 100644 --- a/CoreCms.Net.Services/Cart/CoreCmsCartServices.cs +++ b/CoreCms.Net.Services/Cart/CoreCmsCartServices.cs @@ -721,20 +721,17 @@ namespace CoreCms.Net.Services { return true; } - var store = await _storeServices.QueryByClauseAsync(p => p.isDefault == true); - if (store == null) + //var store = await _storeServices.QueryByClauseAsync(p => p.isDefault == true); + //if (store == null) + //{ + // return true; + //} + + if (string.IsNullOrEmpty(userShip.longitude) || string.IsNullOrEmpty(userShip.latitude)) { return true; } - if (string.IsNullOrEmpty(userShip.longitude) || string.IsNullOrEmpty(userShip.latitude) || string.IsNullOrEmpty(store.longitude) || string.IsNullOrEmpty(store.latitude)) - { - return true; - } - - //第一种调用方法 - var result = MapHelper.GetDistance(Convert.ToDouble(userShip.latitude.Trim()), Convert.ToDouble(userShip.longitude.Trim()), Convert.ToDouble(store.latitude.Trim()), Convert.ToDouble(store.longitude.Trim())); - var allConfigs = await _settingServices.GetConfigDictionaries(); var intraCityServiceBy2Km = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.IntraCityServiceBy2KM).ObjectToDecimal(0); var intraCityServiceBy5Km = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.IntraCityServiceBy5KM).ObjectToDecimal(0); @@ -743,6 +740,24 @@ namespace CoreCms.Net.Services var intraCityServiceBy20Km = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.IntraCityServiceBy20KM).ObjectToDecimal(0); var intraCityServiceByExceed20Km = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.IntraCityServiceByExceed20KM).ObjectToDecimal(0); + + var reshipCoordinate = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ReshipCoordinate); + + double result = 0; + + if (!string.IsNullOrEmpty(reshipCoordinate)) + { + var reshipCoordinateArr = reshipCoordinate.Split(","); + if (reshipCoordinateArr.Length != 2) + { + result = 0; + } + else + { + result = MapHelper.GetDistance(Convert.ToDouble(userShip.latitude.Trim()), Convert.ToDouble(userShip.longitude.Trim()), Convert.ToDouble(reshipCoordinateArr[0].Trim()), Convert.ToDouble(reshipCoordinateArr[1].Trim())); + } + } + if (result is >= 0 and <= 2) cartDto.costFreight = intraCityServiceBy2Km; else if (result is > 2 and <= 5) @@ -765,6 +780,19 @@ namespace CoreCms.Net.Services { cartDto.costFreight = 0; } + cartDto.error = new WebApiCallBack() + { + status = true, + msg = "运费计算成功", + data = result, + otherData = new + { + userShiplatitude = userShip.latitude, + userShiplongitude = userShip.longitude, + reshipCoordinate + } + }; + cartDto.amount = Math.Round(cartDto.amount + cartDto.costFreight, 2); } return true;