# 第五课附录处理报表|支付
### 对于少量数据采用Excel导入导出
- 导入
```
<pre class="calibre14">```
<span class="token"><</span>form id<span class="token">=</span><span class="token4">"importform"</span> class<span class="token">=</span><span class="token4">"form-horizontal form"</span> action<span class="token">=</span><span class="token4">""</span> method<span class="token">=</span><span class="token4">"post"</span> enctype<span class="token">=</span><span class="token4">"multipart/form-data"</span><span class="token">></span>
<span class="token"><</span>div class<span class="token">=</span><span class="token4">"form-group"</span><span class="token">></span>
<span class="token"><</span>label class<span class="token">=</span><span class="token4">"col-sm-2 control-label must"</span><span class="token">></span>EXCEL<span class="token"><</span><span class="token">/</span>label<span class="token">></span>
<span class="token"><</span>div class<span class="token">=</span><span class="token4">"col-sm-5"</span> style<span class="token">=</span><span class="token4">"padding-right:0;"</span> <span class="token">></span>
<span class="token"><</span>input type<span class="token">=</span><span class="token4">"file"</span> name<span class="token">=</span><span class="token4">"excelfile"</span> class<span class="token">=</span><span class="token4">"form-control"</span> <span class="token">/</span><span class="token">></span>
<span class="token"><</span>span class<span class="token">=</span><span class="token4">"help-block"</span><span class="token">></span>选择excel文件<span class="token"><</span><span class="token">/</span>span<span class="token">></span>
<span class="token"><</span><span class="token">/</span>div<span class="token">></span>
<span class="token"><</span><span class="token">/</span>div<span class="token">></span>
<span class="token"><</span>div class<span class="token">=</span><span class="token4">'form-group'</span><span class="token">></span>
<span class="token"><</span>div class<span class="token">=</span><span class="token4">"col-sm-12"</span><span class="token">></span>
<span class="token"><</span>div class<span class="token">=</span><span class="token4">"modal-footer"</span><span class="token">></span>
<span class="token"><</span>button type<span class="token">=</span><span class="token4">"submit"</span> class<span class="token">=</span><span class="token4">"btn btn-primary"</span> name<span class="token">=</span><span class="token4">"cancelsend"</span> value<span class="token">=</span><span class="token4">"yes"</span><span class="token">></span>确认导入<span class="token"><</span><span class="token">/</span>button<span class="token">></span>
<span class="token"><</span><span class="token">/</span>div<span class="token">></span>
<span class="token"><</span><span class="token">/</span>div<span class="token">></span>
<span class="token"><</span><span class="token">/</span>div<span class="token">></span>
<span class="token"><</span><span class="token">/</span>form<span class="token">></span>
```
```
php处理
```
<pre class="calibre14">```
<span class="token5">if</span> <span class="token2">(</span>$_W<span class="token2">[</span><span class="token4">'ispost'</span><span class="token2">]</span><span class="token2">)</span> <span class="token2">{</span>
$rows <span class="token">=</span> <span class="token1">m</span><span class="token2">(</span><span class="token4">'excel'</span><span class="token2">)</span><span class="token">-</span><span class="token">></span><span class="token1">import</span><span class="token2">(</span><span class="token4">'excelfile'</span><span class="token2">)</span><span class="token2">;</span>
$time <span class="token">=</span> <span class="token1">time</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
foreach <span class="token2">(</span>$rows as $rownum <span class="token">=</span><span class="token">></span> $col<span class="token2">)</span> <span class="token2">{</span>
$data <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span>
<span class="token4">'uniacid'</span> <span class="token">=</span><span class="token">></span> $_W<span class="token2">[</span><span class="token4">'uniacid'</span><span class="token2">]</span><span class="token2">,</span>
<span class="token4">'createtime'</span> <span class="token">=</span><span class="token">></span> $time<span class="token2">,</span>
<span class="token4">'category'</span> <span class="token">=</span><span class="token">></span> <span class="token1">trim</span><span class="token2">(</span>$col<span class="token2">[</span><span class="token3">0</span><span class="token2">]</span><span class="token2">)</span><span class="token2">,</span>
<span class="token4">'orderid'</span> <span class="token">=</span><span class="token">></span> <span class="token1">trim</span><span class="token2">(</span>$col<span class="token2">[</span><span class="token3">1</span><span class="token2">]</span><span class="token2">)</span><span class="token2">,</span>
<span class="token4">'isuse'</span> <span class="token">=</span><span class="token">></span> <span class="token1">trim</span><span class="token2">(</span>$col<span class="token2">[</span><span class="token3">2</span><span class="token2">]</span><span class="token2">)</span>
<span class="token2">)</span><span class="token2">;</span>
<span class="token5">if</span> <span class="token2">(</span><span class="token1">empty</span><span class="token2">(</span>$col<span class="token2">[</span><span class="token3">0</span><span class="token2">]</span><span class="token2">)</span><span class="token2">)</span> <span class="token2">{</span>
<span class="token5">continue</span><span class="token2">;</span>
<span class="token2">}</span>
<span class="token1">pdo_insert</span><span class="token2">(</span><span class="token4">'ewei'</span><span class="token2">,</span>$data<span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
$this<span class="token">-</span><span class="token">></span><span class="token1">message</span><span class="token2">(</span><span class="token4">'导入成功!'</span><span class="token2">,</span><span class="token1">webUrl</span><span class="token2">(</span><span class="token4">''</span><span class="token2">)</span><span class="token2">,</span> <span class="token4">''</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
```
```
- 导出模板,调用以下方法即可
```
<pre class="calibre14">```
public <span class="token5">function</span> <span class="token1">import</span><span class="token2">(</span><span class="token2">)</span>
<span class="token2">{</span>
$columns <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
$columns<span class="token2">[</span><span class="token2">]</span> <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">'title'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'物流类别'</span><span class="token2">,</span> <span class="token4">'field'</span> <span class="token">=</span><span class="token">></span> <span class="token4">''</span><span class="token2">,</span> <span class="token4">'width'</span> <span class="token">=</span><span class="token">></span> <span class="token3">32</span><span class="token2">)</span><span class="token2">;</span>
$columns<span class="token2">[</span><span class="token2">]</span> <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">'title'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'物流单号'</span><span class="token2">,</span> <span class="token4">'field'</span> <span class="token">=</span><span class="token">></span> <span class="token4">''</span><span class="token2">,</span> <span class="token4">'width'</span> <span class="token">=</span><span class="token">></span> <span class="token3">32</span><span class="token2">)</span><span class="token2">;</span>
$columns<span class="token2">[</span><span class="token2">]</span> <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">'title'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'是否使用'</span><span class="token2">,</span> <span class="token4">'field'</span> <span class="token">=</span><span class="token">></span> <span class="token4">''</span><span class="token2">,</span> <span class="token4">'width'</span> <span class="token">=</span><span class="token">></span> <span class="token3">32</span><span class="token2">)</span><span class="token2">;</span>
<span class="token1">m</span><span class="token2">(</span><span class="token4">'excel'</span><span class="token2">)</span><span class="token">-</span><span class="token">></span><span class="token1">temp</span><span class="token2">(</span><span class="token4">'文件名'</span><span class="token2">.</span> <span class="token1">date</span><span class="token2">(</span><span class="token4">'Y-m-d-H-i'</span><span class="token2">,</span> <span class="token1">time</span><span class="token2">(</span><span class="token2">)</span><span class="token2">)</span><span class="token2">,</span> $columns<span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
```
```
- 导出excel
```
<pre class="calibre14">```
<span class="token"><</span>button type<span class="token">=</span><span class="token4">"submit"</span> name<span class="token">=</span><span class="token4">"export_order"</span> value<span class="token">=</span><span class="token4">"1"</span> class<span class="token">=</span><span class="token4">"btn btn-primary btn-sm"</span><span class="token">></span>导出订单<span class="token"><</span><span class="token">/</span>button<span class="token">></span>
<span class="token6">//$list是数据</span>
<span class="token5">if</span> <span class="token2">(</span>$_GPC<span class="token2">[</span><span class="token4">'export_order'</span><span class="token2">]</span> <span class="token">==</span> <span class="token3">1</span><span class="token2">)</span> <span class="token2">{</span>
$earr <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
<span class="token1">foreach</span><span class="token2">(</span>$list as $v<span class="token2">)</span><span class="token2">{</span>
$earr<span class="token2">[</span><span class="token2">]</span><span class="token">=</span><span class="token1">array</span><span class="token2">(</span>
<span class="token4">'openid'</span> <span class="token">=</span><span class="token">></span> $v<span class="token2">[</span><span class="token4">'openid'</span><span class="token2">]</span><span class="token2">,</span>
<span class="token4">'price'</span> <span class="token">=</span><span class="token">></span> $v<span class="token2">[</span><span class="token4">'price'</span><span class="token2">]</span><span class="token2">,</span>
<span class="token4">'mobile'</span><span class="token">=</span><span class="token">></span> $v<span class="token2">[</span><span class="token4">'mobile'</span><span class="token2">]</span><span class="token2">,</span>
<span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
$titlearr <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span>
<span class="token1">array</span><span class="token2">(</span><span class="token4">'title'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'openid'</span><span class="token2">,</span> <span class="token4">'field'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'openid'</span><span class="token2">,</span> <span class="token4">'width'</span> <span class="token">=</span><span class="token">></span> <span class="token3">24</span><span class="token2">)</span><span class="token2">,</span>
<span class="token1">array</span><span class="token2">(</span><span class="token4">'title'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'手机号'</span><span class="token2">,</span> <span class="token4">'field'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'mobile'</span><span class="token2">,</span> <span class="token4">'width'</span> <span class="token">=</span><span class="token">></span> <span class="token3">12</span><span class="token2">)</span><span class="token2">,</span>
<span class="token1">array</span><span class="token2">(</span><span class="token4">'title'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'智慧卡金额'</span><span class="token2">,</span> <span class="token4">'field'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'price'</span><span class="token2">,</span> <span class="token4">'width'</span> <span class="token">=</span><span class="token">></span> <span class="token3">12</span><span class="token2">)</span><span class="token2">,</span>
<span class="token2">)</span><span class="token2">;</span>
<span class="token1">m</span><span class="token2">(</span><span class="token4">'excel'</span><span class="token2">)</span><span class="token">-</span><span class="token">></span><span class="token1">export</span><span class="token2">(</span>$earr<span class="token2">,</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">'title'</span> <span class="token">=</span><span class="token">></span> <span class="token4">'订单-'</span> <span class="token2">.</span> <span class="token1">date</span><span class="token2">(</span><span class="token4">'Y-m-d-H-i'</span><span class="token2">,</span> <span class="token1">time</span><span class="token2">(</span><span class="token2">)</span><span class="token2">)</span><span class="token2">,</span> <span class="token4">'columns'</span> <span class="token">=</span><span class="token">></span> $titlearr<span class="token2">)</span><span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
```
```
### 大数据导入导出
#### csv导出大数据使用方法fputcsv()函数;
#### 步骤如下
- 计算出总数据数,大概测试出每次可导出数据量,比如1000条可导出,内存不会溢出;并设置初始导出;下面语句都是需要的,输出缓存,并且保证不会中文乱码
```
<pre class="calibre14">```
$totalcount <span class="token">=</span> <span class="token1">pdo_fetchcolumn</span><span class="token2">(</span><span class="token4">"select count(id) from "</span><span class="token2">.</span><span class="token1">tablename</span><span class="token2">(</span><span class="token4">'ewei_shop_order'</span><span class="token2">)</span><span class="token2">.</span><span class="token4">' where uniacid='</span><span class="token2">.</span>$uniacid<span class="token2">)</span><span class="token2">;</span>
$pagecount <span class="token">=</span> <span class="token3">1000</span><span class="token2">;</span>
<span class="token1">set_time_limit</span><span class="token2">(</span><span class="token3">0</span><span class="token2">)</span><span class="token2">;</span>
<span class="token1">header</span><span class="token2">(</span><span class="token4">"Content-type:application/vnd.ms-excel"</span><span class="token2">)</span><span class="token2">;</span>
<span class="token1">header</span><span class="token2">(</span><span class="token4">"Content-Disposition:attachment;filename=全部订单-"</span><span class="token2">.</span><span class="token1">date</span><span class="token2">(</span><span class="token4">'Y-m-d-H-i-s'</span><span class="token2">)</span><span class="token2">.</span><span class="token4">".csv"</span><span class="token2">)</span><span class="token2">;</span>
<span class="token1">ob_start</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
<span class="token1">ob_end_clean</span><span class="token2">(</span><span class="token2">)</span><span class="token2">;</span>
echo <span class="token4">"\xEF\xBB\xBF"</span><span class="token2">;</span>
$head <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span><span class="token4">'openid'</span><span class="token2">,</span><span class="token4">'粉丝昵称'</span><span class="token2">)</span><span class="token2">;</span>
$fp <span class="token">=</span> <span class="token1">fopen</span><span class="token2">(</span><span class="token4">'php://output'</span><span class="token2">,</span> <span class="token4">'a'</span><span class="token2">)</span><span class="token2">;</span>
<span class="token1">fputcsv</span><span class="token2">(</span>$fp<span class="token2">,</span> $head<span class="token2">)</span><span class="token2">;</span>
<span class="token5">for</span><span class="token2">(</span>$i<span class="token">=</span><span class="token3">0</span><span class="token2">;</span>$i<span class="token"><</span><span class="token1">intval</span><span class="token2">(</span>$totalcount<span class="token">/</span>$pagecount<span class="token2">)</span><span class="token">+</span><span class="token3">1</span><span class="token2">;</span>$i<span class="token">++</span><span class="token2">)</span><span class="token2">{</span>
$sql<span class="token">=</span><span class="token4">""</span><span class="token2">;</span>
$sql <span class="token2">.</span><span class="token">=</span> <span class="token4">' LIMIT '</span> <span class="token2">.</span> <span class="token1">strval</span><span class="token2">(</span>$i<span class="token">*</span>$pagecount<span class="token2">)</span> <span class="token2">.</span> <span class="token4">','</span> <span class="token2">.</span> $pagecount<span class="token2">;</span>
$list <span class="token">=</span> <span class="token1">pdo_fetchall</span><span class="token2">(</span>$sql<span class="token2">)</span><span class="token2">;</span>
<span class="token1">foreach</span><span class="token2">(</span>$list as <span class="token">&</span>$row<span class="token2">)</span><span class="token2">{</span>
$export <span class="token">=</span> <span class="token1">array</span><span class="token2">(</span>$row<span class="token2">[</span><span class="token4">'openid'</span><span class="token2">]</span><span class="token2">,</span>$row<span class="token2">[</span><span class="token4">'nickname'</span><span class="token2">]</span><span class="token2">)</span><span class="token2">;</span>
<span class="token1">fputcsv</span><span class="token2">(</span>$fp<span class="token2">,</span> $export<span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
<span class="token1">unset</span><span class="token2">(</span>$row<span class="token2">)</span><span class="token2">;</span>
<span class="token2">}</span>
```
```
支付通知文件,返回如下信息,ewei\_shopv2\\payment\\wechat\\notify.php
通过 $this->get\['attach'\]获取
```
<pre class="calibre16">```
Array
<span class="token2">(</span>
<span class="token2">[</span>get<span class="token2">]</span> <span class="token">=</span><span class="token">></span> Array
<span class="token2">(</span>
<span class="token2">[</span>appid<span class="token2">]</span> <span class="token">=</span><span class="token">></span> wx8a86306dcc35b538
<span class="token2">[</span>attach<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">5</span><span class="token2">:</span><span class="token3">17</span> <span class="token6">//前者为公众号id,后者是支付方式代码</span>
<span class="token2">[</span>bank_type<span class="token2">]</span> <span class="token">=</span><span class="token">></span> CFT
<span class="token2">[</span>cash_fee<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">1</span>
<span class="token2">[</span>device_info<span class="token2">]</span> <span class="token">=</span><span class="token">></span> ewei_shopv2
<span class="token2">[</span>fee_type<span class="token2">]</span> <span class="token">=</span><span class="token">></span> CNY
<span class="token2">[</span>is_subscribe<span class="token2">]</span> <span class="token">=</span><span class="token">></span> Y
<span class="token2">[</span>mch_id<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">1485040312</span>
<span class="token2">[</span>nonce_str<span class="token2">]</span> <span class="token">=</span><span class="token">></span> d1l11eOETpaY5AeRwC1E18e4T388O14o
<span class="token2">[</span>openid<span class="token2">]</span> <span class="token">=</span><span class="token">></span> o2SfSwZusX6_wKAFOBGrBAiUpPNk
<span class="token2">[</span>out_trade_no<span class="token2">]</span> <span class="token">=</span><span class="token">></span> OS20171128143422642364
<span class="token2">[</span>result_code<span class="token2">]</span> <span class="token">=</span><span class="token">></span> SUCCESS
<span class="token2">[</span>return_code<span class="token2">]</span> <span class="token">=</span><span class="token">></span> SUCCESS
<span class="token2">[</span>sign<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">5</span>B1B86703788788B021E51ED5D667E74
<span class="token2">[</span>time_end<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">20171128143428</span>
<span class="token2">[</span>total_fee<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">1</span>
<span class="token2">[</span>trade_type<span class="token2">]</span> <span class="token">=</span><span class="token">></span> JSAPI
<span class="token2">[</span>transaction_id<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">4200000042201711287611180681</span>
<span class="token2">)</span>
<span class="token2">[</span>type<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">17</span>
<span class="token2">[</span>total_fee<span class="token2">]</span> <span class="token">=</span><span class="token">></span> <span class="token3">0.01</span>
<span class="token2">[</span>set<span class="token2">]</span> <span class="token">=</span><span class="token">></span>
<span class="token2">[</span>setting<span class="token2">]</span> <span class="token">=</span><span class="token">></span>
<span class="token2">[</span>sec<span class="token2">]</span> <span class="token">=</span><span class="token">></span>
<span class="token2">[</span>sign<span class="token2">]</span> <span class="token">=</span><span class="token">></span>
<span class="token2">[</span>isapp<span class="token2">]</span> <span class="token">=</span><span class="token">></span>
<span class="token2">[</span>is_jie<span class="token2">]</span> <span class="token">=</span><span class="token">></span>
<span class="token2">)</span>
```
```
- 简介
- 第一章 数据库
- Mysql/mariadb
- 函数
- 基础
- 增删改索引
- 标准查询
- 高级查询
- TIDB集群mysql解决方案
- Redis
- 语言基础
- 5种数据类型
- 其他类型
- Sqlite
- 语言基础
- 常用查询
- 第二章 PHP
- 语言基础
- 第一课 流程控制和运算
- 第二课 数组
- 第三课 日期时间
- 第四课 常用函数
- 第五课 字符串
- 第六课 文件操作
- 第七课 面向对象
- 第八课 正则表达式
- 第九课 图片处理生成
- 第十课 curl/memche
- 第十一课 mysql和pdo
- 第十三课 cookie和session
- 第十四课 xml操作
- 第十五课 php5.3+新特性
- 第十六课 php7+
- 第十七课 密码安全
- 废弃函数
- php命令行
- redis应用
- 算法
- 排序算法
- 基础算法
- 无限级分类
- 自定义函数Fn
- 查找算法
- 自定义函数数据函数fn
- laravel
- 路由
- 常用语句
- 数据库
- dingo/api
- Yii2
- 控制器
- 常用类
- 数据库
- redis
- thinkphp6
- TP6文档
- TP6插件
- dedecms
- 织梦标签大全
- 数据库操作
- 内置函数和定义函数
- 织梦核心改动
- 织梦插件/底层标签开发
- PHP相关工具
- composer
- php开发环境phpenv
- Phpstorm使用
- windows编译php扩展
- PHP开源库
- 开源项目管理禅道
- sns_auth
- php-casbin权限控制
- php-jwt
- 微信SDKeasywechat
- querylist采集库
- workerman
- Box/Spout处理excel和csv
- dll扩展
- redis/memche/xdebug
- redis
- Lua
- php_xlswriter
- event
- swoole
- 常用代码库
- 微擎框架
- 第一课全局变量
- 第二课常用函数
- 第三课自定义微擎独有函数
- 第四课数据库操作
- 第五课微信端回复
- 第六课微擎高级操作
- 第八课global函数列表
- mainfest.xml详解
- js方法
- 人人商城
- 第一课model解读
- 第二课常用语句解读
- 第三课常用js解读
- 第四课附录常见问题
- 第五课附录处理报表|支付
- 常用JSON状态码
- 第三章 JavaScript
- js基础
- 浏览器对象
- 语言基础
- html5接口
- ES6新语法
- vue
- 基础语法
- 京东vueUI组件
- uniapp
- 组件开发规范
- nodejs
- 基础知识
- 安装node
- nvm不同版本node切换
- js常用标准库
- zepto/jquery
- weui
- js图标库
- elementUI
- validator表单验证
- layer弹出层
- requirejs
- wow动画
- 动画animate
- swiper4
- 百度编辑器
- flyio/axios/qs
- jquery.form
- bootstrap3
- clipboard复制
- slideout侧滑
- imagehover.css图片悬停动画
- webpack打包
- Bulma UI框架
- store 客户端存储
- lottie动画创建库
- sweetalert
- js自定义函数
- 常见JSSDK
- 微信公众号JSSDK
- 腾讯地图jssdk
- 微信小程序
- 第四章 编程语言
- markdown语言
- Dart语言
- Dart语言基础
- Flutter框架
- Lua语言
- 字符串,数组,表
- 自定义方法
- go语言
- 第1.1语言基本语法
- 第1.2流程控制
- 第1.3函数
- 第1.4结构体
- 第1.5接口
- 第1.6包
- go语言框架Gin
- CSS3语言
- CSS与CSS3
- 选择符
- 属性
- css3
- loading动画
- HTML5语言
- less
- sass
- C#
- 基础知识
- 函数
- 第五章 开发工具
- git
- nginx/apache服务器
- Linux常用操作
- crontab定时任务
- 注册表与cmd
- 阿里云ECS
- frp穿透和ssl续期
- 宝塔安装
- 树莓派
- 浏览器模拟
- 火狐/chrome常用插件
- WSL安装使用
- mac brew和终端命令
- win10相关