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

Revision 23546, 6.2 KB checked in by shutta, 12 years ago (diff)

#2580 Copyrightを更新
Copyrightを2014に更新

Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2014 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            } elseif (strlen($data['rule_max']) != 0) {
92                if ($data['rule_max'] <= $total) {
93                    $arrPayment[] = $data;
94                }
95            // 上限のみ設定されている
96            } elseif (strlen($data['upper_rule']) != 0) {
97                if ($data['upper_rule'] >= $total) {
98                    $arrPayment[] = $data;
99                }
100            // いずれも設定なし
101            } else {
102                $arrPayment[] = $data;
103            }
104        }
105
106        return $arrPayment;
107    }
108
109    /**
110     * 支払方法の登録.
111     *
112     * @param  array $sqlval
113     * @return void
114     */
115    public function save($sqlval)
116    {
117        $objQuery =& SC_Query_Ex::getSingletonInstance();
118
119        $payment_id = $sqlval['payment_id'];
120        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
121        // 新規登録
122        if ($payment_id == '') {
123            // INSERTの実行
124            $sqlval['rank'] = $objQuery->max('rank', 'dtb_payment') + 1;
125            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
126            $sqlval['payment_id'] = $objQuery->nextVal('dtb_payment_payment_id');
127            $objQuery->insert('dtb_payment', $sqlval);
128        // 既存編集
129        } else {
130            unset($sqlval['creator_id']);
131            unset($sqlval['create_date']);
132            $where = 'payment_id = ?';
133            $objQuery->update('dtb_payment', $sqlval, $where, array($payment_id));
134        }
135    }
136
137    /**
138     * 支払方法の削除.
139     *
140     * @param  integer $payment_id 支払方法ID
141     * @return void
142     */
143    public function delete($payment_id)
144    {
145        $objDb = new SC_Helper_DB_Ex();
146        // ランク付きレコードの削除
147        $objDb->sfDeleteRankRecord('dtb_payment', 'payment_id', $payment_id);
148    }
149
150    /**
151     * 支払方法の表示順をひとつ上げる.
152     *
153     * @param  integer $payment_id 支払方法ID
154     * @return void
155     */
156    public function rankUp($payment_id)
157    {
158        $objDb = new SC_Helper_DB_Ex();
159        $objDb->sfRankUp('dtb_payment', 'payment_id', $payment_id);
160    }
161
162    /**
163     * 支払方法の表示順をひとつ下げる.
164     *
165     * @param  integer $payment_id 支払方法ID
166     * @return void
167     */
168    public function rankDown($payment_id)
169    {
170        $objDb = new SC_Helper_DB_Ex();
171        $objDb->sfRankDown('dtb_payment', 'payment_id', $payment_id);
172    }
173
174    /**
175     * 決済モジュールを使用するかどうか.
176     *
177     * dtb_payment.memo03 に値が入っている場合は決済モジュールと見なす.
178     *
179     * @param  integer $payment_id 支払い方法ID
180     * @return boolean 決済モジュールを使用する支払い方法の場合 true
181     */
182    public static function useModule($payment_id)
183    {
184        $objQuery =& SC_Query_Ex::getSingletonInstance();
185        $memo03 = $objQuery->get('memo03', 'dtb_payment', 'payment_id = ?', array($payment_id));
186
187        return !SC_Utils_Ex::isBlank($memo03);
188    }
189
190    /**
191     * 支払方法IDをキー, 名前を値とする配列を取得.
192     *
193     * @param  string $type 値のタイプ
194     * @return array
195     */
196    public static function getIDValueList($type = 'payment_method')
197    {
198        return SC_Helper_DB_Ex::sfGetIDValueList('dtb_payment', 'payment_id', $type);
199    }
200}
Note: See TracBrowser for help on using the repository browser.