12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace app\api\controller\h5;
- use app\hander\HelpHander;
- use think\Db;
- class GCart extends Base
- {
- //添加购物车
- public function addCart(){
- $goodsId=input('goods_id/d',0);
- $ret = model('GCart')->add($goodsId,$this->userId);
- if(!$ret){
- HelpHander::error(model('GCart')->getError());
- }
- HelpHander::success([],'添加成功');
- }
- //购物车列表
- public function cartList(){
- $ret = model('GCart')->lists($this->userId);
- HelpHander::success($ret);
- }
- //购物车加减
- public function updateNum(){
- $id=input('id/d',0);
- $nums=input('nums/d',0);
- $ret = model('GCart')->updateNum($id,$nums);
- if($ret){
- HelpHander::success('成功');
- }else{
- HelpHander::error('失败');
- }
- }
- //购物车删除
- public function cartDel(){
- $id = input('id','');
- if($id == ''){
- HelpHander::error('请选择商品');
- }
- $ret = model('GCart')->whereIn('id',$id)->delete();
- if($ret){
- HelpHander::success('删除成功');
- }else{
- HelpHander::error('删除失败');
- }
- }
- }
|