对于少量数据采用Excel导入导出
- 导入
<form id="importform" class="form-horizontal form" action="" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="col-sm-2 control-label must">EXCEL</label>
<div class="col-sm-5" style="padding-right:0;" >
<input type="file" name="excelfile" class="form-control" />
<span class="help-block">选择excel文件</span>
</div>
</div>
<div class='form-group'>
<div class="col-sm-12">
<div class="modal-footer">
<button type="submit" class="btn btn-primary" name="cancelsend" value="yes">确认导入</button>
</div>
</div>
</div>
</form>
- php处理
if ($_W['ispost']) {
$rows = m('excel')->import('excelfile');
$time = time();
foreach ($rows as $rownum => $col) {
$data = array(
'uniacid' => $_W['uniacid'],
'createtime' => $time,
'category' => trim($col[0]),
'orderid' => trim($col[1]),
'isuse' => trim($col[2])
);
if (empty($col[0])) {
continue;
}
pdo_insert('ewei',$data);
}
$this->message('导入成功!',webUrl(''), '');
}
- 导出模板,调用以下方法即可
public function import()
{
$columns = array();
$columns[] = array('title' => '物流类别', 'field' => '', 'width' => 32);
$columns[] = array('title' => '物流单号', 'field' => '', 'width' => 32);
$columns[] = array('title' => '是否使用', 'field' => '', 'width' => 32);
m('excel')->temp('文件名'. date('Y-m-d-H-i', time()), $columns);
}
- 导出excel
<button type="submit" name="export_order" value="1" class="btn btn-primary btn-sm">导出订单</button>
//$list是数据
if ($_GPC['export_order'] == 1) {
$earr = array();
foreach($list as $v){
$earr[]=array(
'openid' => $v['openid'],
'price' => $v['price'],
'mobile'=> $v['mobile'],
);
}
$titlearr = array(
array('title' => 'openid', 'field' => 'openid', 'width' => 24),
array('title' => '手机号', 'field' => 'mobile', 'width' => 12),
array('title' => '智慧卡金额', 'field' => 'price', 'width' => 12),
);
m('excel')->export($earr, array('title' => '订单-' . date('Y-m-d-H-i', time()), 'columns' => $titlearr));
}
大数据导入导出
csv导出大数据使用方法fputcsv()函数;
步骤如下
- 计算出总数据数,大概测试出每次可导出数据量,比如1000条可导出,内存不会溢出;并设置初始导出;下面语句都是需要的,输出缓存,并且保证不会中文乱码
$totalcount = pdo_fetchcolumn("select count(id) from ".tablename('ewei_shop_order').' where uniacid='.$uniacid);
$pagecount = 1000;
set_time_limit(0);
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=全部订单-".date('Y-m-d-H-i-s').".csv");
ob_start();
ob_end_clean();
echo "\xEF\xBB\xBF";
$head = array('openid','粉丝昵称');
$fp = fopen('php://output', 'a');
fputcsv($fp, $head);
for($i=0;$i<intval($totalcount/$pagecount)+1;$i++){
$sql="";
$sql .= ' LIMIT ' . strval($i*$pagecount) . ',' . $pagecount;
$list = pdo_fetchall($sql);
foreach($list as &$row){
$export = array($row['openid'],$row['nickname']);
fputcsv($fp, $export);
}
unset($row);
}
支付通知文件,返回如下信息,ewei_shopv2\payment\wechat\notify.php
通过 $this->get[‘attach’]获取
Array
(
[get] => Array
(
[appid] => wx8a86306dcc35b538
[attach] => 5:17 //前者为公众号id,后者是支付方式代码
[bank_type] => CFT
[cash_fee] => 1
[device_info] => ewei_shopv2
[fee_type] => CNY
[is_subscribe] => Y
[mch_id] => 1485040312
[nonce_str] => d1l11eOETpaY5AeRwC1E18e4T388O14o
[openid] => o2SfSwZusX6_wKAFOBGrBAiUpPNk
[out_trade_no] => OS20171128143422642364
[result_code] => SUCCESS
[return_code] => SUCCESS
[sign] => 5B1B86703788788B021E51ED5D667E74
[time_end] => 20171128143428
[total_fee] => 1
[trade_type] => JSAPI
[transaction_id] => 4200000042201711287611180681
)
[type] => 17
[total_fee] => 0.01
[set] =>
[setting] =>
[sec] =>
[sign] =>
[isapp] =>
[is_jie] =>
)
作者:Yoby 创建时间:2020-07-23 23:04
更新时间:2024-12-05 13:26
更新时间:2024-12-05 13:26