dedecms导出csv文件

 

1.mshd_orderlist.tpl

"frm" method="GET" action="mshd_orderlist.php">   "hidden" name="op" id="op" value="user_list">   "submit" name="sub" value="导出秒杀名单" onClick="export_data()" />

 

2.mshd_orderlist.php

if($op == 'export'){
    $miaosha_list = $mshd_miaosha_member_obj -> getMemberList(false, $where_str, $order_by,'',"add_time,user_id,mobile,item_name,serial_number,payment_code,pay_price,out_trade_no,`status`");
    $film_name = 'miaosha_list_' . date('Ymd') . '.xls';
    header("Content-Type: application/vnd.ms-excel");
    header("Content-Disposition: attachment;filename=" . $film_name);
    echo iconv('utf-8', 'gbk', "用户ID\t用户手机号\t商品名称\t兑换码\t支付方式\t价格\t秒杀时间\t订单外部交易号\t支付状态");
    foreach ($miaosha_list as $k => $v)
    {
        $time = date('Y-m-d H:i:s', $v['add_time']);
        $str = "\r\n" . $v['user_id'];
        $str .= "\t" . $v['mobile'];
        $str .= "\t" . $v['item_name'];
        $str .= "\t" . $v['serial_number'];
        $str .= "\t" . $v['payment_code'];
        $str .= "\t" . $v['pay_price'];
        $str .= "\t" . $time;
        $str .= "\t" . $v['out_trade_no'];

        $msg_info = "";
        if($v['status'] == 1){
            $msg_info = "已支付";
        }else if($v['status'] == 2){
            $msg_info = "无效";
        }else if($v['status'] == 3){
            $msg_info = "已退款";
        }else{
            $msg_info = "未支付";
        }
        $str .= "\t" . $msg_info;

        echo iconv('utf-8', 'gbk', $str);
    }
    exit();
}

 

转载于:https://www.cnblogs.com/xiaobiaomei/p/8287159.html

你可能感兴趣的:(dedecms导出csv文件)