function get_header_gcategories($amount, $position, $brand_is_recommend = 1) { $gcategory_mod =& bm('gcategory', array('_store_id' => 0)); $gcategories = array(); if (!$amount) { $gcategories = $gcategory_mod->get_list(-1, true); } else { $gcategory = $gcategory_mod->get_list(0, true); $gcategories = $gcategory; foreach ($gcategory as $val) { $result = $gcategory_mod->get_list($val['cate_id'], true); $result = array_slice($result, 0, $amount); $gcategories = array_merge($gcategories, $result); } } import('tree.lib'); $tree = new Tree(); $tree->setTree($gcategories, 'cate_id', 'parent_id', 'cate_name'); $gcategory_list = $tree->getArrayList(0); $i = 0; $brand_mod =& m('brand'); foreach ($gcategory_list as $k => $v) { $gcategory_list[$k]['top'] = isset($position[$i]) ? $position[$i] : '0px'; $i++; $gcategory_list[$k]['brands'] = $brand_mod->find(array('conditions' => "tag = '" . $v['value'] . "' AND recommended=" . $brand_is_recommend, 'order' => 'sort_order asc,brand_id desc')); } return array('gcategories' => $gcategory_list); }
function _get_data() { $this->options['amount'] = intval($this->options['amount']); $cache_server =& cache_server(); $key = $this->_get_cache_id(); $data = $cache_server->get($key); if ($data === false) { $gcategory_mod =& bm('gcategory', array('_store_id' => 0)); $gcategories = array(); if (empty($this->options['amount'])) { $gcategories = $gcategory_mod->get_list(-1, true); } else { $gcategory = $gcategory_mod->get_list(0, true); $gcategories = $gcategory; foreach ($gcategory as $val) { $result = $gcategory_mod->get_list($val['cate_id'], true); $result = array_slice($result, 0, $this->options['amount']); $gcategories = array_merge($gcategories, $result); } } import('tree.lib'); $tree = new Tree(); //LLL 商品分类挂件根据语言选择分类字段 $lang2 = get_lang2(); //like fr,sc etc... $gcategories = chg_array2_string($gcategories, 'cate_name', $lang2); $tree->setTree($gcategories, 'cate_id', 'parent_id', 'cate_name'); $data = $tree->getArrayList(0); $cache_server->set($key, $data, $this->_ttl); } return $data; }
function _get_data() { $cache_server =& cache_server(); $key = $this->_get_cache_id(); $data = $cache_server->get($key); if ($data === false) { $gcategory_mod =& bm('gcategory', array('_store_id' => 0)); $gcategories = array(); $brand_mod =& m('brand'); if (empty($this->options['amount'])) { $gcategories = $gcategory_mod->get_list(-1, true); } else { $gcategory = $gcategory_mod->get_list(0, true); $gcategories = $gcategory; foreach ($gcategory as $val) { $result = $gcategory_mod->get_list($val['cate_id'], true); $result = array_slice($result, 0, $this->options['amount']); $gcategories = array_merge($gcategories, $result); } } import('tree.lib'); $tree = new Tree(); $tree->setTree($gcategories, 'cate_id', 'parent_id', 'cate_name'); $data = array('gcategories' => $tree->getArrayList(0), 'model_name' => $this->options['model_name'], 'brands' => $brand_mod->find(array('conditions' => "recommended = 1 AND if_show = 1", 'order' => 'sort_order', 'limit' => $this->_num))); $cache_server->set($key, $data, $this->_ttl); } return $data; }
function DatacallModule() { parent::__construct(); $this->type = isset($_REQUEST['type']) ? intval($_REQUEST['type']) : 'goods'; $this->call_mod =& af('datacall'); $this->_gcategory_mod =& bm("gcategory"); }
function ajax_cate() { if (!isset($_GET['id']) || empty($_GET['id'])) { echo ecm_json_encode(false); return; } $this->_gcategory_mod =& bm('gcategory'); $cate = $this->_gcategory_mod->get_list($_GET['id']); foreach ($cate as $key => $val) { $child = $this->_gcategory_mod->get_list($val['cate_id']); $lay = $this->_gcategory_mod->get_layer($val['cate_id']); if ($lay >= MAX_LAYER) { $cate[$key]['add_child'] = 0; } else { $cate[$key]['add_child'] = 1; } if (!$child || empty($child)) { $cate[$key]['switchs'] = 0; } else { $cate[$key]['switchs'] = 1; } } header("Content-Type:text/html;charset=" . CHARSET); echo ecm_json_encode(array_values($cate)); return; }
function ChannelApp() { parent::BackendApp(); $this->_channel_mod =& af('channels'); $this->_gcategory_mod =& bm('gcategory', array('_store_id' => 0)); $this->_tpl_filepath = ROOT_PATH . '/themes/mall/' . $this->_get_template_name() . '/'; $this->_tpl_confpath = ROOT_PATH . '/data/page_config/'; $this->_tpl_url = SITE_URL . '/themes/mall/' . $this->_get_template_name() . '/styles/' . $this->_get_style_name(); }
function _list_gcategory() { $gcategory_mod =& bm('gcategory', array('_store_id' => 0)); $gcategories = $gcategory_mod->get_list(-1, true); import('tree.lib'); $tree = new Tree(); $tree->setTree($gcategories, 'cate_id', 'parent_id', 'cate_name'); return $tree->getArrayList(0); }
function get_cat_goods_total($cate_id) { $goods_mod =& m('goods'); $gcategory_mod =& bm('gcategory'); $cate_ids = implode(",", $gcategory_mod->get_descendant_ids($cate_id)); if ($cate_id > 0) { $conditions = " AND cate_id IN (" . $cate_ids . ")"; } else { $conditions = ''; } $goods = $goods_mod->find(array('conditions' => 'if_show=1 and closed=0 ' . $conditions, 'fields' => 'goods_id')); return count($goods); }
function _list_gcategory() { $gcategory_mod =& bm('gcategory', array('_store_id' => 0)); $gcategories = $gcategory_mod->get_list(-1, true); import('tree.lib'); $tree = new Tree(); $lang2 = get_lang2(); //LLL 获取语言2个字母的代称,如fr, sc, en $gcategories = chg_array2_string($gcategories, 'cate_name', $lang2); //保留数组第二维字段字符串中指定语言的部分 $tree->setTree($gcategories, 'cate_id', 'parent_id', 'cate_name'); return $tree->getArrayList(0); }
function _list_gcategory() { $cache_server =& cache_server(); $key = 'page_goods_category'; $data = $cache_server->get($key); if ($data === false) { $gcategory_mod =& bm('gcategory', array('_store_id' => 0)); $gcategories = $gcategory_mod->get_list(-1, true); import('tree.lib'); $tree = new Tree(); $tree->setTree($gcategories, 'cate_id', 'parent_id', 'cate_name'); $data = $tree->getArrayList(0); $cache_server->set($key, $data, 3600); } return $data; }
function _get_data() { $gcategory_mod =& bm('gcategory'); $gcategories = array(); if (!empty($this->options['cate_id'])) { $gcategorys = $gcategory_mod->get_children($this->options['cate_id']); foreach ($gcategorys as $key => $cate) { $gcategorys[$key]['children'] = array(); $gcategorys[$key]['children'] = $gcategory_mod->get_children($cate['cate_id']); foreach ($gcategorys[$key]['children'] as $k => $v) { $gcategorys[$key]['children'][$k]['children'] = $gcategory_mod->get_children($v['cate_id']); } } } $ads = array(); for ($i = 1; $i < 9; $i++) { $ads[$i]['ad_image_url'] = $this->options['ad' . $i . '_image_url']; $ads[$i]['ad_link_url'] = $this->options['ad' . $i . '_link_url']; } $data = array('model_color' => $this->options['model_color'], 're_store' => $this->options['re_store'], 'gcategories' => $gcategorys, 'ad0_image_url' => $this->options['ad0_image_url'], 'ads' => $ads, 'wid' => md5($this->options['model_color'])); return $data; }
function store_goods() { $goods_mod =& bm('goods', array('_store_id' => $this->_store_id)); /* 搜索条件 */ $conditions = "1 = 1"; if (trim($_GET['goods_name'])) { $str = "LIKE '%" . trim($_GET['goods_name']) . "%'"; $conditions .= " AND (goods_name {$str})"; } if (intval($_GET['sgcate_id']) > 0) { $cate_mod =& bm('gcategory', array('_store_id' => $this->_store_id)); $cate_ids = $cate_mod->get_descendant(intval($_GET['sgcate_id'])); } else { $cate_ids = 0; } /* 取得商品列表 */ $goods_list = $goods_mod->get_list(array('conditions' => $conditions . ' AND g.if_show=1 AND g.closed=0', 'order' => 'g.add_time DESC', 'limit' => 100), $cate_ids); foreach ($goods_list as $key => $val) { $goods_list[$key]['goods_name'] = htmlspecialchars($val['goods_name']); } $this->json_result($goods_list); }
function _get_gcategory_options($parent_id = 0) { $mod_gcategory =& bm('gcategory'); $gcategories = $mod_gcategory->get_list($parent_id, true); foreach ($gcategories as $gcategory) { $res[$gcategory['cate_id']] = $gcategory['cate_name']; } return $res; }
function My_categoryApp() { parent::__construct(); $this->_gcategory_mod =& bm('gcategory', array('_store_id' => $this->visitor->get('manage_store'))); }
function _get_mgcategory_options($parent_id = 0) { $res = array(); $mod =& bm('gcategory', array('_store_id' => 0)); $gcategories = $mod->get_list($parent_id, true); foreach ($gcategories as $gcategory) { $res[$gcategory['cate_id']] = $gcategory['cate_name']; } return $res; }
function _get_store_gcategory() { $gcategory_mod =& bm('gcategory', array('_store_id' => $this->_store_id)); $gcategories = $gcategory_mod->get_list(-1, true); //LLL store gcategories里面的cate_name部分仅保留对应语言的字符 frontend.base, store中的商品分类 $gcategories = chg_array2_string($gcategories, 'cate_name', get_lang2()); import('tree.lib'); $tree = new Tree(); $tree->setTree($gcategories, 'cate_id', 'parent_id', 'cate_name'); return $tree->getArrayList(0); }
function index() { /* 取得导航 */ $this->assign('navs', $this->_get_navs()); /* 取得满足条件的商品 */ $conditions = "g.if_show = 1 AND g.closed = 0 AND s.state = 1"; // 上架且没有被禁售,店铺是开启状态 $filters = array(); // 筛选条件 // 分类 $cate_id = empty($_GET['cate_id']) ? 0 : intval($_GET['cate_id']); if ($cate_id > 0) { $gcategory_mod =& m('gcategory'); $cate_ids = $gcategory_mod->get_descendant($cate_id); $conditions .= " AND cate_id" . db_create_in($cate_ids); } // 关键字 $keyword = trim($_GET['keyword']); if (!empty($keyword)) { //LLL 主搜索中 也搜索货号 //$conditions .= " AND goods_name OR sku LIKE '%{$keyword}%' "; $conditions .= " AND goods_name OR sku LIKE '%{$keyword}%' "; $filters['keyword'] = array('key' => 'keyword', 'name' => LANG::get('keyword'), 'value' => $keyword); } // 品牌 if (!empty($_GET['brand'])) { $conditions .= " AND brand = '{$_GET['brand']}' "; $filters['brand'] = array('key' => 'brand', 'name' => LANG::get('brand'), 'value' => $_GET['brand']); } // 地区 if (!empty($_GET['region_id'])) { $conditions .= " AND region_id = '{$_GET['region_id']}' "; $region_mod =& m('region'); $region = $region_mod->get_info($_GET['region_id']); $filters['region_id'] = array('key' => 'region_id', 'name' => LANG::get('region'), 'value' => $region['region_name']); } // 价格区间 if (!empty($_GET['price'])) { $arr = explode('-', $_GET['price']); $min = floatval($arr[0]); $max = floatval($arr[1]); if ($min != 0 || $max != 0) { if ($min != 0 && $max != 0) { if ($min > $max) { list($min, $max) = array($max, $min); } $conditions .= " AND price >= '{$min}' AND price <= '{$max}' "; $filters['price'] = array('key' => 'price', 'name' => LANG::get('price'), 'value' => price_format($min) . ' - ' . price_format($max)); } else { if ($min != 0) { $conditions .= " AND price >= '{$min}' "; $filters['price'] = array('key' => 'price', 'name' => LANG::get('price'), 'value' => LANG::get('ge') . ' ' . price_format($min)); } else { $conditions .= " AND price <= '{$max}' "; $filters['price'] = array('key' => 'price', 'name' => LANG::get('price'), 'value' => LANG::get('le') . ' ' . price_format($max)); } } } else { unset($_GET['price']); } } $page = $this->_get_page(12); $goods_mod =& m('goods'); $store_mod =& m('store'); $sgrade_mod =& m('sgrade'); $sgrades = $sgrade_mod->find(array('fields' => 'grade_name')); $goods_list = $goods_mod->get_list(array('conditions' => $conditions, 'count' => true, 'order' => empty($_GET['order']) || !in_array($_GET['order'], array('sales desc', 'price asc', 'price desc', 'credit_value_desc', 'views desc', 'add_time desc')) ? 'sales desc' : $_GET['order'], 'limit' => $page['limit'])); //LLL search 页面中商品列表中商品名多语言 $goods_list = chg_array2_string($goods_list, 'goods_name', get_lang2()); foreach ($goods_list as $key => $goods) { //等级图片 $step = intval(Conf::get('upgrade_required')); $step < 1 && ($step = 5); $goods_list[$key]['credit_image'] = $this->_view->res_base . '/images/' . $store_mod->compute_credit($goods['credit_value'], $step); empty($goods['default_image']) && ($goods_list[$key]['default_image'] = Conf::get('default_goods_image')); $goods_list[$key]['grade_name'] = $sgrades[$goods['sgrade']]['grade_name']; } $this->assign('goods_list', $goods_list); $page['item_count'] = $goods_mod->getCount(); $this->_format_page($page); $this->assign('page_info', $page); /* 商品展示方式 */ $display_mode = ecm_getcookie('goodsDisplayMode'); if (empty($display_mode) || !in_array($display_mode, array('list', 'squares'))) { $display_mode = 'squares'; // 默认格子方式 } $this->assign('display_mode', $display_mode); /* 统计品牌 */ $brands = $goods_mod->count_brand(); $this->assign('brands', $brands); $this->assign('brand_count', count($brands)); /* 统计价格 */ $this->assign('price_intervals', $goods_mod->count_price()); /* 统计地区 */ $regions = $goods_mod->count_region(); $this->assign('regions', $regions); $this->assign('region_count', count($regions)); /* 筛选条件 */ $this->assign('filters', $filters); /* 排序方式 */ $this->assign('orders', array('sales desc' => LANG::get('sales_desc'), 'credit_value desc' => LANG::get('credit_value_desc'), 'price asc' => LANG::get('price_asc'), 'price desc' => LANG::get('price_desc'), 'views desc' => LANG::get('views_desc'), 'add_time desc' => LANG::get('add_time_desc'))); /* 取得下级分类 */ $gcategory_mod =& bm('gcategory', array('_store_id' => 0)); $categories = $gcategory_mod->get_list($cate_id, true); //LLL categories里面的cate_name部分仅保留对应语言的字符 search page中左categories内容 $categories = chg_array2_string($categories, 'cate_name', get_lang2()); $this->assign('categories', $categories); $this->assign('category_count', count($categories)); /* 当前位置 */ $this->_curlocal($this->_get_goods_curlocal($cate_id)); $this->assign('page_title', Conf::get('site_title')); $this->display('search.goods.html'); }
function get_sgcategory_options($store_id) { $mod =& bm('gcategory', array('_store_id' => $store_id)); $gcategories = $mod->get_list(); import('tree.lib'); $tree = new Tree(); $tree->setTree($gcategories, 'cate_id', 'parent_id', 'cate_name'); return $tree->getOptions(); }
function GcategoryApp() { parent::__construct(); $this->_gcategory_mod =& bm('gcategory', array('_store_id' => 0)); }
function distribute() { if (!IS_POST) { $cate_id = empty($_GET['cate_id']) ? 0 : intval($_GET['cate_id']); if (!$cate_id) { $this->show_warning('Hacking Attempt'); return; } //当前分类的级层,如 女装/连衣裙 $this->_gcate_mod =& bm('gcategory'); $this->assign('distribute_cate', $this->_gcate_mod->get_ancestor($cate_id)); $prop_list = $this->_props_mod->find(array('conditions' => 'status=1', 'order' => 'sort_order,pid')); foreach ($prop_list as $key => $prop) { $prop_list[$key]['prop_value'] = $this->_prop_value_mod->find(array('conditions' => 'status=1 and pid=' . $prop['pid'], 'order' => 'sort_order,vid')); } // 如果已经分配过属性,则进行 checked="checked" 设置 $cate_pvs = $this->_cate_pvs_mod->get($cate_id); if ($cate_pvs) { $pvs = $cate_pvs['pvs']; $pv = explode(';', $pvs); $p = array(); // 存储分配有属性名 prop 的数组 $v = array(); // 存储分配有属性值 prop_value 的数组 foreach ($pv as $pitem) { $item = explode(':', $pitem); $p[] = $item[0]; $v[] = $item[1]; } $p = array_unique($p); // 去掉重复值 $v = array_unique($v); // 去掉重复值 } foreach ($prop_list as $key => $prop) { if (isset($p) && in_array($prop['pid'], $p)) { $prop_list[$key]['checked'] = 1; } else { $prop_list[$key]['checked'] = 0; } foreach ($prop['prop_value'] as $key_v => $pvalue) { if (isset($v) && in_array($pvalue['vid'], $v)) { $prop_list[$key]['prop_value'][$key_v]['checked'] = 1; } else { $prop_list[$key]['prop_value'][$key_v]['checked'] = 0; } } } //print_r($prop_list);exit; $this->assign('prop_list', $prop_list); /* 导入css */ $this->import_resource(array('style' => 'res:style/jqtreetable.css')); $this->assign('cate_id', $cate_id); $this->display('props.distribute.html'); } else { $cate_id = intval($_POST['cate_id']); $pids = $_POST['pid']; $vids = $_POST['vid']; //if(!isset($pids) || !isset($vids)) { //$this->show_message('prop_empty', //'back', 'index.php?app=props&act=distribute&cate_id='.$cate_id); //return; //} $data = array('cate_id' => $cate_id, 'pvs' => ''); if (isset($pids) && isset($vids)) { // 去除非选中的 pid foreach ($vids as $item) { $vid = explode(':', $item); if (in_array($vid[0], $pids)) { $pvs .= ';' . $item; } } $data['pvs'] = substr($pvs, 1); } if ($this->_cate_pvs_mod->get($cate_id)) { $this->_cate_pvs_mod->edit($cate_id, $data); } else { $this->_cate_pvs_mod->add($data); } $this->show_message('save_ok', 'back', 'index.php?app=props&act=distribute&cate_id=' . $cate_id); } }
function edit() { $coupon_id = isset($_GET['id']) ? intval($_GET['id']) : 0; $current_coupon = $this->_coupon_mod->get_info($coupon_id); if (empty($coupon_id)) { echo Lang::get("no_coupon"); } if (!IS_POST) { $this->import_resource(array('script' => array(array('path' => 'jquery.ui/jquery.ui.js', 'attr' => ''), array('path' => 'jquery.ui/i18n/' . i18n_code() . '.js', 'attr' => ''), array('path' => 'jquery.plugins/jquery.validate.js', 'attr' => '')), 'style' => 'jquery.ui/themes/ui-lightness/jquery.ui.css')); header("Content-Type:text/html;charset=" . CHARSET); $gcategory_mod =& bm('gcategory', array('store_id' => 0)); $this->assign('scategories', $this->_get_scategories()); $this->assign('sgrades', $this->_get_sgrade()); $this->assign('gcategories', $gcategory_mod->get_options(0)); $current_coupon['selected'] = array(); $current_coupon['selected'][$current_coupon['type']] = $current_coupon['type_content']; if ($current_coupon['coupon_image']) { $current_coupon['coupon_image'] = dirname(site_url()) . "/" . $current_coupon['coupon_image']; } $store_mod =& m('store'); $store = $store_mod->find(array('conditions' => 'state=1', 'fields' => 'store_name,store_id')); if ($current_coupon['type'] == 4) { $type_content = unserialize($current_coupon['type_content']); if (!empty($type_content)) { foreach ($type_content as $key => $val) { $store[$val]['selected'] = 1; } } } $this->assign('build_editor', $this->_build_editor(array('name' => 'tip', 'content_css' => SITE_URL . "/themes/mall/{$template_name}/styles/{$style_name}/css/ecmall.css"))); $this->assign('build_upload', $this->_build_upload(array('belong' => BELONG_ARTICLE, 'item_id' => 0))); // 构建swfupload上传组件 $this->assign('store', $store); $this->assign('coupon', $current_coupon); $this->display('coupon.form.html'); } else { if (!$current_coupon['if_issue']) { $coupon_value = floatval(trim($_POST['coupon_value'])); $use_times = intval(trim($_POST['use_times'])); $min_amount = floatval(trim($_POST['min_amount'])); if (empty($coupon_value) || $coupon_value < 0) { $this->show_warning('coupon_value_not'); exit; } if (empty($use_times)) { $this->show_warning('use_times_not_zero'); exit; } if ($min_amount < 0) { $this->show_warning("min_amount_gt_zero"); exit; } $start_time = gmstr2time(trim($_POST['start_time'])); $end_time = gmstr2time_end(trim($_POST['end_time'])) - 1; //echo gmstr2time_end(trim($_POST['end_time'])) . '-------' .$end_time;exit; if ($end_time < $start_time) { $this->show_warning('end_gt_start'); exit; } $coupon = array('coupon_name' => trim($_POST['coupon_name']), 'coupon_value' => $coupon_value, 'store_id' => 0, 'use_times' => $use_times, 'start_time' => $start_time, 'end_time' => $end_time, 'min_amount' => $min_amount, 'if_issue' => trim($_POST['if_issue']) == 1 ? 1 : 0, 'tip' => $_POST['tip'], 'open_agree_item' => $_POST['open_agree_item'], 'show_in_list' => $_POST['show_in_list']); if ($_POST['open_agree_item']) { $coupon['type_content'] = $_POST['type'] == 4 ? serialize($_POST['type_content'][$_POST['type']]) : $_POST['type_content'][$_POST['type']]; $coupon['type'] = $_POST['type']; } else { $coupon['type_content'] = ''; $coupon['type'] = ''; } /* 处理上传的图片 */ $coupon_image = $this->_upload_image($coupon_id); if ($coupon_image) { $coupon['coupon_image'] = $coupon_image; } if ($_POST['open_agree_item']) { $store_ids = $this->_save_store_coupon($_POST['type'], $_POST['type_content'][$_POST['type']], $coupon_id); if (trim($_POST['if_issue']) == 1) { if ($store_ids) { foreach ($store_ids as $key => $val) { $ms =& ms(); $content = get_msg(Lang::get('to_store_owner_who_can_use_coupon'), array('coupon_name' => $_POST['coupon_name'])); $ms->pm->send(MSG_SYSTEM, $val, '', $content); } } } } else { $store_coupon_mod =& m('store_coupon'); $store_coupon_mod->drop('coupon_id=' . $coupon_id); } } else { $coupon['if_issue'] = trim($_POST['if_issue']) == 1 ? 1 : 0; $coupon['tip'] = $_POST['tip']; } $this->_coupon_mod->edit($coupon_id, $coupon); if ($this->_coupon_mod->has_error()) { $this->show_warning($this->_coupon_mod->get_error()); exit; } $this->show_message('edit_coupon_success', 'back_list', 'index.php?app=coupon'); } }
function _get_mgcategory_options($parent_id = 0) { $res = array(); $mod =& bm('gcategory', array('_store_id' => 0)); $gcategories = $mod->get_list($parent_id, true); foreach ($gcategories as $gcategory) { //LLL 本店所有商品分类多语言 $res[$gcategory['cate_id']] = get_part_string($gcategory['cate_name'], '', true); } return $res; }
function _get_group_by_info($param, $cached) { $data = false; if ($cached) { $cache_server =& cache_server(); $key = 'group_by_info_' . var_export($param, true); $data = $cache_server->get($key); } if ($data === false) { $data = array('total_count' => 0, 'by_category' => array(), 'by_brand' => array(), 'by_region' => array(), 'by_price' => array()); $goods_mod =& m('goods'); $store_mod =& m('store'); // sku tyioocom $goods_pvs_mod =& m('goods_pvs'); $props_mod =& m('props'); $prop_value_mod =& m('prop_value'); $table = " {$goods_mod->table} g LEFT JOIN {$store_mod->table} s ON g.store_id = s.store_id LEFT JOIN {$goods_pvs_mod->table} gp ON gp.goods_id=g.goods_id "; // end sku $conditions = $this->_get_goods_conditions($param); $sql = "SELECT COUNT(*) FROM {$table} WHERE" . $conditions; $total_count = $goods_mod->getOne($sql); if ($total_count > 0) { $data['total_count'] = $total_count; /* 按分类统计 */ $cate_id = isset($param['cate_id']) ? $param['cate_id'] : 0; $sql = ""; if ($cate_id > 0) { $layer = $param['layer']; if ($layer < 4) { $sql = "SELECT g.cate_id_" . ($layer + 1) . " AS id, COUNT(*) AS count FROM {$table} WHERE" . $conditions . " AND g.cate_id_" . ($layer + 1) . " > 0 GROUP BY g.cate_id_" . ($layer + 1) . " ORDER BY count DESC"; } } else { $sql = "SELECT g.cate_id_1 AS id, COUNT(*) AS count FROM {$table} WHERE" . $conditions . " AND g.cate_id_1 > 0 GROUP BY g.cate_id_1 ORDER BY count DESC"; } if ($sql) { $category_mod =& bm('gcategory'); $children = $category_mod->get_children($cate_id, true); $res = $goods_mod->db->query($sql); while ($row = $goods_mod->db->fetchRow($res)) { $data['by_category'][$row['id']] = array('cate_id' => $row['id'], 'cate_name' => $children[$row['id']]['cate_name'], 'count' => $row['count']); } } /* 按品牌统计 */ $sql = "SELECT g.brand, COUNT(*) AS count FROM {$table} WHERE" . $conditions . " AND g.brand > '' GROUP BY g.brand ORDER BY count DESC"; $by_brands = $goods_mod->db->getAllWithIndex($sql, 'brand'); /* 滤去未通过商城审核的品牌 */ if ($by_brands) { $m_brand =& m('brand'); $brand_conditions = db_create_in(addslashes_deep(array_keys($by_brands)), 'brand_name'); $brands_verified = $m_brand->getCol("SELECT brand_name FROM {$m_brand->table} WHERE " . $brand_conditions . ' AND if_show=1'); foreach ($by_brands as $k => $v) { if (!in_array($k, $brands_verified)) { unset($by_brands[$k]); } } } import('init.lib'); $by_brands = Init_SearchApp::_get_group_by_info_by_brands($by_brands, $param); $data['by_brand'] = $by_brands; /* 按地区统计 */ $sql = "SELECT s.region_id, s.region_name, COUNT(*) AS count FROM {$table} WHERE" . $conditions . " AND s.region_id > 0 GROUP BY s.region_id ORDER BY count DESC"; $by_regions = Init_SearchApp::_get_group_by_info_by_region($sql, $param); $data['by_region'] = $by_regions; /* end */ /* 按价格统计 */ if ($total_count > NUM_PER_PAGE) { $sql = "SELECT MIN(g.price) AS min, MAX(g.price) AS max FROM {$table} WHERE" . $conditions; $row = $goods_mod->getRow($sql); $min = $row['min']; $max = min($row['max'], MAX_STAT_PRICE); $step = max(ceil(($max - $min) / PRICE_INTERVAL_NUM), MIN_STAT_STEP); $sql = "SELECT FLOOR((g.price - '{$min}') / '{$step}') AS i, count(*) AS count FROM {$table} WHERE " . $conditions . " GROUP BY i ORDER BY i"; $res = $goods_mod->db->query($sql); while ($row = $goods_mod->db->fetchRow($res)) { $data['by_price'][] = array('count' => $row['count'], 'min' => $min + $row['i'] * $step, 'max' => $min + ($row['i'] + 1) * $step); } } // sku tyioocom 按 属性统计 $sql = "SELECT gp.* FROM {$table} WHERE " . $conditions . " AND gp.pvs > '' "; $prop_list = $goods_mod->getAll($sql); $pvs = ''; foreach ($prop_list as $key => $prop) { $pvs .= ';' . $prop['pvs']; } $pvs = substr($pvs, 1); // 去掉前面的";" $props_data = array(); if (!empty($pvs)) { $pv_arr = array_unique(explode(';', $pvs)); // 去除重复值,形成新的数组 $pid = 0; $prop_value = array(); // 先排序 foreach ($pv_arr as $key => $row) { $volume[$key] = $row[0]; } array_multisort($volume, SORT_DESC, $pv_arr); // 排序后才能做以下 $pid!=$item[0] 的判断 /* 检查属性名和属性值是否存在,有可能是之前有,但后面删除了 */ foreach ($pv_arr as $key => $pv) { if ($pv) { $item = explode(':', $pv); $check_prop = $props_mod->get(array('conditions' => 'pid=' . $item[0] . ' AND status=1', 'fields' => 'pid')); // 如果属性名存在,则检查该属性名下的当前属性值是否存在 if ($check_prop) { $check_prop_value = $prop_value_mod->get(array('conditions' => 'pid=' . $item[0] . ' AND vid=' . $item[1] . ' and status=1', 'fields' => 'vid')); if (!$check_prop_value) { unset($pv_arr[$key]); } } else { unset($pv_arr[$key]); } } } // 将当前的筛选数据除掉 $p = array(); if (!empty($_GET['props'])) { foreach (explode(';', $_GET['props']) as $pv) { $pv = explode(':', $pv); $p[] = $pv[0]; } $p = array_unique($p); } // end 当前的筛选数据除掉 foreach ($pv_arr as $key => $pv) { $item = explode(':', $pv); if (!empty($item[1]) && !in_array($item[0], $p)) { $props = $props_mod->get(array('conditions' => 'status=1 and pid=' . $item[0], 'fields' => 'name,pid')); $props_data[$item[0]] = $props; if ($pid != $item[0]) { // 不是同一个 pid 的属性值,不做累加 $prop_value = array(); $pid = $item[0]; } $prop_value[] = $prop_value_mod->get(array('conditions' => 'status=1 and pid=' . $item[0] . ' and vid=' . $item[1], 'fields' => 'prop_value,vid,pid')); $props_data[$item[0]] += array('value' => $prop_value); } } } $data['by_props'] = $props_data; } if ($cached) { $cache_server->set($key, $data, SEARCH_CACHE_TTL); } } return $data; }
/** * 取得某分类的前4级分类id(存入商品作为冗余数据,方便查询和统计) * * @param int $cate_id 分类id * @return array( * 'cate_id_1' => 1, * 'cate_id_2' => 2, * 'cate_id_3' => 3, * 'cate_id_4' => 4, * ) */ function _get_cate_ids($cate_id) { $res = array('cate_id_1' => 0, 'cate_id_2' => 0, 'cate_id_3' => 0, 'cate_id_4' => 0); if ($cate_id > 0) { $gcategory_mod =& bm('gcategory'); $ancestor = $gcategory_mod->get_ancestor($cate_id); for ($i = 1; $i <= 4; $i++) { $res['cate_id_' . $i] = isset($ancestor[$i - 1]) ? $ancestor[$i - 1]['cate_id'] : 0; } } return $res; }
/** * 根据查询条件取得分组统计信息 * * @param array $param 查询参数(参加函数_get_query_param的返回值说明) * @param bool $cached 是否缓存 * @return array( * 'total_count' => 10, * 'by_category' => array(id => array('cate_id' => 1, 'cate_name' => 'haha', 'count' => 10)) * 'by_brand' => array(array('brand' => brand, 'count' => count)) * 'by_region' => array(array('region_id' => region_id, 'region_name' => region_name, 'count' => count)) * 'by_price' => array(array('min' => 10, 'max' => 50, 'count' => 10)) * ) */ function _get_group_by_info($param, $cached) { $data = false; if ($cached) { $cache_server =& cache_server(); $key = 'group_by_info_' . var_export($param, true); $data = $cache_server->get($key); } if ($data === false) { $data = array('total_count' => 0, 'by_category' => array(), 'by_brand' => array(), 'by_region' => array(), 'by_price' => array()); $goods_mod =& m('goods'); $store_mod =& m('store'); $table = " {$goods_mod->table} g LEFT JOIN {$store_mod->table} s ON g.store_id = s.store_id"; $conditions = $this->_get_goods_conditions($param); $sql = "SELECT COUNT(*) FROM {$table} WHERE" . $conditions; $total_count = $goods_mod->getOne($sql); if ($total_count > 0) { $data['total_count'] = $total_count; /* 按分类统计 */ $cate_id = isset($param['cate_id']) ? $param['cate_id'] : 0; $sql = ""; if ($cate_id > 0) { $layer = $param['layer']; if ($layer < 4) { $sql = "SELECT g.cate_id_" . ($layer + 1) . " AS id, COUNT(*) AS count FROM {$table} WHERE" . $conditions . " AND g.cate_id_" . ($layer + 1) . " > 0 GROUP BY g.cate_id_" . ($layer + 1) . " ORDER BY count DESC"; } } else { $sql = "SELECT g.cate_id_1 AS id, COUNT(*) AS count FROM {$table} WHERE" . $conditions . " AND g.cate_id_1 > 0 GROUP BY g.cate_id_1 ORDER BY count DESC"; } if ($sql) { $category_mod =& bm('gcategory'); $children = $category_mod->get_children($cate_id, true); $res = $goods_mod->db->query($sql); while ($row = $goods_mod->db->fetchRow($res)) { $data['by_category'][$row['id']] = array('cate_id' => $row['id'], 'cate_name' => $children[$row['id']]['cate_name'], 'count' => $row['count']); } } /* 按品牌统计 */ $sql = "SELECT g.brand, COUNT(*) AS count FROM {$table} WHERE" . $conditions . " AND g.brand > '' GROUP BY g.brand ORDER BY count DESC"; $data['by_brand'] = $goods_mod->getAll($sql); /* 按地区统计 */ $sql = "SELECT s.region_id, s.region_name, COUNT(*) AS count FROM {$table} WHERE" . $conditions . " AND s.region_id > 0 GROUP BY s.region_id ORDER BY count DESC"; $data['by_region'] = $goods_mod->getAll($sql); /* 按价格统计 */ if ($total_count > NUM_PER_PAGE) { $sql = "SELECT MIN(g.price) AS min, MAX(g.price) AS max FROM {$table} WHERE" . $conditions; $row = $goods_mod->getRow($sql); $min = $row['min']; $max = min($row['max'], MAX_STAT_PRICE); $step = max(ceil(($max - $min) / PRICE_INTERVAL_NUM), MIN_STAT_STEP); $sql = "SELECT FLOOR((g.price - '{$min}') / '{$step}') AS i, count(*) AS count FROM {$table} WHERE " . $conditions . " GROUP BY i ORDER BY i"; $res = $goods_mod->db->query($sql); while ($row = $goods_mod->db->fetchRow($res)) { $data['by_price'][] = array('count' => $row['count'], 'min' => $min + $row['i'] * $step, 'max' => $min + ($row['i'] + 1) * $step); } } } if ($cached) { $cache_server->set($key, $data, SEARCH_CACHE_TTL); } } return $data; }
function _assign_searched_goods($id) { $goods_mod =& bm('goods', array('_store_id' => $id)); $search_name = LANG::get('all_goods'); $conditions = $this->_get_query_conditions(array(array('field' => 'goods_name', 'name' => 'keyword', 'equal' => 'like'))); if ($conditions) { $search_name = sprintf(LANG::get('goods_include'), $_GET['keyword']); $sgcate_id = 0; } else { $sgcate_id = empty($_GET['cate_id']) ? 0 : intval($_GET['cate_id']); } if ($sgcate_id > 0) { $gcategory_mod =& bm('gcategory', array('_store_id' => $id)); $sgcate = $gcategory_mod->get_info($sgcate_id); $search_name = $sgcate['cate_name']; $sgcate_ids = $gcategory_mod->get_descendant_ids($sgcate_id); } else { $sgcate_ids = array(); } /* 排序方式 */ $orders = array('add_time desc' => LANG::get('add_time_desc'), 'price asc' => LANG::get('price_asc'), 'price desc' => LANG::get('price_desc')); $this->assign('orders', $orders); $page = $this->_get_page(16); $goods_list = $goods_mod->get_list(array('conditions' => 'closed = 0 AND if_show = 1' . $conditions, 'count' => true, 'order' => empty($_GET['order']) || !isset($orders[$_GET['order']]) ? 'add_time desc' : $_GET['order'], 'limit' => $page['limit']), $sgcate_ids); foreach ($goods_list as $key => $goods) { empty($goods['default_image']) && ($goods_list[$key]['default_image'] = Conf::get('default_goods_image')); } $this->assign('searched_goods', $goods_list); $page['item_count'] = $goods_mod->getCount(); $this->_format_page($page); $this->assign('page_info', $page); $this->assign('search_name', $search_name); }
/** * 取得当前位置 * * @param int $cate_id 分类id */ function _get_curlocal($cate_id) { $parents = array(); if ($cate_id) { $gcategory_mod =& bm('gcategory'); $parents = $gcategory_mod->get_ancestor($cate_id, true); } $curlocal = array(array('text' => LANG::get('all_categories'), 'url' => url('app=category'))); foreach ($parents as $category) { $curlocal[] = array('text' => $category['cate_name'], 'url' => url('app=search&cate_id=' . $category['cate_id'])); } $curlocal[] = array('text' => LANG::get('goods_detail')); return $curlocal; }
/** * 取得当前位置 * * @param int $cate_id 分类id */ function _get_curlocal($cate_id, $goods_name) { $parents = array(); if ($cate_id) { $gcategory_mod =& bm('gcategory'); $parents = $gcategory_mod->get_ancestor($cate_id, true); } foreach ($parents as $category) { $curlocal[] = array('text' => $category['cate_name'], 'url' => url('app=search&cate_id=' . $category['cate_id'])); } $curlocal[] = array('text' => $goods_name); return $curlocal; }
<li><a href="<?php echo get_base_url(); ?> dashboard/<?php echo bm(); ?> " class="glyphicons dashboard"><i></i> <?php echo _t('Dashboard'); ?> </a></li> <li class="divider"></li> <li><a href="<?php echo get_base_url(); ?> crse/<?php echo bm(); ?> " class="glyphicons search"><i></i> <?php echo _t('Search Course'); ?> </a></li> <li class="divider"></li> <li><?php echo _t('Create Course'); ?> </li> </ul> <h3><?php echo _t('Add Course'); ?>
function edit() { if (!IS_POST) { // 第一级分类 $cate_mod =& bm('gcategory', array('_store_id' => 0)); $this->assign('gcategories', $cate_mod->get_options(0, true)); $this->headtag('<script type="text/javascript" src="{lib file=mlselection.js}"></script>'); $this->display('goods.batch.html'); } else { $id = isset($_POST['id']) ? trim($_POST['id']) : ''; if (!$id) { $this->show_warning('Hacking Attempt'); return; } $ids = explode(',', $id); $data = array(); if ($_POST['cate_id'] > 0) { $data['cate_id'] = $_POST['cate_id']; $data['cate_name'] = $_POST['cate_name']; } if (trim($_POST['brand'])) { $data['brand'] = trim($_POST['brand']); } if ($_POST['closed'] >= 0) { $data['closed'] = $_POST['closed'] ? 1 : 0; $data['close_reason'] = $_POST['closed'] ? $_POST['close_reason'] : ''; } if (empty($data)) { $this->show_warning('no_change_set'); return; } $this->_goods_mod->edit($ids, $data); $ret_page = isset($_GET['ret_page']) ? intval($_GET['ret_page']) : 1; $this->show_message('edit_ok', 'back_list', 'index.php?app=goods&page=' . $ret_page); } }