javascript - ecshop 中如何在猜你喜欢中加入库存的判断,库存小于0就不显示
程序员文章站
2022-06-05 16:22:27
...
我加了goods_number 但是没取出来
/*
*获取推荐商品(猜你喜欢)
*/
function insert_like_product($arr){
$need_cache = $GLOBALS['smarty']->caching;
$need_compile = $GLOBALS['smarty']->force_compile;
$GLOBALS['smarty']->caching = false;
$GLOBALS['smarty']->force_compile = true;
if (!in_array($arr['type'], array('like')))
{
$GLOBALS['smarty']->assign('number', $arr['number']);
return array();
}
static $type_goods = array();
if (empty($type_goods[$arr['type']]))
{
//初始化数据
$type_goods['like'] = array();
$goods_data = array();
$data = read_static_cache('like_product_'.$arr['number']);
if ($data == false)
{
$where = db_create_in($_COOKIE['ECS']['history'], 'goods_id');
$sql = 'SELECT goods_id, cat_id FROM ' . $GLOBALS['ecs']->table('goods') ." WHERE ".$where." AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0";
$like_goods =$GLOBALS['db']->getAll($sql);
foreach($like_goods as $val)
{
$like = get_category_goods('', $val['cat_id'],20,false);
foreach($like as $value)
{
if(count($goods_data) assign('like_goods', $goods_data);
$GLOBALS['smarty']->assign('type', $arr['type']);
$val= $GLOBALS['smarty']->fetch('library/like_product.lbi');
$GLOBALS['smarty']->caching = $need_cache;
$GLOBALS['smarty']->force_compile = $need_compile;
return $val;
}
===================================================================================
/*
*获取分类推荐商品
*/
function get_category_goods($type = '', $cats = '',$num=0,$status=true, $brand = 0, $min =0, $max = 0, $ext=''){
$brand_where = ($brand > 0) ? " AND g.brand_id = '$brand'" : '';
$price_where = ($min > 0) ? " AND g.shop_price >= $min " : '';
$price_where .= ($max > 0) ? " AND g.shop_price table('goods') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' .
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . $brand_where . $price_where . $ext;
$type2lib = array('best'=>'recommend_best', 'new'=>'recommend_new', 'hot'=>'recommend_hot', 'promote'=>'recommend_promotion');
if($status)
$num = get_library_number($type2lib[$type]);
switch ($type)
{
case 'best':
$sql .= ' AND is_best = 1';
break;
case 'new':
$sql .= ' AND is_new = 1';
break;
case 'hot':
$sql .= ' AND is_hot = 1';
break;
case 'promote':
$time = gmtime();
$sql .= " AND is_promote = 1 AND promote_start_date = '$time'";
break;
}
if (!empty($cats))
{
$sql .= " AND (g.cat_id=" . $cats . " OR " . get_extension_goods($cats) .")";
}
$order_type = $GLOBALS['_CFG']['recommend_order'];
$sql .= ($order_type == 0) ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY RAND()';
$res = $GLOBALS['db']->selectLimit($sql, $num);
$idx = 0;
$goods = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
}
else
{
$goods[$idx]['promote_price'] = '';
}
$goods[$idx]['id'] = $row['goods_id'];
$goods[$idx]['name'] = $row['goods_name'];
$goods[$idx]['number'] = $row['goods_number'];//库存
$goods[$idx]['brief'] = $row['goods_brief'];
$goods[$idx]['brand_name'] = $row['brand_name'];
$goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$goods[$idx]['market_price'] = price_format($row['market_price']);
$goods[$idx]['shop_price'] = price_format($row['shop_price']);
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
$goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']);
$idx++;
}
return $goods;
}
回复内容:
我加了goods_number 但是没取出来
/*
*获取推荐商品(猜你喜欢)
*/
function insert_like_product($arr){
$need_cache = $GLOBALS['smarty']->caching;
$need_compile = $GLOBALS['smarty']->force_compile;
$GLOBALS['smarty']->caching = false;
$GLOBALS['smarty']->force_compile = true;
if (!in_array($arr['type'], array('like')))
{
$GLOBALS['smarty']->assign('number', $arr['number']);
return array();
}
static $type_goods = array();
if (empty($type_goods[$arr['type']]))
{
//初始化数据
$type_goods['like'] = array();
$goods_data = array();
$data = read_static_cache('like_product_'.$arr['number']);
if ($data == false)
{
$where = db_create_in($_COOKIE['ECS']['history'], 'goods_id');
$sql = 'SELECT goods_id, cat_id FROM ' . $GLOBALS['ecs']->table('goods') ." WHERE ".$where." AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0";
$like_goods =$GLOBALS['db']->getAll($sql);
foreach($like_goods as $val)
{
$like = get_category_goods('', $val['cat_id'],20,false);
foreach($like as $value)
{
if(count($goods_data) assign('like_goods', $goods_data);
$GLOBALS['smarty']->assign('type', $arr['type']);
$val= $GLOBALS['smarty']->fetch('library/like_product.lbi');
$GLOBALS['smarty']->caching = $need_cache;
$GLOBALS['smarty']->force_compile = $need_compile;
return $val;
}
===================================================================================
/*
*获取分类推荐商品
*/
function get_category_goods($type = '', $cats = '',$num=0,$status=true, $brand = 0, $min =0, $max = 0, $ext=''){
$brand_where = ($brand > 0) ? " AND g.brand_id = '$brand'" : '';
$price_where = ($min > 0) ? " AND g.shop_price >= $min " : '';
$price_where .= ($max > 0) ? " AND g.shop_price table('goods') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' .
"LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
"ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . $brand_where . $price_where . $ext;
$type2lib = array('best'=>'recommend_best', 'new'=>'recommend_new', 'hot'=>'recommend_hot', 'promote'=>'recommend_promotion');
if($status)
$num = get_library_number($type2lib[$type]);
switch ($type)
{
case 'best':
$sql .= ' AND is_best = 1';
break;
case 'new':
$sql .= ' AND is_new = 1';
break;
case 'hot':
$sql .= ' AND is_hot = 1';
break;
case 'promote':
$time = gmtime();
$sql .= " AND is_promote = 1 AND promote_start_date = '$time'";
break;
}
if (!empty($cats))
{
$sql .= " AND (g.cat_id=" . $cats . " OR " . get_extension_goods($cats) .")";
}
$order_type = $GLOBALS['_CFG']['recommend_order'];
$sql .= ($order_type == 0) ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY RAND()';
$res = $GLOBALS['db']->selectLimit($sql, $num);
$idx = 0;
$goods = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
$goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
}
else
{
$goods[$idx]['promote_price'] = '';
}
$goods[$idx]['id'] = $row['goods_id'];
$goods[$idx]['name'] = $row['goods_name'];
$goods[$idx]['number'] = $row['goods_number'];//库存
$goods[$idx]['brief'] = $row['goods_brief'];
$goods[$idx]['brand_name'] = $row['brand_name'];
$goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$goods[$idx]['market_price'] = price_format($row['market_price']);
$goods[$idx]['shop_price'] = price_format($row['shop_price']);
$goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
$goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']);
$idx++;
}
return $goods;
}
你找到了对应的方法,那改了以后就打印下SQL语句调试下吧
insert_like_product函数中where条件加个goods_number>0的判断啊
上一篇: 高并发之消息队列
下一篇: MySQL数据库的授权原则_MySQL