| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- /**
- * User: admin
- * Date Time: 2021/5/21 20:50
- */
- namespace common\components;
- use Yii;
- //运费计算
- class freight
- {
- //模仿达达运费计算
- /**
- * 0km < d <=2 8元
- * 2km < d <=10 每新增1km加2
- * 10km < d <=50 每新增5km 加6
- *
- * 重量
- * 0 <w <=2 kg 不加价
- * 2kg < w <= 10 kg 每增1 kg 加2
- * 10 kg < w <= 50kg 每新增 5kg 加6
- */
- /**
- * @param $startLat
- * @param $starLng
- * @param $endLat
- * @param $endLng
- * @param $weight 重量kg
- */
- public static function getCost($startLat,$starLng,$endLat,$endLng,$weight)
- {
- if($weight > 50 ){
- return "";
- // util::fail("重量太重了哦!");
- }
- //后端计算距离 m
- $phpStatDistance = util::getDistance($startLat, $starLng, $endLat, $endLng);
- $phpStatDistance = $phpStatDistance/1000;
- if($phpStatDistance > 50) {
- return "";
- // util::fail("距离太远了哦!");
- }
- //起步
- $cost = 9;
- //距离计算
- Yii::info("距离为:".$phpStatDistance);
- $phpStatDistance = $phpStatDistance -2;
- if($phpStatDistance > 0){
- if ($phpStatDistance <=10){
- //每新增1km加2
- $phpStatDistanceCeil = ceil($phpStatDistance);
- $diffCost = $phpStatDistanceCeil*2;
- $cost += $diffCost;
- }else{
- //8*2
- $cost += 16;
- }
- if($phpStatDistance > 10){
- //每新增5km 加6
- $diff = ceil(($phpStatDistance - 10) / 5);
- $diffCost = $diff*6;
- $cost += $diffCost;
- }
- }
- //重量计算
- Yii::info("重量为:".$weight);
- $weight = $weight -2;
- if($weight > 0){
- if ($weight <=10){
- //每增1 kg 加2
- $weightCeil = ceil($weight);
- $diffCost = $weightCeil*2;
- $cost += $diffCost;
- $weight = $weight -2;
- }else{
- //8*2
- $cost += 16;
- }
- if($weight > 10){
- //每新增 5kg 加6
- $diff = ceil(($weight - 10) / 5);
- $diffCost = $diff*6;
- $cost += $diffCost;
- }
- }
- return $cost;
- }
- }
|