public function downCardList($product_id){ $product = model('Product')->getOneData(' * ',['id'=>$product_id]); $card = model('CardType')->getOneData(' * ',['id'=>$product['cardtype']]); $table = 'card_'.$card->mark; $data = Db::table($table)->field('*')->where(['product_id'=>$product_id])->select(); //到这里都是获取信息 //开始设置内容 $str = ' < html>'; $str .= ' < head>'; $str .= ' < meta http - equiv = "Content-Type" content = "text/html; charset=utf-8" > '; $str .= ' '; $str .= ' '; $str .= '
'; $str .= ' '; $str .= " 产品名称 | ".$product->name." | "; $str .= '
'; $str .= ' '; $str .= " 产品数量 | ".$product->num." | "; $str .= '
'; $str .= ' '; $str .= " 产品创建时间 | ".$product->create_time." | "; $str .= '
'; $str .= ' '; $str .= ' 卡号 | 激活码 | '; $str .= '
'; //遍历主体内容 foreach ($data as $val){ $str .= ' '; //数字每四位加空格,方便看 $psw = substr_replace($val['password'],' ',4,0); $psw = substr_replace($psw,' ',9,0); $psw = substr_replace($psw,' ',14,0); $str .= " ".$card->mark.$val['id']." | ".$psw." | ";//vnd.ms-excel.numberformat:@将表格设置为文本,以便长数字全部正常显示 $str .= '
'; } $str .= '
'; $str .= ' '; $str .= ' '; header("cache-control:no-cache,must-revalidate");//无浏览器缓存 header("Content-Type:application/vnd.ms-execl");//提示下载为Excel header("Content-Type:application/octet-stream"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=".$product->name.'-'.date('Y-m-d').".xls"); header('Expires:0'); header('Pragma:public'); echo "\xFF\xFE".mb_convert_encoding( $str, 'UCS-2LE', 'UTF-8' ); }