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.

45 lines
1.4 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Constants\v3\ErrorCode;
  4. use App\Exception\ErrorCodeException;
  5. use Hyperf\Di\Annotation\Inject;
  6. use App\Service\v3\Interfaces\DistributionPriceServiceInterface;
  7. class DistributionPriceService implements DistributionPriceServiceInterface
  8. {
  9. public function do($distance)
  10. {
  11. $deliveryDistance = config('distance.delivery_distance');
  12. $deliveryDistance = ceil($deliveryDistance/1000);
  13. $km = ceil($distance/1000);
  14. switch (true){
  15. case ($km > 3 && $km < 5) :
  16. $distributionRrice = bcmul(0.70,($km-3),2);
  17. break;
  18. case ($km >= 5 && $km < 7) :
  19. $distributionRrice = bcmul(1.00,($km-3),2);
  20. break;
  21. case ($km >= 7 && $km < $deliveryDistance) :
  22. $distributionRrice = bcmul(1.50,($km-3),2);
  23. break;
  24. case ($km >= $deliveryDistance) :
  25. throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE);
  26. break;
  27. default:
  28. $distributionRrice = 0;
  29. }
  30. $distributionRrice = bcadd($distributionRrice,3.50,2);
  31. return (float) $distributionRrice;
  32. }
  33. public function check()
  34. {
  35. // TODO: Implement check() method.
  36. }
  37. public function undo()
  38. {
  39. // TODO: Implement undo() method.
  40. }
  41. }