 {"id":229,"date":"2010-09-16T10:27:31","date_gmt":"2010-09-16T02:27:31","guid":{"rendered":"http:\/\/www.qyuef.com\/?p=229"},"modified":"2010-09-16T10:27:31","modified_gmt":"2010-09-16T02:27:31","slug":"ecshop%e5%8d%95%e7%8b%ac%e9%a1%b5%e9%9d%a2%e6%98%be%e7%a4%ba%e4%b8%8b%e6%9e%b6%e5%95%86%e5%93%81%e7%9a%84%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.qyuef.com\/?p=229","title":{"rendered":"ecshop\u5355\u72ec\u9875\u9762\u663e\u793a\u4e0b\u67b6\u5546\u54c1\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>&nbsp;&nbsp;&nbsp;&nbsp; \u6700\u8fd1\u5e2e\u670b\u53cb\u7528ecshop\u505a\u4e00\u4e2a\u5173\u4e8e\u670d\u88c5\u7684\u5546\u57ce\uff0c\u9700\u8981\u4e00\u4e2a\u5355\u72ec\u663e\u793a\u4e0b\u67b6\u5546\u54c1\u7684\u529f\u80fd\uff0c\u800cecshop\u76ee\u524d\u7684\u7248\u672c\u5e76\u4e0d\u652f\u6301\u3002\u6240\u4ee5\u6211\u81ea\u5df1\u5199\u4e86\u4e00\u4e2a\u3002\u5728\u8fd9\u91cc\u8d34\u51fa\u6765\uff0c\u5e0c\u671b\u5e2e\u5230\u9700\u8981\u7684\u670b\u53cb\u3002<br \/>\n\t&nbsp;&nbsp;&nbsp; \u7531\u4e8e\u5f88\u591a\u7ad9\u957f\u5bf9\u4e8ephp\u7a0b\u5e8f\u90fd\u4e0d\u662f\u5f88\u4e86\u89e3\uff0c\u8fd9\u91cc\u6211\u5c06\u4fee\u6539\u8fc7\u7684search.php\u5546\u54c1\u641c\u7d22\u6587\u4ef6\u76f4\u63a5\u8d34\u51fa\u6765\u8986\u76d6\u5c31\u53ef\u4ee5\u4e86\u3002\u5728\u94fe\u63a5\u7684\u65f6\u5019\u52a0\u4e0asearch.php?intro=old\u5c31\u80fd\u663e\u793a\u51fa\u6240\u6709\u4e0b\u67b6\u7684\u5546\u54c1\u3002<\/p>\n<pre lang=\"php\" line=\"1\">\n< ?php\n\n\/**\n * ECSHOP \u641c\u7d22\u7a0b\u5e8f\n * ============================================================================\n * \u7248\u6743\u6240\u6709 2005-2010 \u4e0a\u6d77\u5546\u6d3e\u7f51\u7edc\u79d1\u6280\u6709\u9650\u516c\u53f8\uff0c\u5e76\u4fdd\u7559\u6240\u6709\u6743\u5229\u3002\n * \u7f51\u7ad9\u5730\u5740: http:\/\/www.ecshop.com\uff1b\n * ----------------------------------------------------------------------------\n * \u8fd9\u4e0d\u662f\u4e00\u4e2a\u81ea\u7531\u8f6f\u4ef6\uff01\u60a8\u53ea\u80fd\u5728\u4e0d\u7528\u4e8e\u5546\u4e1a\u76ee\u7684\u7684\u524d\u63d0\u4e0b\u5bf9\u7a0b\u5e8f\u4ee3\u7801\u8fdb\u884c\u4fee\u6539\u548c\n * \u4f7f\u7528\uff1b\u4e0d\u5141\u8bb8\u5bf9\u7a0b\u5e8f\u4ee3\u7801\u4ee5\u4efb\u4f55\u5f62\u5f0f\u4efb\u4f55\u76ee\u7684\u7684\u518d\u53d1\u5e03\u3002\n * ============================================================================\n * $Author: liuhui $\n * $Id: search.php 17163 2010-05-20 10:13:23Z liuhui $\n*\/\n\ndefine('IN_ECS', true);\n\nif (empty($_GET['encode']))\n{\n    $string = array_merge($_GET, $_POST);\n    if (get_magic_quotes_gpc())\n    {\n        require(dirname(__FILE__) . '\/includes\/lib_base.php');\n        \/\/require(dirname(__FILE__) . '\/includes\/lib_common.php');\n\n        $string = stripslashes_deep($string);\n    }\n    $string['search_encode_time'] = time();\n    $string = str_replace('+', '%2b', base64_encode(serialize($string)));\n\n    header(\"Location: search.php?encode=$string\\n\");\n\n    exit;\n}\nelse\n{\n    $string = base64_decode(trim($_GET['encode']));\n    if ($string !== false)\n    {\n        $string = unserialize($string);\n        if ($string !== false)\n        {\n            \/* \u7528\u6237\u5728\u91cd\u5b9a\u5411\u7684\u60c5\u51b5\u4e0b\u5f53\u4f5c\u4e00\u6b21\u8bbf\u95ee *\/\n            if (!empty($string['search_encode_time']))\n            {\n                if (time() > $string['search_encode_time'] + 2)\n                {\n                    define('INGORE_VISIT_STATS', true);\n                }\n            }\n            else\n            {\n                define('INGORE_VISIT_STATS', true);\n            }\n        }\n        else\n        {\n            $string = array();\n        }\n    }\n    else\n    {\n        $string = array();\n    }\n}\n\nrequire(dirname(__FILE__) . '\/includes\/init.php');\n\n$_REQUEST = array_merge($_REQUEST, addslashes_deep($string));\n\n$_REQUEST['act'] = !empty($_REQUEST['act']) ? trim($_REQUEST['act']) : '';\n\n\/*------------------------------------------------------ *\/\n\/\/-- \u9ad8\u7ea7\u641c\u7d22\n\/*------------------------------------------------------ *\/\nif ($_REQUEST['act'] == 'advanced_search')\n{\n    $goods_type = !empty($_REQUEST['goods_type']) ? intval($_REQUEST['goods_type']) : 0;\n    $attributes = get_seachable_attributes($goods_type);\n    $smarty->assign('goods_type_selected', $goods_type);\n    $smarty->assign('goods_type_list',     $attributes['cate']);\n    $smarty->assign('goods_attributes',    $attributes['attr']);\n\n    assign_template();\n    assign_dynamic('search');\n    $position = assign_ur_here(0, $_LANG['advanced_search']);\n    $smarty->assign('page_title', $position['title']);    \/\/ \u9875\u9762\u6807\u9898\n    $smarty->assign('ur_here',    $position['ur_here']);  \/\/ \u5f53\u524d\u4f4d\u7f6e\n\n    $smarty->assign('categories', get_categories_tree()); \/\/ \u5206\u7c7b\u6811\n    $smarty->assign('helps',      get_shop_help());       \/\/ \u7f51\u5e97\u5e2e\u52a9\n    $smarty->assign('top_goods',  get_top10());           \/\/ \u9500\u552e\u6392\u884c\n    $smarty->assign('promotion_info', get_promotion_info());\n    $smarty->assign('cat_list',   cat_list(0, 0, true, 2, false));\n    $smarty->assign('brand_list', get_brand_list());\n    $smarty->assign('action',     'form');\n    $smarty->assign('use_storage', $_CFG['use_storage']);\n\n    $smarty->display('search.dwt');\n\n    exit;\n}\n\/*------------------------------------------------------ *\/\n\/\/-- \u641c\u7d22\u7ed3\u679c\n\/*------------------------------------------------------ *\/\nelse\n{\n    $_REQUEST['keywords']   = !empty($_REQUEST['keywords'])   ? trim($_REQUEST['keywords'])     : '';\n    $_REQUEST['brand']      = !empty($_REQUEST['brand'])      ? intval($_REQUEST['brand'])      : 0;\n    $_REQUEST['category']   = !empty($_REQUEST['category'])   ? intval($_REQUEST['category'])   : 0;\n    $_REQUEST['min_price']  = !empty($_REQUEST['min_price'])  ? intval($_REQUEST['min_price'])  : 0;\n    $_REQUEST['max_price']  = !empty($_REQUEST['max_price'])  ? intval($_REQUEST['max_price'])  : 0;\n    $_REQUEST['goods_type'] = !empty($_REQUEST['goods_type']) ? intval($_REQUEST['goods_type']) : 0;\n    $_REQUEST['sc_ds']      = !empty($_REQUEST['sc_ds']) ? intval($_REQUEST['sc_ds']) : 0;\n    $_REQUEST['outstock']   = !empty($_REQUEST['outstock']) ? 1 : 0;\n\n    $action = '';\n    if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'form')\n    {\n        \/* \u8981\u663e\u793a\u9ad8\u7ea7\u641c\u7d22\u680f *\/\n        $adv_value['keywords']  = htmlspecialchars(stripcslashes($_REQUEST['keywords']));\n        $adv_value['brand']     = $_REQUEST['brand'];\n        $adv_value['min_price'] = $_REQUEST['min_price'];\n        $adv_value['max_price'] = $_REQUEST['max_price'];\n        $adv_value['category']  = $_REQUEST['category'];\n\n        $attributes = get_seachable_attributes($_REQUEST['goods_type']);\n\n        \/* \u5c06\u63d0\u4ea4\u6570\u636e\u91cd\u65b0\u8d4b\u503c *\/\n        foreach ($attributes['attr'] AS $key => $val)\n        {\n            if (!empty($_REQUEST['attr'][$val['id']]))\n            {\n                if ($val['type'] == 2)\n                {\n                    $attributes['attr'][$key]['value']['from'] = !empty($_REQUEST['attr'][$val['id']]['from']) ? trim($_REQUEST['attr'][$val['id']]['from']) : '';\n                    $attributes['attr'][$key]['value']['to']   = !empty($_REQUEST['attr'][$val['id']]['to'])   ? trim($_REQUEST['attr'][$val['id']]['to'])   : '';\n                }\n                else\n                {\n                    $attributes['attr'][$key]['value'] = !empty($_REQUEST['attr'][$val['id']]) ? trim($_REQUEST['attr'][$val['id']]) : '';\n                }\n            }\n        }\n        if ($_REQUEST['sc_ds'])\n        {\n            $smarty->assign('scck',            'checked');\n        }\n        $smarty->assign('adv_val',             $adv_value);\n        $smarty->assign('goods_type_list',     $attributes['cate']);\n        $smarty->assign('goods_attributes',    $attributes['attr']);\n        $smarty->assign('goods_type_selected', $_REQUEST['goods_type']);\n        $smarty->assign('cat_list',            cat_list(0, $adv_value['category'], true, 2, false));\n        $smarty->assign('brand_list',          get_brand_list());\n        $smarty->assign('action',              'form');\n        $smarty->assign('use_storage',          $_CFG['use_storage']);\n\n        $action = 'form';\n    }\n\n    \/* \u521d\u59cb\u5316\u641c\u7d22\u6761\u4ef6 *\/\n    $keywords  = '';\n    $tag_where = '';\n    if (!empty($_REQUEST['keywords']))\n    {\n        $arr = array();\n        if (stristr($_REQUEST['keywords'], ' AND ') !== false)\n        {\n            \/* \u68c0\u67e5\u5173\u952e\u5b57\u4e2d\u662f\u5426\u6709AND\uff0c\u5982\u679c\u5b58\u5728\u5c31\u662f\u5e76 *\/\n            $arr        = explode('AND', $_REQUEST['keywords']);\n            $operator   = \" AND \";\n        }\n        elseif (stristr($_REQUEST['keywords'], ' OR ') !== false)\n        {\n            \/* \u68c0\u67e5\u5173\u952e\u5b57\u4e2d\u662f\u5426\u6709OR\uff0c\u5982\u679c\u5b58\u5728\u5c31\u662f\u6216 *\/\n            $arr        = explode('OR', $_REQUEST['keywords']);\n            $operator   = \" OR \";\n        }\n        elseif (stristr($_REQUEST['keywords'], ' + ') !== false)\n        {\n            \/* \u68c0\u67e5\u5173\u952e\u5b57\u4e2d\u662f\u5426\u6709\u52a0\u53f7\uff0c\u5982\u679c\u5b58\u5728\u5c31\u662f\u6216 *\/\n            $arr        = explode('+', $_REQUEST['keywords']);\n            $operator   = \" OR \";\n        }\n        else\n        {\n            \/* \u68c0\u67e5\u5173\u952e\u5b57\u4e2d\u662f\u5426\u6709\u7a7a\u683c\uff0c\u5982\u679c\u5b58\u5728\u5c31\u662f\u5e76 *\/\n            $arr        = explode(' ', $_REQUEST['keywords']);\n            $operator   = \" AND \";\n        }\n\n        $keywords = 'AND (';\n        $goods_ids = array();\n        foreach ($arr AS $key => $val)\n        {\n            if ($key > 0 && $key < count($arr) &#038;&#038; count($arr) > 1)\n            {\n                $keywords .= $operator;\n            }\n            $val        = mysql_like_quote(trim($val));\n            $sc_dsad    = $_REQUEST['sc_ds'] ? \" OR goods_desc LIKE '%$val%'\" : '';\n            $keywords  .= \"(goods_name LIKE '%$val%' OR goods_sn LIKE '%$val%' OR keywords LIKE '%$val%' $sc_dsad)\";\n\n            $sql = 'SELECT DISTINCT goods_id FROM ' . $ecs->table('tag') . \" WHERE tag_words LIKE '%$val%' \";\n            $res = $db->query($sql);\n            while ($row = $db->FetchRow($res))\n            {\n                $goods_ids[] = $row['goods_id'];\n            }\n\n            $db->autoReplace($ecs->table('keywords'), array('date' => local_date('Y-m-d'),\n                'searchengine' => 'ecshop', 'keyword' => $val, 'count' => 1), array('count' => 1));\n        }\n        $keywords .= ')';\n\n        $goods_ids = array_unique($goods_ids);\n        $tag_where = implode(',', $goods_ids);\n        if (!empty($tag_where))\n        {\n            $tag_where = 'OR g.goods_id ' . db_create_in($tag_where);\n        }\n    }\n\n    $category   = !empty($_REQUEST['category']) ? intval($_REQUEST['category'])        : 0;\n    $categories = ($category > 0)               ? ' AND ' . get_children($category)    : '';\n    $brand      = $_REQUEST['brand']            ? \" AND brand_id = '$_REQUEST[brand]'\" : '';\n    $outstock   = !empty($_REQUEST['outstock']) ? \" AND g.goods_number > 0 \"           : '';\n\n    $min_price  = $_REQUEST['min_price'] != 0                               ? \" AND g.shop_price >= '$_REQUEST[min_price]'\" : '';\n    $max_price  = $_REQUEST['max_price'] != 0 || $_REQUEST['min_price'] < 0 ? \" AND g.shop_price <= '$_REQUEST[max_price]'\" : '';\n\n    \/* \u6392\u5e8f\u3001\u663e\u793a\u65b9\u5f0f\u4ee5\u53ca\u7c7b\u578b *\/\n    $default_display_type = $_CFG['show_order_type'] == '0' ? 'list' : ($_CFG['show_order_type'] == '1' ? 'grid' : 'text');\n    $default_sort_order_method = $_CFG['sort_order_method'] == '0' ? 'DESC' : 'ASC';\n    $default_sort_order_type   = $_CFG['sort_order_type'] == '0' ? 'goods_id' : ($_CFG['sort_order_type'] == '1' ? 'shop_price' : 'last_update');\n\n    $sort = (isset($_REQUEST['sort'])  &#038;&#038; in_array(trim(strtolower($_REQUEST['sort'])), array('goods_id', 'shop_price', 'last_update'))) ? trim($_REQUEST['sort'])  : $default_sort_order_type;\n    $order = (isset($_REQUEST['order']) &#038;&#038; in_array(trim(strtoupper($_REQUEST['order'])), array('ASC', 'DESC'))) ? trim($_REQUEST['order']) : $default_sort_order_method;\n    $display  = (isset($_REQUEST['display']) &#038;&#038; in_array(trim(strtolower($_REQUEST['display'])), array('list', 'grid', 'text'))) ? trim($_REQUEST['display'])  : (isset($_SESSION['display_search']) ? $_SESSION['display_search'] : $default_display_type);\n\n    $_SESSION['display_search'] = $display;\n\n    $page       = !empty($_REQUEST['page'])  &#038;&#038; intval($_REQUEST['page'])  > 0 ? intval($_REQUEST['page'])  : 1;\n    $size       = !empty($_CFG['page_size']) && intval($_CFG['page_size']) > 0 ? intval($_CFG['page_size']) : 10;\n\n    $intromode = '';    \/\/\u65b9\u5f0f\uff0c\u7528\u4e8e\u51b3\u5b9a\u641c\u7d22\u7ed3\u679c\u9875\u6807\u9898\u56fe\u7247\n\n    if (!empty($_REQUEST['intro']))\n    {\n        switch ($_REQUEST['intro'])\n        {\n            case 'best':\n                $intro   = ' AND g.is_best = 1';\n                $intromode = 'best';\n                $ur_here = $_LANG['best_goods'];\n                break;\n            case 'new':\n                $intro   = ' AND g.is_new = 1';\n                $intromode ='new';\n                $ur_here = $_LANG['new_goods'];\n                break;\n\t\t\tcase 'old':\n                $intro   = ' AND g.is_on_sale =0';\n                $intromode ='old';\n                $ur_here = $_LANG['old_goods'];\n                break;\n            case 'hot':\n                $intro   = ' AND g.is_hot = 1';\n                $intromode = 'hot';\n                $ur_here = $_LANG['hot_goods'];\n                break;\n            case 'promotion':\n                $time    = gmtime();\n                $intro   = \" AND g.promote_price > 0 AND g.promote_start_date < = '$time' AND g.promote_end_date >= '$time'\";\n                $intromode = 'promotion';\n                $ur_here = $_LANG['promotion_goods'];\n                break;\n            default:\n                $intro   = '';\n        }\n    }\n    else\n    {\n        $intro = '';\n    }\n\n    if (empty($ur_here))\n    {\n        $ur_here = $_LANG['search_goods'];\n    }\n\n    \/*------------------------------------------------------ *\/\n    \/\/-- \u5c5e\u6027\u68c0\u7d22\n    \/*------------------------------------------------------ *\/\n    $attr_in  = '';\n    $attr_num = 0;\n    $attr_url = '';\n    $attr_arg = array();\n\n    if (!empty($_REQUEST['attr']))\n    {\n        $sql = \"SELECT goods_id, COUNT(*) AS num FROM \" . $ecs->table(\"goods_attr\") . \" WHERE 0 \";\n        foreach ($_REQUEST['attr'] AS $key => $val)\n        {\n            if (is_not_null($val) && is_numeric($key))\n            {\n                $attr_num++;\n                $sql .= \" OR (1 \";\n\n                if (is_array($val))\n                {\n                    $sql .= \" AND attr_id = '$key'\";\n\n                    if (!empty($val['from']))\n                    {\n                        $sql .= is_numeric($val['from']) ? \" AND attr_value >= \" . floatval($val['from'])  : \" AND attr_value >= '$val[from]'\";\n                        $attr_arg[\"attr[$key][from]\"] = $val['from'];\n                        $attr_url .= \"&amp;attr[$key][from]=$val[from]\";\n                    }\n\n                    if (!empty($val['to']))\n                    {\n                        $sql .= is_numeric($val['to']) ? \" AND attr_value < = \" . floatval($val['to']) : \" AND attr_value <= '$val[to]'\";\n                        $attr_arg[\"attr[$key][to]\"] = $val['to'];\n                        $attr_url .= \"&amp;attr[$key][to]=$val[to]\";\n                    }\n                }\n                else\n                {\n                    \/* \u5904\u7406\u9009\u8d2d\u4e2d\u5fc3\u8fc7\u6765\u7684\u94fe\u63a5 *\/\n                    $sql .= isset($_REQUEST['pickout']) ? \" AND attr_id = '$key' AND attr_value = '\" . $val . \"' \" : \" AND attr_id = '$key' AND attr_value LIKE '%\" . mysql_like_quote($val) . \"%' \";\n                    $attr_url .= \"&amp;attr[$key]=$val\";\n                    $attr_arg[\"attr[$key]\"] = $val;\n                }\n\n                $sql .= ')';\n            }\n        }\n\n        \/* \u5982\u679c\u68c0\u7d22\u6761\u4ef6\u90fd\u662f\u65e0\u6548\u7684\uff0c\u5c31\u4e0d\u7528\u68c0\u7d22 *\/\n        if ($attr_num > 0)\n        {\n            $sql .= \" GROUP BY goods_id HAVING num = '$attr_num'\";\n\n            $row = $db->getCol($sql);\n            if (count($row))\n            {\n                $attr_in = \" AND \" . db_create_in($row, 'g.goods_id');\n            }\n            else\n            {\n                $attr_in = \" AND 0 \";\n            }\n        }\n    }\n    elseif (isset($_REQUEST['pickout']))\n    {\n        \/* \u4ece\u9009\u8d2d\u4e2d\u5fc3\u8fdb\u5165\u7684\u94fe\u63a5 *\/\n        $sql = \"SELECT DISTINCT(goods_id) FROM \" . $ecs->table('goods_attr');\n        $col = $db->getCol($sql);\n        \/\/\u5982\u679c\u5546\u5e97\u6ca1\u6709\u8bbe\u7f6e\u5546\u54c1\u5c5e\u6027,\u90a3\u4e48\u6b64\u68c0\u7d22\u6761\u4ef6\u662f\u65e0\u6548\u7684\n        if (!empty($col))\n        {\n            $attr_in = \" AND \" . db_create_in($col, 'g.goods_id');\n        }\n    }\n\n    \/* \u83b7\u5f97\u7b26\u5408\u6761\u4ef6\u7684\u5546\u54c1\u603b\u6570 *\/\n\tif($_REQUEST['intro']==\"old\"){\n\t$sql   = \"SELECT COUNT(*) FROM \" .$ecs->table('goods'). \" AS g \".\n        \"WHERE g.is_delete = 0 AND  g.is_alone_sale = 1 $attr_in \".\n        \"AND (( 1 \" . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock .\" ) \".$tag_where.\" )\";\n\t}else{\n\t$sql   = \"SELECT COUNT(*) FROM \" .$ecs->table('goods'). \" AS g \".\n        \"WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in \".\n        \"AND (( 1 \" . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock .\" ) \".$tag_where.\" )\";\n\t}\n    \n\n    $count = $db->getOne($sql);\n\n    $max_page = ($count> 0) ? ceil($count \/ $size) : 1;\n    if ($page > $max_page)\n    {\n        $page = $max_page;\n    }\n\n    \/* \u67e5\u8be2\u5546\u54c1 *\/\n\tif($_REQUEST['intro']==\"old\"){\n    $sql = \"SELECT g.goods_id, g.goods_name, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, \".\n                \"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, \".\n                \"g.promote_price, g.promote_start_date, g.promote_end_date, g.goods_thumb, g.goods_img, g.goods_brief, g.goods_type \".\n            \"FROM \" .$ecs->table('goods'). \" AS g \".\n            \"LEFT JOIN \" . $GLOBALS['ecs']->table('member_price') . \" AS mp \".\n                    \"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' \".\n            \"WHERE g.is_delete = 0  AND g.is_alone_sale = 1 $attr_in \".\n                \"AND (( 1 \" . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock . \" ) \".$tag_where.\" ) \" .\n            \"ORDER BY $sort $order\";\n\t\t\t}else{\n\t\t\t$sql = \"SELECT g.goods_id, g.goods_name, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, \".\n                \"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, \".\n                \"g.promote_price, g.promote_start_date, g.promote_end_date, g.goods_thumb, g.goods_img, g.goods_brief, g.goods_type \".\n            \"FROM \" .$ecs->table('goods'). \" AS g \".\n            \"LEFT JOIN \" . $GLOBALS['ecs']->table('member_price') . \" AS mp \".\n                    \"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' \".\n            \"WHERE g.is_delete = 0 AND g.is_on_sale = 1 AND g.is_alone_sale = 1 $attr_in \".\n                \"AND (( 1 \" . $categories . $keywords . $brand . $min_price . $max_price . $intro . $outstock . \" ) \".$tag_where.\" ) \" .\n            \"ORDER BY $sort $order\";\n\t\t\t\n\t\t\t}\n\t\t\t\n    $res = $db->SelectLimit($sql, $size, ($page - 1) * $size);\n\n    $arr = array();\n    while ($row = $db->FetchRow($res))\n    {\n        if ($row['promote_price'] > 0)\n        {\n            $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);\n        }\n        else\n        {\n            $promote_price = 0;\n        }\n\n        \/* \u5904\u7406\u5546\u54c1\u6c34\u5370\u56fe\u7247 *\/\n        \/* \u5904\u7406\u5546\u54c1\u6c34\u5370\u56fe\u7247 *\/\n        $watermark_img = '';\n\n        if ($promote_price != 0)\n        {\n            $watermark_img = \"watermark_promote_small\";\n        }\n        elseif ($row['is_new'] != 0)\n        {\n            $watermark_img = \"watermark_new_small\";\n        }\n        elseif ($row['is_best'] != 0)\n        {\n            $watermark_img = \"watermark_best_small\";\n        }\n        elseif ($row['is_hot'] != 0)\n        {\n            $watermark_img = 'watermark_hot_small';\n        }\n\n        if ($watermark_img != '')\n        {\n            $arr[$row['goods_id']]['watermark_img'] =  $watermark_img;\n        }\n\n        $arr[$row['goods_id']]['goods_id']      = $row['goods_id'];\n        if($display == 'grid')\n        {\n            $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'];\n        }\n        else\n        {\n            $arr[$row['goods_id']]['goods_name'] = $row['goods_name'];\n        }\n        $arr[$row['goods_id']]['type']          = $row['goods_type'];\n        $arr[$row['goods_id']]['market_price']  = price_format($row['market_price']);\n        $arr[$row['goods_id']]['shop_price']    = price_format($row['shop_price']);\n        $arr[$row['goods_id']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : '';\n        $arr[$row['goods_id']]['goods_brief']   = $row['goods_brief'];\n        $arr[$row['goods_id']]['goods_thumb']   = get_image_path($row['goods_id'], $row['goods_thumb'], true);\n        $arr[$row['goods_id']]['goods_img']     = get_image_path($row['goods_id'], $row['goods_img']);\n        $arr[$row['goods_id']]['url']           = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);\n    }\n\n    if($display == 'grid')\n    {\n        if(count($arr) % 2 != 0)\n        {\n            $arr[] = array();\n        }\n    }\n    $smarty->assign('goods_list', $arr);\n    $smarty->assign('category',   $category);\n    $smarty->assign('keywords',   htmlspecialchars(stripslashes($_REQUEST['keywords'])));\n    $smarty->assign('search_keywords',   stripslashes($_REQUEST['keywords']));\n    $smarty->assign('brand',      $_REQUEST['brand']);\n    $smarty->assign('min_price',  $min_price);\n    $smarty->assign('max_price',  $max_price);\n    $smarty->assign('outstock',  $_REQUEST['outstock']);\n\n    \/* \u5206\u9875 *\/\n    $url_format = \"search.php?category=$category&amp;keywords=\" . urlencode(stripslashes($_REQUEST['keywords'])) . \"&amp;brand=\" . $_REQUEST['brand'].\"&amp;action=\".$action.\"&amp;goods_type=\" . $_REQUEST['goods_type'] . \"&amp;sc_ds=\" . $_REQUEST['sc_ds'];\n    if (!empty($intromode))\n    {\n        $url_format .= \"&amp;intro=\" . $intromode;\n    }\n    if (isset($_REQUEST['pickout']))\n    {\n        $url_format .= '&amp;pickout=1';\n    }\n    $url_format .= \"&amp;min_price=\" . $_REQUEST['min_price'] .\"&amp;max_price=\" . $_REQUEST['max_price'] . \"&amp;sort=$sort\";\n\n    $url_format .= \"$attr_url&amp;order=$order&amp;page=\";\n\n    $pager['search'] = array(\n        'keywords'   => stripslashes(urlencode($_REQUEST['keywords'])),\n        'category'   => $category,\n        'brand'      => $_REQUEST['brand'],\n        'sort'       => $sort,\n        'order'      => $order,\n        'min_price'  => $_REQUEST['min_price'],\n        'max_price'  => $_REQUEST['max_price'],\n        'action'     => $action,\n        'intro'      => empty($intromode) ? '' : trim($intromode),\n        'goods_type' => $_REQUEST['goods_type'],\n        'sc_ds'      => $_REQUEST['sc_ds'],\n        'outstock'   => $_REQUEST['outstock']\n    );\n    $pager['search'] = array_merge($pager['search'], $attr_arg);\n\n    $pager = get_pager('search.php', $pager['search'], $count, $page, $size);\n    $pager['display'] = $display;\n\n    $smarty->assign('url_format', $url_format);\n    $smarty->assign('pager', $pager);\n\n    assign_template();\n    assign_dynamic('search');\n    $position = assign_ur_here(0, $ur_here . ($_REQUEST['keywords'] ? '_' . $_REQUEST['keywords'] : ''));\n    $smarty->assign('page_title', $position['title']);    \/\/ \u9875\u9762\u6807\u9898\n    $smarty->assign('ur_here',    $position['ur_here']);  \/\/ \u5f53\u524d\u4f4d\u7f6e\n    $smarty->assign('intromode',      $intromode);\n    $smarty->assign('categories', get_categories_tree()); \/\/ \u5206\u7c7b\u6811\n    $smarty->assign('helps',       get_shop_help());      \/\/ \u7f51\u5e97\u5e2e\u52a9\n    $smarty->assign('top_goods',  get_top10());           \/\/ \u9500\u552e\u6392\u884c\n    $smarty->assign('promotion_info', get_promotion_info());\n\n    $smarty->display('search.dwt');\n}\n\n\/*------------------------------------------------------ *\/\n\/\/-- PRIVATE FUNCTION\n\/*------------------------------------------------------ *\/\n\/**\n *\n *\n * @access public\n * @param\n *\n * @return void\n *\/\nfunction is_not_null($value)\n{\n    if (is_array($value))\n    {\n        return (!empty($value['from'])) || (!empty($value['to']));\n    }\n    else\n    {\n        return !empty($value);\n    }\n}\n\n\/**\n * \u83b7\u5f97\u53ef\u4ee5\u68c0\u7d22\u7684\u5c5e\u6027\n *\n * @access  public\n * @params  integer $cat_id\n * @return  void\n *\/\nfunction get_seachable_attributes($cat_id = 0)\n{\n    $attributes = array(\n        'cate' => array(),\n        'attr' => array()\n    );\n\n    \/* \u83b7\u5f97\u53ef\u7528\u7684\u5546\u54c1\u7c7b\u578b *\/\n    $sql = \"SELECT t.cat_id, cat_name FROM \" .$GLOBALS['ecs']->table('goods_type'). \" AS t, \".\n           $GLOBALS['ecs']->table('attribute') .\" AS a\".\n           \" WHERE t.cat_id = a.cat_id AND t.enabled = 1 AND a.attr_index > 0 \";\n    $cat = $GLOBALS['db']->getAll($sql);\n\n    \/* \u83b7\u53d6\u53ef\u4ee5\u68c0\u7d22\u7684\u5c5e\u6027 *\/\n    if (!empty($cat))\n    {\n        foreach ($cat AS $val)\n        {\n            $attributes['cate'][$val['cat_id']] = $val['cat_name'];\n        }\n        $where = $cat_id > 0 ? ' AND a.cat_id = ' . $cat_id : \" AND a.cat_id = \" . $cat[0]['cat_id'];\n\n        $sql = 'SELECT attr_id, attr_name, attr_input_type, attr_type, attr_values, attr_index, sort_order ' .\n               ' FROM ' . $GLOBALS['ecs']->table('attribute') . ' AS a ' .\n               ' WHERE a.attr_index > 0 ' .$where.\n               ' ORDER BY cat_id, sort_order ASC';\n        $res = $GLOBALS['db']->query($sql);\n\n        while ($row = $GLOBALS['db']->FetchRow($res))\n        {\n            if ($row['attr_index'] == 1 && $row['attr_input_type'] == 1)\n            {\n                $row['attr_values'] = str_replace(\"\\r\", '', $row['attr_values']);\n                $options = explode(\"\\n\", $row['attr_values']);\n\n                $attr_value = array();\n                foreach ($options AS $opt)\n                {\n                    $attr_value[$opt] = $opt;\n                }\n                $attributes['attr'][] = array(\n                    'id'      => $row['attr_id'],\n                    'attr'    => $row['attr_name'],\n                    'options' => $attr_value,\n                    'type'    => 3\n                );\n            }\n            else\n            {\n                $attributes['attr'][] = array(\n                    'id'   => $row['attr_id'],\n                    'attr' => $row['attr_name'],\n                    'type' => $row['attr_index']\n                );\n            }\n        }\n    }\n\n    return $attributes;\n}\n?>\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5e2e\u670b\u53cb\u7528ecshop\u505a\u4e00\u4e2a\u5173\u4e8e\u670d\u88c5\u7684\u5546\u57ce\uff0c\u9700\u8981\u4e00\u4e2a\u5355\u72ec\u663e\u793a\u4e0b\u67b6\u5546\u54c1\u7684\u529f\u80fd\uff0c\u800cecshop\u76ee\u524d\u7684\u7248\u672c\u5e76\u4e0d\u652f\u6301\u3002\u6240\u4ee5\u6211\u81ea\u5df1\u5199\u4e86\u4e00\u4e2a\u3002\u5728\u8fd9\u91cc\u8d34\u51fa\u6765\uff0c\u5e0c\u671b\u5e2e\u5230\u9700\u8981\u7684\u670b\u53cb\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[22,46,77],"tcat":[],"_links":{"self":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/posts\/229"}],"collection":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=229"}],"version-history":[{"count":0,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/posts\/229\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=229"},{"taxonomy":"tcat","embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftcat&post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}