protected static function getIns() { if (!self::$ins instanceof self) { self::$ins = new self(); } return self::$ins; }
<?php /* @Dscribe:购物流程页面商城的核心功能 @Author:GongBiao @Date:2015/07/05 */ header('Content-Type:text/html; charset=utf-8'); define('ACC', true); require('./include/init.php'); //设置一个动作参数,判断用户想干什么,比如是下订单/写地址/提交/清空购物车等 $act = isset($_GET['act']) ? $_GET['act'] : 'buy'; $cart = CartTool::getCart(); //获取购物车实例 $goods = new GoodsModel(); if($act == 'buy'){ //把商品放入购物车 $goods_id = isset($_GET['goods_id']) ? $_GET['goods_id'] + 0 : 0; $num = isset($_GET['num']) ? $_GET['num'] + 0 : 1; if($goods_id){ //$goods_id为真,是想把商品入到购物车里 $g = $goods->find($goods_id); if(!empty($g)){ //说明有商品 //需要判断此商品,是否在回收站 //此商品是否下架 if($g['is_delete'] == 1 || $g['is_on_sale'] == 0){ $msg = '此商品不能购买'; include(ROOT . 'view/front/msg.html'); exit;
<?php define('ACC', true); require './include/init.php'; // 设置一个动作参数,判断用户想干什么,比如是下订单/写地址/提交/清空购物车等 $act = isset($_GET['act']) ? $_GET['act'] : 'buy'; $cart = CartTool::getCart(); // 获取购物车实例 $goods = new GoodsModel(); if ($act == 'buy') { // 这是把商品加到购物车 $goods_id = isset($_GET['goods_id']) ? $_GET['goods_id'] + 0 : 0; $num = isset($_GET['num']) ? $_GET['num'] + 0 : 1; if ($goods_id) { // $goods_id为真,是想把商品放到购物车里 $g = $goods->find($goods_id); if (!empty($g)) { // 有此商品 // 需要判断此商品,是否在回收站 // 此商品是否已下架 if ($g['is_delete'] == 1 || $g['is_on_sale'] == 0) { $msg = '此商品不能购买'; include ROOT . 'view/front/msg.html'; exit; } // 先把商品加到购物车 $cart->addItem($goods_id, $g['goods_name'], $g['shop_price'], $num); // 判断库存够不够 $items = $cart->all(); if ($items[$goods_id]['num'] > $g['goods_number']) { // 库存不够了,把刚才加到购物车的动作撤回!