diff --git a/app/Constants/v3/ErrorCode.php b/app/Constants/v3/ErrorCode.php index e2f7875..2b5c58e 100644 --- a/app/Constants/v3/ErrorCode.php +++ b/app/Constants/v3/ErrorCode.php @@ -83,6 +83,12 @@ class ErrorCode extends AbstractConstants */ const ORDER_REFUND_FAIL = 610; + /** + * 下单失败 + * @Message("订单金额未满起送价") + */ + const ORDER_NOT_ENOUGH_INITIAL_DELIVERY = 611; + /************************************/ /* 支付相关 651-700 */ /************************************/ diff --git a/app/Controller/v3/ShopCartController.php b/app/Controller/v3/ShopCartController.php index 280c474..43975e0 100644 --- a/app/Controller/v3/ShopCartController.php +++ b/app/Controller/v3/ShopCartController.php @@ -3,7 +3,7 @@ namespace App\Controller\v3; use App\Controller\BaseController; -use App\Service\v3\Interfaces\IntialDeliveryServiceInterface; +use App\Service\v3\Interfaces\InitialDeliveryServiceInterface; use Hyperf\Di\Annotation\Inject; use App\Service\v3\Interfaces\ShopCartServiceInterface; @@ -16,7 +16,7 @@ class ShopCartController extends BaseController protected $shopCartService; /** * @Inject - * @var IntialDeliveryServiceInterface + * @var InitialDeliveryServiceInterface */ protected $intialDeliveryService; public function detail() diff --git a/app/Service/v3/Implementations/IntialDeliveryService.php b/app/Service/v3/Implementations/InitialDeliveryService.php similarity index 81% rename from app/Service/v3/Implementations/IntialDeliveryService.php rename to app/Service/v3/Implementations/InitialDeliveryService.php index 5045076..a707d29 100644 --- a/app/Service/v3/Implementations/IntialDeliveryService.php +++ b/app/Service/v3/Implementations/InitialDeliveryService.php @@ -4,10 +4,10 @@ namespace App\Service\v3\Implementations; use App\Constants\v3\SsdbKeys; use App\Model\v3\SystemConfig; -use App\Service\v3\Interfaces\IntialDeliveryServiceInterface; +use App\Service\v3\Interfaces\InitialDeliveryServiceInterface; use Hyperf\Utils\ApplicationContext; use App\TaskWorker\SSDBTask; -class IntialDeliveryService implements IntialDeliveryServiceInterface +class InitialDeliveryService implements InitialDeliveryServiceInterface { public function do() @@ -32,7 +32,7 @@ class IntialDeliveryService implements IntialDeliveryServiceInterface if($intialDelivery === false || empty($intialDelivery)) { $systemConfig = SystemConfig::query()->where('menu_name','initial_delivery_amount')->first(); $intialDelivery = number_format($systemConfig->value,2); - $ssdb->exec('set',SsdbKeys::INTIAL_DELIVERY_AMOUNT,$intialDelivery); + $ssdb->exec('setnx',SsdbKeys::INTIAL_DELIVERY_AMOUNT,$intialDelivery); return $intialDelivery; } return $intialDelivery; diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index f497d07..6899757 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -24,6 +24,7 @@ use App\Service\v3\Interfaces\CouponRecServiceInterface; use App\Service\v3\Interfaces\CouponServiceInterface; use App\Service\v3\Interfaces\GoodsActivityServiceInterface; use App\Service\v3\Interfaces\GoodsServiceInterface; +use App\Service\v3\Interfaces\InitialDeliveryServiceInterface; use App\Service\v3\Interfaces\PaymentServiceInterface; use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface; use App\Service\v3\Interfaces\UserAddressServiceInterface; @@ -93,6 +94,11 @@ class OrderOnlineService implements OrderOnlineServiceInterface */ protected $badgeService; + /** + * @var InitialDeliveryServiceInterface + */ + protected $initialDeliveryService; + /** * 下单 * @param $marketId @@ -252,6 +258,12 @@ class OrderOnlineService implements OrderOnlineServiceInterface throw new ErrorCodeException(ErrorCode::ORDER_TOTAL_AMOUNT_ERROR); } + // 校验订单总金额是否满足起送 + $initDeliveryAmount = $this->initialDeliveryService->get(); + if ($orderAmount < $initDeliveryAmount) { + throw new ErrorCodeException(ErrorCode::ORDER_NOT_ENOUGH_INITIAL_DELIVERY, "[{$initDeliveryAmount}]"); + } + $dataMain = [ 'market_id' => $marketId, 'order_num' => $globalOrderId, diff --git a/app/Service/v3/Interfaces/IntialDeliveryServiceInterface.php b/app/Service/v3/Interfaces/InitialDeliveryServiceInterface.php similarity index 78% rename from app/Service/v3/Interfaces/IntialDeliveryServiceInterface.php rename to app/Service/v3/Interfaces/InitialDeliveryServiceInterface.php index bdb48d3..366c287 100644 --- a/app/Service/v3/Interfaces/IntialDeliveryServiceInterface.php +++ b/app/Service/v3/Interfaces/InitialDeliveryServiceInterface.php @@ -4,7 +4,7 @@ namespace App\Service\v3\Interfaces; -interface IntialDeliveryServiceInterface +interface InitialDeliveryServiceInterface { public function do(); public function check(); diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 140bed5..dff2df8 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -84,5 +84,5 @@ return [ \App\Service\v3\Interfaces\OrderStatisticsServiceInterface::class => \App\Service\v3\Implementations\OrderStatisticsService::class, \App\Service\v3\Interfaces\UserRelationBindServiceInterface::class => \App\Service\v3\Implementations\UserCommunityBindService::class, \App\Service\v3\Interfaces\BadgeServiceInterface::class => \App\Service\v3\Implementations\BadgeService::class, - \App\Service\v3\Interfaces\IntialDeliveryServiceInterface::class => \App\Service\v3\Implementations\IntialDeliveryService::class, + \App\Service\v3\Interfaces\InitialDeliveryServiceInterface::class => \App\Service\v3\Implementations\InitialDeliveryService::class, ];