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

Revision 18217, 71.0 KB checked in by Seasoft, 15 years ago (diff)

#454(非公開の商品を購入できる)を改修

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