订单查询的导出功能

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家

对订单查询结果的导出,为了程序执行效率尽量选择查询条件然后导出,比如按月导出。

1、打开admin/templates/order_query.htm找到
  1. <input name="query" type="submit" class="button" id="query" value="{$lang.button_search}" />
复制代码
下面加入
  1. <input name="export" type="submit" class="button" id="query" value="导出订单" />
复制代码


2、打开admin下order.php
  1. $order_list = order_list();
  2. $smarty->assign('order_list', $order_list['orders']);
  3. $smarty->assign('filter', $order_list['filter']);
  4. $smarty->assign('record_count', $order_list['record_count']);
  5. $smarty->assign('page_count', $order_list['page_count']);
  6. $smarty->assign('sort_order_time', '<img src="images/sort_desc.gif">');

  7. /* 显示模板 */
  8. assign_query_info();
  9. $smarty->display('order_list.htm');
复制代码
替换成
  1. if($_POST['export'] !='')
  2. {
  3. $order_list_export = order_list_export();
  4. $filename = ecs_iconv(EC_CHARSET, 'GB2312','订单导出');
  5. header("Content-type: application/vnd.ms-excel; charset=utf-8");
  6. header("Content-Disposition: attachment; filename=$filename.xls");

  7. echo ecs_iconv(EC_CHARSET, 'GB2312','订单号') . "\t";
  8. echo ecs_iconv(EC_CHARSET, 'GB2312','下单时间') . "\t";
  9. echo ecs_iconv(EC_CHARSET, 'GB2312','收货人') . "\t";
  10. echo ecs_iconv(EC_CHARSET, 'GB2312','详细地址') . "\t";
  11. echo ecs_iconv(EC_CHARSET, 'GB2312','电子邮件') . "\t";
  12. echo ecs_iconv(EC_CHARSET, 'GB2312','手机号码') . "\t";
  13. echo ecs_iconv(EC_CHARSET, 'GB2312','总金额') . "\t";
  14. echo ecs_iconv(EC_CHARSET, 'GB2312','应付金额') . "\t";
  15. echo ecs_iconv(EC_CHARSET, 'GB2312','付款方式') . "\t";
  16. foreach ($order_list_export[orders] AS $k => $row)
  17. {
  18. $order_by = $k + 1;
  19. $data .= "$row[order_sn]\t$row[short_order_time]\t$row[c**ignee]\t$row[address]\t$row[email]\t$row[mobile]\t$row[formated_total_fee]\t$row[formated_order_amount]\t$row[pay_name]\n";
  20. }
  21. echo ecs_iconv(EC_CHARSET, 'GB2312', $data);
  22. }
  23. else
  24. {
  25. $order_list = order_list();
  26. $smarty->assign('order_list', $order_list['orders']);
  27. $smarty->assign('filter', $order_list['filter']);
  28. $smarty->assign('record_count', $order_list['record_count']);
  29. $smarty->assign('page_count', $order_list['page_count']);
  30. $smarty->assign('sort_order_time', '<img src="images/sort_desc.gif">');

  31. /* 显示模板 */
  32. assign_query_info();
  33. $smarty->display('order_list.htm');
  34. }
复制代码

复制 order_list 函数紧挨着这个函数加入 粘贴然后重命名
order_list_export然后找
  1. $sql = "SELECT o.order_id, o.order_sn,o.pay_name, o.add_time, o.order_status, o.shipping_status, o.order_amount, o.money_paid," .
  2. "o.pay_status, o.c**ignee, o.address, o.email, o.tel, o.extension_code, o.extension_id, " .
  3. "(" . order_amount_field('o.') . ") AS total_fee, " .
  4. "IFNULL(u.user_name, '" .$GLOBALS['_LANG']['anonymous']. "') AS buyer ".
  5. " FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " .
  6. " LEFT JOIN " .$GLOBALS['ecs']->table('users'). " AS u ON u.user_id=o.user_id ". $where .
  7. " ORDER BY $filter[sort_by] $filter[sort_order] ".
  8. " LIMIT " . ($filter['page'] - 1) * $filter['page_size'] . ",$filter[page_size]";
复制代码

换成
  1. /* 查询 */
  2. $sql = "SELECT o.order_id, o.order_sn,o.pay_name, o.add_time, o.order_status, o.shipping_status, o.order_amount, o.money_paid," .
  3. "o.pay_status, o.c**ignee, o.address, o.email, o.tel, o.extension_code, o.extension_id, " .
  4. "(" . order_amount_field('o.') . ") AS total_fee, " .
  5. "IFNULL(u.user_name, '" .$GLOBALS['_LANG']['anonymous']. "') AS buyer ".
  6. " FROM " . $GLOBALS['ecs']->table('order_info') . " AS o " .
  7. " LEFT JOIN " .$GLOBALS['ecs']->table('users'). " AS u ON u.user_id=o.user_id ". $where .
  8. " ORDER BY $filter[sort_by] $filter[sort_order] ";
复制代码

其实就是去掉limit。

然后去调试。


回答:
不行哦。

Fatal error: Call to undefined function order_list_export() in D:\xampp\htdocs\admin\order.php on line 77
提示这个错误啊,贴主解释下...

齐老师不是说要出新版教程?大半年过去了

最近比较忙 希望大家谅解

这个不错 收藏

终于是正式会员了,楼主写的教程是管用的。有一定基础的问用起来比较得心应手

$sql = "SELECT o.order_id, o.order_sn,o.pay_name, o.add_time, o.order_status, o.shipping_status, o.order_amount, o.money_paid," .
如果需要新增导出项目,可以多些一些数据库字段,也可以导出商品等,主要是数据库语句。
多表联合查询,不会的兄弟可以百度。

辛苦了!

ecshop学习资料:http://www.phpally.com