Example #1
0
function getChildId($data, $pid)
{
    foreach ($data as $k => $v) {
        if ($v['pid'] == $pid) {
            $id .= getChildId($data, $v['id']);
            $id .= $v['id'] . ',';
        }
    }
    return $id;
}
Example #2
0
/**
 *  获取子类ID    
 *@param $types array 分类结果集
 *@param $pid int 父类id
 *@return array 返回子类ID数组(一维数组)
 */
function getChildId($types, $pid = 0)
{
    $arr = array();
    foreach ($types as $v) {
        if ($v['pid'] == $pid) {
            $arr[] = $v['id'];
            $arr = array_merge($arr, getChildId($types, $v['id']));
        }
    }
    return $arr;
}
Example #3
0
 public function hot()
 {
     $id = I('get.id', '', 'int');
     if (empty($id)) {
         $this->error('操作错误');
     }
     $where = "1";
     $select_option['id'] = $id;
     $catdata = D('Category')->where('status=1')->find($id);
     $catid = I('get.catid', 0, 'int');
     $select_option['catid'] = $catid;
     $catid = $catid > 0 ? $catid : $id;
     //获取所有子类id
     $catlist = D('Category')->where('status=1')->select();
     $idlist = $catid . ',' . getChildId($catlist, $catid);
     $idlist = substr($idlist, 0, strlen($idlist) - 1);
     //$map['w.catid'] = array('in',$idlist);
     $where .= " AND w.catid in ({$idlist})";
     if (isset($_GET['o']) && trim($_GET['o'])) {
         $o = trim($_GET['o']) ? trim($_GET['o']) : 'create_time';
         $order_array = array('create_time', 'hits', 'xh');
         if (!in_array($o, $order_array)) {
             $this->error("数据错误!");
         }
         $select_option['o'] = $o;
         $order = " w.{$o} desc ";
     }
     //获取相关时间段
     $between = I('get.between', 0, 'int');
     if ($between > 0) {
         $now = time();
         $target_time = $now - 86400 * $between;
     }
     $select_option['between'] = $between;
     $time = time();
     /*
     $where['t.starttime']=array('elt',$time);
     $where['t.endtime']=array('egt',$time-(24*3600));
     $where['_logic'] = 'and';
     $mapa['_complex'] = $where;
     $mapa['t.timelimit']=array('eq',0);
     $mapa['_logic'] = 'or';
     $mapb['_complex'] = $mapa;
     $mapb['t.creat_time'] = array('between',array($now,$target_time));
     $mapb['_logic'] = 'and';
     $map['_complex'] = $mapb;
     */
     $time_where = " AND ((t.starttime <= {$time} AND t.endtime >= {$time}) OR (t.timelimit = 0)) ";
     $where .= $time_where;
     $target_time > 0 ? $where .= " AND (t.create_time <= {$now} AND t.create_time >={$target_time}) " : '';
     $prefix = C('DB_PREFIX');
     //获取热门推荐的公号
     /*
     $map['t.status']=array('eq',1);
     $map['t.recommendid']=array('eq',1);
     */
     $where .= " AND t.status = 1 AND t.recommendid = 1 ";
     //取所有热门推荐数据
     $name = $this->getActionName();
     //获取分页设置
     $Model = M('Model');
     $modelmap['table'] = array('eq', $name);
     $pageinfo = $Model->where($modelmap)->find();
     $tuijian = M('Tuijian');
     import("@.ORG.Page");
     //导入分页类
     $count = $tuijian->Table($prefix . 'tuijian t')->join($prefix . 'weixin w ON w.id=t.wxid')->where($where)->count();
     //计算总数
     //        $Page = new Page($count, $pageinfo['listrows']);
     $Page = new Page($count, 42);
     $list = $tuijian->Table($prefix . 'tuijian t')->join($prefix . 'weixin w ON w.id=t.wxid')->where($where)->field('w.*')->order($order)->limit($Page->firstRow . ',' . $Page->listRows)->select();
     foreach ($list as $k => $v) {
         $list[$k]['past_time'] = $this->pastTime($v['create_time']);
     }
     // 设置分页显示
     $Page->setConfig('header', $pageinfo['header']);
     $Page->setConfig('first', $pageinfo['first']);
     $Page->setConfig('last', $pageinfo['last']);
     $Page->setConfig('prev', $pageinfo['prev']);
     $Page->setConfig('next', $pageinfo['next']);
     $Page->setConfig('theme', $pageinfo['theme']);
     $page = $Page->show();
     $this->assign("page", $page);
     $this->assign("list", $list);
     $this->assign("data", $catdata);
     $this->assign("so", $select_option);
     $this->assign("count", $count);
     //获取下级子分类
     $childCatMap['pid'] = array('eq', $id);
     $childCatMap['status'] = array('eq', 1);
     $childCatList = D('Category')->where($childCatMap)->order('listorder')->select();
     $this->assign("childCatList", $childCatList);
     //seo
     $position = D('Common')->getPosition($id);
     foreach ($position as $value) {
         $title = $value['catname'] . "_" . $title;
     }
     $title = substr($title, 0, strlen($title) - 1);
     $this->seo($catdata['title'] ? $catdata['title'] : $title, $catdata['keywords'] ? $catdata['keywords'] : C(SITE_KEYWORDS), $catdata['description'] ? $catdata['description'] : C(SITE_DESCRIPTION), $position);
     $this->display();
 }
