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_Delivery
|
---|
32 | {
|
---|
33 | /**
|
---|
34 | * 配送方法の情報を取得.
|
---|
35 | *
|
---|
36 | * @param integer $deliv_id 配送方法ID
|
---|
37 | * @param boolean $has_deleted 削除された支払方法も含む場合 true; 初期値 false
|
---|
38 | * @return array
|
---|
39 | */
|
---|
40 | public function get($deliv_id, $has_deleted = false) {
|
---|
41 | $objQuery =& SC_Query_Ex::getSingletonInstance();
|
---|
42 |
|
---|
43 | // 配送業者一覧の取得
|
---|
44 | $col = 'deliv_id, name, service_name, remark, confirm_url, product_type_id';
|
---|
45 | $where = 'deliv_id = ?';
|
---|
46 | if (!$has_deleted) {
|
---|
47 | $where .= ' AND del_flg = 0';
|
---|
48 | }
|
---|
49 | $table = 'dtb_deliv';
|
---|
50 | $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
|
---|
51 | $arrDeliv = $arrRet[0];
|
---|
52 | if (!$arrDeliv) {
|
---|
53 | return $arrDeliv;
|
---|
54 | }
|
---|
55 |
|
---|
56 | // お届け時間の取得
|
---|
57 | $col = 'deliv_time';
|
---|
58 | $where = 'deliv_id = ? ORDER BY time_id';
|
---|
59 | $table = 'dtb_delivtime';
|
---|
60 | $arrDeliv['deliv_time'] = $objQuery->select($col, $table, $where, array($deliv_id));
|
---|
61 |
|
---|
62 | // 配送料金の取得
|
---|
63 | $col = 'fee';
|
---|
64 | $where = 'deliv_id = ? ORDER BY pref';
|
---|
65 | $table = 'dtb_delivfee';
|
---|
66 | $arrDeliv['fee'] = $objQuery->select($col, $table, $where, array($deliv_id));
|
---|
67 |
|
---|
68 | // 支払方法
|
---|
69 | $col = 'payment_id';
|
---|
70 | $where = 'deliv_id = ? ORDER BY rank';
|
---|
71 | $table = 'dtb_payment_options';
|
---|
72 | $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
|
---|
73 | $arrPaymentIds = array();
|
---|
74 | foreach ($arrRet as $val) {
|
---|
75 | $arrPaymentIds[] = $val['payment_id'];
|
---|
76 | }
|
---|
77 | $arrDeliv['payment_ids'] = $arrPaymentIds;
|
---|
78 |
|
---|
79 | return $arrDeliv;
|
---|
80 | }
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * 配送方法一覧の取得.
|
---|
84 | *
|
---|
85 | * @param integer $product_type_id 商品種別ID
|
---|
86 | * @param boolean $has_deleted 削除された支払方法も含む場合 true; 初期値 false
|
---|
87 | * @return array
|
---|
88 | */
|
---|
89 | public function getList($product_type_id = null, $has_deleted = false) {
|
---|
90 | $objQuery =& SC_Query_Ex::getSingletonInstance();
|
---|
91 | $col = '*';
|
---|
92 | $where = '';
|
---|
93 | $arrVal = array();
|
---|
94 | if (!$has_deleted) {
|
---|
95 | $where .= 'del_flg = 0';
|
---|
96 | }
|
---|
97 | if (!is_null($product_type_id)) {
|
---|
98 | if (!$has_deleted) {
|
---|
99 | $where .= ' AND ';
|
---|
100 | }
|
---|
101 | $where .= 'product_type_id = ?';
|
---|
102 | $arrVal[] = $product_type_id;
|
---|
103 | }
|
---|
104 | $table = 'dtb_deliv';
|
---|
105 | $objQuery->setOrder('rank DESC');
|
---|
106 | $arrRet = $objQuery->select($col, $table, $where, $arrVal);
|
---|
107 | return $arrRet;
|
---|
108 | }
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * 配送方法の登録.
|
---|
112 | *
|
---|
113 | * @param array $sqlval
|
---|
114 | * @return integer $deliv_id
|
---|
115 | */
|
---|
116 | public function save($sqlval) {
|
---|
117 | $objQuery =& SC_Query_Ex::getSingletonInstance();
|
---|
118 | $objQuery->begin();
|
---|
119 |
|
---|
120 | // お届け時間
|
---|
121 | $sqlval_deliv_time = $sqlval['deliv_time'];
|
---|
122 | unset($sqlval['deliv_time']);
|
---|
123 | // 配送料
|
---|
124 | if (INPUT_DELIV_FEE) {
|
---|
125 | $sqlval_deliv_fee = $sqlval['deliv_fee'];
|
---|
126 | }
|
---|
127 | unset($sqlval['deliv_fee']);
|
---|
128 | // 支払い方法
|
---|
129 | $sqlval_payment_ids = $sqlval['payment_ids'];
|
---|
130 | unset($sqlval['payment_ids']);
|
---|
131 |
|
---|
132 | // deliv_id が決まっていた場合
|
---|
133 | if ($sqlval['deliv_id'] != '') {
|
---|
134 | $deliv_id = $sqlval['deliv_id'];
|
---|
135 | $where = 'deliv_id = ?';
|
---|
136 | $objQuery->update('dtb_deliv', $sqlval, $where, array($deliv_id));
|
---|
137 |
|
---|
138 | // お届け時間の登録
|
---|
139 | $table = 'dtb_delivtime';
|
---|
140 | $where = 'deliv_id = ? AND time_id = ?';
|
---|
141 | for ($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
|
---|
142 | $keyname = 'deliv_time'.$cnt;
|
---|
143 | $arrWhereVal = array($deliv_id, $cnt);
|
---|
144 | // 既存データの有無を確認
|
---|
145 | $curData = $objQuery->select('*', $table, $where, $arrWhereVal);
|
---|
146 |
|
---|
147 | if (isset($sqlval_deliv_time[$cnt])) {
|
---|
148 | $deliv_time = $sqlval_deliv_time[$cnt];
|
---|
149 |
|
---|
150 | // 入力が空ではなく、DBに情報があれば更新
|
---|
151 | if (count($curData)) {
|
---|
152 | $objQuery->update($table, $deliv_time, $where, $arrWhereVal);
|
---|
153 | }
|
---|
154 | // DBに情報がなければ登録
|
---|
155 | else {
|
---|
156 | $deliv_time['deliv_id'] = $deliv_id;
|
---|
157 | $deliv_time['time_id'] = $cnt;
|
---|
158 | $objQuery->insert($table, $deliv_time);
|
---|
159 | }
|
---|
160 | }
|
---|
161 | // 入力が空で、DBに情報がある場合は削除
|
---|
162 | else if (count($curData)) {
|
---|
163 | $objQuery->delete($table, $where, $arrWhereVal);
|
---|
164 | }
|
---|
165 | }
|
---|
166 |
|
---|
167 | // 配送料の登録
|
---|
168 | if (INPUT_DELIV_FEE) {
|
---|
169 | foreach ($sqlval_deliv_fee as $cnt => $deliv_fee) {
|
---|
170 | $objQuery->update('dtb_delivfee', array('fee' => $deliv_fee['fee']), 'deliv_id = ? AND fee_id = ?', array($deliv_id, $cnt));
|
---|
171 | }
|
---|
172 | }
|
---|
173 | } else {
|
---|
174 | // 登録する配送業者IDの取得
|
---|
175 | $deliv_id = $objQuery->nextVal('dtb_deliv_deliv_id');
|
---|
176 | $sqlval['deliv_id'] = $deliv_id;
|
---|
177 | $sqlval['rank'] = $objQuery->max('rank', 'dtb_deliv') + 1;
|
---|
178 | $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
|
---|
179 | // INSERTの実行
|
---|
180 | $objQuery->insert('dtb_deliv', $sqlval);
|
---|
181 |
|
---|
182 | // お届け時間の設定
|
---|
183 | foreach ($sqlval_deliv_time as $cnt => $deliv_time) {
|
---|
184 | $deliv_time['deliv_id'] = $deliv_id;
|
---|
185 | $deliv_time['time_id'] = $cnt;
|
---|
186 | // INSERTの実行
|
---|
187 | $objQuery->insert('dtb_delivtime', $deliv_time);
|
---|
188 | }
|
---|
189 |
|
---|
190 | if (INPUT_DELIV_FEE) {
|
---|
191 | // 配送料金の設定
|
---|
192 | foreach ($sqlval_deliv_fee as $cnt => $deliv_fee) {
|
---|
193 | $deliv_fee['deliv_id'] = $deliv_id;
|
---|
194 | $deliv_fee['fee_id'] = $cnt;
|
---|
195 | // INSERTの実行
|
---|
196 | $objQuery->insert('dtb_delivfee', $deliv_fee);
|
---|
197 | }
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|
201 | // 支払い方法
|
---|
202 | $objQuery->delete('dtb_payment_options', 'deliv_id = ?', array($deliv_id));
|
---|
203 | foreach ($sqlval_payment_ids as $payment_ids) {
|
---|
204 | $payment_ids['deliv_id'] = $deliv_id;
|
---|
205 | $objQuery->insert('dtb_payment_options', $payment_ids);
|
---|
206 | }
|
---|
207 |
|
---|
208 | $objQuery->commit();
|
---|
209 |
|
---|
210 | return $deliv_id;
|
---|
211 | }
|
---|
212 |
|
---|
213 | /**
|
---|
214 | * 配送方法の削除.
|
---|
215 | *
|
---|
216 | * @param integer $deliv_id 配送方法ID
|
---|
217 | * @return void
|
---|
218 | */
|
---|
219 | public function delete($deliv_id) {
|
---|
220 | $objDb = new SC_Helper_DB_Ex();
|
---|
221 | // ランク付きレコードの削除
|
---|
222 | $objDb->sfDeleteRankRecord('dtb_deliv', 'deliv_id', $deliv_id);
|
---|
223 | }
|
---|
224 |
|
---|
225 | /**
|
---|
226 | * 配送方法の表示順をひとつ上げる.
|
---|
227 | *
|
---|
228 | * @param integer $deliv_id 配送方法ID
|
---|
229 | * @return void
|
---|
230 | */
|
---|
231 | public function rankUp($deliv_id) {
|
---|
232 | $objDb = new SC_Helper_DB_Ex();
|
---|
233 | $objDb->sfRankUp('dtb_deliv', 'deliv_id', $deliv_id);
|
---|
234 | }
|
---|
235 |
|
---|
236 | /**
|
---|
237 | * 配送方法の表示順をひとつ下げる.
|
---|
238 | *
|
---|
239 | * @param integer $deliv_id 配送方法ID
|
---|
240 | * @return void
|
---|
241 | */
|
---|
242 | public function rankDown($deliv_id) {
|
---|
243 | $objDb = new SC_Helper_DB_Ex();
|
---|
244 | $objDb->sfRankDown('dtb_deliv', 'deliv_id', $deliv_id);
|
---|
245 | }
|
---|
246 |
|
---|
247 | /**
|
---|
248 | * 同じ内容の配送方法が存在するか確認.
|
---|
249 | *
|
---|
250 | * @param array $arrDeliv
|
---|
251 | * @return boolean
|
---|
252 | */
|
---|
253 | public function checkExist($arrDeliv) {
|
---|
254 | $objDb = new SC_Helper_DB_Ex();
|
---|
255 | if ($arrDeliv['deliv_id'] == '') {
|
---|
256 | $ret = $objDb->sfIsRecord('dtb_deliv', 'service_name', array($arrDeliv['service_name']));
|
---|
257 | } else {
|
---|
258 | $objQuery =& SC_Query_Ex::getSingletonInstance();
|
---|
259 | $ret = (($objQuery->count('dtb_deliv', 'deliv_id != ? AND service_name = ? ', array($arrDeliv['deliv_id'], $arrDeliv['service_name'])) > 0)? true : false);
|
---|
260 | }
|
---|
261 | return $ret;
|
---|
262 | }
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * 配送方法IDをキー, 名前を値とする配列を取得.
|
---|
266 | *
|
---|
267 | * @param string $type 値のタイプ
|
---|
268 | * @return array
|
---|
269 | */
|
---|
270 | public static function getIDValueList($type = 'name') {
|
---|
271 | return SC_Helper_DB_Ex::sfGetIDValueList('dtb_deliv', 'deliv_id', $type);
|
---|
272 | }
|
---|
273 | }
|
---|