public function update($cat_id)
 {
     $cat_id = (int) $cat_id;
     $model = new \Model\CategoryModel();
     if (IS_POST) {
         if ($data = $model->create(I('post.'), 2)) {
             //查找自身和下级的cat_id,防止修改表单恶意提交(将自身或者下级作为自身的父级)
             $ids = $model->getChild($cat_id);
             $ids[] = $cat_id;
             $parent_id = (int) I('post.parent_id');
             if (in_array($parent_id, $ids)) {
                 $this->error('不能讲自身和下级栏目作为自身的父级');
             }
             if ($model->save($data) !== false) {
                 $this->success('修改成功', U('showlist'), 1);
                 exit;
             } else {
                 $this->error('修改失败');
             }
         } else {
             $this->error($model->getError());
         }
     }
     //取出要修改栏目的信息
     $info = $model->find($cat_id);
     $this->assign('info', $info);
     //取出要修改的栏目的自身和下级栏目,在修改界面不显示
     $ids = $model->getChild($cat_id);
     $ids[] = $cat_id;
     $this->assign('ids', $ids);
     //取出商品栏目
     $cat_list = $model->getTree();
     $this->assign('cat_list', $cat_list);
     $this->display();
 }
 public function Category()
 {
     $cat_model = new \Model\CategoryModel();
     $goods_model = new \Model\GoodsModel();
     //精品推荐
     $this->goods_best_list = $goods_model->getGoodsByType('best', 3);
     //判断栏目是否是顶级栏目,是就查出该栏目下所有子栏目的商品
     $cat_id = $_GET['cat_id'] + 0;
     $ids = $cat_model->getChild($cat_id);
     if (empty($ids)) {
         //代表自身是子栏目,将自身加入到数组中
         $ids[] = $cat_id;
     }
     $ids = implode(',', $ids);
     //总记录数
     $count = $goods_model->where("cat_id in ({$ids})")->count();
     $pagesize = 2;
     //总页数
     $pagecount = ceil($count / $pagesize);
     //获取页码
     $pageno = isset($_GET['pageno']) ? $_GET['pageno'] : 1;
     if ($pageno < 1) {
         $pageno = 1;
     }
     if ($pageno > $pagecount) {
         $pageno = $pagecount;
     }
     $goods_cat_list = $goods_model->field('goods_id,goods_name,shop_price,goods_thumb')->where("cat_id in ({$ids})")->page($pageno, $pagesize)->select();
     if (isset($_GET['pageno'])) {
         $this->ajaxReturn($goods_cat_list);
         exit;
     } else {
         $this->assign('goods_cat_list', $goods_cat_list);
         $this->assign('pagecount', $pagecount);
         $this->assign('pageno', $pageno);
         $this->assign('cat_id', $cat_id);
         $this->display();
     }
 }