private function write($bid = 0){
set_time_limit(0);
// 输出Excel文件头
header('Content-Type: application/vnd.ms-excel;charset=gbk');
header('Content-Disposition: attachment;filename="产品导出.csv"');
header('Cache-Control: max-age=0');
// PHP文件句柄,php://output 表示直接输出到浏览器
$fp = fopen('php://output', 'a');
// 输出Excel列头信息
$head = array(
0 => '标题',
1 => '连接'
);
foreach ($head as $i => $v) {
// CSV的Excel支持GBK编码,一定要转换,否则乱码
$head[$i] = iconv('utf-8', 'gbk', $v);
}
// 写入列头
fputcsv($fp, $head);
$row = array();
$row['serial'] = "标题";
$row['wserial'] = '连接';
fputcsv($fp, $row);
}
另外一些
<?php
/**
* 导出推送消息详情
* @author Jiaxu<156549562@qq.com>
* @date 2015-01-19
*/
function orderlist_execl2(){
$order = M("order","t_","51yche");
$user = M("user","t_","51yche");
if($_GET['date'] != NULL){
$condition['_string'] = ' a.order_add_timestamp > "'.$_GET['date'].' 00:00:00" AND a.order_add_timestamp<"'.$_GET['date'].' 23:59:59" and d.route_type=1';
}else{
$condition['_string'] = ' a.order_add_timestamp > "'.date("Y-m-d",time()).' 00:00:00" AND a.order_add_timestamp<"'.date("Y-m-d",time()).' 23:59:59"';
}
$count = $order->table('t_order as a')
->join('LEFT JOIN t_order_push as e ON a.order_id=e.fk_order_id')
->join('LEFT JOIN t_user as b ON e.fk_user_id=b.user_id')
->join('LEFT JOIN t_user as c ON a.fk_user_id=c.user_id')
->join('LEFT JOIN t_route as d ON e.fk_user_id=d.fk_user_id')
->join('LEFT JOIN t_driver as f ON e.fk_user_id=f.fk_user_id')
->where($condition)
->count();
set_time_limit(0);
$page_start = 0;
$base_num = 10000;
$limt = ceil($count/$base_num);
if($count<$p_num){
$p_num = $count;
if($count<$base_num){
$limt = 1;
}else{
$limt = ceil($count/$base_num);
}
}
$title = array('请求ID','发布时间','乘客ID','乘客昵称','出发时间','起点名称','终点名称',
'起点坐标','终点坐标','车型选择','订单价格','车主ID','车主昵称','车主类型',
'车型','线路ID','车主线路出发时间','车主起点','车主终点','起点坐标',
'终点坐标','详情展示时间','抢单时间','订单状态','达成订单id','付款时间',
'完成时间','取消时间','操作人','取消原因','客服的备注');
foreach ($title as $k => $v) {
$title[$k]=iconv("UTF-8", "gbk",$v);
}
$title= implode("\t", $title);
$str = "$title\n";
$file_dir = C('DLOG_DIR');
$excel_file = $file_dir."order_push_list-".$_GET['date'].".xls";
$fp = fopen($excel_file, 'w');
for($i=1;$i<=$limt;$i++){
$Push = array();
$Push = $order->table('t_order as a')
->join('LEFT JOIN t_order_push as e ON a.order_id=e.fk_order_id')
->join('LEFT JOIN t_user as b ON e.fk_user_id=b.user_id')
->join('LEFT JOIN t_user as c ON a.fk_user_id=c.user_id')
->join('LEFT JOIN t_route as d ON e.fk_user_id=d.fk_user_id')
->join('LEFT JOIN t_driver as f ON e.fk_user_id=f.fk_user_id')
->where($condition)
->limit($page_start.','.$base_num)
->field('e.fk_user_id as push_driver_id,a.order_id,a.order_add_timestamp,a.order_start_timestamp,a.order_distance,a.order_start,a.order_end,a.order_start_lng,a.order_start_lat,a.order_end_lng,a.order_end_lat,a.order_car_type,a.order_amt,b.user_nick,b.user_rank,c.user_nick as passenger_user_nick,d.route_id,d.route_type,d.route_start_time,d.route_start,d.route_end,d.route_start_lat,d.route_start_lng,d.route_end_lat,d.route_end_lng,f.driver_car_type')
->order('e.order_push_time desc')
->select();
foreach ($Push as $key => $value) {
if($Push[$key]['driver_user_id']!=0){
$Push[$key]['order_driver_get_time']=$this->getOrderTime($value['order_id']);
}else{
$Push[$key]['order_driver_get_time']='';
}
if($this->getPayTime($value['order_id'])){
$Push[$key]['order_pay_time']=$this->getPayTime($value['order_id']);
}else{
$Push[$key]['order_pay_time']='';
}
if($this->getFinishTime($value['order_id'])){
$Push[$key]['order_finish_time']=$this->getFinishTime($value['order_id']);
}else{
$Push[$key]['order_finish_time']='';
}
if($this->getCancelTime($value['order_id'],$value['order_status'])){
$Push[$key]['order_cancel_time']=$this->getCancelTime($value['order_id'],$value['order_status']);
}else{
$Push[$key]['order_cancel_time']='';
}
}
$arr = array();
foreach ($Push as $key => $value) {
$arr[$key]['order_id'] = $value['order_id'];
$arr[$key]['order_add_timestamp'] = $value['order_add_timestamp'];
$arr[$key]['fk_user_id'] = $value['fk_user_id'];
$arr[$key]['passenger_user_nick']=$value['passenger_user_nick'];
$arr[$key]['order_start_timestamp'] = $value['order_start_timestamp'];
$arr[$key]['order_start'] = $value['order_start'];
$arr[$key]['order_end'] = $value['order_end'];
$arr[$key]['order_start_coordinate'] ="({$value['order_start_lng']}".","."{$value['order_start_lat']})";
$arr[$key]['order_end_coordinate'] ="({$value['order_end_lng']}".","."{$value['order_end_lat']})";
$arr[$key]['order_car_type'] = $this->getCartype($value['order_car_type']);
$arr[$key]['order_amt'] = $value['order_amt'];
$arr[$key]['push_driver_id'] = $value['push_driver_id'];
$arr[$key]['user_nick'] = $value['user_nick'];
if($value['user_rank']==1){
$arr[$key]['driver_type']='普通车主';
}elseif($value['user_rank']==2){
$arr[$key]['driver_type']='核心车主';
}else{
$arr[$key]['driver_type']='租赁车主';
}
if($value['driver_car_type']==1){
$arr[$key]['driver_car_type']='经济型';
}elseif($value['driver_car_type']==2){
$arr[$key]['driver_car_type']='舒适型';
}else{
$arr[$key]['driver_car_type']='豪华型';
}
$arr[$key]['route_id'] = $value['route_id'];
$arr[$key]['route_start_time'] = $value['route_start_time'];
$arr[$key]['route_start'] = $value['route_start'];
$arr[$key]['route_end'] = $value['route_end'];
$arr[$key]['route_start_coordinate'] ="({$value['route_start_lng']}".","."{$value['route_start_lat']})";
$arr[$key]['route_end_coordinate'] ="({$value['route_end_lng']}".","."{$value['route_end_lat']})";
$arr[$key]['order_driver_first_time']='0000-00-00 00:00:00';
$arr[$key]['order_driver_get_time']=$value['order_driver_get_time'];
$arr[$key]['order_status'] = $this->getStatusDesc($value['order_status']);
if($value['driver_user_id']!=0){
$arr[$key]['order_get_id']=$value['order_id'];
}else{
$arr[$key]['order_get_id']='';
}
$arr[$key]['order_pay_time']=$value['order_pay_time'];
$arr[$key]['order_finish_time']=$value['order_finish_time'];
$arr[$key]['order_cancel_time']=$value['order_cancel_time'];
$arr[$key]['fk_mis_nickname']=$value['fk_mis_nickname'];
$arr[$key]['order_cancel_reason']=$value['order_cancel_reason'];
$arr[$key]['order_cancel_content']=$value['order_cancel_content'];
}
foreach($arr as $key=>$val){
foreach ($val as $ck => $cv) {
$arr[$key][$ck]=iconv("UTF-8", "gbk", $cv);
}
$arr[$key]=implode("\t", $arr[$key]);
}
fwrite($fp,implode("\n",$arr));
fwrite($fp,"\n");
unset($Push);
unset($arr);
$page_start = $page_start+$base_num;
}
fclose($fp);
echo "<a href='/log/order_push_list-".$_GET['date'].".xls'>/log/order_push_list-".$_GET['date']."xls</a>";
}
?>