//處理訂單狀態(tài)
$fileName= "訂單列表";
$header= [
? ? '訂單狀態(tài)',
? ? '訂單類型',
? ? '結(jié)算狀態(tài)',
? ? '主訂單號(hào)',
? ? '子訂單號(hào)',
? ? '供應(yīng)商ID',
? ? '供應(yīng)商',
? ? '訂單采購金額',
? ? '訂單銷售金額',
? ? '售后退款金額',
? ? '用戶id',
? ? '會(huì)員等級(jí)',
? ? '收貨人',
? ? '收貨電話',
? ? '收貨地址',
? ? '商品SKU',
? ? '商品名稱',
? ? '規(guī)格',
? ? '商品分類',
? ? '品牌',
? ? '銷售類型',
? ? '數(shù)量',
? ? '銷售單價(jià)',
? ? '銷售總價(jià)',
? ? '采購單價(jià)',
? ? '采購總價(jià)',
? ? '下單時(shí)間',
? ? '支付時(shí)間',
];? //表頭信息
$fields= [
? ? 'orderStatusName',
? ? 'afterSaleStr',
? ? 'billStatus',
? ? 'orderNumber',
? ? 'parcelNumber',
? ? 'goodsSupplierId',
? ? 'supplierName',
? ? 'allGoodsPurchasingPrice',
? ? 'totalAmt',
? ? 'refundAmt',
? ? 'userId',
? ? 'memberLevelStr',
? ? 'consignee',
? ? 'mobile',
? ? 'codeStringInfo',
? ? 'skuId',
? ? 'orderDetailTitle',
? ? 'goodsSpecification',
? ? 'goodsTypeThreeName',
? ? 'brandName',
? ? 'activityName',
? ? 'goodsNum',
? ? 'goodsTotalAmtE2',
? ? 'totalAmtE2',
? ? 'goodsPurchasingPriceE2',
? ? 'goodsPurchasingPriceE2Total',
? ? 'createdAt',
? ? 'payTimeStr',
];
//設(shè)置header
$header= array_combine($fields,$header);
BaseFormModel::csvExport($data, $header, [], $fileName, true, 'utf-8');
/**
* 導(dǎo)出csv
* @param array $data 數(shù)據(jù)
* @param array $headers csv標(biāo)題+數(shù)據(jù)
* @param array $specHeaders 需要轉(zhuǎn)成字符串的數(shù)組下標(biāo)
* @param string $fileName 文件名稱
* @param bool $isFirst 是否只去第一條
* @param string $fontType 需要導(dǎo)出的字符集 csv默認(rèn)為utf-8
* @author zhaohao
* @date 2019-12-10 11:38
*/
public static function csvExport(array $data, array $headers, $specHeaders = [], $fileName = '',$isFirst = false, $fontType = 'gbk//IGNORE') {
? ? //終端導(dǎo)出無需header頭
? ? header('Content-Type: application/vnd.ms-excel');
? ? header('Content-Disposition: attachment;filename="'.$fileName.'.csv"');
? ? header('Cache-Control: max-age=0');
? ? $fp= fopen('php://output','a');
? ? foreach ($headers as $key=> $value) {
? ? ? ? $headers[$key] = mb_convert_encoding($value, $fontType, 'utf-8');
}
? ? if($isFirst){
? ? ? ? fputcsv($fp, $headers);
}
? ? //計(jì)數(shù)器
? ? $num= 0;
? ? $limit= 50000;
? ? //逐行取出數(shù)據(jù),不浪費(fèi)內(nèi)存
? ? $count= count($data);
? ? for ($i= 0; $i< $count; $i++) {
? ? ? ? $num++;
? ? ? ? if ($limit%200 == $num) {
? ? ? ? ? ? ob_flush();
? ? ? ? ? ? flush();
? ? ? ? ? ? $num= 0;
}
? ? ? ? $row= $data[$i];
? ? ? ? $ret= [];
? ? ? ? foreach ($headers as $key=> $value) {
? ? ? ? ? ? if(!empty($specHeaders) && in_array($key,$specHeaders)){
? ? ? ? ? ? ? ? $ret[$key] = mb_convert_encoding($row[$key], $fontType, 'utf-8')."\t";
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? $ret[$key] = mb_convert_encoding($row[$key], $fontType, 'utf-8');
}
}
? ? ? ? fputcsv($fp, $ret);
}
? ? unset($data);
? ? unset($ret);
? ? fclose($fp);
? ? exit;
}