/** * 获得指定分类同级的所有分类以及该分类下的子分类 * * @access public * @param integer $cat_id 分类编号 * @return array */ function get_categories_tree_pro($cat_id = 0) { if ($cat_id > 0) { $sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '{$cat_id}'"; $parent_id = $GLOBALS['db']->getOne($sql); } else { $parent_id = 0; } $admin_agency_id = admin_agency_id() ? admin_agency_id() : agency_id(); if ($admin_agency_id) { // $where = " AND (FIND_IN_SET('$admin_agency_id',agency_cat) OR host_cat = 1) "; //注释2015-03-19 ccx $where = " AND (FIND_IN_SET('{$admin_agency_id}',agency_cat)) "; } else { $where = "AND host_cat = 1 "; } /* 判断当前分类中全是是否是底级分类, 如果是取出底级分类上级分类, 如果不是取当前分类及其下的子分类 */ $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '{$parent_id}' AND is_show = 1 "; if ($GLOBALS['db']->getOne($sql) || $parent_id == 0) { /* 获取当前分类及其子分类 */ $sql = 'SELECT cat_id,cat_name ,parent_id,is_show ' . 'FROM ' . $GLOBALS['ecs']->table('category') . "WHERE parent_id = '{$parent_id}' AND is_show = 1 {$where} ORDER BY sort_order ASC, cat_id ASC"; $res = $GLOBALS['db']->getAll($sql); foreach ($res as $row) { $cat_id = $row['cat_id']; $children = get_children($cat_id); $cat = $GLOBALS['db']->getRow('SELECT cat_name, keywords, cat_desc, style, grade, filter_attr, parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '{$cat_id}'"); /* 获取分类下文章 */ $sql = 'SELECT a.article_id, a.title, ac.cat_name, a.add_time, a.file_url, a.open_type FROM ' . $GLOBALS['ecs']->table('article_cat') . ' AS ac RIGHT JOIN ' . $GLOBALS['ecs']->table('article') . " AS a ON a.cat_id=ac.cat_id AND a.is_open = 1 WHERE ac.cat_name='{$row['cat_name']}' ORDER BY a.article_type,a.article_id DESC LIMIT 4 "; $articles = $GLOBALS['db']->getAll($sql); foreach ($articles as $key => $val) { $articles[$key]['url'] = $val['open_type'] != 1 ? build_uri('article', array('aid' => $val['article_id']), $val['title']) : trim($val['file_url']); } /* 获取分类下品牌 */ $sql = "SELECT b.brand_id, b.brand_name, b.brand_logo, COUNT(*) AS goods_num, IF(b.brand_logo > '', '1', '0') AS tag " . "FROM " . $GLOBALS['ecs']->table('brand') . "AS b, " . $GLOBALS['ecs']->table('goods') . " AS g LEFT JOIN " . $GLOBALS['ecs']->table('goods_cat') . " AS gc ON g.goods_id = gc.goods_id " . "WHERE g.brand_id = b.brand_id AND ({$children} OR " . 'gc.cat_id ' . db_create_in(array_unique(array_merge(array($cat_id), array_keys(cat_list($cat_id, 0, false))))) . ") AND b.is_show = 1 " . " AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 " . "GROUP BY b.brand_id HAVING goods_num > 0 ORDER BY b.sort_order, b.brand_id ASC"; //dump($sql); $brands = $GLOBALS['db']->getAll($sql); foreach ($brands as $key => $val) { $brands[$key]['brand_name'] = $val['brand_name']; $brands[$key]['url'] = build_uri('category', array('cid' => $cat_id, 'bid' => $val['brand_id'], 'price_min' => $price_min, 'price_max' => $price_max, 'filter_attr' => $filter_attr_str), $cat['cat_name']); } $cat_arr[$row['cat_id']]['brands'] = $brands; $cat_arr[$row['cat_id']]['articles'] = $articles; if ($row['is_show']) { $cat_arr[$row['cat_id']]['id'] = $row['cat_id']; $cat_arr[$row['cat_id']]['name'] = $row['cat_name']; $cat_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']); if (isset($row['cat_id']) != NULL) { $cat_arr[$row['cat_id']]['cat_id'] = get_child_tree_pro($row['cat_id']); } } } } if (isset($cat_arr)) { return $cat_arr; } }
/** * 获得指定分类同级的所有分类以及该分类下的子分类 * * @access public * @param integer $cat_id 分类编号 * @return array */ function get_categories_tree($cat_id = 0) { if ($cat_id > 0) { $sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '{$cat_id}'"; $parent_id = $GLOBALS['db']->getOne($sql); } else { $parent_id = 0; } $admin_agency_id = admin_agency_id() ? admin_agency_id() : agency_id(); if ($admin_agency_id) { //$where = " AND (FIND_IN_SET('$admin_agency_id',agency_cat) OR host_cat = 1) "; //注释2015-03-19 ccx $where = " AND (FIND_IN_SET('{$admin_agency_id}',agency_cat) ) "; } else { $where = "AND host_cat = 1 "; } //dump($where); /* 判断当前分类中全是是否是底级分类, 如果是取出底级分类上级分类, 如果不是取当前分类及其下的子分类 */ $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '{$parent_id}' AND is_show = 1 "; if ($GLOBALS['db']->getOne($sql) || $parent_id == 0) { /* 获取当前分类及其子分类 */ $sql = 'SELECT cat_id,cat_name ,parent_id,is_show ' . 'FROM ' . $GLOBALS['ecs']->table('category') . "WHERE parent_id = '{$parent_id}' AND is_show = 1 {$where} ORDER BY sort_order ASC, cat_id ASC"; $res = $GLOBALS['db']->getAll($sql); //dump($res); foreach ($res as $row) { if ($row['is_show']) { $cat_arr[$row['cat_id']]['id'] = $row['cat_id']; $cat_arr[$row['cat_id']]['name'] = $row['cat_name']; $cat_arr[$row['cat_id']]['url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']); if (isset($row['cat_id']) != NULL) { $cat_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']); } } } } if (isset($cat_arr)) { return $cat_arr; } }
/** * 获取广告数据 **/ public function get_res() { $fiel_name = $this->php_file(); if ($fiel_name === false) { return false; } $admin_agency_id = agency_id(); $res = $this->db->getAll("SELECT position_id,id,keyword,particulars,url,img,width,height,admin_agency_id,file,ad_name FROM " . $this->ecs->table('ad_new') . " WHERE file like '%,{$fiel_name},%' AND start = 1 AND admin_agency_id = {$admin_agency_id}"); //$res = $this->db->getAll("SELECT position_id,id,keyword,particulars,url,img,width,height,admin_agency_id,file,ad_name FROM ". //$this->ecs->table('ad_new')." WHERE file like '%,$fiel_name,%' AND start = 1"); if (empty($res)) { return false; } $return_arr = array(); foreach ($res as $key => $value) { if (strpos($value['img'], 'http://') === false) { $value['img'] = img_url() . $value['img']; } $return_arr[$value['position_id']] = $value; } return $return_arr; }
/** * ccx 2015-03-17 主站跟代理商的分类显示要区分开来 start * 获得指定分类下的子分类的数组 * * @access public * @param int $cat_id 分类的ID * @param int $selected 当前选中分类的ID * @param boolean $re_type 返回的类型: 值为真时返回下拉列表,否则返回数组 * @param int $level 限定返回的级数。为0时返回所有级数 * @param int $is_show_all 如果为true显示所有分类,如果为false隐藏不可见分类。 * @return mix */ function cat_list_ccx($cat_id = 0, $selected = 0, $re_type = true, $level = 0, $is_show_all = true) { static $res = NULL; $admin_agency_id = admin_agency_id() ? admin_agency_id() : agency_id(); if ($admin_agency_id) { $where = " WHERE c.agency_cat like '%,{$admin_agency_id},%' "; } else { $admin_agency_id = empty($_REQUEST['admin_agency_id']) ? '' : trim($_REQUEST['admin_agency_id']); if ($admin_agency_id) { $where = " WHERE c.agency_cat like '%,{$admin_agency_id},%' "; } else { $where = "WHERE c.host_cat = 1 "; } } if ($res === NULL) { $data = read_static_cache('cat_pid_releate'); $data = false; if ($data === false) { $sql = "SELECT c.host_cat,c.agency_cat,c.cat_id, c.cat_name, c.measure_unit, c.parent_id, c.is_show," . "c.show_in_nav, c.grade, c.sort_order, COUNT(s.cat_id) AS has_children " . 'FROM ' . $GLOBALS['ecs']->table('category') . " AS c " . "LEFT JOIN " . $GLOBALS['ecs']->table('category') . " AS s ON s.parent_id=c.cat_id " . " {$where} GROUP BY c.cat_id " . 'ORDER BY c.parent_id, c.sort_order ASC'; $res = $GLOBALS['db']->getAll($sql); $sql = "SELECT cat_id, COUNT(*) AS goods_num " . " FROM " . $GLOBALS['ecs']->table('goods') . " WHERE is_delete = 0 AND is_on_sale = 1 " . " GROUP BY cat_id"; $res2 = $GLOBALS['db']->getAll($sql); $sql = "SELECT gc.cat_id, COUNT(*) AS goods_num " . " FROM " . $GLOBALS['ecs']->table('goods_cat') . " AS gc , " . $GLOBALS['ecs']->table('goods') . " AS g " . " WHERE g.goods_id = gc.goods_id AND g.is_delete = 0 AND g.is_on_sale = 1 " . " GROUP BY gc.cat_id"; $res3 = $GLOBALS['db']->getAll($sql); $newres = array(); foreach ($res2 as $k => $v) { $newres[$v['cat_id']] = $v['goods_num']; foreach ($res3 as $ks => $vs) { if ($v['cat_id'] == $vs['cat_id']) { $newres[$v['cat_id']] = $v['goods_num'] + $vs['goods_num']; } } } foreach ($res as $k => $v) { $res[$k]['goods_num'] = !empty($newres[$v['cat_id']]) ? $newres[$v['cat_id']] : 0; if (admin_agency_id()) { $res[$k]['agency_state'] = strpos($v['agency_cat'], ',' . admin_agency_id() . ',') !== false ? 1 : 0; } } //如果数组过大,不采用静态缓存方式 if (count($res) <= 1000) { //write_static_cache('cat_pid_releate', $res); } } else { $res = $data; } } if (empty($res) == true) { return $re_type ? '' : array(); } $options = cat_options($cat_id, $res); // 获得指定分类下的子分类的数组 $children_level = 99999; //大于这个分类的将被删除 if ($is_show_all == false) { foreach ($options as $key => $val) { if ($val['level'] > $children_level) { unset($options[$key]); } else { if ($val['is_show'] == 0) { unset($options[$key]); if ($children_level > $val['level']) { $children_level = $val['level']; //标记一下,这样子分类也能删除 } } else { $children_level = 99999; //恢复初始值 } } } } /* 截取到指定的缩减级别 */ if ($level > 0) { if ($cat_id == 0) { $end_level = $level; } else { $first_item = reset($options); // 获取第一个元素 $end_level = $first_item['level'] + $level; } /* 保留level小于end_level的部分 */ foreach ($options as $key => $val) { if ($val['level'] >= $end_level) { unset($options[$key]); } } } if ($re_type == true) { $select = ''; foreach ($options as $var) { $select .= '<option value="' . $var['cat_id'] . '" '; $select .= $selected == $var['cat_id'] ? "selected='ture'" : ''; $select .= '>'; if ($var['level'] > 0) { $select .= str_repeat(' ', $var['level'] * 4); } $select .= htmlspecialchars(addslashes($var['cat_name']), ENT_QUOTES) . '</option>'; } return $select; } else { foreach ($options as $key => $value) { $options[$key]['url'] = build_uri('category', array('cid' => $value['cat_id']), $value['cat_name']); //if(empty($options[$key]['host_cat'])) //{ //if(!admin_agency_id() || !strstr($options[$key]['agency_cat'],','.admin_agency_id().',')) //unset($options[$key]); //} } return $options; } }
/** * 用户注册,登录函数 * * @access public * @param string $username 注册用户名 * @param string $password 用户密码 * @param string $email 注册email * @param array $other 注册的其他信息 * * @return bool $bool */ function register($username, $password, $email, $other = array()) { /* 检查注册是否关闭 */ if (!empty($GLOBALS['_CFG']['shop_reg_closed'])) { $GLOBALS['err']->add($GLOBALS['_LANG']['shop_register_closed']); } /* 检查username */ if (empty($username)) { $GLOBALS['err']->add($GLOBALS['_LANG']['username_empty']); } else { if (preg_match('/\'\\/^\\s*$|^c:\\\\con\\\\con$|[%,\\*\\"\\s\\t\\<\\>\\&\'\\\\]/', $username)) { $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['username_invalid'], htmlspecialchars($username))); } } /* 检查email 去掉邮箱 if (empty($email)) { $GLOBALS['err']->add($GLOBALS['_LANG']['email_empty']); } else { if (!is_email($email)) { $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['email_invalid'], htmlspecialchars($email))); } }*/ if ($GLOBALS['err']->error_no > 0) { return false; } /* 检查是否和管理员重名 */ if (admin_registered($username)) { $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['username_exist'], $username)); return false; } if (!$GLOBALS['user']->add_user($username, $password, $email)) { if ($GLOBALS['user']->error == ERR_INVALID_USERNAME) { $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['username_invalid'], $username)); } elseif ($GLOBALS['user']->error == ERR_USERNAME_NOT_ALLOW) { $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['username_not_allow'], $username)); } elseif ($GLOBALS['user']->error == ERR_USERNAME_EXISTS) { $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['username_exist'], $username)); } elseif ($GLOBALS['user']->error == ERR_INVALID_EMAIL) { $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['email_invalid'], $email)); } elseif ($GLOBALS['user']->error == ERR_EMAIL_NOT_ALLOW) { $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['email_not_allow'], $email)); } elseif ($GLOBALS['user']->error == ERR_EMAIL_EXISTS) { $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['email_exist'], $email)); } else { $GLOBALS['err']->add('UNKNOWN ERROR!'); } //注册失败 return false; } else { //注册成功 /* 写入代理商id */ $agency_id = agency_id(); $GLOBALS['db']->query("update " . $GLOBALS['ecs']->table('users') . " set top_rank='{$agency_id}' where user_name='{$username}'"); /* 设置成登录状态 */ $GLOBALS['user']->set_session($username); $GLOBALS['user']->set_cookie($username); /* 注册送积分 */ if (!empty($GLOBALS['_CFG']['register_points'])) { log_account_change($_SESSION['user_id'], 0, 0, $GLOBALS['_CFG']['register_points'], $GLOBALS['_CFG']['register_points'], $GLOBALS['_LANG']['register_points']); } /*推荐处理*/ $affiliate = unserialize($GLOBALS['_CFG']['affiliate']); if (isset($affiliate['on']) && $affiliate['on'] == 1) { // 推荐开关开启 $up_uid = get_affiliate(); empty($affiliate) && ($affiliate = array()); $affiliate['config']['level_register_all'] = intval($affiliate['config']['level_register_all']); $affiliate['config']['level_register_up'] = intval($affiliate['config']['level_register_up']); if ($up_uid) { if (!empty($affiliate['config']['level_register_all'])) { if (!empty($affiliate['config']['level_register_up'])) { $rank_points = $GLOBALS['db']->getOne("SELECT rank_points FROM " . $GLOBALS['ecs']->table('users') . " WHERE user_id = '{$up_uid}'"); if ($rank_points + $affiliate['config']['level_register_all'] <= $affiliate['config']['level_register_up']) { log_account_change($up_uid, 0, 0, $affiliate['config']['level_register_all'], 0, sprintf($GLOBALS['_LANG']['register_affiliate'], $_SESSION['user_id'], $username)); } } else { log_account_change($up_uid, 0, 0, $affiliate['config']['level_register_all'], 0, $GLOBALS['_LANG']['register_affiliate']); } } //设置推荐人 $sql = 'UPDATE ' . $GLOBALS['ecs']->table('users') . ' SET parent_id = ' . $up_uid . ' WHERE user_id = ' . $_SESSION['user_id']; $GLOBALS['db']->query($sql); } } //定义other合法的变量数组 $other_key_array = array('msn', 'qq', 'office_phone', 'home_phone', 'mobile_phone'); $update_data['reg_time'] = local_strtotime(local_date('Y-m-d H:i:s')); if ($other) { foreach ($other as $key => $val) { //删除非法key值 if (!in_array($key, $other_key_array)) { unset($other[$key]); } else { $other[$key] = htmlspecialchars(trim($val)); //防止用户输入javascript代码 } } $update_data = array_merge($update_data, $other); } $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('users'), $update_data, 'UPDATE', 'user_id = ' . $_SESSION['user_id']); update_user_info(); // 更新用户信息 recalculate_price(); // 重新计算购物车中的商品价格 return true; } }
} } } assign_template('c', array($cat_id)); $position = assign_ur_here($cat_id, $brand_name); $smarty->assign('page_title', $position['title']); // 页面标题 $smarty->assign('ur_here', $position['ur_here']); // 当前位置 /*ccx 2014-12-20 代理商只显示自己的商品导航 开始*/ //if(agency_id() != 345 ) //大学城代理商 //{ $smarty->assign('categories_pro', get_categories_tree_pro()); // 分类树加强版/* 周改 */ //} $smarty->assign('agency_id', agency_id()); /*ccx 2014-12-20 代理商只显示自己的商品导航 结束*/ $smarty->assign('categories', get_categories_tree($cat_id)); // 分类树 $smarty->assign('helps', get_shop_help()); // 网店帮助 $smarty->assign('top_goods', get_top10()); // 销售排行 $smarty->assign('show_marketprice', $_CFG['show_marketprice']); $smarty->assign('category', $cat_id); /* 周改 */ $sql = 'SELECT parent_id FROM ' . $ecs->table('category') . ' WHERE cat_id =' . $cat_id; $parent_id = $db->getOne($sql); $parent_id_show = $parent_id; while ($parent_id != 0) { $parent_id_show = $parent_id;
function filtration_xml() { $xml = get_flash_xml(); $agency_id = agency_id(); $playerdb = array(); foreach ($xml as $key => $val) { if ($agency_id == $val['agency']) { if (strpos($val['src'], 'http') === false) { $playerdb[$key]['src'] = img_url() . $val['src']; $playerdb[$key]['url'] = preg_match('|http:|', $val['url']) ? $val['url'] : $uri . $val['url']; } } } $ad = array(); if (!empty($playerdb)) { $i = 1; foreach ($playerdb as $key => $value) { if ($i <= 5) { $value['src'] = $value['src']; $ad[] = $value; } $i++; } } else { $ad[0]['src'] = img_url() . 'data/afficheimg/ad.jpg'; $ad[0]['url'] = 'http://'; } return $ad; }
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和 * 使用;不允许对程序代码以任何形式任何目的的再发布。 * ============================================================================ * $Author: liubo $ * $Id: index.php 17217 2011-01-19 06:29:08Z liubo $ */ define('IN_ECS', true); require dirname(__FILE__) . '/includes/init.php'; //print_r($_SESSION); //$kk=get_recommend_cat('新品上市'); //dump($kk); if ((DEBUG_MODE & 2) != 2) { $smarty->caching = true; } $ua = strtolower($_SERVER['HTTP_USER_AGENT']); $smarty->assign('link', agency_id()); $uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i"; if (($ua == '' || preg_match($uachar, $ua)) && !strpos(strtolower($_SERVER['REQUEST_URI']), 'wap')) { $Loaction = 'mobile/'; if (!empty($Loaction)) { ecs_header("Location: {$Loaction}\n"); exit; } } /*------------------------------------------------------ */ //-- Shopex系统地址转换 /*------------------------------------------------------ */ if (!empty($_GET['gOo'])) { if (!empty($_GET['gcat'])) { /* 商品分类。*/ $Loaction = 'category.php?id=' . $_GET['gcat'];
$parent_id = get_affiliate(); if ($user_id == $parent_id) { $parent_id = 0; } } elseif (isset($affiliate['on']) && $affiliate['on'] == 1 && $affiliate['config']['separate_by'] == 0) { //推荐注册分成 $parent_id = 0; } else { //分成功能关闭 $parent_id = 0; } $order['parent_id'] = $parent_id; /* 插入订单表 */ $error_no = 0; /*add by hg for date 2014-04-22 订单加入代理商id begin*/ $order['admin_agency_id'] = agency_id(); /*end*/ /*ccx 2014-12-15 时间限定,在规定的时间内,只要下了订单就会产生相应的活动代码 本地活动到2014-12-31 开始*/ if (gmtime() < 1420041600) { $order['activity_code'] = '2014120001'; //活动代码表示:2014年12月加上后面0001四位 } /*ccx 2014-12-15 时间限定,在规定的时间内,只要下了订单就会产生相应的活动代码 本地活动到2014-12-31 结束*/ /*ccx 2015-04-20 针对无上级会员, 在代理商站点购物上级归属该代理商 start*/ //print_r($order); edit_parent_id($order['user_id'], $order['admin_agency_id']); /*ccx 2015-04-20 针对无上级会员, 在代理商站点购物上级归属该代理商 end*/ do { $order['order_sn'] = get_order_sn(); //获取新订单号 $GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'), $order, 'INSERT');
/** * 代理商余额不作不能进行购物动作 * time:2014-05-22 * author:hg **/ function check_agecny_remaining($goods_amount) { return false; //关闭此方法 $agency_id = agency_id(); if ($agency_id) { $user_money = $GLOBALS['db']->getOne("select user_money from" . $GLOBALS['ecs']->table('users') . " where user_id = {$agency_id}"); if ($goods_amount > $user_money) { show_message('该站点暂时关闭购物功能。如有不便,敬请谅解!'); } } }
function get_logo_pic() { $agency_id = agency_id(); if ($agency_id == 0) { //$shop_logo = "主站的logo"; $sql = 'SELECT value FROM ' . $GLOBALS['ecs']->table('shop_config') . " WHERE code = 'shop_logo' AND type = 'file' "; $row = $GLOBALS['db']->getRow($sql); } else { //$shop_logo = "代理商的logo"; $sql = 'SELECT value FROM ' . $GLOBALS['ecs']->table('agency_shop_config') . " WHERE code = 'shop_logo' AND type = 'file' AND admin_agency_id = " . $agency_id; $row = $GLOBALS['db']->getRow($sql); } return $row['value']; }