From b16bc29d69c6fd4df81a9665c2ddfb9d10630ebf Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 17 Sep 2020 20:35:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=93=E5=AD=98=20=20=E9=85=8D=E9=80=81?= =?UTF-8?q?=E8=B4=B9=20=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/OrderOnlineController.php | 4 ++-- .../v3/Implementations/AppointmentTimeService.php | 2 +- .../v3/Implementations/DistributionPriceService.php | 10 +++++----- .../v3/Implementations/GoodsActivityService.php | 3 ++- app/Service/v3/Implementations/GoodsService.php | 3 ++- app/Service/v3/Implementations/UserAddressService.php | 1 - config/config.php | 7 ++++++- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index 9c74126..687e983 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -106,8 +106,8 @@ class OrderOnlineController extends BaseController if(!empty($address->lng) && !empty($address->lat)){ $distance = $this->locationService->getDistanceByTencent($market->lng,$market->lat,$address->lng,$address->lat); } - - if(isset($distance) && $distance < 8000){ + $deliveryDistance = config('distance.delivery_distance'); + if(isset($distance) && $distance < $deliveryDistance){ $distributionPrice = $this->distributionPriceService->do($distance); $res['location'] = [ 'address' => $address, diff --git a/app/Service/v3/Implementations/AppointmentTimeService.php b/app/Service/v3/Implementations/AppointmentTimeService.php index f784317..3ce10c4 100644 --- a/app/Service/v3/Implementations/AppointmentTimeService.php +++ b/app/Service/v3/Implementations/AppointmentTimeService.php @@ -44,7 +44,7 @@ class AppointmentTimeService implements AppointmentTimeServiceInterface $nowTime = time(); //服务站最晚营业时间 if (env('APP_ENV') === 'prod') { - $closedTime = strtotime(config('market_rest_time')); + $closedTime = strtotime(config('market.rest_time')); if($nowTime > $closedTime){ throw new ErrorCodeException(ErrorCode::MARKET_REST); } diff --git a/app/Service/v3/Implementations/DistributionPriceService.php b/app/Service/v3/Implementations/DistributionPriceService.php index 5765ea8..8b84ab9 100644 --- a/app/Service/v3/Implementations/DistributionPriceService.php +++ b/app/Service/v3/Implementations/DistributionPriceService.php @@ -7,28 +7,28 @@ use App\Constants\v3\ErrorCode; use App\Exception\ErrorCodeException; use Hyperf\Di\Annotation\Inject; use App\Service\v3\Interfaces\DistributionPriceServiceInterface; - class DistributionPriceService implements DistributionPriceServiceInterface { public function do($distance) { + $deliveryDistance = config('distance.delivery_distance'); + $deliveryDistance = ceil($deliveryDistance/1000); $km = ceil($distance/1000); - switch ($km){ + switch (true){ 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 < 8) : + case ($km >= 7 && $km < $deliveryDistance) : $distributionRrice = bcmul(1.50,($km-3),2); break; - case ($km >= 8) : + case ($km >= $deliveryDistance) : throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE); break; default: $distributionRrice = 0; - break; } $distributionRrice = bcadd($distributionRrice,3.50,2); return (float) $distributionRrice; diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index 68becdd..97ce98c 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -49,7 +49,8 @@ class GoodsActivityService implements GoodsActivityServiceInterface // 商品库存不足 // 获取冻结的库存 - $inventoryFrozen = (int)$redis->get($inventoryKey); + //$inventoryFrozen = (int)$redis->get($inventoryKey); + $inventoryFrozen = 0; if($goods->is_infinite != 1 && $goods->inventory < ($num+$inventoryFrozen)){ return ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR; } diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index 3a7f0bb..996248f 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -40,7 +40,8 @@ class GoodsService implements GoodsServiceInterface } // 商品库存不足 // 获取冻结的库存 - $inventoryFrozen = (int)$redis->get($inventoryKey); + //$inventoryFrozen = (int)$redis->get($inventoryKey); + $inventoryFrozen = 0; if($goods->is_infinite != 1 && $goods->inventory < ($num+$inventoryFrozen)){ return ErrorCode::GOODS_INVENTORY_ERROR; } diff --git a/app/Service/v3/Implementations/UserAddressService.php b/app/Service/v3/Implementations/UserAddressService.php index 0851fe2..0c30865 100644 --- a/app/Service/v3/Implementations/UserAddressService.php +++ b/app/Service/v3/Implementations/UserAddressService.php @@ -88,7 +88,6 @@ class UserAddressService implements UserAddressServiceInterface if(empty($address['address']->lng) || empty($address['address']->lat) || empty($market->lng) || empty($market->lat)){ throw new ErrorCodeException(ErrorCode::LOCATION_USER_ADDRESS); } - var_dump($address->lng,$market); $distance = $this->locationService->getDistanceByTencent($address['address']->lng,$address['address']->lat,$market->lng,$market->lat); $distributionPrice = $this->distributionPriceService->do($distance); $res['address'] = $address; diff --git a/config/config.php b/config/config.php index ae184a5..106c3e0 100644 --- a/config/config.php +++ b/config/config.php @@ -55,8 +55,13 @@ return [ 'login' => [ 'authkey' => env('STORE_LOGIN_AUTHKEY', ''), ], - 'market_rest_time' => env('MARKET_REST_TIME', '19:30'), + 'market' => [ + 'rest_time' => env('MARKET_REST_TIME', '19:30'), + ], 'map' => [ 'tencent' => env('TENCENT_MAP_KEY', ''), ], + 'distance' => [ + 'delivery_distance' => env('DELIVERY_DISTANCE', '8000') + ], ];