示例#1
0
 public function index()
 {
     $CategoryModel = new CategoryGoodsModel();
     $keywords = I('post.keywords') ? I('post.keywords') : I('get.keywords');
     if (empty($keywords)) {
         $this->error('请输入搜索的关键词');
     }
     $search = M('search_keyword')->where(array("name" => $keywords))->find();
     if ($search) {
         M('search_keyword')->save(array("id" => $search["id"], "times" => $search["id"] + 1));
     } else {
         M('search_keyword')->add(array("name" => $keywords, "times" => 1));
     }
     $where['title'] = array('like', "%" . $keywords . "%");
     $GoodsModel = new GoodsModel();
     $count = $GoodsModel->where($where)->count();
     $once = 20;
     $Page = $this->iniPage($count, $once);
     $result = $GoodsModel->getGoodsList($Page, $where);
     $totalPage = ceil($GoodsModel->where($where)->count() / $once);
     $this->assign("CategoryList", $CategoryModel->getCategoryList(0, 1));
     $this->assign('goods', $result);
     $this->assign('keyword', $keywords);
     $this->assign('totalPage', $totalPage);
     if (IS_AJAX) {
         $page = I('get.p', '', 'intval');
         $this->assign('page', $page + 1);
         $this->display('ajgetgoods');
     } else {
         $this->display();
     }
 }
示例#2
0
 public function index()
 {
     $where["status"] = 1;
     if (I('id')) {
         $where['id'] = I('id');
         $page = M('page')->where($where)->find();
     } else {
         $page = M('page')->where($where)->select();
     }
     if (!$page) {
         $this->error('栏目不存在');
     }
     $CategoryModel = new CategoryGoodsModel();
     $this->assign('id', I('id'));
     $this->assign('page', $page);
     $this->assign("CategoryList", $CategoryModel->getCategoryList(0, 1));
     $this->display();
 }
示例#3
0
 public function cate()
 {
     $where['id'] = I('id');
     $CategoryModel = new CategoryGoodsModel();
     $cate = $CategoryModel->where($where)->find();
     if (!$cate) {
         $this->error('栏目不存在');
     }
     $cates = $CategoryModel->where(array("p_id" => I('id')))->select();
     if ($cates) {
         $goods = array();
         $goodsdb = M('goods');
         foreach ($cates as $key => $value) {
             $cids = $CategoryModel->getChild($value["id"]);
             $value["goods"] = $goodsdb->where("status = 1 and cate_id in (" . $cids . ")")->limit("4")->select();
             $goods[] = $value;
         }
         $this->assign("iscate", 1);
     } else {
         $goodsdb = M('goods');
         $GoodsModel = new GoodsModel();
         unset($where);
         $where['cate_id'] = I('get.id', '', 'intval');
         $where['status'] = 1;
         $once = 10;
         $count = M('goods')->where($where)->count();
         $Page = new \Think\Page($count, $once);
         $show = $Page->show();
         $GoodsModel = new GoodsModel();
         $goods = $GoodsModel->getGoodsList($Page, $where);
         $this->assign("iscate", 2);
         $this->assign('page', $show);
     }
     $this->assign('goods', $goods);
     $this->assign('cate', $cate);
     $this->assign("CategoryList", $CategoryModel->getCategoryList(0, 1));
     $this->display();
 }