ExpressService.php 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace bizMall\merchant\services;
  3. use bizMall\base\services\BaseService;
  4. use bizMall\merchant\classes\ShopClass;
  5. use common\components\mapUtil;
  6. class ExpressService extends BaseService
  7. {
  8. public static $baseFile = '\bizMall\merchant\classes\ExpressClass';
  9. //计算客户的距离和运费 ssh 2020.5.14
  10. public static function getUserDistance($lng, $lat, $shopId, $extend)
  11. {
  12. $shop = ShopClass::getById($shopId);
  13. $shopLat = isset($shop['lat']) ? $shop['lat'] : '';
  14. $shopLong = isset($shop['long']) ? $shop['long'] : '';
  15. $distance = mapUtil::calculateDistance($shopLong , $shopLat, $lng, $lat);
  16. $perKiloFee = isset($extend['freight']) ? $extend['freight'] : 10;
  17. $freeDistance = isset($extend['freeDistance']) ? $extend['freeDistance'] : 5;
  18. $fee = 0;
  19. if ($distance > $freeDistance * 1000) {
  20. $fee = ceil(($distance - $freeDistance * 1000) / 1000) * $perKiloFee;
  21. }
  22. $showDistance = sprintf("%.1f", ($distance / 1000));
  23. return ['distance' => $distance, 'showDistance' => $showDistance, 'fee' => $fee];
  24. }
  25. }