1. 定义报表类文件/admin/report/goods_sale_month.php:
<?php
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
/* 实例化对象 */
$report = new report_goods_sale_month();
/* 显示报表 */
$report->display();
/* 报表类 */
class report_goods_sale_month
{
public function __construct()
{
/* 设置报表名称 */
$this->name = '商品月销售量报表';
/* 设置报表 SQL */
$this->sql = 'SELECT goods_id, SUM(goods_number) AS num, FROM_UNIXTIME(add_time, "%Y%m") AS month FROM ' . $GLOBALS['ecs']->table('order_goods') . ' WHERE FROM_UNIXTIME(add_time, "%Y%m") >= ' . get_begin_month() . ' GROUP BY goods_id, month ORDER BY num DESC';
}
public function display()
{
/* 统计数据 */
$data = $this->get_data();
/* 分页大小 */
$size = 10;
/* 计算页数 */
$page_count = ceil(count($data) / $size);
/* 获取当前页 */
$page = empty($_REQUEST['page']) ? 1 : intval($_REQUEST['page']);
/* 获取页数范围 */
$pages = get_pages($page, $page_count, $size);
/* 获取商品数据 */
$items = array_slice($data, ($page-1)*$size, $size);
/* 模板赋值显示 */
$smarty->assign('name', $this->name);
$smarty->assign('data', $items);
$smarty->assign('pages', $pages);
$smarty->display('report_goods_sale_month.html');
}
}
2. 定义报表模板文件/admin/templates/report_goods_sale_month.html:
<table class="list-table">
<thead>
<tr>
<th>商品名称</th>
<th>月份</th>
<th>销售数量</th>
</tr>
</thead>
<tbody>
{foreach from=$data item=item}
<tr>
<td>{$item.goods_name}</td>
<td>{$item.month}</td>
<td align="right">{$item.num}</td>
</tr>
{/foreach}
</tbody>
</table>
{$pages}
3. 设置cron任务定期运行/admin/report/goods_sale_month.php脚本生成报表。
4. 在ECShop后台点击“报表”->“商品月销售量报表”查看结果。
© 版权声明
本文刊载的所有内容,包括文字、图片、音频、视频、软件、程序、以及网页版式设计等部门来源于互联网,版权均归原作者所有!本网站提供的内容服务于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯本网站及相关权利人的合法权利。
联系信息:邮箱aoxolcom@163.com或见网站底部。
联系信息:邮箱aoxolcom@163.com或见网站底部。
THE END



















请登录后发表评论
注册
社交帐号登录