You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
7.3 KiB
115 lines
7.3 KiB
<?php
|
|
// 载入db.php来连结资料库
|
|
require_once "database.php";
|
|
include "header.php";
|
|
require_once 'PHPExcel/PHPExcel.php';
|
|
require_once 'PHPExcel/IOFactory.php';
|
|
$file_name = $_FILES["fileToUpload"]["name"];
|
|
$temp_file_name = $_FILES["fileToUpload"]["tmp_name"];
|
|
$target_dir = "expert-uploads/";
|
|
$target_file = strtolower($target_dir . iconv("UTF-8", "gbk", basename($file_name)));
|
|
$EXTENSION = pathinfo($target_file, PATHINFO_EXTENSION);
|
|
if (move_uploaded_file($temp_file_name, $target_file)) {
|
|
if ($EXTENSION == 'xls') {
|
|
$objReader = PHPExcel_IOFactory::createReader('Excel5');//支持xls
|
|
} else {
|
|
$objReader = PHPExcel_IOFactory::createReader('Excel2007');//支持xlsx
|
|
}
|
|
$objPHPExcel = $objReader->load($target_file); //读取上传到服务器的文件
|
|
$sheet = $objPHPExcel->getSheet(0);//拿到第一个sheet数据
|
|
$highestRow = $sheet->getHighestRow(); // 取得总行数
|
|
$highestColumn = $sheet->getHighestColumn(); // 取得总列数
|
|
$highestColumn = PHPExcel_Cell::columnIndexFromString($highestColumn); // 转换字母为对应的统计数字;
|
|
$excelArray = array();
|
|
for ($row = 2; $row <= $highestRow; $row++) {
|
|
$val = $sheet->getCellByColumnAndRow(0, $row)->getCalculatedValue();
|
|
|
|
if ($val == "") return;
|
|
for ($column = 1; $column < $highestColumn; $column++) {
|
|
$val = $sheet->getCellByColumnAndRow($column, $row)->getCalculatedValue();
|
|
$excelArray[$row][] = $val; //读取excel数据到数组
|
|
}
|
|
|
|
$facilityno = $excelArray[$row][1]; //作番id
|
|
$facilitsql = "SELECT * FROM facility where facilityno='$facilityno'";
|
|
$facilit_nums_rows = mysqli_num_rows(mysqli_query($link, $facilitsql));
|
|
if ($facilit_nums_rows == 0) {
|
|
echo $row;
|
|
$contractno = $excelArray[$row][0]?:'null'; //合约号
|
|
$facilityno = $excelArray[$row][1]?:'null'; //作番号
|
|
$address = $excelArray[$row][2]?:'null'; //作番安装地址
|
|
$longitude = $excelArray[$row][3]?:'null';//纬度
|
|
$latitude = $excelArray[$row][4]?:'null';//经度
|
|
$customerid = $excelArray[$row][5]?:'null'; //客户/业主名称
|
|
$customercode = $excelArray[$row][6]?:'null'; //业主ID或统一信用代码
|
|
$customerlinknumber = $excelArray[$row][7]?:'null'; //业主联络电话或手机
|
|
$repairerid = $excelArray[$row][8]?:'null'; //保养员工号
|
|
$repairername = $excelArray[$row][9]?:'null'; //保养员姓名
|
|
$repairerphonenumber = $excelArray[$row][10]?:'null'; //保养员手机号
|
|
$baoyangdate= $excelArray[$row][11]?:'null'; //保养日期
|
|
$maintainance= $excelArray[$row][12]?:'null'; //保养计划类别.保養別\r\nA=全包\r\nB=半包\r\nC=清包\r\nD=半包:2個月保養一次
|
|
$yingshoukuandate= $excelArray[$row][13]?:'null'; //应收款日期
|
|
$contractstartdate= $excelArray[$row][14]?:'null'; //合约起始年月日
|
|
$contractenddate= $excelArray[$row][15]?:'null'; //合约终止年月日
|
|
$facilitychuchangno= $excelArray[$row][16]?:'null'; //原作番出厂编号
|
|
$contractpersonid= $excelArray[$row][17]?:'null'; //契约人员工号
|
|
$contractpersonname= $excelArray[$row][18]?:'null'; //契约人员姓名
|
|
$weight= $excelArray[$row][19]?:'null'; //载重/输送能力
|
|
$numberoffloor= $excelArray[$row][20]?:'null'; //层站,停数/提升高度
|
|
$speed= $excelArray[$row][21]?:'null'; //速度
|
|
$brand= $excelArray[$row][22]?:'null'; //品牌,型号
|
|
$officialregistrationcode= $excelArray[$row][13]?:'null'; //官方注册代码
|
|
$manufacturedate= $excelArray[$row][24]?:'null'; //制造日期
|
|
$creater = "batch";
|
|
$create_at = date('Y/m/d H:i:s');
|
|
//无效字段
|
|
$numberofstop='0';
|
|
$opentype='0';
|
|
$repairtype='0';
|
|
echo $db_query1 = "INSERT INTO facility(contractno, facilityno, customerid, weight,numberofstop, numberoffloor,opentype,speed,repairtype,longitude, latitude, address,repairerid,repairername,creater, create_at) VALUES ('$contractno', '$facilityno', '$customerid', '$weight','$numberofstop', '$numberoffloor','$opentype','$speed','$repairtype','$longitude', '$latitude', '$address','$repairerid','$repairername','$creater', '$create_at')";
|
|
|
|
mysqli_query($link, $db_query1);
|
|
if (mysqli_affected_rows($link) > 0) {
|
|
echo "作番新增成功\n";
|
|
//添加作番拓展字段
|
|
$facilityid=mysqli_insert_id($link);
|
|
$db_query2 = "INSERT INTO facility_extends(facilityid,facilitychuchangno,contractpersonid,contractpersonname,brand,officialregistrationcode,manufacturedate,creater, create_at) VALUES (";
|
|
$db_query2.=" '$facilityid', '$facilitychuchangno','$contractpersonid','$contractpersonname','$brand','$officialregistrationcode','$manufacturedate','$creater', '$create_at')";
|
|
|
|
|
|
mysqli_query($link, $db_query2);
|
|
if (mysqli_affected_rows($link) > 0) {
|
|
echo '扩展添加成功';
|
|
}
|
|
|
|
} elseif (mysqli_affected_rows($link) == 0) {
|
|
echo "无新增资料";
|
|
}
|
|
} else {
|
|
echo "作番已经存在";
|
|
echo $facilityno;
|
|
}
|
|
|
|
//print_r($excelArray);
|
|
}
|
|
mysqli_close($link);
|
|
}
|
|
|
|
?>
|
|
<div class="container">
|
|
<form class="form-inline" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"
|
|
enctype="multipart/form-data">
|
|
|
|
<div class="bottom-margin">资料
|
|
<label for="fileToUpload">上传</label>
|
|
<div>
|
|
<input type="file" name="fileToUpload" id="fileToUpload">
|
|
</div>
|
|
<div class="bottom-margin">
|
|
<button type="submit" name="submit">确定</button>
|
|
</div>
|
|
</div>
|
|
|
|
</form>
|
|
</div>
|
|
|
|
|