layout = 'goodsMain'; $userId = $this->userId; $this->webTitle = '购物车-'.$this->webTitle;//标题 $cart = xhCartService::getUserCartList($userId); return $this->render('index',['cart' => $cart]); } /** * 添加到购物车 */ public function actionAdd() { $post = Yii::$app->request->post(); //dump($post);die; $goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0; $post['merchantId'] = $this->merchantId; $post['createTime'] = date("Y-m-d H:i:s"); $post['userId'] = $this->userId; unset($post['_csrf']); xhCartService::replace($this->userId, $goodsId, $post); util::successInfo('添加成功'); } /** * 删除购物车的一个商品 */ public function actionDel() { $post = Yii::$app->request->post(); $goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0; $cart = xhCartService::getByIds($this->userId, $goodsId, $post['goodsPriceId']); if($cart['userId'] != $this->userId){ util::stop('非法访问'); } $goodsPriceId = $cart['goodsPriceId']; xhCartService::delByIds($this->userId, $goodsId, $goodsPriceId, $cart['goodsPriceId']); util::successInfo('删除成功'); } }