CartController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * User: shish <shish@zhhinc.com>
  4. * Date: 2019/7/17
  5. * Time: 14:27
  6. */
  7. namespace mini\controllers;
  8. use common\components\util;
  9. use common\services\xhCartService;
  10. use Yii;
  11. use yii\helpers\Json;
  12. class CartController extends BaseController
  13. {
  14. public $enableCsrfValidation = false;
  15. //添加到购物车 shish 2019.7.17
  16. public function actionAddCart()
  17. {
  18. //还有个post参数 multiPriceId
  19. $post = Yii::$app->request->post();
  20. $goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0;
  21. $post['merchantId'] = $this->merchantId;
  22. $post['createTime'] = date("Y-m-d H:i:s");
  23. $post['userId'] = $this->userId;
  24. xhCartService::replace($this->userId, $goodsId, $post);
  25. util::sendSuccess();
  26. }
  27. //获取购物车的列表 shish 2019.7.17
  28. public function actionGetList()
  29. {
  30. $userId = $this->userId;
  31. $cart = xhCartService::getUserCartList($userId);
  32. util::sendJson(['cart' => $cart]);
  33. }
  34. //删除购物车记录 2019.7.17
  35. public function actionDelCart()
  36. {
  37. $post = Yii::$app->request->post();
  38. $goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0;
  39. $cart = xhCartService::getByIds($this->userId, $goodsId, $post['goodsPriceId']);
  40. if ($cart['userId'] != $this->userId) {
  41. util::failInfo('非法访问');
  42. }
  43. $goodsPriceId = $cart['goodsPriceId'];
  44. xhCartService::delByIds($this->userId, $goodsId, $goodsPriceId, $cart['goodsPriceId']);
  45. util::sendSuccess('删除成功');
  46. }
  47. }