加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
categoryall.php 18.17 KB
一键复制 编辑 原始数据 按行查看 历史
守你 提交于 2020-11-25 15:26 . 上传文件
<?php
/**
* DDXY 文章内容
* ============================================================================
* 版权所有 2005-2016 山东叮咚小愿信息科技有限公司,并保留所有权利。
* 网站地址: http://www.dingdongxiaoyuan.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: liuhui $
* $Id: article.php 17069 2010-03-26 05:28:01Z liuhui $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
if ((DEBUG_MODE & 2) != 2)
{
$smarty->caching = true;
}
require(ROOT_PATH . '/includes/lib_area.php'); //叮咚小愿 --zhuo
$warehouse_other = [
'province_id' => $province_id,
'city_id' => $city_id
];
$warehouse_area_info = get_warehouse_area_info($warehouse_other);
$region_id = $warehouse_area_info['region_id'];
$area_id = $warehouse_area_info['area_id'];
$area_city = $warehouse_area_info['city_id'];
/*------------------------------------------------------ */
//--获取二级分类和商品
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'category_cat'){
include_once(ROOT_PATH . 'includes/cls_json.php');
$json = new JSON;
$id = empty($_REQUEST['id']) ? '' : intval($_REQUEST['id']); //顶级分类
$cat_id = empty($_REQUEST['cat_id']) ? '' : intval($_REQUEST['cat_id']); //二级分类
$order = empty($_REQUEST['order']) ? 'DESC' : $_REQUEST['order']; //排序
$min = empty($_REQUEST['min']) ? 0 : intval($_REQUEST['min']); //二级分类
$max = empty($_REQUEST['max']) ? 0 : intval($_REQUEST['max']); //二级分类
//顶级分类和二级分类都存获取二级分类下的商品
if(!empty($id)){
if(empty($id)) make_json_response('二级分类id必传');
//根据顶级分类获取二级分类
$sql = 'SELECT * ' .
' FROM ' . $GLOBALS['ecs']->table('category') .
" WHERE parent_id = '" . $id . "' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";
$res = $GLOBALS['db']->getAll($sql);
foreach ($res as $k => $v) {
$data[$k]['id'] = $id;
$data[$k]['cat_id'] = $v['cat_id'];
$data[$k]['cat_name'] = $v['cat_name'];
$data[$k]['url'] = build_uri('category', array('cid' => $v['cat_id']), $v['cat_name']);
}
$children_id = get_children($data[0]['cat_id']);
$goods_list = get_goods_category_list($children_id, '', $min, $max, '', 100, 1, 'goods_id', $order, 0, 0, 0, [], '');
$data['list'] = $goods_list;
}else if(!empty($cat_id)){
if(empty($cat_id)) make_json_response('二级分类id必传');
$children = get_children($cat_id);
//获取二级下的所有商品
$data = get_goods_category_list($children, '', $min, $max, '', 100, 1, 'goods_id', $order, 0, 0, 0, [], '');
}else{
make_json_response('参数错误');die;
}
$val = $json->encode($data);
exit($val);
}
/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */
$cache_id = sprintf('%X', crc32($_REQUEST['id'] . '-' . $_CFG['lang']));
if (!$smarty->is_cached('category_all.dwt', $cache_id))
{
$position = assign_ur_here(0, $_LANG['all_category']);
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('ur_here', $position['ur_here']); // 当前位置
for($i=1;$i<=$_CFG['auction_ad'];$i++){
$category_all_left .= "'category_all_left".$i.","; //左边广告位
$category_all_right .= "'category_all_right".$i.","; //左边广告位
}
$smarty->assign('category_all_left', $category_all_left);
$smarty->assign('category_all_right', $category_all_right);
$categories_list = get_category_tree_leve_one(0, 1);
$smarty->assign('categories_list', $categories_list);
$categories_pro = get_category_tree_leve_one();
$smarty->assign('categories_pro', $categories_pro); // 分类树加强版
$top_goods = get_top10(0, '', 0, $region_id, $area_id, $area_city);
$smarty->assign('top_goods', $top_goods); // 销售排行
$smarty->assign('helps', get_shop_help()); // 网店帮助
assign_dynamic('category_all');
assign_template('c', $catlist);
}
//获取传来的分类id(顶级)
$id = empty($_REQUEST['id']) ? '' : intval($_REQUEST['id']);
$smarty->assign('id',$id);
$smarty->display('category_all.dwt', $cache_id);
/**
* 获得分类下的商品
*
* @access public
* @param string $children
* @return array
*/
function get_goods_category_list($children, $brand, $min, $max, $ext, $size, $page, $sort, $order, $warehouse_id = 0, $area_id = 0, $area_city = 0, $where_ext = [])
{
$display = $GLOBALS['display'];
$where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_show = 1 AND " .
"g.is_delete = 0 AND ($children OR " . get_extension_goods($children) . ')';
$leftJoin = '';
if ($brand) {
$where .= " AND g.brand_id " . db_create_in($brand);
}
$where_area = '';
if ($GLOBALS['_CFG']['area_pricetype'] == 1) {
$where_area = " AND wag.city_id = '$area_city'";
}
$leftJoin .= " LEFT JOIN " . $GLOBALS['ecs']->table('merchants_shop_information') . " AS msi ON msi.user_id = g.user_id ";
if ($GLOBALS['_CFG']['open_area_goods'] == 1) {
$where .= "(SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('link_area_goods') . " AS lag WHERE g.goods_id = lag.goods_id AND lag.region_id = '$area_id') > 0";
}
$warehouse_price = "(SELECT wg.warehouse_price FROM " . $GLOBALS['ecs']->table('warehouse_goods') . " AS wg WHERE g.goods_id = wg.goods_id AND wg.region_id = '$warehouse_id')";
$region_price = "(SELECT wag.region_price FROM " . $GLOBALS['ecs']->table('warehouse_area_goods') . " AS wag WHERE g.goods_id = wag.goods_id AND wag.region_id = '$area_id' $where_area)";
if ($min > 0) {
$sort = "g.shop_price " ;
$order = 'ASC';
}else if ($max > 0) {
$sort = "g.shop_price " ;
$order = 'DESC';
}else if ($sort == 'last_update') {
$sort = 'g.last_update ';
}else if ($sort == 'goods_id') {
$sort = "g.goods_id ";
}
/* 商品查询条件扩展 */
if (isset($where_ext['self']) && $where_ext['self'] == 1) {
$ext .= " AND (g.user_id = 0 or msi.self_run = 1) ";
}
if (isset($where_ext['have']) && $where_ext['have'] == 1) {
$warehouse_number = "(SELECT wg.region_number FROM " . $GLOBALS['ecs']->table('warehouse_goods') . " AS wg WHERE g.goods_id = wg.goods_id AND wg.region_id = '$warehouse_id')";
$region_number = "(SELECT wag.region_number FROM " . $GLOBALS['ecs']->table('warehouse_area_goods') . " AS wag WHERE g.goods_id = wag.goods_id AND wag.region_id = '$area_id' $where_area)";
$ext .= " AND IF(g.model_price < 1, g.goods_number, IF(g.model_price < 2, " . $warehouse_number . ", " . $region_number . ")) > 0 ";
}
if (isset($where_ext['ship']) && $where_ext['ship'] == 1) {
$ext .= " AND g.is_shipping = 1 ";
}
if ($GLOBALS['_CFG']['review_goods'] == 1) {
$where .= ' AND g.review_status > 2 ';
}
//卖场
$where .= get_rs_where($_COOKIE['city']);
$mp_select = "(SELECT mp.user_price FROM " . $GLOBALS['ecs']->table('member_price') . " AS mp WHERE mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]') AS user_price, ";
/* 获得商品列表 */
$sql = 'SELECT g.model_price, g.model_attr, ' . $mp_select .
"(SELECT IF((iw.goods_number + iw.user_number + iw.goods_comment_number + iw.merchants_comment_number + iw.user_attention_number) > iw.return_number, (iw.goods_number + iw.user_number + iw.goods_comment_number + iw.merchants_comment_number + iw.user_attention_number - iw.return_number), 0) " .
" AS goods_sort FROM " . $GLOBALS['ecs']->table('intelligent_weight') . " AS iw WHERE iw.goods_id = g.goods_id LIMIT 1) AS goods_sort, " .
' g.sort_order, g.goods_id,g.is_shipping, g.user_id, g.goods_name, g.goods_name_style, g.comments_number, g.sales_volume, g.goods_number, g.shop_price, g.promote_price, g.market_price, g.is_new, g.is_best, g.is_hot, g.store_new, g.store_best, g.store_hot, ' .
" g.goods_type, g.promote_start_date, g.promote_end_date, g.is_promote, g.goods_brief, g.goods_thumb , g.goods_img, msi.self_run, g.product_price, g.product_promote_price " .
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
$leftJoin .
" WHERE $where $ext ORDER BY $sort $order ";
//瀑布流加载分类商品 by wu
if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'load_more_goods') {
$start = intval($_REQUEST['goods_num']);
} //else {
//$start = ($page - 1) * $size;
//}
$res = $GLOBALS['db']->selectLimit($sql, $size, $start, 1);
$arr = array();
$count = 0;
while ($row = $GLOBALS['db']->fetchRow($res)) {
if ($row['model_price'] > 0) {
$sql = "SELECT warehouse_price, warehouse_promote_price, region_number FROM " . $GLOBALS['ecs']->table('warehouse_goods') . " AS wg " .
" WHERE goods_id = '" . $row['goods_id'] . "' AND wg.region_id = '$warehouse_id'";
$warehouse_goods = $GLOBALS['db']->getRow($sql);
$sql = "SELECT region_price, region_promote_price, region_number FROM " . $GLOBALS['ecs']->table('warehouse_area_goods') . " AS wg " .
" WHERE goods_id = '" . $row['goods_id'] . "' AND wg.region_id = '$area_id' $where_area";
$warehouse_area_goods = $GLOBALS['db']->getRow($sql);
if ($row['model_price'] == 1) {
$row['org_price'] = $warehouse_goods ? $warehouse_goods['warehouse_price'] : 0;
$row['goods_number'] = $warehouse_goods ? $warehouse_goods['region_number'] : 0;
$row['promote_price'] = $warehouse_goods ? $warehouse_goods['warehouse_promote_price'] : 0;
} else {
$row['org_price'] = $warehouse_area_goods ? $warehouse_area_goods['region_price'] : 0;
$row['goods_number'] = $warehouse_area_goods ? $warehouse_area_goods['region_number'] : 0;
$row['promote_price'] = $warehouse_area_goods ? $warehouse_area_goods['promote_price'] : 0;
}
$row['shop_price'] = $row['org_price'];
}
if ($row['user_price'] && $row['user_price'] > 0) {
$row['shop_price'] = $row['user_price'];
} else {
$row['shop_price'] = $row['shop_price'] * $_SESSION['discount'];
}
$arr[$count]['org_price'] = $row['org_price'];
$arr[$count]['model_price'] = $row['model_price'];
$arr[$count]['warehouse_price'] = $row['warehouse_price'];
$arr[$count]['warehouse_promote_price'] = $row['warehouse_promote_price'];
$arr[$count]['region_price'] = $row['region_price'];
$arr[$count]['region_promote_price'] = $row['region_promote_price'];
if ($row['promote_price'] > 0) {
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
} else {
$promote_price = 0;
}
/* 处理商品水印图片 */
$watermark_img = '';
if ($promote_price != 0) {
$watermark_img = "watermark_promote_small";
} elseif ($row['is_new'] != 0) {
$watermark_img = "watermark_new_small";
} elseif ($row['is_best'] != 0) {
$watermark_img = "watermark_best_small";
} elseif ($row['is_hot'] != 0) {
$watermark_img = 'watermark_hot_small';
}
if ($watermark_img != '') {
$arr[$count]['watermark_img'] = $watermark_img;
}
$arr[$count]['sort_order'] = $row['sort_order'];
$arr[$count]['goods_sort'] = $row['goods_sort'];
$arr[$count]['goods_id'] = $row['goods_id'];
if ($display == 'grid') {
$arr[$count]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
} else {
$arr[$count]['goods_name'] = $row['goods_name'];
}
$arr[$count]['name'] = $row['goods_name'];
$arr[$count]['goods_brief'] = $row['goods_brief'];
$arr[$count]['sales_volume'] = $row['sales_volume'];
$arr[$count]['is_promote'] = $row['is_promote'];
$arr[$count]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']);
$arr[$count]['market_price'] = price_format($row['market_price']);
$arr[$count]['shop_price'] = price_format($row['shop_price']);
$arr[$count]['type'] = $row['goods_type'];
$arr[$count]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : '';
$arr[$count]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$arr[$count]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$arr[$count]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
$arr[$count]['is_hot'] = $row['is_hot'];
$arr[$count]['is_best'] = $row['is_best'];
$arr[$count]['is_new'] = $row['is_new'];
$arr[$count]['self_run'] = $row['self_run'];
$arr[$count]['is_shipping'] = $row['is_shipping'];
//叮咚小愿 --zhuo start
if ($row['model_attr'] == 1) {
$table_products = "products_warehouse";
$type_files = " and warehouse_id = '$warehouse_id'";
} elseif ($row['model_attr'] == 2) {
$where_products = '';
if ($GLOBALS['_CFG']['area_pricetype'] == 1) {
$where_products = " AND city_id = '$area_city'";
}
$table_products = "products_area";
$type_files = " and area_id = '$area_id' $where_products";
} else {
$table_products = "products";
$type_files = "";
}
$sql = "SELECT product_id FROM " . $GLOBALS['ecs']->table($table_products) . " WHERE goods_id = '" . $row['goods_id'] . "'" . $type_files;
if (!$GLOBALS['db']->getOne($sql, true)) { //当商品没有属性库存时
$arr[$count]['prod'] = 1;
} else {
$arr[$count]['prod'] = 0;
}
$arr[$count]['goods_number'] = $row['goods_number'];
$sql = "SELECT kf_type, kf_ww, kf_qq FROM " . $GLOBALS['ecs']->table('seller_shopinfo') . " WHERE ru_id = '" . $row['user_id'] . "' LIMIT 1";
$basic_info = $GLOBALS['db']->getRow($sql);
$arr[$count]['kf_type'] = $basic_info['kf_type'];
/*处理客服旺旺数组 by kong*/
if ($basic_info['kf_ww']) {
$kf_ww = array_filter(preg_split('/\s+/', $basic_info['kf_ww']));
$kf_ww = explode("|", $kf_ww[0]);
if (!empty($kf_ww[1])) {
$arr[$count]['kf_ww'] = $kf_ww[1];
} else {
$arr[$count]['kf_ww'] = "";
}
} else {
$arr[$count]['kf_ww'] = "";
}
/*处理客服QQ数组 by kong*/
if ($basic_info['kf_qq']) {
$kf_qq = array_filter(preg_split('/\s+/', $basic_info['kf_qq']));
$kf_qq = explode("|", $kf_qq[0]);
if (!empty($kf_qq[1])) {
$arr[$count]['kf_qq'] = $kf_qq[1];
} else {
$arr[$count]['kf_qq'] = "";
}
} else {
$arr[$count]['kf_qq'] = "";
}
$shop_info = get_shop_name($row['user_id'], 3);
$arr[$count]['rz_shopName'] = $shop_info['shop_name']; //店铺名称
$arr[$count]['user_id'] = $row['user_id'];
$build_uri = array(
'urid' => $row['user_id'],
'append' => $arr[$row['goods_id']]['rz_shopName']
);
$domain_url = get_seller_domain_url($row['user_id'], $build_uri);
$arr[$count]['store_url'] = $domain_url['domain_name'];
/* 评分数 */
$sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('comment') . " WHERE id_value = '" . $row['goods_id'] . "' AND status = 1 AND parent_id = 0";
$review_count = $GLOBALS['db']->getOne($sql);
$arr[$count]['review_count'] = $review_count;
$arr[$count]['pictures'] = get_goods_gallery($row['goods_id'], 6);// 商品相册
if ($GLOBALS['_CFG']['customer_service'] == 0) {
$seller_id = 0;
$shop_information = get_shop_name($seller_id); //通过ru_id获取到店铺信息;
} else {
$seller_id = $row['user_id'];
$shop_information = $shop_info['shop_information'];
}
/* @author-bylu 判断当前商家是否允许"在线客服" start */
$arr[$count]['is_IM'] = $shop_information['is_IM']; //平台是否允许商家使用"在线客服";
//判断当前商家是平台,还是入驻商家 bylu
if ($seller_id == 0) {
//判断平台是否开启了IM在线客服
if ($GLOBALS['db']->getOne("SELECT kf_im_switch FROM " . $GLOBALS['ecs']->table('seller_shopinfo') . "WHERE ru_id = 0", true)) {
$arr[$count]['is_dsc'] = true;
} else {
$arr[$count]['is_dsc'] = false;
}
} else {
$arr[$count]['is_dsc'] = false;
}
/* @author-bylu end */
$arr[$count]['is_collect'] = get_collect_user_goods($row['goods_id']);
$count ++;
}
return $arr;
}
/**
* 创建一个JSON格式的数据
*
* @access public
* @param string $content
* @param integer $error
* @param string $message
* @param array $append
* @return void
*/
function make_json_response($content = '', $error = 0, $message = '', $append = array())
{
include_once(ROOT_PATH . 'includes/cls_json.php');
$json = new JSON;
$res = array('error' => $error, 'message' => $message, 'content' => $content);
if (!empty($append))
{
foreach ($append AS $key => $val)
{
$res[$key] = $val;
}
}
$val = $json->encode($res);
exit($val);
}
?>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化