CartController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\workerapi\controller\shops;
  3. use app\workerapi\controller\BaseApiController;
  4. use app\workerapi\lists\shops\ShopCartLists;
  5. use app\workerapi\logic\shops\ShopCartLogic;
  6. use app\workerapi\validate\shops\ShopCartValidate;
  7. /**
  8. * 商城购物车
  9. */
  10. class CartController extends BaseApiController
  11. {
  12. public function addCart()
  13. {
  14. $params = (new ShopCartValidate())->post()->goCheck('add',['worker_id'=>$this->userId]);
  15. $result = ShopCartLogic::add($params);
  16. if(false === $result ){
  17. return $this->fail(ShopCartLogic::getError() ?: '系统错误');
  18. }
  19. return $this->success('加入购物车成功', [], 1, 0);
  20. }
  21. public function cartList()
  22. {
  23. return $this->dataLists(new ShopCartLists());
  24. }
  25. public function delCart()
  26. {
  27. $params = (new ShopCartValidate())->post()->goCheck('delete',['worker_id'=>$this->userId]);
  28. $result = ShopCartLogic::delete($params);
  29. if(false === $result ){
  30. return $this->fail(ShopCartLogic::getError() ?: '系统错误');
  31. }
  32. return $this->success('删除购物车成功', [], 1, 0);
  33. }
  34. public function editCart()
  35. {
  36. $params = (new ShopCartValidate())->post()->goCheck('edit',['worker_id'=>$this->userId]);
  37. $result = ShopCartLogic::edit($params);
  38. if(false === $result ){
  39. return $this->fail(ShopCartLogic::getError() ?: '系统错误');
  40. }
  41. return $this->success('修改购物车成功', [], 1, 0);
  42. }
  43. }