50 ){ util::fail("重量太重了哦!"); } //后端计算距离 m $phpStatDistance = util::getDistance($startLat, $starLng, $endLat, $endLng); $phpStatDistance = $phpStatDistance/1000; if($phpStatDistance > 50) { util::fail("距离太远了哦!"); } $cost = 8; //起步价 //距离计算 if($phpStatDistance > 10){ //每新增5km 加6 $diff = ceil(($phpStatDistance - 10) / 5); $diffCost = $diff*6; $cost += $diffCost; }elseif ($phpStatDistance <=10 && $phpStatDistance > 2){ //每新增1km加2 $diff = ceil(($phpStatDistance - 2)); $diffCost = $diff*2; $cost += $diffCost; } //重量计算 if($weight > 10){ //每新增 5kg 加6 $diff = ceil(($weight - 10) / 5); $diffCost = $diff*6; $cost += $diffCost; }elseif ($weight <=10 && $weight > 2){ //每增1 kg 加2 $diff = ceil(($weight - 2)); $diffCost = $diff*2; $cost += $diffCost; } return $cost; } }