Example #4
0
 public function index()
 {
     //=======活动开始============
     $news = M('news');
     $news_data = $news->where("type=2")->order("addtime")->limit(5)->select();
     //===================
     //=======浏览历史开始============
     //从session中获取到用户的id
     $uid = session('uid');
     $histories = M("histories");
     $his_data = $histories->where("user_id={$uid}")->order('addtime DESC')->limit(15)->select();
     //遍历数据得到商品id,进而得到商品的详细信息
     $goods = M('goods');
     foreach ($his_data as $g) {
         $goods_id = $g['goods_id'];
         $goods_data[$goods_id] = $goods->find($goods_id);
     }
     //=========浏览历史结束==========
     //=======热卖商品开始============
     $hot_data = $goods->where("ishot=2")->order('addtime')->limit('3')->select();
     //===================
     //======推荐商品开始=============
     $best_data = $goods->where("isbest=2")->order('addtime')->limit('10')->select();
     //======获取商品类别=============
     $type = M('type')->order('sort ASC')->where('state != 2')->select();
     //获取商品显示中的全部类别
     foreach ($type as $v) {
         $typeList[$v['id']] = $v['name'];
         //自定义数组$typeList,下标为类别ID,值为类名名称
     }
     //======商品搜索=============
     //获取搜索条件
     foreach ($_GET as $k => $v) {
         if ($v) {
             //商品名称搜索
             if ($k == 'keyword') {
                 $map['name'] = array('like', "%{$v}%");
                 //组合商品名称搜索条件
             }
             //按商品类别搜索
             if ($k == 'typeid') {
                 $v = implode(',', getChildId($type, $v)) . ',' . $v;
                 //获取子类及本类ID字符串
                 $map['type_id'] = array('in', $v);
                 //组合类别搜索条件
             }
             //按商品品牌搜索
             if ($k == 'brandid') {
                 $map['brand_id'] = $v;
                 //组合品牌搜索条件
             }
             //按价格
             if ($k == 'price') {
                 $priceFilter = explode('_', $v);
                 $map['saleprice'] = array('gt', $priceFilter[0]);
                 if ($priceFilter[1]) {
                     $map['saleprice'] = array(array('gt', $priceFilter[0]), array('elt', $priceFilter[1]));
                 }
             }
             //按属性(颜色、尺码)
             if ($k == 'attrid') {
                 //$_GET['attrid'] =
                 //如果存在
                 if (is_array($_GET['attrid'])) {
                     //如果尺码存在,组合到属性数组
                     if ($_GET['attrsizeid']) {
                         $_GET['attrid'][] = $_GET['attrsizeid'];
                     }
                     $radio = 'OR';
                     //设置属性搜索条件为合集
                     //遍历属性数组并组合为一维数组,
                     for ($i = 0; $i < count($_GET['attrid']); $i++) {
                         $searchAttr[] = '%' . $_GET['attrid'][$i] . '%';
                     }
                 } else {
                     $radio = 'AND';
                     //设置属性条件是交集还是合集,默认交集
                     if ($_GET['attrsizeid']) {
                         $searchAttr[] = '%' . $_GET['attrsizeid'] . '%';
                     }
                     $searchAttr[] = '%' . $_GET['attrid'] . '%';
                 }
             }
             //判断尺码是否存在
             if ($k == 'attrsizeid') {
                 if (!$_GET['attrid']) {
                     $searchAttr[] = '%' . $_GET['attrsizeid'] . '%';
                 }
             }
             $attrMap['attrvalue_id'] = array('like', $searchAttr, $radio);
             //组合搜索条件
             $goodsId = M('attr')->field('goods_id')->where($attrMap)->select();
             //查询商品ID字符串
         }
     }
     //如果有颜色尺码或属性存在,组合搜索条件
     if ($_GET['attrid'] || $_GET['attrsizeid']) {
         if ($goodsId) {
             foreach ($goodsId as $v) {
                 $goodsids[] = $v['goods_id'];
             }
             $map['id'] = array('in', $goodsids);
             //组合颜色、尺码属性搜索条件
         } else {
             $map['id'] = array('in', '');
             //如果颜色或尺寸搜索条件,没有获取到商品,条件赋空
         }
     }
     $map['state'] = '2';
     //组合商品状态搜索条件
     if ($_POST['order']) {
         $orderFilter = explode('_', $_POST['order']);
         $order = "{$orderFilter[0]} {$orderFilter[1]}";
     } else {
         $order = 'id ASC';
     }
     $count = $goods->where($map)->order('id ASC')->count();
     $Page = new \Think\Page($count, 4, $_GET);
     $goodsList = $goods->where($map)->order("{$order}")->page($_GET['p'], 4)->select();
     //获取商品列表
     $show = $Page->show();
     //======获取商品品牌=============
     $brands = M('brands');
     if ($_GET['typeid']) {
         $typeid = implode(',', getChildId($type, $v) . ',' . $v);
         //获取商品父类及本类字串
         $brandList = $brands->where("state != 2 AND type_id in ({$_GET['typeid']})")->select();
     }
     //======获取商品属性=============
     $attrs = getData('attrvalue', 'state = 1', 'id ASC');
     //======获取搜索分类属性=============
     $type_id = $_GET['typeid'];
     $navType = getParentId($type, $type_id);
     //获取前辈类ID
     if ($navType) {
         $navTypeList = explode(',', $navType);
     }
     $navTypeList[] = $type_id;
     $this->assign("goodsList", $goodsList);
     //======商品=======
     $this->assign("count", $count);
     //======商品总数=======
     $this->assign("typeList", $typeList);
     //======类别=======
     $this->assign("navTypeList", $navTypeList);
     //======类别导航=======
     $this->assign("attrs", $attrs);
     //======属性=======
     $this->assign("brandList", $brandList);
     //======品牌=======
     $this->assign("page", $show);
     //======分页=======
     $this->assign("news", $news_data);
     //======活动=======
     $this->assign("histories", $goods_data);
     //=====浏览历史=====
     $this->assign('hot_goods', $hot_data);
     //=====热卖商品======
     $this->assign('best_goods', $best_data);
     //=====热卖商品======
     $this->display();
 }
