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.
46 lines
1.4 KiB
46 lines
1.4 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) :
|
|
$distributionRrice = bcmul(0.70,($km-3),2);
|
|
break;
|
|
case ($km >= 5 && $km < 7) :
|
|
$distributionRrice = bcmul(1.00,($km-3),2);
|
|
break;
|
|
case ($km >= 7 && $km <= $deliveryDistance) :
|
|
$distributionRrice = bcmul(1.50,($km-3),2);
|
|
break;
|
|
case ($km > $deliveryDistance) :
|
|
throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE);
|
|
break;
|
|
default:
|
|
$distributionRrice = 0;
|
|
}
|
|
$distributionRrice = bcadd($distributionRrice,3.50,2);
|
|
return (float) $distributionRrice;
|
|
}
|
|
|
|
public function check()
|
|
{
|
|
// TODO: Implement check() method.
|
|
}
|
|
|
|
public function undo()
|
|
{
|
|
// TODO: Implement undo() method.
|
|
}
|
|
}
|