| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 6 | * |
|---|
| 7 | * http://www.lockon.co.jp/ |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or |
|---|
| 10 | * modify it under the terms of the GNU General Public License |
|---|
| 11 | * as published by the Free Software Foundation; either version 2 |
|---|
| 12 | * of the License, or (at your option) any later version. |
|---|
| 13 | * |
|---|
| 14 | * This program is distributed in the hope that it will be useful, |
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | * GNU General Public License for more details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU General Public License |
|---|
| 20 | * along with this program; if not, write to the Free Software |
|---|
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * DB関連のヘルパークラス. |
|---|
| 26 | * |
|---|
| 27 | * @package Helper |
|---|
| 28 | * @author LOCKON CO.,LTD. |
|---|
| 29 | * @version $Id:SC_Helper_DB.php 15532 2007-08-31 14:39:46Z nanasess $ |
|---|
| 30 | */ |
|---|
| 31 | class SC_Helper_DB { |
|---|
| 32 | |
|---|
| 33 | // {{{ properties |
|---|
| 34 | |
|---|
| 35 | /** ルートカテゴリ取得フラグ */ |
|---|
| 36 | var $g_root_on; |
|---|
| 37 | |
|---|
| 38 | /** ルートカテゴリID */ |
|---|
| 39 | var $g_root_id; |
|---|
| 40 | |
|---|
| 41 | /** 選択中カテゴリ取得フラグ */ |
|---|
| 42 | var $g_category_on; |
|---|
| 43 | |
|---|
| 44 | /** 選択中カテゴリID */ |
|---|
| 45 | var $g_category_id; |
|---|
| 46 | |
|---|
| 47 | // }}} |
|---|
| 48 | // {{{ functions |
|---|
| 49 | |
|---|
| 50 | /** |
|---|
| 51 | * データベースのバージョンを所得する. |
|---|
| 52 | * |
|---|
| 53 | * @param string $dsn データソース名 |
|---|
| 54 | * @return string データベースのバージョン |
|---|
| 55 | */ |
|---|
| 56 | function sfGetDBVersion($dsn = "") { |
|---|
| 57 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
|---|
| 58 | return $dbFactory->sfGetDBVersion($dsn); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | /** |
|---|
| 62 | * カラムの存在チェックと作成を行う. |
|---|
| 63 | * |
|---|
| 64 | * チェック対象のテーブルに, 該当のカラムが存在するかチェックする. |
|---|
| 65 | * 引数 $add が true の場合, 該当のカラムが存在しない場合は, カラムの生成を行う. |
|---|
| 66 | * カラムの生成も行う場合は, $col_type も必須となる. |
|---|
| 67 | * |
|---|
| 68 | * @param string $table_name テーブル名 |
|---|
| 69 | * @param string $column_name カラム名 |
|---|
| 70 | * @param string $col_type カラムのデータ型 |
|---|
| 71 | * @param string $dsn データソース名 |
|---|
| 72 | * @param bool $add カラムの作成も行う場合 true |
|---|
| 73 | * @return bool カラムが存在する場合とカラムの生成に成功した場合 true, |
|---|
| 74 | * テーブルが存在しない場合 false, |
|---|
| 75 | * 引数 $add == false でカラムが存在しない場合 false |
|---|
| 76 | */ |
|---|
| 77 | function sfColumnExists($table_name, $col_name, $col_type = "", $dsn = "", $add = false) { |
|---|
| 78 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
|---|
| 79 | $dsn = $dbFactory->getDSN($dsn); |
|---|
| 80 | |
|---|
| 81 | $objQuery =& SC_Query::getSingletonInstance($dsn); |
|---|
| 82 | |
|---|
| 83 | // テーブルが無ければエラー |
|---|
| 84 | if(!in_array($table_name, $objQuery->listTables())) return false; |
|---|
| 85 | |
|---|
| 86 | // 正常に接続されている場合 |
|---|
| 87 | if(!$objQuery->isError()) { |
|---|
| 88 | list($db_type) = split(":", $dsn); |
|---|
| 89 | |
|---|
| 90 | // カラムリストを取得 |
|---|
| 91 | $columns = $objQuery->listTableFields($table_name); |
|---|
| 92 | |
|---|
| 93 | if(in_array($col_name, $columns)){ |
|---|
| 94 | return true; |
|---|
| 95 | } |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | // カラムを追加する |
|---|
| 99 | if($add){ |
|---|
| 100 | $objQuery->query("ALTER TABLE $table_name ADD $col_name $col_type "); |
|---|
| 101 | return true; |
|---|
| 102 | } |
|---|
| 103 | return false; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | /** |
|---|
| 107 | * データの存在チェックを行う. |
|---|
| 108 | * |
|---|
| 109 | * @param string $table_name テーブル名 |
|---|
| 110 | * @param string $where データを検索する WHERE 句 |
|---|
| 111 | * @param string $dsn データソース名 |
|---|
| 112 | * @param string $sql データの追加を行う場合の SQL文 |
|---|
| 113 | * @param bool $add データの追加も行う場合 true |
|---|
| 114 | * @return bool データが存在する場合 true, データの追加に成功した場合 true, |
|---|
| 115 | * $add == false で, データが存在しない場合 false |
|---|
| 116 | */ |
|---|
| 117 | function sfDataExists($table_name, $where, $arrval, $dsn = "", $sql = "", $add = false) { |
|---|
| 118 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
|---|
| 119 | $dsn = $dbFactory->getDSN($dsn); |
|---|
| 120 | |
|---|
| 121 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 122 | $count = $objQuery->count($table_name, $where, $arrval); |
|---|
| 123 | |
|---|
| 124 | if($count > 0) { |
|---|
| 125 | $ret = true; |
|---|
| 126 | } else { |
|---|
| 127 | $ret = false; |
|---|
| 128 | } |
|---|
| 129 | // データを追加する |
|---|
| 130 | if(!$ret && $add) { |
|---|
| 131 | $objQuery->exec($sql); |
|---|
| 132 | } |
|---|
| 133 | return $ret; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | /** |
|---|
| 137 | * 店舗基本情報を取得する. |
|---|
| 138 | * |
|---|
| 139 | * @param boolean $force 強制的にDB取得するか |
|---|
| 140 | * @return array 店舗基本情報の配列 |
|---|
| 141 | */ |
|---|
| 142 | function sf_getBasisData($force = false) { |
|---|
| 143 | static $data; |
|---|
| 144 | |
|---|
| 145 | if ($force || !isset($data)) { |
|---|
| 146 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 147 | $arrRet = $objQuery->select('*', 'dtb_baseinfo'); |
|---|
| 148 | |
|---|
| 149 | if (isset($arrRet[0])) { |
|---|
| 150 | $data = $arrRet[0]; |
|---|
| 151 | } else { |
|---|
| 152 | $data = array(); |
|---|
| 153 | } |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | return $data; |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | /* 選択中のアイテムのルートカテゴリIDを取得する */ |
|---|
| 160 | function sfGetRootId() { |
|---|
| 161 | |
|---|
| 162 | if(!$this->g_root_on) { |
|---|
| 163 | $this->g_root_on = true; |
|---|
| 164 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 165 | |
|---|
| 166 | if (!isset($_GET['product_id'])) $_GET['product_id'] = ""; |
|---|
| 167 | if (!isset($_GET['category_id'])) $_GET['category_id'] = ""; |
|---|
| 168 | |
|---|
| 169 | if(!empty($_GET['product_id']) || !empty($_GET['category_id'])) { |
|---|
| 170 | // 選択中のカテゴリIDを判定する |
|---|
| 171 | $category_id = $this->sfGetCategoryId($_GET['product_id'], $_GET['category_id']); |
|---|
| 172 | // ROOTカテゴリIDの取得 |
|---|
| 173 | $arrRet = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); |
|---|
| 174 | $root_id = isset($arrRet[0]) ? $arrRet[0] : ""; |
|---|
| 175 | } else { |
|---|
| 176 | // ROOTカテゴリIDをなしに設定する |
|---|
| 177 | $root_id = ""; |
|---|
| 178 | } |
|---|
| 179 | $this->g_root_id = $root_id; |
|---|
| 180 | } |
|---|
| 181 | return $this->g_root_id; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | /** |
|---|
| 185 | * 商品規格情報を取得する. |
|---|
| 186 | * |
|---|
| 187 | * TODO SC_Product クラスへ移動 |
|---|
| 188 | * |
|---|
| 189 | * @param array $arrID 規格ID |
|---|
| 190 | * @param boolean $includePrivateProducts 非公開商品を含むか |
|---|
| 191 | * @return array 規格情報の配列 |
|---|
| 192 | */ |
|---|
| 193 | function sfGetProductsClass($arrID, $includePrivateProducts = false) { |
|---|
| 194 | list($product_id, $classcategory_id1, $classcategory_id2) = $arrID; |
|---|
| 195 | |
|---|
| 196 | if (strlen($classcategory_id1) == 0) { |
|---|
| 197 | $classcategory_id1 = null; |
|---|
| 198 | } |
|---|
| 199 | if (strlen($classcategory_id2) == 0) { |
|---|
| 200 | $classcategory_id2 = null; |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | // 商品規格取得 |
|---|
| 204 | $objProduct = new SC_Product(); |
|---|
| 205 | $detail = $objProduct->getDetail($product_id); |
|---|
| 206 | $productsClass = $objProduct->getProductsClassFullByProductId($product_id); |
|---|
| 207 | foreach ($productsClass as $val) { |
|---|
| 208 | |
|---|
| 209 | if ($val['classcategory_id1'] == $classcategory_id1 |
|---|
| 210 | && $val['classcategory_id2'] == $classcategory_id2) { |
|---|
| 211 | |
|---|
| 212 | $detail = array_merge($val, $detail); |
|---|
| 213 | if (!$includePrivateProducts) { |
|---|
| 214 | if ($detail['status'] == 1) { |
|---|
| 215 | return $detail; |
|---|
| 216 | } |
|---|
| 217 | } |
|---|
| 218 | return $detail; |
|---|
| 219 | } |
|---|
| 220 | } |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | /** |
|---|
| 224 | * 支払い方法を取得する. |
|---|
| 225 | * |
|---|
| 226 | * @return void |
|---|
| 227 | */ |
|---|
| 228 | function sfGetPayment() { |
|---|
| 229 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 230 | // 購入金額が条件額以下の項目を取得 |
|---|
| 231 | $where = "del_flg = 0"; |
|---|
| 232 | $objQuery->setOrder("fix, rank DESC"); |
|---|
| 233 | $arrRet = $objQuery->select("payment_id, payment_method, rule", "dtb_payment", $where); |
|---|
| 234 | return $arrRet; |
|---|
| 235 | } |
|---|
| 236 | |
|---|
| 237 | /** |
|---|
| 238 | * カート内商品の集計処理を行う. |
|---|
| 239 | * |
|---|
| 240 | * 管理機能での利用は想定していないので注意。(非公開商品は除外される。) |
|---|
| 241 | * |
|---|
| 242 | * @param LC_Page $objPage ページクラスのインスタンス |
|---|
| 243 | * @param SC_CartSession $objCartSess カートセッションのインスタンス |
|---|
| 244 | * @param null $dummy1 互換性確保用(決済モジュール互換のため) |
|---|
| 245 | * @return LC_Page 集計処理後のページクラスインスタンス |
|---|
| 246 | */ |
|---|
| 247 | function sfTotalCart(&$objPage, $objCartSess, $dummy1 = null, $key = "") { |
|---|
| 248 | |
|---|
| 249 | $objPage->tpl_total_pretax[$key] = 0; // 費用合計(税込み) |
|---|
| 250 | $objPage->tpl_total_tax[$key] = 0; // 消費税合計 |
|---|
| 251 | $objPage->tpl_total_point[$key] = 0; // ポイント合計 |
|---|
| 252 | |
|---|
| 253 | $objProduct = new SC_Product(); |
|---|
| 254 | // カート内情報の取得 |
|---|
| 255 | $arrQuantityInfo_by_product = array(); |
|---|
| 256 | $cnt = 0; |
|---|
| 257 | foreach ($objCartSess->getCartList() as $arrCart) { |
|---|
| 258 | // 商品規格情報の取得 |
|---|
| 259 | $arrData = $objProduct->getDetailAndProductsClass($arrCart['id']); |
|---|
| 260 | $limit = null; |
|---|
| 261 | // DBに存在する商品 |
|---|
| 262 | if (count($arrData) > 0) { |
|---|
| 263 | |
|---|
| 264 | // 購入制限数を求める。 |
|---|
| 265 | if ($arrData['stock_unlimited'] != '1' && SC_Utils_Ex::sfIsInt($arrData['sale_limit'])) { |
|---|
| 266 | $limit = min($arrData['sale_limit'], $arrData['stock']); |
|---|
| 267 | } elseif (SC_Utils_Ex::sfIsInt($arrData['sale_limit'])) { |
|---|
| 268 | $limit = $arrData['sale_limit']; |
|---|
| 269 | } elseif ($arrData['stock_unlimited'] != '1') { |
|---|
| 270 | $limit = $arrData['stock']; |
|---|
| 271 | } |
|---|
| 272 | |
|---|
| 273 | if (!is_null($limit) && $arrCart['quantity'] > $limit) { |
|---|
| 274 | if ($limit > 0) { |
|---|
| 275 | // カート内商品数を制限に合わせる |
|---|
| 276 | $objCartSess->setProductValue($arrCart['id'], 'quantity', $limit); |
|---|
| 277 | $quantity = $limit; |
|---|
| 278 | $objPage->tpl_message .= "※「" . $arrData['name'] . "」は販売制限(または在庫が不足)しております。一度に数量{$limit}以上の購入はできません。\n"; |
|---|
| 279 | } else { |
|---|
| 280 | // 売り切れ商品をカートから削除する |
|---|
| 281 | $objCartSess->delProduct($arrCart['cart_no']); |
|---|
| 282 | $objPage->tpl_message .= "※「" . $arrData['name'] . "」は売り切れました。\n"; |
|---|
| 283 | continue; |
|---|
| 284 | } |
|---|
| 285 | } else { |
|---|
| 286 | $quantity = $arrCart['quantity']; |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | // (商品規格単位でなく)商品単位での評価のための準備 |
|---|
| 290 | $product_id = $arrData['product_id']; |
|---|
| 291 | $arrQuantityInfo_by_product[$product_id]['quantity'] += $quantity; |
|---|
| 292 | $arrQuantityInfo_by_product[$product_id]['sale_limit'] = $arrData['sale_limit']; |
|---|
| 293 | $arrQuantityInfo_by_product[$product_id]['name'] = $arrData['name']; |
|---|
| 294 | |
|---|
| 295 | $objPage->arrProductsClass[$cnt][$key] = $arrData; |
|---|
| 296 | $objPage->arrProductsClass[$cnt]['quantity'][$key] = $quantity; |
|---|
| 297 | $objPage->arrProductsClass[$cnt]['cart_no'][$key] = $arrCart['cart_no']; |
|---|
| 298 | $objPage->arrProductsClass[$cnt]['class_name1'][$key] = |
|---|
| 299 | isset($arrData['class_name1']) |
|---|
| 300 | ? $arrData['class_name1'] : ""; |
|---|
| 301 | |
|---|
| 302 | $objPage->arrProductsClass[$cnt]['class_name2'][$key] = |
|---|
| 303 | isset($arrData['class_name2']) |
|---|
| 304 | ? $arrData['class_name2'] : ""; |
|---|
| 305 | |
|---|
| 306 | $objPage->arrProductsClass[$cnt]['classcategory_name1'][$key] = $arrData['name1']; |
|---|
| 307 | |
|---|
| 308 | $objPage->arrProductsClass[$cnt]['classcategory_name2'][$key] = $arrData['name2']; |
|---|
| 309 | // 価格の登録 |
|---|
| 310 | $objCartSess->setProductValue($arrCart['id'], 'price', $arrData['price02']); |
|---|
| 311 | $objPage->arrProductsClass[$cnt]['uniq_price'][$key] = $arrData['price02']; |
|---|
| 312 | // ポイント付与率の登録 |
|---|
| 313 | if (USE_POINT !== false) { |
|---|
| 314 | $objCartSess->setProductValue($arrCart['id'], 'point_rate', $arrData['point_rate']); |
|---|
| 315 | } |
|---|
| 316 | // 商品ごとの合計金額 |
|---|
| 317 | $objPage->arrProductsClass[$cnt]['total_pretax'][$key] = $objCartSess->getProductTotal($arrCart['id']); |
|---|
| 318 | // 送料の合計を計算する |
|---|
| 319 | $objPage->tpl_total_deliv_fee[$key] += ($arrData['deliv_fee'] * $arrCart['quantity']); |
|---|
| 320 | $cnt++; |
|---|
| 321 | } else { // DBに商品が見つからない場合、 |
|---|
| 322 | $objPage->tpl_message .= "※ 現時点で販売していない商品が含まれておりました。該当商品をカートから削除しました。\n"; |
|---|
| 323 | // カート商品の削除 |
|---|
| 324 | $objCartSess->delProduct($arrCart['cart_no']); |
|---|
| 325 | } |
|---|
| 326 | } |
|---|
| 327 | |
|---|
| 328 | foreach ($arrQuantityInfo_by_product as $product_id => $quantityInfo) { |
|---|
| 329 | if (SC_Utils_Ex::sfIsInt($quantityInfo['sale_limit']) && $quantityInfo['quantity'] > $quantityInfo['sale_limit']) { |
|---|
| 330 | $objPage->tpl_error = "※「{$quantityInfo['name']}」は数量「{$quantityInfo['sale_limit']}」以下に販売制限しております。一度にこれ以上の購入はできません。\n"; |
|---|
| 331 | // 販売制限に引っかかった商品をマークする |
|---|
| 332 | foreach (array_keys($objPage->arrProductsClass) as $k) { |
|---|
| 333 | $ProductsClass =& $objPage->arrProductsClass[$k]; |
|---|
| 334 | if ($ProductsClass['product_id'] == $product_id) { |
|---|
| 335 | $ProductsClass['error'] = true; |
|---|
| 336 | } |
|---|
| 337 | } |
|---|
| 338 | } |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | // 全商品合計金額(税込み) |
|---|
| 342 | $objPage->tpl_total_pretax[$key] = $objCartSess->getAllProductsTotal(); |
|---|
| 343 | // 全商品合計消費税 |
|---|
| 344 | $objPage->tpl_total_tax[$key] = $objCartSess->getAllProductsTax(); |
|---|
| 345 | // 全商品合計ポイント |
|---|
| 346 | if (USE_POINT !== false) { |
|---|
| 347 | $objPage->tpl_total_point[$key] = $objCartSess->getAllProductsPoint(); |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | return $objPage; |
|---|
| 351 | } |
|---|
| 352 | |
|---|
| 353 | /** |
|---|
| 354 | * 受注一時テーブルへの書き込み処理を行う. |
|---|
| 355 | * |
|---|
| 356 | * @param string $uniqid ユニークID |
|---|
| 357 | * @param array $sqlval SQLの値の配列 |
|---|
| 358 | * @return void |
|---|
| 359 | */ |
|---|
| 360 | function sfRegistTempOrder($uniqid, $sqlval) { |
|---|
| 361 | if($uniqid != "") { |
|---|
| 362 | // 既存データのチェック |
|---|
| 363 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 364 | $where = "order_temp_id = ?"; |
|---|
| 365 | $cnt = $objQuery->count("dtb_order_temp", $where, array($uniqid)); |
|---|
| 366 | // 既存データがない場合 |
|---|
| 367 | if ($cnt == 0) { |
|---|
| 368 | // 初回書き込み時に会員の登録済み情報を取り込む |
|---|
| 369 | $sqlval = $this->sfGetCustomerSqlVal($uniqid, $sqlval); |
|---|
| 370 | $sqlval['create_date'] = "now()"; |
|---|
| 371 | $objQuery->insert("dtb_order_temp", $sqlval); |
|---|
| 372 | } else { |
|---|
| 373 | $objQuery->update("dtb_order_temp", $sqlval, $where, array($uniqid)); |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | // 受注_Tempテーブルの名称列を更新 |
|---|
| 377 | // ・決済モジュールに対応するため、static メソッドとして扱う |
|---|
| 378 | SC_Helper_DB_Ex::sfUpdateOrderNameCol($uniqid, true); |
|---|
| 379 | } |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | /** |
|---|
| 383 | * 会員情報から SQL文の値を生成する. |
|---|
| 384 | * |
|---|
| 385 | * @param string $uniqid ユニークID |
|---|
| 386 | * @param array $sqlval SQL の値の配列 |
|---|
| 387 | * @return array 会員情報を含んだ SQL の値の配列 |
|---|
| 388 | */ |
|---|
| 389 | function sfGetCustomerSqlVal($uniqid, $sqlval) { |
|---|
| 390 | $objCustomer = new SC_Customer(); |
|---|
| 391 | // 会員情報登録処理 |
|---|
| 392 | if ($objCustomer->isLoginSuccess(true)) { |
|---|
| 393 | // 登録データの作成 |
|---|
| 394 | $sqlval['order_temp_id'] = $uniqid; |
|---|
| 395 | $sqlval['update_date'] = 'Now()'; |
|---|
| 396 | $sqlval['customer_id'] = $objCustomer->getValue('customer_id'); |
|---|
| 397 | $sqlval['order_name01'] = $objCustomer->getValue('name01'); |
|---|
| 398 | $sqlval['order_name02'] = $objCustomer->getValue('name02'); |
|---|
| 399 | $sqlval['order_kana01'] = $objCustomer->getValue('kana01'); |
|---|
| 400 | $sqlval['order_kana02'] = $objCustomer->getValue('kana02'); |
|---|
| 401 | $sqlval['order_sex'] = $objCustomer->getValue('sex'); |
|---|
| 402 | $sqlval['order_zip01'] = $objCustomer->getValue('zip01'); |
|---|
| 403 | $sqlval['order_zip02'] = $objCustomer->getValue('zip02'); |
|---|
| 404 | $sqlval['order_pref'] = $objCustomer->getValue('pref'); |
|---|
| 405 | $sqlval['order_addr01'] = $objCustomer->getValue('addr01'); |
|---|
| 406 | $sqlval['order_addr02'] = $objCustomer->getValue('addr02'); |
|---|
| 407 | $sqlval['order_tel01'] = $objCustomer->getValue('tel01'); |
|---|
| 408 | $sqlval['order_tel02'] = $objCustomer->getValue('tel02'); |
|---|
| 409 | $sqlval['order_tel03'] = $objCustomer->getValue('tel03'); |
|---|
| 410 | if (defined('MOBILE_SITE')) { |
|---|
| 411 | $email_mobile = $objCustomer->getValue('email_mobile'); |
|---|
| 412 | if (empty($email_mobile)) { |
|---|
| 413 | $sqlval['order_email'] = $objCustomer->getValue('email'); |
|---|
| 414 | } else { |
|---|
| 415 | $sqlval['order_email'] = $email_mobile; |
|---|
| 416 | } |
|---|
| 417 | } else { |
|---|
| 418 | $sqlval['order_email'] = $objCustomer->getValue('email'); |
|---|
| 419 | } |
|---|
| 420 | $sqlval['order_job'] = $objCustomer->getValue('job'); |
|---|
| 421 | $sqlval['order_birth'] = $objCustomer->getValue('birth'); |
|---|
| 422 | } |
|---|
| 423 | return $sqlval; |
|---|
| 424 | } |
|---|
| 425 | |
|---|
| 426 | /** |
|---|
| 427 | * 会員編集登録処理を行う. |
|---|
| 428 | * |
|---|
| 429 | * @param array $array パラメータの配列 |
|---|
| 430 | * @param array $arrRegistColumn 登録するカラムの配列 |
|---|
| 431 | * @return void |
|---|
| 432 | */ |
|---|
| 433 | function sfEditCustomerData($array, $arrRegistColumn) { |
|---|
| 434 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 435 | |
|---|
| 436 | foreach ($arrRegistColumn as $data) { |
|---|
| 437 | if ($data["column"] != "password") { |
|---|
| 438 | if($array[ $data['column'] ] != "") { |
|---|
| 439 | $arrRegist[ $data["column"] ] = $array[ $data["column"] ]; |
|---|
| 440 | } else { |
|---|
| 441 | $arrRegist[ $data['column'] ] = NULL; |
|---|
| 442 | } |
|---|
| 443 | } |
|---|
| 444 | } |
|---|
| 445 | if (strlen($array["year"]) > 0 && strlen($array["month"]) > 0 && strlen($array["day"]) > 0) { |
|---|
| 446 | $arrRegist["birth"] = $array["year"] ."/". $array["month"] ."/". $array["day"] ." 00:00:00"; |
|---|
| 447 | } else { |
|---|
| 448 | $arrRegist["birth"] = NULL; |
|---|
| 449 | } |
|---|
| 450 | |
|---|
| 451 | //-- パスワードの更新がある場合は暗号化。(更新がない場合はUPDATE文を構成しない) |
|---|
| 452 | if ($array["password"] != DEFAULT_PASSWORD) $arrRegist["password"] = sha1($array["password"] . ":" . AUTH_MAGIC); |
|---|
| 453 | $arrRegist["update_date"] = "NOW()"; |
|---|
| 454 | |
|---|
| 455 | //-- 編集登録実行 |
|---|
| 456 | $objQuery->update("dtb_customer", $arrRegist, "customer_id = ? ", array($array['customer_id'])); |
|---|
| 457 | } |
|---|
| 458 | |
|---|
| 459 | /** |
|---|
| 460 | * 注文番号、利用ポイント、加算ポイントから最終ポイントを取得する. |
|---|
| 461 | * |
|---|
| 462 | * @param integer $order_id 注文番号 |
|---|
| 463 | * @param integer $use_point 利用ポイント |
|---|
| 464 | * @param integer $add_point 加算ポイント |
|---|
| 465 | * @return array 最終ポイントの配列 |
|---|
| 466 | */ |
|---|
| 467 | function sfGetCustomerPoint($order_id, $use_point, $add_point) { |
|---|
| 468 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 469 | $arrRet = $objQuery->select("customer_id", "dtb_order", "order_id = ?", array($order_id)); |
|---|
| 470 | $customer_id = $arrRet[0]['customer_id']; |
|---|
| 471 | if ($customer_id != "" && $customer_id >= 1) { |
|---|
| 472 | if (USE_POINT !== false) { |
|---|
| 473 | $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id)); |
|---|
| 474 | $point = $arrRet[0]['point']; |
|---|
| 475 | $total_point = $arrRet[0]['point'] - $use_point + $add_point; |
|---|
| 476 | } else { |
|---|
| 477 | $total_point = 0; |
|---|
| 478 | $point = 0; |
|---|
| 479 | } |
|---|
| 480 | } else { |
|---|
| 481 | $total_point = ""; |
|---|
| 482 | $point = ""; |
|---|
| 483 | } |
|---|
| 484 | return array($point, $total_point); |
|---|
| 485 | } |
|---|
| 486 | |
|---|
| 487 | /** |
|---|
| 488 | * 顧客番号、利用ポイント、加算ポイントから最終ポイントを取得する. |
|---|
| 489 | * |
|---|
| 490 | * @param integer $customer_id 顧客番号 |
|---|
| 491 | * @param integer $use_point 利用ポイント |
|---|
| 492 | * @param integer $add_point 加算ポイント |
|---|
| 493 | * @return array 最終ポイントの配列 |
|---|
| 494 | */ |
|---|
| 495 | function sfGetCustomerPointFromCid($customer_id, $use_point, $add_point) { |
|---|
| 496 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 497 | if (USE_POINT !== false) { |
|---|
| 498 | $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id)); |
|---|
| 499 | $point = $arrRet[0]['point']; |
|---|
| 500 | $total_point = $arrRet[0]['point'] - $use_point + $add_point; |
|---|
| 501 | } else { |
|---|
| 502 | $total_point = 0; |
|---|
| 503 | $point = 0; |
|---|
| 504 | } |
|---|
| 505 | return array($point, $total_point); |
|---|
| 506 | } |
|---|
| 507 | /** |
|---|
| 508 | * カテゴリツリーの取得を行う. |
|---|
| 509 | * |
|---|
| 510 | * @param integer $parent_category_id 親カテゴリID |
|---|
| 511 | * @param bool $count_check 登録商品数のチェックを行う場合 true |
|---|
| 512 | * @return array カテゴリツリーの配列 |
|---|
| 513 | */ |
|---|
| 514 | function sfGetCatTree($parent_category_id, $count_check = false) { |
|---|
| 515 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 516 | $col = ""; |
|---|
| 517 | $col .= " cat.category_id,"; |
|---|
| 518 | $col .= " cat.category_name,"; |
|---|
| 519 | $col .= " cat.parent_category_id,"; |
|---|
| 520 | $col .= " cat.level,"; |
|---|
| 521 | $col .= " cat.rank,"; |
|---|
| 522 | $col .= " cat.creator_id,"; |
|---|
| 523 | $col .= " cat.create_date,"; |
|---|
| 524 | $col .= " cat.update_date,"; |
|---|
| 525 | $col .= " cat.del_flg, "; |
|---|
| 526 | $col .= " ttl.product_count"; |
|---|
| 527 | $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id"; |
|---|
| 528 | // 登録商品数のチェック |
|---|
| 529 | if($count_check) { |
|---|
| 530 | $where = "del_flg = 0 AND product_count > 0"; |
|---|
| 531 | } else { |
|---|
| 532 | $where = "del_flg = 0"; |
|---|
| 533 | } |
|---|
| 534 | $objQuery->setOption("ORDER BY rank DESC"); |
|---|
| 535 | $arrRet = $objQuery->select($col, $from, $where); |
|---|
| 536 | |
|---|
| 537 | $arrParentID = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id); |
|---|
| 538 | |
|---|
| 539 | foreach($arrRet as $key => $array) { |
|---|
| 540 | foreach($arrParentID as $val) { |
|---|
| 541 | if($array['category_id'] == $val) { |
|---|
| 542 | $arrRet[$key]['display'] = 1; |
|---|
| 543 | break; |
|---|
| 544 | } |
|---|
| 545 | } |
|---|
| 546 | } |
|---|
| 547 | |
|---|
| 548 | return $arrRet; |
|---|
| 549 | } |
|---|
| 550 | |
|---|
| 551 | /** |
|---|
| 552 | * カテゴリツリーの取得を複数カテゴリーで行う. |
|---|
| 553 | * |
|---|
| 554 | * @param integer $product_id 商品ID |
|---|
| 555 | * @param bool $count_check 登録商品数のチェックを行う場合 true |
|---|
| 556 | * @return array カテゴリツリーの配列 |
|---|
| 557 | */ |
|---|
| 558 | function sfGetMultiCatTree($product_id, $count_check = false) { |
|---|
| 559 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 560 | $col = ""; |
|---|
| 561 | $col .= " cat.category_id,"; |
|---|
| 562 | $col .= " cat.category_name,"; |
|---|
| 563 | $col .= " cat.parent_category_id,"; |
|---|
| 564 | $col .= " cat.level,"; |
|---|
| 565 | $col .= " cat.rank,"; |
|---|
| 566 | $col .= " cat.creator_id,"; |
|---|
| 567 | $col .= " cat.create_date,"; |
|---|
| 568 | $col .= " cat.update_date,"; |
|---|
| 569 | $col .= " cat.del_flg, "; |
|---|
| 570 | $col .= " ttl.product_count"; |
|---|
| 571 | $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id"; |
|---|
| 572 | // 登録商品数のチェック |
|---|
| 573 | if($count_check) { |
|---|
| 574 | $where = "del_flg = 0 AND product_count > 0"; |
|---|
| 575 | } else { |
|---|
| 576 | $where = "del_flg = 0"; |
|---|
| 577 | } |
|---|
| 578 | $objQuery->setOption("ORDER BY rank DESC"); |
|---|
| 579 | $arrRet = $objQuery->select($col, $from, $where); |
|---|
| 580 | |
|---|
| 581 | $arrCategory_id = $this->sfGetCategoryId($product_id); |
|---|
| 582 | |
|---|
| 583 | $arrCatTree = array(); |
|---|
| 584 | foreach ($arrCategory_id as $pkey => $parent_category_id) { |
|---|
| 585 | $arrParentID = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id); |
|---|
| 586 | |
|---|
| 587 | foreach($arrParentID as $pid) { |
|---|
| 588 | foreach($arrRet as $key => $array) { |
|---|
| 589 | if($array['category_id'] == $pid) { |
|---|
| 590 | $arrCatTree[$pkey][] = $arrRet[$key]; |
|---|
| 591 | break; |
|---|
| 592 | } |
|---|
| 593 | } |
|---|
| 594 | } |
|---|
| 595 | } |
|---|
| 596 | |
|---|
| 597 | return $arrCatTree; |
|---|
| 598 | } |
|---|
| 599 | |
|---|
| 600 | /** |
|---|
| 601 | * 親カテゴリーを連結した文字列を取得する. |
|---|
| 602 | * |
|---|
| 603 | * @param integer $category_id カテゴリID |
|---|
| 604 | * @return string 親カテゴリーを連結した文字列 |
|---|
| 605 | */ |
|---|
| 606 | function sfGetCatCombName($category_id){ |
|---|
| 607 | // 商品が属するカテゴリIDを縦に取得 |
|---|
| 608 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 609 | $arrCatID = $this->sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id); |
|---|
| 610 | $ConbName = ""; |
|---|
| 611 | |
|---|
| 612 | // カテゴリー名称を取得する |
|---|
| 613 | foreach($arrCatID as $key => $val){ |
|---|
| 614 | $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?"; |
|---|
| 615 | $arrVal = array($val); |
|---|
| 616 | $CatName = $objQuery->getOne($sql,$arrVal); |
|---|
| 617 | $ConbName .= $CatName . ' | '; |
|---|
| 618 | } |
|---|
| 619 | // 最後の | をカットする |
|---|
| 620 | $ConbName = substr_replace($ConbName, "", strlen($ConbName) - 2, 2); |
|---|
| 621 | |
|---|
| 622 | return $ConbName; |
|---|
| 623 | } |
|---|
| 624 | |
|---|
| 625 | /** |
|---|
| 626 | * 指定したカテゴリーIDのカテゴリーを取得する. |
|---|
| 627 | * |
|---|
| 628 | * @param integer $category_id カテゴリID |
|---|
| 629 | * @return array 指定したカテゴリーIDのカテゴリー |
|---|
| 630 | */ |
|---|
| 631 | function sfGetCat($category_id){ |
|---|
| 632 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 633 | |
|---|
| 634 | // カテゴリーを取得する |
|---|
| 635 | $arrVal = array($category_id); |
|---|
| 636 | $res = $objQuery->select('category_id AS id, category_name AS name', 'dtb_category', 'category_id = ?', $arrVal); |
|---|
| 637 | |
|---|
| 638 | return $res[0]; |
|---|
| 639 | } |
|---|
| 640 | |
|---|
| 641 | /** |
|---|
| 642 | * 指定したカテゴリーIDの大カテゴリーを取得する. |
|---|
| 643 | * |
|---|
| 644 | * @param integer $category_id カテゴリID |
|---|
| 645 | * @return array 指定したカテゴリーIDの大カテゴリー |
|---|
| 646 | */ |
|---|
| 647 | function sfGetFirstCat($category_id){ |
|---|
| 648 | // 商品が属するカテゴリIDを縦に取得 |
|---|
| 649 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 650 | $arrRet = array(); |
|---|
| 651 | $arrCatID = $this->sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id); |
|---|
| 652 | $arrRet['id'] = $arrCatID[0]; |
|---|
| 653 | |
|---|
| 654 | // カテゴリー名称を取得する |
|---|
| 655 | $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?"; |
|---|
| 656 | $arrVal = array($arrRet['id']); |
|---|
| 657 | $arrRet['name'] = $objQuery->getOne($sql,$arrVal); |
|---|
| 658 | |
|---|
| 659 | return $arrRet; |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | /** |
|---|
| 663 | * カテゴリツリーの取得を行う. |
|---|
| 664 | * |
|---|
| 665 | * $products_check:true商品登録済みのものだけ取得する |
|---|
| 666 | * |
|---|
| 667 | * @param string $addwhere 追加する WHERE 句 |
|---|
| 668 | * @param bool $products_check 商品の存在するカテゴリのみ取得する場合 true |
|---|
| 669 | * @param string $head カテゴリ名のプレフィックス文字列 |
|---|
| 670 | * @return array カテゴリツリーの配列 |
|---|
| 671 | */ |
|---|
| 672 | function sfGetCategoryList($addwhere = "", $products_check = false, $head = CATEGORY_HEAD) { |
|---|
| 673 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 674 | $where = "del_flg = 0"; |
|---|
| 675 | |
|---|
| 676 | if($addwhere != "") { |
|---|
| 677 | $where.= " AND $addwhere"; |
|---|
| 678 | } |
|---|
| 679 | |
|---|
| 680 | $objQuery->setOption("ORDER BY rank DESC"); |
|---|
| 681 | |
|---|
| 682 | if($products_check) { |
|---|
| 683 | $col = "T1.category_id, category_name, level"; |
|---|
| 684 | $from = "dtb_category AS T1 LEFT JOIN dtb_category_total_count AS T2 ON T1.category_id = T2.category_id"; |
|---|
| 685 | $where .= " AND product_count > 0"; |
|---|
| 686 | } else { |
|---|
| 687 | $col = "category_id, category_name, level"; |
|---|
| 688 | $from = "dtb_category"; |
|---|
| 689 | } |
|---|
| 690 | |
|---|
| 691 | $arrRet = $objQuery->select($col, $from, $where); |
|---|
| 692 | |
|---|
| 693 | $max = count($arrRet); |
|---|
| 694 | for($cnt = 0; $cnt < $max; $cnt++) { |
|---|
| 695 | $id = $arrRet[$cnt]['category_id']; |
|---|
| 696 | $name = $arrRet[$cnt]['category_name']; |
|---|
| 697 | $arrList[$id] = str_repeat($head, $arrRet[$cnt]['level']) . $name; |
|---|
| 698 | } |
|---|
| 699 | return $arrList; |
|---|
| 700 | } |
|---|
| 701 | |
|---|
| 702 | /** |
|---|
| 703 | * カテゴリーツリーの取得を行う. |
|---|
| 704 | * |
|---|
| 705 | * 親カテゴリの Value=0 を対象とする |
|---|
| 706 | * |
|---|
| 707 | * @param bool $parent_zero 親カテゴリの Value=0 の場合 true |
|---|
| 708 | * @return array カテゴリツリーの配列 |
|---|
| 709 | */ |
|---|
| 710 | function sfGetLevelCatList($parent_zero = true) { |
|---|
| 711 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 712 | |
|---|
| 713 | // カテゴリ名リストを取得 |
|---|
| 714 | $col = "category_id, parent_category_id, category_name"; |
|---|
| 715 | $where = "del_flg = 0"; |
|---|
| 716 | $objQuery->setOption("ORDER BY level"); |
|---|
| 717 | $arrRet = $objQuery->select($col, "dtb_category", $where); |
|---|
| 718 | $arrCatName = array(); |
|---|
| 719 | foreach ($arrRet as $arrTmp) { |
|---|
| 720 | $arrCatName[$arrTmp['category_id']] = |
|---|
| 721 | (($arrTmp['parent_category_id'] > 0)? |
|---|
| 722 | $arrCatName[$arrTmp['parent_category_id']] : "") |
|---|
| 723 | . CATEGORY_HEAD . $arrTmp['category_name']; |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | $col = "category_id, parent_category_id, category_name, level"; |
|---|
| 727 | $where = "del_flg = 0"; |
|---|
| 728 | $objQuery->setOption("ORDER BY rank DESC"); |
|---|
| 729 | $arrRet = $objQuery->select($col, "dtb_category", $where); |
|---|
| 730 | $max = count($arrRet); |
|---|
| 731 | |
|---|
| 732 | for($cnt = 0; $cnt < $max; $cnt++) { |
|---|
| 733 | if($parent_zero) { |
|---|
| 734 | if($arrRet[$cnt]['level'] == LEVEL_MAX) { |
|---|
| 735 | $arrValue[$cnt] = $arrRet[$cnt]['category_id']; |
|---|
| 736 | } else { |
|---|
| 737 | $arrValue[$cnt] = ""; |
|---|
| 738 | } |
|---|
| 739 | } else { |
|---|
| 740 | $arrValue[$cnt] = $arrRet[$cnt]['category_id']; |
|---|
| 741 | } |
|---|
| 742 | |
|---|
| 743 | $arrOutput[$cnt] = $arrCatName[$arrRet[$cnt]['category_id']]; |
|---|
| 744 | } |
|---|
| 745 | |
|---|
| 746 | return array($arrValue, $arrOutput); |
|---|
| 747 | } |
|---|
| 748 | |
|---|
| 749 | /** |
|---|
| 750 | * 選択中の商品のカテゴリを取得する. |
|---|
| 751 | * |
|---|
| 752 | * @param integer $product_id プロダクトID |
|---|
| 753 | * @param integer $category_id カテゴリID |
|---|
| 754 | * @return array 選択中の商品のカテゴリIDの配列 |
|---|
| 755 | * |
|---|
| 756 | */ |
|---|
| 757 | function sfGetCategoryId($product_id, $category_id = 0, $closed = false) { |
|---|
| 758 | if ($closed) { |
|---|
| 759 | $status = ""; |
|---|
| 760 | } else { |
|---|
| 761 | $status = "status = 1"; |
|---|
| 762 | } |
|---|
| 763 | |
|---|
| 764 | if(!$this->g_category_on) { |
|---|
| 765 | $this->g_category_on = true; |
|---|
| 766 | $category_id = (int) $category_id; |
|---|
| 767 | $product_id = (int) $product_id; |
|---|
| 768 | if (SC_Utils_Ex::sfIsInt($category_id) && $category_id != 0 && $this->sfIsRecord("dtb_category","category_id", $category_id)) { |
|---|
| 769 | $this->g_category_id = array($category_id); |
|---|
| 770 | } else if (SC_Utils_Ex::sfIsInt($product_id) && $product_id != 0 && $this->sfIsRecord("dtb_products","product_id", $product_id, $status)) { |
|---|
| 771 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 772 | $where = "product_id = ?"; |
|---|
| 773 | $category_id = $objQuery->getCol("dtb_product_categories", "category_id", "product_id = ?", array($product_id)); |
|---|
| 774 | $this->g_category_id = $category_id; |
|---|
| 775 | } else { |
|---|
| 776 | // 不正な場合は、空の配列を返す。 |
|---|
| 777 | $this->g_category_id = array(); |
|---|
| 778 | } |
|---|
| 779 | } |
|---|
| 780 | return $this->g_category_id; |
|---|
| 781 | } |
|---|
| 782 | |
|---|
| 783 | /** |
|---|
| 784 | * 商品をカテゴリの先頭に追加する. |
|---|
| 785 | * |
|---|
| 786 | * @param integer $category_id カテゴリID |
|---|
| 787 | * @param integer $product_id プロダクトID |
|---|
| 788 | * @return void |
|---|
| 789 | */ |
|---|
| 790 | function addProductBeforCategories($category_id, $product_id) { |
|---|
| 791 | |
|---|
| 792 | $sqlval = array("category_id" => $category_id, |
|---|
| 793 | "product_id" => $product_id); |
|---|
| 794 | |
|---|
| 795 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 796 | |
|---|
| 797 | // 現在の商品カテゴリを取得 |
|---|
| 798 | $arrCat = $objQuery->select("product_id, category_id, rank", |
|---|
| 799 | "dtb_product_categories", |
|---|
| 800 | "category_id = ?", |
|---|
| 801 | array($category_id)); |
|---|
| 802 | |
|---|
| 803 | $max = "0"; |
|---|
| 804 | foreach ($arrCat as $val) { |
|---|
| 805 | // 同一商品が存在する場合は登録しない |
|---|
| 806 | if ($val["product_id"] == $product_id) { |
|---|
| 807 | return; |
|---|
| 808 | } |
|---|
| 809 | // 最上位ランクを取得 |
|---|
| 810 | $max = ($max < $val["rank"]) ? $val["rank"] : $max; |
|---|
| 811 | } |
|---|
| 812 | $sqlval["rank"] = $max + 1; |
|---|
| 813 | $objQuery->insert("dtb_product_categories", $sqlval); |
|---|
| 814 | } |
|---|
| 815 | |
|---|
| 816 | /** |
|---|
| 817 | * 商品をカテゴリの末尾に追加する. |
|---|
| 818 | * |
|---|
| 819 | * @param integer $category_id カテゴリID |
|---|
| 820 | * @param integer $product_id プロダクトID |
|---|
| 821 | * @return void |
|---|
| 822 | */ |
|---|
| 823 | function addProductAfterCategories($category_id, $product_id) { |
|---|
| 824 | $sqlval = array("category_id" => $category_id, |
|---|
| 825 | "product_id" => $product_id); |
|---|
| 826 | |
|---|
| 827 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 828 | |
|---|
| 829 | // 現在の商品カテゴリを取得 |
|---|
| 830 | $arrCat = $objQuery->select("product_id, category_id, rank", |
|---|
| 831 | "dtb_product_categories", |
|---|
| 832 | "category_id = ?", |
|---|
| 833 | array($category_id)); |
|---|
| 834 | |
|---|
| 835 | $min = 0; |
|---|
| 836 | foreach ($arrCat as $val) { |
|---|
| 837 | // 同一商品が存在する場合は登録しない |
|---|
| 838 | if ($val["product_id"] == $product_id) { |
|---|
| 839 | return; |
|---|
| 840 | } |
|---|
| 841 | // 最下位ランクを取得 |
|---|
| 842 | $min = ($min < $val["rank"]) ? $val["rank"] : $min; |
|---|
| 843 | } |
|---|
| 844 | $sqlval["rank"] = $min; |
|---|
| 845 | $objQuery->insert("dtb_product_categories", $sqlval); |
|---|
| 846 | } |
|---|
| 847 | |
|---|
| 848 | /** |
|---|
| 849 | * 商品をカテゴリから削除する. |
|---|
| 850 | * |
|---|
| 851 | * @param integer $category_id カテゴリID |
|---|
| 852 | * @param integer $product_id プロダクトID |
|---|
| 853 | * @return void |
|---|
| 854 | */ |
|---|
| 855 | function removeProductByCategories($category_id, $product_id) { |
|---|
| 856 | $sqlval = array("category_id" => $category_id, |
|---|
| 857 | "product_id" => $product_id); |
|---|
| 858 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 859 | $objQuery->delete("dtb_product_categories", |
|---|
| 860 | "category_id = ? AND product_id = ?", $sqlval); |
|---|
| 861 | } |
|---|
| 862 | |
|---|
| 863 | /** |
|---|
| 864 | * 商品カテゴリを更新する. |
|---|
| 865 | * |
|---|
| 866 | * @param array $arrCategory_id 登録するカテゴリIDの配列 |
|---|
| 867 | * @param integer $product_id プロダクトID |
|---|
| 868 | * @return void |
|---|
| 869 | */ |
|---|
| 870 | function updateProductCategories($arrCategory_id, $product_id) { |
|---|
| 871 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 872 | |
|---|
| 873 | // 現在のカテゴリ情報を取得 |
|---|
| 874 | $arrCurrentCat = $objQuery->select("product_id, category_id, rank", |
|---|
| 875 | "dtb_product_categories", |
|---|
| 876 | "product_id = ?", |
|---|
| 877 | array($product_id)); |
|---|
| 878 | |
|---|
| 879 | // 登録するカテゴリ情報と比較 |
|---|
| 880 | foreach ($arrCurrentCat as $val) { |
|---|
| 881 | |
|---|
| 882 | // 登録しないカテゴリを削除 |
|---|
| 883 | if (!in_array($val["category_id"], $arrCategory_id)) { |
|---|
| 884 | $this->removeProductByCategories($val["category_id"], $product_id); |
|---|
| 885 | } |
|---|
| 886 | } |
|---|
| 887 | |
|---|
| 888 | // カテゴリを登録 |
|---|
| 889 | foreach ($arrCategory_id as $category_id) { |
|---|
| 890 | $this->addProductBeforCategories($category_id, $product_id); |
|---|
| 891 | } |
|---|
| 892 | } |
|---|
| 893 | |
|---|
| 894 | /** |
|---|
| 895 | * カテゴリ数の登録を行う. |
|---|
| 896 | * |
|---|
| 897 | * @param SC_Query $objQuery SC_Query インスタンス |
|---|
| 898 | * @return void |
|---|
| 899 | */ |
|---|
| 900 | function sfCategory_Count($objQuery){ |
|---|
| 901 | |
|---|
| 902 | //テーブル内容の削除 |
|---|
| 903 | $objQuery->query("DELETE FROM dtb_category_count"); |
|---|
| 904 | $objQuery->query("DELETE FROM dtb_category_total_count"); |
|---|
| 905 | |
|---|
| 906 | $sql_where .= 'alldtl.del_flg = 0 AND alldtl.status = 1'; |
|---|
| 907 | // 在庫無し商品の非表示 |
|---|
| 908 | if (NOSTOCK_HIDDEN === true) { |
|---|
| 909 | $sql_where .= ' AND (alldtl.stock_max >= 1 OR alldtl.stock_unlimited_max = 1)'; |
|---|
| 910 | } |
|---|
| 911 | |
|---|
| 912 | //子カテゴリ内の商品数を集計する |
|---|
| 913 | |
|---|
| 914 | // カテゴリ情報を取得 |
|---|
| 915 | $arrCat = $objQuery->select('category_id', 'dtb_category'); |
|---|
| 916 | |
|---|
| 917 | $objProduct = new SC_Product(); |
|---|
| 918 | |
|---|
| 919 | foreach ($arrCat as $row) { |
|---|
| 920 | $category_id = $row['category_id']; |
|---|
| 921 | $arrval = array(); |
|---|
| 922 | |
|---|
| 923 | $arrval[] = $category_id; |
|---|
| 924 | |
|---|
| 925 | list($tmp_where, $tmp_arrval) = $this->sfGetCatWhere($category_id); |
|---|
| 926 | if ($tmp_where != "") { |
|---|
| 927 | $sql_where_product_ids = "product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")"; |
|---|
| 928 | $arrval = array_merge((array)$arrval, (array)$tmp_arrval, (array)$tmp_arrval); |
|---|
| 929 | } else { |
|---|
| 930 | $sql_where_product_ids = '0<>0'; // 一致させない |
|---|
| 931 | } |
|---|
| 932 | $where = "($sql_where) AND ($sql_where_product_ids)"; |
|---|
| 933 | |
|---|
| 934 | $from = $objProduct->alldtlSQL($sql_where_product_ids); |
|---|
| 935 | $sql = <<< __EOS__ |
|---|
| 936 | INSERT INTO dtb_category_total_count (category_id, product_count, create_date) |
|---|
| 937 | SELECT |
|---|
| 938 | ? |
|---|
| 939 | ,count(*) |
|---|
| 940 | ,now() |
|---|
| 941 | FROM $from |
|---|
| 942 | WHERE $where |
|---|
| 943 | __EOS__; |
|---|
| 944 | |
|---|
| 945 | $objQuery->query($sql, $arrval); |
|---|
| 946 | } |
|---|
| 947 | } |
|---|
| 948 | |
|---|
| 949 | /** |
|---|
| 950 | * 子IDの配列を返す. |
|---|
| 951 | * |
|---|
| 952 | * @param string $table テーブル名 |
|---|
| 953 | * @param string $pid_name 親ID名 |
|---|
| 954 | * @param string $id_name ID名 |
|---|
| 955 | * @param integer $id ID |
|---|
| 956 | * @param array 子ID の配列 |
|---|
| 957 | */ |
|---|
| 958 | function sfGetChildsID($table, $pid_name, $id_name, $id) { |
|---|
| 959 | $arrRet = $this->sfGetChildrenArray($table, $pid_name, $id_name, $id); |
|---|
| 960 | return $arrRet; |
|---|
| 961 | } |
|---|
| 962 | |
|---|
| 963 | /** |
|---|
| 964 | * 階層構造のテーブルから子ID配列を取得する. |
|---|
| 965 | * |
|---|
| 966 | * @param string $table テーブル名 |
|---|
| 967 | * @param string $pid_name 親ID名 |
|---|
| 968 | * @param string $id_name ID名 |
|---|
| 969 | * @param integer $id ID番号 |
|---|
| 970 | * @return array 子IDの配列 |
|---|
| 971 | */ |
|---|
| 972 | function sfGetChildrenArray($table, $pid_name, $id_name, $id) { |
|---|
| 973 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 974 | $col = $pid_name . "," . $id_name; |
|---|
| 975 | $arrData = $objQuery->select($col, $table); |
|---|
| 976 | |
|---|
| 977 | $arrPID = array(); |
|---|
| 978 | $arrPID[] = $id; |
|---|
| 979 | $arrChildren = array(); |
|---|
| 980 | $arrChildren[] = $id; |
|---|
| 981 | |
|---|
| 982 | $arrRet = $this->sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID); |
|---|
| 983 | |
|---|
| 984 | while(count($arrRet) > 0) { |
|---|
| 985 | $arrChildren = array_merge($arrChildren, $arrRet); |
|---|
| 986 | $arrRet = $this->sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrRet); |
|---|
| 987 | } |
|---|
| 988 | |
|---|
| 989 | return $arrChildren; |
|---|
| 990 | } |
|---|
| 991 | |
|---|
| 992 | /** |
|---|
| 993 | * 親ID直下の子IDをすべて取得する. |
|---|
| 994 | * |
|---|
| 995 | * @param array $arrData 親カテゴリの配列 |
|---|
| 996 | * @param string $pid_name 親ID名 |
|---|
| 997 | * @param string $id_name ID名 |
|---|
| 998 | * @param array $arrPID 親IDの配列 |
|---|
| 999 | * @return array 子IDの配列 |
|---|
| 1000 | */ |
|---|
| 1001 | function sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID) { |
|---|
| 1002 | $arrChildren = array(); |
|---|
| 1003 | $max = count($arrData); |
|---|
| 1004 | |
|---|
| 1005 | for($i = 0; $i < $max; $i++) { |
|---|
| 1006 | foreach($arrPID as $val) { |
|---|
| 1007 | if($arrData[$i][$pid_name] == $val) { |
|---|
| 1008 | $arrChildren[] = $arrData[$i][$id_name]; |
|---|
| 1009 | } |
|---|
| 1010 | } |
|---|
| 1011 | } |
|---|
| 1012 | return $arrChildren; |
|---|
| 1013 | } |
|---|
| 1014 | |
|---|
| 1015 | /** |
|---|
| 1016 | * 所属するすべての階層の親IDを配列で返す. |
|---|
| 1017 | * |
|---|
| 1018 | * @param SC_Query $objQuery SC_Query インスタンス |
|---|
| 1019 | * @param string $table テーブル名 |
|---|
| 1020 | * @param string $pid_name 親ID名 |
|---|
| 1021 | * @param string $id_name ID名 |
|---|
| 1022 | * @param integer $id ID |
|---|
| 1023 | * @return array 親IDの配列 |
|---|
| 1024 | */ |
|---|
| 1025 | function sfGetParents($objQuery, $table, $pid_name, $id_name, $id) { |
|---|
| 1026 | $arrRet = $this->sfGetParentsArray($table, $pid_name, $id_name, $id); |
|---|
| 1027 | // 配列の先頭1つを削除する。 |
|---|
| 1028 | array_shift($arrRet); |
|---|
| 1029 | return $arrRet; |
|---|
| 1030 | } |
|---|
| 1031 | |
|---|
| 1032 | /** |
|---|
| 1033 | * 階層構造のテーブルから親ID配列を取得する. |
|---|
| 1034 | * |
|---|
| 1035 | * @param string $table テーブル名 |
|---|
| 1036 | * @param string $pid_name 親ID名 |
|---|
| 1037 | * @param string $id_name ID名 |
|---|
| 1038 | * @param integer $id ID |
|---|
| 1039 | * @return array 親IDの配列 |
|---|
| 1040 | */ |
|---|
| 1041 | function sfGetParentsArray($table, $pid_name, $id_name, $id) { |
|---|
| 1042 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1043 | $col = $pid_name . "," . $id_name; |
|---|
| 1044 | $arrData = $objQuery->select($col, $table); |
|---|
| 1045 | |
|---|
| 1046 | $arrParents = array(); |
|---|
| 1047 | $arrParents[] = $id; |
|---|
| 1048 | $child = $id; |
|---|
| 1049 | |
|---|
| 1050 | $ret = SC_Utils::sfGetParentsArraySub($arrData, $pid_name, $id_name, $child); |
|---|
| 1051 | |
|---|
| 1052 | while($ret != "") { |
|---|
| 1053 | $arrParents[] = $ret; |
|---|
| 1054 | $ret = SC_Utils::sfGetParentsArraySub($arrData, $pid_name, $id_name, $ret); |
|---|
| 1055 | } |
|---|
| 1056 | |
|---|
| 1057 | $arrParents = array_reverse($arrParents); |
|---|
| 1058 | |
|---|
| 1059 | return $arrParents; |
|---|
| 1060 | } |
|---|
| 1061 | |
|---|
| 1062 | /** |
|---|
| 1063 | * カテゴリから商品を検索する場合のWHERE文と値を返す. |
|---|
| 1064 | * |
|---|
| 1065 | * @param integer $category_id カテゴリID |
|---|
| 1066 | * @return array 商品を検索する場合の配列 |
|---|
| 1067 | */ |
|---|
| 1068 | function sfGetCatWhere($category_id) { |
|---|
| 1069 | // 子カテゴリIDの取得 |
|---|
| 1070 | $arrRet = $this->sfGetChildsID("dtb_category", "parent_category_id", "category_id", $category_id); |
|---|
| 1071 | $tmp_where = ""; |
|---|
| 1072 | foreach ($arrRet as $val) { |
|---|
| 1073 | if($tmp_where == "") { |
|---|
| 1074 | $tmp_where.= "category_id IN ( ?"; |
|---|
| 1075 | } else { |
|---|
| 1076 | $tmp_where.= ",? "; |
|---|
| 1077 | } |
|---|
| 1078 | $arrval[] = $val; |
|---|
| 1079 | } |
|---|
| 1080 | $tmp_where.= " ) "; |
|---|
| 1081 | return array($tmp_where, $arrval); |
|---|
| 1082 | } |
|---|
| 1083 | |
|---|
| 1084 | /** |
|---|
| 1085 | * 受注一時テーブルから情報を取得する. |
|---|
| 1086 | * |
|---|
| 1087 | * @param integer $order_temp_id 受注一時ID |
|---|
| 1088 | * @return array 受注一時情報の配列 |
|---|
| 1089 | */ |
|---|
| 1090 | function sfGetOrderTemp($order_temp_id) { |
|---|
| 1091 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1092 | $where = "order_temp_id = ?"; |
|---|
| 1093 | $arrRet = $objQuery->select("*", "dtb_order_temp", $where, array($order_temp_id)); |
|---|
| 1094 | return $arrRet[0]; |
|---|
| 1095 | } |
|---|
| 1096 | |
|---|
| 1097 | /** |
|---|
| 1098 | * SELECTボックス用リストを作成する. |
|---|
| 1099 | * |
|---|
| 1100 | * @param string $table テーブル名 |
|---|
| 1101 | * @param string $keyname プライマリーキーのカラム名 |
|---|
| 1102 | * @param string $valname データ内容のカラム名 |
|---|
| 1103 | * @return array SELECT ボックス用リストの配列 |
|---|
| 1104 | */ |
|---|
| 1105 | function sfGetIDValueList($table, $keyname, $valname) { |
|---|
| 1106 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1107 | $col = "$keyname, $valname"; |
|---|
| 1108 | $objQuery->setWhere("del_flg = 0"); |
|---|
| 1109 | $objQuery->setOrder("rank DESC"); |
|---|
| 1110 | $arrList = $objQuery->select($col, $table); |
|---|
| 1111 | $count = count($arrList); |
|---|
| 1112 | for($cnt = 0; $cnt < $count; $cnt++) { |
|---|
| 1113 | $key = $arrList[$cnt][$keyname]; |
|---|
| 1114 | $val = $arrList[$cnt][$valname]; |
|---|
| 1115 | $arrRet[$key] = $val; |
|---|
| 1116 | } |
|---|
| 1117 | return $arrRet; |
|---|
| 1118 | } |
|---|
| 1119 | |
|---|
| 1120 | /** |
|---|
| 1121 | * ランキングを上げる. |
|---|
| 1122 | * |
|---|
| 1123 | * @param string $table テーブル名 |
|---|
| 1124 | * @param string $colname カラム名 |
|---|
| 1125 | * @param string|integer $id テーブルのキー |
|---|
| 1126 | * @param string $andwhere SQL の AND 条件である WHERE 句 |
|---|
| 1127 | * @return void |
|---|
| 1128 | */ |
|---|
| 1129 | function sfRankUp($table, $colname, $id, $andwhere = "") { |
|---|
| 1130 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1131 | $objQuery->begin(); |
|---|
| 1132 | $where = "$colname = ?"; |
|---|
| 1133 | if($andwhere != "") { |
|---|
| 1134 | $where.= " AND $andwhere"; |
|---|
| 1135 | } |
|---|
| 1136 | // 対象項目のランクを取得 |
|---|
| 1137 | $rank = $objQuery->get($table, "rank", $where, array($id)); |
|---|
| 1138 | // ランクの最大値を取得 |
|---|
| 1139 | $maxrank = $objQuery->max($table, "rank", $andwhere); |
|---|
| 1140 | // ランクが最大値よりも小さい場合に実行する。 |
|---|
| 1141 | if($rank < $maxrank) { |
|---|
| 1142 | // ランクが一つ上のIDを取得する。 |
|---|
| 1143 | $where = "rank = ?"; |
|---|
| 1144 | if($andwhere != "") { |
|---|
| 1145 | $where.= " AND $andwhere"; |
|---|
| 1146 | } |
|---|
| 1147 | $uprank = $rank + 1; |
|---|
| 1148 | $up_id = $objQuery->get($table, $colname, $where, array($uprank)); |
|---|
| 1149 | // ランク入れ替えの実行 |
|---|
| 1150 | $sqlup = "UPDATE $table SET rank = ? WHERE $colname = ?"; |
|---|
| 1151 | if($andwhere != "") { |
|---|
| 1152 | $sqlup.= " AND $andwhere"; |
|---|
| 1153 | } |
|---|
| 1154 | $objQuery->exec($sqlup, array($rank + 1, $id)); |
|---|
| 1155 | $objQuery->exec($sqlup, array($rank, $up_id)); |
|---|
| 1156 | } |
|---|
| 1157 | $objQuery->commit(); |
|---|
| 1158 | } |
|---|
| 1159 | |
|---|
| 1160 | /** |
|---|
| 1161 | * ランキングを下げる. |
|---|
| 1162 | * |
|---|
| 1163 | * @param string $table テーブル名 |
|---|
| 1164 | * @param string $colname カラム名 |
|---|
| 1165 | * @param string|integer $id テーブルのキー |
|---|
| 1166 | * @param string $andwhere SQL の AND 条件である WHERE 句 |
|---|
| 1167 | * @return void |
|---|
| 1168 | */ |
|---|
| 1169 | function sfRankDown($table, $colname, $id, $andwhere = "") { |
|---|
| 1170 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1171 | $objQuery->begin(); |
|---|
| 1172 | $where = "$colname = ?"; |
|---|
| 1173 | if($andwhere != "") { |
|---|
| 1174 | $where.= " AND $andwhere"; |
|---|
| 1175 | } |
|---|
| 1176 | // 対象項目のランクを取得 |
|---|
| 1177 | $rank = $objQuery->get($table, "rank", $where, array($id)); |
|---|
| 1178 | |
|---|
| 1179 | // ランクが1(最小値)よりも大きい場合に実行する。 |
|---|
| 1180 | if($rank > 1) { |
|---|
| 1181 | // ランクが一つ下のIDを取得する。 |
|---|
| 1182 | $where = "rank = ?"; |
|---|
| 1183 | if($andwhere != "") { |
|---|
| 1184 | $where.= " AND $andwhere"; |
|---|
| 1185 | } |
|---|
| 1186 | $downrank = $rank - 1; |
|---|
| 1187 | $down_id = $objQuery->get($table, $colname, $where, array($downrank)); |
|---|
| 1188 | // ランク入れ替えの実行 |
|---|
| 1189 | $sqlup = "UPDATE $table SET rank = ? WHERE $colname = ?"; |
|---|
| 1190 | if($andwhere != "") { |
|---|
| 1191 | $sqlup.= " AND $andwhere"; |
|---|
| 1192 | } |
|---|
| 1193 | $objQuery->exec($sqlup, array($rank - 1, $id)); |
|---|
| 1194 | $objQuery->exec($sqlup, array($rank, $down_id)); |
|---|
| 1195 | } |
|---|
| 1196 | $objQuery->commit(); |
|---|
| 1197 | } |
|---|
| 1198 | |
|---|
| 1199 | /** |
|---|
| 1200 | * 指定順位へ移動する. |
|---|
| 1201 | * |
|---|
| 1202 | * @param string $tableName テーブル名 |
|---|
| 1203 | * @param string $keyIdColumn キーを保持するカラム名 |
|---|
| 1204 | * @param string|integer $keyId キーの値 |
|---|
| 1205 | * @param integer $pos 指定順位 |
|---|
| 1206 | * @param string $where SQL の AND 条件である WHERE 句 |
|---|
| 1207 | * @return void |
|---|
| 1208 | */ |
|---|
| 1209 | function sfMoveRank($tableName, $keyIdColumn, $keyId, $pos, $where = "") { |
|---|
| 1210 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1211 | $objQuery->begin(); |
|---|
| 1212 | |
|---|
| 1213 | // 自身のランクを取得する |
|---|
| 1214 | if($where != "") { |
|---|
| 1215 | $getWhere = "$keyIdColumn = ? AND " . $where; |
|---|
| 1216 | } else { |
|---|
| 1217 | $getWhere = "$keyIdColumn = ?"; |
|---|
| 1218 | } |
|---|
| 1219 | $rank = $objQuery->get($tableName, "rank", $getWhere, array($keyId)); |
|---|
| 1220 | |
|---|
| 1221 | $max = $objQuery->max($tableName, "rank", $where); |
|---|
| 1222 | |
|---|
| 1223 | // 値の調整(逆順) |
|---|
| 1224 | if($pos > $max) { |
|---|
| 1225 | $position = 1; |
|---|
| 1226 | } else if($pos < 1) { |
|---|
| 1227 | $position = $max; |
|---|
| 1228 | } else { |
|---|
| 1229 | $position = $max - $pos + 1; |
|---|
| 1230 | } |
|---|
| 1231 | |
|---|
| 1232 | //入れ替え先の順位が入れ換え元の順位より大きい場合 |
|---|
| 1233 | if( $position > $rank ) $term = "rank - 1"; |
|---|
| 1234 | |
|---|
| 1235 | //入れ替え先の順位が入れ換え元の順位より小さい場合 |
|---|
| 1236 | if( $position < $rank ) $term = "rank + 1"; |
|---|
| 1237 | |
|---|
| 1238 | // XXX 入れ替え先の順位が入れ替え元の順位と同じ場合 |
|---|
| 1239 | if (!isset($term)) $term = "rank"; |
|---|
| 1240 | |
|---|
| 1241 | // 指定した順位の商品から移動させる商品までのrankを1つずらす |
|---|
| 1242 | $sql = "UPDATE $tableName SET rank = $term WHERE rank BETWEEN ? AND ?"; |
|---|
| 1243 | if($where != "") { |
|---|
| 1244 | $sql.= " AND $where"; |
|---|
| 1245 | } |
|---|
| 1246 | |
|---|
| 1247 | if( $position > $rank ) $objQuery->exec( $sql, array( $rank + 1, $position )); |
|---|
| 1248 | if( $position < $rank ) $objQuery->exec( $sql, array( $position, $rank - 1 )); |
|---|
| 1249 | |
|---|
| 1250 | // 指定した順位へrankを書き換える。 |
|---|
| 1251 | $sql = "UPDATE $tableName SET rank = ? WHERE $keyIdColumn = ? "; |
|---|
| 1252 | if($where != "") { |
|---|
| 1253 | $sql.= " AND $where"; |
|---|
| 1254 | } |
|---|
| 1255 | |
|---|
| 1256 | $objQuery->exec( $sql, array( $position, $keyId ) ); |
|---|
| 1257 | $objQuery->commit(); |
|---|
| 1258 | } |
|---|
| 1259 | |
|---|
| 1260 | /** |
|---|
| 1261 | * ランクを含むレコードを削除する. |
|---|
| 1262 | * |
|---|
| 1263 | * レコードごと削除する場合は、$deleteをtrueにする |
|---|
| 1264 | * |
|---|
| 1265 | * @param string $table テーブル名 |
|---|
| 1266 | * @param string $colname カラム名 |
|---|
| 1267 | * @param string|integer $id テーブルのキー |
|---|
| 1268 | * @param string $andwhere SQL の AND 条件である WHERE 句 |
|---|
| 1269 | * @param bool $delete レコードごと削除する場合 true, |
|---|
| 1270 | * レコードごと削除しない場合 false |
|---|
| 1271 | * @return void |
|---|
| 1272 | */ |
|---|
| 1273 | function sfDeleteRankRecord($table, $colname, $id, $andwhere = "", |
|---|
| 1274 | $delete = false) { |
|---|
| 1275 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1276 | $objQuery->begin(); |
|---|
| 1277 | // 削除レコードのランクを取得する。 |
|---|
| 1278 | $where = "$colname = ?"; |
|---|
| 1279 | if($andwhere != "") { |
|---|
| 1280 | $where.= " AND $andwhere"; |
|---|
| 1281 | } |
|---|
| 1282 | $rank = $objQuery->get($table, "rank", $where, array($id)); |
|---|
| 1283 | |
|---|
| 1284 | if(!$delete) { |
|---|
| 1285 | // ランクを最下位にする、DELフラグON |
|---|
| 1286 | $sqlup = "UPDATE $table SET rank = 0, del_flg = 1 "; |
|---|
| 1287 | $sqlup.= "WHERE $colname = ?"; |
|---|
| 1288 | // UPDATEの実行 |
|---|
| 1289 | $objQuery->exec($sqlup, array($id)); |
|---|
| 1290 | } else { |
|---|
| 1291 | $objQuery->delete($table, "$colname = ?", array($id)); |
|---|
| 1292 | } |
|---|
| 1293 | |
|---|
| 1294 | // 追加レコードのランクより上のレコードを一つずらす。 |
|---|
| 1295 | $where = "rank > ?"; |
|---|
| 1296 | if($andwhere != "") { |
|---|
| 1297 | $where.= " AND $andwhere"; |
|---|
| 1298 | } |
|---|
| 1299 | $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where"; |
|---|
| 1300 | $objQuery->exec($sqlup, array($rank)); |
|---|
| 1301 | $objQuery->commit(); |
|---|
| 1302 | } |
|---|
| 1303 | |
|---|
| 1304 | /** |
|---|
| 1305 | * 親IDの配列を元に特定のカラムを取得する. |
|---|
| 1306 | * |
|---|
| 1307 | * @param SC_Query $objQuery SC_Query インスタンス |
|---|
| 1308 | * @param string $table テーブル名 |
|---|
| 1309 | * @param string $id_name ID名 |
|---|
| 1310 | * @param string $col_name カラム名 |
|---|
| 1311 | * @param array $arrId IDの配列 |
|---|
| 1312 | * @return array 特定のカラムの配列 |
|---|
| 1313 | */ |
|---|
| 1314 | function sfGetParentsCol($objQuery, $table, $id_name, $col_name, $arrId ) { |
|---|
| 1315 | $col = $col_name; |
|---|
| 1316 | $len = count($arrId); |
|---|
| 1317 | $where = ""; |
|---|
| 1318 | |
|---|
| 1319 | for($cnt = 0; $cnt < $len; $cnt++) { |
|---|
| 1320 | if($where == "") { |
|---|
| 1321 | $where = "$id_name = ?"; |
|---|
| 1322 | } else { |
|---|
| 1323 | $where.= " OR $id_name = ?"; |
|---|
| 1324 | } |
|---|
| 1325 | } |
|---|
| 1326 | |
|---|
| 1327 | $objQuery->setOrder("level"); |
|---|
| 1328 | $arrRet = $objQuery->select($col, $table, $where, $arrId); |
|---|
| 1329 | return $arrRet; |
|---|
| 1330 | } |
|---|
| 1331 | |
|---|
| 1332 | /** |
|---|
| 1333 | * カテゴリ変更時の移動処理を行う. |
|---|
| 1334 | * |
|---|
| 1335 | * @param SC_Query $objQuery SC_Query インスタンス |
|---|
| 1336 | * @param string $table テーブル名 |
|---|
| 1337 | * @param string $id_name ID名 |
|---|
| 1338 | * @param string $cat_name カテゴリ名 |
|---|
| 1339 | * @param integer $old_catid 旧カテゴリID |
|---|
| 1340 | * @param integer $new_catid 新カテゴリID |
|---|
| 1341 | * @param integer $id ID |
|---|
| 1342 | * @return void |
|---|
| 1343 | */ |
|---|
| 1344 | function sfMoveCatRank($objQuery, $table, $id_name, $cat_name, $old_catid, $new_catid, $id) { |
|---|
| 1345 | if ($old_catid == $new_catid) { |
|---|
| 1346 | return; |
|---|
| 1347 | } |
|---|
| 1348 | // 旧カテゴリでのランク削除処理 |
|---|
| 1349 | // 移動レコードのランクを取得する。 |
|---|
| 1350 | $where = "$id_name = ?"; |
|---|
| 1351 | $rank = $objQuery->get($table, "rank", $where, array($id)); |
|---|
| 1352 | // 削除レコードのランクより上のレコードを一つ下にずらす。 |
|---|
| 1353 | $where = "rank > ? AND $cat_name = ?"; |
|---|
| 1354 | $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where"; |
|---|
| 1355 | $objQuery->exec($sqlup, array($rank, $old_catid)); |
|---|
| 1356 | // 新カテゴリでの登録処理 |
|---|
| 1357 | // 新カテゴリの最大ランクを取得する。 |
|---|
| 1358 | $max_rank = $objQuery->max($table, "rank", "$cat_name = ?", array($new_catid)) + 1; |
|---|
| 1359 | $where = "$id_name = ?"; |
|---|
| 1360 | $sqlup = "UPDATE $table SET rank = ? WHERE $where"; |
|---|
| 1361 | $objQuery->exec($sqlup, array($max_rank, $id)); |
|---|
| 1362 | } |
|---|
| 1363 | |
|---|
| 1364 | /** |
|---|
| 1365 | * お届け時間を取得する. |
|---|
| 1366 | * |
|---|
| 1367 | * @param integer $payment_id 支払い方法ID |
|---|
| 1368 | * @return array お届け時間の配列 |
|---|
| 1369 | */ |
|---|
| 1370 | function sfGetDelivTime($payment_id = "") { |
|---|
| 1371 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1372 | |
|---|
| 1373 | $deliv_id = ""; |
|---|
| 1374 | $arrRet = array(); |
|---|
| 1375 | |
|---|
| 1376 | if($payment_id != "") { |
|---|
| 1377 | $where = "del_flg = 0 AND payment_id = ?"; |
|---|
| 1378 | $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id)); |
|---|
| 1379 | $deliv_id = $arrRet[0]['deliv_id']; |
|---|
| 1380 | } |
|---|
| 1381 | |
|---|
| 1382 | if($deliv_id != "") { |
|---|
| 1383 | $objQuery->setOrder("time_id"); |
|---|
| 1384 | $where = "deliv_id = ?"; |
|---|
| 1385 | $arrRet= $objQuery->select("time_id, deliv_time", "dtb_delivtime", $where, array($deliv_id)); |
|---|
| 1386 | } |
|---|
| 1387 | |
|---|
| 1388 | return $arrRet; |
|---|
| 1389 | } |
|---|
| 1390 | |
|---|
| 1391 | /** |
|---|
| 1392 | * 都道府県、支払い方法から配送料金を取得する. |
|---|
| 1393 | * |
|---|
| 1394 | * @param array $arrData 各種情報 |
|---|
| 1395 | * @return string 指定の都道府県, 支払い方法の配送料金 |
|---|
| 1396 | */ |
|---|
| 1397 | function sfGetDelivFee($arrData) { |
|---|
| 1398 | $pref = $arrData['deliv_pref']; |
|---|
| 1399 | $payment_id = isset($arrData['payment_id']) ? $arrData['payment_id'] : ""; |
|---|
| 1400 | |
|---|
| 1401 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1402 | |
|---|
| 1403 | $deliv_id = ""; |
|---|
| 1404 | |
|---|
| 1405 | // 支払い方法が指定されている場合は、対応した配送業者を取得する |
|---|
| 1406 | if($payment_id != "") { |
|---|
| 1407 | $where = "del_flg = 0 AND payment_id = ?"; |
|---|
| 1408 | $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id)); |
|---|
| 1409 | $deliv_id = $arrRet[0]['deliv_id']; |
|---|
| 1410 | // 支払い方法が指定されていない場合は、先頭の配送業者を取得する |
|---|
| 1411 | } else { |
|---|
| 1412 | $where = "del_flg = 0"; |
|---|
| 1413 | $objQuery->setOrder("rank DESC"); |
|---|
| 1414 | $objQuery->setLimitOffset(1); |
|---|
| 1415 | $arrRet = $objQuery->select("deliv_id", "dtb_deliv", $where); |
|---|
| 1416 | $deliv_id = $arrRet[0]['deliv_id']; |
|---|
| 1417 | } |
|---|
| 1418 | |
|---|
| 1419 | // 配送業者から配送料を取得 |
|---|
| 1420 | if($deliv_id != "") { |
|---|
| 1421 | |
|---|
| 1422 | // 都道府県が指定されていない場合は、東京都の番号を指定しておく |
|---|
| 1423 | if($pref == "") { |
|---|
| 1424 | $pref = 13; |
|---|
| 1425 | } |
|---|
| 1426 | |
|---|
| 1427 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1428 | $where = "deliv_id = ? AND pref = ?"; |
|---|
| 1429 | $arrRet= $objQuery->select("fee", "dtb_delivfee", $where, array($deliv_id, $pref)); |
|---|
| 1430 | } |
|---|
| 1431 | return $arrRet[0]['fee']; |
|---|
| 1432 | } |
|---|
| 1433 | |
|---|
| 1434 | /** |
|---|
| 1435 | * 集計情報を元に最終計算を行う. |
|---|
| 1436 | * |
|---|
| 1437 | * @param array $arrData 各種情報 |
|---|
| 1438 | * @param LC_Page $objPage LC_Page インスタンス |
|---|
| 1439 | * @param SC_CartSession $objCartSess SC_CartSession インスタンス |
|---|
| 1440 | * @param null $dummy1 互換性確保用(決済モジュール互換のため) |
|---|
| 1441 | * @param SC_Customer $objCustomer SC_Customer インスタンス |
|---|
| 1442 | * @return array 最終計算後の配列 |
|---|
| 1443 | */ |
|---|
| 1444 | function sfTotalConfirm($arrData, &$objPage, &$objCartSess, $dummy1 = null, $objCustomer = "", $key = "") { |
|---|
| 1445 | // 店舗基本情報を取得する |
|---|
| 1446 | $arrInfo = SC_Helper_DB_Ex::sf_getBasisData(); |
|---|
| 1447 | |
|---|
| 1448 | // 未定義変数を定義 |
|---|
| 1449 | if (!isset($arrData['deliv_pref'])) $arrData['deliv_pref'] = ""; |
|---|
| 1450 | if (!isset($arrData['payment_id'])) $arrData['payment_id'] = ""; |
|---|
| 1451 | if (!isset($arrData['charge'])) $arrData['charge'] = ""; |
|---|
| 1452 | if (!isset($arrData['use_point'])) $arrData['use_point'] = ""; |
|---|
| 1453 | if (!isset($arrData['add_point'])) $arrData['add_point'] = 0; |
|---|
| 1454 | |
|---|
| 1455 | // 税金の取得 |
|---|
| 1456 | $arrData['tax'] = $objPage->tpl_total_tax[$key]; |
|---|
| 1457 | // 小計の取得 |
|---|
| 1458 | $arrData['subtotal'] = $objPage->tpl_total_pretax[$key]; |
|---|
| 1459 | |
|---|
| 1460 | // 合計送料の取得 |
|---|
| 1461 | $arrData['deliv_fee'] = 0; |
|---|
| 1462 | |
|---|
| 1463 | // 商品ごとの送料が有効の場合 |
|---|
| 1464 | if (OPTION_PRODUCT_DELIV_FEE == 1) { |
|---|
| 1465 | // 全商品の合計送料を加算する |
|---|
| 1466 | $this->lfAddAllProductsDelivFee($arrData, $objPage, $objCartSess); |
|---|
| 1467 | } |
|---|
| 1468 | |
|---|
| 1469 | // 配送業者の送料が有効の場合 |
|---|
| 1470 | if (OPTION_DELIV_FEE == 1) { |
|---|
| 1471 | // 都道府県、支払い方法から配送料金を加算する |
|---|
| 1472 | $this->lfAddDelivFee($arrData); |
|---|
| 1473 | } |
|---|
| 1474 | |
|---|
| 1475 | // 送料無料の購入数が設定されている場合 |
|---|
| 1476 | if (DELIV_FREE_AMOUNT > 0) { |
|---|
| 1477 | // 商品の合計数量 |
|---|
| 1478 | $total_quantity = $objCartSess->getTotalQuantity(true); |
|---|
| 1479 | |
|---|
| 1480 | if($total_quantity >= DELIV_FREE_AMOUNT) { |
|---|
| 1481 | $arrData['deliv_fee'] = 0; |
|---|
| 1482 | } |
|---|
| 1483 | } |
|---|
| 1484 | |
|---|
| 1485 | // ダウンロード商品のみの場合は送料無料 |
|---|
| 1486 | if($this->chkCartDown($objCartSess)==2){ |
|---|
| 1487 | $arrData['deliv_fee'] = 0; |
|---|
| 1488 | } |
|---|
| 1489 | |
|---|
| 1490 | // 送料無料条件が設定されている場合 |
|---|
| 1491 | if($arrInfo['free_rule'] > 0) { |
|---|
| 1492 | // 小計が無料条件を超えている場合 |
|---|
| 1493 | if($arrData['subtotal'] >= $arrInfo['free_rule']) { |
|---|
| 1494 | $arrData['deliv_fee'] = 0; |
|---|
| 1495 | } |
|---|
| 1496 | } |
|---|
| 1497 | |
|---|
| 1498 | // 合計の計算 |
|---|
| 1499 | $arrData['total'] = $objPage->tpl_total_pretax[$key]; // 商品合計 |
|---|
| 1500 | $arrData['total']+= $arrData['deliv_fee']; // 送料 |
|---|
| 1501 | $arrData['total']+= $arrData['charge']; // 手数料 |
|---|
| 1502 | // お支払い合計 |
|---|
| 1503 | $arrData['payment_total'] = $arrData['total'] - ($arrData['use_point'] * POINT_VALUE); |
|---|
| 1504 | // 加算ポイントの計算 |
|---|
| 1505 | if (USE_POINT !== false) { |
|---|
| 1506 | $arrData['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($objPage->tpl_total_point[$key], $arrData['use_point']); |
|---|
| 1507 | |
|---|
| 1508 | if($objCustomer != "") { |
|---|
| 1509 | // 誕生日月であった場合 |
|---|
| 1510 | if($objCustomer->isBirthMonth()) { |
|---|
| 1511 | $arrData['birth_point'] = BIRTH_MONTH_POINT; |
|---|
| 1512 | $arrData['add_point'] += $arrData['birth_point']; |
|---|
| 1513 | } |
|---|
| 1514 | } |
|---|
| 1515 | } |
|---|
| 1516 | |
|---|
| 1517 | if($arrData['add_point'] < 0) { |
|---|
| 1518 | $arrData['add_point'] = 0; |
|---|
| 1519 | } |
|---|
| 1520 | return $arrData; |
|---|
| 1521 | } |
|---|
| 1522 | |
|---|
| 1523 | /** |
|---|
| 1524 | * レコードの存在チェックを行う. |
|---|
| 1525 | * |
|---|
| 1526 | * @param string $table テーブル名 |
|---|
| 1527 | * @param string $col カラム名 |
|---|
| 1528 | * @param array $arrval 要素の配列 |
|---|
| 1529 | * @param array $addwhere SQL の AND 条件である WHERE 句 |
|---|
| 1530 | * @return bool レコードが存在する場合 true |
|---|
| 1531 | */ |
|---|
| 1532 | function sfIsRecord($table, $col, $arrval, $addwhere = "") { |
|---|
| 1533 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1534 | $arrCol = split("[, ]", $col); |
|---|
| 1535 | |
|---|
| 1536 | $where = "del_flg = 0"; |
|---|
| 1537 | |
|---|
| 1538 | if($addwhere != "") { |
|---|
| 1539 | $where.= " AND $addwhere"; |
|---|
| 1540 | } |
|---|
| 1541 | |
|---|
| 1542 | foreach($arrCol as $val) { |
|---|
| 1543 | if($val != "") { |
|---|
| 1544 | if($where == "") { |
|---|
| 1545 | $where = "$val = ?"; |
|---|
| 1546 | } else { |
|---|
| 1547 | $where.= " AND $val = ?"; |
|---|
| 1548 | } |
|---|
| 1549 | } |
|---|
| 1550 | } |
|---|
| 1551 | $ret = $objQuery->get($table, $col, $where, $arrval); |
|---|
| 1552 | |
|---|
| 1553 | if($ret != "") { |
|---|
| 1554 | return true; |
|---|
| 1555 | } |
|---|
| 1556 | return false; |
|---|
| 1557 | } |
|---|
| 1558 | |
|---|
| 1559 | /** |
|---|
| 1560 | * メーカー商品数数の登録を行う. |
|---|
| 1561 | * |
|---|
| 1562 | * @param SC_Query $objQuery SC_Query インスタンス |
|---|
| 1563 | * @return void |
|---|
| 1564 | */ |
|---|
| 1565 | function sfMaker_Count($objQuery){ |
|---|
| 1566 | $sql = ""; |
|---|
| 1567 | |
|---|
| 1568 | //テーブル内容の削除 |
|---|
| 1569 | $objQuery->query("DELETE FROM dtb_maker_count"); |
|---|
| 1570 | |
|---|
| 1571 | //各メーカーの商品数を数えて格納 |
|---|
| 1572 | $sql = " INSERT INTO dtb_maker_count(maker_id, product_count, create_date) "; |
|---|
| 1573 | $sql .= " SELECT T1.maker_id, count(T2.maker_id), now() "; |
|---|
| 1574 | $sql .= " FROM dtb_maker AS T1 LEFT JOIN dtb_products AS T2"; |
|---|
| 1575 | $sql .= " ON T1.maker_id = T2.maker_id "; |
|---|
| 1576 | $sql .= " WHERE T2.del_flg = 0 AND T2.status = 1 "; |
|---|
| 1577 | $sql .= " GROUP BY T1.maker_id, T2.maker_id "; |
|---|
| 1578 | $objQuery->query($sql); |
|---|
| 1579 | } |
|---|
| 1580 | |
|---|
| 1581 | /** |
|---|
| 1582 | * 選択中の商品のメーカーを取得する. |
|---|
| 1583 | * |
|---|
| 1584 | * @param integer $product_id プロダクトID |
|---|
| 1585 | * @param integer $maker_id メーカーID |
|---|
| 1586 | * @return array 選択中の商品のメーカーIDの配列 |
|---|
| 1587 | * |
|---|
| 1588 | */ |
|---|
| 1589 | function sfGetMakerId($product_id, $maker_id = 0, $closed = false) { |
|---|
| 1590 | if ($closed) { |
|---|
| 1591 | $status = ""; |
|---|
| 1592 | } else { |
|---|
| 1593 | $status = "status = 1"; |
|---|
| 1594 | } |
|---|
| 1595 | |
|---|
| 1596 | if (!$this->g_maker_on) { |
|---|
| 1597 | $this->g_maker_on = true; |
|---|
| 1598 | $maker_id = (int) $maker_id; |
|---|
| 1599 | $product_id = (int) $product_id; |
|---|
| 1600 | if (SC_Utils_Ex::sfIsInt($maker_id) && $maker_id != 0 && $this->sfIsRecord("dtb_maker","maker_id", $maker_id)) { |
|---|
| 1601 | $this->g_maker_id = array($maker_id); |
|---|
| 1602 | } else if (SC_Utils_Ex::sfIsInt($product_id) && $product_id != 0 && $this->sfIsRecord("dtb_products","product_id", $product_id, $status)) { |
|---|
| 1603 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1604 | $where = "product_id = ?"; |
|---|
| 1605 | $maker_id = $objQuery->getCol("dtb_products", "maker_id", "product_id = ?", array($product_id)); |
|---|
| 1606 | $this->g_maker_id = $maker_id; |
|---|
| 1607 | } else { |
|---|
| 1608 | // 不正な場合は、空の配列を返す。 |
|---|
| 1609 | $this->g_maker_id = array(); |
|---|
| 1610 | } |
|---|
| 1611 | } |
|---|
| 1612 | return $this->g_maker_id; |
|---|
| 1613 | } |
|---|
| 1614 | |
|---|
| 1615 | /** |
|---|
| 1616 | * メーカーの取得を行う. |
|---|
| 1617 | * |
|---|
| 1618 | * $products_check:true商品登録済みのものだけ取得する |
|---|
| 1619 | * |
|---|
| 1620 | * @param string $addwhere 追加する WHERE 句 |
|---|
| 1621 | * @param bool $products_check 商品の存在するカテゴリのみ取得する場合 true |
|---|
| 1622 | * @return array カテゴリツリーの配列 |
|---|
| 1623 | */ |
|---|
| 1624 | function sfGetMakerList($addwhere = "", $products_check = false) { |
|---|
| 1625 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1626 | $where = "del_flg = 0"; |
|---|
| 1627 | |
|---|
| 1628 | if($addwhere != "") { |
|---|
| 1629 | $where.= " AND $addwhere"; |
|---|
| 1630 | } |
|---|
| 1631 | |
|---|
| 1632 | $objQuery->setOption("ORDER BY rank DESC"); |
|---|
| 1633 | |
|---|
| 1634 | if($products_check) { |
|---|
| 1635 | $col = "T1.maker_id, name"; |
|---|
| 1636 | $from = "dtb_maker AS T1 LEFT JOIN dtb_maker_count AS T2 ON T1.maker_id = T2.maker_id"; |
|---|
| 1637 | $where .= " AND product_count > 0"; |
|---|
| 1638 | } else { |
|---|
| 1639 | $col = "maker_id, name"; |
|---|
| 1640 | $from = "dtb_maker"; |
|---|
| 1641 | } |
|---|
| 1642 | |
|---|
| 1643 | $arrRet = $objQuery->select($col, $from, $where); |
|---|
| 1644 | |
|---|
| 1645 | $max = count($arrRet); |
|---|
| 1646 | for($cnt = 0; $cnt < $max; $cnt++) { |
|---|
| 1647 | $id = $arrRet[$cnt]['maker_id']; |
|---|
| 1648 | $name = $arrRet[$cnt]['name']; |
|---|
| 1649 | $arrList[$id].= $name; |
|---|
| 1650 | } |
|---|
| 1651 | return $arrList; |
|---|
| 1652 | } |
|---|
| 1653 | |
|---|
| 1654 | /** |
|---|
| 1655 | * 全商品の合計送料を加算する |
|---|
| 1656 | */ |
|---|
| 1657 | function lfAddAllProductsDelivFee(&$arrData, &$objPage, &$objCartSess) { |
|---|
| 1658 | $arrData['deliv_fee'] += $this->lfCalcAllProductsDelivFee($arrData, $objCartSess); |
|---|
| 1659 | } |
|---|
| 1660 | |
|---|
| 1661 | /** |
|---|
| 1662 | * 全商品の合計送料を計算する |
|---|
| 1663 | */ |
|---|
| 1664 | function lfCalcAllProductsDelivFee(&$arrData, &$objCartSess) { |
|---|
| 1665 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1666 | $deliv_fee_total = 0; |
|---|
| 1667 | $max = $objCartSess->getMax(); |
|---|
| 1668 | for ($i = 0; $i <= $max; $i++) { |
|---|
| 1669 | // 商品送料 |
|---|
| 1670 | $deliv_fee = $objQuery->getOne('SELECT deliv_fee FROM dtb_products WHERE product_id = ?', array($_SESSION[$objCartSess->key][$i]['id'][0])); |
|---|
| 1671 | // 数量 |
|---|
| 1672 | $quantity = $_SESSION[$objCartSess->key][$i]['quantity']; |
|---|
| 1673 | // 累積 |
|---|
| 1674 | $deliv_fee_total += $deliv_fee * $quantity; |
|---|
| 1675 | } |
|---|
| 1676 | return $deliv_fee_total; |
|---|
| 1677 | } |
|---|
| 1678 | |
|---|
| 1679 | /** |
|---|
| 1680 | * 都道府県、支払い方法から配送料金を加算する. |
|---|
| 1681 | * |
|---|
| 1682 | * @param array $arrData 各種情報 |
|---|
| 1683 | */ |
|---|
| 1684 | function lfAddDelivFee(&$arrData) { |
|---|
| 1685 | $arrData['deliv_fee'] += $this->sfGetDelivFee($arrData); |
|---|
| 1686 | } |
|---|
| 1687 | |
|---|
| 1688 | /** |
|---|
| 1689 | * 受注の名称列を更新する |
|---|
| 1690 | * |
|---|
| 1691 | * @param integer $order_id 更新対象の注文番号 |
|---|
| 1692 | * @param boolean $temp_table 更新対象は「受注_Temp」か |
|---|
| 1693 | * @static |
|---|
| 1694 | */ |
|---|
| 1695 | function sfUpdateOrderNameCol($order_id, $temp_table = false) { |
|---|
| 1696 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1697 | |
|---|
| 1698 | if ($temp_table) { |
|---|
| 1699 | $tgt_table = 'dtb_order_temp'; |
|---|
| 1700 | $sql_where = 'WHERE order_temp_id = ?'; |
|---|
| 1701 | } else { |
|---|
| 1702 | $tgt_table = 'dtb_order'; |
|---|
| 1703 | $sql_where = 'WHERE order_id = ?'; |
|---|
| 1704 | } |
|---|
| 1705 | |
|---|
| 1706 | $sql = <<< __EOS__ |
|---|
| 1707 | UPDATE |
|---|
| 1708 | {$tgt_table} |
|---|
| 1709 | SET |
|---|
| 1710 | payment_method = (SELECT payment_method FROM dtb_payment WHERE payment_id = {$tgt_table}.payment_id) |
|---|
| 1711 | ,deliv_time = (SELECT deliv_time FROM dtb_delivtime WHERE time_id = {$tgt_table}.deliv_time_id AND deliv_id = {$tgt_table}.deliv_id) |
|---|
| 1712 | $sql_where |
|---|
| 1713 | __EOS__; |
|---|
| 1714 | |
|---|
| 1715 | $objQuery->query($sql, array($order_id)); |
|---|
| 1716 | } |
|---|
| 1717 | |
|---|
| 1718 | /** |
|---|
| 1719 | * 店舗基本情報に基づいて税金額を返す |
|---|
| 1720 | * |
|---|
| 1721 | * @param integer $price 計算対象の金額 |
|---|
| 1722 | * @return integer 税金額 |
|---|
| 1723 | */ |
|---|
| 1724 | function sfTax($price) { |
|---|
| 1725 | // 店舗基本情報を取得 |
|---|
| 1726 | $CONF = SC_Helper_DB_Ex::sf_getBasisData(); |
|---|
| 1727 | |
|---|
| 1728 | return SC_Utils_Ex::sfTax($price, $CONF['tax'], $CONF['tax_rule']); |
|---|
| 1729 | } |
|---|
| 1730 | |
|---|
| 1731 | /** |
|---|
| 1732 | * 店舗基本情報に基づいて税金付与した金額を返す |
|---|
| 1733 | * |
|---|
| 1734 | * @param integer $price 計算対象の金額 |
|---|
| 1735 | * @return integer 税金付与した金額 |
|---|
| 1736 | */ |
|---|
| 1737 | function sfPreTax($price, $tax = null, $tax_rule = null) { |
|---|
| 1738 | // 店舗基本情報を取得 |
|---|
| 1739 | $CONF = SC_Helper_DB_Ex::sf_getBasisData(); |
|---|
| 1740 | |
|---|
| 1741 | return SC_Utils_Ex::sfPreTax($price, $CONF['tax'], $CONF['tax_rule']); |
|---|
| 1742 | } |
|---|
| 1743 | |
|---|
| 1744 | /** |
|---|
| 1745 | * 店舗基本情報に基づいて加算ポイントを返す |
|---|
| 1746 | * |
|---|
| 1747 | * @param integer $totalpoint |
|---|
| 1748 | * @param integer $use_point |
|---|
| 1749 | * @return integer 加算ポイント |
|---|
| 1750 | */ |
|---|
| 1751 | function sfGetAddPoint($totalpoint, $use_point) { |
|---|
| 1752 | // 店舗基本情報を取得 |
|---|
| 1753 | $CONF = SC_Helper_DB_Ex::sf_getBasisData(); |
|---|
| 1754 | |
|---|
| 1755 | return SC_Utils_Ex::sfGetAddPoint($totalpoint, $use_point, $CONF['point_rate']); |
|---|
| 1756 | } |
|---|
| 1757 | |
|---|
| 1758 | /** |
|---|
| 1759 | * 受注.対応状況の更新 |
|---|
| 1760 | * |
|---|
| 1761 | * ・必ず呼び出し元でトランザクションブロックを開いておくこと。 |
|---|
| 1762 | * |
|---|
| 1763 | * @param integer $orderId 注文番号 |
|---|
| 1764 | * @param integer|null $newStatus 対応状況 (null=変更無し) |
|---|
| 1765 | * @param integer|null $newAddPoint 加算ポイント (null=変更無し) |
|---|
| 1766 | * @param integer|null $newUsePoint 使用ポイント (null=変更無し) |
|---|
| 1767 | * @return void |
|---|
| 1768 | */ |
|---|
| 1769 | function sfUpdateOrderStatus($orderId, $newStatus = null, $newAddPoint = null, $newUsePoint = null) { |
|---|
| 1770 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1771 | |
|---|
| 1772 | $arrOrderOld = $objQuery->getRow('dtb_order', 'status, add_point, use_point, customer_id', 'order_id = ?', array($orderId)); |
|---|
| 1773 | |
|---|
| 1774 | // 対応状況が変更無しの場合、DB値を引き継ぐ |
|---|
| 1775 | if (is_null($newStatus)) { |
|---|
| 1776 | $newStatus = $arrOrderOld['status']; |
|---|
| 1777 | } |
|---|
| 1778 | |
|---|
| 1779 | // 使用ポイント、DB値を引き継ぐ |
|---|
| 1780 | if (is_null($newUsePoint)) { |
|---|
| 1781 | $newUsePoint = $arrOrderOld['use_point']; |
|---|
| 1782 | } |
|---|
| 1783 | |
|---|
| 1784 | // 加算ポイント、DB値を引き継ぐ |
|---|
| 1785 | if (is_null($newAddPoint)) { |
|---|
| 1786 | $newAddPoint = $arrOrderOld['add_point']; |
|---|
| 1787 | } |
|---|
| 1788 | |
|---|
| 1789 | if (USE_POINT !== false) { |
|---|
| 1790 | // 顧客.ポイントの加減値 |
|---|
| 1791 | $addCustomerPoint = 0; |
|---|
| 1792 | |
|---|
| 1793 | // ▼使用ポイント |
|---|
| 1794 | // 変更前の対応状況が利用対象の場合、変更前の使用ポイント分を戻す |
|---|
| 1795 | if (SC_Utils_Ex::sfIsUsePoint($arrOrderOld['status'])) { |
|---|
| 1796 | $addCustomerPoint += $arrOrderOld['use_point']; |
|---|
| 1797 | } |
|---|
| 1798 | |
|---|
| 1799 | // 変更後の対応状況が利用対象の場合、変更後の使用ポイント分を引く |
|---|
| 1800 | if (SC_Utils_Ex::sfIsUsePoint($newStatus)) { |
|---|
| 1801 | $addCustomerPoint -= $newUsePoint; |
|---|
| 1802 | } |
|---|
| 1803 | // ▲使用ポイント |
|---|
| 1804 | |
|---|
| 1805 | // ▼加算ポイント |
|---|
| 1806 | // 変更前の対応状況が加算対象の場合、変更前の加算ポイント分を戻す |
|---|
| 1807 | if (SC_Utils_Ex::sfIsAddPoint($arrOrderOld['status'])) { |
|---|
| 1808 | $addCustomerPoint -= $arrOrderOld['add_point']; |
|---|
| 1809 | } |
|---|
| 1810 | |
|---|
| 1811 | // 変更後の対応状況が加算対象の場合、変更後の加算ポイント分を足す |
|---|
| 1812 | if (SC_Utils_Ex::sfIsAddPoint($newStatus)) { |
|---|
| 1813 | $addCustomerPoint += $newAddPoint; |
|---|
| 1814 | } |
|---|
| 1815 | // ▲加算ポイント |
|---|
| 1816 | |
|---|
| 1817 | if ($addCustomerPoint != 0) { |
|---|
| 1818 | // ▼顧客テーブルの更新 |
|---|
| 1819 | $sqlval = array(); |
|---|
| 1820 | $where = ''; |
|---|
| 1821 | $arrVal = array(); |
|---|
| 1822 | $arrRawSql = array(); |
|---|
| 1823 | $arrRawSqlVal = array(); |
|---|
| 1824 | |
|---|
| 1825 | $sqlval['update_date'] = 'Now()'; |
|---|
| 1826 | $arrRawSql['point'] = 'point + ?'; |
|---|
| 1827 | $arrRawSqlVal[] = $addCustomerPoint; |
|---|
| 1828 | $where .= 'customer_id = ?'; |
|---|
| 1829 | $arrVal[] = $arrOrderOld['customer_id']; |
|---|
| 1830 | |
|---|
| 1831 | $objQuery->update('dtb_customer', $sqlval, $where, $arrVal, $arrRawSql, $arrRawSqlVal); |
|---|
| 1832 | // ▲顧客テーブルの更新 |
|---|
| 1833 | |
|---|
| 1834 | // 顧客.ポイントをマイナスした場合、 |
|---|
| 1835 | if ($addCustomerPoint < 0) { |
|---|
| 1836 | $sql = 'SELECT point FROM dtb_customer WHERE customer_id = ?'; |
|---|
| 1837 | $point = $objQuery->getOne($sql, array($arrOrderOld['customer_id'])); |
|---|
| 1838 | // 変更後の顧客.ポイントがマイナスの場合、 |
|---|
| 1839 | if ($point < 0) { |
|---|
| 1840 | // ロールバック |
|---|
| 1841 | $objQuery->rollback(); |
|---|
| 1842 | // エラー |
|---|
| 1843 | SC_Utils_Ex::sfDispSiteError(LACK_POINT); |
|---|
| 1844 | } |
|---|
| 1845 | } |
|---|
| 1846 | } |
|---|
| 1847 | } |
|---|
| 1848 | |
|---|
| 1849 | // ▼受注テーブルの更新 |
|---|
| 1850 | $sqlval = array(); |
|---|
| 1851 | if (USE_POINT !== false) { |
|---|
| 1852 | $sqlval['add_point'] = $newAddPoint; |
|---|
| 1853 | $sqlval['use_point'] = $newUsePoint; |
|---|
| 1854 | } |
|---|
| 1855 | // ステータスが発送済みに変更の場合、発送日を更新 |
|---|
| 1856 | if ($arrOrderOld['status'] != ORDER_DELIV && $newStatus == ORDER_DELIV) { |
|---|
| 1857 | $sqlval['commit_date'] = 'Now()'; |
|---|
| 1858 | } |
|---|
| 1859 | // ステータスが入金済みに変更の場合、入金日を更新 |
|---|
| 1860 | elseif ($arrOrderOld['status'] != ORDER_PRE_END && $newStatus == ORDER_PRE_END) { |
|---|
| 1861 | $sqlval['payment_date'] = 'Now()'; |
|---|
| 1862 | } |
|---|
| 1863 | |
|---|
| 1864 | $sqlval['status'] = $newStatus; |
|---|
| 1865 | $sqlval['update_date'] = 'Now()'; |
|---|
| 1866 | |
|---|
| 1867 | $objQuery->update('dtb_order', $sqlval, 'order_id = ?', array($orderId)); |
|---|
| 1868 | // ▲受注テーブルの更新 |
|---|
| 1869 | } |
|---|
| 1870 | |
|---|
| 1871 | /** |
|---|
| 1872 | * 指定ファイルが存在する場合 SQL として実行 |
|---|
| 1873 | * |
|---|
| 1874 | * XXX プラグイン用に追加。将来消すかも。 |
|---|
| 1875 | * |
|---|
| 1876 | * @param string $sqlFilePath SQL ファイルのパス |
|---|
| 1877 | * @return void |
|---|
| 1878 | */ |
|---|
| 1879 | function sfExecSqlByFile($sqlFilePath) { |
|---|
| 1880 | if (file_exists($sqlFilePath)) { |
|---|
| 1881 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1882 | |
|---|
| 1883 | $sqls = file_get_contents($sqlFilePath); |
|---|
| 1884 | if ($sqls === false) SC_Utils_Ex::sfDispException('ファイルは存在するが読み込めない'); |
|---|
| 1885 | |
|---|
| 1886 | foreach (explode(';', $sqls) as $sql) { |
|---|
| 1887 | $sql = trim($sql); |
|---|
| 1888 | if (strlen($sql) == 0) continue; |
|---|
| 1889 | $objQuery->query($sql); |
|---|
| 1890 | } |
|---|
| 1891 | } |
|---|
| 1892 | } |
|---|
| 1893 | |
|---|
| 1894 | /** |
|---|
| 1895 | * 商品規格を設定しているか |
|---|
| 1896 | * |
|---|
| 1897 | * @param integer $product_id 商品ID |
|---|
| 1898 | * @return bool 商品規格が存在する場合:true, それ以外:false |
|---|
| 1899 | */ |
|---|
| 1900 | function sfHasProductClass($product_id) { |
|---|
| 1901 | if (!SC_Utils_Ex::sfIsInt($product_id)) return false; |
|---|
| 1902 | |
|---|
| 1903 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1904 | $where = 'product_id = ? AND class_combination_id IS NOT NULL'; |
|---|
| 1905 | $count = $objQuery->count('dtb_products_class', $where, array($product_id)); |
|---|
| 1906 | |
|---|
| 1907 | return $count >= 1; |
|---|
| 1908 | } |
|---|
| 1909 | /** |
|---|
| 1910 | * カート内の商品の販売方法判定処理 |
|---|
| 1911 | * |
|---|
| 1912 | * @param $objCartSess SC_CartSession カートセッション |
|---|
| 1913 | * @return bool 0:実商品のみ 1:ダウンロード販売と実商品混在 2:全てダウンロード販売 |
|---|
| 1914 | */ |
|---|
| 1915 | function chkCartDown($objCartSess) { |
|---|
| 1916 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 1917 | $down = false; |
|---|
| 1918 | $nodown = false; |
|---|
| 1919 | $ret = 0; |
|---|
| 1920 | $arrID = $objCartSess->getAllProductID(); |
|---|
| 1921 | $table = "dtb_products_class pc"; |
|---|
| 1922 | $where = "pc.product_class_id = ?"; |
|---|
| 1923 | if(!is_null($arrID)){ |
|---|
| 1924 | //カート内のIDから販売方法を取得 |
|---|
| 1925 | foreach ($arrID as $rec) { |
|---|
| 1926 | $arrRet = $objQuery->select("pc.down AS down", $table, $where, array($rec)); |
|---|
| 1927 | if ($arrRet[0]['down'] == "2"){ |
|---|
| 1928 | $down = true; |
|---|
| 1929 | }else{ |
|---|
| 1930 | $nodown = true; |
|---|
| 1931 | } |
|---|
| 1932 | } |
|---|
| 1933 | } |
|---|
| 1934 | //混在 |
|---|
| 1935 | if($nodown && $down){ |
|---|
| 1936 | $ret = 1; |
|---|
| 1937 | //全てダウンロード商品 |
|---|
| 1938 | }else if(!$nodown && $down){ |
|---|
| 1939 | $ret = 2; |
|---|
| 1940 | } |
|---|
| 1941 | return $ret; |
|---|
| 1942 | } |
|---|
| 1943 | |
|---|
| 1944 | /* 会員情報の住所を一時受注テーブルへ */ |
|---|
| 1945 | function sfRegistDelivData($uniqid, $objCustomer) { |
|---|
| 1946 | |
|---|
| 1947 | // 登録データの作成 |
|---|
| 1948 | $sqlval['order_temp_id'] = $uniqid; |
|---|
| 1949 | $sqlval['update_date'] = 'Now()'; |
|---|
| 1950 | $sqlval['customer_id'] = $objCustomer->getValue('customer_id'); |
|---|
| 1951 | $sqlval['deliv_check'] = '-1'; |
|---|
| 1952 | $sqlval['order_name01'] = $objCustomer->getValue('name01'); |
|---|
| 1953 | $sqlval['order_name02'] = $objCustomer->getValue('name02'); |
|---|
| 1954 | $sqlval['order_kana01'] = $objCustomer->getValue('kana01'); |
|---|
| 1955 | $sqlval['order_kana02'] = $objCustomer->getValue('kana02'); |
|---|
| 1956 | $sqlval['order_zip01'] = $objCustomer->getValue('zip01'); |
|---|
| 1957 | $sqlval['order_zip02'] = $objCustomer->getValue('zip02'); |
|---|
| 1958 | $sqlval['order_pref'] = $objCustomer->getValue('pref'); |
|---|
| 1959 | $sqlval['order_addr01'] = $objCustomer->getValue('addr01'); |
|---|
| 1960 | $sqlval['order_addr02'] = $objCustomer->getValue('addr02'); |
|---|
| 1961 | $sqlval['order_tel01'] = $objCustomer->getValue('tel01'); |
|---|
| 1962 | $sqlval['order_tel02'] = $objCustomer->getValue('tel02'); |
|---|
| 1963 | $sqlval['order_tel03'] = $objCustomer->getValue('tel03'); |
|---|
| 1964 | $sqlval['order_fax01'] = $objCustomer->getValue('fax01'); |
|---|
| 1965 | $sqlval['order_fax02'] = $objCustomer->getValue('fax02'); |
|---|
| 1966 | $sqlval['order_fax03'] = $objCustomer->getValue('fax03'); |
|---|
| 1967 | $sqlval['deliv_name01'] = $objCustomer->getValue('name01'); |
|---|
| 1968 | $sqlval['deliv_name02'] = $objCustomer->getValue('name02'); |
|---|
| 1969 | $sqlval['deliv_kana01'] = $objCustomer->getValue('kana01'); |
|---|
| 1970 | $sqlval['deliv_kana02'] = $objCustomer->getValue('kana02'); |
|---|
| 1971 | $sqlval['deliv_zip01'] = $objCustomer->getValue('zip01'); |
|---|
| 1972 | $sqlval['deliv_zip02'] = $objCustomer->getValue('zip02'); |
|---|
| 1973 | $sqlval['deliv_pref'] = $objCustomer->getValue('pref'); |
|---|
| 1974 | $sqlval['deliv_addr01'] = $objCustomer->getValue('addr01'); |
|---|
| 1975 | $sqlval['deliv_addr02'] = $objCustomer->getValue('addr02'); |
|---|
| 1976 | $sqlval['deliv_tel01'] = $objCustomer->getValue('tel01'); |
|---|
| 1977 | $sqlval['deliv_tel02'] = $objCustomer->getValue('tel02'); |
|---|
| 1978 | $sqlval['deliv_tel03'] = $objCustomer->getValue('tel03'); |
|---|
| 1979 | $sqlval['deliv_fax01'] = $objCustomer->getValue('fax01'); |
|---|
| 1980 | $sqlval['deliv_fax02'] = $objCustomer->getValue('fax02'); |
|---|
| 1981 | $sqlval['deliv_fax03'] = $objCustomer->getValue('fax03'); |
|---|
| 1982 | |
|---|
| 1983 | $this->sfRegistTempOrder($uniqid, $sqlval); |
|---|
| 1984 | } |
|---|
| 1985 | } |
|---|
| 1986 | ?> |
|---|