Browse Source

库存 配送费 库存

master
Lemon 6 years ago
parent
commit
b16bc29d69
  1. 4
      app/Controller/v3/OrderOnlineController.php
  2. 2
      app/Service/v3/Implementations/AppointmentTimeService.php
  3. 10
      app/Service/v3/Implementations/DistributionPriceService.php
  4. 3
      app/Service/v3/Implementations/GoodsActivityService.php
  5. 3
      app/Service/v3/Implementations/GoodsService.php
  6. 1
      app/Service/v3/Implementations/UserAddressService.php
  7. 7
      config/config.php

4
app/Controller/v3/OrderOnlineController.php

@ -106,8 +106,8 @@ class OrderOnlineController extends BaseController
if(!empty($address->lng) && !empty($address->lat)){ if(!empty($address->lng) && !empty($address->lat)){
$distance = $this->locationService->getDistanceByTencent($market->lng,$market->lat,$address->lng,$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); $distributionPrice = $this->distributionPriceService->do($distance);
$res['location'] = [ $res['location'] = [
'address' => $address, 'address' => $address,

2
app/Service/v3/Implementations/AppointmentTimeService.php

@ -44,7 +44,7 @@ class AppointmentTimeService implements AppointmentTimeServiceInterface
$nowTime = time(); $nowTime = time();
//服务站最晚营业时间 //服务站最晚营业时间
if (env('APP_ENV') === 'prod') { if (env('APP_ENV') === 'prod') {
$closedTime = strtotime(config('market_rest_time'));
$closedTime = strtotime(config('market.rest_time'));
if($nowTime > $closedTime){ if($nowTime > $closedTime){
throw new ErrorCodeException(ErrorCode::MARKET_REST); throw new ErrorCodeException(ErrorCode::MARKET_REST);
} }

10
app/Service/v3/Implementations/DistributionPriceService.php

@ -7,28 +7,28 @@ use App\Constants\v3\ErrorCode;
use App\Exception\ErrorCodeException; use App\Exception\ErrorCodeException;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use App\Service\v3\Interfaces\DistributionPriceServiceInterface; use App\Service\v3\Interfaces\DistributionPriceServiceInterface;
class DistributionPriceService implements DistributionPriceServiceInterface class DistributionPriceService implements DistributionPriceServiceInterface
{ {
public function do($distance) public function do($distance)
{ {
$deliveryDistance = config('distance.delivery_distance');
$deliveryDistance = ceil($deliveryDistance/1000);
$km = ceil($distance/1000); $km = ceil($distance/1000);
switch ($km){
switch (true){
case ($km > 3 && $km < 5) : case ($km > 3 && $km < 5) :
$distributionRrice = bcmul(0.70,($km-3),2); $distributionRrice = bcmul(0.70,($km-3),2);
break; break;
case ($km >= 5 && $km < 7) : case ($km >= 5 && $km < 7) :
$distributionRrice = bcmul(1.00,($km-3),2); $distributionRrice = bcmul(1.00,($km-3),2);
break; break;
case ($km >= 7 && $km < 8) :
case ($km >= 7 && $km < $deliveryDistance) :
$distributionRrice = bcmul(1.50,($km-3),2); $distributionRrice = bcmul(1.50,($km-3),2);
break; break;
case ($km >= 8) :
case ($km >= $deliveryDistance) :
throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE); throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE);
break; break;
default: default:
$distributionRrice = 0; $distributionRrice = 0;
break;
} }
$distributionRrice = bcadd($distributionRrice,3.50,2); $distributionRrice = bcadd($distributionRrice,3.50,2);
return (float) $distributionRrice; return (float) $distributionRrice;

3
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)){ if($goods->is_infinite != 1 && $goods->inventory < ($num+$inventoryFrozen)){
return ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR; return ErrorCode::GOODS_ACTIVITY_INVENTORY_ERROR;
} }

3
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)){ if($goods->is_infinite != 1 && $goods->inventory < ($num+$inventoryFrozen)){
return ErrorCode::GOODS_INVENTORY_ERROR; return ErrorCode::GOODS_INVENTORY_ERROR;
} }

1
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)){ if(empty($address['address']->lng) || empty($address['address']->lat) || empty($market->lng) || empty($market->lat)){
throw new ErrorCodeException(ErrorCode::LOCATION_USER_ADDRESS); 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); $distance = $this->locationService->getDistanceByTencent($address['address']->lng,$address['address']->lat,$market->lng,$market->lat);
$distributionPrice = $this->distributionPriceService->do($distance); $distributionPrice = $this->distributionPriceService->do($distance);
$res['address'] = $address; $res['address'] = $address;

7
config/config.php

@ -55,8 +55,13 @@ return [
'login' => [ 'login' => [
'authkey' => env('STORE_LOGIN_AUTHKEY', ''), 'authkey' => env('STORE_LOGIN_AUTHKEY', ''),
], ],
'market_rest_time' => env('MARKET_REST_TIME', '19:30'),
'market' => [
'rest_time' => env('MARKET_REST_TIME', '19:30'),
],
'map' => [ 'map' => [
'tencent' => env('TENCENT_MAP_KEY', ''), 'tencent' => env('TENCENT_MAP_KEY', ''),
], ],
'distance' => [
'delivery_distance' => env('DELIVERY_DISTANCE', '8000')
],
]; ];
Loading…
Cancel
Save