source: branches/comu-ver2/data/class/helper/SC_Helper_DB.php @ 18370

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