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.
180 lines
4.6 KiB
180 lines
4.6 KiB
<?php
|
|
require_once('DAO.php');
|
|
|
|
class ProductDAO extends DAO {
|
|
private $prodTable = 'product';
|
|
private $accessoryTable = 'product_accessory'; //小電梯配件 table
|
|
|
|
function __construct() {
|
|
$this->pdo = new DB_Access(ENUM::DBLocate, ENUM::DBName, ENUM::DBUser, ENUM::DBPassword);
|
|
}
|
|
|
|
/**
|
|
* 取得第 N 層的資料
|
|
*
|
|
* @param int $level 第幾層
|
|
* @param int $firstLevel 第一層的 id
|
|
* @return array
|
|
*/
|
|
function getLevelList($level, $firstLevel){
|
|
$sqlStr = " SELECT uuid, level, title FROM ".$this->prodTable." WHERE level = :level AND first_level_id = :first; ";
|
|
return $this->pdo->execute($sqlStr, array('level'=>$level, 'first'=>$firstLevel));
|
|
}
|
|
|
|
/**
|
|
* 依第幾層和 title 取得資料
|
|
*
|
|
* @param int $level 第幾層
|
|
* @param int $title 標題
|
|
* @param int $firstLevel 第一層的 id
|
|
* @return array
|
|
*/
|
|
function getLevelDataByName($level, $title, $firstLevel){
|
|
$sqlStr = " SELECT uuid, level, title FROM ".$this->prodTable." WHERE level = :level AND title = :title AND first_level_id = :first; ";
|
|
return $this->pdo->execute($sqlStr, array('level'=>$level,'title'=>$title, 'first'=>$firstLevel));
|
|
}
|
|
|
|
/**
|
|
* 取得產品資料
|
|
*
|
|
* @param int $dataId
|
|
* @return array
|
|
*/
|
|
function getProdContent($dataId){
|
|
$sqlStr = " SELECT uuid, level, upper_level, title, sub_title, image_url, image_alt, content FROM ".$this->prodTable." WHERE uuid = :id ";
|
|
return $this->pdo->execute($sqlStr, array('id'=>$dataId));
|
|
}
|
|
|
|
/**
|
|
* 寫入資料
|
|
*
|
|
* @param array $dataArray
|
|
* @return boolean
|
|
*/
|
|
function addProdData($dataArray){
|
|
$this->pdo->insert($this->prodTable, $dataArray);
|
|
if ( !is_null($this->pdo->getLastId()) && $this->pdo->getLastId() != 0 ){
|
|
return $this->pdo->getLastId();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* 更新資料
|
|
*
|
|
* @param string $id
|
|
* @param string $dataArray
|
|
* @return boolen
|
|
*/
|
|
function updateProdData($id, $dataArray){
|
|
return $this->pdo->update($this->prodTable, $dataArray, 'uuid', $id);
|
|
}
|
|
|
|
/**
|
|
* 取得該分類底下的列表資料
|
|
*
|
|
* @param int $level 第幾層
|
|
* @param int $dataId 資料 ID
|
|
* @param int $pages 頁數
|
|
* @param int $limit 筆數
|
|
* @return array
|
|
*/
|
|
function getLevelDataById($level, $dataId, $pages, $limit){
|
|
$pagesStr = '';
|
|
$start = ($pages-1)*$limit;
|
|
|
|
$pagesStr.= ' LIMIT :pages , :limit';
|
|
$paramArr = array();
|
|
$paramArr['level'] = $level;
|
|
$paramArr['id'] = $dataId;
|
|
$paramArr['pages'] = $start;
|
|
$paramArr['limit'] = $limit;
|
|
|
|
$sqlStr = " SELECT uuid, level, title, sub_title, image_url, image_alt, upper_level, content FROM ".$this->prodTable." WHERE level = :level AND upper_level = :id ORDER BY create_date DESC, uuid ASC ".$pagesStr." ; ";
|
|
return $this->pdo->execute($sqlStr, $paramArr);
|
|
}
|
|
|
|
/**
|
|
* 取得該分類底下的列表全部筆數
|
|
*
|
|
* @param int $level 第幾層
|
|
* @param int $dataId 資料 ID
|
|
* @return array
|
|
*/
|
|
function getLevelDataByIdTotalNum($level, $dataId){
|
|
$dataNum = 0;
|
|
$paramArr = array();
|
|
$paramArr['level'] = $level;
|
|
$paramArr['id'] = $dataId;
|
|
$sqlStr = " SELECT count(uuid) as num FROM ".$this->prodTable." WHERE level = :level AND upper_level = :id; ";
|
|
$result = $this->pdo->execute($sqlStr, $paramArr);
|
|
if ( is_array($result) && count($result) != 0 && isset($result[0]['num']) && is_numeric($result[0]['num']) ){
|
|
$dataNum = $result[0]['num'];
|
|
}
|
|
return $dataNum;
|
|
}
|
|
|
|
|
|
/**
|
|
* 小電梯 用名稱取得產品內容該筆 id
|
|
*
|
|
* @param string $prodName
|
|
* @return array
|
|
*/
|
|
function getProdIdByName($prodName){
|
|
$sqlStr = " SELECT uuid FROM ".$this->prodTable." WHERE title = :prodName AND level = 2 ";
|
|
return $this->pdo->execute($sqlStr, array('prodName'=>$prodName));
|
|
}
|
|
|
|
/**
|
|
* 寫入配件資料
|
|
*
|
|
* @param array $dataArray
|
|
* @return boolean
|
|
*/
|
|
function addAccessoryData($dataArray){
|
|
$this->pdo->insert($this->accessoryTable, $dataArray);
|
|
if ( !is_null($this->pdo->getLastId()) && $this->pdo->getLastId() != 0 ){
|
|
return $this->pdo->getLastId();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* 取得配件列表
|
|
*
|
|
* @param int $productId
|
|
* @param int $cateId
|
|
* @return array
|
|
*/
|
|
function getAccessoryData($productId, $cateId){
|
|
$cateName = '標準配置';
|
|
if ( $cateId == 2){
|
|
$cateName = '可選配置';
|
|
}
|
|
$sqlStr = " SELECT * FROM ".$this->accessoryTable." WHERE prod_id = :dataId AND accessory_configuration = :cateName ";
|
|
return $this->pdo->execute($sqlStr, array('dataId'=>$productId, 'cateName'=>$cateName));
|
|
}
|
|
|
|
|
|
function transaction(){
|
|
$this->pdo->transaction();
|
|
}
|
|
|
|
function rollbackDB(){
|
|
$this->pdo->rollbackDB();
|
|
}
|
|
|
|
function commitDB(){
|
|
$this->pdo->commitDB();
|
|
}
|
|
|
|
function closeDB(){
|
|
$this->pdo->closeDB();
|
|
}
|
|
|
|
function getLastId(){
|
|
$this->pdo->getLastId();
|
|
}
|
|
}
|
|
?>
|