php猜你喜欢,php,javascript_ecshop 中如何在猜你喜欢中加入库存的判断,库存小于0就不显示,php,javascript - phpStudy...

ecshop 中如何在猜你喜欢中加入库存的判断,库存小于0就不显示

我加了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) < $arr['number']){

$goods_data[] = $value;

$goods_data = unique_arr($goods_data);

}

}

}

write_static_cache('like_product_'.$arr['number'], $goods_data);

}

else

{

$goods_data = $data;

}

}

$GLOBALS['smarty']->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 <= $max " : '';

$sql = 'SELECT g.goods_id, g.goods_name, g.goods_number, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' .

"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".

'promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name ' .

'FROM ' . $GLOBALS['ecs']->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' AND promote_end_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;

}

相关阅读:

请问jquery里的$("',$());是啥意思?

Vue 父子组件传递数据

请教各位高手,下一代编译型语言Go、Rust、Zimbu的对比?

php写的前端,java写的后台接口,请问各位大神,php怎样调用后台接口?

php通过composer添加一个包以后,无法通过git将这个包的代码文件提交上去

关于多个activity中侧滑菜单的问题

只有一台服务器,怎么备份MySQL数据库

微信公众号开发,获取用户openid,不使用授权回调方式

mongodb LUUID 类型查询

angular怎么修改ng-repeat的ng-checked状态?

用PHP做微信支付签名错误,请教一下这个是什么原因?

在npm中git和git+ssh和git+https有什么区别?

关于html5嵌入声音问题。

Typecho怎么调用每个分类的分类图片

Python下的正则表达式在Js下使用的问题

react-native 在ListView的renderRow方法中获取当前state中的指定值,总是null

如何比较UIView的transform属性

Android关于自定义actionbar会闪原来的actionbar

javascript问题:rgb语法书写问题

应该如何设计一个SNS网站的timeline系统..

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值