wyyl/beike/Shop/Services/TotalServices/ShippingService.php

42 lines
1.1 KiB
PHP

<?php
/**
* ShippingService.php
*
* @copyright 2022 opencart.cn - All Rights Reserved
* @link http://www.guangdawangluo.com
* @author Edward Yang <yangjin@opencart.cn>
* @created 2022-07-22 17:58:14
* @modified 2022-07-22 17:58:14
*/
namespace Beike\Shop\Services\TotalServices;
use Beike\Shop\Services\TotalService;
use Illuminate\Support\Str;
class ShippingService
{
public static function getTotal(TotalService $totalService)
{
$shippingMethod = $totalService->shippingMethod;
if (empty($shippingMethod)) {
return null;
}
$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' => '运费',
'amount' => $amount,
'amount_format' => currency_format($amount)
];
}
}