diff --git a/beike/Shop/Providers/PluginServiceProvider.php b/beike/Shop/Providers/PluginServiceProvider.php index 817b24b8..1dc8e435 100644 --- a/beike/Shop/Providers/PluginServiceProvider.php +++ b/beike/Shop/Providers/PluginServiceProvider.php @@ -44,18 +44,22 @@ class PluginServiceProvider extends ServiceProvider $filePath = $bootstrap['file']; $pluginCode = $bootstrap['code']; if (file_exists($filePath)) { - require_once $filePath; $className = "Plugin\\{$pluginCode}\\Bootstrap"; - (new $className)->boot(); + if (method_exists($className, 'boot')) { + (new $className)->boot(); + } + } + + $routePath = "{$pluginBasePath}/{$pluginCode}/routes.php"; + if (file_exists($routePath)) { + Route::prefix('plugin') + ->middleware('web') + ->group(function () use ($routePath) { + $this->loadRoutesFrom($routePath); + }); } $this->loadViewsFrom("{$pluginBasePath}/{$pluginCode}/Views", $pluginCode); - - Route::prefix('plugin') - ->middleware('web') - ->group(function () use ($pluginBasePath, $pluginCode) { - $this->loadRoutesFrom("{$pluginBasePath}/{$pluginCode}/routes.php"); - }); } } } diff --git a/beike/Shop/Services/TotalServices/ShippingService.php b/beike/Shop/Services/TotalServices/ShippingService.php index 51bbdf37..659559c4 100644 --- a/beike/Shop/Services/TotalServices/ShippingService.php +++ b/beike/Shop/Services/TotalServices/ShippingService.php @@ -13,6 +13,7 @@ namespace Beike\Shop\Services\TotalServices; use Beike\Shop\Services\TotalService; +use Illuminate\Support\Str; class ShippingService { @@ -22,7 +23,14 @@ class ShippingService if (empty($shippingMethod)) { return null; } - $amount = 5; + + $pluginCode = Str::studly($shippingMethod); + $className = "Plugin\\{$pluginCode}\\Bootstrap"; + + if (!method_exists($className, 'getShippingFee')) { + throw new \Exception("请在插件 {$className} 实现方法 getShippingFee"); + } + $amount = (float)(new $className)->getShippingFee($totalService); return [ 'code' => 'shipping', 'title' => '运费', diff --git a/beike/Shop/Services/TotalServices/TaxService.php b/beike/Shop/Services/TotalServices/TaxService.php index 1dd97409..b3134c36 100644 --- a/beike/Shop/Services/TotalServices/TaxService.php +++ b/beike/Shop/Services/TotalServices/TaxService.php @@ -20,8 +20,8 @@ class TaxService { $amount = $totalService->amount * 0.02; return [ - 'code' => 'shipping', - 'title' => '运费', + 'code' => 'tax', + 'title' => '税费', 'amount' => $amount, 'amount_format' => currency_format($amount) ]; diff --git a/plugins/FlatShipping/Bootstrap.php b/plugins/FlatShipping/Bootstrap.php new file mode 100644 index 00000000..e7dfa5bd --- /dev/null +++ b/plugins/FlatShipping/Bootstrap.php @@ -0,0 +1,32 @@ + + * @created 2022-07-20 15:35:59 + * @modified 2022-07-20 15:35:59 + */ + +namespace Plugin\FlatShipping; + +class Bootstrap +{ + /** + * @return float + */ + public function getShippingFee($totalService) + { + $amount = $totalService->amount; + $shippingType = plugin_setting('flat_shipping.type', 'fixed'); + $shippingValue = plugin_setting('flat_shipping.value', 0); + if ($shippingType == 'fixed') { + return $shippingValue; + } elseif ($shippingType == 'rate') { + return $amount * $shippingValue / 100; + } else { + return 0; + } + } +}