コード例 #1
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();
 }
コード例 #2
0
ファイル: GoodsController.class.php プロジェクト: hslun/jjg
 public function index($goods_id)
 {
     $category = new \Model\CategoryModel();
     $goods = new \Model\GoodsModel();
     $goods_id = $_GET['goods_id'];
     //商品信息
     $goods_info = $goods->find($goods_id);
     $this->assign('goods_info', $goods_info);
     //商品评论
     $comment = D('comment');
     $sql = "SELECT c . * , u.username FROM sw_comment AS c LEFT JOIN sw_user AS u ON c.user_id = u.user_id where c.goods_id=" . $goods_id . " order by c.comment_id desc";
     $comment_info = $comment->query($sql);
     $this->assign('comment_info', $comment_info);
     $this->display();
 }
コード例 #3
0
ファイル: GoodsController.class.php プロジェクト: hslun/jjg
 public function update($goods_id)
 {
     $goods = new \Model\GoodsModel();
     if (!empty($_POST)) {
         if ($_FILES['goods_img']['error'] === 0) {
             $cfg = array('rootPath' => './Admin/Public/goods/');
             $up = new \Think\Upload($cfg);
             $z = $up->uploadOne($_FILES['goods_img']);
             $_POST['goods_big_img'] = $up->rootPath . $z['savepath'] . $z['savename'];
             $bigimg = $_POST['goods_big_img'];
             //对上传图片进行缩略图处理
             $im = new \Think\Image();
             //实例化对象
             $im->open($bigimg);
             //相对服务器路径打开图片
             $im->thumb(165, 165, 3);
             //自适应大小制作缩略图
             $smallimg = $up->rootPath . $z['savepath'] . "small_" . $z['savename'];
             $im->save($smallimg);
             //保存
             $_POST['goods_small_img'] = $smallimg;
             //var_dump($_POST['goods_big_img']);die;
         }
         $arr = $goods->create();
         $result = $goods->save($arr);
         if ($result) {
             $this->redirect('showlist', array(), 2, '修改商品成功');
         } else {
             var_dump($goods->getError());
         }
     }
     $category = new \Model\CategoryModel();
     $cats = $category->select();
     $this->assign('cats', $cats);
     $info = $goods->find($goods_id);
     $this->assign('info', $info);
     $this->display();
 }