完善运费插件
This commit is contained in:
parent
acfad8a621
commit
6fa5818e82
|
|
@ -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");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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' => '运费',
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
/**
|
||||
* bootstrap.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author Edward Yang <yangjin@opencart.cn>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue