Ejemplo n.º 1
0
 public function index()
 {
     $category = new \Model\CategoryModel();
     $goods = new \Model\GoodsModel();
     //商品信息
     //给商品实现分页
     $total = $goods->count();
     //model里的__call封装
     $per = 8;
     $page = new \Tool\Page($total, $per);
     //sql语句获得每页商品信息
     $sql = "SELECT a . * , b.cat_name\nFROM sw_goods AS a\nLEFT JOIN sw_category AS b ON a.goods_category_id = b.cat_id  order by goods_id desc " . $page->limit;
     $goods_info = $goods->query($sql);
     //制作页码表
     $pagelist = $page->fpage();
     $this->assign('pagelist', $pagelist);
     $goods_info1 = $goods->where("is_hot=1")->select();
     //分类信息
     $cate_info = $category->select();
     $this->assign('cate_info', $cate_info);
     $this->assign('goods_info', $goods_info);
     $this->assign('goods_info1', $goods_info1);
     $this->assign('user_id', $_SESSION['user_id']);
     $this->display();
 }
Ejemplo n.º 2
0
 public function showlist()
 {
     //取出商品栏目
     $cat_model = new \Model\CategoryModel();
     $cat_list = $cat_model->getTree();
     $this->assign('cat_list', $cat_list);
     //取出商品并分页显示
     $goods_model = new \Model\GoodsModel();
     $pagesize = C('pagesize');
     $count = $goods_model->count();
     $page = new \Think\Page($count, $pagesize);
     //设置分页样式
     $page->lastSuffix = false;
     //不显示末页
     $page->rollPage = 3;
     //一次显示三页
     $page->setConfig('prev', '【上一页】');
     $page->setConfig('next', '【下一页】');
     $page->setConfig('first', '【首页】');
     $page->setConfig('last', '【末页】');
     $page->setConfig('theme', '共 %TOTAL_ROW% 条记录,当前 %NOW_PAGE%/%TOTAL_PAGE%%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
     $pageinfo = $page->show();
     //获取当前页方便跳转
     $nowpage = $page->nowPage;
     $goods_list = $goods_model->order('goods_id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
     $this->assign('goods_list', $goods_list);
     $this->assign('pageinfo', $pageinfo);
     $this->assign('nowpage', $nowpage);
     $this->display();
 }
Ejemplo n.º 3
0
 public function index()
 {
     $goods = D('Goods');
     $category = new \Model\CategoryModel();
     $cat_id = $_GET['category_id'];
     $catslist = $category->getTopIds($cat_id);
     $cate_info = $category->select();
     $goods_info1 = $goods->where("is_hot=1")->select();
     //给商品实现分页
     $per = 8;
     //sql语句获得每页商品信息
     if ($cat_id == "") {
         $total = $goods->count();
         $page = new \Tool\Page($total, $per);
         $sql = "SELECT a . * , b.cat_name\nFROM sw_goods AS a\nLEFT JOIN sw_category AS b ON a.goods_category_id = b.cat_id  order by goods_id desc " . $page->limit;
     } else {
         $total = $goods->where("goods_category_id='{$cat_id}'")->count();
         $page = new \Tool\Page($total, $per);
         $sql = "SELECT a . * , b.cat_name\nFROM sw_goods AS a\nLEFT JOIN sw_category AS b ON a.goods_category_id = b.cat_id where a.goods_category_id='{$cat_id}' order by goods_id desc " . $page->limit;
     }
     $info = $goods->query($sql);
     //制作页码表
     $pagelist = $page->fpage();
     $this->assign('cat_id', $cat_id);
     $this->assign('pagelist', $pagelist);
     //把商品信息传递给模板
     $this->assign('goods_info1', $goods_info1);
     $this->assign('cate_info', $cate_info);
     $this->assign('catslist', $catslist);
     $this->assign('info', $info);
     $this->display();
 }
Ejemplo n.º 4
0
 function __construct()
 {
     parent::__construct();
     $goods = D('Goods');
     $category = new \Model\CategoryModel();
     $goods_info1 = $goods->where("is_hot=1")->select();
     $this->assign('goods_info1', $goods_info1);
     $this->assign('cate_info', $cate_info);
     $cats = $category->frontCats();
     $this->assign('cats', $cats);
 }
Ejemplo n.º 5
0
 public function _initialize()
 {
     //获取购物车中的总商品数和总价格
     $cart_model = new \Model\CartModel();
     $total = $cart_model->getTotal();
     $this->assign('total', $total);
     //取出顶级栏目,用于导航显示
     $cat_model = new \Model\CategoryModel();
     $nav_list = $cat_model->getNav();
     $this->assign('nav_list', $nav_list);
 }
Ejemplo n.º 6
0
 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();
 }
Ejemplo n.º 7
0
 public function detail()
 {
     $goods_id = $_GET['goods_id'] + 0;
     $goods_model = new \Model\GoodsModel();
     $goods_info = $goods_model->find($goods_id);
     //如果没有商品则跳转到首页
     if (empty($goods_info)) {
         header('location:/index.php');
     }
     //取出商品属性
     $attrdata = M('GoodsAttr')->field("a.id,a.attr_id,a.attr_value,b.attr_type,b.attr_name")->join("a left join it_attribute b using(attr_id)")->where("goods_id={$goods_id}")->select();
     //重置数组,把单选属性过滤出来,方便遍历
     $radiodata = array();
     foreach ($attrdata as $v) {
         if ($v['attr_type'] == 1) {
             $radiodata[$v['attr_id']][] = $v;
         }
     }
     $this->assign('radiodata', $radiodata);
     //取出栏目家谱树,用做面包屑导航
     $cat_model = new \Model\CategoryModel();
     $cat_family = $cat_model->getFamily($goods_info['cat_id']);
     $this->assign('cat_family', $cat_family);
     $this->assign('goods_info', $goods_info);
     $this->display();
 }
Ejemplo n.º 8
0
 public function catupdate($cat_id)
 {
     $category = new \Model\CategoryModel();
     if (!empty($_POST)) {
         //收集表单数据
         $info = $category->create();
         $result = $category->save($info);
         if ($result) {
             //跳转
             $this->redirect('category', array(), 2, '修改分类成功');
         }
     }
     $par_info = $category->where("parent_id=0")->select();
     $this->assign('par_info', $par_info);
     $info = $category->find($cat_id);
     $this->assign('info', $info);
     $this->display();
 }