diff --git a/app/Constants/v3/ErrorCode.php b/app/Constants/v3/ErrorCode.php index a4984d8..87d03d1 100644 --- a/app/Constants/v3/ErrorCode.php +++ b/app/Constants/v3/ErrorCode.php @@ -79,4 +79,25 @@ class ErrorCode extends AbstractConstants * @Message("短信发送失败") */ const SMS_SEND_FAILURE = 1003; + + /************************************/ + /* 商品相关 1101-1200 */ + /************************************/ + /** + * 库存不足 + * @Message("库存不足") + */ + const GOODS_INVENTORY_ERROR = 1101; + + /** + * 超过商品购买数量限制 + * @Message("超过商品购买数量限制") + */ + const PURCHASE_LIMIT_ERROR = 1102; + + /** + * 当前特价商品已被购买过 + * @Message("当前特价商品已被购买过") + */ + const SPERCIAL_OFFER_GOODS_ERROR = 1103; } \ No newline at end of file diff --git a/app/Controller/v3/UpdateShopCartController.php b/app/Controller/v3/UpdateShopCartController.php index 292b34f..38820ef 100644 --- a/app/Controller/v3/UpdateShopCartController.php +++ b/app/Controller/v3/UpdateShopCartController.php @@ -3,12 +3,20 @@ namespace App\Controller\v3; use App\Controller\BaseController; +use Hyperf\Di\Annotation\Inject; +use App\Service\v3\Interfaces\UpdateShopCartServiceInterface; class UpdateShopCartController extends BaseController { + /** + * @Inject + * @var UpdateShopCartServiceInterface + */ + protected $updateShopCarService; public function do() { - + $res = $this->updateShopCarService->do($this->request->all()); + return $this->success($res); } public function check(){ diff --git a/app/Service/v3/Implementations/UpdateShopCartService.php b/app/Service/v3/Implementations/UpdateShopCartService.php index 90efa68..01d28c1 100644 --- a/app/Service/v3/Implementations/UpdateShopCartService.php +++ b/app/Service/v3/Implementations/UpdateShopCartService.php @@ -2,13 +2,28 @@ namespace App\Service\v3\Implementations; +use App\Constants\v3\ErrorCode; +use App\Exception\ErrorCodeException; use App\Service\v3\Interfaces\UpdateShopCartServiceInterface; class UpdateShopCartService implements UpdateShopCartServiceInterface { - public function do() + public function do($params) { - // TODO: Implement check() method. + switch ($params['goods_id']) + { + case 1000: + throw new ErrorCodeException(ErrorCode::GOODS_INVENTORY_ERROR); + break; + case 2000: + throw new ErrorCodeException(ErrorCode::PURCHASE_LIMIT_ERROR); + break; + case 3000: + throw new ErrorCodeException(ErrorCode::SPERCIAL_OFFER_GOODS_ERROR); + break; + default: + return true; + } } public function check() diff --git a/app/Service/v3/Interfaces/UpdateShopCartServiceInterface.php b/app/Service/v3/Interfaces/UpdateShopCartServiceInterface.php index fe46b6d..e6fe034 100644 --- a/app/Service/v3/Interfaces/UpdateShopCartServiceInterface.php +++ b/app/Service/v3/Interfaces/UpdateShopCartServiceInterface.php @@ -4,7 +4,7 @@ namespace App\Service\v3\Interfaces; interface UpdateShopCartServiceInterface { - public function do(); + public function do($params); public function check(); diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index b17471f..5e87da1 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -44,4 +44,5 @@ return [ \App\Service\v3\Interfaces\DistributionPriceServiceInterface::class => \App\Service\v3\Implementations\DistributionPriceService::class, \App\Service\v3\Interfaces\AppointmentTimeServiceInterface::class => \App\Service\v3\Implementations\AppointmentTimeService::class, \App\Service\v3\Interfaces\CategoryServiceInterface::class => \App\Service\v3\Implementations\CategoryService::class, + \App\Service\v3\Interfaces\UpdateShopCartServiceInterface::class => \App\Service\v3\Implementations\UpdateShopCartService::class, ]; diff --git a/config/routes.php b/config/routes.php index 74eefc1..8cf4b07 100644 --- a/config/routes.php +++ b/config/routes.php @@ -84,6 +84,7 @@ Router::addGroup('/v3/', function () { Router::post('onlineOrder/confirm', 'App\Controller\v3\OnlineOrderController@do'); Router::post('distributionPrice/get', 'App\Controller\v3\DistributionPriceController@do'); Router::post('category/all', 'App\Controller\v3\CategoryController@all'); + Router::post('UpdateShopCart/update', 'App\Controller\v3\UpdateShopCartController@do'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]); // 需要登录的路由