TestController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\wx\services\WxOpenService;
  4. use common\components\miniUtil;
  5. use Yii;
  6. class TestController extends BaseController
  7. {
  8. public $guestAccess = ['show'];
  9. public function actionShow()
  10. {
  11. //基础配送费8元,0-5公里,每公里+1元,5-100公里,6元起,每公里+2元
  12. //5-10公斤,2元起,每公斤+2元,10-15公斤,+12元,超过15公斤,+20元
  13. //00:00 - 06:00 +6元,22:00-24:00 +4元
  14. //恶劣天气,下单高峰期会临时调整价格
  15. //起步价
  16. $baseFee = 8;
  17. $distance = 3300;
  18. $weight = 15.1;
  19. echo "距离 {$distance} 重量:{$weight} <br/>\n";
  20. //0-5公里,每公里+1元,5-100公里,6元起,每公里+2元
  21. $formatDistance = ceil($distance / 1000);
  22. $startKiloFee = 6;
  23. if ($formatDistance < 5) {
  24. $addDistanceFee = bcmul($formatDistance, 1);
  25. } elseif ($formatDistance == 5) {
  26. $addDistanceFee = $startKiloFee;
  27. } else {
  28. $overKilo = bcsub($formatDistance, 5);
  29. $overFee = bcmul($overKilo, 2);
  30. $addDistanceFee = bcadd($startKiloFee, $overFee);
  31. }
  32. //5-10公斤,2元起,每公斤+2元,10-15公斤,+12元,超过15公斤,+20元
  33. $formatWeight = ceil($weight);
  34. if ($formatWeight > 15) {
  35. $addWeightFee = 20;
  36. } elseif ($formatWeight >= 10 && $formatWeight <= 15) {
  37. $addWeightFee = 12;
  38. } elseif ($formatWeight >= 5 && $formatWeight < 10) {
  39. $overWeight = bcsub($formatWeight, 4);
  40. $addWeightFee = bcmul($overWeight, 2);
  41. } else {
  42. $addWeightFee = 0;
  43. }
  44. $addFee = bcadd($addDistanceFee, $addWeightFee, 2);
  45. $totalFee = bcadd($baseFee, $addFee, 2);
  46. //特殊时段费
  47. $timeFee = 0;
  48. $hour = date("G");
  49. //22:00 - 24:00 +4元
  50. if (in_array($hour, [22, 23])) {
  51. $timeFee = 4;
  52. }
  53. //00:00 - 06:00 +6元
  54. if (in_array($hour, [0, 1, 2, 3, 4, 5])) {
  55. $timeFee = 6;
  56. }
  57. $totalFee = bcadd($totalFee, $timeFee, 2);
  58. //恶劣天气和下单高峰费用
  59. $weatherFee = 0;
  60. $totalFee = bcadd($totalFee, $weatherFee, 2);
  61. $showDistance = sprintf("%.1f", ($distance / 1000));
  62. echo "<pre>";
  63. print_r(['distance' => $distance, 'showDistance' => $showDistance, 'fee' => $totalFee]);
  64. }
  65. }