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

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