|
|
@@ -0,0 +1,38 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace biz\merchant\services;
|
|
|
+
|
|
|
+use biz\base\services\BaseService;
|
|
|
+use biz\merchant\classes\ShopClass;
|
|
|
+use common\components\mapUtil;
|
|
|
+use common\components\stringUtil;
|
|
|
+use common\components\util;
|
|
|
+use Yii;
|
|
|
+
|
|
|
+class ExpressService extends BaseService
|
|
|
+{
|
|
|
+
|
|
|
+ public static $baseFile = '\biz\merchant\classes\ExpressClass';
|
|
|
+
|
|
|
+ //计算客户的距离和运费 shish 2020.5.14
|
|
|
+ public static function getUserDistance($lnt, $lat, $shopId, $extend)
|
|
|
+ {
|
|
|
+ $shop = ShopClass::getById($shopId);
|
|
|
+ $shopLat = isset($shop['lat']) ? $shop['lat'] : '';
|
|
|
+ $shopLong = isset($shop['long']) ? $shop['long'] : '';
|
|
|
+ $distance = mapUtil::calculateDistance($shopLong, $shopLat, $lnt, $lat);
|
|
|
+ $perKiloFee = isset($extend['freight']) ? $extend['freight'] : 10;
|
|
|
+ $freeDistance = isset($extend['freeDistance']) ? $extend['freeDistance'] : 5;
|
|
|
+ $fee = 0;
|
|
|
+ if ($distance > $freeDistance * 1000) {
|
|
|
+ $fee = ceil(($distance - $freeDistance * 1000) / 1000) * $perKiloFee;
|
|
|
+ }
|
|
|
+ if ($distance > 1000) {
|
|
|
+ $showDistance = sprintf("%.1f", ($distance / 1000));
|
|
|
+ } else {
|
|
|
+ $showDistance = $distance . '米';
|
|
|
+ }
|
|
|
+ return ['distance' => $distance, 'showDistance' => $showDistance, 'fee' => $fee];
|
|
|
+ }
|
|
|
+
|
|
|
+}
|