/** * 获得文章分类下的文章列表 * * @access public * @param integer $cat_id * @param integer $page * @param integer $size * * @return array */ function get_cat_articles($cat_id, $page = 1, $size = 20, $requirement = '') { //取出所有非0的文章 if ($cat_id == '-1') { $cat_str = 'cat_id > 0'; } else { $cat_str = get_article_children($cat_id); } //dump($cat_str); /* 增加代理商条件 */ $where = agency_goods(); //增加搜索条件,如果有搜索内容就进行搜索 if ($requirement != '') { $sql = 'SELECT article_id, title, author, add_time, file_url, open_type' . ' FROM ' . $GLOBALS['ecs']->table('article') . ' WHERE ' . $where . ' is_open = 1 AND title like \'%' . $requirement . '%\' ' . ' ORDER BY article_type DESC, article_id DESC'; } else { $sql = 'SELECT article_id, title, author, add_time, file_url, open_type' . ' FROM ' . $GLOBALS['ecs']->table('article') . ' WHERE ' . $where . ' is_open = 1 AND ' . $cat_str . ' ORDER BY article_type DESC, article_id DESC'; } if (!$GLOBALS['db']->getOne($sql)) { $sql = str_replace($where, '', $sql); } $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); $arr = array(); if ($res) { while ($row = $GLOBALS['db']->fetchRow($res)) { $article_id = $row['article_id']; $arr[$article_id]['id'] = $article_id; $arr[$article_id]['title'] = $row['title']; $arr[$article_id]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ? sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title']; $arr[$article_id]['author'] = empty($row['author']) || $row['author'] == '_SHOPHELP' ? $GLOBALS['_CFG']['shop_name'] : $row['author']; $arr[$article_id]['url'] = $row['open_type'] != 1 ? build_uri('article', array('aid' => $article_id), $row['title']) : trim($row['file_url']); $arr[$article_id]['add_time'] = date($GLOBALS['_CFG']['date_format'], $row['add_time']); } } return $arr; }
/** * 所有的促销活动信息 * * @access public * @return array */ function get_promotion_info($goods_id = '') { $snatch = array(); $group = array(); $auction = array(); $package = array(); $favourable = array(); $gmtime = gmtime(); /*根据代理商过滤 by hg for 2014-06-10*/ $where = agency_goods(); $sql = 'SELECT act_id, act_name, act_type, start_time, end_time FROM ' . $GLOBALS['ecs']->table('goods_activity') . " WHERE {$where} is_finished=0 AND start_time <= '{$gmtime}' AND end_time >= '{$gmtime}'"; if (!empty($goods_id)) { $sql .= " AND goods_id = '{$goods_id}'"; } $res = $GLOBALS['db']->getAll($sql); foreach ($res as $data) { switch ($data['act_type']) { case GAT_SNATCH: //夺宝奇兵 $snatch[$data['act_id']]['act_name'] = $data['act_name']; $snatch[$data['act_id']]['url'] = build_uri('snatch', array('sid' => $data['act_id'])); $snatch[$data['act_id']]['time'] = sprintf($GLOBALS['_LANG']['promotion_time'], local_date('Y-m-d', $data['start_time']), local_date('Y-m-d', $data['end_time'])); $snatch[$data['act_id']]['sort'] = $data['start_time']; $snatch[$data['act_id']]['type'] = 'snatch'; break; case GAT_GROUP_BUY: //团购 $group[$data['act_id']]['act_name'] = $data['act_name']; $group[$data['act_id']]['url'] = build_uri('group_buy', array('gbid' => $data['act_id'])); $group[$data['act_id']]['time'] = sprintf($GLOBALS['_LANG']['promotion_time'], local_date('Y-m-d', $data['start_time']), local_date('Y-m-d', $data['end_time'])); $group[$data['act_id']]['sort'] = $data['start_time']; $group[$data['act_id']]['type'] = 'group_buy'; break; case GAT_AUCTION: //拍卖 $auction[$data['act_id']]['act_name'] = $data['act_name']; $auction[$data['act_id']]['url'] = build_uri('auction', array('auid' => $data['act_id'])); $auction[$data['act_id']]['time'] = sprintf($GLOBALS['_LANG']['promotion_time'], local_date('Y-m-d', $data['start_time']), local_date('Y-m-d', $data['end_time'])); $auction[$data['act_id']]['sort'] = $data['start_time']; $auction[$data['act_id']]['type'] = 'auction'; break; case GAT_PACKAGE: //礼包 $package[$data['act_id']]['act_name'] = $data['act_name']; $package[$data['act_id']]['url'] = 'package.php#' . $data['act_id']; $package[$data['act_id']]['time'] = sprintf($GLOBALS['_LANG']['promotion_time'], local_date('Y-m-d', $data['start_time']), local_date('Y-m-d', $data['end_time'])); $package[$data['act_id']]['sort'] = $data['start_time']; $package[$data['act_id']]['type'] = 'package'; break; } } $user_rank = ',' . $_SESSION['user_rank'] . ','; $favourable = array(); $sql = 'SELECT act_id, act_range, act_range_ext, act_name, start_time, end_time FROM ' . $GLOBALS['ecs']->table('favourable_activity') . " WHERE start_time <= '{$gmtime}' AND end_time >= '{$gmtime}'"; if (!empty($goods_id)) { $sql .= " AND CONCAT(',', user_rank, ',') LIKE '%" . $user_rank . "%'"; } $res = $GLOBALS['db']->getAll($sql); if (empty($goods_id)) { foreach ($res as $rows) { $favourable[$rows['act_id']]['act_name'] = $rows['act_name']; $favourable[$rows['act_id']]['url'] = 'activity.php'; $favourable[$rows['act_id']]['time'] = sprintf($GLOBALS['_LANG']['promotion_time'], local_date('Y-m-d', $rows['start_time']), local_date('Y-m-d', $rows['end_time'])); $favourable[$rows['act_id']]['sort'] = $rows['start_time']; $favourable[$rows['act_id']]['type'] = 'favourable'; } } else { $sql = "SELECT cat_id, brand_id FROM " . $GLOBALS['ecs']->table('goods') . "WHERE goods_id = '{$goods_id}'"; $row = $GLOBALS['db']->getRow($sql); $category_id = $row['cat_id']; $brand_id = $row['brand_id']; foreach ($res as $rows) { if ($rows['act_range'] == FAR_ALL) { $favourable[$rows['act_id']]['act_name'] = $rows['act_name']; $favourable[$rows['act_id']]['url'] = 'activity.php'; $favourable[$rows['act_id']]['time'] = sprintf($GLOBALS['_LANG']['promotion_time'], local_date('Y-m-d', $rows['start_time']), local_date('Y-m-d', $rows['end_time'])); $favourable[$rows['act_id']]['sort'] = $rows['start_time']; $favourable[$rows['act_id']]['type'] = 'favourable'; } elseif ($rows['act_range'] == FAR_CATEGORY) { /* 找出分类id的子分类id */ $id_list = array(); $raw_id_list = explode(',', $rows['act_range_ext']); foreach ($raw_id_list as $id) { $id_list = array_merge($id_list, array_keys(cat_list($id, 0, false))); } $ids = join(',', array_unique($id_list)); if (strpos(',' . $ids . ',', ',' . $category_id . ',') !== false) { $favourable[$rows['act_id']]['act_name'] = $rows['act_name']; $favourable[$rows['act_id']]['url'] = 'activity.php'; $favourable[$rows['act_id']]['time'] = sprintf($GLOBALS['_LANG']['promotion_time'], local_date('Y-m-d', $rows['start_time']), local_date('Y-m-d', $rows['end_time'])); $favourable[$rows['act_id']]['sort'] = $rows['start_time']; $favourable[$rows['act_id']]['type'] = 'favourable'; } } elseif ($rows['act_range'] == FAR_BRAND) { if (strpos(',' . $rows['act_range_ext'] . ',', ',' . $brand_id . ',') !== false) { $favourable[$rows['act_id']]['act_name'] = $rows['act_name']; $favourable[$rows['act_id']]['url'] = 'activity.php'; $favourable[$rows['act_id']]['time'] = sprintf($GLOBALS['_LANG']['promotion_time'], local_date('Y-m-d', $rows['start_time']), local_date('Y-m-d', $rows['end_time'])); $favourable[$rows['act_id']]['sort'] = $rows['start_time']; $favourable[$rows['act_id']]['type'] = 'favourable'; } } elseif ($rows['act_range'] == FAR_GOODS) { if (strpos(',' . $rows['act_range_ext'] . ',', ',' . $goods_id . ',') !== false) { $favourable[$rows['act_id']]['act_name'] = $rows['act_name']; $favourable[$rows['act_id']]['url'] = 'activity.php'; $favourable[$rows['act_id']]['time'] = sprintf($GLOBALS['_LANG']['promotion_time'], local_date('Y-m-d', $rows['start_time']), local_date('Y-m-d', $rows['end_time'])); $favourable[$rows['act_id']]['sort'] = $rows['start_time']; $favourable[$rows['act_id']]['type'] = 'favourable'; } } } } // if(!empty($goods_id)) // { // return array('snatch'=>$snatch, 'group_buy'=>$group, 'auction'=>$auction, 'favourable'=>$favourable); // } $sort_time = array(); $arr = array_merge($snatch, $group, $auction, $package, $favourable); foreach ($arr as $key => $value) { $sort_time[] = $value['sort']; } array_multisort($sort_time, SORT_NUMERIC, SORT_DESC, $arr); return $arr; }
/** * 获得分类下的商品总数 * * @access public * @param string $cat_id * @return integer */ function get_cagtegory_goods_count($children, $brand = 0, $min = 0, $max = 0, $ext = '') { //获取显示商品条件 add by hg for date 2014-03-26 $agency_where = agency_goods(); if ($agency_where != null) { $agency_where = 'g.' . $agency_where; } $where = "{$agency_where} g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND ({$children} OR " . get_extension_goods($children) . ')'; if ($brand > 0) { $where .= " AND g.brand_id = {$brand} "; } if ($min > 0) { $where .= " AND g.shop_price >= {$min} "; } if ($max > 0) { $where .= " AND g.shop_price <= {$max} "; } /* 返回商品总数 */ return $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('goods') . " AS g WHERE {$where} {$ext}"); }
/** * 调用浏览历史 * * @access public * @return string */ function insert_history() { $str = ''; if (!empty($_COOKIE['ECS']['history'])) { /*获取显示商品条件 add by hg for date 2014-03-26 */ $agency_where = agency_goods(); if ($agency_where != null) { $agency_where = $agency_where; } /*end*/ $where = db_create_in($_COOKIE['ECS']['history'], 'goods_id'); $sql = 'SELECT goods_id, goods_name, goods_thumb, shop_price,market_price FROM ' . $GLOBALS['ecs']->table('goods') . " WHERE {$agency_where} {$where} AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0"; $res = $GLOBALS['db']->getAll($sql); foreach ($res as $idx => $row) { $goods[$idx]['goods_id'] = $row['goods_id']; $goods[$idx]['goods_name'] = $row['goods_name']; $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['shop_price'] = price_format($row['shop_price']); $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); } $GLOBALS['smarty']->assign('history_goods', $goods); $output = $GLOBALS['smarty']->fetch('library/goods_history_info.lbi'); //dump(htmlspecialchars($output)); $GLOBALS['smarty']->caching = $need_cache; return $output; } // return $str; }
/** * 获得购物车中商品的配件 * * @access public * @param array $goods_list * @return array */ function get_goods_fittings($goods_list = array()) { $temp_index = 0; $arr = array(); /*获取显示商品条件 add by hg for date 2014-03-26 */ $agency_where = agency_goods(); if ($agency_where != null) { $agency_where = 'g.' . $agency_where; } /*end*/ $sql = 'SELECT gg.parent_id, ggg.goods_name AS parent_name, gg.goods_id, gg.goods_price, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price " . 'FROM ' . $GLOBALS['ecs']->table('group_goods') . ' AS gg ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . 'AS g ON g.goods_id = gg.goods_id ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = gg.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . "LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS ggg ON ggg.goods_id = gg.parent_id " . "WHERE {$agency_where} gg.parent_id " . db_create_in($goods_list) . " AND g.is_delete = 0 AND g.is_on_sale = 1 " . "ORDER BY gg.parent_id, gg.goods_id"; $res = $GLOBALS['db']->query($sql); while ($row = $GLOBALS['db']->fetchRow($res)) { $arr[$temp_index]['parent_id'] = $row['parent_id']; //配件的基本件ID /* 折扣节省计算 by ecmoban start */ if ($row['market_price'] > 0) { $discount_arr = get_discount($row['goods_id']); //函数get_discount参数goods_id } $arr[$temp_index]['zhekou'] = $discount_arr['discount']; //zhekou $arr[$temp_index]['jiesheng'] = $discount_arr['jiesheng']; //jiesheng /* 折扣节省计算 by ecmoban end */ $arr[$temp_index]['parent_name'] = $row['parent_name']; //配件的基本件的名称 $arr[$temp_index]['parent_short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['parent_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['parent_name']; //配件的基本件显示的名称 $arr[$temp_index]['goods_id'] = $row['goods_id']; //配件的商品ID $arr[$temp_index]['goods_name'] = $row['goods_name']; //配件的名称 $arr[$temp_index]['comments_number'] = $row['comments_number']; $arr[$temp_index]['sales_volume'] = $row['sales_volume']; $arr[$temp_index]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; //配件显示的名称 $arr[$temp_index]['fittings_price'] = price_format($row['goods_price']); //配件价格 $arr[$temp_index]['shop_price'] = price_format($row['shop_price']); //配件原价格 $arr[$temp_index]['spare_price'] = price_format($row['shop_price'] - $row['goods_price']); //节省的差价 by mike $arr[$temp_index]['shop_price_ori'] = $row['shop_price']; //配件原价格 by mike $arr[$temp_index]['fittings_price_ori'] = $row['goods_price']; //配件价格 by mike $arr[$temp_index]['spare_price_ori'] = $row['shop_price'] - $row['goods_price']; //节省的差价 by mike $arr[$temp_index]['group_id'] = $row['group_id']; //套餐组 by mike $arr[$temp_index]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $arr[$temp_index]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $arr[$temp_index]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $temp_index++; } return $arr; }
/** * 获得与指定品牌相关的分类 * * @access public * @param integer $brand * @return array */ function brand_related_cat($brand) { //获取显示商品条件 add by hg for date 2014-03-26 $agency_where = agency_goods(); if ($agency_where != null) { $agency_where = 'g.' . $agency_where; } /*end*/ $arr[] = array('cat_id' => 0, 'cat_name' => $GLOBALS['_LANG']['all_category'], 'url' => build_uri('brand', array('bid' => $brand), $GLOBALS['_LANG']['all_category'])); $sql = "SELECT c.cat_id, c.cat_name, COUNT(g.goods_id) AS goods_count FROM " . $GLOBALS['ecs']->table('category') . " AS c, " . $GLOBALS['ecs']->table('goods') . " AS g " . "WHERE {$agency_where} g.brand_id = '{$brand}' AND c.cat_id = g.cat_id AND g.is_alone_sale = 1 " . "GROUP BY g.cat_id"; $res = $GLOBALS['db']->query($sql); while ($row = $GLOBALS['db']->fetchRow($res)) { $row['url'] = build_uri('brand', array('cid' => $row['cat_id'], 'bid' => $brand), $row['cat_name']); $arr[] = $row; } return $arr; }
/** * 获取最近要到期的活动id,没有则返回 0 * * @access public * @param * * @return void */ function get_last_snatch() { $now = gmtime(); $where = agency_goods(); $sql = 'SELECT act_id FROM ' . $GLOBALS['ecs']->table('goods_activity') . " WHERE {$where} start_time < '{$now}' AND end_time > '{$now}' AND act_type = " . GAT_SNATCH . " ORDER BY end_time ASC LIMIT 1"; return $GLOBALS['db']->GetOne($sql); }
/** * 获得最新的文章列表。 * * @access private * @return array */ function index_get_new_articles() { /* 加入代理商条件 */ $where = agency_goods(); $where = 'a.' . substr($where, 0, -4); $sql = 'SELECT a.article_id, a.title, ac.cat_name, a.add_time, a.file_url, a.open_type, ac.cat_id, ac.cat_name ' . ' FROM ' . $GLOBALS['ecs']->table('article') . ' AS a, ' . $GLOBALS['ecs']->table('article_cat') . ' AS ac' . ' WHERE (' . $where . ' or a.show_every = 1) and a.is_open = 1 AND a.cat_id = ac.cat_id AND ac.cat_type = 1' . ' ORDER BY a.show_every DESC, a.article_type DESC, a.add_time DESC LIMIT ' . $GLOBALS['_CFG']['article_number']; $res = $GLOBALS['db']->getAll($sql); //dump( $sql); $arr = array(); foreach ($res as $idx => $row) { $arr[$idx]['id'] = $row['article_id']; $arr[$idx]['title'] = $row['title']; $arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ? sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title']; $arr[$idx]['cat_name'] = $row['cat_name']; $arr[$idx]['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); $arr[$idx]['url'] = $row['open_type'] != 1 ? build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']); $arr[$idx]['cat_url'] = build_uri('article_cat', array('acid' => $row['cat_id']), $row['cat_name']); } return $arr; }
/** * 获得促销商品 * * @access public * @return array */ function get_promote_goods($cats = '') { $time = gmtime(); $order_type = $GLOBALS['_CFG']['recommend_order']; $agency_where = agency_goods(); /* 取得促销lbi的数量限制 */ $num = get_library_number("recommend_promotion"); $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, " . "g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd " . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . 'WHERE ' . $agency_where . ' g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . " AND g.is_promote = 1 AND promote_start_date <= '{$time}' AND promote_end_date >= '{$time}' "; $sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY rnd'; $sql .= " LIMIT {$num} "; $result = $GLOBALS['db']->getAll($sql); $goods = array(); foreach ($result as $idx => $row) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; } else { $goods[$idx]['promote_price'] = ''; } $goods[$idx]['id'] = $row['goods_id']; $goods[$idx]['name'] = $row['goods_name']; $goods[$idx]['brief'] = $row['goods_brief']; $goods[$idx]['brand_name'] = $row['brand_name']; $goods[$idx]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']); $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']); $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['shop_price'] = price_format($row['shop_price']); $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); } return $goods; }
/* 初始化session */ include ROOT_PATH . 'includes/cls_session.php'; $sess = new cls_session($db, $ecs->table('sessions'), $ecs->table('sessions_data')); define('SESS_ID', $sess->get_session_id()); } if (isset($_SERVER['PHP_SELF'])) { $_SERVER['PHP_SELF'] = htmlspecialchars($_SERVER['PHP_SELF']); } if (!defined('INIT_NO_SMARTY')) { header('Cache-control: private'); header('Content-type: text/html; charset=' . EC_CHARSET); /* 创建 Smarty 对象。*/ require ROOT_PATH . 'includes/cls_template.php'; $smarty = new cls_template(); /*获取代理商关联user_id add by hg for date 2014-04-01*/ $agency_where = agency_goods(); $agency_user_id_arr = explode(' ', $agency_where); $agency_user_id = $agency_user_id_arr[2]; if ($agency_user_id) { $user_tpl = $db->getRow("select agency_template from " . $ecs->table('admin_user') . " where agency_user_id = {$agency_user_id}"); } else { $user_tpl = $db->getRow("select agency_template from " . $ecs->table('admin_user') . " where agency_user_id is null or action_list = 'all'"); } if (!empty($user_tpl['agency_template'])) { //反序列化 $user_tpl = unserialize($user_tpl['agency_template']); $_CFG['template'] = $user_tpl['tpl_name']; $_CFG['stylename'] = $user_tpl['tpl_fg']; } else { } //清理模板
function judge_agency($goods_id) { if (empty($goods_id)) { return ''; } //商品所属代理商id $agency_static = $GLOBALS['db']->getRow("select admin_agency_id from " . $GLOBALS['ecs']->table('goods') . "where goods_id = {$goods_id}"); $res = agency_goods(); $resArray = explode(' ', $res); if ($resArray[2] == $agency_static['admin_agency_id']) { return true; } else { return false; } }
/** * 取得自定义导航栏列表 * @param string $type 位置,如top、bottom、middle * @return array 列表 */ function get_navigator($ctype = '', $catlist = array()) { /* 2014-12-26 $sql = 'SELECT * FROM '. $GLOBALS['ecs']->table('nav') . ' WHERE ifshow = \'1\' ORDER BY type, vieworder'; */ /*ccx 2014-12-26 开始 自定义导航栏根据不同站点不同代理商显示各自的导航栏信息*/ $agency_where = agency_goods(); $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('nav') . "WHERE " . $agency_where . " ifshow = 1 ORDER BY type, vieworder "; /*ccx 2014-12-26 结束 */ $res = $GLOBALS['db']->query($sql); $cur_url = substr(strrchr($_SERVER['REQUEST_URI'], '/'), 1); if (intval($GLOBALS['_CFG']['rewrite'])) { if (strpos($cur_url, '-')) { preg_match('/([a-z]*)-([0-9]*)/', $cur_url, $matches); $cur_url = $matches[1] . '.php?id=' . $matches[2]; } } else { $cur_url = substr(strrchr($_SERVER['REQUEST_URI'], '/'), 1); } $noindex = false; $active = 0; $navlist = array('top' => array(), 'middle' => array(), 'bottom' => array()); while ($row = $GLOBALS['db']->fetchRow($res)) { $navlist[$row['type']][] = array('name' => $row['name'], 'opennew' => $row['opennew'], 'url' => $row['url'], 'ctype' => $row['ctype'], 'cid' => $row['cid']); } /*遍历自定义是否存在currentPage*/ foreach ($navlist['middle'] as $k => $v) { $condition = empty($ctype) ? strpos($cur_url, $v['url']) === 0 : strpos($cur_url, $v['url']) === 0 && strlen($cur_url) == strlen($v['url']); if ($condition) { $navlist['middle'][$k]['active'] = 1; $noindex = true; $active += 1; } if (substr($v['url'], 0, 8) == 'category') { $cat_id = $v['cid']; $children = get_children($cat_id); $cat_list = get_categories_tree_xaphp($cat_id); $navlist['middle'][$k]['cat'] = 1; $navlist['middle'][$k]['cat_list'] = $cat_list; } } if (!empty($ctype) && $active < 1) { foreach ($catlist as $key => $val) { foreach ($navlist['middle'] as $k => $v) { if (!empty($v['ctype']) && $v['ctype'] == $ctype && $v['cid'] == $val && $active < 1) { $navlist['middle'][$k]['active'] = 1; $noindex = true; $active += 1; } } } } if ($noindex == false) { $navlist['config']['index'] = 1; } return $navlist; }
/** * 获得分类下的商品总数 * * @access public * @param string $cat_id * @return integer */ function get_exchange_goods_count($children, $min = 0, $max = 0, $ext = '') { //获取显示商品条件 add by hg for date 2014-03-26 $agency_where = agency_goods(); if ($agency_where != null) { $agency_where = 'g.' . $agency_where; } $where = "{$agency_where} eg.is_exchange = 1 AND g.is_delete = 0 AND ({$children} OR " . get_extension_goods($children) . ')'; if ($min > 0) { $where .= " AND eg.exchange_integral >= {$min} "; } if ($max > 0) { $where .= " AND eg.exchange_integral <= {$max} "; } $sql = 'SELECT COUNT(*) FROM ' . $GLOBALS['ecs']->table('exchange_goods') . ' AS eg, ' . $GLOBALS['ecs']->table('goods') . " AS g WHERE eg.goods_id = g.goods_id AND {$where} {$ext}"; /* 返回商品总数 */ return $GLOBALS['db']->getOne($sql); }
/** * 获得分类下的商品 * * @access public * @param string $children * @return array */ function category_get_goods($children, $brand, $min, $max, $ext, $size, $page, $sort, $order) { //获取显示商品条件 add by hg for date 2014-03-26 $agency_where = agency_goods(); if ($agency_where != null) { $agency_where = 'g.' . $agency_where; } $display = $GLOBALS['display']; $where = "{$agency_where} g.is_on_sale = 1 AND g.is_alone_sale = 1 AND " . "g.is_delete = 0 AND ({$children} OR " . get_extension_goods($children) . ')'; if ($brand > 0) { $where .= "AND g.brand_id={$brand} "; } if ($min > 0) { $where .= " AND g.shop_price >= {$min} "; } if ($max > 0) { $where .= " AND g.shop_price <= {$max} "; } /* 获得商品列表 */ $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, g.promote_price, g.goods_type, " . 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . "WHERE {$where} {$ext} ORDER BY {$sort} {$order}"; $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); $arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } /* 处理商品水印图片 */ $watermark_img = ''; if ($promote_price != 0) { $watermark_img = "watermark_promote_small"; } elseif ($row['is_new'] != 0) { $watermark_img = "watermark_new_small"; } elseif ($row['is_best'] != 0) { $watermark_img = "watermark_best_small"; } elseif ($row['is_hot'] != 0) { $watermark_img = 'watermark_hot_small'; } if ($watermark_img != '') { $arr[$row['goods_id']]['watermark_img'] = $watermark_img; } $arr[$row['goods_id']]['goods_id'] = $row['goods_id']; if ($display == 'grid') { $arr[$row['goods_id']]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; } else { $arr[$row['goods_id']]['goods_name'] = $row['goods_name']; } $arr[$row['goods_id']]['name'] = strlen($row['goods_name']) > 16 ? mb_substr($row['goods_name'], 0, 16, 'utf-8') . '..' : $row['goods_name']; $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief']; $arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']); $arr[$row['goods_id']]['market_price'] = price_format($row['market_price']); $arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']); $arr[$row['goods_id']]['type'] = $row['goods_type']; $arr[$row['goods_id']]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; $arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $arr[$row['goods_id']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $arr[$row['goods_id']]['sales_count'] = get_goods_sales_count($row['goods_id']); } return $arr; }