Example #1
0
 public function index()
 {
     //商品分类
     $cate = new \Home\Model\Cate();
     $cateData = $cate->getChan();
     // p($cateData);
     View::with('cateData', $cateData);
     //创建商品对象
     $goods = new \Home\Model\Goods();
     //最新发布商品
     $new = $goods->getNew();
     View::with('new', $new);
     //重组分类列表,并去取出8件商品
     $cateTree = $cateData;
     foreach ($cateData as $k => $v) {
         $a = array();
         //取该分组下的三级分类
         foreach ($v['_data'] as $m => $n) {
             $a = array_merge($a, array_keys($n['_data']));
         }
         unset($cateTree[$k]['_data']);
         $cateTree[$k]['three'] = $a;
         if ($a) {
             $level_goods = $goods->whereIn('cate_id', $a)->limit(8)->get();
             $cateTree[$k]['level_goods'] = $level_goods;
         }
     }
     // p($cateTree);
     View::with('cateTree', $cateTree);
     View::make($this->tpl . 'index.html');
 }
Example #2
0
 public function index()
 {
     //商品主要数据
     $goodsData = $this->db->getOne(Q('goods_id'));
     if (!$goodsData) {
         echo '没有此商品记录';
         exit;
     }
     View::with('goodsData', $goodsData);
     //最近浏览
     $viewData = $this->db->recentView();
     View::with('viewData', $viewData);
     //最新发布商品
     $new = $this->db->getNew();
     View::with('new', $new);
     //缩略图数据
     $pics = new \Home\Model\Pics();
     $picsData = $pics->getAll(Q('goods_id'));
     View::with('picsData', $picsData);
     //商品属性数据
     $im_attr = Db::table('goods_attr ga')->join('shop_attr sa', 'ga.attr_id', '=', 'sa.attr_id')->where('goods_id', Q('goods_id'))->where('sa.attr_type', 2)->groupBy('sa.attr_id')->get();
     View::with('im_attr', $im_attr);
     //取当前商品的全部规格属性
     $goods_attr = Db::table('goods_attr')->where('goods_id', $goodsData['goods_id'])->get();
     View::with('goods_attr', $goods_attr);
     //全部商品分类
     $cate = new \Home\Model\Cate();
     $cateData = $cate->getChan();
     // p($cateData);
     View::with('cateData', $cateData);
     //分配相关分类
     $data = $cate->getAll();
     $d = Data::parentChannel($data, $goodsData['cate_id'], 'cate_id', 'pid');
     foreach ($d as $key => $v) {
         if ($v['pid'] == 0) {
             $cateRel = $cate->getRel($v['cate_id']);
         }
     }
     View::with('cateRel', $cateRel);
     View::make($this->tpl . 'goods.html');
 }