Browse Source

更新购物车 mock

master
Lemon 5 years ago
parent
commit
77fb4603b2
  1. 21
      app/Constants/v3/ErrorCode.php
  2. 10
      app/Controller/v3/UpdateShopCartController.php
  3. 19
      app/Service/v3/Implementations/UpdateShopCartService.php
  4. 2
      app/Service/v3/Interfaces/UpdateShopCartServiceInterface.php
  5. 1
      config/autoload/dependencies.php
  6. 1
      config/routes.php

21
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;
}

10
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(){

19
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()

2
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();

1
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,
];

1
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]]);
// 需要登录的路由

Loading…
Cancel
Save