function __construct()
 {
     $this->CI =& get_instance();
     //变量可以在这里定义,或者来自配置文件,也可以去数据
     $smtp = read_static_cache("smtp_config");
     $website = read_static_cache("website_config");
     $upload = read_static_cache("upload_config");
     $this->CI->load->model("sk_admin/systemconfig_model");
     if (empty($smtp)) {
         $where = array("app_name" => "smtp");
         $smtp_list = $this->CI->systemconfig_model->getAll($where);
         $smtp = array();
         if ($smtp_list && count($smtp_list) > 0) {
             foreach ($smtp_list as $k => $v) {
                 $smtp[$v['paras']] = $v['value'];
             }
         }
         if (!empty($smtp)) {
             write_static_cache("smtp_config", $smtp);
         }
     }
     if (empty($website)) {
         $where = array("app_name" => "website");
         $website_list = $this->CI->systemconfig_model->getAll($where);
         $website = array();
         if ($website_list && count($website_list) > 0) {
             foreach ($website_list as $k => $v) {
                 $website[$v['paras']] = $v['value'];
             }
         }
         if (!empty($website)) {
             write_static_cache("website_config", $website);
         }
     }
     if (empty($upload)) {
         $where = array("app_name" => "upload");
         $upload_list = $this->CI->systemconfig_model->getAll($where);
         $upload = array();
         if ($upload_list && count($upload_list) > 0) {
             foreach ($upload_list as $k => $v) {
                 $upload[$v['paras']] = $v['value'];
             }
         }
         if (!empty($upload)) {
             write_static_cache("upload_config", $upload);
         }
     }
     $this->variable['smtp'] = $smtp;
     $this->variable['website'] = $website;
     $this->variable['upload'] = $upload;
     $this->CI->load->vars($this->variable);
 }