Example #5
0
 public function index()
 {
     $id = I('get.id', '', 'int');
     if (empty($id)) {
         $this->error('操作错误');
     }
     $catdata = D('Category')->where('status=1')->find($id);
     //获取所有子类id
     $catlist = D('Category')->where('status=1')->select();
     $idlist = $id . ',' . getChildId($catlist, $id);
     $idlist = substr($idlist, 0, strlen($idlist) - 1);
     $map['catid'] = array('in', $idlist);
     if (method_exists($this, '_filter')) {
         $this->_filter($map);
     }
     $name = $this->getActionName();
     //获取分页设置
     $Model = M('Model');
     $map['table'] = array('eq', $name);
     $pageinfo = $Model->where($map)->find();
     $Form = M($name);
     import("@.ORG.Page");
     //导入分页类
     $count = $Form->where($map)->count();
     //计算总数
     $Page = new Page($count, $pageinfo['listrows']);
     $list = $Form->where($map)->limit($Page->firstRow . ',' . $Page->listRows)->order('id desc')->select();
     // 设置分页显示
     $Page->setConfig('header', $pageinfo['header']);
     $Page->setConfig('first', $pageinfo['first']);
     $Page->setConfig('last', $pageinfo['last']);
     $Page->setConfig('prev', $pageinfo['prev']);
     $Page->setConfig('next', $pageinfo['next']);
     $Page->setConfig('theme', $pageinfo['theme']);
     $page = $Page->show();
     $this->assign("data", $catdata);
     $this->assign("page", $page);
     $this->assign("list", $list);
     $position = D('Common')->getPosition($id);
     foreach ($position as $value) {
         $title = $value['catname'] . "_" . $title;
     }
     $title = substr($title, 0, strlen($title) - 1);
     $this->seo($catdata['title'] ? $catdata['title'] : $title, $catdata['keywords'] ? $catdata['keywords'] : C(SITE_KEYWORDS), $catdata['description'] ? $catdata['description'] : C(SITE_DESCRIPTION), $position);
     $this->display();
 }
