ExpressService.php 1.1 KB

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