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.

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