You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.5 KiB
48 lines
1.5 KiB
<?php
|
|
|
|
|
|
namespace App\Service\v3\Implementations;
|
|
|
|
use App\Constants\v3\ErrorCode;
|
|
use App\Exception\ErrorCodeException;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
use App\Service\v3\Interfaces\DistributionPriceServiceInterface;
|
|
class DistributionPriceService implements DistributionPriceServiceInterface
|
|
{
|
|
public function do($distance)
|
|
{
|
|
|
|
$deliveryDistance = config('distance.delivery_distance');
|
|
$deliveryDistance = ceil($deliveryDistance/1000);
|
|
$km = ceil($distance/1000);
|
|
switch (true){
|
|
case ($km > 3 && $km <= 5) :
|
|
// $distributionPrice = bcmul(0.70,($km-3),2);
|
|
$distributionPrice = 0;
|
|
break;
|
|
case ($km > 5 && $km <= 7) :
|
|
$distributionPrice = bcmul(1.00,($km-3),2);
|
|
break;
|
|
case ($km > 7 && $km <= $deliveryDistance) :
|
|
$distributionPrice = bcmul(1.50,($km-3),2);
|
|
break;
|
|
case ($km > $deliveryDistance) :
|
|
throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE,'',['message' => '超出配送范围', 'data' => ['距离' => $km, '配送距离' => $deliveryDistance]]);
|
|
break;
|
|
default:
|
|
$distributionPrice = 0;
|
|
}
|
|
$distributionPrice = bcadd($distributionPrice,3.50,2);
|
|
return (float) $distributionPrice;
|
|
}
|
|
|
|
public function check()
|
|
{
|
|
// TODO: Implement check() method.
|
|
}
|
|
|
|
public function undo()
|
|
{
|
|
// TODO: Implement undo() method.
|
|
}
|
|
}
|