CartController.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace backend\controllers;
  3. use common\services\xhGoodsService;
  4. use common\services\xhCartService;
  5. use common\services\xhUserService;
  6. use common\components\util;
  7. use Yii;
  8. use yii\web\Controller;
  9. class CartController extends BackendController
  10. {
  11. /**
  12. * 查看用户的购物车
  13. */
  14. public function actionUser()
  15. {
  16. $get = Yii::$app->request->get();
  17. $userId = isset($get['userId']) ? $get['userId'] : 0;
  18. $user = xhUserService::getById($userId);
  19. if($user['merchantId'] != $this->merchantId){
  20. util::stop('非法访问');
  21. }
  22. $cart = xhCartService::getUserCartList($userId);
  23. return $this->render('user', ['cart' => $cart,'user' => $user]);
  24. }
  25. /**
  26. * 购物车的里每个商品明细
  27. */
  28. public function actionDetail()
  29. {
  30. $get = Yii::$app->request->get();
  31. $userId = isset($get['userId']) ? $get['userId'] : 0;
  32. $goodsId = isset($get['goodsId']) ? $get['goodsId'] : 0;
  33. $user = xhUserService::getById($userId);
  34. if($user['merchantId'] != $this->merchantId){
  35. util::stop('非法访问');
  36. }
  37. $cart = xhCartService::getByIds($goodsId, $userId);
  38. $goods = xhGoodsService::getById($goodsId);
  39. return $this->render('detail',['cart' => $cart,'goods' => $goods]);
  40. }
  41. }