source: branches/feature-module-update/data/class/helper/SC_Helper_DB.php @ 15604

Revision 15604, 49.2 KB checked in by nanasess, 17 years ago (diff)

リファクタリング

  • DB インスタンスを生成する関数の移動
  • 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 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8/**
9 * DB関連のヘルパークラス.
10 *
11 * @package Helper
12 * @author LOCKON CO.,LTD.
13 * @version $Id:SC_Helper_DB.php 15532 2007-08-31 14:39:46Z nanasess $
14 */
15class SC_Helper_DB {
16
17    // {{{ properties
18
19    /** ルートカテゴリ取得フラグ */
20    var $g_root_on;
21
22    /** ルートカテゴリID */
23    var $g_root_id;
24
25    /** 選択中カテゴリ取得フラグ */
26    var $g_category_on;
27
28    /** 選択中カテゴリID */
29    var $g_category_id;
30
31    // }}}
32    // {{{ functions
33
34    /**
35     * データベースのバージョンを所得する.
36     *
37     * @param string $dsn データソース名
38     * @return string データベースのバージョン
39     */
40    function sfGetDBVersion($dsn = "") {
41        $dbFactory = SC_DB_DBFactory::getInstance();
42        return $dbFactory->sfGetDBVersion($dsn);
43    }
44
45    /**
46     * テーブルの存在をチェックする.
47     *
48     * @param string $table_name チェック対象のテーブル名
49     * @param string $dsn データソース名
50     * @return テーブルが存在する場合 true
51     */
52    function sfTabaleExists($table_name, $dsn = "") {
53        $dbFactory = SC_DB_DBFactory::getInstance();
54        $dsn = $dbFactory->getDSN($dsn);
55
56        $objQuery = new SC_Query($dsn, true, true);
57        // 正常に接続されている場合
58        if(!$objQuery->isError()) {
59            list($db_type) = split(":", $dsn);
60            $sql = $dbFactory->getTableExistsSql();
61            $arrRet = $objQuery->getAll($sql, array($table_name));
62            if(count($arrRet) > 0) {
63                return true;
64            }
65        }
66        return false;
67    }
68
69    /**
70     * カラムの存在チェックと作成を行う.
71     *
72     * チェック対象のテーブルに, 該当のカラムが存在するかチェックする.
73     * 引数 $add が true の場合, 該当のカラムが存在しない場合は, カラムの生成を行う.
74     * カラムの生成も行う場合は, $col_type も必須となる.
75     *
76     * @param string $table_name テーブル名
77     * @param string $column_name カラム名
78     * @param string $col_type カラムのデータ型
79     * @param string $dsn データソース名
80     * @param bool $add カラムの作成も行う場合 true
81     * @return bool カラムが存在する場合とカラムの生成に成功した場合 true,
82     *               テーブルが存在しない場合 false,
83     *               引数 $add == false でカラムが存在しない場合 false
84     */
85    function sfColumnExists($table_name, $col_name, $col_type = "", $dsn = "", $add = false) {
86        $dbFactory = SC_DB_DBFactory::getInstance();
87        $dsn = $dbFactory->getDSN($dsn);
88
89        // テーブルが無ければエラー
90        if(!$this->sfTabaleExists($table_name, $dsn)) return false;
91
92        $objQuery = new SC_Query($dsn, true, true);
93        // 正常に接続されている場合
94        if(!$objQuery->isError()) {
95            list($db_type) = split(":", $dsn);
96
97            // カラムリストを取得
98            $arrRet = $dbFactory->sfGetColumnList($table_name);
99            if(count($arrRet) > 0) {
100                if(in_array($col_name, $arrRet)){
101                    return true;
102                }
103            }
104        }
105
106        // カラムを追加する
107        if($add){
108            $objQuery->query("ALTER TABLE $table_name ADD $col_name $col_type ");
109            return true;
110        }
111        return false;
112    }
113
114    /**
115     * インデックスの存在チェックと作成を行う.
116     *
117     * チェック対象のテーブルに, 該当のインデックスが存在するかチェックする.
118     * 引数 $add が true の場合, 該当のインデックスが存在しない場合は, インデックスの生成を行う.
119     * インデックスの生成も行う場合で, DB_TYPE が mysql の場合は, $length も必須となる.
120     *
121     * @param string $table_name テーブル名
122     * @param string $column_name カラム名
123     * @param string $index_name インデックス名
124     * @param integer|string $length インデックスを作成するデータ長
125     * @param string $dsn データソース名
126     * @param bool $add インデックスの生成もする場合 true
127     * @return bool インデックスが存在する場合とインデックスの生成に成功した場合 true,
128     *               テーブルが存在しない場合 false,
129     *               引数 $add == false でインデックスが存在しない場合 false
130     */
131    function sfIndexExists($table_name, $col_name, $index_name, $length = "", $dsn = "", $add = false) {
132        $dbFactory = SC_DB_DBFactory::getInstance();
133        $dsn = $dbFactory->getDSN($dsn);
134
135        // テーブルが無ければエラー
136        if (!$this->sfTabaleExists($table_name, $dsn)) return false;
137
138        $objQuery = new SC_Query($dsn, true, true);
139        $arrRet = $dbFactory->getTableIndex($index_name, $table_name);
140
141        // すでにインデックスが存在する場合
142        if(count($arrRet) > 0) {
143            return true;
144        }
145
146        // インデックスを作成する
147        if($add){
148            $dbFactory->createTableIndex($index_name, $table_name, $col_name, $length());
149            return true;
150        }
151        return false;
152    }
153
154    /**
155     * データの存在チェックを行う.
156     *
157     * @param string $table_name テーブル名
158     * @param string $where データを検索する WHERE 句
159     * @param string $dsn データソース名
160     * @param string $sql データの追加を行う場合の SQL文
161     * @param bool $add データの追加も行う場合 true
162     * @return bool データが存在する場合 true, データの追加に成功した場合 true,
163     *               $add == false で, データが存在しない場合 false
164     */
165    function sfDataExists($table_name, $where, $arrval, $dsn = "", $sql = "", $add = false) {
166        $dbFactory = SC_DB_DBFactory::getInstance();
167        $dsn = $dbFactory->getDSN($dsn);
168
169        $objQuery = new SC_Query($dsn, true, true);
170        $count = $objQuery->count($table_name, $where, $arrval);
171
172        if($count > 0) {
173            $ret = true;
174        } else {
175            $ret = false;
176        }
177        // データを追加する
178        if(!$ret && $add) {
179            $objQuery->exec($sql);
180        }
181        return $ret;
182    }
183
184    /**
185     * 店舗基本情報を取得する.
186     *
187     * @return array 店舗基本情報の配列
188     */
189    function sf_getBasisData() {
190        //DBから設定情報を取得
191        $objConn = new SC_DbConn();
192        $result = $objConn->getAll("SELECT * FROM dtb_baseinfo");
193        if(is_array($result[0])) {
194            foreach ( $result[0] as $key=>$value ){
195                $CONF["$key"] = $value;
196            }
197        }
198        return $CONF;
199    }
200
201    /* 選択中のアイテムのルートカテゴリIDを取得する */
202    function sfGetRootId() {
203
204        if(!$this->g_root_on)   {
205            $this->g_root_on = true;
206            $objQuery = new SC_Query();
207
208            if (!isset($_GET['product_id'])) $_GET['product_id'] = "";
209            if (!isset($_GET['category_id'])) $_GET['category_id'] = "";
210
211            if(!empty($_GET['product_id']) || !empty($_GET['category_id'])) {
212                // 選択中のカテゴリIDを判定する
213                $category_id = $this->sfGetCategoryId($_GET['product_id'], $_GET['category_id']);
214                // ROOTカテゴリIDの取得
215                $arrRet = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id);
216                $root_id = $arrRet[0];
217            } else {
218                // ROOTカテゴリIDをなしに設定する
219                $root_id = "";
220            }
221            $this->g_root_id = $root_id;
222        }
223        return $this->g_root_id;
224    }
225
226    /**
227     * 商品規格情報を取得する.
228     *
229     * @param array $arrID 規格ID
230     * @return array 規格情報の配列
231     */
232    function sfGetProductsClass($arrID) {
233        list($product_id, $classcategory_id1, $classcategory_id2) = $arrID;
234
235        if($classcategory_id1 == "") {
236            $classcategory_id1 = '0';
237        }
238        if($classcategory_id2 == "") {
239            $classcategory_id2 = '0';
240        }
241
242        // 商品規格取得
243        $objQuery = new SC_Query();
244        $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";
245        $table = "vw_product_class AS prdcls";
246        $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?";
247        $objQuery->setorder("rank1 DESC, rank2 DESC");
248        $arrRet = $objQuery->select($col, $table, $where, array($product_id, $classcategory_id1, $classcategory_id2));
249        return $arrRet[0];
250    }
251
252    /**
253     * 支払い方法を取得する.
254     *
255     * @return void
256     */
257    function sfGetPayment() {
258        $objQuery = new SC_Query();
259        // 購入金額が条件額以下の項目を取得
260        $where = "del_flg = 0";
261        $objQuery->setorder("fix, rank DESC");
262        $arrRet = $objQuery->select("payment_id, payment_method, rule", "dtb_payment", $where);
263        return $arrRet;
264    }
265
266    /**
267     * カート内商品の集計処理を行う.
268     *
269     * @param LC_Page $objPage ページクラスのインスタンス
270     * @param SC_CartSession $objCartSess カートセッションのインスタンス
271     * @param array $arrInfo 商品情報の配列
272     * @return LC_Page 集計処理後のページクラスインスタンス
273     */
274    function sfTotalCart(&$objPage, $objCartSess, $arrInfo) {
275        $objDb = new SC_Helper_DB_Ex();
276        // 規格名一覧
277        $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name");
278        // 規格分類名一覧
279        $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
280
281        $objPage->tpl_total_pretax = 0;     // 費用合計(税込み)
282        $objPage->tpl_total_tax = 0;        // 消費税合計
283        $objPage->tpl_total_point = 0;      // ポイント合計
284
285        // カート内情報の取得
286        $arrCart = $objCartSess->getCartList();
287        $max = count($arrCart);
288        $cnt = 0;
289
290        for ($i = 0; $i < $max; $i++) {
291            // 商品規格情報の取得
292            $arrData = $this->sfGetProductsClass($arrCart[$i]['id']);
293            $limit = "";
294            // DBに存在する商品
295            if (count($arrData) > 0) {
296
297                // 購入制限数を求める。
298                if ($arrData['stock_unlimited'] != '1' && $arrData['sale_unlimited'] != '1') {
299                    if($arrData['sale_limit'] < $arrData['stock']) {
300                        $limit = $arrData['sale_limit'];
301                    } else {
302                        $limit = $arrData['stock'];
303                    }
304                } else {
305                    if ($arrData['sale_unlimited'] != '1') {
306                        $limit = $arrData['sale_limit'];
307                    }
308                    if ($arrData['stock_unlimited'] != '1') {
309                        $limit = $arrData['stock'];
310                    }
311                }
312
313                if($limit != "" && $limit < $arrCart[$i]['quantity']) {
314                    // カート内商品数を制限に合わせる
315                    $objCartSess->setProductValue($arrCart[$i]['id'], 'quantity', $limit);
316                    $quantity = $limit;
317                    $objPage->tpl_message = "※「" . $arrData['name'] . "」は販売制限しております、一度にこれ以上の購入はできません。";
318                } else {
319                    $quantity = $arrCart[$i]['quantity'];
320                }
321
322                $objPage->arrProductsClass[$cnt] = $arrData;
323                $objPage->arrProductsClass[$cnt]['quantity'] = $quantity;
324                $objPage->arrProductsClass[$cnt]['cart_no'] = $arrCart[$i]['cart_no'];
325                $objPage->arrProductsClass[$cnt]['class_name1'] =
326                    isset($arrClassName[$arrData['class_id1']])
327                        ? $arrClassName[$arrData['class_id1']] : "";
328
329                $objPage->arrProductsClass[$cnt]['class_name2'] =
330                    isset($arrClassName[$arrData['class_id2']])
331                        ? $arrClassName[$arrData['class_id2']] : "";
332
333                $objPage->arrProductsClass[$cnt]['classcategory_name1'] =
334                    $arrClassCatName[$arrData['classcategory_id1']];
335
336                $objPage->arrProductsClass[$cnt]['classcategory_name2'] =
337                    $arrClassCatName[$arrData['classcategory_id2']];
338
339                // 画像サイズ
340                list($image_width, $image_height) = getimagesize(IMAGE_SAVE_DIR . basename($objPage->arrProductsClass[$cnt]["main_image"]));
341                $objPage->arrProductsClass[$cnt]["tpl_image_width"] = $image_width + 60;
342                $objPage->arrProductsClass[$cnt]["tpl_image_height"] = $image_height + 80;
343
344                // 価格の登録
345                if ($arrData['price02'] != "") {
346                    $objCartSess->setProductValue($arrCart[$i]['id'], 'price', $arrData['price02']);
347                    $objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price02'];
348                } else {
349                    $objCartSess->setProductValue($arrCart[$i]['id'], 'price', $arrData['price01']);
350                    $objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price01'];
351                }
352                // ポイント付与率の登録
353                $objCartSess->setProductValue($arrCart[$i]['id'], 'point_rate', $arrData['point_rate']);
354                // 商品ごとの合計金額
355                $objPage->arrProductsClass[$cnt]['total_pretax'] = $objCartSess->getProductTotal($arrInfo, $arrCart[$i]['id']);
356                // 送料の合計を計算する
357                $objPage->tpl_total_deliv_fee+= ($arrData['deliv_fee'] * $arrCart[$i]['quantity']);
358                $cnt++;
359            } else {
360                // DBに商品が見つからない場合はカート商品の削除
361                $objCartSess->delProductKey('id', $arrCart[$i]['id']);
362            }
363        }
364
365        // 全商品合計金額(税込み)
366        $objPage->tpl_total_pretax = $objCartSess->getAllProductsTotal($arrInfo);
367        // 全商品合計消費税
368        $objPage->tpl_total_tax = $objCartSess->getAllProductsTax($arrInfo);
369        // 全商品合計ポイント
370        $objPage->tpl_total_point = $objCartSess->getAllProductsPoint();
371
372        return $objPage;
373    }
374
375    /**
376     * 受注一時テーブルへの書き込み処理を行う.
377     *
378     * @param string $uniqid ユニークID
379     * @param array $sqlval SQLの値の配列
380     * @return void
381     */
382    function sfRegistTempOrder($uniqid, $sqlval) {
383        if($uniqid != "") {
384            // 既存データのチェック
385            $objQuery = new SC_Query();
386            $where = "order_temp_id = ?";
387            $cnt = $objQuery->count("dtb_order_temp", $where, array($uniqid));
388            // 既存データがない場合
389            if ($cnt == 0) {
390                // 初回書き込み時に会員の登録済み情報を取り込む
391                $sqlval = $this->sfGetCustomerSqlVal($uniqid, $sqlval);
392                $sqlval['create_date'] = "now()";
393                $objQuery->insert("dtb_order_temp", $sqlval);
394            } else {
395                $objQuery->update("dtb_order_temp", $sqlval, $where, array($uniqid));
396            }
397        }
398    }
399
400    /**
401     * 会員情報から SQL文の値を生成する.
402     *
403     * @param string $uniqid ユニークID
404     * @param array $sqlval SQL の値の配列
405     * @return array 会員情報を含んだ SQL の値の配列
406     */
407    function sfGetCustomerSqlVal($uniqid, $sqlval) {
408        $objCustomer = new SC_Customer();
409        // 会員情報登録処理
410        if ($objCustomer->isLoginSuccess()) {
411            // 登録データの作成
412            $sqlval['order_temp_id'] = $uniqid;
413            $sqlval['update_date'] = 'Now()';
414            $sqlval['customer_id'] = $objCustomer->getValue('customer_id');
415            $sqlval['order_name01'] = $objCustomer->getValue('name01');
416            $sqlval['order_name02'] = $objCustomer->getValue('name02');
417            $sqlval['order_kana01'] = $objCustomer->getValue('kana01');
418            $sqlval['order_kana02'] = $objCustomer->getValue('kana02');
419            $sqlval['order_sex'] = $objCustomer->getValue('sex');
420            $sqlval['order_zip01'] = $objCustomer->getValue('zip01');
421            $sqlval['order_zip02'] = $objCustomer->getValue('zip02');
422            $sqlval['order_pref'] = $objCustomer->getValue('pref');
423            $sqlval['order_addr01'] = $objCustomer->getValue('addr01');
424            $sqlval['order_addr02'] = $objCustomer->getValue('addr02');
425            $sqlval['order_tel01'] = $objCustomer->getValue('tel01');
426            $sqlval['order_tel02'] = $objCustomer->getValue('tel02');
427            $sqlval['order_tel03'] = $objCustomer->getValue('tel03');
428            if (defined('MOBILE_SITE')) {
429                $sqlval['order_email'] = $objCustomer->getValue('email_mobile');
430            } else {
431                $sqlval['order_email'] = $objCustomer->getValue('email');
432            }
433            $sqlval['order_job'] = $objCustomer->getValue('job');
434            $sqlval['order_birth'] = $objCustomer->getValue('birth');
435        }
436        return $sqlval;
437    }
438
439    /**
440     * 会員編集登録処理を行う.
441     *
442     * @param array $array パラメータの配列
443     * @param array $arrRegistColumn 登録するカラムの配列
444     * @return void
445     */
446    function sfEditCustomerData($array, $arrRegistColumn) {
447        $objQuery = new SC_Query();
448
449        foreach ($arrRegistColumn as $data) {
450            if ($data["column"] != "password") {
451                if($array[ $data['column'] ] != "") {
452                    $arrRegist[ $data["column"] ] = $array[ $data["column"] ];
453                } else {
454                    $arrRegist[ $data['column'] ] = NULL;
455                }
456            }
457        }
458        if (strlen($array["year"]) > 0 && strlen($array["month"]) > 0 && strlen($array["day"]) > 0) {
459            $arrRegist["birth"] = $array["year"] ."/". $array["month"] ."/". $array["day"] ." 00:00:00";
460        } else {
461            $arrRegist["birth"] = NULL;
462        }
463
464        //-- パスワードの更新がある場合は暗号化。(更新がない場合はUPDATE文を構成しない)
465        if ($array["password"] != DEFAULT_PASSWORD) $arrRegist["password"] = sha1($array["password"] . ":" . AUTH_MAGIC);
466        $arrRegist["update_date"] = "NOW()";
467
468        //-- 編集登録実行
469        if (defined('MOBILE_SITE')) {
470            $arrRegist['email_mobile'] = $arrRegist['email'];
471            unset($arrRegist['email']);
472        }
473        $objQuery->begin();
474        $objQuery->update("dtb_customer", $arrRegist, "customer_id = ? ", array($array['customer_id']));
475        $objQuery->commit();
476    }
477
478    /**
479     * 受注番号、利用ポイント、加算ポイントから最終ポイントを取得する.
480     *
481     * @param integer $order_id 受注番号
482     * @param integer $use_point 利用ポイント
483     * @param integer $add_point 加算ポイント
484     * @return array 最終ポイントの配列
485     */
486    function sfGetCustomerPoint($order_id, $use_point, $add_point) {
487        $objQuery = new SC_Query();
488        $arrRet = $objQuery->select("customer_id", "dtb_order", "order_id = ?", array($order_id));
489        $customer_id = $arrRet[0]['customer_id'];
490        if($customer_id != "" && $customer_id >= 1) {
491            $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id));
492            $point = $arrRet[0]['point'];
493            $total_point = $arrRet[0]['point'] - $use_point + $add_point;
494        } else {
495            $total_point = "";
496            $point = "";
497        }
498        return array($point, $total_point);
499    }
500
501    /**
502     * カテゴリツリーの取得を行う.
503     *
504     * @param integer $parent_category_id 親カテゴリID
505     * @param bool $count_check 登録商品数のチェックを行う場合 true
506     * @return array カテゴリツリーの配列
507     */
508    function sfGetCatTree($parent_category_id, $count_check = false) {
509        $objQuery = new SC_Query();
510        $col = "";
511        $col .= " cat.category_id,";
512        $col .= " cat.category_name,";
513        $col .= " cat.parent_category_id,";
514        $col .= " cat.level,";
515        $col .= " cat.rank,";
516        $col .= " cat.creator_id,";
517        $col .= " cat.create_date,";
518        $col .= " cat.update_date,";
519        $col .= " cat.del_flg, ";
520        $col .= " ttl.product_count";
521        $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id";
522        // 登録商品数のチェック
523        if($count_check) {
524            $where = "del_flg = 0 AND product_count > 0";
525        } else {
526            $where = "del_flg = 0";
527        }
528        $objQuery->setoption("ORDER BY rank DESC");
529        $arrRet = $objQuery->select($col, $from, $where);
530
531        $arrParentID = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id);
532
533        foreach($arrRet as $key => $array) {
534            foreach($arrParentID as $val) {
535                if($array['category_id'] == $val) {
536                    $arrRet[$key]['display'] = 1;
537                    break;
538                }
539            }
540        }
541
542        return $arrRet;
543    }
544
545    /**
546     * 親カテゴリーを連結した文字列を取得する.
547     *
548     * @param integer $category_id カテゴリID
549     * @return string 親カテゴリーを連結した文字列
550     */
551    function sfGetCatCombName($category_id){
552        // 商品が属するカテゴリIDを縦に取得
553        $objQuery = new SC_Query();
554        $arrCatID = sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
555        $ConbName = "";
556
557        // カテゴリー名称を取得する
558        foreach($arrCatID as $key => $val){
559            $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
560            $arrVal = array($val);
561            $CatName = $objQuery->getOne($sql,$arrVal);
562            $ConbName .= $CatName . ' | ';
563        }
564        // 最後の | をカットする
565        $ConbName = substr_replace($ConbName, "", strlen($ConbName) - 2, 2);
566
567        return $ConbName;
568    }
569
570    /**
571     * 指定したカテゴリーIDの大カテゴリーを取得する.
572     *
573     * @param integer $category_id カテゴリID
574     * @return array 指定したカテゴリーIDの大カテゴリー
575     */
576    function sfGetFirstCat($category_id){
577        // 商品が属するカテゴリIDを縦に取得
578        $objQuery = new SC_Query();
579        $arrRet = array();
580        $arrCatID = $this->sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id);
581        $arrRet['id'] = $arrCatID[0];
582
583        // カテゴリー名称を取得する
584        $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?";
585        $arrVal = array($arrRet['id']);
586        $arrRet['name'] = $objQuery->getOne($sql,$arrVal);
587
588        return $arrRet;
589    }
590
591    /**
592     * カテゴリツリーの取得を行う.
593     *
594     * $products_check:true商品登録済みのものだけ取得する
595     *
596     * @param string $addwhere 追加する WHERE 句
597     * @param bool $products_check 商品の存在するカテゴリのみ取得する場合 true
598     * @param string $head カテゴリ名のプレフィックス文字列
599     * @return array カテゴリツリーの配列
600     */
601    function sfGetCategoryList($addwhere = "", $products_check = false, $head = CATEGORY_HEAD) {
602        $objQuery = new SC_Query();
603        $where = "del_flg = 0";
604
605        if($addwhere != "") {
606            $where.= " AND $addwhere";
607        }
608
609        $objQuery->setoption("ORDER BY rank DESC");
610
611        if($products_check) {
612            $col = "T1.category_id, category_name, level";
613            $from = "dtb_category AS T1 LEFT JOIN dtb_category_total_count AS T2 ON T1.category_id = T2.category_id";
614            $where .= " AND product_count > 0";
615        } else {
616            $col = "category_id, category_name, level";
617            $from = "dtb_category";
618        }
619
620        $arrRet = $objQuery->select($col, $from, $where);
621
622        $max = count($arrRet);
623        for($cnt = 0; $cnt < $max; $cnt++) {
624            $id = $arrRet[$cnt]['category_id'];
625            $name = $arrRet[$cnt]['category_name'];
626            $arrList[$id] = "";
627            /*
628            for($n = 1; $n < $arrRet[$cnt]['level']; $n++) {
629                $arrList[$id].= " ";
630            }
631            */
632            for($cat_cnt = 0; $cat_cnt < $arrRet[$cnt]['level']; $cat_cnt++) {
633                $arrList[$id].= $head;
634            }
635            $arrList[$id].= $name;
636        }
637        return $arrList;
638    }
639
640    /**
641     * カテゴリーツリーの取得を行う.
642     *
643     * 親カテゴリの Value=0 を対象とする
644     *
645     * @param bool $parent_zero 親カテゴリの Value=0 の場合 true
646     * @return array カテゴリツリーの配列
647     */
648    function sfGetLevelCatList($parent_zero = true) {
649        $objQuery = new SC_Query();
650        $col = "category_id, category_name, level";
651        $where = "del_flg = 0";
652        $objQuery->setoption("ORDER BY rank DESC");
653        $arrRet = $objQuery->select($col, "dtb_category", $where);
654        $max = count($arrRet);
655
656        for($cnt = 0; $cnt < $max; $cnt++) {
657            if($parent_zero) {
658                if($arrRet[$cnt]['level'] == LEVEL_MAX) {
659                    $arrValue[$cnt] = $arrRet[$cnt]['category_id'];
660                } else {
661                    $arrValue[$cnt] = "";
662                }
663            } else {
664                $arrValue[$cnt] = $arrRet[$cnt]['category_id'];
665            }
666
667            $arrOutput[$cnt] = "";
668            /*
669            for($n = 1; $n < $arrRet[$cnt]['level']; $n++) {
670                $arrOutput[$cnt].= " ";
671            }
672            */
673            for($cat_cnt = 0; $cat_cnt < $arrRet[$cnt]['level']; $cat_cnt++) {
674                $arrOutput[$cnt].= CATEGORY_HEAD;
675            }
676            $arrOutput[$cnt].= $arrRet[$cnt]['category_name'];
677        }
678        return array($arrValue, $arrOutput);
679    }
680
681    /**
682     * 選択中のカテゴリを取得する.
683     *
684     * @param integer $product_id プロダクトID
685     * @param integer $category_id カテゴリID
686     * @return integer 選択中のカテゴリID
687     *
688     */
689    function sfGetCategoryId($product_id, $category_id) {
690
691        if(!$this->g_category_on)   {
692            $this->g_category_on = true;
693            $category_id = (int) $category_id;
694            $product_id = (int) $product_id;
695            if(SC_Utils_Ex::sfIsInt($category_id) && $this->sfIsRecord("dtb_category","category_id", $category_id)) {
696                $this->g_category_id = $category_id;
697            } else if (SC_Utils_Ex::sfIsInt($product_id) && $this->sfIsRecord("dtb_products","product_id", $product_id, "status = 1")) {
698                $objQuery = new SC_Query();
699                $where = "product_id = ?";
700                $category_id = $objQuery->get("dtb_products", "category_id", $where, array($product_id));
701                $this->g_category_id = $category_id;
702            } else {
703                // 不正な場合は、0を返す。
704                $this->g_category_id = 0;
705            }
706        }
707        return $this->g_category_id;
708    }
709
710    /**
711     * カテゴリ数の登録を行う.
712     *
713     * @param SC_Query $objQuery SC_Query インスタンス
714     * @return void
715     */
716    function sfCategory_Count($objQuery){
717        $sql = "";
718
719        //テーブル内容の削除
720        $objQuery->query("DELETE FROM dtb_category_count");
721        $objQuery->query("DELETE FROM dtb_category_total_count");
722
723        //各カテゴリ内の商品数を数えて格納
724        $sql = " INSERT INTO dtb_category_count(category_id, product_count, create_date) ";
725        $sql .= " SELECT T1.category_id, count(T2.category_id), now() FROM dtb_category AS T1 LEFT JOIN dtb_products AS T2 ";
726        $sql .= " ON T1.category_id = T2.category_id  ";
727        $sql .= " WHERE T2.del_flg = 0 AND T2.status = 1 ";
728        $sql .= " GROUP BY T1.category_id, T2.category_id ";
729        $objQuery->query($sql);
730
731        //子カテゴリ内の商品数を集計する
732        $arrCat = $objQuery->getAll("SELECT * FROM dtb_category");
733
734        $sql = "";
735        foreach($arrCat as $key => $val){
736
737            // 子ID一覧を取得
738            $arrRet = $this->sfGetChildrenArray('dtb_category', 'parent_category_id', 'category_id', $val['category_id']);
739            $line = SC_Utils_Ex::sfGetCommaList($arrRet);
740
741            $sql = " INSERT INTO dtb_category_total_count(category_id, product_count, create_date) ";
742            $sql .= " SELECT ?, SUM(product_count), now() FROM dtb_category_count ";
743            $sql .= " WHERE category_id IN (" . $line . ")";
744
745            $objQuery->query($sql, array($val['category_id']));
746        }
747    }
748
749    /**
750     * 子IDの配列を返す.
751     *
752     * @param string $table テーブル名
753     * @param string $pid_name 親ID名
754     * @param string $id_name ID名
755     * @param integer $id ID
756     * @param array 子ID の配列
757     */
758    function sfGetChildsID($table, $pid_name, $id_name, $id) {
759        $arrRet = $this->sfGetChildrenArray($table, $pid_name, $id_name, $id);
760        return $arrRet;
761    }
762
763    /**
764     * 階層構造のテーブルから子ID配列を取得する.
765     *
766     * @param string $table テーブル名
767     * @param string $pid_name 親ID名
768     * @param string $id_name ID名
769     * @param integer $id ID番号
770     * @return array 子IDの配列
771     */
772    function sfGetChildrenArray($table, $pid_name, $id_name, $id) {
773        $objQuery = new SC_Query();
774        $col = $pid_name . "," . $id_name;
775         $arrData = $objQuery->select($col, $table);
776
777        $arrPID = array();
778        $arrPID[] = $id;
779        $arrChildren = array();
780        $arrChildren[] = $id;
781
782        $arrRet = $this->sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID);
783
784        while(count($arrRet) > 0) {
785            $arrChildren = array_merge($arrChildren, $arrRet);
786            $arrRet = $this->sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrRet);
787        }
788
789        return $arrChildren;
790    }
791
792    /**
793     * 親ID直下の子IDをすべて取得する.
794     *
795     * @param array $arrData 親カテゴリの配列
796     * @param string $pid_name 親ID名
797     * @param string $id_name ID名
798     * @param array $arrPID 親IDの配列
799     * @return array 子IDの配列
800     */
801    function sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID) {
802        $arrChildren = array();
803        $max = count($arrData);
804
805        for($i = 0; $i < $max; $i++) {
806            foreach($arrPID as $val) {
807                if($arrData[$i][$pid_name] == $val) {
808                    $arrChildren[] = $arrData[$i][$id_name];
809                }
810            }
811        }
812        return $arrChildren;
813    }
814
815    /**
816     * 所属するすべての階層の親IDを配列で返す.
817     *
818     * @param SC_Query $objQuery SC_Query インスタンス
819     * @param string $table テーブル名
820     * @param string $pid_name 親ID名
821     * @param string $id_name ID名
822     * @param integer $id ID
823     * @return array 親IDの配列
824     */
825    function sfGetParents($objQuery, $table, $pid_name, $id_name, $id) {
826        $arrRet = $this->sfGetParentsArray($table, $pid_name, $id_name, $id);
827        // 配列の先頭1つを削除する。
828        array_shift($arrRet);
829        return $arrRet;
830    }
831
832    /**
833     * 階層構造のテーブルから親ID配列を取得する.
834     *
835     * @param string $table テーブル名
836     * @param string $pid_name 親ID名
837     * @param string $id_name ID名
838     * @param integer $id ID
839     * @return array 親IDの配列
840     */
841    function sfGetParentsArray($table, $pid_name, $id_name, $id) {
842        $objQuery = new SC_Query();
843        $col = $pid_name . "," . $id_name;
844         $arrData = $objQuery->select($col, $table);
845
846        $arrParents = array();
847        $arrParents[] = $id;
848        $child = $id;
849
850        $ret = SC_Utils::sfGetParentsArraySub($arrData, $pid_name, $id_name, $child);
851
852        while($ret != "") {
853            $arrParents[] = $ret;
854            $ret = SC_Utils::sfGetParentsArraySub($arrData, $pid_name, $id_name, $ret);
855        }
856
857        $arrParents = array_reverse($arrParents);
858
859        return $arrParents;
860    }
861
862    /**
863     * カテゴリから商品を検索する場合のWHERE文と値を返す.
864     *
865     * @param integer $category_id カテゴリID
866     * @return array 商品を検索する場合の配列
867     */
868    function sfGetCatWhere($category_id) {
869        // 子カテゴリIDの取得
870        $arrRet = $this->sfGetChildsID("dtb_category", "parent_category_id", "category_id", $category_id);
871        $tmp_where = "";
872        foreach ($arrRet as $val) {
873            if($tmp_where == "") {
874                $tmp_where.= " category_id IN ( ?";
875            } else {
876                $tmp_where.= ",? ";
877            }
878            $arrval[] = $val;
879        }
880        $tmp_where.= " ) ";
881        return array($tmp_where, $arrval);
882    }
883
884    /**
885     * 受注一時テーブルから情報を取得する.
886     *
887     * @param integer $order_temp_id 受注一時ID
888     * @return array 受注一時情報の配列
889     */
890    function sfGetOrderTemp($order_temp_id) {
891        $objQuery = new SC_Query();
892        $where = "order_temp_id = ?";
893        $arrRet = $objQuery->select("*", "dtb_order_temp", $where, array($order_temp_id));
894        return $arrRet[0];
895    }
896
897    /**
898     * SELECTボックス用リストを作成する.
899     *
900     * @param string $table テーブル名
901     * @param string $keyname プライマリーキーのカラム名
902     * @param string $valname データ内容のカラム名
903     * @return array SELECT ボックス用リストの配列
904     */
905    function sfGetIDValueList($table, $keyname, $valname) {
906        $objQuery = new SC_Query();
907        $col = "$keyname, $valname";
908        $objQuery->setwhere("del_flg = 0");
909        $objQuery->setorder("rank DESC");
910        $arrList = $objQuery->select($col, $table);
911        $count = count($arrList);
912        for($cnt = 0; $cnt < $count; $cnt++) {
913            $key = $arrList[$cnt][$keyname];
914            $val = $arrList[$cnt][$valname];
915            $arrRet[$key] = $val;
916        }
917        return $arrRet;
918    }
919
920    /**
921     * ランキングを上げる.
922     *
923     * @param string $table テーブル名
924     * @param string $colname カラム名
925     * @param string|integer $id テーブルのキー
926     * @param string $andwhere SQL の AND 条件である WHERE 句
927     * @return void
928     */
929    function sfRankUp($table, $colname, $id, $andwhere = "") {
930        $objQuery = new SC_Query();
931        $objQuery->begin();
932        $where = "$colname = ?";
933        if($andwhere != "") {
934            $where.= " AND $andwhere";
935        }
936        // 対象項目のランクを取得
937        $rank = $objQuery->get($table, "rank", $where, array($id));
938        // ランクの最大値を取得
939        $maxrank = $objQuery->max($table, "rank", $andwhere);
940        // ランクが最大値よりも小さい場合に実行する。
941        if($rank < $maxrank) {
942            // ランクが一つ上のIDを取得する。
943            $where = "rank = ?";
944            if($andwhere != "") {
945                $where.= " AND $andwhere";
946            }
947            $uprank = $rank + 1;
948            $up_id = $objQuery->get($table, $colname, $where, array($uprank));
949            // ランク入れ替えの実行
950            $sqlup = "UPDATE $table SET rank = ?, update_date = Now() WHERE $colname = ?";
951            $objQuery->exec($sqlup, array($rank + 1, $id));
952            $objQuery->exec($sqlup, array($rank, $up_id));
953        }
954        $objQuery->commit();
955    }
956
957    /**
958     * ランキングを下げる.
959     *
960     * @param string $table テーブル名
961     * @param string $colname カラム名
962     * @param string|integer $id テーブルのキー
963     * @param string $andwhere SQL の AND 条件である WHERE 句
964     * @return void
965     */
966    function sfRankDown($table, $colname, $id, $andwhere = "") {
967        $objQuery = new SC_Query();
968        $objQuery->begin();
969        $where = "$colname = ?";
970        if($andwhere != "") {
971            $where.= " AND $andwhere";
972        }
973        // 対象項目のランクを取得
974        $rank = $objQuery->get($table, "rank", $where, array($id));
975
976        // ランクが1(最小値)よりも大きい場合に実行する。
977        if($rank > 1) {
978            // ランクが一つ下のIDを取得する。
979            $where = "rank = ?";
980            if($andwhere != "") {
981                $where.= " AND $andwhere";
982            }
983            $downrank = $rank - 1;
984            $down_id = $objQuery->get($table, $colname, $where, array($downrank));
985            // ランク入れ替えの実行
986            $sqlup = "UPDATE $table SET rank = ?, update_date = Now() WHERE $colname = ?";
987            $objQuery->exec($sqlup, array($rank - 1, $id));
988            $objQuery->exec($sqlup, array($rank, $down_id));
989        }
990        $objQuery->commit();
991    }
992
993    /**
994     * 指定順位へ移動する.
995     *
996     * @param string $tableName テーブル名
997     * @param string $keyIdColumn キーを保持するカラム名
998     * @param string|integer $keyId キーの値
999     * @param integer $pos 指定順位
1000     * @param string $where SQL の AND 条件である WHERE 句
1001     * @return void
1002     */
1003    function sfMoveRank($tableName, $keyIdColumn, $keyId, $pos, $where = "") {
1004        $objQuery = new SC_Query();
1005        $objQuery->begin();
1006
1007        // 自身のランクを取得する
1008        $rank = $objQuery->get($tableName, "rank", "$keyIdColumn = ?", array($keyId));
1009        $max = $objQuery->max($tableName, "rank", $where);
1010
1011        // 値の調整(逆順)
1012        if($pos > $max) {
1013            $position = 1;
1014        } else if($pos < 1) {
1015            $position = $max;
1016        } else {
1017            $position = $max - $pos + 1;
1018        }
1019
1020        if( $position > $rank ) $term = "rank - 1"; //入れ替え先の順位が入れ換え元の順位より大きい場合
1021        if( $position < $rank ) $term = "rank + 1"; //入れ替え先の順位が入れ換え元の順位より小さい場合
1022
1023        // 指定した順位の商品から移動させる商品までのrankを1つずらす
1024        $sql = "UPDATE $tableName SET rank = $term, update_date = NOW() WHERE rank BETWEEN ? AND ? AND del_flg = 0";
1025        if($where != "") {
1026            $sql.= " AND $where";
1027        }
1028
1029        if( $position > $rank ) $objQuery->exec( $sql, array( $rank + 1, $position ));
1030        if( $position < $rank ) $objQuery->exec( $sql, array( $position, $rank - 1 ));
1031
1032        // 指定した順位へrankを書き換える。
1033        $sql  = "UPDATE $tableName SET rank = ?, update_date = NOW() WHERE $keyIdColumn = ? AND del_flg = 0 ";
1034        if($where != "") {
1035            $sql.= " AND $where";
1036        }
1037
1038        $objQuery->exec( $sql, array( $position, $keyId ) );
1039        $objQuery->commit();
1040    }
1041
1042    /**
1043     * ランクを含むレコードを削除する.
1044     *
1045     * レコードごと削除する場合は、$deleteをtrueにする
1046     *
1047     * @param string $table テーブル名
1048     * @param string $colname カラム名
1049     * @param string|integer $id テーブルのキー
1050     * @param string $andwhere SQL の AND 条件である WHERE 句
1051     * @param bool $delete レコードごと削除する場合 true,
1052     *                     レコードごと削除しない場合 false
1053     * @return void
1054     */
1055    function sfDeleteRankRecord($table, $colname, $id, $andwhere = "",
1056                                $delete = false) {
1057        $objQuery = new SC_Query();
1058        $objQuery->begin();
1059        // 削除レコードのランクを取得する。
1060        $where = "$colname = ?";
1061        if($andwhere != "") {
1062            $where.= " AND $andwhere";
1063        }
1064        $rank = $objQuery->get($table, "rank", $where, array($id));
1065
1066        if(!$delete) {
1067            // ランクを最下位にする、DELフラグON
1068            $sqlup = "UPDATE $table SET rank = 0, del_flg = 1, update_date = Now() ";
1069            $sqlup.= "WHERE $colname = ?";
1070            // UPDATEの実行
1071            $objQuery->exec($sqlup, array($id));
1072        } else {
1073            $objQuery->delete($table, "$colname = ?", array($id));
1074        }
1075
1076        // 追加レコードのランクより上のレコードを一つずらす。
1077        $where = "rank > ?";
1078        if($andwhere != "") {
1079            $where.= " AND $andwhere";
1080        }
1081        $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";
1082        $objQuery->exec($sqlup, array($rank));
1083        $objQuery->commit();
1084    }
1085
1086    /**
1087     * 親IDの配列を元に特定のカラムを取得する.
1088     *
1089     * @param SC_Query $objQuery SC_Query インスタンス
1090     * @param string $table テーブル名
1091     * @param string $id_name ID名
1092     * @param string $col_name カラム名
1093     * @param array $arrId IDの配列
1094     * @return array 特定のカラムの配列
1095     */
1096    function sfGetParentsCol($objQuery, $table, $id_name, $col_name, $arrId ) {
1097        $col = $col_name;
1098        $len = count($arrId);
1099        $where = "";
1100
1101        for($cnt = 0; $cnt < $len; $cnt++) {
1102            if($where == "") {
1103                $where = "$id_name = ?";
1104            } else {
1105                $where.= " OR $id_name = ?";
1106            }
1107        }
1108
1109        $objQuery->setorder("level");
1110        $arrRet = $objQuery->select($col, $table, $where, $arrId);
1111        return $arrRet;
1112    }
1113
1114    /**
1115     * カテゴリ変更時の移動処理を行う.
1116     *
1117     * @param SC_Query $objQuery SC_Query インスタンス
1118     * @param string $table テーブル名
1119     * @param string $id_name ID名
1120     * @param string $cat_name カテゴリ名
1121     * @param integer $old_catid 旧カテゴリID
1122     * @param integer $new_catid 新カテゴリID
1123     * @param integer $id ID
1124     * @return void
1125     */
1126    function sfMoveCatRank($objQuery, $table, $id_name, $cat_name, $old_catid, $new_catid, $id) {
1127        if ($old_catid == $new_catid) {
1128            return;
1129        }
1130        // 旧カテゴリでのランク削除処理
1131        // 移動レコードのランクを取得する。
1132        $where = "$id_name = ?";
1133        $rank = $objQuery->get($table, "rank", $where, array($id));
1134        // 削除レコードのランクより上のレコードを一つ下にずらす。
1135        $where = "rank > ? AND $cat_name = ?";
1136        $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where";
1137        $objQuery->exec($sqlup, array($rank, $old_catid));
1138        // 新カテゴリでの登録処理
1139        // 新カテゴリの最大ランクを取得する。
1140        $max_rank = $objQuery->max($table, "rank", "$cat_name = ?", array($new_catid)) + 1;
1141        $where = "$id_name = ?";
1142        $sqlup = "UPDATE $table SET rank = ? WHERE $where";
1143        $objQuery->exec($sqlup, array($max_rank, $id));
1144    }
1145
1146    /**
1147     * 配送時間を取得する.
1148     *
1149     * @param integer $payment_id 支払い方法ID
1150     * @return array 配送時間の配列
1151     */
1152    function sfGetDelivTime($payment_id = "") {
1153        $objQuery = new SC_Query();
1154
1155        $deliv_id = "";
1156
1157        if($payment_id != "") {
1158            $where = "del_flg = 0 AND payment_id = ?";
1159            $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id));
1160            $deliv_id = $arrRet[0]['deliv_id'];
1161        }
1162
1163        if($deliv_id != "") {
1164            $objQuery->setorder("time_id");
1165            $where = "deliv_id = ?";
1166            $arrRet= $objQuery->select("time_id, deliv_time", "dtb_delivtime", $where, array($deliv_id));
1167        }
1168
1169        return $arrRet;
1170    }
1171
1172    /**
1173     * 都道府県、支払い方法から配送料金を取得する.
1174     *
1175     * @param integer $pref 都道府県ID
1176     * @param integer $payment_id 支払い方法ID
1177     * @return string 指定の都道府県, 支払い方法の配送料金
1178     */
1179    function sfGetDelivFee($pref, $payment_id = "") {
1180        $objQuery = new SC_Query();
1181
1182        $deliv_id = "";
1183
1184        // 支払い方法が指定されている場合は、対応した配送業者を取得する
1185        if($payment_id != "") {
1186            $where = "del_flg = 0 AND payment_id = ?";
1187            $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id));
1188            $deliv_id = $arrRet[0]['deliv_id'];
1189        // 支払い方法が指定されていない場合は、先頭の配送業者を取得する
1190        } else {
1191            $where = "del_flg = 0";
1192            $objQuery->setOrder("rank DESC");
1193            $objQuery->setLimitOffset(1);
1194            $arrRet = $objQuery->select("deliv_id", "dtb_deliv", $where);
1195            $deliv_id = $arrRet[0]['deliv_id'];
1196        }
1197
1198        // 配送業者から配送料を取得
1199        if($deliv_id != "") {
1200
1201            // 都道府県が指定されていない場合は、東京都の番号を指定しておく
1202            if($pref == "") {
1203                $pref = 13;
1204            }
1205
1206            $objQuery = new SC_Query();
1207            $where = "deliv_id = ? AND pref = ?";
1208            $arrRet= $objQuery->select("fee", "dtb_delivfee", $where, array($deliv_id, $pref));
1209        }
1210        return $arrRet[0]['fee'];
1211    }
1212
1213    /**
1214     * 集計情報を元に最終計算を行う.
1215     *
1216     * @param array $arrData 各種情報
1217     * @param LC_Page $objPage LC_Page インスタンス
1218     * @param SC_CartSession $objCartSess SC_CartSession インスタンス
1219     * @param array $arrInfo 店舗情報の配列
1220     * @param SC_Customer $objCustomer SC_Customer インスタンス
1221     * @return array 最終計算後の配列
1222     */
1223    function sfTotalConfirm($arrData, &$objPage, &$objCartSess, $arrInfo, &$objCustomer = "") {
1224        // 未定義変数を定義
1225        if (!isset($arrData['deliv_pref'])) $arrData['deliv_pref'] = "";
1226        if (!isset($arrData['payment_id'])) $arrData['payment_id'] = "";
1227        if (!isset($arrData['charge'])) $arrData['charge'] = "";
1228        if (!isset($arrData['use_point'])) $arrData['use_point'] = "";
1229
1230        // 商品の合計個数
1231        $total_quantity = $objCartSess->getTotalQuantity(true);
1232
1233        // 税金の取得
1234        $arrData['tax'] = $objPage->tpl_total_tax;
1235        // 小計の取得
1236        $arrData['subtotal'] = $objPage->tpl_total_pretax;
1237
1238        // 合計送料の取得
1239        $arrData['deliv_fee'] = 0;
1240
1241        // 商品ごとの送料が有効の場合
1242        if (OPTION_PRODUCT_DELIV_FEE == 1) {
1243            $arrData['deliv_fee']+= $objCartSess->getAllProductsDelivFee();
1244        }
1245
1246        // 配送業者の送料が有効の場合
1247        if (OPTION_DELIV_FEE == 1) {
1248            // 送料の合計を計算する
1249            $arrData['deliv_fee']
1250                += $this->sfGetDelivFee($arrData['deliv_pref'],
1251                                           $arrData['payment_id']);
1252
1253        }
1254
1255        // 送料無料の購入数が設定されている場合
1256        if(DELIV_FREE_AMOUNT > 0) {
1257            if($total_quantity >= DELIV_FREE_AMOUNT) {
1258                $arrData['deliv_fee'] = 0;
1259            }
1260        }
1261
1262        // 送料無料条件が設定されている場合
1263        if($arrInfo['free_rule'] > 0) {
1264            // 小計が無料条件を超えている場合
1265            if($arrData['subtotal'] >= $arrInfo['free_rule']) {
1266                $arrData['deliv_fee'] = 0;
1267            }
1268        }
1269
1270        // 合計の計算
1271        $arrData['total'] = $objPage->tpl_total_pretax; // 商品合計
1272        $arrData['total']+= $arrData['deliv_fee'];      // 送料
1273        $arrData['total']+= $arrData['charge'];         // 手数料
1274        // お支払い合計
1275        $arrData['payment_total'] = $arrData['total'] - ($arrData['use_point'] * POINT_VALUE);
1276        // 加算ポイントの計算
1277        $arrData['add_point'] = SC_Utils::sfGetAddPoint($objPage->tpl_total_point, $arrData['use_point'], $arrInfo);
1278
1279        if($objCustomer != "") {
1280            // 誕生日月であった場合
1281            if($objCustomer->isBirthMonth()) {
1282                $arrData['birth_point'] = BIRTH_MONTH_POINT;
1283                $arrData['add_point'] += $arrData['birth_point'];
1284            }
1285        }
1286
1287        if($arrData['add_point'] < 0) {
1288            $arrData['add_point'] = 0;
1289        }
1290        return $arrData;
1291    }
1292
1293    /**
1294     * レコードの存在チェックを行う.
1295     *
1296     * @param string $table テーブル名
1297     * @param string $col カラム名
1298     * @param array $arrval 要素の配列
1299     * @param array $addwhere SQL の AND 条件である WHERE 句
1300     * @return bool レコードが存在する場合 true
1301     */
1302    function sfIsRecord($table, $col, $arrval, $addwhere = "") {
1303        $objQuery = new SC_Query();
1304        $arrCol = split("[, ]", $col);
1305
1306        $where = "del_flg = 0";
1307
1308        if($addwhere != "") {
1309            $where.= " AND $addwhere";
1310        }
1311
1312        foreach($arrCol as $val) {
1313            if($val != "") {
1314                if($where == "") {
1315                    $where = "$val = ?";
1316                } else {
1317                    $where.= " AND $val = ?";
1318                }
1319            }
1320        }
1321        $ret = $objQuery->get($table, $col, $where, $arrval);
1322
1323        if($ret != "") {
1324            return true;
1325        }
1326        return false;
1327    }
1328
1329}
1330?>
Note: See TracBrowser for help on using the repository browser.