Commit 259b3c43 authored by 蔡闯's avatar 蔡闯

20201-1-7

parent 719da6bc
......@@ -359,8 +359,6 @@ class Common extends BaseController
//用户导入
public static function importTenant($filePath,$village_id) {
$where['village_id'] = $village_id;
$objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容
$objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件
......@@ -370,11 +368,12 @@ class Common extends BaseController
$errorData =[]; //存放导入失败的数据;
$insertData = [];
$layout_list = Db::name('layout_list')->where($where)->column('layout_id','code');
$layoutList = Db::name('layout_list');
for($i=1;$i<$highestRow;$i++) {
$msg="";
$name = $dataAll[$i][0];
if(is_null($name)){
continue;
}
$phone = $dataAll[$i][1];
if(!isPhoneNo($phone)){
$msg.="手机号不正确!";
......@@ -387,13 +386,13 @@ class Common extends BaseController
if($layout_list_code) {
$layout_id = $layout_list[$layout_list_code];
} else {
$msg .="社区布局未选择!";
$msg.="社区布局未选择!";
}
$vacancyCode = $dataAll[$i][3];
//验证房间编号是否存在,是否合理
$res_vacancy_code = self::getVacancyCode($vacancyCode,$layout_id);
if($res_vacancy_code['code'] !=200) {
$msg .= "房间编号不正确!";
$msg.= "房间编号不正确!";
}
$where['vacancy_code'] = $res_vacancy_code['msg'];
$vacancy_id = Db::name('house_vacancy')->where($where)->value('vacancy_id');
......@@ -418,16 +417,13 @@ class Common extends BaseController
$msg.='该房间已绑定业主,请在解绑!';
}
}
$data['vacancy_id'] = $vacancy_id;
$data['village_id'] = $village_id;
$data['id_card'] = $id_card;
$data['name'] = $name;
$data['phone'] = $phone;
$data['type'] = $type;
if($type==1) {
$data['relatives_type'] =1; //默认
}
$data['relatives_type'] =1; //默认
$data['create_time'] = $data['pass_time'] = time();
$data['status'] =1;
if(empty($msg)){
......@@ -437,59 +433,55 @@ class Common extends BaseController
$errorData[] = $dataAll[$i];
}
}
//导入对的数据
if(!empty($insertData)){
Db::name('house_user_bind')->insertAll($insertData);
if($errorData){
//导出错误的数据
$file = "./formwork/importTenant.xls";
$phpExcel = \PHPExcel_IOFactory::load($file);
$title = ['A','B','C','D','E','F','G'];
$i = 2;
$optionsArr = $layoutList->where(['village_id'=>$village_id])->column('code');
$optionsString = implode(',',$optionsArr);//这个是选择布局
foreach ($errorData as $k =>$v) {
foreach ($title as $key=>$value) {
$phpExcel->getActiveSheet()->setCellValue($value.$i,$v[$key]);
}
//设置单元楼下拉
$phpExcel->getActiveSheet()->getCell('F'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
-> setAllowBlank(false)
-> setShowInputMessage(true)
-> setShowErrorMessage(true)
-> setShowDropDown(true)
-> setErrorTitle('输入的值有误')
-> setError('您输入的值不在下拉框列表内.')
-> setPromptTitle('社区布局')
-> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格
$phpExcel->getActiveSheet()->getCell('E'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
-> setAllowBlank(false)
-> setShowInputMessage(true)
-> setShowErrorMessage(true)
-> setShowDropDown(true)
-> setErrorTitle('输入的值有误')
-> setError('您输入的值不在下拉框列表内.')
-> setPromptTitle('房屋类型')
-> setFormula1('"租客,业主,家属"'); //这一句为要设置数据有效性的单元格
$i++;
}
//如果有错误的数据,导出
if($errorData){
//导出错误的数据
$file = "./formwork/importTenant.xls";
$phpExcel = \PHPExcel_IOFactory::load($file);
$title = ['A','B','C','D','E','F','G'];
$i = 2;
$optionsArr = Db::name('layout_list')->where(['village_id'=>$village_id])->column('code');
$optionsString = implode(',',$optionsArr);//这个是选择布局
foreach ($errorData as $k =>$v) {
foreach ($title as $key=>$value) {
$phpExcel->getActiveSheet()->setCellValue($value.$i,$v[$key]);
}
$objWriter = new \PHPExcel_Writer_Excel5($phpExcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="用户导入失败数据.xls"');
header('Cache-Control: max-age=0');
$objWriter->save("php://output");
//设置单元楼下拉
$phpExcel->getActiveSheet()->getCell('F'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
-> setAllowBlank(false)
-> setShowInputMessage(true)
-> setShowErrorMessage(true)
-> setShowDropDown(true)
-> setErrorTitle('输入的值有误')
-> setError('您输入的值不在下拉框列表内.')
-> setPromptTitle('社区布局')
-> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格
$phpExcel->getActiveSheet()->getCell('E'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
-> setAllowBlank(false)
-> setShowInputMessage(true)
-> setShowErrorMessage(true)
-> setShowDropDown(true)
-> setErrorTitle('输入的值有误')
-> setError('您输入的值不在下拉框列表内.')
-> setPromptTitle('房屋类型')
-> setFormula1('"租客,业主,家属"'); //这一句为要设置数据有效性的单元格
} else {
return ['code'=>200,'data'=>[]];
$i++;
}
$objWriter = new \PHPExcel_Writer_Excel5($phpExcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="用户导入失败数据.xls"');
header('Cache-Control: max-age=0');
$objWriter->save("php://output");
} else {
return ['code'=>200,'data'=>[]];
}
}
//车辆导入
......@@ -514,6 +506,7 @@ class Common extends BaseController
$license_plate = $dataAll[$i][2];
$car_color = $dataAll[$i][3];
$brand = $dataAll[$i][4];
$car_type = $dataAll[$i][5];
$data['name'] = $name;
$data['phone'] = $phone;
$data['license_plate'] = $license_plate;
......@@ -521,6 +514,7 @@ class Common extends BaseController
$data['create_time'] = time();
$data['village_id'] = $village_id;
$data['brand'] = $brand;
$data['car_type'] = $car_type;
if(empty($msg)){
$insertData[] = $data;
} else {
......@@ -535,7 +529,7 @@ class Common extends BaseController
//导出错误的数据
$file = "./formwork/importCar.xls";
$phpExcel = \PHPExcel_IOFactory::load($file);
$title = ['A','B','C','D','E','F'];
$title = ['A','B','C','D','E','F','G'];
$i = 2;
$optionsArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('name');
$optionsString = implode(',',$optionsArr);//这个是的车库
......
......@@ -33,8 +33,6 @@ class Base extends BaseController
}
......
......@@ -220,6 +220,7 @@ class Parking extends Base
$data['brand'] = Request::param('brand');
$data['car_color'] = Request::param('car_color');
$data['brand'] = Request::param('brand');
$data['car_type'] = Request::param('car_type');
$data['license_plate'] = Request::param('license_plate');
$data['sort_id'] = Request::param('sort_id',1);
if($car_id) {
......
......@@ -233,7 +233,6 @@ class Userbind extends Base
//用户批量导入数据
public function importTenant() {
$filePath = Request::param('filePath');
if(!file_exists($filePath)){
return $this->returnJson([],'文件不存在!',400);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment