/** * Displays a list of pages which are either: * The children of the current page, or * The children of the parent page with a back to parent link */ function getParentId($pageId, $idsArray) { $parentId = wp_get_post_parent_id($pageId); if ($parentId !== 0) { array_unshift($idsArray, $parentId); return getParentId($parentId, $idsArray); } return $idsArray; }
function getParentId($id, &$ary) { global $oMgr; $sql = "SELECT parent_id FROM garoon_belong_view WHERE current_id = '" . $id . "'"; $pid = $oMgr->oDb->getOne($sql); if ($pid != "") { array_unshift($ary, $pid); getParentId($pid, &$ary); } return; }
/** * 获取前辈ID (字串) *@param $types array 分类结果集 *@param $id int 本类id *@return string 返回前辈类ID字符串 */ function getParentId($types, $id) { $str = ''; foreach ($types as $v) { if ($v['id'] == $id) { if ($v['pid'] != 0) { $str .= $v['pid'] . ","; $str .= getParentId($types, $v['pid']); } } } $str = trim($str, ','); return $str; }
public function index() { //==========地址三级连动================= $city = Area::city(); $this->assign("city", $city); //=============根据商品 id 获取商品评价====== $goods = M('goods'); //作为测试 假设商品id=1 $goods_id = I('id'); // $goodsreviews = M('goodsreviews'); //===========将浏览次浏览记录添加到浏览历史开始================= $histories = M('histories'); $his['goods_id'] = $goods_id; $his['user_id'] = session('uid'); $his['addtime'] = time(); //dump($his); $data = $histories->where("goods_id={$his['goods_id']}")->find(); if (!$data) { if ($histories->create($his)) { $histories->add(); } } //===========将浏览次浏览记录添加到浏览历史结束================= $users = M('users'); $attr = M('attr'); $attrvalue = M('attrvalue'); //==========获取商品的详细信息============ $goods_info = $goods->find($goods_id); //根据商品的id获取属性id,进而获取属性值 $attr_ids = $attr->where("goods_id={$goods_id}")->select(); $attrvalue_id = ""; //定义一个变量,用户存放属性值id $stock = 0; //定义一个变量,用户存放总库存 foreach ($attr_ids as $attr_id) { $attrvalue_id .= $attr_id['attrvalue_id'] . ","; $stock += $attr_id['stock']; } $attrvalue_id = rtrim($attrvalue_id, ","); //获取商品分类级别栏 $type_id = $goods_info['type_id']; //所属类别ID $typeData = getData('type'); $typeIds = getParentId($typeData, $type_id); $typeIds = explode(',', $typeIds); //组合数组 foreach ($typeData as $v) { $typeInfo[$v['id']] = $v['name']; //遍历得到一维数组,下标为类ID,值为类名称 } //获取颜色 $c['attrname'] = array('EQ', "颜色"); $c['id'] = array("IN", $attrvalue_id); $at_value['color'] = $attrvalue->where($c)->select(); //获取尺寸 $s['attrname'] = array('EQ', "尺码"); $s['id'] = array("IN", $attrvalue_id); $at_value['size'] = $attrvalue->where($s)->select(); //dump($at_value); //exit; //=================获取全部评价数,好,中,差======== $al['goods_id'] = array('EQ', $goods_id); $al['state'] = array('EQ', "1"); $count['all'] = $goodsreviews->where($al)->count(); $wl['goods_id'] = array('EQ', $goods_id); $wl['star'] = array('EQ', "5"); $count['w'] = $goodsreviews->where($wl)->count(); $ml['goods_id'] = array('EQ', $goods_id); $ml['star'] = array('IN', "3,4"); $count['m'] = $goodsreviews->where($ml)->count(); $bl['goods_id'] = array('EQ', $goods_id); $bl['star'] = array('IN', "1,2"); $count['b'] = $goodsreviews->where($bl)->count(); //====好,中差评率=== $rate['w'] = ceil($count['w'] / $count['all'] * 100); $rate['m'] = floor($count['m'] / $count['all'] * 100); $rate['b'] = floor($count['b'] / $count['all'] * 100); //=======================获取商品全部评价============================================ $page_count = $goodsreviews->where($al)->count(); $Page = new \Think\Page($page_count, 10); $all_show = $Page->show(); $all_data = $goodsreviews->where($al)->limit($Page->firstRow . ',' . $Page->listRows)->select(); // dump($all_data); // exit; //获取到评论人的 id ,在根据id 获取到====(会员名)===(会员等级)===== $reviewsreply = M('reviewsreply'); foreach ($all_data as $all) { //将评论信息存储到以评论id为名字的数组中,下标为'review' , $a[$all['id']]['review'] = $all; //获取评论人的id,进而获取详细信息,并将获取的信息储存到 $a[$all['id']]['user'] $user_id = $all['user_id']; $a[$all['id']]['user'] = $users->where("id={$user_id}")->find(); //评论id = $all['id'] ,利用其查询出对应的回复 $a[$all['id']]['reviewsreply'] = $reviewsreply->where("reviews_id={$all['id']}")->order('addtime desc')->limit("5")->select(); $a[$all['id']]['count'] = $reviewsreply->where("reviews_id={$all['id']}")->order('addtime desc')->count(); } //=======================获取商品好评============================================ $all_data = $goodsreviews->where($wl)->select(); //获取到评论人的 id ,在根据id 获取到====(会员名)===(会员等级)===== $reviewsreply = M('reviewsreply'); foreach ($all_data as $all) { //将评论信息存储到以评论id为名字的数组中,下标为'review' , $w[$all['id']]['review'] = $all; //获取评论人的id,进而获取详细信息,并将获取的信息储存到 $a[$all['id']]['user'] $user_id = $all['user_id']; $w[$all['id']]['user'] = $users->find($user_id); //评论id = $all['id'] ,利用其查询出对应的回复 $w[$all['id']]['reviewsreply'] = $reviewsreply->where("reviews_id={$all['id']}")->order('addtime desc')->limit("5")->select(); $w[$all['id']]['count'] = $reviewsreply->where("reviews_id={$all['id']}")->order('addtime desc')->count(); } //=======================获取商品中评============================================ $all_data = $goodsreviews->where($ml)->select(); //获取到评论人的 id ,在根据id 获取到====(会员名)===(会员等级)===== $reviewsreply = M('reviewsreply'); foreach ($all_data as $all) { //将评论信息存储到以评论id为名字的数组中,下标为'review' , $m[$all['id']]['review'] = $all; //获取评论人的id,进而获取详细信息,并将获取的信息储存到 $a[$all['id']]['user'] $user_id = $all['user_id']; $m[$all['id']]['user'] = $users->find($user_id); //评论id = $all['id'] ,利用其查询出对应的回复 $m[$all['id']]['reviewsreply'] = $reviewsreply->where("reviews_id={$all['id']}")->order('addtime desc')->limit("5")->select(); $m[$all['id']]['count'] = $reviewsreply->where("reviews_id={$all['id']}")->order('addtime desc')->count(); } //=======================获取商品差评============================================ $all_data = $goodsreviews->where($bl)->select(); //获取到评论人的 id ,在根据id 获取到====(会员名)===(会员等级)===== $reviewsreply = M('reviewsreply'); foreach ($all_data as $all) { //将评论信息存储到以评论id为名字的数组中,下标为'review' , $b[$all['id']]['review'] = $all; //获取评论人的id,进而获取详细信息,并将获取的信息储存到 $a[$all['id']]['user'] $user_id = $all['user_id']; $b[$all['id']]['user'] = $users->find($user_id); //评论id = $all['id'] ,利用其查询出对应的回复 $b[$all['id']]['reviewsreply'] = $reviewsreply->where("reviews_id={$all['id']}")->order('addtime desc')->limit("5")->select(); $b[$all['id']]['count'] = $reviewsreply->where("reviews_id={$all['id']}")->order('addtime desc')->count(); } $best_data = $goods->where("ishot=2 AND state = 2")->limit('10')->order('addtime')->select(); //热销商品 $this->assign('typeIds', $typeIds); //所属类前辈类ID数组(一维) $this->assign('typeInfo', $typeInfo); //类信息数组(一维) $this->assign('type_id', $type_id); //所属类ID $this->assign('best_goods', $best_data); $this->assign('histories', $hot_data); $this->assign("count", $count); //评论数 $this->assign("rate", $rate); //好评率 $this->assign("goods_info", $goods_info); //商品信息 $this->assign("a", $a); //$a 全部评级 $this->assign("w", $w); //$w 好评 $this->assign("m", $m); //$m 中评 $this->assign("b", $b); //$b 差评 $this->assign("all_page", $all_show); //评论分页 $this->assign("at_color", $at_value['color']); //商颜色属性值 $this->assign("at_size", $at_value['size']); //商品尺寸属性值 //$this -> assign("stock",$stock); //商品库存量 $this->display(); }
<tr> <td>Vendor details</td> <td colspan="3"><textarea name="vendordetails" style="width:430px; height:40px;"></textarea></td> </tr> <tr> <td valign="top">Category:</td> <td colspan="3"><select name="category" id="category" size="10" style="width: 430px;"> <? $sql = "SELECT catid, catname FROM categories WHERE catparent = '0' ORDER BY catname ASC"; $res = mysql_query($sql) or die(mysql_error()); while(list($catid, $catname) = mysql_fetch_array($res)) { echo "<optgroup label=\"$catname\">\n"; getParentId($catid); echo "</optgroup>\n"; } /* for($i=1; $i <= 60; $i++) { echo "<optgroup label=\"category$i\">\n"; for ($z=1; $z <= 5; $z++) { echo "\t<option value=\"$z\">subcategory $z</option>\n"; } echo "</optgroup>\n"; } */ ?> </select></td>
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(); }
public function getAttrs() { $types = M("type"); $data = $types->field('id,pid')->select(); $id = I('id'); //获取接受的类ID $typesId = getParentId($data, $id); //获取父类ID $typesId = rtrim($typesId, ',') . "," . $id; //安全过滤父类ID,组合本类ID,得到类ID字符串 $map['attrname'] = I("attrname"); //获取查询商品属性条件 $map['type_id'] = array('in', $typesId); $attrvalue = M("attrvalue"); $data = $attrvalue->where($map)->field('id,attrvalue')->select(); $this->ajaxReturn($data); //ajax返回数据 }