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(); }
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(); }
public function show1() { //使用数据模型 //实例化Model对象 $goods = new \Model\GoodsModel(); // $goods = D('Goods'); // $goods = M('Goods'); // dump($goods); // $info = $goods -> select(); //查询价格大于1000的所有商品 // $info = $goods -> where('goods_price >1000 and goods_name like "索爱%"') ->select(); //查询指定字段 // $info = $goods -> field('goods_id,goods_name') -> select(); //限制条数 // $info = $goods -> limit("5") -> select(); // $info = $goods -> limit('10,5') -> select(); //分组查询 group by //查询当前商品一共的分组 // $info = $goods -> field('goods_category_id') -> select(); //有重复数据 // $info = $goods -> field('goods_category_id') -> group('goods_category_id ') -> select(); //排序查询 $info = $goods->order('goods_price desc')->select(); // dump($info); $this->assign('info', $info); $this->display(); }
public function search() { // if (!empty($_GET)) { $goods = new \Model\GoodsModel(); $keyword = $_GET['keyword']; if (!$keyword == "") { $sql1 = "SELECT * FROM sw_goods WHERE goods_name like '%{$keyword}%' order by goods_id desc " . $page->limit; } $keygoods = $goods->query($sql1); $this->assign('keygoods', $keygoods); $this->assign('keyword', $keyword); } $this->display(); }
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(); }
public function product() { $goods_id = $_GET['goods_id'] + 0; $p = $_GET['p'] + 0; //库存入库 if (IS_POST) { $goods_id = I('post.goods_id'); $goods_number = I('post.goods_number'); $attr = I('post.attr'); //修改库存,就是删除旧的数据,增加新的数据 //取出已经存在的库存数据,如果有就删除 $kcdata = M('Product')->where("goods_id={$goods_id}")->select(); if ($kcdata) { M('Product')->where("goods_id={$goods_id}")->delete(); } //计算出总的库存 $kc = 0; foreach ($goods_number as $k => $v) { $a = array(); foreach ($attr as $k1 => $v1) { $a[] = $v1[$k]; } M('Product')->add(array('goods_id' => $goods_id, 'goods_number' => $v, 'goods_attr_id' => implode(',', $a))); //计算总的库存 $kc += $v; } //修改总的库存 M('Goods')->where("goods_id={$goods_id}")->setField('goods_number', $kc); $this->success('添加库存成功', U('showlist', array('p' => $p)), 1); exit; } //修改库存,先把设置的库存取出来显示 $kcdata = M('Product')->where("goods_id={$goods_id}")->select(); $this->assign('kcdata', $kcdata); $goods_model = new \Model\GoodsModel(); $goods_info = $goods_model->field("goods_name")->find($goods_id); $this->assign('goods_info', $goods_info); //取出设置库存的属性id和属性名及值 $data = $goods_model->getRadio($goods_id); //为了方便遍历,转换成三维数组 $radiodata = array(); foreach ($data as $v) { $radiodata[$v['attr_id']][] = $v; } $this->assign('goods_id', $goods_id); $this->assign('radiodata', $radiodata); $this->display(); }