| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- /**
- * User: shish <shish@zhhinc.com>
- * Date: 2019/7/17
- * Time: 14:27
- */
- namespace mini\controllers;
- use common\components\util;
- use common\services\xhCartService;
- use Yii;
- use yii\helpers\Json;
- class CartController extends BaseController
- {
-
- public $enableCsrfValidation = false;
-
- //添加到购物车 shish 2019.7.17
- public function actionAddCart()
- {
- //还有个post参数 multiPriceId
- $post = Yii::$app->request->post();
- $goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0;
- $post['merchantId'] = $this->merchantId;
- $post['createTime'] = date("Y-m-d H:i:s");
- $post['userId'] = $this->userId;
- xhCartService::replace($this->userId, $goodsId, $post);
- util::sendSuccess();
- }
- //获取购物车的列表 shish 2019.7.17
- public function actionGetList()
- {
- $userId = $this->userId;
- $cart = xhCartService::getUserCartList($userId);
- util::sendJson(['cart' => $cart]);
- }
- //删除购物车记录 2019.7.17
- public function actionDelCart()
- {
- $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::failInfo('非法访问');
- }
- $goodsPriceId = $cart['goodsPriceId'];
- xhCartService::delByIds($this->userId, $goodsId, $goodsPriceId, $cart['goodsPriceId']);
- util::sendSuccess('删除成功');
- }
-
- }
|