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.
 
 
 
 
 
 

171 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;
// 指定要讀取的 Excel 文件
$filePath = './option/option'.$id.'.xlsx';
// 嘗試讀取文件
try {
$spreadsheet = IOFactory::load($filePath);
} catch (\PhpOffice\PhpSpreadsheet\Reader\Exception $e) {
die('Error loading file: ' . $e->getMessage());
}
// 獲取活動工作表
$sheet = $spreadsheet->getActiveSheet();
$create_at = date('Y-m-d H:i:s');
$sql_str = "INSERT INTO option_price (kind, subkind, group_name, spec, memo, optional, unit, price, status, create_at) VALUES (:kind, :subkind, :group_name, :spec, :memo, :optional, :unit, :price, :status, :create_at)";
$sql_str_mi = "INSERT INTO option_mi (option_price_id, min_weight, max_weight, open_kind, base_floor, base_floor_plus, price, quotation_no, create_at) VALUES (:option_price_id, :min_weight, :max_weight, :open_kind, :base_floor, :base_floor_plus, :price, :quotation_no, :create_at)";
$open_kind_arr = ['CO', '2S'];
// 遍歷工作表中的每一行
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 == 'B'){
$group_name = $cell->getValue();
echo $group_name;
}elseif($idx == 'C'){
$spec = $cell->getValue();
echo $spec;
}elseif($idx == 'D'){
$memo = $cell->getValue();
echo $memo;
}elseif($idx == 'E'){
if($cell->getValue() == "標配"){
$optional = 1;
}else{
$optional = 2;
}
echo $optional;
}elseif($idx == 'F'){
$cost = $cell->getValue();
}
elseif($idx == 'G'){
$price = $cell->getValue();
echo $price;
}elseif($idx == 'H'){
$unit = $cell->getValue();
echo $unit;
}
}
echo "<br>"; // 換行,以分隔不同的行
$status = "Y";
$kindArr = ['A', 'B','C', 'D'];
if($id == 1){
$kind = 'A';
$subkind = 'A1';
}elseif($id == 2){
$kind = 'B';
$subkind = 'B1';
}elseif($id == 3){
$kind = 'B';
$subkind = 'B2';
}elseif($id == 4){
$kind ='B';
$subkind = 'B3';
}elseif($id == 5){
$kind ='B';
$subkind = 'B4';
}elseif($id == 6){
$kind ='B';
$subkind = 'B5';
}elseif($id == 7){
$kind ='B';
$subkind = 'B6';
}elseif($id == 8){
$kind ='B';
$subkind = 'B7';
}elseif($id == 9){
$kind ='C';
$subkind = 'C1';
}elseif($id == 10){
$kind ='C';
$subkind = 'C2';
}elseif($id == 11){
$kind ='C';
$subkind = 'C3';
}elseif($id == 12){
$kind ='C';
$subkind = 'C4';
}elseif($id == 13){
$kind ='D';
$subkind = 'D1';
}elseif($id == 14){
$kind ='D';
$subkind = 'D2';
}elseif($id == 15){
$kind ='E';
$subkind = 'E1';
}elseif($id == 16){
$kind ='F';
$subkind = 'F1';
}
if(isset($_GET['id'])){
try{
$stmt = $conn -> prepare($sql_str);
$stmt ->bindParam(':kind', $kind);
$stmt ->bindParam(':subkind', $subkind);
$stmt ->bindParam(':group_name', $group_name);
$stmt ->bindParam(':spec', $spec);
$stmt ->bindParam(':memo', $memo);
$stmt ->bindParam(':optional', $optional);
$stmt ->bindParam(':unit', $unit);
$stmt ->bindParam(':price', $price);
$stmt ->bindParam(':status', $status);
$stmt ->bindParam(':create_at', $create_at);
// 遍歷當前行的每一個單元格
$stmt ->execute();
$last_id = $conn->lastInsertId();
$option_price_id = $last_id;
$option_price = $cost;
$quotation_no = 'Q2311001';
foreach($open_kind_arr as $kind){
$min_weight = 1;
$max_weight = 1600;
$open_kind = $kind;
$base_floor = 0;
$base_floor_plus = 0;
$sale_price = $option_price;
$stmt = $conn -> prepare($sql_str_mi);
$stmt ->bindParam(':option_price_id', $option_price_id);
$stmt ->bindParam(':min_weight', $min_weight);
$stmt ->bindParam(':max_weight', $max_weight);
$stmt ->bindParam(':open_kind', $open_kind);
$stmt ->bindParam(':base_floor', $base_floor);
$stmt ->bindParam(':base_floor_plus', $base_floor_plus);
$stmt ->bindParam(':price', $sale_price);
$stmt ->bindParam(':quotation_no', $quotation_no);
$stmt ->bindParam(':create_at', $create_at);
$stmt ->execute();
}
}catch(PDOException $e){
echo $e->getMessage();
die('Error!:'.$e->getMessage());
}
}
}
?>