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 | */ |
---|
31 | class 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 | return $arrRet[0]; |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * 支払方法一覧の取得. |
---|
53 | * |
---|
54 | * @param boolean $has_deleted 削除された支払方法も含む場合 true; 初期値 false |
---|
55 | * @return array |
---|
56 | */ |
---|
57 | public function getList($has_deleted = false) |
---|
58 | { |
---|
59 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
60 | $col = 'payment_id, payment_method, payment_image, charge, rule_max, upper_rule, note, fix, charge_flg'; |
---|
61 | $where = ''; |
---|
62 | if (!$has_deleted) { |
---|
63 | $where .= 'del_flg = 0'; |
---|
64 | } |
---|
65 | $table = 'dtb_payment'; |
---|
66 | $objQuery->setOrder('rank DESC'); |
---|
67 | $arrRet = $objQuery->select($col, $table, $where); |
---|
68 | return $arrRet; |
---|
69 | } |
---|
70 | |
---|
71 | /** |
---|
72 | * 購入金額に応じた支払方法を取得する. |
---|
73 | * |
---|
74 | * @param integer $total 購入金額 |
---|
75 | * @return array 購入金額に応じた支払方法の配列 |
---|
76 | */ |
---|
77 | function getByPrice($total) |
---|
78 | { |
---|
79 | // 削除されていない支払方法を取得 |
---|
80 | $payments = $this->getList(); |
---|
81 | $arrPayment = array(); |
---|
82 | foreach ($payments as $data) { |
---|
83 | // 下限と上限が設定されている |
---|
84 | if (strlen($data['rule_max']) != 0 && strlen($data['upper_rule']) != 0) { |
---|
85 | if ($data['rule_max'] <= $total && $data['upper_rule'] >= $total) { |
---|
86 | $arrPayment[] = $data; |
---|
87 | } |
---|
88 | } |
---|
89 | // 下限のみ設定されている |
---|
90 | elseif (strlen($data['rule_max']) != 0) { |
---|
91 | if ($data['rule_max'] <= $total) { |
---|
92 | $arrPayment[] = $data; |
---|
93 | } |
---|
94 | } |
---|
95 | // 上限のみ設定されている |
---|
96 | elseif (strlen($data['upper_rule']) != 0) { |
---|
97 | if ($data['upper_rule'] >= $total) { |
---|
98 | $arrPayment[] = $data; |
---|
99 | } |
---|
100 | } |
---|
101 | // いずれも設定なし |
---|
102 | else { |
---|
103 | $arrPayment[] = $data; |
---|
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 | return !SC_Utils_Ex::isBlank($memo03); |
---|
187 | } |
---|
188 | |
---|
189 | /** |
---|
190 | * 支払方法IDをキー, 名前を値とする配列を取得. |
---|
191 | * |
---|
192 | * @return array |
---|
193 | */ |
---|
194 | public static function getIDValueList() |
---|
195 | { |
---|
196 | return SC_Helper_DB_Ex::sfGetIDValueList('dtb_payment', 'payment_id', 'payment_method'); |
---|
197 | } |
---|
198 | } |
---|