|
@@ -15,6 +15,7 @@ namespace app\api\controller;
|
|
|
use app\api\model\Cart as CartModel;
|
|
use app\api\model\Cart as CartModel;
|
|
|
use app\api\service\Cart as CartService;
|
|
use app\api\service\Cart as CartService;
|
|
|
use app\common\exception\BaseException;
|
|
use app\common\exception\BaseException;
|
|
|
|
|
+use think\response\Json;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 购物车管理
|
|
* 购物车管理
|
|
@@ -25,13 +26,14 @@ class Cart extends Controller
|
|
|
{
|
|
{
|
|
|
/**
|
|
/**
|
|
|
* 购物车商品列表
|
|
* 购物车商品列表
|
|
|
- * @return array|\think\response\Json
|
|
|
|
|
|
|
+ * @return Json
|
|
|
* @throws BaseException
|
|
* @throws BaseException
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\DbException
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ * @throws \cores\exception\BaseException
|
|
|
*/
|
|
*/
|
|
|
- public function list()
|
|
|
|
|
|
|
+ public function list(): Json
|
|
|
{
|
|
{
|
|
|
// 购物车商品列表
|
|
// 购物车商品列表
|
|
|
$service = new CartService;
|
|
$service = new CartService;
|
|
@@ -43,10 +45,11 @@ class Cart extends Controller
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 购物车商品总数量
|
|
* 购物车商品总数量
|
|
|
- * @return array|\think\response\Json
|
|
|
|
|
|
|
+ * @return Json
|
|
|
* @throws BaseException
|
|
* @throws BaseException
|
|
|
*/
|
|
*/
|
|
|
- public function total() {
|
|
|
|
|
|
|
+ public function total(): Json
|
|
|
|
|
+ {
|
|
|
$model = new CartModel;
|
|
$model = new CartModel;
|
|
|
$cartTotal = $model->getCartTotal();
|
|
$cartTotal = $model->getCartTotal();
|
|
|
return $this->renderSuccess(compact('cartTotal'));
|
|
return $this->renderSuccess(compact('cartTotal'));
|
|
@@ -54,16 +57,16 @@ class Cart extends Controller
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 加入购物车
|
|
* 加入购物车
|
|
|
- * @param int $goodsId 商品id
|
|
|
|
|
|
|
+ * @param int $goodsId 商品ID
|
|
|
* @param string $goodsSkuId 商品sku索引
|
|
* @param string $goodsSkuId 商品sku索引
|
|
|
* @param int $goodsNum 商品数量
|
|
* @param int $goodsNum 商品数量
|
|
|
- * @return array|\think\response\Json
|
|
|
|
|
|
|
+ * @return Json
|
|
|
* @throws BaseException
|
|
* @throws BaseException
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\DbException
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
*/
|
|
*/
|
|
|
- public function add(int $goodsId, string $goodsSkuId, int $goodsNum)
|
|
|
|
|
|
|
+ public function add(int $goodsId, string $goodsSkuId, int $goodsNum): Json
|
|
|
{
|
|
{
|
|
|
$model = new CartModel;
|
|
$model = new CartModel;
|
|
|
if (!$model->add($goodsId, $goodsSkuId, $goodsNum)) {
|
|
if (!$model->add($goodsId, $goodsSkuId, $goodsNum)) {
|
|
@@ -76,16 +79,16 @@ class Cart extends Controller
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 更新购物车商品数量
|
|
* 更新购物车商品数量
|
|
|
- * @param int $goodsId 商品id
|
|
|
|
|
|
|
+ * @param int $goodsId 商品ID
|
|
|
* @param string $goodsSkuId 商品sku索引
|
|
* @param string $goodsSkuId 商品sku索引
|
|
|
* @param int $goodsNum 商品数量
|
|
* @param int $goodsNum 商品数量
|
|
|
- * @return array|\think\response\Json
|
|
|
|
|
|
|
+ * @return Json
|
|
|
* @throws BaseException
|
|
* @throws BaseException
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\DbException
|
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
|
*/
|
|
*/
|
|
|
- public function update(int $goodsId, string $goodsSkuId, int $goodsNum)
|
|
|
|
|
|
|
+ public function update(int $goodsId, string $goodsSkuId, int $goodsNum): Json
|
|
|
{
|
|
{
|
|
|
$model = new CartModel;
|
|
$model = new CartModel;
|
|
|
if (!$model->sUpdate($goodsId, $goodsSkuId, $goodsNum)) {
|
|
if (!$model->sUpdate($goodsId, $goodsSkuId, $goodsNum)) {
|
|
@@ -99,10 +102,10 @@ class Cart extends Controller
|
|
|
/**
|
|
/**
|
|
|
* 删除购物车中指定记录
|
|
* 删除购物车中指定记录
|
|
|
* @param array $cartIds 购物车ID集, 如果为空删除所有
|
|
* @param array $cartIds 购物车ID集, 如果为空删除所有
|
|
|
- * @return array|\think\response\Json
|
|
|
|
|
|
|
+ * @return Json
|
|
|
* @throws BaseException
|
|
* @throws BaseException
|
|
|
*/
|
|
*/
|
|
|
- public function clear(array $cartIds = [])
|
|
|
|
|
|
|
+ public function clear(array $cartIds = []): Json
|
|
|
{
|
|
{
|
|
|
$model = new CartModel;
|
|
$model = new CartModel;
|
|
|
if (!$model->clear($cartIds)) {
|
|
if (!$model->clear($cartIds)) {
|
|
@@ -112,5 +115,4 @@ class Cart extends Controller
|
|
|
$cartTotal = $model->getCartTotal();
|
|
$cartTotal = $model->getCartTotal();
|
|
|
return $this->renderSuccess(compact('cartTotal'), '操作成功');
|
|
return $this->renderSuccess(compact('cartTotal'), '操作成功');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
}
|
|
}
|