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.2 KiB

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. $km = ceil($distance/1000);
  12. switch ($km){
  13. case ($km > 3 && $km < 5) :
  14. $distributionRrice = bcmul(0.70,($km-3),2);
  15. break;
  16. case ($km >= 5 && $km < 7) :
  17. $distributionRrice = bcmul(1.00,($km-3),2);
  18. break;
  19. case ($km >= 7 && $km < 10) :
  20. $distributionRrice = bcmul(1.50,($km-3),2);
  21. break;
  22. case ($km >= 10) :
  23. throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE);
  24. break;
  25. default:
  26. $distributionRrice = 0;
  27. break;
  28. }
  29. $distributionRrice = bcadd($distributionRrice,3.50,2);
  30. return $distributionRrice;
  31. }
  32. public function check()
  33. {
  34. // TODO: Implement check() method.
  35. }
  36. public function undo()
  37. {
  38. // TODO: Implement undo() method.
  39. }
  40. }