我加了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的判断啊