人人商城处理导入Excel和导入Excel的方法
导入
前端
<form id="importform" class="form-horizontal form" action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="typeid" value="{$item['id']}"/>
<div class='form-group'>
<div class="form-group">
<label class="col-lg control-label must">EXCEL</label>
<div class="col-sm-5 goodsname" style="padding-right:0;" >
<input type="file" name="excelfile" class="form-control" />
<!-- <span class="help-block">如果遇到数据重复则将进行数据更新</span>-->
</div>
</div>
</div>
<div class='form-group'>
<div class="col-sm-12">
<div class="modal-footer" style="text-align: left">
<!-- {ifp 'order.batchsend.main'}-->
<button type="submit" class="btn btn-primary" name="cancelsend" value="yes">确认导入</button>
<!-- {/if}-->
<!-- {ifp 'order.batchsend.import'}-->
<!-- <a class="btn btn-primary" href="{php echo webUrl('order/batchsend/import')}" style="margin-right: 10px;" ><i class="fa fa-download" title=""></i> 下载Excel模板文件</a>-->
<!-- {/if}-->
</div>
</div>
</div>
<!--</div>-->
</form>
后端
if ($_W['ispost']) {
// 读取Excel
$rows = m('excel')->import('excelfile');
$num = count($rows);
$time = time();
$i = 0;
$err_array = array();
unset($rows[0]);
// 循环插入数据
foreach ($rows as $k=>$v){
var_dump($v);
$createData['uniacid'] = $_W['uniacid'];
$createData['name'] = $v[1];
$createData['work_number'] = $v[2];
$createData['serial_number'] = $v[0];
$createData['superior_id'] = 0;
pdo_insert('ewei_shop_team', $createData);
$superior_id = pdo_insertid();
$createData['uniacid'] = $_W['uniacid'];
$createData['name'] = $v[3];
$createData['work_number'] = $v[4];
$createData['serial_number'] = $v[0];
$createData['superior_id'] = $superior_id;
pdo_insert('ewei_shop_team', $createData);
$createData['uniacid'] = $_W['uniacid'];
$createData['name'] = $v[5];
$createData['work_number'] = $v[6];
$createData['serial_number'] = $v[0];
$createData['superior_id'] = $superior_id;
pdo_insert('ewei_shop_team', $createData);
}
}
导出
// 导出excel
if ($_GPC['export'] == 1) {
ca('statistics.goods.export');
$list[] = array('data' => '商品总计', 'count' => $total);
foreach ($list as &$row) {
$row['createtime'] = date('Y-m-d H:i', $row['createtime']);
}
unset($row);
// $list是每一行的数据
m('excel')->export($list, array(
'title' => '商品销售报告-' . date('Y-m-d-H-i', time()),
'columns' => array(
array('title' => '订单号', 'field' => 'ordersn', 'width' => 24),
array('title' => '商品名称', 'field' => 'title', 'width' => 48),
array('title' => '规格名称', 'field' => 'optiontitle', 'width' => 24),
array('title' => '商品编号', 'field' => 'goodssn', 'width' => 12),
array('title' => '数量', 'field' => 'total', 'width' => 12),
array('title' => '价格', 'field' => 'price', 'width' => 12),
array('title' => '成交时间', 'field' => 'createtime', 'width' => 24)
)
));
plog('statistics.goods.export', '导出商品销售明细');
}
评论 (0)