0
0

GCart.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\api\controller\h5;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. class GCart extends Base
  6. {
  7. //添加购物车
  8. public function addCart(){
  9. $goodsId=input('goods_id/d',0);
  10. $ret = model('GCart')->add($goodsId,$this->userId);
  11. if(!$ret){
  12. HelpHander::error(model('GCart')->getError());
  13. }
  14. HelpHander::success([],'添加成功');
  15. }
  16. //购物车列表
  17. public function cartList(){
  18. $ret = model('GCart')->lists($this->userId);
  19. HelpHander::success($ret);
  20. }
  21. //购物车加减
  22. public function updateNum(){
  23. $id=input('id/d',0);
  24. $nums=input('nums/d',0);
  25. $ret = model('GCart')->updateNum($id,$nums);
  26. if($ret){
  27. HelpHander::success('成功');
  28. }else{
  29. HelpHander::error('失败');
  30. }
  31. }
  32. //购物车删除
  33. public function cartDel(){
  34. $id = input('id','');
  35. if($id == ''){
  36. HelpHander::error('请选择商品');
  37. }
  38. $ret = model('GCart')->whereIn('id',$id)->delete();
  39. if($ret){
  40. HelpHander::success('删除成功');
  41. }else{
  42. HelpHander::error('删除失败');
  43. }
  44. }
  45. }