作者 董瑞恩
1 个管道 的构建 通过 耗费 1 秒

cost

... ... @@ -11,6 +11,7 @@ namespace app\portal\controller;
use app\portal\model\EquipmentModel;
use cmf\controller\AdminBaseController;
use PHPExcel_IOFactory;
use QRcode;
use think\Db;
... ... @@ -61,7 +62,53 @@ class AdminEquipmentController extends AdminBaseController{
}
public function batch_addPost(){
//上传excel文件
$file = $this->request->file('myfile');
//移到/public/uploads/excel/下
$info = $file->move(ROOT_PATH.'public'.DS.'upload'.DS.'excel');
//上传文件成功
if($info) {
//引入PHPExcel类
vendor('VENDOR_PATH/phpoffice/phpexcel/Classes/PHPExcel.php');
vendor('VENDOR_PATH/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php');
//获取上传后的文件名
$fileName = $info->getSaveName();
//文件路径
$filePath = ROOT_PATH.'public/upload/excel/'.$fileName;
//实例化PHPExcel类
//使用 PHPExcel_IOFactory 来鉴别文件应该使用哪一个读取类
$inputFileType = PHPExcel_IOFactory::identify($filePath);
//实例化类
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
//$PHPReader = new \PHPExcel_Reader_Excel2007();
//读取excel文件
$objPHPExcel = $objReader->load($filePath);
//读取excel文件中的第一个工作表
$sheet = $objPHPExcel->getSheet(0);
$allRow = $sheet->getHighestRow(); //取得总行数
// $testInfo=new TestinfoModel();
//从第二行开始插入,第一行是列名
for ($j = 2; $j <= $allRow; $j++) {
$data=[
'serial_number'=> $objPHPExcel->getActiveSheet()->getCell("a" . $j)->getValue(),
'mac_address' => $objPHPExcel->getActiveSheet()->getCell("b" . $j)->getValue(),
'name' => $objPHPExcel->getActiveSheet()->getCell("c" . $j)->getValue(),
'hospital' => $objPHPExcel->getActiveSheet()->getCell("d" . $j)->getValue(),
'note' => $objPHPExcel->getActiveSheet()->getCell("e" . $j)->getValue(),
'create_time' => time()
];
$data['qr_code'] = $this->createQrCode($data['mac_address']);
$Equipment=new EquipmentModel();
try{
$Equipment->save($data);
echo "第" . $j . "行数据导入成功!<br/>";
}catch (\Exception $exception){
echo "第" . $j . "行数据导入失败!错误信息:".$exception->getMessage()."<br/>";
}
}
}else{
echo "上传文件失败!";
}
}
... ...
<include file="public@header"/>
<style type="text/css">
.pic-list li {
margin-bottom: 5px;
}
</style>
<script type="text/html" id="photos-item-tpl">
<li id="saved-image{id}">
<input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
<input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
style="width: 200px;" title="图片名称">
<img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
onclick="imagePreviewDialog(this.src);">
<a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
<a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
</li>
</script>
<script type="text/html" id="files-item-tpl">
<li id="saved-file{id}">
<input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
<input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
style="width: 200px;" title="文件名称">
<a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
<a href="javascript:uploadOne('图片上传','#file-{id}','file');">替换</a>
<a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
</li>
</script>
</head>
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li><a href="{:url('AdminTestInfo/index')}">检测报告</a></li>
<li class="active"><a href="{:url('AdminTestInfo/add')}">添加报告</a></li>
</ul>
<!--js-ajax-form margin-top-20-->
<form action="{:url('AdminTestInfo/addPost')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<table class="table table-bordered">
<tr>
<th width="80">设备锁编号<span class="form-required">*</span></th>
<td>
<input class="form-control" type="text" name="serial_number"
id="serial_number" required value="" placeholder="请输入设备锁编号"/>
</td>
</tr>
</table>
</div>
</div>
</form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
function confirm() {
var serial_number = $('#serial_number').val();
var mac_address = $('#mac_address').val();
var name = $('#name').val();
var hospital = $('#hospital').val();
var note = $('#note').val();
var create_time = $('#create_time').val();
return {
serial_number:serial_number,
mac_address :mac_address,
name :name,
hospital :hospital,
note :note,
create_time :create_time
};
}
</script>
</body>
</html>
\ No newline at end of file
... ...
... ... @@ -30,7 +30,7 @@
onclick="doAdd()">新增
</button>
<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
onclick="doAdd()">批量新增
onclick="batch_add()">批量新增
</button>
<button class="btn btn-primary btn-sm js-ajax-submit" type="submit"
data-action="{:url('AdminEquipment/publish',array('yes'=>1))}" data-subcheck="true">批量导出
... ... @@ -153,6 +153,39 @@
});
}
function batch_add() {
openIframeLayer("{:url('AdminEquipment/batch_add')}", '请选择分类', {
area: ['1000px', '800px'],
btn: ['确定', '取消'],
yes: function (index, layero) {
var iframeWin = window[layero.find('iframe')[0]['name']];
var data = iframeWin.confirm();
// $.ajax({
// url:"{:url('AdminEquipment/addPost')}",
// type:"POST",
// data:{
// serial_number:data.serial_number,
// mac_address:data.mac_address,
// name:data.name,
// hospital:data.hospital,
// note:data.note,
// create_time:data.create_time
// },
// dataType:"JSON",
// success:function (data) {
// if (data.code===200){
// alert('添加成功');
// window.location.reload();
// }
// },
// error:function () {
// alert('接口异常')
// }
// });
layer.close(index); //如果设定了yes回调,需进行手工关闭
}
});
}
function reloadPage(win) {
... ...