Warning: Can't use blame annotator:
svn blame failed on branches/comu-ver2/data/class/helper/SC_Helper_DB.php: バイナリファイル 'file:///home/svn/open/branches/comu-ver2/data/class/helper/SC_Helper_DB.php' に対しては blame で各行の最終変更者を計算できません 195004

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

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