Ejemplo n.º 1
0
 public function add_cart()
 {
     import('Think.ORG.Cart');
     // 导入分页类
     $cart = new Cart();
     $goodId = $this->_post('goodId', 'intval');
     //商品ID
     $quantity = $this->_post('quantity', 'intval');
     //购买数量
     $item = M('item')->field('id,title,img,price,goods_stock')->find($goodId);
     if (!is_array($item)) {
         $data = array('status' => 0, 'msg' => '不存在该商品', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } elseif ($item['goods_stock'] < $quantity) {
         $data = array('status' => 0, 'msg' => '没有足够的库存', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } else {
         $result = $cart->addItem($item['id'], $item['title'], $item['price'], $quantity, $item['img']);
         if ($result == 1) {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '该商品已经存在购物车');
         } else {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '商品已成功添加到购物车');
         }
     }
     //$data=array('status'=>2);
     echo json_encode($data);
 }
Ejemplo n.º 2
0
 public function add_cart()
 {
     header("content-Type: text/html; charset=Utf-8");
     import('Think.ORG.Cart');
     // 导入分页类
     $cart = new Cart();
     $goodId = $this->_post('goodId', 'intval');
     //商品ID
     $quantity = $this->_post('quantity', 'intval');
     //购买数量
     $size = $this->_post('size', 'intval');
     //大小
     $color = $this->_post('color', 'trim');
     //颜色
     $item = M('item')->field('id,title,img,price,goods_stock,tokenTall,free,pingyou,kuaidi,ems')->find($goodId);
     $item['size'] = $size;
     $item['color'] = $color;
     //mb_convert_encoding($color, "UTF-8", "GBK");
     if (!is_array($item)) {
         $data = array('status' => 0, 'msg' => '不存在该商品', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } elseif ($item['goods_stock'] < $quantity) {
         $data = array('status' => 0, 'msg' => '没有足够的库存', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } else {
         $result = $cart->addItem($item['id'], $item['title'], $item['price'], $quantity, $item['img'], $item['size'], $item['color'], $item['tokenTall'], $item['free'], $item['pingyou'], $item['kuaidi'], $item['ems']);
         if ($result == 1) {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '该商品已经存在购物车');
         } else {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '商品已成功添加到购物车');
         }
     }
     //$data=array('status'=>2);
     echo json_encode($data);
 }
Ejemplo n.º 3
0
 public function add_cart()
 {
     //导入购物车
     import('@.ORG.Cart');
     $cart = new \Cart();
     $goodId = I('post.goodId', '', 'intval');
     $quantity = I('post.quantity', '', 'intval');
     $item = api('Document/get_detail', array('id' => $goodId));
     if (empty($item)) {
         $data = array('status' => 0, 'msg' => '不存在该商品', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } elseif ($item['shop_goods_stock'] < $quantity) {
         $data = array('status' => 0, 'msg' => '没有足够的库存', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } else {
         $result = $cart->addItem($item['id'], $item['title'], $item['shop_good_price'], $quantity, $item['cover_id']);
         if ($result == 1) {
             //购物车存在该商品
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '该商品已经存在购物车');
         } else {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '商品已成功添加到购物车');
         }
     }
     echo json_encode($data);
 }
Ejemplo n.º 4
0
 public function item_buy()
 {
     import('Think.ORG.Cart');
     // 导入分页类
     $cart = new Cart();
     $goodId = $this->_post('goodId', 'intval');
     //商品ID
     $quantity = $this->_post('quantity', 'intval');
     //购买数量
     $size = $this->_post('size', 'intval');
     //大小
     $color = $this->_post('color', 'trim');
     //颜色
     // dump($goodId.'--'.$quantity.'--'.$size.'--'.$color);
     $item = M('item')->field('id,title,img,price,goods_stock,tokenTall,free,pingyou,kuaidi,ems')->find($goodId);
     $item['size'] = $size;
     $item['color'] = $color;
     //mb_convert_encoding($color, "UTF-8", "GBK");
     if (!is_array($item)) {
         $data = array('status' => 0, 'msg' => '不存在该商品', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } elseif ($item['goods_stock'] < $quantity) {
         $data = array('status' => 0, 'msg' => '没有足够的库存', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } else {
         $result = $cart->addItem($item['id'], $item['title'], $item['price'], $quantity, $item['img'], $item['size'], $item['color'], $item['tokenTall'], $item['free'], $item['pingyou'], $item['kuaidi'], $item['ems']);
         if ($result == 1) {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '该商品已经存在购物车');
         } else {
             $data = array('result' => $result, 'status' => 1, 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice(), 'msg' => '商品已成功添加到购物车');
         }
     }
     $this->redirect("index");
 }
Ejemplo n.º 5
0
 public function change_quantity()
 {
     import('Think.ORG.Cart');
     // 导入购物车类
     $cart = new Cart();
     $itemId = $this->_post('itemId', 'intval');
     //商品ID
     $quantity = $this->_post('quantity', 'intval');
     //购买数量
     $spec_id = $this->_post('spec_id', 'intval');
     //购买数量
     $goods_stock = 0;
     $spec_1 = '';
     $spec_2 = '';
     $price = 0;
     $item = M('item')->field('id,title,img,price,goods_stock')->find($itemId);
     if (!is_array($item)) {
         $data = array('status' => 0, 'msg' => '不存在该商品', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     }
     if ($spec_id == 0) {
         $goods_stock = $item['goods_stock'];
         $price = $item['price'];
     } else {
         $item_spec = M('item_spec')->field('spec_1,spec_2,price,stock')->find($spec_id);
         $goods_stock = $item_spec['stock'];
         $price = $item_spec['price'];
         $spec_1 = $item_spec['spec_1'];
         $spec_2 = $item_spec['spec_2'];
     }
     if ($goods_stock < $quantity) {
         $data = array('status' => 0, 'msg' => '没有足够的库存', 'count' => $cart->getCnt(), 'sumPrice' => $cart->getPrice());
     } else {
         $cart->modNum($itemId, $spec_id, $quantity);
         $data = array('status' => 1, 'item' => $cart->getItem($itemId, $spec_id), 'sumPrice' => $cart->getPrice());
     }
     echo json_encode($data);
 }