|
|
@ -6,6 +6,7 @@ use App\Constants\v3\ErrorCode; |
|
|
use App\Exception\ErrorCodeException; |
|
|
use App\Exception\ErrorCodeException; |
|
|
use App\Model\v3\Market; |
|
|
use App\Model\v3\Market; |
|
|
use App\Model\v3\UserAddress; |
|
|
use App\Model\v3\UserAddress; |
|
|
|
|
|
use App\Service\v3\Interfaces\DistributionPriceServiceInterface; |
|
|
use App\Service\v3\Interfaces\LocationServiceInterface; |
|
|
use App\Service\v3\Interfaces\LocationServiceInterface; |
|
|
use App\Service\v3\Interfaces\UserAddressServiceInterface; |
|
|
use App\Service\v3\Interfaces\UserAddressServiceInterface; |
|
|
use Hyperf\Di\Annotation\Inject; |
|
|
use Hyperf\Di\Annotation\Inject; |
|
|
@ -18,6 +19,12 @@ class UserAddressService implements UserAddressServiceInterface |
|
|
*/ |
|
|
*/ |
|
|
protected $locationService; |
|
|
protected $locationService; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @Inject |
|
|
|
|
|
* @var DistributionPriceServiceInterface |
|
|
|
|
|
*/ |
|
|
|
|
|
protected $distributionPriceService; |
|
|
|
|
|
|
|
|
public function do($userAddressId,$user_id,$user_name,$address,$doorplate,$gender,$lat,$lng,$tel,$tags) |
|
|
public function do($userAddressId,$user_id,$user_name,$address,$doorplate,$gender,$lat,$lng,$tel,$tags) |
|
|
{ |
|
|
{ |
|
|
$userAddress = UserAddress::updateOrCreate(['id' => $userAddressId], |
|
|
$userAddress = UserAddress::updateOrCreate(['id' => $userAddressId], |
|
|
@ -71,42 +78,16 @@ class UserAddressService implements UserAddressServiceInterface |
|
|
* @param $marketId |
|
|
* @param $marketId |
|
|
* @return false|float |
|
|
* @return false|float |
|
|
*/ |
|
|
*/ |
|
|
public function getAddressAndDistributionRrice($userAddressId,$marketId) |
|
|
|
|
|
|
|
|
public function getAddressAndDistributionPrice($userAddressId,$marketId) |
|
|
{ |
|
|
{ |
|
|
$address = $this->get($userAddressId); |
|
|
$address = $this->get($userAddressId); |
|
|
$market = Market::query()->select('lng','lat')->find($marketId); |
|
|
$market = Market::query()->select('lng','lat')->find($marketId); |
|
|
$distance = $this->locationService->getDistanceByTencent($address->lng,$address->lat,$market->lng,$market->lat); |
|
|
$distance = $this->locationService->getDistanceByTencent($address->lng,$address->lat,$market->lng,$market->lat); |
|
|
$distributionRrice = $this->calculateDistributionRrice($distance); |
|
|
|
|
|
|
|
|
$distributionPrice = $this->distributionPriceService->do($distance); |
|
|
$res['address'] = $address; |
|
|
$res['address'] = $address; |
|
|
$res['distribution_price'] = $distributionRrice; |
|
|
|
|
|
|
|
|
$res['distribution_price'] = $distributionPrice; |
|
|
return $res; |
|
|
return $res; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @param $distance |
|
|
|
|
|
* @return false|float |
|
|
|
|
|
*/ |
|
|
|
|
|
function calculateDistributionRrice($distance) |
|
|
|
|
|
{ |
|
|
|
|
|
$km = ceil($distance/1000); |
|
|
|
|
|
switch ($km){ |
|
|
|
|
|
case ($km > 3 && $km < 5) : |
|
|
|
|
|
$distributionRrice = bcmul(0.70,($km-3),2); |
|
|
|
|
|
break; |
|
|
|
|
|
case ($km >= 5 && $km < 7) : |
|
|
|
|
|
$distributionRrice = bcmul(1.00,($km-3),2); |
|
|
|
|
|
break; |
|
|
|
|
|
case ($km >= 7 && $km < 10) : |
|
|
|
|
|
$distributionRrice = bcmul(1.50,($km-3),2); |
|
|
|
|
|
break; |
|
|
|
|
|
case ($km >= 10) : |
|
|
|
|
|
throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
$distributionRrice = 0; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
$distributionRrice = bcadd($distributionRrice,3.50,2); |
|
|
|
|
|
return $distributionRrice; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |