ecshop增加 购买过该商品的人还购买过哪些商品 功能

这个在ecshop中其实自带这个功能,但是ecshop中的这个功能是根据订单商品order_goods 表来获取的数据,实际上只是获得了 购买这个商品的订单中的其他的商品 ,而不是购买这个商品的人还购买了哪些商品,对此我做了一些改进。

先看函数

在goods.php中添加function get_have_buys($goods_id);

 

 

/*
购买过该商品的人还购买了
*/
function get_have_buys($goods_id){
$sql = “select distinct(o.user_id) from “.$GLOBALS['ecs']->table(“order_goods”).” as og “.
“left join “.$GLOBALS['ecs']->table(“order_info”).” as o on og.order_id=o.order_id “.
” where og.goods_id=’$goods_id’ and (o.order_status=1 or o.order_status=5)  and o.user_id!=0″;

//获得购买过该商品的人 ,这些用户不包括那些没有注册的人,否则得话就会有许多不真实的商品出现
$users = $GLOBALS['db']->getAll($sql);
$ins = ”;
foreach($users as $key=>$val){
$ins .= $val['user_id'].”,”;
}
$ins = rtrim($ins,’,');
if(empty($ins)){
return array();
}
//这些人都购买了哪些东西
$sql = “select distinct(og.goods_id) from “.$GLOBALS['ecs']->table(“order_goods”).” as og “.
“left join “.$GLOBALS['ecs']->table(“order_info”).” as o on og.order_id=o.order_id “.
” where o.user_id in ($ins) and (o.order_status=1 or o.order_status=5)”;
$goods = $GLOBALS['db']->getAll($sql);
$ins = ”;
foreach($goods as $keys=>$val){
$ins.=$val['goods_id'].”,”;
}

$ins = rtrim($ins,’,');
if(empty($ins)){
return array();
}
$sql = “select * from “.$GLOBALS['ecs']->table(“goods”).” where goods_id in ($ins) and is_on_sale = 1 AND is_alone_sale = 1 and is_delete=0 limit 10″;
$res = $GLOBALS['db']->query($sql);
$arr = 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']);
}
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[$row['goods_id']]['watermark_img'] = $watermark_img;
}

$arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
if($display == ‘grid’)
{
$arr[$row['goods_id']]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
}
else
{
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
}
$arr[$row['goods_id']]['name'] = $row['goods_name'];
$arr[$row['goods_id']]['goods_brief'] = $row['goods_brief'];
$arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
$arr[$row['goods_id']]['market_price'] = price_format($row['market_price']);
$arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']);
$arr[$row['goods_id']]['type'] = $row['goods_type'];
$arr[$row['goods_id']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : ”;
$arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
$arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$arr[$row['goods_id']]['url'] = build_uri(‘goods’, array(‘gid’=>$row['goods_id']), $row['goods_name']);
}
return $arr;
}

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值