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.
151 lines
5.5 KiB
151 lines
5.5 KiB
<?php
|
|
|
|
require_once('./conn.php');
|
|
require 'vendor/autoload.php';
|
|
ini_set('date.timezone', 'Asia/Taipei');
|
|
|
|
$id = $_GET['id'];
|
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
|
if($id == 999){
|
|
$filePath = './option/facility.xlsx';
|
|
try {
|
|
$spreadsheet = IOFactory::load($filePath);
|
|
} catch (\PhpOffice\PhpSpreadsheet\Reader\Exception $e) {
|
|
die('Error loading file: ' . $e->getMessage());
|
|
}
|
|
// 獲取活動工作表
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
|
|
$status = "Y";
|
|
$create_at = date('Y-m-d H:i:s');
|
|
$sql_str = "INSERT INTO facility_price (kind, model, seat, numberofstop, speed, price, price_mi, status, create_dt)
|
|
VALUES (:kind, :model, :seat, :numberofstop, :speed, :price, :price_mi, :status, :create_at)";
|
|
// 遍歷工作表中的每一行
|
|
$inserttotal = 0;
|
|
foreach ($sheet->getRowIterator() as $key => $row) {
|
|
// 獲得單元格迭代器
|
|
$cellIterator = $row->getCellIterator();
|
|
$cellIterator->setIterateOnlyExistingCells(false); // This loops through all cells,
|
|
// even if a cell value is not set.
|
|
// By default, only cells that have a value set will be iterated.
|
|
foreach ($cellIterator as $idx => $cell) {
|
|
if ($cell !== null) {
|
|
// 打印單元格數據
|
|
// echo $cell->getValue() . '///';
|
|
}
|
|
if ($idx == 'A') {
|
|
$model = $cell->getValue();
|
|
$kind = explode("-", $model)[0];
|
|
$seat = explode("*", explode("-", $model)[1])[0];
|
|
$numberofstop = explode("*", explode("-", $model)[1])[1];
|
|
$spec = explode("-", $model)[2];
|
|
if(stripos($spec, "09")){
|
|
$speed = 9;
|
|
}elseif(stripos($spec, "24")){
|
|
$speed = 24;
|
|
$openfn = str_replace("24", "", $spec);
|
|
}elseif(stripos($spec, "45")){
|
|
$speed = 45;
|
|
$openfn = str_replace("45", "", $spec);
|
|
}elseif(stripos($spec, "60")){
|
|
$speed = 60;
|
|
$openfn = str_replace("60", "", $spec);
|
|
}elseif(stripos($spec, "90")){
|
|
$speed = 90;
|
|
$openfn = str_replace("90", "", $spec);
|
|
}elseif(stripos($spec, "105")){
|
|
$speed = 105;
|
|
$openfn = str_replace("105", "", $spec);
|
|
}elseif(stripos($spec, "120")){
|
|
$speed = 120;
|
|
$openfn = str_replace("120", "", $spec);
|
|
}elseif(stripos($spec, "150")){
|
|
$speed = 150;
|
|
$openfn = str_replace("150", "", $spec);
|
|
}elseif(stripos($spec, "180")){
|
|
$speed = 180;
|
|
$openfn = str_replace("180", "", $spec);
|
|
}
|
|
$speed = trim($speed);
|
|
$openfn = trim($openfn);
|
|
echo "種類:".$kind;
|
|
echo "規格:".$model;
|
|
echo "人乘:".$seat;
|
|
echo "停數".$numberofstop;
|
|
echo "速度:".$speed;
|
|
echo "開門方式:" . $openfn;
|
|
} elseif($idx == "B"){
|
|
$price = (float)$cell->getValue() *10000;
|
|
echo "價錢:".$price;
|
|
}elseif($idx == "C"){
|
|
$add = (float)$cell->getValue() *10000;
|
|
echo "+-1停:".$add;
|
|
}elseif($idx == "D"){
|
|
$min_stop = $cell->getValue();
|
|
echo "最低停數:".$min_stop;
|
|
}
|
|
}
|
|
echo "-------><br>";
|
|
try{
|
|
for($i=2;$i<$numberofstop;$i++){
|
|
$stop = ($i <= $min_stop) ? $min_stop : $i;
|
|
echo $kind . "-" . $seat . "*" . $i . "-" . $openfn . $speed;
|
|
$new_model = $kind . "-" . $seat . "*" . $i . "-" . $openfn . $speed;
|
|
$calc_price = $price + $add * ($stop-$numberofstop);
|
|
echo "價錢:" . $calc_price;
|
|
//kind, :model, :seat, :numberofstop, :speed, :price, :price_mi, :status, :create_at
|
|
$stmt = $conn->prepare($sql_str);
|
|
$stmt->bindParam(':kind', $kind);
|
|
$stmt->bindParam(':model', $new_model);
|
|
$stmt->bindParam(':seat', $seat);
|
|
$stmt->bindParam(':numberofstop', $i);
|
|
$stmt->bindParam(':speed', $speed);
|
|
$stmt->bindParam(':price', $calc_price);
|
|
$stmt->bindParam(':price_mi', $calc_price);
|
|
$stmt->bindParam(':status', $status);
|
|
$stmt->bindParam(':create_at', $create_at);
|
|
|
|
$stmt->execute();
|
|
$inserttotal++;
|
|
echo "OK";
|
|
echo "<br>";
|
|
}
|
|
for($i=$numberofstop;$i<=30;$i++){
|
|
$stop = ($i <= $min_stop) ? $min_stop : $i;
|
|
$new_model = $kind . "-" . $seat . "*" . $i . "-" . $openfn . $speed;
|
|
echo $new_model;
|
|
$calc_price = $price + $add * ($stop-$numberofstop);
|
|
echo "價錢:" . $calc_price;
|
|
|
|
$stmt = $conn->prepare($sql_str);
|
|
$stmt->bindParam(':kind', $kind);
|
|
$stmt->bindParam(':model', $new_model);
|
|
$stmt->bindParam(':seat', $seat);
|
|
$stmt->bindParam(':numberofstop', $i);
|
|
$stmt->bindParam(':speed', $speed);
|
|
$stmt->bindParam(':price', $calc_price);
|
|
$stmt->bindParam(':price_mi', $calc_price);
|
|
$stmt->bindParam(':status', $status);
|
|
$stmt->bindParam(':create_at', $create_at);
|
|
|
|
$stmt->execute();
|
|
$inserttotal++;
|
|
echo "OK";
|
|
echo "<br>";
|
|
}
|
|
}
|
|
catch (PDOException $e) {
|
|
echo $e->getMessage();
|
|
die('Error!:' . $e->getMessage());
|
|
}
|
|
|
|
echo "<br>"; // 換行,以分隔不同的行
|
|
|
|
|
|
}
|
|
echo $inserttotal;
|
|
|
|
}
|
|
|
|
|