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.
 
 
 
 
 
 

244 lines
12 KiB

<?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 = "excel-uploads/";
$target_file = strtolower($target_dir . iconv("UTF-8", "big5",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数据到数组
}
/*
(
[2] => Array
(
[0] => M230875
[1] => 3TX23001
[2] => 桃園市中壢區榮民南路81巷8號
[3] => 121.25820796563
[4] => 24.955059621474
[5] => 梁智芳
[6] =>
[7] => 921389826
[8] => M0089
[9] => 郭玠德
[10] => 0905-378-991
[11] => 2023/07/14
[12] => BW002
[13] =>
[14] => 45108
[15] => 45473
[16] =>
)
)*/
//print_r($excelArray);exit;
echo "".$row;
// excel欄位名稱
list($contractno, $facilityno, $address, $longitude, $latitude, $name, $customerid, $tel, $repairerid, $repairer_name, $repairer_tel, $duedate, $combono, $receivable_date, $c_start_date, $c_end_date) = $excelArray[$row];
$customerid = (!$customerid) ? $contractno : $customerid;
$repairer_tel = str_pad(str_replace("-", "", $repairer_tel), 10, "0", STR_PAD_LEFT); // 保養員手机号
$combono = substr($combono,-5);//套餐编码
$area = mb_substr($address, 0, 3);
if (is_numeric($duedate)) $duedate = date("Y-m-d", ($duedate-25569)*24*60*60); // 預保養日
if (is_numeric($c_start_date)) $c_start_date = date("Y-m-d", ($c_start_date-25569)*24*60*60); // 合約起始日
if (is_numeric($c_end_date)) $c_end_date = date("Y-m-d", ($c_end_date-25569)*24*60*60); // 合約終止日
// 创建客户信息
$accountid= $contractno; //账户id
//判断账户是否存在
$sql = "select * from account where accountid = '$accountid'";
$data = mysqli_query($link,$sql);
$nums_rows = mysqli_num_rows($data);
if($nums_rows==0){
//添加用户
$accounttype = "A"; //账户类型
$pwd = "123";//账户默认密码
//查询保养员电话
$sqlfre = "SELECT name, tel FROM account where accountid = '$repairerid' and accounttype = 'B'";
$repairerdata = mysqli_query($link, $sqlfre); # 用mysqli_query方法执行(sql语法)将结果存在变数中
if ($rowdata = mysqli_fetch_assoc($repairerdata)) {
$db_repair_name = $rowdata['name'];
$db_repair_tel = $rowdata['tel'];
}
mysqli_free_result($repairerdata);
if ($db_repair_name == $repairer_name && (str_pad(str_replace("-", "", $db_repair_tel), 10, "0", STR_PAD_LEFT)) == $repairer_tel) {
$create_at = date('Y/m/d H:i:s');//账户创建时间
$db_query1 = "insert into account(accounttype, accountid, pwd, name, tel, address,phone_call_help, repairerid, creater, create_at) values (";
$db_query1 .= "'$accounttype', '$accountid', '$pwd', '$name', '$tel', '$address', '$repairer_tel', '$repairerid','$user_id', '$create_at')";
mysqli_query($link,$db_query1);
if (mysqli_affected_rows($link) > 0) {
echo "客户账户新增成功\r\n";
$repair_right = 1;
}
elseif(mysqli_affected_rows($link)==0) {
echo "无新增资料";
}
} else {
echo "保養員姓名或電話有誤";
}
} else {
echo "账户已经存在";
$repair_right = 1;
}
if ($repair_right) {
//创建合约信息
//判断合约是否存在
$contractsql = "select * from contract where contractno = '$contractno'";
$contract_nums_rows=mysqli_num_rows(mysqli_query($link,$contractsql));
if($contract_nums_rows==0){
$contracttype= "A";
$company= $name;//公司名称默认客户姓名
$taxid= " ";//统一编码
$promiser= $name;//契约人,个人客户默认客户姓名
$contractperson= $name;//联系人
$contractaddress= $address;//联系地址
$contracttel= $tel;//联络电话
$contractemail= "";
$contract_employee= "";//契约员工号
$create_at = date('Y/m/d H:i:s');//合同创建时间
$db_query2 = "INSERT INTO contract(contracttype, contractno, company, taxid, address, tel, promiser, customerid, contractperson, contractaddress, contracttel, contractemail,contract_employee,start_date,end_date, creater, create_at) VALUES ('$contracttype', '$contractno', '$company', '$taxid', '$address', '$tel', '$promiser', '$customerid', '$contractperson', '$contractaddress', '$contracttel', '$contractemail','$contract_employee','$c_start_date','$c_end_date', '$user_id', '$create_at')";
mysqli_query($link,$db_query2);
if (mysqli_affected_rows($link)>0) {
echo "合约新增成功\r\n";
}
elseif(mysqli_affected_rows($link)==0) {
echo "无新增资料";
}
}else{
echo "合约已经存在";
}
//创建作番信息
switch ($facilityno) {
case (preg_match('/TX/', $facilityno) ? true : false):
case (preg_match('/JX/', $facilityno) ? true : false):
$facility_kind = "MAE100";
break;
case (preg_match('/TW/', $facilityno) ? true : false):
$facility_kind = "MAM200";
break;
case (preg_match('/TH/', $facilityno) ? true : false):
$facility_kind = "MAH100";
break;
case (preg_match('/TZ/', $facilityno) ? true : false):
$facility_kind = "MAZ100";
break;
case (preg_match('/TH/', $facilityno) ? true : false):
$facility_kind = "MAQ100";
break;
default:
$facility_kind = "";
}
$facilitsql = "SELECT * FROM facility where facilityno='$facilityno' and contractno='$contractno'";
$facilit_nums_rows=mysqli_num_rows(mysqli_query($link,$facilitsql));
if($facilit_nums_rows==0){
$weight= "450";//重量
$numberofpassenger = "6"; // 人乘
$numberofstop= "2";//停数
$numberoffloor= "2";//楼层数
$opentype= "CO-SO";//开门方式
$speed= "60";//速度
$repairtype= "A";//维护类型
$create_at = date('Y/m/d H:i:s');//作番创建时间
$db_query3 = "INSERT INTO facility(contractno, facilityno, customerid, weight,numberofpassenger,numberofstop, numberoffloor,opentype,speed,repairtype,facility_kind,longitude, latitude, address,repairerid,repairername,area,creater, create_at) VALUES ('$contractno', '$facilityno', '$customerid', '$weight','$numberofpassenger','$numberofstop', '$numberoffloor','$opentype','$speed','$repairtype','$facility_kind','$longitude', '$latitude', '$address','$repairerid','$repairer_name','$area','$user_id', '$create_at')";
mysqli_query($link,$db_query3);
if (mysqli_affected_rows($link)>0) {
echo "作番新增成功\n";
}
elseif(mysqli_affected_rows($link)==0) {
echo "无新增资料";
}
}else{
echo "作番已经存在";
}
//创建保养计划
echo "保养日期";
$schedulesql = "SELECT * FROM schedule where facilityno='$facilityno' and duedate='$duedate'";
$schedule_nums_rows=mysqli_num_rows(mysqli_query($link,$schedulesql));
if($schedule_nums_rows==0){
$create_at = date('Y/m/d H:i:s');//作番创建时间
$db_query4 = "INSERT INTO schedule(contractno, facilityno, combono, repairerid, repairername, duedate, creater, create_at) VALUES ('$contractno', '$facilityno', '$combono', '$repairerid', '$repairer_name', '$duedate', '$user_id', '$create_at')";
$resiult=mysqli_query($link,$db_query4);
if (mysqli_affected_rows($link)>0) {
echo $combono."作番保养计划新增成功\r\n";
}
elseif(mysqli_affected_rows($link)==0) {
echo "无新增资料";
}
}else{
echo "作番保养计划已经存在";
}
}
}
mysqli_close($link);
}
//for ($i = 0; $i <= sizeof($excelArray); $i++) {
// //处理数据
//// 创建客户信息
// echo "循环读取数据插入数据库---".$row."---";
// echo$accounttype= "A"; //账户类型
// echo$accountid= $excelArray[$row][6]; //账户id
// echo$pwd= "123";//账户默认密码
// echo$name= $excelArray[$row][5];//账户姓名
// echo$address= $excelArray[$row][2];//账户地址
// echo$phone_call_help=$excelArray[$row][7];//联络手机号
// echo$repairerid=$excelArray[$row][8];//服务与支持人员工号
// echo$creater = 'vensen';//建档人
// echo$create_at = date('Y/m/d H:i:s');//账户创建时间
////判断账户是否存在
// $sqlselect='select * from account where accountid='.$accountid;
// $res = mysqli_query($link,$sqlselect);
// echo "------结果".'<br>';
// print_r($res);
//
// echo "------".'<br>';
//}
//
// var_dump($excelArray);
?>
<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>
<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>
<input type="hidden" name="token" value="<?php echo $_GET['token']; ?>">
</form>
</div>