<?php
class GoodsAction extends IniAction{
    public function goodslist(){
        $where_sort['sort_id'] = I('get.id','','intval');
        $sort = M('sort')->where($where_sort)->find();
        if(!$sort) $this->error ('栏目不存在');
        $goodsdb = M('goods');
        $where['sort_id'] = I('get.id','','intval');
        $where['state'] = 1;
        $once = 20;
        $totalPage = ceil($goodsdb->where($where)->count()/$once);
        $count = M('goods')->where($where)->count();
        $goods = GoodsModel::I()->_getGoodsList($this->iniPage($count),$where);
        $this->assign('goods',$goods);
        $this->assign('totalPage',$totalPage);
        $this->assign('sort',$sort);
        $this->display();
    }
    
    public function detail(){
        $id = I('get.id','','intval');
        $pre = C('DB_PREFIX');
        $where['goods_id'] = $id;
        $where['g.state'] = 1;
        $goods = M()->table($pre."goods g")->field('g.seo_title,g.seo_keywords,g.seo_description,g.goods_id,g.num_iid,g.title,g.sort_id,g.goods_type,g.price,g.discount_price,g.pic_url,g.item_url,g.click_url,g.item_body,s.sort_name')->join($pre.'sort s on g.sort_id=s.sort_id')->where($where)->find();
        if($goods){
            M('goods')->where('goods_id='.$id)->setInc('hits');
            $where_hot['sort_id'] = $goods['sort_id'];
            $hot_goods = M('goods')->where($where_hot)->order('hits DESC,goods_id DESC')->limit(8)->select();
            $this->assign('hot_goods',$hot_goods);
            $this->assign('goods',$goods);
            $this->display();   
        }else{
            $this->error('商品不存在');
        }
    }
}