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