public function csv()
{
error_reporting(E_ALL ^ E_NOTICE);
//读取数据库数据
$db = DB::table('xxxxx')->where('xxx', '2')->pluck('id');
$result = DB::table('xxxx')->select('id', 'employee_id')->whereIn('id', $db)->get();
set_time_limit(0);
//文件存储路径
$pathFile = 'D:\PhpPro\csv\123.csv';
$handle = fopen($pathFile,'wb');
if ($handle) {
//第一行
$header = array(
iconv( 'UTF-8', 'GB2312//IGNORE', '店铺id' ),
//将utf-8转成gb2312,ignore的意思是忽略转换时的错误
iconv( 'UTF-8', 'GB2312//IGNORE', '员工账号' ),
);
fputcsv( $handle, $header );
//写入csv
foreach( $result as $key=>$value ) {
$fields[$key] = [
'app_id'=>$value->app_id,'employee_id' => $value->employee_id
];
fputcsv( $handle, $fields[$key]);
}
}
fclose($handle);
echo 'ok';
}