Example #6
0
 public function _hits($attr, $content)
 {
     $tag = $this->parseXmlAttr($attr, 'hits');
     $result = !empty($tag['result']) ? $tag['result'] : 'hits';
     $prefix = C('DB_PREFIX');
     $catlist = D('Category')->where('status=1')->select();
     $idlist = $tag['catid'] . ',' . getChildId($catlist, $tag['catid']);
     $idlist = substr($idlist, 0, strlen($idlist) - 1);
     $map .= "'" . $prefix . "weixin.status=1";
     if (strtolower($tag['order']) == "d") {
         $map .= " and date(FROM_UNIXTIME(hittime)) = curdate()";
     } elseif (strtolower($tag['order']) == "w") {
         $map .= " and DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(FROM_UNIXTIME(hittime))";
     } elseif (strtolower($tag['order']) == "m") {
         $map .= " and DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(FROM_UNIXTIME(hittime))";
     }
     $map .= $tag['catid'] ? " and " . $prefix . "weixin.catid in ({$idlist})'" : "'";
     $sql = "M('hits')->";
     $sql .= "join('" . $prefix . "weixin ON " . $prefix . "weixin.id=" . $prefix . "hits.accountid')->";
     $sql .= "where({$map})->";
     $sql .= "field('" . $prefix . "weixin.*')->group('accountid')->";
     $sql .= "order('hitnum desc')->";
     $sql .= $tag['num'] ? "limit({$tag['num']})->" : "";
     $sql .= "select()";
     //下面拼接输出语句
     $parsestr = '<?php $_result=' . $sql . ';';
     $parsestr .= 'foreach($_result as $key=>$' . $result . '):?>';
     $parsestr .= $content;
     //解析在article标签中的内容
     $parsestr .= '<?php endforeach;?>';
     return $parsestr;
 }
Example #7
0
 public function index()
 {
     $type = M('type');
     //获取商品类别
     $types = $type->field('id,name,pid')->order('sort ASC')->select();
     $typeList = getList($types);
     //过滤搜索条件
     if ($_GET['filter']) {
         $map = json_decode(urldecode($_GET['filter']), true);
     } else {
         if ($_POST) {
             foreach ($_POST as $k => $v) {
                 if ($v) {
                     //按名称搜索
                     if ($k == 'name') {
                         $map[$k] = array('like', "%{$v}%");
                     }
                     //按价格搜索
                     if ($k == 'minPrice') {
                         $map['saleprice'] = array('egt', "{$v}");
                         if ($_POST['maxPrice']) {
                             $map['saleprice'] = array(array('egt', "{$v}"), array('elt', "{$_POST['maxPrice']}"));
                         }
                     }
                     if ($k == 'maxPrice') {
                         if (!$_POST['minPrice']) {
                             $map['saleprice'] = array('elt', "{$v}");
                         }
                     }
                     //按类别搜索
                     if ($k == 'type_id') {
                         $typeids = getChildId($types, $v);
                         if (!empty($typeids)) {
                             $typeids[] = $v;
                             $typeIdList = $typeids;
                         } else {
                             $typeIdList[] = $v;
                         }
                         $map['type_id'] = array('in', $typeIdList);
                     }
                     //按状态搜索
                     if ($k == 'state' || $k == 'isbest' || $k == 'ishot') {
                         $map[$k] = array('eq', $v);
                     }
                 }
             }
         } else {
             $map = null;
         }
     }
     //获取商品列表信息
     $goods = M("goods");
     $total = $goods->where($map)->count();
     $list = $goods->where($map)->page($_GET['p'], 10)->order('id DESC')->select();
     $Page = new \Think\Page($total, 10);
     $Page->parameter = array('filter' => urlencode(json_encode($map)));
     //给分页类传入搜索条件,保持搜索
     $show = $Page->show();
     $this->assign('types', $typeList);
     $this->assign('goods', $list);
     $this->assign('page', $show);
     $this->display();
 }