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.

47 lines
1.5 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
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. // $distributionPrice = bcmul(0.70,($km-3),2);
  17. $distributionPrice = 0;
  18. break;
  19. case ($km > 5 && $km < 7) :
  20. $distributionPrice = bcmul(1.00,($km-3),2);
  21. break;
  22. case ($km >= 7 && $km <= $deliveryDistance) :
  23. $distributionPrice = bcmul(1.50,($km-3),2);
  24. break;
  25. case ($km > $deliveryDistance) :
  26. throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE,'',['message' => '超出配送范围', 'data' => ['距离' => $km, '配送距离' => $deliveryDistance]]);
  27. break;
  28. default:
  29. $distributionPrice = 0;
  30. }
  31. $distributionPrice = bcadd($distributionPrice,3.50,2);
  32. return (float) $distributionPrice;
  33. }
  34. public function check()
  35. {
  36. // TODO: Implement check() method.
  37. }
  38. public function undo()
  39. {
  40. // TODO: Implement undo() method.
  41. }
  42. }