CartController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LikeShop有特色的全开源社交分销电商系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 商业用途务必购买系统授权,以免引起不必要的法律纠纷
  7. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  8. // | 微信公众号:好象科技
  9. // | 访问官网:http://www.likemarket.net
  10. // | 访问社区:http://bbs.likemarket.net
  11. // | 访问手册:http://doc.likemarket.net
  12. // | 好象科技开发团队 版权所有 拥有最终解释权
  13. // +----------------------------------------------------------------------
  14. // | Author: LikeShopTeam-段誉
  15. // +----------------------------------------------------------------------
  16. namespace app\shopapi\controller;
  17. use app\shopapi\logic\Order\CartLogic;
  18. use app\shopapi\validate\CartValidate;
  19. /**
  20. * 购物车
  21. * Class CartController
  22. * @package app\shopapi\controller
  23. */
  24. class CartController extends BaseShopController
  25. {
  26. /**
  27. * @notes 购物车列表
  28. * @return \think\response\Json
  29. * @author 段誉
  30. * @date 2021/7/20 16:29
  31. */
  32. public function lists()
  33. {
  34. return $this->data(CartLogic::getCartLists($this->userId));
  35. }
  36. /**
  37. * @notes 添加
  38. * @return \think\response\Json
  39. * @author 段誉
  40. * @date 2021/7/19 19:10
  41. */
  42. public function add()
  43. {
  44. $params = (new CartValidate())->post()->gocheck('add', ['user_id' => $this->userId]);
  45. $result = CartLogic::addCart($params, $this->userId);
  46. if (true !== $result) {
  47. return $this->fail($result);
  48. }
  49. return $this->success('加入成功');
  50. }
  51. /**
  52. * @notes 删除
  53. * @return \think\response\Json
  54. * @author 段誉
  55. * @date 2021/7/19 19:10
  56. */
  57. public function del()
  58. {
  59. $params = (new CartValidate())->post()->goCheck('del', ['user_id' => $this->userId]);
  60. CartLogic::del($params['cart_id'], $params['user_id']);
  61. return $this->success('删除成功');
  62. }
  63. /**
  64. * @notes 批量删除
  65. * @return \think\response\Json
  66. * @author lbzy
  67. * @datetime 2023-07-17 18:01:35
  68. */
  69. function del_ids()
  70. {
  71. $params = (new CartValidate())->post()->goCheck('delIds', [ 'user_id' => $this->userId ]);
  72. CartLogic::del_ids($params['cart_ids'], $params['user_id']);
  73. return $this->success('删除成功');
  74. }
  75. /**
  76. * @notes 更改 商品item
  77. * @return \think\response\Json
  78. * @author lbzy
  79. * @datetime 2023-07-18 10:53:11
  80. */
  81. function edit_goods_item()
  82. {
  83. $params = (new CartValidate())->post()->goCheck('editSku', [ 'user_id' => $this->userId ]);
  84. CartLogic::edit_goods_item($params);
  85. return $this->success('成功');
  86. }
  87. /**
  88. * @notes 变更购物车数量
  89. * @return \think\response\Json
  90. * @author 段誉
  91. * @date 2021/7/19 19:10
  92. */
  93. public function change()
  94. {
  95. $params = (new CartValidate())->post()->goCheck('change', ['user_id' => $this->userId]);
  96. $result = CartLogic::changeCartNum($params);
  97. if (true !== $result) {
  98. return $this->fail($result);
  99. }
  100. return $this->success();
  101. }
  102. /**
  103. * @notes 选中状态
  104. * @return \think\response\Json
  105. * @author 段誉
  106. * @date 2021/7/19 19:10
  107. */
  108. public function selected()
  109. {
  110. $params = (new CartValidate())->post()->goCheck('selected', ['user_id' => $this->userId]);
  111. CartLogic::selected($params);
  112. return $this->success();
  113. }
  114. /**
  115. * @notes 购物车数量
  116. * @return \think\response\Json
  117. * @author 段誉
  118. * @date 2021/7/19 19:11
  119. */
  120. public function num()
  121. {
  122. return $this->data(CartLogic::getCartNum($this->userId));
  123. }
  124. }