You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.2 KiB

  1. <?php
  2. namespace api\controllers;
  3. use backend\models\ars\Cart;
  4. use yii\db\ActiveRecord;
  5. use yii\rest\ActiveController;
  6. use Yii;
  7. /**
  8. * @author iron
  9. * @email weiriron@gmail.com
  10. */
  11. class CartController extends CommonController
  12. {
  13. public $modelClass = 'common\models\ars\Cart';
  14. public function actions()
  15. {
  16. $action = parent::actions();
  17. unset($action['index']);
  18. return $action;
  19. }
  20. public function actionIndex()
  21. {
  22. return Cart::find()
  23. ->where(['user_id' => Yii::$app->user->getId()])
  24. ->all();
  25. }
  26. /**
  27. * @return bool
  28. * 更新购物车(增/删商品)
  29. */
  30. public function actionUpdate()
  31. {
  32. $type = Yii::$app->request->post('type');
  33. return Yii::$app->cartLogic->addOrSubGoods($type);
  34. }
  35. /**
  36. * @return ActiveRecord
  37. * 创建商品
  38. */
  39. public function actionCreate()
  40. {
  41. $goodsId = Yii::$app->request->getBodyParam('goodsId');
  42. $count = Yii::$app->request->getBodyParam('count');
  43. $skuId = Yii::$app->request->getBodyParam('skuId');
  44. return Yii::$app->cartLogic->create($goodsId, $count, $skuId);
  45. }
  46. }