public function indexAction()
 {
     $cid = intval($this->param('cid', 0));
     if (!$cid) {
         $url = ComTool::url("index");
         ComTool::redirect($url);
     }
     $category = CategoryData::getById($cid);
     if (!$category) {
         $url = ComTool::url("index");
         ComTool::redirect($url);
     }
     $curTime = time();
     $category['start_time'] = '09:00:00';
     $category['end_time'] = '24:00:00';
     $startTime = strtotime($category['start_time']);
     $endTime = strtotime($category['end_time']);
     $notStart = $curTime < $startTime ? true : false;
     //true为尚未开始
     $isOver = $curTime > $endTime ? true : false;
     //true为已结束
     $isOn = !$notStart && !$isOver;
     //过程中
     $this->assign('notStart', $notStart);
     $this->assign('isOver', $isOver);
     $this->assign('isOn', $isOn);
     $group = GroupData::getById($category['group_id']);
     $store = StoreData::getById($category['store_id']);
     $goods = GoodsData::getsByCid($cid);
     $cart = array();
     $cart = $this->getCart($cid);
     $this->assign('category', $category);
     $this->assign('group', $group);
     $this->assign('store', $store);
     $this->assign('goods', $goods);
     $this->assign('products', $cart['products']);
     $this->assign('totalPrice', $cart['totalPrice']);
     $this->display();
 }
 /**
  * 添加商品
  */
 public function goodsAction()
 {
     if (ComTool::isAjax()) {
         $name = trim($this->post('name'));
         $cid = trim($this->post('c_cat'));
         $price = trim($this->post('price'));
         $priceNum = trim($this->post('price_num'));
         $priceUnit = trim($this->post('price_unit'));
         $desc = trim($this->post('desc'));
         $order = trim($this->post('order'));
         $status = trim($this->post('status'));
         $data = array();
         $data['name'] = $name;
         $data['category_id'] = $cid;
         $data['price'] = $price;
         $data['price_num'] = $priceNum;
         $data['price_unit'] = $priceUnit;
         $data['desc'] = $desc;
         $data['create_time'] = time();
         $data['create_date'] = date("Y-m-d");
         $data['order'] = $order;
         $data['status'] = $status;
         $res = GoodsData::add($data);
         ComTool::result($res, '失败', '成功');
     }
     $goods = GoodsData::getsAll();
     $this->assign('goods', $goods);
     $this->display();
 }
Example #3
0
 /**
  * update cart更新购物车物品数量+-
  */
 public function ucAction()
 {
     if (ComTool::isAjax()) {
         $type = $this->post('type', 'inc');
         $productId = intval($this->post('proid', 0));
         if (!$productId) {
             ComTool::ajax(100001, '服务器忙,请刷新重试');
         }
         $product = GoodsData::getById($productId);
         if (!$product) {
             ComTool::ajax(100001, '服务器忙,请刷新重试');
         }
         $curCategory = $product['category_id'];
         $productInCart = $_SESSION['cart'][$curCategory][$productId];
         $productQuantity = intval($productInCart['quantity']);
         switch ($type) {
             case 'inc':
                 //increment
                 $productInCart['quantity'] = $productQuantity + 1;
                 $_SESSION['cart'][$curCategory][$productId] = $productInCart;
                 break;
             case 'dec':
                 //decrement
                 $productInCart['quantity'] = $productQuantity - 1;
                 if ($productInCart['quantity'] <= 0) {
                     $_SESSION['cart'][$curCategory][$productId] = array();
                     unset($_SESSION['cart'][$curCategory][$productId]);
                 } else {
                     $_SESSION['cart'][$curCategory][$productId] = $productInCart;
                 }
                 break;
             case 'rm':
                 //delete
                 $_SESSION['cart'][$curCategory][$productId] = array();
                 unset($_SESSION['cart'][$curCategory][$productId]);
                 break;
         }
         ComTool::ajax(100000, 'ok');
     }
 }