如何在ecshop显示商品销售记录 商品已销售数量
1个回答
展开全部
一、新建,goods_buy.lbi 文件
加入如下代码
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!-- {if $goods_buy} --> <table width="80%" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#cccccc"> <tr> <td colspan="4" align="right" bgcolor="#ffffff">{$goods_buy_num}</td> </tr> <tr> <th bgcolor="#ffffff">会员ID</th> <th bgcolor="#ffffff">客户地址</th> <th bgcolor="#ffffff">订购数量</th> <th bgcolor="#ffffff">订购时间</th> </tr> <!-- {foreach from=$goods_buy item=goodsbuy} 购买记录 --> <tr> <td bgcolor="#ffffff">{$goodsbuy.consignee}</td> <td bgcolor="#ffffff">{$goodsbuy.address}</td> <td bgcolor="#ffffff">{$goodsbuy.goods_number}</td> <td bgcolor="#ffffff">{$goodsbuy.add_time}</td> </tr> <!-- {/foreach} --> </table> <!-- {/if} --> 二、修改goods.PHP文件,两处
1、在文件尾加入两个函数
/** * 取得跟商品关联前10条订购记录 * * @param string $goods_id 商品编号 * * @return 订购记录 */ function get_goods_buy_list($goods_id) { $sql = "SELECT g.goods_id,o.consignee,o.add_time,g.goods_number,g.order_id,o.address". " FROM " . $GLOBALS['ecs']->table('order_goods') . " AS g". " LEFT JOIN " . $GLOBALS['ecs']->table('order_info') . " AS o on o.order_id=g.order_id". " WHERE g.goods_id = " . $goods_id . " and o.order_status=1" . " ORDER BY o.add_time LIMIT 10 "; $res = $GLOBALS['db']->query($sql); $arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { $row['add_time'] = local_date('Y-m-d H:i:s',$row['add_time']); $row['address'] = sub_str($row['address'],6); $arr[] = $row; } return $arr; } /** * 取得跟商品关联前10条订购记录 * * @param string $goods_id 商品编号 * * @return 订购记录 */ function get_goods_buy_num($goods_id) { $sql = "SELECT count(g.rec_id) as num". " FROM " . $GLOBALS['ecs']->table('order_goods') . " AS g". " LEFT JOIN " . $GLOBALS['ecs']->table('order_info') . " AS o on o.order_id=g.order_id". " WHERE g.goods_id = " . $goods_id . " and o.shipping_status=1"; return $GLOBALS['db']->getOne($sql); } /** * 取得商品销售总量 * * @param string $goods_id 商品编号 * * @return 订购量 */ function get_goods_buy_sum($goods_id) { $sql = "SELECT sum(g.goods_number) as num". " FROM " . $GLOBALS['ecs']->table('order_goods') . " AS g". " WHERE g.goods_id = " . $goods_id . " " ; return $GLOBALS['db']->getOne($sql); } 2、查找 $smarty->assign('goods', $goods);
在其下一行加入
//获取商品销售记录 $smarty->assign('goods_buy', get_goods_buy_list($goods_id)); $buy_num = get_goods_buy_num($goods_id); if ($buy_num!= 0 ) sprintf("[%s]位顾客购买过", $buy_num); $smarty->assign('goods_buy_num', $buy_num); 三、修改模板查找<h2 class="h2bg"><span class="L"></span><span class="R"></span>{$lang.shopman_comment}</h2>在其下加入<h2 class="h2bg"><span class="L"></span><span class="R"></span>{$lang.goods_buy}</h2>
查找</blockquote>在最后一个标记之后
<!-- {/foreach} -->
</blockquote>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询