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

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