首页
IT
登录
6mi
u
盘
搜
搜 索
IT
ecshop 后台订单导出
ecshop 后台订单导出
xiaoxiao
2026-05-18
0
1.
获取订单列表信息:这里只导出
'订单号'
,
'时间'
,
'付款方式'
,
'金额'
2.
格式化数据 header(
"Content-type:text/html;charset=utf-8"
);
//获取订单列表
$sql
=
"SELECT order_sn,add_time,confirm_time,order_amount,currency,pay_name,goods_amount,shipping_fee,(goods_amount + shipping_fee) AS total FROM "
.
$GLOBALS
[
'fds'
]->table(
'order_info'
).
" WHERE pay_status=2 ORDER BY order_id DESC"
;
$order_list
=
$GLOBALS
[
'db'
]->getAll(
$sql
);
if
(
$order_list
){
foreach
(
$order_list
as
$k
=>
$v
){
$order_list
[
$k
][
'format_confirm_time'
] = local_date(
"Y/m/d"
,
$v
[
'confirm_time'
]);
//付款时间
$order_list
[
$k
][
'format_add_time'
] = local_date(
"Y/m/d"
,
$v
[
'add_time'
]);
//添加时间
} }
//整理数据
if
(
$order_list
){
$temp
=
array
();
foreach
(
$order_list
as
$key
=>
$val
){
$temp
[
$key
][
'order_sn'
] =
$val
[
'order_sn'
];
$temp
[
$key
][
'format_confirm_time'
] =
$val
[
'format_confirm_time'
];
$temp
[
$key
][
'pay_name'
] =
$val
[
'pay_name'
];
$temp
[
$key
][
'order_amount_s'
] =
$val
[
'total'
].
' '
.
$val
[
'currency'
]; } }
$title
=
array
(
'订单号'
,
'时间'
,
'付款方式'
,
'金额'
); exportexcel(
$temp
,
$title
,
'order'
);
3.
创建exportexcel函数
/** * 导出数据为excel表格 *@param $data 一个二维数组,结构如同从数据库查出来的数组 *@param $title excel的第一行标题,一个数组,如果为空则没有标题 *@param $filename 下载的文件名 *@examlpe $stu = M ('User'); $arr = $stu -> select(); exportexcel($arr,array('id','账户','密码','昵称'),'文件名!'); */
function
exportexcel
(
$data
=array
()
,
$title
=array
()
,
$filename
=
'report'
)
{
header(
"Content-type:application/octet-stream"
); header(
"Accept-Ranges:bytes"
); header(
"Content-type:application/vnd.ms-excel"
); header(
"Content-Disposition:attachment;filename="
.
$filename
.
".xls"
); header(
"Pragma: no-cache"
); header(
"Expires: 0"
);
//导出xls 开始
if
(!
empty
(
$title
)){
foreach
(
$title
as
$k
=>
$v
) {
$title
[
$k
]=iconv(
"utf-8"
,
"gb2312"
,
$v
); }
$title
= implode(
"\t"
,
$title
);
echo
"$title\n"
; }
if
(!
empty
(
$data
)){
foreach
(
$data
as
$key
=>
$val
){
foreach
(
$val
as
$ck
=>
$cv
) {
$data
[
$key
][
$ck
]=iconv(
"UTF-8"
,
"GB2312"
,
$cv
); }
$data
[
$key
]=implode(
"\t"
,
$data
[
$key
]); }
echo
implode(
"\n"
,
$data
); } }
转载请注明原文地址: https://ju.6miu.com/read-1309798.html
最新回复
(
0
)