function refresh_subsite_cache()
{
    global $db, $_CFG;
    $cache_file_path = QISHI_ROOT_PATH . "data/cache_subsite.php";
    $cache_file_path_m = QISHI_ROOT_PATH . "data/cache_m_subsite.php";
    $sql = "SELECT * FROM " . table('subsite') . " WHERE s_effective=1 ORDER BY s_order desc,s_id desc";
    $arr = $db->getall($sql);
    foreach ($arr as $key => $val) {
        $s_m_domain_key = $val['s_m_domain'] ? $val['s_m_domain'] : $val['s_domain'];
        $config_arr[$val['s_domain']] = array("id" => $val['s_id'], "sitename" => $val['s_sitename'], "domain" => 'http://' . $val['s_domain'] . '/', "m_domain" => $val['s_m_domain'] ? 'http://' . $val['s_m_domain'] . '/' : 'http://' . $val['s_domain'] . '/m/', "district" => $val['s_district'], "districtname" => $val['s_districtname'], "tpl" => $val['s_tpl'], "logo" => $val['s_logo'], "title" => $val['s_title'], "keywords" => $val['s_keywords'], "description" => $val['s_description']);
        $config_m_arr[$s_m_domain_key] = array("id" => $val['s_id'], "sitename" => $val['s_sitename'], "domain" => 'http://' . $val['s_domain'] . '/', "m_domain" => $val['s_m_domain'] ? 'http://' . $val['s_m_domain'] . '/' : 'http://' . $val['s_domain'] . '/m/', "district" => $val['s_district'], "districtname" => $val['s_districtname'], "tpl" => $val['s_tpl'], "logo" => $val['s_logo'], "title" => $val['s_title'], "keywords" => $val['s_keywords'], "description" => $val['s_description']);
    }
    write_static_cache($cache_file_path, $config_arr);
    write_static_cache($cache_file_path_m, $config_m_arr);
}
Exemple #3
0
        $apiget = "ver= {$ecs_version} &ecs_lang= {$ecs_lang} &charset= {$ecs_charset} ";
        $t = new transport();
        $api_comment = $t->request('http://cloud.ecshop.com/menu_api.php', $apiget);
        $api_str = $api_comment["body"];
        if (!empty($api_str)) {
            include_once ROOT_PATH . 'includes/cls_json.php';
            $json = new JSON();
            $api_arr = @$json->decode($api_str, 1);
            if (!empty($api_arr) && $api_arr['error'] == 0 && md5($api_arr['content']) == $api_arr['hash']) {
                $api_arr['content'] = urldecode($api_arr['content']);
                if ($ecs_charset != 'UTF-8') {
                    $api_arr['content'] = ecs_iconv('UTF-8', $ecs_charset, $api_arr['content']);
                }
                echo $api_arr['content'];
                $api_arr['api_time'] = date('dmY');
                write_static_cache('menu_api', $api_arr);
                exit;
            } else {
                exit;
            }
        } else {
            exit;
        }
    } else {
        die($data['content']);
    }
} elseif ($_REQUEST['act'] == 'first') {
    $smarty->assign('countries', get_regions());
    $smarty->assign('provinces', get_regions(1, 1));
    $smarty->assign('cities', get_regions(2, 2));
    $sql = 'SELECT value from ' . $ecs->table('shop_config') . " WHERE code='shop_name'";
Exemple #4
0
/**
 * 载入配置信息
 *
 * @access  public
 * @return  array
 */
function load_config()
{
    $arr = array();
    $data = read_static_cache('shop_config');
    if ($data === false) {
        $sql = 'SELECT code, value FROM ' . $GLOBALS['ecs']->table('shop_config') . ' WHERE parent_id > 0';
        $res = $GLOBALS['db']->getAll($sql);
        foreach ($res as $row) {
            $arr[$row['code']] = $row['value'];
        }
        /* 对数值型设置处理 */
        $arr['watermark_alpha'] = intval($arr['watermark_alpha']);
        $arr['market_price_rate'] = floatval($arr['market_price_rate']);
        $arr['integral_scale'] = floatval($arr['integral_scale']);
        //$arr['integral_percent']     = floatval($arr['integral_percent']);
        $arr['cache_time'] = intval($arr['cache_time']);
        $arr['thumb_width'] = intval($arr['thumb_width']);
        $arr['thumb_height'] = intval($arr['thumb_height']);
        $arr['image_width'] = intval($arr['image_width']);
        $arr['image_height'] = intval($arr['image_height']);
        $arr['best_number'] = !empty($arr['best_number']) && intval($arr['best_number']) > 0 ? intval($arr['best_number']) : 3;
        $arr['new_number'] = !empty($arr['new_number']) && intval($arr['new_number']) > 0 ? intval($arr['new_number']) : 3;
        $arr['hot_number'] = !empty($arr['hot_number']) && intval($arr['hot_number']) > 0 ? intval($arr['hot_number']) : 3;
        $arr['promote_number'] = !empty($arr['promote_number']) && intval($arr['promote_number']) > 0 ? intval($arr['promote_number']) : 3;
        $arr['top_number'] = intval($arr['top_number']) > 0 ? intval($arr['top_number']) : 10;
        $arr['history_number'] = intval($arr['history_number']) > 0 ? intval($arr['history_number']) : 5;
        $arr['comments_number'] = intval($arr['comments_number']) > 0 ? intval($arr['comments_number']) : 5;
        $arr['article_number'] = intval($arr['article_number']) > 0 ? intval($arr['article_number']) : 5;
        $arr['page_size'] = intval($arr['page_size']) > 0 ? intval($arr['page_size']) : 10;
        $arr['bought_goods'] = intval($arr['bought_goods']);
        $arr['goods_name_length'] = intval($arr['goods_name_length']);
        $arr['top10_time'] = intval($arr['top10_time']);
        $arr['goods_gallery_number'] = intval($arr['goods_gallery_number']) ? intval($arr['goods_gallery_number']) : 5;
        $arr['no_picture'] = !empty($arr['no_picture']) ? str_replace('../', './', $arr['no_picture']) : 'images/no_picture.gif';
        // 修改默认商品图片的路径
        $arr['qq'] = !empty($arr['qq']) ? $arr['qq'] : '';
        $arr['ww'] = !empty($arr['ww']) ? $arr['ww'] : '';
        $arr['default_storage'] = isset($arr['default_storage']) ? intval($arr['default_storage']) : 1;
        $arr['min_goods_amount'] = isset($arr['min_goods_amount']) ? floatval($arr['min_goods_amount']) : 0;
        $arr['one_step_buy'] = empty($arr['one_step_buy']) ? 0 : 1;
        $arr['invoice_type'] = empty($arr['invoice_type']) ? array('type' => array(), 'rate' => array()) : unserialize($arr['invoice_type']);
        $arr['show_order_type'] = isset($arr['show_order_type']) ? $arr['show_order_type'] : 0;
        // 显示方式默认为列表方式
        $arr['help_open'] = isset($arr['help_open']) ? $arr['help_open'] : 1;
        // 显示方式默认为列表方式
        if (!isset($GLOBALS['_CFG']['ecs_version'])) {
            /* 如果没有版本号则默认为2.0.5 */
            $GLOBALS['_CFG']['ecs_version'] = 'v2.0.5';
        }
        //限定语言项
        $lang_array = array('zh_cn', 'zh_tw', 'en_us');
        if (empty($arr['lang']) || !in_array($arr['lang'], $lang_array)) {
            $arr['lang'] = 'zh_cn';
            // 默认语言为简体中文
        }
        if (empty($arr['integrate_code'])) {
            $arr['integrate_code'] = 'ecshop';
            // 默认的会员整合插件为 ecshop
        }
        write_static_cache('shop_config', $arr);
    } else {
        $arr = $data;
    }
    return $arr;
}
Exemple #5
0
/**
*@param int $parent_id 父id
*@return array $arr  有层级的数组
*/
function digui($arrayinfo = array(), $parent_id = 0)
{
    global $db, $ecs;
    $data = read_static_cache('city_tree_68');
    if ($data !== false && is_array($data)) {
        return $data;
    }
    if (empty($arrayinfo)) {
        $sql = "select * from " . $ecs->table('region');
        $arrayinfo = $db->getAll($sql);
    }
    $arr = array();
    foreach ($arrayinfo as $key => $val) {
        if ($val['parent_id'] == $parent_id) {
            $region_id = $val['region_id'];
            $arr[$region_id] = array('id' => $region_id, 'text' => $val['region_name'], 'level' => $val['region_type'], 'parent_id' => $val['parent_id']);
            unset($arrayinfo[$key]);
            $arr[$region_id]['child'] = digui($arrayinfo, $region_id);
            if (empty($arr[$region_id]['child'])) {
                $arr[$region_id]['child'] = null;
            }
        }
    }
    write_static_cache('city_tree_68', $arr);
    return $arr;
}
Exemple #6
0
/**
 * 内容聚合关键字缓存
 * @return [type] [description]
 */
function refresh_content_key_link_cache($cachename)
{
    global $db;
    $data = "";
    $cache_file_path = QISHI_ROOT_PATH . "data/cache_" . $cachename . ".php";
    $sql = "SELECT * FROM " . table($cachename);
    $arr = $db->getall($sql);
    write_static_cache($cache_file_path, $arr);
}
Exemple #7
0
/**
 * 取得最近的上级分类的grade值.
 *
 * @param int $cat_id //当前的cat_id
 *
 * @return int
 */
function get_parent_grade($cat_id)
{
    static $res = null;
    if ($res === null) {
        $data = read_static_cache('cat_parent_grade');
        if ($data === false) {
            $sql = 'SELECT parent_id, cat_id, grade ' . ' FROM ' . $GLOBALS['ecs']->table('category');
            $res = $GLOBALS['db']->getAll($sql);
            write_static_cache('cat_parent_grade', $res);
        } else {
            $res = $data;
        }
    }
    if (!$res) {
        return 0;
    }
    $parent_arr = array();
    $grade_arr = array();
    foreach ($res as $val) {
        $parent_arr[$val['cat_id']] = $val['parent_id'];
        $grade_arr[$val['cat_id']] = $val['grade'];
    }
    while ($parent_arr[$cat_id] > 0 && $grade_arr[$cat_id] == 0) {
        $cat_id = $parent_arr[$cat_id];
    }
    return $grade_arr[$cat_id];
}
Exemple #8
0
/**
 * 获得推荐商品
 *
 * @access  public
 * @param   string      $type       推荐类型,可以是 best, new, hot
 * @return  array
 */
function get_recommend_goods($type = '', $cats = '')
{
    if (!in_array($type, array('best', 'new', 'hot'))) {
        return array();
    }
    //取不同推荐对应的商品
    static $type_goods = array();
    if (empty($type_goods[$type])) {
        //初始化数据
        $type_goods['best'] = array();
        $type_goods['new'] = array();
        $type_goods['hot'] = array();
        $data = read_static_cache('recommend_goods');
        if ($data === false) {
            $sql = 'SELECT g.goods_id, g.is_best, g.is_new, g.is_hot, g.is_promote, b.brand_name,g.sort_order ' . ' FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . ' LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . ' WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND (g.is_best = 1 OR g.is_new =1 OR g.is_hot = 1)' . ' ORDER BY g.sort_order, g.last_update DESC';
            $goods_res = $GLOBALS['db']->getAll($sql);
            //定义推荐,最新,热门,促销商品
            $goods_data['best'] = array();
            $goods_data['new'] = array();
            $goods_data['hot'] = array();
            $goods_data['brand'] = array();
            if (!empty($goods_res)) {
                foreach ($goods_res as $data) {
                    if ($data['is_best'] == 1) {
                        $goods_data['best'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']);
                    }
                    if ($data['is_new'] == 1) {
                        $goods_data['new'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']);
                    }
                    if ($data['is_hot'] == 1) {
                        $goods_data['hot'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']);
                    }
                    if ($data['brand_name'] != '') {
                        $goods_data['brand'][$data['goods_id']] = $data['brand_name'];
                    }
                }
            }
            write_static_cache('recommend_goods', $goods_data);
        } else {
            $goods_data = $data;
        }
        $time = gmtime();
        $order_type = $GLOBALS['_CFG']['recommend_order'];
        //按推荐数量及排序取每一项推荐显示的商品 order_type可以根据后台设定进行各种条件显示
        static $type_array = array();
        $type2lib = array('best' => 'recommend_best', 'new' => 'recommend_new', 'hot' => 'recommend_hot');
        if (empty($type_array)) {
            foreach ($type2lib as $key => $data) {
                if (!empty($goods_data[$key])) {
                    $num = get_library_number($data);
                    $data_count = count($goods_data[$key]);
                    $num = $data_count > $num ? $num : $data_count;
                    if ($order_type == 0) {
                        //usort($goods_data[$key], 'goods_sort');
                        $rand_key = array_slice($goods_data[$key], 0, $num);
                        foreach ($rand_key as $key_data) {
                            $type_array[$key][] = $key_data['goods_id'];
                        }
                    } else {
                        $rand_key = array_rand($goods_data[$key], $num);
                        if ($num == 1) {
                            $type_array[$key][] = $goods_data[$key][$rand_key]['goods_id'];
                        } else {
                            foreach ($rand_key as $key_data) {
                                $type_array[$key][] = $goods_data[$key][$key_data]['goods_id'];
                            }
                        }
                    }
                } else {
                    $type_array[$key] = array();
                }
            }
        }
        //取出所有符合条件的商品数据,并将结果存入对应的推荐类型数组中
        $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, g.goods_img, RAND() AS rnd " . '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']}' ";
        $type_merge = array_merge($type_array['new'], $type_array['best'], $type_array['hot']);
        $type_merge = array_unique($type_merge);
        $sql .= ' WHERE g.goods_id ' . db_create_in($type_merge);
        $sql .= ' ORDER BY g.sort_order, g.last_update DESC';
        $result = $GLOBALS['db']->getAll($sql);
        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'] = isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] : '';
            $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']);
            if (in_array($row['goods_id'], $type_array['best'])) {
                $type_goods['best'][] = $goods[$idx];
            }
            if (in_array($row['goods_id'], $type_array['new'])) {
                $type_goods['new'][] = $goods[$idx];
            }
            if (in_array($row['goods_id'], $type_array['hot'])) {
                $type_goods['hot'][] = $goods[$idx];
            }
        }
    }
    return $type_goods[$type];
}
Exemple #9
0
        $ecs_style = $style;
        $shop_url = urlencode($ecs->url());

        $patch_file = file_get_contents(ROOT_PATH.ADMIN_PATH."/patch_num");

        $apiget = "ver= $ecs_version &lang= $ecs_lang &release= $ecs_release &php_ver= $php_ver &mysql_ver= $mysql_ver &ocount= $ocount &oamount= $oamount &gcount= $gcount &charset= $ecs_charset &usecount= $ecs_user &template= $ecs_template &style= $ecs_style &url= $shop_url &patch= $patch_file ";

        $t = new transport;
        $api_comment = $t->request('http://ecshop.ecmoban.com/checkver.php', $apiget);
        $api_str = $api_comment["body"];
        echo $api_str;
        
        $f=ROOT_PATH . 'data/config.php'; 
        file_put_contents($f,str_replace("'API_TIME', '".API_TIME."'","'API_TIME', '".date('Y-m-d H:i:s',time())."'",file_get_contents($f)));
        
        write_static_cache('api_str', $api_str);
    }
    else 
    {
        echo $data;
    }

}


/*------------------------------------------------------ */
//-- 开店向导第一步
/*------------------------------------------------------ */

elseif ($_REQUEST['act'] == 'first')
{
Exemple #10
0
    die($json->encode($result_url));
} elseif ($_POST['act'] == 'word_search') {
    $keyword = !empty($_POST['keyword']) ? $_POST['keyword'] : '';
    $sql = "SELECT region_id,region_name,pinyin FROM " . $ecs->table('region') . " WHERE region_name LIKE '{$keyword}%' OR pinyin LIKE '{$keyword}%'";
    $rows = $db->getAll($sql);
    //dump($rows);
    die($json->encode($rows));
} elseif ($_POST['act'] == 'capital_search') {
    #读取缓存
    $rows = read_static_cache('region');
    if ($rows === false) {
        $sql = "SELECT region_id,region_name,capital FROM " . $ecs->table('region') . " WHERE region_type = 2 ORDER BY capital ASC";
        $rows = array();
        $rows = $db->getAll($sql);
        #写入缓存
        write_static_cache('region', $rows);
    }
    /* 对数据进行组装 start */
    $arr = array();
    foreach ($rows as $key => $value) {
        $arr[$value['capital']][] = $value;
    }
    $html = '';
    foreach ($arr as $k => $v) {
        $city = '';
        $html .= "<li id='city-A' class=''><div class='cf fn-clear'><div class='label'><strong>" . $k . "</strong></div><div class='label-city fn-clear'>";
        foreach ($v as $city_k => $city_v) {
            $city .= "<div class='city-content'><a class='link' onclick='jq_cookie({$city_v['region_id']})' value='{$city_v['region_id']}' " . " style='font-size:14px;' target='_self' href='{$url}'>{$city_v['region_name']}</a>" . '<div class="city-county">';
            $res = array();
            $sql = "SELECT region_id,region_name,capital FROM " . $ecs->table('region') . " WHERE parent_id = {$city_v['region_id']} ORDER BY capital ASC";
            $res = $db->getAll($sql);
Exemple #11
0
/**
*@param int $parent_id 父id
*@return array $arr  有层级的数组
*/
function digui($arrayinfo = array(), $parent_id = 0)
{
    global $db, $ecs;
    $data = read_static_cache('city_tree_68');
    //if($data !== false && is_array($data)){
    //	return $data;
    //}
    $select_region = create_ever_sql();
    if (count($select_region) > 0) {
        $where = " where region_id not in (" . implode(',', $select_region) . ")";
    } else {
        $where = '';
    }
    $sql = "select * from " . $ecs->table('region') . $where;
    $arrayinfo = $db->getAll($sql);
    $arr = array();
    $arr = sss($arrayinfo, 0);
    write_static_cache('city_tree_68', $arr);
    return $arr;
}
Exemple #12
0
    update_configure($code, '');
    /* 记录日志 */
    admin_log('', 'edit', 'shop_config');
    /* 清除缓存 */
    clear_all_files();
    sys_msg($_LANG['save_success'], 0);
} elseif ($_REQUEST['act'] == 'shop_cache') {
    /* 检查权限 */
    check_authz_json('shop_config');
    $sql = "SELECT * FROM " . $ecs->table('shop') . " WHERE status > 0";
    $rs = $db->getAll($sql);
    $shop_list = array();
    foreach ($rs as &$shop) {
        $shop_list[$shop['shop_id']] = $shop;
    }
    write_static_cache('shop_list', $shop_list);
    // copy to mobile dir
    $src = ROOT_PATH . 'temp/static_caches/shop_list.php';
    $dest = ROOT_PATH . 'mobile/data/static_caches/shop_list.php';
    @copy($src, $dest);
}
/**
 * 设置系统设置
 *
 * @param   string  $key
 * @param   string  $val
 *
 * @return  boolean
 */
function update_configure($key, $val = '')
{
Exemple #13
0
 /**
  * 载入配置信息
  * @access  public
  * @return  array
  */
 public function load_config()
 {
     $data = read_static_cache('touch_shop_config');
     if ($data === false) {
         $sql = 'SELECT code, value FROM ' . $this->pre . 'touch_shop_config WHERE parent_id > 0';
         $res = $this->query($sql);
         $arr1 = array();
         foreach ($res as $row) {
             $arr1[$row['code']] = $row['value'];
         }
         $sql = 'SELECT code, value FROM ' . $this->pre . 'shop_config WHERE parent_id > 0';
         $res = $this->query($sql);
         $arr2 = array();
         foreach ($res as $row) {
             $arr2[$row['code']] = $row['value'];
         }
         $arr = array_merge($arr2, $arr1);
         /* 对数值型设置处理 */
         $arr['watermark_alpha'] = intval($arr['watermark_alpha']);
         $arr['market_price_rate'] = floatval($arr['market_price_rate']);
         $arr['integral_scale'] = floatval($arr['integral_scale']);
         //$arr['integral_percent']     = floatval($arr['integral_percent']);
         $arr['cache_time'] = intval($arr['cache_time']);
         $arr['thumb_width'] = intval($arr['thumb_width']);
         $arr['thumb_height'] = intval($arr['thumb_height']);
         $arr['image_width'] = intval($arr['image_width']);
         $arr['image_height'] = intval($arr['image_height']);
         $arr['best_number'] = !empty($arr['best_number']) && intval($arr['best_number']) > 0 ? intval($arr['best_number']) : 3;
         $arr['new_number'] = !empty($arr['new_number']) && intval($arr['new_number']) > 0 ? intval($arr['new_number']) : 3;
         $arr['hot_number'] = !empty($arr['hot_number']) && intval($arr['hot_number']) > 0 ? intval($arr['hot_number']) : 3;
         $arr['promote_number'] = !empty($arr['promote_number']) && intval($arr['promote_number']) > 0 ? intval($arr['promote_number']) : 3;
         $arr['top_number'] = intval($arr['top_number']) > 0 ? intval($arr['top_number']) : 10;
         $arr['history_number'] = intval($arr['history_number']) > 0 ? intval($arr['history_number']) : 5;
         $arr['comments_number'] = intval($arr['comments_number']) > 0 ? intval($arr['comments_number']) : 5;
         $arr['article_number'] = intval($arr['article_number']) > 0 ? intval($arr['article_number']) : 5;
         $arr['page_size'] = intval($arr['page_size']) > 0 ? intval($arr['page_size']) : 10;
         $arr['bought_goods'] = intval($arr['bought_goods']);
         $arr['goods_name_length'] = intval($arr['goods_name_length']);
         $arr['top10_time'] = intval($arr['top10_time']);
         $arr['goods_gallery_number'] = intval($arr['goods_gallery_number']) ? intval($arr['goods_gallery_number']) : 5;
         $arr['no_picture'] = !empty($arr['no_picture']) ? str_replace('./', '/', $arr['no_picture']) : __ROOT__ . '/data/common/images/no_picture.gif';
         // 修改默认商品图片的路径
         $arr['qq'] = !empty($arr['qq']) ? $arr['qq'] : '';
         $arr['ww'] = !empty($arr['ww']) ? $arr['ww'] : '';
         $arr['default_storage'] = isset($arr['default_storage']) ? intval($arr['default_storage']) : 1;
         $arr['min_goods_amount'] = isset($arr['min_goods_amount']) ? floatval($arr['min_goods_amount']) : 0;
         $arr['one_step_buy'] = empty($arr['one_step_buy']) ? 0 : 1;
         $arr['invoice_type'] = empty($arr['invoice_type']) ? array('type' => array(), 'rate' => array()) : unserialize($arr['invoice_type']);
         $arr['show_order_type'] = isset($arr['show_order_type']) ? $arr['show_order_type'] : 0;
         // 显示方式默认为列表方式
         $arr['help_open'] = isset($arr['help_open']) ? $arr['help_open'] : 1;
         // 显示方式默认为列表方式
         $ecs_version = C('ecs_version');
         if (!isset($ecs_version)) {
             /* 如果没有版本号则默认为2.0.5 */
             C('ecs_version', 'v2.7.3');
         }
         //限定语言项
         $lang_array = array('zh_cn', 'zh_tw', 'en_us');
         if (empty($arr['lang']) || !in_array($arr['lang'], $lang_array)) {
             $arr['lang'] = 'zh_cn';
             // 默认语言为简体中文
         }
         if (empty($arr['integrate_code'])) {
             $arr['integrate_code'] = 'ecshop';
             // 默认的会员整合插件为 ecshop
         }
         write_static_cache('touch_shop_config', $arr);
     } else {
         $arr = $data;
     }
     $config = array();
     foreach ($arr as $key => $vo) {
         $config[strtoupper($key)] = $vo;
     }
     return $config;
 }
/**
 * 取得最近的上级分类的grade值
 *
 * @access  public
 * @param   int     $cat_id    //当前的cat_id
 *
 * @return int
 */
function get_parent_grade($cat_id)
{
    static $res = NULL;
    if ($res === NULL) {
        $data = read_static_cache('cat_parent_grade_supplier' . $_GET['suppId']);
        if ($data === false) {
            $sql = "SELECT parent_id, cat_id, grade " . " FROM " . $GLOBALS['ecs']->table('supplier_category') . "WHERE supplier_id=" . $_GET['suppId'];
            $res = $GLOBALS['db']->getAll($sql);
            write_static_cache('cat_parent_grade_supplier' . $_GET['suppId'], $res);
        } else {
            $res = $data;
        }
    }
    if (!$res) {
        return 0;
    }
    $parent_arr = array();
    $grade_arr = array();
    foreach ($res as $val) {
        $parent_arr[$val['cat_id']] = $val['parent_id'];
        $grade_arr[$val['cat_id']] = $val['grade'];
    }
    while ($parent_arr[$cat_id] > 0 && $grade_arr[$cat_id] == 0) {
        $cat_id = $parent_arr[$cat_id];
    }
    return $grade_arr[$cat_id];
}
/**
 * 过滤和排序所有分类,返回一个带有缩进级别的数组
 *
 * @access  private
 * @param   int     $cat_id     上级分类ID
 * @param   array   $arr        含有所有分类的数组
 * @param   int     $level      级别
 * @return  void
 */
function cat_options($spec_cat_id, $arr) {
    static $cat_options = array();

    if (isset($cat_options[$spec_cat_id])) {
        return $cat_options[$spec_cat_id];
    }

    if (!isset($cat_options[0])) {
        $level = $last_cat_id = 0;
        $options = $cat_id_array = $level_array = array();
        $data = read_static_cache('cat_option_static');
        if ($data === false) {
            while (!empty($arr)) {
                foreach ($arr AS $key => $value) {
                    $cat_id = $value['cat_id'];
                    if ($level == 0 && $last_cat_id == 0) {
                        if ($value['parent_id'] > 0) {
                            break;
                        }

                        $options[$cat_id] = $value;
                        $options[$cat_id]['level'] = $level;
                        $options[$cat_id]['id'] = $cat_id;
                        $options[$cat_id]['name'] = $value['cat_name'];
                        unset($arr[$key]);

                        if ($value['has_children'] == 0) {
                            continue;
                        }
                        $last_cat_id = $cat_id;
                        $cat_id_array = array($cat_id);
                        $level_array[$last_cat_id] = ++$level;
                        continue;
                    }

                    if ($value['parent_id'] == $last_cat_id) {
                        $options[$cat_id] = $value;
                        $options[$cat_id]['level'] = $level;
                        $options[$cat_id]['id'] = $cat_id;
                        $options[$cat_id]['name'] = $value['cat_name'];
                        unset($arr[$key]);

                        if ($value['has_children'] > 0) {
                            if (end($cat_id_array) != $last_cat_id) {
                                $cat_id_array[] = $last_cat_id;
                            }
                            $last_cat_id = $cat_id;
                            $cat_id_array[] = $cat_id;
                            $level_array[$last_cat_id] = ++$level;
                        }
                    } elseif ($value['parent_id'] > $last_cat_id) {
                        break;
                    }
                }

                $count = count($cat_id_array);
                if ($count > 1) {
                    $last_cat_id = array_pop($cat_id_array);
                } elseif ($count == 1) {
                    if ($last_cat_id != end($cat_id_array)) {
                        $last_cat_id = end($cat_id_array);
                    } else {
                        $level = 0;
                        $last_cat_id = 0;
                        $cat_id_array = array();
                        continue;
                    }
                }

                if ($last_cat_id && isset($level_array[$last_cat_id])) {
                    $level = $level_array[$last_cat_id];
                } else {
                    $level = 0;
                }
            }
            //如果数组过大,不采用静态缓存方式
            if (count($options) <= 2000) {
                write_static_cache('cat_option_static', $options);
            }
        } else {
            $options = $data;
        }
        $cat_options[0] = $options;
    } else {
        $options = $cat_options[0];
    }

    if (!$spec_cat_id) {
        return $options;
    } else {
        if (empty($options[$spec_cat_id])) {
            return array();
        }

        $spec_cat_id_level = $options[$spec_cat_id]['level'];

        foreach ($options AS $key => $value) {
            if ($key != $spec_cat_id) {
                unset($options[$key]);
            } else {
                break;
            }
        }

        $spec_cat_id_array = array();
        foreach ($options AS $key => $value) {
            if (($spec_cat_id_level == $value['level'] && $value['cat_id'] != $spec_cat_id) ||
                    ($spec_cat_id_level > $value['level'])) {
                break;
            } else {
                $spec_cat_id_array[$key] = $value;
            }
        }
        $cat_options[$spec_cat_id] = $spec_cat_id_array;

        return $spec_cat_id_array;
    }
}
Exemple #16
0
        $t = new transport('-1', 5);
        $apiget = "ver={$data['version']}&ecs_lang={$data['ecs_lang']}&charset={$data['charset']}&certificate_id={$data['certificate_id']}&ent_id={$data['ent_id']}";
        $api_comment = $t->request('http://ecshop.ecmoban.com/cloud_remind.php', $apiget);
        $api_str = $api_comment["body"];
        $json = new Services_JSON();
        $api_arr = @$json->decode($api_str, 1);
        if (!empty($api_str)) {
            if (!empty($api_arr) && $api_arr['error'] == 0 && md5($api_arr['content']) == $api_arr['hash']) {
                $api_arr['content'] = urldecode($api_arr['content']);
                $message = explode('|', $api_arr['content']);
                $api_arr['content'] = '<li  class="cloud_close">' . $message['0'] . '<img onclick="cloud_close(' . $message['1'] . ')" src="images/no.gif"></li>';
                if ($data['charset'] != 'UTF-8') {
                    $api_arr['content'] = ecs_iconv('UTF-8', $data['charset'], $api_arr['content']);
                }
                $api_arr['api_time'] = date('Ymd');
                write_static_cache('cloud_remind', $api_arr);
                make_json_result($api_arr['content']);
            } else {
                make_json_result('0');
            }
        } else {
            make_json_result('0');
        }
    } else {
        make_json_result($api_data['content']);
    }
} elseif ($act == 'close_remind') {
    $remind_id = $_REQUEST['remind_id'];
    $t = new transport('-1', 5);
    $apiget = "ver= {$data['version']} &ecs_lang= {$data['ecs_lang']} &charset= {$data['charset']} &certificate_id={$data['certificate_id']}&ent_id={$data['ent_id']}&remind_id={$remind_id}";
    $api_comment = $t->request('http://ecshop.ecmoban.com/cloud_remind.php', $apiget);
Exemple #17
0
/**
 * 获得推荐商品
 *
 * @access  public
 * @param   string      $type       推荐类型,可以是 best, new, hot
 * @return  array
 */
function get_recommend_goods($type = '', $cats = '')
{
    if (!in_array($type, array('special', 'best', 'new', 'hot'))) {
        return array();
    }
    //取不同推荐对应的商品
    static $type_goods = array();
    //print_r($type_goods[$type]);
    if (empty($type_goods[$type])) {
        //初始化数据
        $type_goods['special'] = array();
        $type_goods['best'] = array();
        $type_goods['new'] = array();
        $type_goods['hot'] = array();
        //获取显示商品条件 add by hg for date 2014-03-26
        $agency_where = agency_goods();
        $data = read_static_cache('recommend_goods');
        //******书签 ---- 关闭首页缓存,删除以下代码
        //if ($data === false)
        // {
        $sql = 'SELECT g.goods_id,g.is_special, g.is_best, g.is_new, g.is_hot, g.is_promote, b.brand_name,g.sort_order ' . ' FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . ' LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' . ' WHERE ' . $agency_where . ' g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND (g.is_special = 1 OR g.is_best = 1 OR g.is_new =1 OR g.is_hot = 1)' . ' ORDER BY g.sort_order, g.last_update DESC';
        $goods_res = $GLOBALS['db']->getAll($sql);
        //dump($goods_res);
        //定义推荐,特产,最新,热门,促销商品
        $goods_data['special'] = array();
        $goods_data['best'] = array();
        $goods_data['new'] = array();
        $goods_data['hot'] = array();
        $goods_data['brand'] = array();
        if (!empty($goods_res)) {
            foreach ($goods_res as $data) {
                if ($data['is_special'] == 1) {
                    $goods_data['special'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']);
                }
                if ($data['is_best'] == 1) {
                    $goods_data['best'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']);
                }
                if ($data['is_new'] == 1) {
                    $goods_data['new'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']);
                }
                if ($data['is_hot'] == 1) {
                    $goods_data['hot'][] = array('goods_id' => $data['goods_id'], 'sort_order' => $data['sort_order']);
                }
                if ($data['brand_name'] != '') {
                    $goods_data['brand'][$data['goods_id']] = $data['brand_name'];
                }
            }
        }
        //dump($goods_data);
        write_static_cache('recommend_goods', $goods_data);
        // }
        // else
        //{
        // $goods_data = $data;
        //  }
        $time = gmtime();
        $order_type = $GLOBALS['_CFG']['recommend_order'];
        //按推荐数量及排序取每一项推荐显示的商品,  order_type可以根据后台设定进行各种条件显示
        static $type_array = array();
        $type2lib = array('special' => 'recommend_special', 'best' => 'recommend_best', 'new' => 'recommend_new', 'hot' => 'recommend_hot');
        if (empty($type_array)) {
            foreach ($type2lib as $key => $data) {
                if (!empty($goods_data[$key])) {
                    $num = get_library_number($data);
                    $data_count = count($goods_data[$key]);
                    $num = $data_count > $num ? $num : $data_count;
                    if ($order_type == 0) {
                        //usort($goods_data[$key], 'goods_sort');
                        $rand_key = array_slice($goods_data[$key], 0, $num);
                        foreach ($rand_key as $key_data) {
                            $type_array[$key][] = $key_data['goods_id'];
                        }
                    } else {
                        $rand_key = array_rand($goods_data[$key], $num);
                        if ($num == 1) {
                            $type_array[$key][] = $goods_data[$key][$rand_key]['goods_id'];
                        } else {
                            foreach ($rand_key as $key_data) {
                                $type_array[$key][] = $goods_data[$key][$key_data]['goods_id'];
                            }
                        }
                    }
                } else {
                    $type_array[$key] = array();
                }
            }
        }
        //取出所有符合条件的商品数据,并将结果存入对应的推荐类型数组中
        $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.comments_number, g.sales_volume, g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . "g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img, RAND() AS rnd " . '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']}' ";
        $type_merge = array_merge($type_array['special'], $type_array['new'], $type_array['best'], $type_array['hot']);
        //dump($type_merge);
        $type_merge = array_unique($type_merge);
        //dump($type_merge);
        $sql .= ' WHERE g.goods_id ' . db_create_in($type_merge);
        $sql .= ' ORDER BY g.sort_order, g.last_update DESC';
        $result = $GLOBALS['db']->getAll($sql);
        //dump($result);
        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'] = '';
            }
            /* 折扣节省计算 by ecmoban start */
            if ($row['market_price'] > 0) {
                $discount_arr = get_discount($row['goods_id']);
                //函数get_discount参数goods_id
            }
            $goods[$idx]['zhekou'] = $discount_arr['discount'];
            //zhekou
            $goods[$idx]['jiesheng'] = $discount_arr['jiesheng'];
            //jiesheng
            /* 折扣节省计算 by ecmoban end */
            $goods[$idx]['id'] = $row['goods_id'];
            $goods[$idx]['name'] = $row['goods_name'];
            $goods[$idx]['brief'] = $row['goods_brief'];
            $goods[$idx]['comments_number'] = $row['comments_number'];
            $goods[$idx]['sales_volume'] = $row['sales_volume'];
            $goods[$idx]['brand_name'] = isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] : '';
            $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'], true, true);
            $goods[$idx]['shop_price'] = !preg_match('/¥/', price_format($row['shop_price'])) ? '<span style="font-size:12px;text-decoration:line-through;font-weight:normal;color:#666666;">市场价:' . price_format($row['market_price'], true, true) . '</span>' : price_format($row['shop_price']);
            $thumb = '';
            $thumb = get_image_path($row['goods_id'], $row['goods_thumb'], true);
            $goods[$idx]['thumb'] = strstr($thumb, 'http://') ? $thumb : img_url() . $thumb;
            //strstr($thumb,'http://')?$thumb:img_url().$thumb;
            $goods_img = '';
            $goods_img = get_image_path($row['goods_id'], $row['goods_img']);
            $goods[$idx]['goods_img'] = strstr($goods_img, 'http://') ? $goods_img : img_url() . $goods_img;
            $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
            if (in_array($row['goods_id'], $type_array['special'])) {
                $type_goods['special'][] = $goods[$idx];
            }
            if (in_array($row['goods_id'], $type_array['best'])) {
                $type_goods['best'][] = $goods[$idx];
            }
            if (in_array($row['goods_id'], $type_array['new'])) {
                $type_goods['new'][] = $goods[$idx];
            }
            if (in_array($row['goods_id'], $type_array['hot'])) {
                $type_goods['hot'][] = $goods[$idx];
            }
        }
    }
    return $type_goods[$type];
}
 /**
  * 取得最近的上级分类的grade值
  *
  * @access  public
  * @param   int     $cat_id    //当前的cat_id
  *
  * @return int
  */
 function get_parent_grade($cat_id)
 {
     static $res = NULL;
     if ($res === NULL) {
         $data = read_static_cache('cat_parent_grade');
         if ($data === false) {
             $sql = "SELECT parent_id, cat_id, grade " . " FROM " . $this->pre . 'category';
             $res = M()->query($sql);
             write_static_cache('cat_parent_grade', $res);
         } else {
             $res = $data;
         }
     }
     if (!$res) {
         return 0;
     }
     $parent_arr = array();
     $grade_arr = array();
     foreach ($res as $val) {
         $parent_arr[$val['cat_id']] = $val['parent_id'];
         $grade_arr[$val['cat_id']] = $val['grade'];
     }
     while ($parent_arr[$cat_id] > 0 && $grade_arr[$cat_id] == 0) {
         $cat_id = $parent_arr[$cat_id];
     }
     return $grade_arr[$cat_id];
 }
Exemple #19
0
function refresh_plug_cache()
{
    global $db;
    $cache_file_path = QISHI_ROOT_PATH . "data/cache_plug.php";
    $sql = "SELECT * FROM " . table('plug');
    $result = $db->query($sql);
    while ($row = $db->fetch_array($result)) {
        $catarr[$row['typename']] = array("plug_name" => $row['plug_name'], "p_install" => $row['p_install']);
    }
    write_static_cache($cache_file_path, $catarr);
}
/**
 * 获得指定分类下的子分类的数组
 *
 * @access  public
 * @param   int     $cat_id     分类的ID
 * @param   int     $selected   当前选中分类的ID
 * @param   boolean $re_type    返回的类型: 值为真时返回下拉列表,否则返回数组
 * @param   int     $level      限定返回的级数。为0时返回所有级数
 * @return  mix
 */
function article_cat_list($cat_id = 0, $selected = 0, $re_type = true, $level = 0)
{
    static $res = NULL;
    if ($res === NULL) {
        $data = read_static_cache('art_cat_pid_releate');
        if ($data === false) {
            $sql = "SELECT c.*, COUNT(s.cat_id) AS has_children, COUNT(a.article_id) AS aricle_num " . ' FROM ' . $GLOBALS['ecs']->table('article_cat') . " AS c" . " LEFT JOIN " . $GLOBALS['ecs']->table('article_cat') . " AS s ON s.parent_id=c.cat_id" . " LEFT JOIN " . $GLOBALS['ecs']->table('article') . " AS a ON a.cat_id=c.cat_id" . " GROUP BY c.cat_id " . " ORDER BY parent_id, sort_order ASC";
            $res = $GLOBALS['db']->getAll($sql);
            write_static_cache('art_cat_pid_releate', $res);
        } else {
            $res = $data;
        }
    }
    if (empty($res) == true) {
        return $re_type ? '' : array();
    }
    $options = article_cat_options($cat_id, $res);
    // 获得指定分类下的子分类的数组
    /* 截取到指定的缩减级别 */
    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]);
            }
        }
    }
    $pre_key = 0;
    foreach ($options as $key => $value) {
        $options[$key]['has_children'] = 1;
        if ($pre_key > 0) {
            if ($options[$pre_key]['cat_id'] == $options[$key]['parent_id']) {
                $options[$pre_key]['has_children'] = 1;
            }
        }
        $pre_key = $key;
    }
    if ($re_type == true) {
        $select = '';
        foreach ($options as $var) {
            $select .= '<option value="' . $var['cat_id'] . '" ';
            $select .= ' cat_type="' . $var['cat_type'] . '" ';
            $select .= $selected == $var['cat_id'] ? "selected='ture'" : '';
            $select .= '>';
            if ($var['level'] > 0) {
                $select .= str_repeat('&nbsp;', $var['level'] * 4);
            }
            $select .= htmlspecialchars(addslashes($var['cat_name'])) . '</option>';
        }
        return $select;
    } else {
        foreach ($options as $key => $value) {
            $options[$key]['url'] = build_uri('article_cat', array('acid' => $value['cat_id']), $value['cat_name']);
        }
        return $options;
    }
}
 /**
  * 获得指定分类下的子分类的数组
  *
  * @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($cat_id = 0, $selected = 0, $re_type = true, $level = 0, $is_show_all = true)
 {
     static $res = NULL;
     if ($res === NULL) {
         $data = read_static_cache('cat_pid_releate');
         if ($data === false) {
             $res = M('category')->alias('c')->field('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')->join(C('DB_PREFIX') . 'category s ON s.parent_id=c.cat_id')->group('c.cat_id')->order('c.parent_id, c.sort_order ASC')->select();
             $res2 = M('goods')->field('cat_id, COUNT(*) AS goods_num')->where(array('is_delete' => 0, 'is_on_sale' => 1))->group('cat_id')->select();
             $res3 = M('goods_cat')->alias('gc')->field('gc.cat_id, COUNT(*) AS goods_num')->join(C('DB_PREFIX') . 'goods g ON g.goods_id = gc.goods_id')->where(array('g.goods_id = gc.goods_id AND g.is_delete = 0 AND g.is_on_sale = 1'))->select();
             $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 (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('&nbsp;', $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']);
         }
         return $options;
     }
 }