public function BuildExcerpts($text, $word, $opts) { $segment = search_core::segment(); $words = $segment->split_words($word); if (empty($opts)) { $opts = array('before_match' => '<font color="red">', 'after_match' => '</font>'); } foreach ($words as $row) { $opts_str = $opts['before_match'] . $row . $opts['after_match']; $text = str_replace($row, $opts_str, $text); } return $text; }
function query($queryArr = array()) { $queryArr = $this->prepaData($queryArr); $index = new Zend_Search_Lucene($this->dir); $analyzerObj = new search_instance_analyzer_cjk(); $analyzerObj->addPreFilter(new search_instance_analyzer_filter_goods()); $analyzerObj->addPreFilter(new search_instance_analyzer_filter_cjk()); $analyzerObj->addFilter(new search_instance_token_filter_lowercase()); Zend_Search_Lucene_Analysis_Analyzer::setDefault($analyzerObj); $segmentObj = search_core::segment(); $service_filter_cjk = new search_service_filter_cjk(); $service_filter_lowercase = new search_service_filter_lowercase(); if (is_object($service_filter_cjk) && is_object($service_filter_lowercase)) { $segmentObj->pre_filter($service_filter_cjk); $segmentObj->token_filter($service_filter_lowercase); /* if(isset($queryArr['title'])){ $segmentObj->set($queryArr['title'], 'utf8'); while($row = $segmentObj->next()){ $title[] = $row['text']; } $queryArr['title'] = @join(" ", $title); }*/ } $this->from = $queryArr['from']; $this->to = $queryArr['to']; $this->order = $queryArr['orderby']; unset($queryArr['from']); unset($queryArr['to']); unset($queryArr['orderby']); if (is_array($queryArr)) { foreach ($queryArr as $k => $v) { $query[] = $k . ':' . $v; } } if (is_array($query)) { $this->query = implode(' AND ', $query); } }
function toAdd() { $goods = $this->_prepareGoodsData($_POST); if ($goods['udfimg'] == 'true' && !$goods['thumbnail_pic']) { $goods['udfimg'] = 'false'; } $this->begin(''); if (count($goods['product']) == 0) { //$this->end(false,'货品未添加'); exit; } if (strlen($goods['brief']) > 255) { $this->end(false, __('商品介绍请不要超过255字节')); } $oGoods =& $this->app->model('goods'); if ($goods['bn']) { if ($oGoods->checkProductBn($goods['bn'], $goods['goods_id'])) { $this->end(false, __('您所填写的商品编号已被使用,请检查!')); } } foreach ($goods['product'] as $k => $p) { if (empty($p['bn'])) { continue; } if ($oGoods->checkProductBn($p['bn'], $goods['goods_id'])) { $this->end(false, __('您所填写的货号已被使用,请检查!')); } } $oUrl = kernel::single('site_route_app'); if (!$oGoods->save($goods)) { $this->end(false, __('您所填写的货号重复,请检查!')); } else { if ($goods['images']) { $oImage =& app::get('image')->model('image'); foreach ($goods['images'] as $k => $v) { $test = $oImage->rebuild($v['image_id'], array('S', 'M', 'L'), true); } } if ($_POST['goods_static']) { $url = $oUrl->fetch_static(array('static' => $_POST['goods_static'])); $goods_url = app::get('site')->router()->gen_url(array('app' => 'b2c', 'real' => 1, 'ctl' => 'site_product', 'args' => array($goods['goods_id']))); $goods_url = substr($goods_url, strlen(app::get('site')->base_url())); $goods_url_info = $oUrl->fetch_static(array('url' => $goods_url)); $goods_url_info['url'] = $goods_url; $goods_url_info['static'] = $_POST['goods_static']; if ($url['url'] && $url['url'] != $goods_url_info['url']) { $this->end(false, __('您填写的自定义链接已存在')); } $oUrl->store_static($goods_url_info); } else { $oUrl->delete_static(array('static' => $_POST['goods_static'])); } } if ($this->app->getConf('system.product.zendlucene') == 'true') { $obj = search_core::segment(); if (is_dir(ROOT_DIR . '/data/search/zend/lucene/')) { $luceneIndex = search_core::instance('b2c_goods')->link(); } else { $luceneIndex = search_core::instance('b2c_goods')->create(); } $luceneIndex = search_core::instance('b2c_goods')->update($goods); } $this->end(true, __('操作成功'), null, array('goods_id' => $goods['goods_id'])); }
function clear() { $type = $_GET['type']; $name = $_GET['name']; $this->begin(); search_core::segment(); foreach (kernel::servicelist($type) as $service) { if (get_class($service) == $name) { $status = $service->clear($msg); break; } } if ($status) { $this->end(true, $this->app->_($msg)); } else { $this->end(false, $this->app->_($msg)); } }
function toAdd() { $this->begin(''); $oGoods =& $this->app->model('goods'); if (isset($_POST['goods']['brief']) && $_POST['goods']['brief'] && strlen($_POST['goods']['brief']) > 210) { $this->end(false, app::get('b2c')->_('简短的商品介绍,请不要超过70个字!')); } if (isset($_POST['spec_load'])) { $this->end(false, app::get('b2c')->_('规格未加载完毕')); } if (isset($_POST['new_goods_spec']) && $_POST['new_goods_spec']) { unset($_POST['goods']['product']); $goodsinfo = json_decode($_POST['new_goods_spec'], 1); $_POST['goods']['product'] = $goodsinfo['product']; $_POST['goods']['spec'] = serialize($goodsinfo['spec']); } if (is_array($_POST['goods']['product'])) { foreach ($_POST['goods']['product'] as $pk => $pv) { if (is_array($_POST['goods']['product']) && is_string($_POST['goods']['spec'])) { if (count($pv['spec_desc']['spec_value_id']) < count(unserialize($_POST['goods']['spec']))) { $this->end(false, app::get('b2c')->_('未选定全部规格')); } } } } if ($_POST['adjunct']['min_num'][0] > $_POST['adjunct']['max_num'][0]) { $this->end(false, app::get('b2c')->_('配件最小购买量大于最大购买量')); } if (!$oGoods->checkPriceWeight($_POST['goods']['product'])) { $this->end(false, app::get('b2c')->_('商品价格或重量格式错误')); } if (!$oGoods->checkStore($_POST['goods']['product'])) { $this->end(false, app::get('b2c')->_('库存格式错误')); } $goods = $this->_prepareGoodsData($_POST); if ($goods['udfimg'] == 'true' && !$goods['thumbnail_pic']) { $goods['udfimg'] = 'false'; } if (is_string($_POST['productkey'])) { $productkey = unserialize($_POST['productkey']); if (is_array($_POST['goods']['product'])) { foreach ($_POST['goods']['product'] as $pk => $pv) { $newpk[] = $pv['product_id']; } } if (is_array($newpk) && is_array($productkey)) { $diff = array_diff($productkey, $newpk); } if (count($diff) > 0) { if (!$this->pre_recycle_spec($_POST['goods']['goods_id'], $diff)) { $this->end(false, app::get('b2c')->_('有的规格订单未处理')); } } } if (count($goods['product']) == 0) { //$this->end(false,'货品未添加'); exit; } if (strlen($goods['brief']) > 255) { $this->end(false, app::get('b2c')->_('商品介绍请不要超过70个汉字')); } if (!$goods['name']) { $this->end(false, app::get('b2c')->_('商品名称不能为空')); } if ($goods['bn']) { if ($oGoods->checkProductBn($goods['bn'], $goods['goods_id'])) { $this->end(false, app::get('b2c')->_('您所填写的商品编号已被使用,请检查!')); } } foreach ($goods['product'] as $k => $p) { if (!$k && $k !== 0) { unset($goods['product'][$k]); continue; } if (is_null($p['store'])) { $goods['product'][$k]['freez'] = null; $goods['product'][$k]['store'] = null; } if (empty($p['bn'])) { continue; } if ($oGoods->checkProductBn($p['bn'], $goods['goods_id'])) { $this->end(false, app::get('b2c')->_('您所填写的货号已被使用,请检查!')); } } if (!$goods['product']) { unset($goods['product']); unset($goods['spec']); } $oUrl = kernel::single('site_route_app'); $arr_remove_image = array(); if ($_POST['goods']['images']) { $oImage_attach = app::get('image')->model('image_attach'); $arr_image_attach = $oImage_attach->getList('*', array('target_id' => $goods['goods_id'], 'target_type' => 'goods')); foreach ((array) $arr_image_attach as $_arr_image_attach) { if (!in_array($_arr_image_attach['image_id'], $_POST['goods']['images'])) { $arr_remove_image[] = $_arr_image_attach['image_id']; } } } if (!$oGoods->save($goods)) { $this->end(false, app::get('b2c')->_('您所填写的货号重复,请检查!')); } else { if ($goods['images']) { $oImage =& app::get('image')->model('image'); if ($arr_remove_image) { /* * Andrew 20130304 * 在商品有关联多个图片时,删除network类型的图片,会导致tag丢失。 * 此处注释图片删除功能,仅仅移除商品与图片的关联。 foreach($arr_remove_image as $_arr_remove_image) $test = $oImage->delete_image($_arr_remove_image,'goods'); * */ } foreach ($goods['images'] as $k => $v) { $test = $oImage->rebuild($v['image_id'], array('S', 'M', 'L'), true); } } if ($_POST['goods_static']) { $url = $oUrl->fetch_static(array('static' => $_POST['goods_static'])); $goods_url = app::get('site')->router()->gen_url(array('app' => 'b2c', 'real' => 1, 'ctl' => 'site_product', 'args' => array($goods['goods_id']))); $goods_url = substr($goods_url, strlen(app::get('site')->base_url())); $goods_url_info = $oUrl->fetch_static(array('static' => $goods_url)); if (empty($goods_url_info['url'])) { $goods_url_info['url'] = $goods_url; } $goods_url_info['static'] = $_POST['goods_static']; $goods_url_info['enable'] = 'true'; if ($url['url'] && $url['url'] != $goods_url_info['url']) { $this->end(false, app::get('b2c')->_('您填写的自定义链接已存在')); } $oUrl->store_static($goods_url_info); } else { $goods_url = app::get('site')->router()->gen_url(array('app' => 'b2c', 'real' => 1, 'ctl' => 'site_product', 'args' => array($goods['goods_id']))); $goods_url = substr($goods_url, strlen(app::get('site')->base_url())); $oUrl->delete_static(array('static' => $goods_url)); } } $_POST['goods'] = $goods; $goodsServiceList = kernel::servicelist("goods.action.save"); foreach ($goodsServiceList as $aGoodsService) { if (!$aGoodsService->save($_POST, $error_msg)) { $this->end(false, $error_msg); } } if (app::get('base')->getConf('server.search_server.search_goods') == 'search_goods') { $obj = search_core::segment(); if (search_core::instance('search_goods')->status($msg)) { $luceneIndex = search_core::instance('search_goods')->link(); } else { $luceneIndex = search_core::instance('search_goods')->create(); } $luceneIndex = search_core::instance('search_goods')->update($goods); } $this->end(true, app::get('b2c')->_('操作成功'), null, array('goods_id' => $goods['goods_id'])); }
public function index($cat_id = '', $urlFilter = null, $orderBy = 0, $tab = null, $page = 1, $cat_type = null, $view = null) { $urlFilter = htmlspecialchars(urldecode($urlFilter)); if ($_GET['scontent']) { $urlFilter = $_GET['scontent']; } if ($cat_id == '_ANY_') { unset($cat_id); } if ($cat_id) { $cat_id = explode(",", $cat_id); foreach ($cat_id as $k => $v) { if ($v) { $cat_id[$k] = intval($v); } } $this->id = implode(",", $cat_id); } if (!$cat_id) { $cat_id = array(''); $this->id = ''; } $pageLimit = $this->app->getConf('gallery.display.listnum'); $pageLimit = $pageLimit ? $pageLimit : -1; $this->pagedata['pdtPic'] = array('width' => 100, 'heigth' => 100); $productCat =& $this->app->model('goods_cat'); $GLOBALS['runtime']['path'] = $productCat->getPath($cat_id[0], ''); $this->pagedata['childnode'] = $productCat->getCatParentById($cat_id, 'index'); $objGoods = $this->app->model('goods'); if (empty($view)) { $view = $this->app->getConf('gallery.default_view') ? $this->app->getConf('gallery.default_view') : 'index'; } $goods_cat =& $this->app->model('goods_cat'); if ($cat_id) { $type_filter = $goods_cat->dump(array('cat_id' => $cat_id), 'type_id'); } $cat = kernel::service('b2c_site_goods_list_viewer_apps')->get_view($cat_id, $view, $type_filter['type_id']); $this->pagedata['args'] = array($this->id, urlencode($urlFilter), $orderBy, $tab, $page, $cat_type, $view); $this->pagedata['curView'] = $view; if ($this->app->getConf('system.seo.noindex_catalog')) { $this->header .= '<meta name="robots" content="noindex,noarchive,follow" />'; } $searchtools =& $this->app->model('search'); $path = array(); $filter = $searchtools->decode($urlFilter, $path, $cat); if (is_array($filter)) { $filter = array_merge(array('cat_id' => $cat_id, 'marketable' => 'true'), $filter); if (($filter['cat_id'][0] === '' || $filter['cat_id'][0] === null) && !isset($filter['cat_id'][1])) { unset($filter['cat_id']); } if (($filter['tag'][0] === '' || $filter['tag'][0] === null) && !isset($filter['tag'][1])) { unset($filter['tag']); } if (($filter['brand_id'][0] === '' || $filter['brand_id'][0] === null) && !isset($filter['brand_id'][1])) { unset($filter['brand_id']); } } else { $filter = array('cat_id' => $cat_id, 'marketable' => 'true'); } //--------获取类型关联的规格 $type_id = $type_filter['type_id']; $gType =& $this->app->model('goods_type'); $SpecList = $gType->getSpec($type_id, 1); //获取关联的规格 $oGoodsTypeSpec = $this->app->model('goods_type_spec'); $type_spec = $oGoodsTypeSpec->get_type_spec($type_id); $oSpecification =& $this->app->model('specification'); $filter['cat_id'] = $cat_id; $filter['goods_type'] = 'normal'; $filter['marketable'] = 'true'; //-----查找当前类别子类别的关联类型ID if ($urlFilter) { if ($vcat['type_id']) { //$filter['type_id']=$vcat['type_id']; $filter['type_id'] = null; } } //-------- $this->pagedata['tabs'] = $cat['tabs']; $this->pagedata['cat_id'] = implode(",", $cat_id); $views = $cat['setting']['list_tpl']; foreach ($views as $key => $val) { $this->pagedata['views'][$key] = array($this->id, urlencode($urlFilter), $orderBy, $tab, $page, $cat_type, $val); } if ($cat['tabs'][$tab]) { parse_str($cat['tabs'][$tab]['filter'], $_filter); $filter = array_merge($filter, $_filter); } if (isset($this->pagedata['orderBy'][$orderBy])) { $orderby = $this->pagedata['orderBy'][$orderBy]['sql']; } $selector = array(); $search = array(); if (!is_array($cat_id) && $cat_id || $cat_id[0] || $cat_type) { $goods_relate = $objGoods->getList("*", $filter, 0, -1); } if ($goods_relate) { unset($tmpSpecValue); foreach ($goods_relate as $grk => $grv) { if ($grv['spec_desc']) { $tmpSdesc = $grv['spec_desc']; if (is_array($tmpSdesc)) { foreach ($tmpSdesc as $tsk => $tsv) { foreach ($tsv as $tk => $tv) { if (is_array($tv['spec_value_id'])) { if (!in_array($tv['spec_value_id'], $tmpSpecValue)) { $tmpSpecValue[] = $tv['spec_value_id']; } } } } } } } } /***********************/ if ($SpecList) { if ($curSpec) { $curSpecKey = array_keys($curSpec); } foreach ($SpecList as $spk => $spv) { $selected = 0; if ($curSpecKey && in_array($spk, $curSpecKey)) { $spv['spec_value'][$curSpec[$spk]]['selected'] = true; $selected = 1; } if ($spv['spec_style'] == "select") { //下拉 $SpecSelList[$spk] = $spv; if ($selected) { $SpecSelList[$spk]['selected'] = true; } } elseif ($spv['spec_style'] == "flat") { $SpecFlatList[$spk] = $spv; if ($selected) { $SpecFlatList[$spk]['selected'] = true; } } } } $this->pagedata['filter'] = $this->filter; $this->pagedata['SpecFlatList'] = $SpecFlatList; $this->pagedata['specimagewidth'] = $this->app->getConf('spec.image.width'); $this->pagedata['specimageheight'] = $this->app->getConf('spec.image.height'); /************************/ if (is_array($cat['brand'])) { foreach ($cat['brand'] as $bk => $bv) { $bCount = 0; if (is_array($filter['brand_id'])) { $bid = array_flip($filter['brand_id']); } $brand = array('name' => __('品牌'), 'value' => $bid); if (is_array($goods_relate)) { foreach ($goods_relate as $gk => $gv) { if ($gv['brand_id']) { if ($gv['brand_id'] == $bv['brand_id']) { $bCount++; } } } } if ($bCount > 0) { $tmpOp[$bv['brand_id']] = $bv['brand_name'] . "<span class='num'>(" . $bCount . ")</span>"; } } $brand['options'] = $tmpOp; $selector['brand_id'] = $brand; } foreach ((array) $cat['props'] as $prop_id => $prop) { if ($prop['type'] == 'select') { $prop['value'] = $filter['p_' . $prop_id][0]; $searchSelect[$prop_id] = $prop; } elseif ($prop['search'] == 'input') { $prop['value'] = $filter['p_' . $prop_id][0]; $searchInput[$prop_id] = $prop; } elseif ($prop['search'] == 'nav') { if (is_array($filter['brand_id']) && isset($filter['p_' . $prop_id])) { $prop['value'] = array_flip($filter['p_' . $prop_id]); } $plugadd = array(); foreach ($goods_relate as $k => $v) { if ($v["p_" . $prop_id] != null) { if ($plugadd[$v["p_" . $prop_id]]) { $plugadd[$v["p_" . $prop_id]] = $plugadd[$v["p_" . $prop_id]] + 1; } else { $plugadd[$v["p_" . $prop_id]] = 1; } } $aFilter['goods_id'][] = $v['goods_id']; //当前的商品结果集 } $navselector = 0; foreach ($prop['options'] as $q => $e) { if ($plugadd[$q]) { $prop['options'][$q] = $prop['options'][$q] . "<span class='num'>(" . $plugadd[$q] . ")</span>"; if (!$navselector) { $navselector = 1; } } else { unset($prop['options'][$q]); } } $selector[$prop_id] = $prop; } } if ($navselector) { $nsvcount = 0; $noshow = 0; foreach ($selector as $sk => $sv) { if ($sv['value']) { $nsvcount++; } if (is_numeric($sk) && !$sv['show']) { $noshow++; } } if ($nsvcount == intval(count($selector) - $noshow)) { $navselector = 0; } } foreach ((array) $cat['spec'] as $spec_id => $spec_name) { $sId['spec_id'][] = $spec_id; } $cat['ordernum'] = $cat['ordernum'] ? $cat['ordernum'] : array('' => 2); if ($cat['ordernum']) { if ($selector) { foreach ($selector as $key => $val) { if (!in_array($key, $cat['ordernum']) && $val) { $selectorExd[$key] = $val; } } } } $this->pagedata['orderBy'] = $objGoods->orderBy(); //排序方式 if (!isset($this->pagedata['orderBy'][$orderBy])) { $this->_response->set_http_response_code(404); } else { $orderby = $this->pagedata['orderBy'][$orderBy]['sql']; } $selector['ordernum'] = $cat['ordernum']; //$objGoods->appendCols .= 'big_pic';/*appendCols big_pic update 2009年9月25日13:46:45*/ if ($this->app->getConf('system.product.zendlucene') == 'true') { search_core::segment(); $filter['from'] = $pageLimit * ($page - 1); //分页 $filter['to'] = $pageLimit; $filter['order'] = $orderby; if (is_dir(ROOT_DIR . '/data/search/zend/lucene/')) { $luceneIndex = search_core::instance('b2c_goods')->link(); } else { $luceneIndex = search_core::instance('b2c_goods')->create(); } $query = search_core::instance('b2c_goods')->query($filter); $rfilter = search_core::instance('b2c_goods')->commit(); $count = count($rfilter['goods_id']); if (count($rfilter['goods_id']) == 0) { $rfilter['goods_id'] = '-1'; } $aProduct = $objGoods->getList('*', $rfilter); } else { $aProduct = $objGoods->getList('*', $filter, $pageLimit * ($page - 1), $pageLimit, $orderby); $count = $objGoods->count($filter); } //对商品进行预处理 $this->pagedata['mask_webslice'] = $this->app->getConf('system.ui.webslice') ? ' hslice' : null; $this->pagedata['searchInput'] =& $searchInput; $this->pagedata['selectorExd'] = $selectorExd; $this->cat_id = $cat_id; $this->_plugins['function']['selector'] = array(&$this, '_selector'); $this->pagedata['pager'] = array('current' => $page, 'total' => ceil($count / $pageLimit), 'link' => $this->gen_url(array('app' => 'b2c', 'ctl' => 'site_gallery', 'full' => 1, 'act' => 'index', 'args' => array(implode(',', $cat_id), urlencode($p['str']), $orderBy, $tab, $tmp = time(), '', $view))), 'token' => $tmp); if ($page != 1 && $page > $this->pagedata['pager']['total']) { $this->_response->set_http_response_code(404); } if (!$count) { $this->pagedata['emtpy_info'] = $this->app->getConf('errorpage.searchempty'); } $this->pagedata['searchtotal'] = $count; if (is_array($aProduct) && count($aProduct) > 0) { $objProduct = $this->app->model('products'); if ($this->app->getConf('site.show_mark_price') == 'true') { $setting['mktprice'] = $this->app->getConf('site.show_mark_price'); if (isset($aProduct)) { foreach ($aProduct as $pk => $pv) { $aProduct[$pk]['mktprice'] = $objProduct->getRealMkt($pv['price']); } } } else { $setting['mktprice'] = 0; } $setting['saveprice'] = $this->app->getConf('site.save_price'); $setting['buytarget'] = $this->app->getConf('site.buy.target'); $this->pagedata['setting'] = $setting; //spec_desc $siteMember = $this->get_current_member(); $this->site_member_lv_id = $siteMember['member_lv']; $oGoodsLv =& $this->app->model('goods_lv_price'); $oMlv =& $this->app->model('member_lv'); $mlv = $oMlv->db_dump($this->site_member_lv_id, 'dis_count'); foreach ($aProduct as &$val) { $temp = $objProduct->getList('product_id, spec_info, price, freez, store, goods_id', array('goods_id' => $val['goods_id'])); if ($this->site_member_lv_id) { $tmpGoods = array(); foreach ($oGoodsLv->getList('product_id,price', array('goods_id' => $val['goods_id'], 'level_id' => $this->site_member_lv_id)) as $k => $v) { $tmpGoods[$v['product_id']] = $v['price']; } foreach ($temp as &$tv) { $tv['price'] = isset($tmpGoods[$tv['product_id']]) ? $tmpGoods[$tv['product_id']] : $mlv['dis_count'] * $tv['price']; } $val['price'] = $tv['price']; } $val['spec_desc_info'] = $temp; } $this->pagedata['products'] =& $aProduct; } $aData = $this->get_current_member(); if (!$aData['member_id']) { $this->pagedata['login'] = '******'; } if ($SpecSelList) { $this->pagedata['SpecSelList'] = $SpecSelList; } if ($searchSelect) { $this->pagedata['searchSelect'] =& $searchSelect; } $this->pagedata['selector'] =& $selector; $this->pagedata['cat_type'] = $cat_type; if ($GLOBALS['search_array']) { $this->pagedata['search_array'] = implode("+", $GLOBALS['search_array']); } $this->pagedata['_PDT_LST_TPL'] = $cat['tpl']; $this->pagedata['filter'] = $filter; $this->set_tmpl('gallery.html'); $this->pagedata['gallery_display'] = $this->app->getConf('gallery.display.grid.colnum'); $imageDefault = app::get('image')->getConf('image.set'); $this->pagedata['image_set'] = $imageDefault; $this->pagedata['defaultImage'] = $imageDefault['S']['default_image']; $this->page('site/gallery/index.html'); }