source: branches/version-2_13-dev/data/class/helper/SC_Helper_Payment.php @ 23124

Revision 23124, 6.2 KB checked in by kimoto, 11 years ago (diff)

#2043 typo修正・ソース整形・ソースコメントの改善 for 2.13.0
PHP4的な書き方の修正

Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2013 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 * 支払方法を管理するヘルパークラス.
26 *
27 * @package Helper
28 * @author pineray
29 * @version $Id:$
30 */
31class SC_Helper_Payment
32{
33    /**
34     * 支払方法の情報を取得.
35     *
36     * @param  integer $payment_id  支払方法ID
37     * @param  boolean $has_deleted 削除された支払方法も含む場合 true; 初期値 false
38     * @return array
39     */
40    public function get($payment_id, $has_deleted = false)
41    {
42        $objQuery =& SC_Query_Ex::getSingletonInstance();
43        $where = 'payment_id = ?';
44        if (!$has_deleted) {
45            $where .= ' AND del_flg = 0';
46        }
47        $arrRet = $objQuery->select('*', 'dtb_payment', $where, array($payment_id));
48
49        return $arrRet[0];
50    }
51
52    /**
53     * 支払方法一覧の取得.
54     *
55     * @param  boolean $has_deleted 削除された支払方法も含む場合 true; 初期値 false
56     * @return array
57     */
58    public function getList($has_deleted = false)
59    {
60        $objQuery =& SC_Query_Ex::getSingletonInstance();
61        $col = 'payment_id, payment_method, payment_image, charge, rule_max, upper_rule, note, fix, charge_flg';
62        $where = '';
63        if (!$has_deleted) {
64            $where .= 'del_flg = 0';
65        }
66        $table = 'dtb_payment';
67        $objQuery->setOrder('rank DESC');
68        $arrRet = $objQuery->select($col, $table, $where);
69
70        return $arrRet;
71    }
72
73    /**
74     * 購入金額に応じた支払方法を取得する.
75     *
76     * @param  integer $total 購入金額
77     * @return array   購入金額に応じた支払方法の配列
78     */
79    public function getByPrice($total)
80    {
81        // 削除されていない支払方法を取得
82        $payments = $this->getList();
83        $arrPayment = array();
84        foreach ($payments as $data) {
85            // 下限と上限が設定されている
86            if (strlen($data['rule_max']) != 0 && strlen($data['upper_rule']) != 0) {
87                if ($data['rule_max'] <= $total && $data['upper_rule'] >= $total) {
88                    $arrPayment[] = $data;
89                }
90            }
91            // 下限のみ設定されている
92            elseif (strlen($data['rule_max']) != 0) {
93                if ($data['rule_max'] <= $total) {
94                    $arrPayment[] = $data;
95                }
96            }
97            // 上限のみ設定されている
98            elseif (strlen($data['upper_rule']) != 0) {
99                if ($data['upper_rule'] >= $total) {
100                    $arrPayment[] = $data;
101                }
102            }
103            // いずれも設定なし
104            else {
105                $arrPayment[] = $data;
106            }
107        }
108
109        return $arrPayment;
110    }
111
112    /**
113     * 支払方法の登録.
114     *
115     * @param  array $sqlval
116     * @return void
117     */
118    public function save($sqlval)
119    {
120        $objQuery =& SC_Query_Ex::getSingletonInstance();
121
122        $payment_id = $sqlval['payment_id'];
123        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
124        // 新規登録
125        if ($payment_id == '') {
126            // INSERTの実行
127            $sqlval['rank'] = $objQuery->max('rank', 'dtb_payment') + 1;
128            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
129            $sqlval['payment_id'] = $objQuery->nextVal('dtb_payment_payment_id');
130            $objQuery->insert('dtb_payment', $sqlval);
131        // 既存編集
132        } else {
133            unset($sqlval['creator_id']);
134            unset($sqlval['create_date']);
135            $where = 'payment_id = ?';
136            $objQuery->update('dtb_payment', $sqlval, $where, array($payment_id));
137        }
138    }
139
140    /**
141     * 支払方法の削除.
142     *
143     * @param  integer $payment_id 支払方法ID
144     * @return void
145     */
146    public function delete($payment_id)
147    {
148        $objDb = new SC_Helper_DB_Ex();
149        // ランク付きレコードの削除
150        $objDb->sfDeleteRankRecord('dtb_payment', 'payment_id', $payment_id);
151    }
152
153    /**
154     * 支払方法の表示順をひとつ上げる.
155     *
156     * @param  integer $payment_id 支払方法ID
157     * @return void
158     */
159    public function rankUp($payment_id)
160    {
161        $objDb = new SC_Helper_DB_Ex();
162        $objDb->sfRankUp('dtb_payment', 'payment_id', $payment_id);
163    }
164
165    /**
166     * 支払方法の表示順をひとつ下げる.
167     *
168     * @param  integer $payment_id 支払方法ID
169     * @return void
170     */
171    public function rankDown($payment_id)
172    {
173        $objDb = new SC_Helper_DB_Ex();
174        $objDb->sfRankDown('dtb_payment', 'payment_id', $payment_id);
175    }
176
177    /**
178     * 決済モジュールを使用するかどうか.
179     *
180     * dtb_payment.memo03 に値が入っている場合は決済モジュールと見なす.
181     *
182     * @param  integer $payment_id 支払い方法ID
183     * @return boolean 決済モジュールを使用する支払い方法の場合 true
184     */
185    public static function useModule($payment_id)
186    {
187        $objQuery =& SC_Query_Ex::getSingletonInstance();
188        $memo03 = $objQuery->get('memo03', 'dtb_payment', 'payment_id = ?', array($payment_id));
189
190        return !SC_Utils_Ex::isBlank($memo03);
191    }
192
193    /**
194     * 支払方法IDをキー, 名前を値とする配列を取得.
195     *
196     * @return array
197     */
198    public static function getIDValueList()
199    {
200        return SC_Helper_DB_Ex::sfGetIDValueList('dtb_payment', 'payment_id', 'payment_method');
201    }
202}
Note: See TracBrowser for help on using the repository browser.