if($op == 'output'){ //导出excl文件 date_default_timezone_set('PRC'); //查询待发货订单 $sql = 'select a.is_out,a.orderno,a.expresssn,a.name,a.mobile,a.price,a.order_pay,a.pay_time,b.gname,a.address,b.option,b.goods_num,a.marketing,a.pin_code,a.pay_type from '.tablename('sl_buyer_order').' a LEFT JOIN '.tablename('sl_buyerorder_detail').' b ON a.orderno = b.orderno where a.order_status = 2 and buyer_id > 205'; $massage = pdo_fetchall($sql); $html = "\xEF\xBB\xBF"; $filter = [ 'aa' => '订单号', 'bb' => '姓名', 'cc' => '电话', 'dd' => '订单总价', 'ee' => '实付', 'ff' => '支付时间', 'gg' => '商品名称', 'hh' => '收货地址', 'ii' => '商品规格', 'jj' => '购买数量', 'kk' => '留言', 'll' => '邮编', 'mm' => '支付类型', 'nn' => '快递单号', ];//待导出信息 foreach ($filter as $key => $title) { //循环写标题 $html .= $title . "\t,"; } $html .= "\n"; foreach ($massage as $k => $v){ $orders[$k]['aa'] = $v['orderno']; $orders[$k]['bb'] = $v['name']; $orders[$k]['cc'] = $v['mobile']; $orders[$k]['dd'] = $v['price']; $orders[$k]['ee'] = $v['order_pay']; $orders[$k]['ff'] = date('Y-m-d H:i:s',$v['pay_time']) ; $orders[$k]['gg'] = $v['gname']; $orders[$k]['hh'] = $v['address']; $orders[$k]['ii'] = $v['option']; $orders[$k]['jj'] = $v['goods_num']; $orders[$k]['kk'] = $v['marketing']; $orders[$k]['ll'] = $v['pin_code']; $orders[$k]['mm'] = ($v['pay_type'] == 1)?'Paytm':'COD'; $orders[$k]['nn'] = $v['expresssn']; foreach ($filter as $key => $title) { $html .= $orders[$k][$key] . "\t,"; } $html .= "\n"; } $str = '已发货订单'.time(); /*$sql = 'update '.tablename('sl_buyer_order').' set is_out = 1, order_status = 2 where is_out != 1 and order_status = 1' ; $result = pdo_query($sql);*/ header("Content-type:text/csv"); header("Content-Disposition:attachment; filename={$str}.csv"); echo $html; exit(); }
php导excel
最新推荐文章于 2024-06-26 13:16:08 发布