1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2010 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 | * DB関連のヘルパークラス. |
---|
26 | * |
---|
27 | * @package Helper |
---|
28 | * @author LOCKON CO.,LTD. |
---|
29 | * @version $Id:SC_Helper_DB.php 15532 2007-08-31 14:39:46Z nanasess $ |
---|
30 | */ |
---|
31 | class SC_Helper_DB { |
---|
32 | |
---|
33 | // {{{ properties |
---|
34 | |
---|
35 | /** ルートカテゴリ取得フラグ */ |
---|
36 | var $g_root_on; |
---|
37 | |
---|
38 | /** ルートカテゴリID */ |
---|
39 | var $g_root_id; |
---|
40 | |
---|
41 | /** 選択中カテゴリ取得フラグ */ |
---|
42 | var $g_category_on; |
---|
43 | |
---|
44 | /** 選択中カテゴリID */ |
---|
45 | var $g_category_id; |
---|
46 | |
---|
47 | // }}} |
---|
48 | // {{{ functions |
---|
49 | |
---|
50 | /** |
---|
51 | * データベースのバージョンを所得する. |
---|
52 | * |
---|
53 | * @param string $dsn データソース名 |
---|
54 | * @return string データベースのバージョン |
---|
55 | */ |
---|
56 | function sfGetDBVersion($dsn = "") { |
---|
57 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
---|
58 | return $dbFactory->sfGetDBVersion($dsn); |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | * カラムの存在チェックと作成を行う. |
---|
63 | * |
---|
64 | * チェック対象のテーブルに, 該当のカラムが存在するかチェックする. |
---|
65 | * 引数 $add が true の場合, 該当のカラムが存在しない場合は, カラムの生成を行う. |
---|
66 | * カラムの生成も行う場合は, $col_type も必須となる. |
---|
67 | * |
---|
68 | * @param string $table_name テーブル名 |
---|
69 | * @param string $column_name カラム名 |
---|
70 | * @param string $col_type カラムのデータ型 |
---|
71 | * @param string $dsn データソース名 |
---|
72 | * @param bool $add カラムの作成も行う場合 true |
---|
73 | * @return bool カラムが存在する場合とカラムの生成に成功した場合 true, |
---|
74 | * テーブルが存在しない場合 false, |
---|
75 | * 引数 $add == false でカラムが存在しない場合 false |
---|
76 | */ |
---|
77 | function sfColumnExists($table_name, $col_name, $col_type = "", $dsn = "", $add = false) { |
---|
78 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
---|
79 | $dsn = $dbFactory->getDSN($dsn); |
---|
80 | |
---|
81 | $objQuery =& SC_Query::getSingletonInstance($dsn); |
---|
82 | |
---|
83 | // テーブルが無ければエラー |
---|
84 | if(!in_array($table_name, $objQuery->listTables())) return false; |
---|
85 | |
---|
86 | // 正常に接続されている場合 |
---|
87 | if(!$objQuery->isError()) { |
---|
88 | list($db_type) = split(":", $dsn); |
---|
89 | |
---|
90 | // カラムリストを取得 |
---|
91 | $columns = $objQuery->listTableFields($table_name); |
---|
92 | |
---|
93 | if(in_array($col_name, $columns)){ |
---|
94 | return true; |
---|
95 | } |
---|
96 | } |
---|
97 | |
---|
98 | // カラムを追加する |
---|
99 | if($add){ |
---|
100 | $objQuery->query("ALTER TABLE $table_name ADD $col_name $col_type "); |
---|
101 | return true; |
---|
102 | } |
---|
103 | return false; |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * データの存在チェックを行う. |
---|
108 | * |
---|
109 | * @param string $table_name テーブル名 |
---|
110 | * @param string $where データを検索する WHERE 句 |
---|
111 | * @param string $dsn データソース名 |
---|
112 | * @param string $sql データの追加を行う場合の SQL文 |
---|
113 | * @param bool $add データの追加も行う場合 true |
---|
114 | * @return bool データが存在する場合 true, データの追加に成功した場合 true, |
---|
115 | * $add == false で, データが存在しない場合 false |
---|
116 | */ |
---|
117 | function sfDataExists($table_name, $where, $arrval, $dsn = "", $sql = "", $add = false) { |
---|
118 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
---|
119 | $dsn = $dbFactory->getDSN($dsn); |
---|
120 | |
---|
121 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
122 | $count = $objQuery->count($table_name, $where, $arrval); |
---|
123 | |
---|
124 | if($count > 0) { |
---|
125 | $ret = true; |
---|
126 | } else { |
---|
127 | $ret = false; |
---|
128 | } |
---|
129 | // データを追加する |
---|
130 | if(!$ret && $add) { |
---|
131 | $objQuery->exec($sql); |
---|
132 | } |
---|
133 | return $ret; |
---|
134 | } |
---|
135 | |
---|
136 | /** |
---|
137 | * 店舗基本情報を取得する. |
---|
138 | * |
---|
139 | * @param boolean $force 強制的にDB取得するか |
---|
140 | * @return array 店舗基本情報の配列 |
---|
141 | */ |
---|
142 | function sf_getBasisData($force = false) { |
---|
143 | static $data; |
---|
144 | |
---|
145 | if ($force || !isset($data)) { |
---|
146 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
147 | $arrRet = $objQuery->select('*', 'dtb_baseinfo'); |
---|
148 | |
---|
149 | if (isset($arrRet[0])) { |
---|
150 | $data = $arrRet[0]; |
---|
151 | } else { |
---|
152 | $data = array(); |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | return $data; |
---|
157 | } |
---|
158 | |
---|
159 | /* 選択中のアイテムのルートカテゴリIDを取得する */ |
---|
160 | function sfGetRootId() { |
---|
161 | |
---|
162 | if(!$this->g_root_on) { |
---|
163 | $this->g_root_on = true; |
---|
164 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
165 | |
---|
166 | if (!isset($_GET['product_id'])) $_GET['product_id'] = ""; |
---|
167 | if (!isset($_GET['category_id'])) $_GET['category_id'] = ""; |
---|
168 | |
---|
169 | if(!empty($_GET['product_id']) || !empty($_GET['category_id'])) { |
---|
170 | // 選択中のカテゴリIDを判定する |
---|
171 | $category_id = $this->sfGetCategoryId($_GET['product_id'], $_GET['category_id']); |
---|
172 | // ROOTカテゴリIDの取得 |
---|
173 | $arrRet = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $category_id); |
---|
174 | $root_id = isset($arrRet[0]) ? $arrRet[0] : ""; |
---|
175 | } else { |
---|
176 | // ROOTカテゴリIDをなしに設定する |
---|
177 | $root_id = ""; |
---|
178 | } |
---|
179 | $this->g_root_id = $root_id; |
---|
180 | } |
---|
181 | return $this->g_root_id; |
---|
182 | } |
---|
183 | |
---|
184 | /** |
---|
185 | * 商品規格情報を取得する. |
---|
186 | * |
---|
187 | * TODO SC_Product クラスへ移動 |
---|
188 | * |
---|
189 | * @param array $arrID 規格ID |
---|
190 | * @param boolean $includePrivateProducts 非公開商品を含むか |
---|
191 | * @return array 規格情報の配列 |
---|
192 | */ |
---|
193 | function sfGetProductsClass($arrID, $includePrivateProducts = false) { |
---|
194 | list($product_id, $classcategory_id1, $classcategory_id2) = $arrID; |
---|
195 | |
---|
196 | if (strlen($classcategory_id1) == 0) { |
---|
197 | $classcategory_id1 = null; |
---|
198 | } |
---|
199 | if (strlen($classcategory_id2) == 0) { |
---|
200 | $classcategory_id2 = null; |
---|
201 | } |
---|
202 | |
---|
203 | // 商品規格取得 |
---|
204 | $objProduct = new SC_Product(); |
---|
205 | $detail = $objProduct->getDetail($product_id); |
---|
206 | $productsClass = $objProduct->getProductsClassFullByProductId($product_id); |
---|
207 | foreach ($productsClass as $val) { |
---|
208 | |
---|
209 | if ($val['classcategory_id1'] == $classcategory_id1 |
---|
210 | && $val['classcategory_id2'] == $classcategory_id2) { |
---|
211 | |
---|
212 | $detail = array_merge($val, $detail); |
---|
213 | if (!$includePrivateProducts) { |
---|
214 | if ($detail['status'] == 1) { |
---|
215 | return $detail; |
---|
216 | } |
---|
217 | } |
---|
218 | return $detail; |
---|
219 | } |
---|
220 | } |
---|
221 | } |
---|
222 | |
---|
223 | /** |
---|
224 | * 支払い方法を取得する. |
---|
225 | * |
---|
226 | * @return void |
---|
227 | */ |
---|
228 | function sfGetPayment() { |
---|
229 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
230 | // 購入金額が条件額以下の項目を取得 |
---|
231 | $where = "del_flg = 0"; |
---|
232 | $objQuery->setOrder("fix, rank DESC"); |
---|
233 | $arrRet = $objQuery->select("payment_id, payment_method, rule", "dtb_payment", $where); |
---|
234 | return $arrRet; |
---|
235 | } |
---|
236 | |
---|
237 | /** |
---|
238 | * カート内商品の集計処理を行う. |
---|
239 | * |
---|
240 | * 管理機能での利用は想定していないので注意。(非公開商品は除外される。) |
---|
241 | * |
---|
242 | * @param LC_Page $objPage ページクラスのインスタンス |
---|
243 | * @param SC_CartSession $objCartSess カートセッションのインスタンス |
---|
244 | * @param null $dummy1 互換性確保用(決済モジュール互換のため) |
---|
245 | * @return LC_Page 集計処理後のページクラスインスタンス |
---|
246 | */ |
---|
247 | function sfTotalCart(&$objPage, $objCartSess, $dummy1 = null) { |
---|
248 | |
---|
249 | // 規格名一覧 |
---|
250 | $arrClassName = $this->sfGetIDValueList("dtb_class", "class_id", "name"); |
---|
251 | // 規格分類名一覧 |
---|
252 | $arrClassCatName = $this->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); |
---|
253 | |
---|
254 | $objPage->tpl_total_pretax = 0; // 費用合計(税込み) |
---|
255 | $objPage->tpl_total_tax = 0; // 消費税合計 |
---|
256 | $objPage->tpl_total_point = 0; // ポイント合計 |
---|
257 | |
---|
258 | // カート内情報の取得 |
---|
259 | $arrQuantityInfo_by_product = array(); |
---|
260 | $cnt = 0; |
---|
261 | foreach ($objCartSess->getCartList() as $arrCart) { |
---|
262 | // 商品規格情報の取得 |
---|
263 | $arrData = $this->sfGetProductsClass($arrCart['id']); |
---|
264 | $limit = null; |
---|
265 | // DBに存在する商品 |
---|
266 | if (count($arrData) > 0) { |
---|
267 | |
---|
268 | // 購入制限数を求める。 |
---|
269 | if ($arrData['stock_unlimited'] != '1' && SC_Utils_Ex::sfIsInt($arrData['sale_limit'])) { |
---|
270 | $limit = min($arrData['sale_limit'], $arrData['stock']); |
---|
271 | } elseif (SC_Utils_Ex::sfIsInt($arrData['sale_limit'])) { |
---|
272 | $limit = $arrData['sale_limit']; |
---|
273 | } elseif ($arrData['stock_unlimited'] != '1') { |
---|
274 | $limit = $arrData['stock']; |
---|
275 | } |
---|
276 | |
---|
277 | if (!is_null($limit) && $arrCart['quantity'] > $limit) { |
---|
278 | if ($limit > 0) { |
---|
279 | // カート内商品数を制限に合わせる |
---|
280 | $objCartSess->setProductValue($arrCart['id'], 'quantity', $limit); |
---|
281 | $quantity = $limit; |
---|
282 | $objPage->tpl_message .= "※「" . $arrData['name'] . "」は販売制限(または在庫が不足)しております。一度に数量{$limit}以上の購入はできません。\n"; |
---|
283 | } else { |
---|
284 | // 売り切れ商品をカートから削除する |
---|
285 | $objCartSess->delProduct($arrCart['cart_no']); |
---|
286 | $objPage->tpl_message .= "※「" . $arrData['name'] . "」は売り切れました。\n"; |
---|
287 | continue; |
---|
288 | } |
---|
289 | } else { |
---|
290 | $quantity = $arrCart['quantity']; |
---|
291 | } |
---|
292 | |
---|
293 | // (商品規格単位でなく)商品単位での評価のための準備 |
---|
294 | $product_id = $arrCart['id'][0]; |
---|
295 | $arrQuantityInfo_by_product[$product_id]['quantity'] += $quantity; |
---|
296 | $arrQuantityInfo_by_product[$product_id]['sale_limit'] = $arrData['sale_limit']; |
---|
297 | $arrQuantityInfo_by_product[$product_id]['name'] = $arrData['name']; |
---|
298 | |
---|
299 | $objPage->arrProductsClass[$cnt] = $arrData; |
---|
300 | $objPage->arrProductsClass[$cnt]['quantity'] = $quantity; |
---|
301 | $objPage->arrProductsClass[$cnt]['cart_no'] = $arrCart['cart_no']; |
---|
302 | $objPage->arrProductsClass[$cnt]['class_name1'] = |
---|
303 | isset($arrClassName[$arrData['class_id1']]) |
---|
304 | ? $arrClassName[$arrData['class_id1']] : ""; |
---|
305 | |
---|
306 | $objPage->arrProductsClass[$cnt]['class_name2'] = |
---|
307 | isset($arrClassName[$arrData['class_id2']]) |
---|
308 | ? $arrClassName[$arrData['class_id2']] : ""; |
---|
309 | |
---|
310 | $objPage->arrProductsClass[$cnt]['classcategory_name1'] = |
---|
311 | $arrClassCatName[$arrData['classcategory_id1']]; |
---|
312 | |
---|
313 | $objPage->arrProductsClass[$cnt]['classcategory_name2'] = |
---|
314 | $arrClassCatName[$arrData['classcategory_id2']]; |
---|
315 | |
---|
316 | // 価格の登録 |
---|
317 | if ($arrData['price02'] != "") { |
---|
318 | $objCartSess->setProductValue($arrCart['id'], 'price', $arrData['price02']); |
---|
319 | $objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price02']; |
---|
320 | } else { |
---|
321 | $objCartSess->setProductValue($arrCart['id'], 'price', $arrData['price01']); |
---|
322 | $objPage->arrProductsClass[$cnt]['uniq_price'] = $arrData['price01']; |
---|
323 | } |
---|
324 | // ポイント付与率の登録 |
---|
325 | if (USE_POINT !== false) { |
---|
326 | $objCartSess->setProductValue($arrCart['id'], 'point_rate', $arrData['point_rate']); |
---|
327 | } |
---|
328 | // 商品ごとの合計金額 |
---|
329 | $objPage->arrProductsClass[$cnt]['total_pretax'] = $objCartSess->getProductTotal($arrCart['id']); |
---|
330 | // 送料の合計を計算する |
---|
331 | $objPage->tpl_total_deliv_fee+= ($arrData['deliv_fee'] * $arrCart['quantity']); |
---|
332 | $cnt++; |
---|
333 | } else { // DBに商品が見つからない場合、 |
---|
334 | $objPage->tpl_message .= "※ 現時点で販売していない商品が含まれておりました。該当商品をカートから削除しました。\n"; |
---|
335 | // カート商品の削除 |
---|
336 | $objCartSess->delProduct($arrCart['cart_no']); |
---|
337 | } |
---|
338 | } |
---|
339 | |
---|
340 | foreach ($arrQuantityInfo_by_product as $product_id => $quantityInfo) { |
---|
341 | if (SC_Utils_Ex::sfIsInt($quantityInfo['sale_limit']) && $quantityInfo['quantity'] > $quantityInfo['sale_limit']) { |
---|
342 | $objPage->tpl_error = "※「{$quantityInfo['name']}」は数量「{$quantityInfo['sale_limit']}」以下に販売制限しております。一度にこれ以上の購入はできません。\n"; |
---|
343 | // 販売制限に引っかかった商品をマークする |
---|
344 | foreach (array_keys($objPage->arrProductsClass) as $key) { |
---|
345 | $ProductsClass =& $objPage->arrProductsClass[$key]; |
---|
346 | if ($ProductsClass['product_id'] == $product_id) { |
---|
347 | $ProductsClass['error'] = true; |
---|
348 | } |
---|
349 | } |
---|
350 | } |
---|
351 | } |
---|
352 | |
---|
353 | // 全商品合計金額(税込み) |
---|
354 | $objPage->tpl_total_pretax = $objCartSess->getAllProductsTotal(); |
---|
355 | // 全商品合計消費税 |
---|
356 | $objPage->tpl_total_tax = $objCartSess->getAllProductsTax(); |
---|
357 | // 全商品合計ポイント |
---|
358 | if (USE_POINT !== false) { |
---|
359 | $objPage->tpl_total_point = $objCartSess->getAllProductsPoint(); |
---|
360 | } |
---|
361 | |
---|
362 | return $objPage; |
---|
363 | } |
---|
364 | |
---|
365 | /** |
---|
366 | * 受注一時テーブルへの書き込み処理を行う. |
---|
367 | * |
---|
368 | * @param string $uniqid ユニークID |
---|
369 | * @param array $sqlval SQLの値の配列 |
---|
370 | * @return void |
---|
371 | */ |
---|
372 | function sfRegistTempOrder($uniqid, $sqlval) { |
---|
373 | if($uniqid != "") { |
---|
374 | // 既存データのチェック |
---|
375 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
376 | $where = "order_temp_id = ?"; |
---|
377 | $cnt = $objQuery->count("dtb_order_temp", $where, array($uniqid)); |
---|
378 | // 既存データがない場合 |
---|
379 | if ($cnt == 0) { |
---|
380 | // 初回書き込み時に会員の登録済み情報を取り込む |
---|
381 | $sqlval = $this->sfGetCustomerSqlVal($uniqid, $sqlval); |
---|
382 | $sqlval['create_date'] = "now()"; |
---|
383 | $objQuery->insert("dtb_order_temp", $sqlval); |
---|
384 | } else { |
---|
385 | $objQuery->update("dtb_order_temp", $sqlval, $where, array($uniqid)); |
---|
386 | } |
---|
387 | |
---|
388 | // 受注_Tempテーブルの名称列を更新 |
---|
389 | // ・決済モジュールに対応するため、static メソッドとして扱う |
---|
390 | SC_Helper_DB_Ex::sfUpdateOrderNameCol($uniqid, true); |
---|
391 | } |
---|
392 | } |
---|
393 | |
---|
394 | /** |
---|
395 | * 会員情報から SQL文の値を生成する. |
---|
396 | * |
---|
397 | * @param string $uniqid ユニークID |
---|
398 | * @param array $sqlval SQL の値の配列 |
---|
399 | * @return array 会員情報を含んだ SQL の値の配列 |
---|
400 | */ |
---|
401 | function sfGetCustomerSqlVal($uniqid, $sqlval) { |
---|
402 | $objCustomer = new SC_Customer(); |
---|
403 | // 会員情報登録処理 |
---|
404 | if ($objCustomer->isLoginSuccess(true)) { |
---|
405 | // 登録データの作成 |
---|
406 | $sqlval['order_temp_id'] = $uniqid; |
---|
407 | $sqlval['update_date'] = 'Now()'; |
---|
408 | $sqlval['customer_id'] = $objCustomer->getValue('customer_id'); |
---|
409 | $sqlval['order_name01'] = $objCustomer->getValue('name01'); |
---|
410 | $sqlval['order_name02'] = $objCustomer->getValue('name02'); |
---|
411 | $sqlval['order_kana01'] = $objCustomer->getValue('kana01'); |
---|
412 | $sqlval['order_kana02'] = $objCustomer->getValue('kana02'); |
---|
413 | $sqlval['order_sex'] = $objCustomer->getValue('sex'); |
---|
414 | $sqlval['order_zip01'] = $objCustomer->getValue('zip01'); |
---|
415 | $sqlval['order_zip02'] = $objCustomer->getValue('zip02'); |
---|
416 | $sqlval['order_pref'] = $objCustomer->getValue('pref'); |
---|
417 | $sqlval['order_addr01'] = $objCustomer->getValue('addr01'); |
---|
418 | $sqlval['order_addr02'] = $objCustomer->getValue('addr02'); |
---|
419 | $sqlval['order_tel01'] = $objCustomer->getValue('tel01'); |
---|
420 | $sqlval['order_tel02'] = $objCustomer->getValue('tel02'); |
---|
421 | $sqlval['order_tel03'] = $objCustomer->getValue('tel03'); |
---|
422 | if (defined('MOBILE_SITE')) { |
---|
423 | $email_mobile = $objCustomer->getValue('email_mobile'); |
---|
424 | if (empty($email_mobile)) { |
---|
425 | $sqlval['order_email'] = $objCustomer->getValue('email'); |
---|
426 | } else { |
---|
427 | $sqlval['order_email'] = $email_mobile; |
---|
428 | } |
---|
429 | } else { |
---|
430 | $sqlval['order_email'] = $objCustomer->getValue('email'); |
---|
431 | } |
---|
432 | $sqlval['order_job'] = $objCustomer->getValue('job'); |
---|
433 | $sqlval['order_birth'] = $objCustomer->getValue('birth'); |
---|
434 | } |
---|
435 | return $sqlval; |
---|
436 | } |
---|
437 | |
---|
438 | /** |
---|
439 | * 会員編集登録処理を行う. |
---|
440 | * |
---|
441 | * @param array $array パラメータの配列 |
---|
442 | * @param array $arrRegistColumn 登録するカラムの配列 |
---|
443 | * @return void |
---|
444 | */ |
---|
445 | function sfEditCustomerData($array, $arrRegistColumn) { |
---|
446 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
447 | |
---|
448 | foreach ($arrRegistColumn as $data) { |
---|
449 | if ($data["column"] != "password") { |
---|
450 | if($array[ $data['column'] ] != "") { |
---|
451 | $arrRegist[ $data["column"] ] = $array[ $data["column"] ]; |
---|
452 | } else { |
---|
453 | $arrRegist[ $data['column'] ] = NULL; |
---|
454 | } |
---|
455 | } |
---|
456 | } |
---|
457 | if (strlen($array["year"]) > 0 && strlen($array["month"]) > 0 && strlen($array["day"]) > 0) { |
---|
458 | $arrRegist["birth"] = $array["year"] ."/". $array["month"] ."/". $array["day"] ." 00:00:00"; |
---|
459 | } else { |
---|
460 | $arrRegist["birth"] = NULL; |
---|
461 | } |
---|
462 | |
---|
463 | //-- パスワードの更新がある場合は暗号化。(更新がない場合はUPDATE文を構成しない) |
---|
464 | if ($array["password"] != DEFAULT_PASSWORD) $arrRegist["password"] = sha1($array["password"] . ":" . AUTH_MAGIC); |
---|
465 | $arrRegist["update_date"] = "NOW()"; |
---|
466 | |
---|
467 | //-- 編集登録実行 |
---|
468 | $objQuery->update("dtb_customer", $arrRegist, "customer_id = ? ", array($array['customer_id'])); |
---|
469 | } |
---|
470 | |
---|
471 | /** |
---|
472 | * 注文番号、利用ポイント、加算ポイントから最終ポイントを取得する. |
---|
473 | * |
---|
474 | * @param integer $order_id 注文番号 |
---|
475 | * @param integer $use_point 利用ポイント |
---|
476 | * @param integer $add_point 加算ポイント |
---|
477 | * @return array 最終ポイントの配列 |
---|
478 | */ |
---|
479 | function sfGetCustomerPoint($order_id, $use_point, $add_point) { |
---|
480 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
481 | $arrRet = $objQuery->select("customer_id", "dtb_order", "order_id = ?", array($order_id)); |
---|
482 | $customer_id = $arrRet[0]['customer_id']; |
---|
483 | if ($customer_id != "" && $customer_id >= 1) { |
---|
484 | if (USE_POINT !== false) { |
---|
485 | $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id)); |
---|
486 | $point = $arrRet[0]['point']; |
---|
487 | $total_point = $arrRet[0]['point'] - $use_point + $add_point; |
---|
488 | } else { |
---|
489 | $total_point = 0; |
---|
490 | $point = 0; |
---|
491 | } |
---|
492 | } else { |
---|
493 | $total_point = ""; |
---|
494 | $point = ""; |
---|
495 | } |
---|
496 | return array($point, $total_point); |
---|
497 | } |
---|
498 | |
---|
499 | /** |
---|
500 | * 顧客番号、利用ポイント、加算ポイントから最終ポイントを取得する. |
---|
501 | * |
---|
502 | * @param integer $customer_id 顧客番号 |
---|
503 | * @param integer $use_point 利用ポイント |
---|
504 | * @param integer $add_point 加算ポイント |
---|
505 | * @return array 最終ポイントの配列 |
---|
506 | */ |
---|
507 | function sfGetCustomerPointFromCid($customer_id, $use_point, $add_point) { |
---|
508 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
509 | if (USE_POINT !== false) { |
---|
510 | $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id)); |
---|
511 | $point = $arrRet[0]['point']; |
---|
512 | $total_point = $arrRet[0]['point'] - $use_point + $add_point; |
---|
513 | } else { |
---|
514 | $total_point = 0; |
---|
515 | $point = 0; |
---|
516 | } |
---|
517 | return array($point, $total_point); |
---|
518 | } |
---|
519 | /** |
---|
520 | * カテゴリツリーの取得を行う. |
---|
521 | * |
---|
522 | * @param integer $parent_category_id 親カテゴリID |
---|
523 | * @param bool $count_check 登録商品数のチェックを行う場合 true |
---|
524 | * @return array カテゴリツリーの配列 |
---|
525 | */ |
---|
526 | function sfGetCatTree($parent_category_id, $count_check = false) { |
---|
527 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
528 | $col = ""; |
---|
529 | $col .= " cat.category_id,"; |
---|
530 | $col .= " cat.category_name,"; |
---|
531 | $col .= " cat.parent_category_id,"; |
---|
532 | $col .= " cat.level,"; |
---|
533 | $col .= " cat.rank,"; |
---|
534 | $col .= " cat.creator_id,"; |
---|
535 | $col .= " cat.create_date,"; |
---|
536 | $col .= " cat.update_date,"; |
---|
537 | $col .= " cat.del_flg, "; |
---|
538 | $col .= " ttl.product_count"; |
---|
539 | $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id"; |
---|
540 | // 登録商品数のチェック |
---|
541 | if($count_check) { |
---|
542 | $where = "del_flg = 0 AND product_count > 0"; |
---|
543 | } else { |
---|
544 | $where = "del_flg = 0"; |
---|
545 | } |
---|
546 | $objQuery->setOption("ORDER BY rank DESC"); |
---|
547 | $arrRet = $objQuery->select($col, $from, $where); |
---|
548 | |
---|
549 | $arrParentID = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id); |
---|
550 | |
---|
551 | foreach($arrRet as $key => $array) { |
---|
552 | foreach($arrParentID as $val) { |
---|
553 | if($array['category_id'] == $val) { |
---|
554 | $arrRet[$key]['display'] = 1; |
---|
555 | break; |
---|
556 | } |
---|
557 | } |
---|
558 | } |
---|
559 | |
---|
560 | return $arrRet; |
---|
561 | } |
---|
562 | |
---|
563 | /** |
---|
564 | * カテゴリツリーの取得を複数カテゴリーで行う. |
---|
565 | * |
---|
566 | * @param integer $product_id 商品ID |
---|
567 | * @param bool $count_check 登録商品数のチェックを行う場合 true |
---|
568 | * @return array カテゴリツリーの配列 |
---|
569 | */ |
---|
570 | function sfGetMultiCatTree($product_id, $count_check = false) { |
---|
571 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
572 | $col = ""; |
---|
573 | $col .= " cat.category_id,"; |
---|
574 | $col .= " cat.category_name,"; |
---|
575 | $col .= " cat.parent_category_id,"; |
---|
576 | $col .= " cat.level,"; |
---|
577 | $col .= " cat.rank,"; |
---|
578 | $col .= " cat.creator_id,"; |
---|
579 | $col .= " cat.create_date,"; |
---|
580 | $col .= " cat.update_date,"; |
---|
581 | $col .= " cat.del_flg, "; |
---|
582 | $col .= " ttl.product_count"; |
---|
583 | $from = "dtb_category as cat left join dtb_category_total_count as ttl on ttl.category_id = cat.category_id"; |
---|
584 | // 登録商品数のチェック |
---|
585 | if($count_check) { |
---|
586 | $where = "del_flg = 0 AND product_count > 0"; |
---|
587 | } else { |
---|
588 | $where = "del_flg = 0"; |
---|
589 | } |
---|
590 | $objQuery->setOption("ORDER BY rank DESC"); |
---|
591 | $arrRet = $objQuery->select($col, $from, $where); |
---|
592 | |
---|
593 | $arrCategory_id = $this->sfGetCategoryId($product_id); |
---|
594 | |
---|
595 | $arrCatTree = array(); |
---|
596 | foreach ($arrCategory_id as $pkey => $parent_category_id) { |
---|
597 | $arrParentID = $this->sfGetParents($objQuery, 'dtb_category', 'parent_category_id', 'category_id', $parent_category_id); |
---|
598 | |
---|
599 | foreach($arrParentID as $pid) { |
---|
600 | foreach($arrRet as $key => $array) { |
---|
601 | if($array['category_id'] == $pid) { |
---|
602 | $arrCatTree[$pkey][] = $arrRet[$key]; |
---|
603 | break; |
---|
604 | } |
---|
605 | } |
---|
606 | } |
---|
607 | } |
---|
608 | |
---|
609 | return $arrCatTree; |
---|
610 | } |
---|
611 | |
---|
612 | /** |
---|
613 | * 親カテゴリーを連結した文字列を取得する. |
---|
614 | * |
---|
615 | * @param integer $category_id カテゴリID |
---|
616 | * @return string 親カテゴリーを連結した文字列 |
---|
617 | */ |
---|
618 | function sfGetCatCombName($category_id){ |
---|
619 | // 商品が属するカテゴリIDを縦に取得 |
---|
620 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
621 | $arrCatID = $this->sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id); |
---|
622 | $ConbName = ""; |
---|
623 | |
---|
624 | // カテゴリー名称を取得する |
---|
625 | foreach($arrCatID as $key => $val){ |
---|
626 | $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?"; |
---|
627 | $arrVal = array($val); |
---|
628 | $CatName = $objQuery->getOne($sql,$arrVal); |
---|
629 | $ConbName .= $CatName . ' | '; |
---|
630 | } |
---|
631 | // 最後の | をカットする |
---|
632 | $ConbName = substr_replace($ConbName, "", strlen($ConbName) - 2, 2); |
---|
633 | |
---|
634 | return $ConbName; |
---|
635 | } |
---|
636 | |
---|
637 | /** |
---|
638 | * 指定したカテゴリーIDのカテゴリーを取得する. |
---|
639 | * |
---|
640 | * @param integer $category_id カテゴリID |
---|
641 | * @return array 指定したカテゴリーIDのカテゴリー |
---|
642 | */ |
---|
643 | function sfGetCat($category_id){ |
---|
644 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
645 | |
---|
646 | // カテゴリーを取得する |
---|
647 | $arrVal = array($category_id); |
---|
648 | $res = $objQuery->select('category_id AS id, category_name AS name', 'dtb_category', 'category_id = ?', $arrVal); |
---|
649 | |
---|
650 | return $res[0]; |
---|
651 | } |
---|
652 | |
---|
653 | /** |
---|
654 | * 指定したカテゴリーIDの大カテゴリーを取得する. |
---|
655 | * |
---|
656 | * @param integer $category_id カテゴリID |
---|
657 | * @return array 指定したカテゴリーIDの大カテゴリー |
---|
658 | */ |
---|
659 | function sfGetFirstCat($category_id){ |
---|
660 | // 商品が属するカテゴリIDを縦に取得 |
---|
661 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
662 | $arrRet = array(); |
---|
663 | $arrCatID = $this->sfGetParents($objQuery, "dtb_category", "parent_category_id", "category_id", $category_id); |
---|
664 | $arrRet['id'] = $arrCatID[0]; |
---|
665 | |
---|
666 | // カテゴリー名称を取得する |
---|
667 | $sql = "SELECT category_name FROM dtb_category WHERE category_id = ?"; |
---|
668 | $arrVal = array($arrRet['id']); |
---|
669 | $arrRet['name'] = $objQuery->getOne($sql,$arrVal); |
---|
670 | |
---|
671 | return $arrRet; |
---|
672 | } |
---|
673 | |
---|
674 | /** |
---|
675 | * カテゴリツリーの取得を行う. |
---|
676 | * |
---|
677 | * $products_check:true商品登録済みのものだけ取得する |
---|
678 | * |
---|
679 | * @param string $addwhere 追加する WHERE 句 |
---|
680 | * @param bool $products_check 商品の存在するカテゴリのみ取得する場合 true |
---|
681 | * @param string $head カテゴリ名のプレフィックス文字列 |
---|
682 | * @return array カテゴリツリーの配列 |
---|
683 | */ |
---|
684 | function sfGetCategoryList($addwhere = "", $products_check = false, $head = CATEGORY_HEAD) { |
---|
685 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
686 | $where = "del_flg = 0"; |
---|
687 | |
---|
688 | if($addwhere != "") { |
---|
689 | $where.= " AND $addwhere"; |
---|
690 | } |
---|
691 | |
---|
692 | $objQuery->setOption("ORDER BY rank DESC"); |
---|
693 | |
---|
694 | if($products_check) { |
---|
695 | $col = "T1.category_id, category_name, level"; |
---|
696 | $from = "dtb_category AS T1 LEFT JOIN dtb_category_total_count AS T2 ON T1.category_id = T2.category_id"; |
---|
697 | $where .= " AND product_count > 0"; |
---|
698 | } else { |
---|
699 | $col = "category_id, category_name, level"; |
---|
700 | $from = "dtb_category"; |
---|
701 | } |
---|
702 | |
---|
703 | $arrRet = $objQuery->select($col, $from, $where); |
---|
704 | |
---|
705 | $max = count($arrRet); |
---|
706 | for($cnt = 0; $cnt < $max; $cnt++) { |
---|
707 | $id = $arrRet[$cnt]['category_id']; |
---|
708 | $name = $arrRet[$cnt]['category_name']; |
---|
709 | $arrList[$id] = str_repeat($head, $arrRet[$cnt]['level']) . $name; |
---|
710 | } |
---|
711 | return $arrList; |
---|
712 | } |
---|
713 | |
---|
714 | /** |
---|
715 | * カテゴリーツリーの取得を行う. |
---|
716 | * |
---|
717 | * 親カテゴリの Value=0 を対象とする |
---|
718 | * |
---|
719 | * @param bool $parent_zero 親カテゴリの Value=0 の場合 true |
---|
720 | * @return array カテゴリツリーの配列 |
---|
721 | */ |
---|
722 | function sfGetLevelCatList($parent_zero = true) { |
---|
723 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
724 | |
---|
725 | // カテゴリ名リストを取得 |
---|
726 | $col = "category_id, parent_category_id, category_name"; |
---|
727 | $where = "del_flg = 0"; |
---|
728 | $objQuery->setOption("ORDER BY level"); |
---|
729 | $arrRet = $objQuery->select($col, "dtb_category", $where); |
---|
730 | $arrCatName = array(); |
---|
731 | foreach ($arrRet as $arrTmp) { |
---|
732 | $arrCatName[$arrTmp['category_id']] = |
---|
733 | (($arrTmp['parent_category_id'] > 0)? |
---|
734 | $arrCatName[$arrTmp['parent_category_id']] : "") |
---|
735 | . CATEGORY_HEAD . $arrTmp['category_name']; |
---|
736 | } |
---|
737 | |
---|
738 | $col = "category_id, parent_category_id, category_name, level"; |
---|
739 | $where = "del_flg = 0"; |
---|
740 | $objQuery->setOption("ORDER BY rank DESC"); |
---|
741 | $arrRet = $objQuery->select($col, "dtb_category", $where); |
---|
742 | $max = count($arrRet); |
---|
743 | |
---|
744 | for($cnt = 0; $cnt < $max; $cnt++) { |
---|
745 | if($parent_zero) { |
---|
746 | if($arrRet[$cnt]['level'] == LEVEL_MAX) { |
---|
747 | $arrValue[$cnt] = $arrRet[$cnt]['category_id']; |
---|
748 | } else { |
---|
749 | $arrValue[$cnt] = ""; |
---|
750 | } |
---|
751 | } else { |
---|
752 | $arrValue[$cnt] = $arrRet[$cnt]['category_id']; |
---|
753 | } |
---|
754 | |
---|
755 | $arrOutput[$cnt] = $arrCatName[$arrRet[$cnt]['category_id']]; |
---|
756 | } |
---|
757 | |
---|
758 | return array($arrValue, $arrOutput); |
---|
759 | } |
---|
760 | |
---|
761 | /** |
---|
762 | * 選択中の商品のカテゴリを取得する. |
---|
763 | * |
---|
764 | * @param integer $product_id プロダクトID |
---|
765 | * @param integer $category_id カテゴリID |
---|
766 | * @return array 選択中の商品のカテゴリIDの配列 |
---|
767 | * |
---|
768 | */ |
---|
769 | function sfGetCategoryId($product_id, $category_id = 0, $closed = false) { |
---|
770 | if ($closed) { |
---|
771 | $status = ""; |
---|
772 | } else { |
---|
773 | $status = "status = 1"; |
---|
774 | } |
---|
775 | |
---|
776 | if(!$this->g_category_on) { |
---|
777 | $this->g_category_on = true; |
---|
778 | $category_id = (int) $category_id; |
---|
779 | $product_id = (int) $product_id; |
---|
780 | if (SC_Utils_Ex::sfIsInt($category_id) && $category_id != 0 && $this->sfIsRecord("dtb_category","category_id", $category_id)) { |
---|
781 | $this->g_category_id = array($category_id); |
---|
782 | } else if (SC_Utils_Ex::sfIsInt($product_id) && $product_id != 0 && $this->sfIsRecord("dtb_products","product_id", $product_id, $status)) { |
---|
783 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
784 | $where = "product_id = ?"; |
---|
785 | $category_id = $objQuery->getCol("dtb_product_categories", "category_id", "product_id = ?", array($product_id)); |
---|
786 | $this->g_category_id = $category_id; |
---|
787 | } else { |
---|
788 | // 不正な場合は、空の配列を返す。 |
---|
789 | $this->g_category_id = array(); |
---|
790 | } |
---|
791 | } |
---|
792 | return $this->g_category_id; |
---|
793 | } |
---|
794 | |
---|
795 | /** |
---|
796 | * 商品をカテゴリの先頭に追加する. |
---|
797 | * |
---|
798 | * @param integer $category_id カテゴリID |
---|
799 | * @param integer $product_id プロダクトID |
---|
800 | * @return void |
---|
801 | */ |
---|
802 | function addProductBeforCategories($category_id, $product_id) { |
---|
803 | |
---|
804 | $sqlval = array("category_id" => $category_id, |
---|
805 | "product_id" => $product_id); |
---|
806 | |
---|
807 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
808 | |
---|
809 | // 現在の商品カテゴリを取得 |
---|
810 | $arrCat = $objQuery->select("product_id, category_id, rank", |
---|
811 | "dtb_product_categories", |
---|
812 | "category_id = ?", |
---|
813 | array($category_id)); |
---|
814 | |
---|
815 | $max = "0"; |
---|
816 | foreach ($arrCat as $val) { |
---|
817 | // 同一商品が存在する場合は登録しない |
---|
818 | if ($val["product_id"] == $product_id) { |
---|
819 | return; |
---|
820 | } |
---|
821 | // 最上位ランクを取得 |
---|
822 | $max = ($max < $val["rank"]) ? $val["rank"] : $max; |
---|
823 | } |
---|
824 | $sqlval["rank"] = $max + 1; |
---|
825 | $objQuery->insert("dtb_product_categories", $sqlval); |
---|
826 | } |
---|
827 | |
---|
828 | /** |
---|
829 | * 商品をカテゴリの末尾に追加する. |
---|
830 | * |
---|
831 | * @param integer $category_id カテゴリID |
---|
832 | * @param integer $product_id プロダクトID |
---|
833 | * @return void |
---|
834 | */ |
---|
835 | function addProductAfterCategories($category_id, $product_id) { |
---|
836 | $sqlval = array("category_id" => $category_id, |
---|
837 | "product_id" => $product_id); |
---|
838 | |
---|
839 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
840 | |
---|
841 | // 現在の商品カテゴリを取得 |
---|
842 | $arrCat = $objQuery->select("product_id, category_id, rank", |
---|
843 | "dtb_product_categories", |
---|
844 | "category_id = ?", |
---|
845 | array($category_id)); |
---|
846 | |
---|
847 | $min = 0; |
---|
848 | foreach ($arrCat as $val) { |
---|
849 | // 同一商品が存在する場合は登録しない |
---|
850 | if ($val["product_id"] == $product_id) { |
---|
851 | return; |
---|
852 | } |
---|
853 | // 最下位ランクを取得 |
---|
854 | $min = ($min < $val["rank"]) ? $val["rank"] : $min; |
---|
855 | } |
---|
856 | $sqlval["rank"] = $min; |
---|
857 | $objQuery->insert("dtb_product_categories", $sqlval); |
---|
858 | } |
---|
859 | |
---|
860 | /** |
---|
861 | * 商品をカテゴリから削除する. |
---|
862 | * |
---|
863 | * @param integer $category_id カテゴリID |
---|
864 | * @param integer $product_id プロダクトID |
---|
865 | * @return void |
---|
866 | */ |
---|
867 | function removeProductByCategories($category_id, $product_id) { |
---|
868 | $sqlval = array("category_id" => $category_id, |
---|
869 | "product_id" => $product_id); |
---|
870 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
871 | $objQuery->delete("dtb_product_categories", |
---|
872 | "category_id = ? AND product_id = ?", $sqlval); |
---|
873 | } |
---|
874 | |
---|
875 | /** |
---|
876 | * 商品カテゴリを更新する. |
---|
877 | * |
---|
878 | * @param array $arrCategory_id 登録するカテゴリIDの配列 |
---|
879 | * @param integer $product_id プロダクトID |
---|
880 | * @return void |
---|
881 | */ |
---|
882 | function updateProductCategories($arrCategory_id, $product_id) { |
---|
883 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
884 | |
---|
885 | // 現在のカテゴリ情報を取得 |
---|
886 | $arrCurrentCat = $objQuery->select("product_id, category_id, rank", |
---|
887 | "dtb_product_categories", |
---|
888 | "product_id = ?", |
---|
889 | array($product_id)); |
---|
890 | |
---|
891 | // 登録するカテゴリ情報と比較 |
---|
892 | foreach ($arrCurrentCat as $val) { |
---|
893 | |
---|
894 | // 登録しないカテゴリを削除 |
---|
895 | if (!in_array($val["category_id"], $arrCategory_id)) { |
---|
896 | $this->removeProductByCategories($val["category_id"], $product_id); |
---|
897 | } |
---|
898 | } |
---|
899 | |
---|
900 | // カテゴリを登録 |
---|
901 | foreach ($arrCategory_id as $category_id) { |
---|
902 | $this->addProductBeforCategories($category_id, $product_id); |
---|
903 | } |
---|
904 | } |
---|
905 | |
---|
906 | /** |
---|
907 | * カテゴリ数の登録を行う. |
---|
908 | * |
---|
909 | * @param SC_Query $objQuery SC_Query インスタンス |
---|
910 | * @return void |
---|
911 | */ |
---|
912 | function sfCategory_Count($objQuery){ |
---|
913 | |
---|
914 | //テーブル内容の削除 |
---|
915 | $objQuery->query("DELETE FROM dtb_category_count"); |
---|
916 | $objQuery->query("DELETE FROM dtb_category_total_count"); |
---|
917 | |
---|
918 | $sql_where .= 'alldtl.del_flg = 0 AND alldtl.status = 1'; |
---|
919 | // 在庫無し商品の非表示 |
---|
920 | if (NOSTOCK_HIDDEN === true) { |
---|
921 | $sql_where .= ' AND (alldtl.stock_max >= 1 OR alldtl.stock_unlimited_max = 1)'; |
---|
922 | } |
---|
923 | |
---|
924 | //子カテゴリ内の商品数を集計する |
---|
925 | |
---|
926 | // カテゴリ情報を取得 |
---|
927 | $arrCat = $objQuery->select('category_id', 'dtb_category'); |
---|
928 | |
---|
929 | $objProduct = new SC_Product(); |
---|
930 | |
---|
931 | foreach ($arrCat as $row) { |
---|
932 | $category_id = $row['category_id']; |
---|
933 | $arrval = array(); |
---|
934 | |
---|
935 | $arrval[] = $category_id; |
---|
936 | |
---|
937 | list($tmp_where, $tmp_arrval) = $this->sfGetCatWhere($category_id); |
---|
938 | if ($tmp_where != "") { |
---|
939 | $sql_where_product_ids = "product_id IN (SELECT product_id FROM dtb_product_categories WHERE " . $tmp_where . ")"; |
---|
940 | $arrval = array_merge((array)$arrval, (array)$tmp_arrval, (array)$tmp_arrval); |
---|
941 | } else { |
---|
942 | $sql_where_product_ids = '0<>0'; // 一致させない |
---|
943 | } |
---|
944 | $where = "($sql_where) AND ($sql_where_product_ids)"; |
---|
945 | |
---|
946 | $from = $objProduct->alldtlSQL($sql_where_product_ids); |
---|
947 | $sql = <<< __EOS__ |
---|
948 | INSERT INTO dtb_category_total_count (category_id, product_count, create_date) |
---|
949 | SELECT |
---|
950 | ? |
---|
951 | ,count(*) |
---|
952 | ,now() |
---|
953 | FROM $from |
---|
954 | WHERE $where |
---|
955 | __EOS__; |
---|
956 | |
---|
957 | $objQuery->query($sql, $arrval); |
---|
958 | } |
---|
959 | } |
---|
960 | |
---|
961 | /** |
---|
962 | * 子IDの配列を返す. |
---|
963 | * |
---|
964 | * @param string $table テーブル名 |
---|
965 | * @param string $pid_name 親ID名 |
---|
966 | * @param string $id_name ID名 |
---|
967 | * @param integer $id ID |
---|
968 | * @param array 子ID の配列 |
---|
969 | */ |
---|
970 | function sfGetChildsID($table, $pid_name, $id_name, $id) { |
---|
971 | $arrRet = $this->sfGetChildrenArray($table, $pid_name, $id_name, $id); |
---|
972 | return $arrRet; |
---|
973 | } |
---|
974 | |
---|
975 | /** |
---|
976 | * 階層構造のテーブルから子ID配列を取得する. |
---|
977 | * |
---|
978 | * @param string $table テーブル名 |
---|
979 | * @param string $pid_name 親ID名 |
---|
980 | * @param string $id_name ID名 |
---|
981 | * @param integer $id ID番号 |
---|
982 | * @return array 子IDの配列 |
---|
983 | */ |
---|
984 | function sfGetChildrenArray($table, $pid_name, $id_name, $id) { |
---|
985 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
986 | $col = $pid_name . "," . $id_name; |
---|
987 | $arrData = $objQuery->select($col, $table); |
---|
988 | |
---|
989 | $arrPID = array(); |
---|
990 | $arrPID[] = $id; |
---|
991 | $arrChildren = array(); |
---|
992 | $arrChildren[] = $id; |
---|
993 | |
---|
994 | $arrRet = $this->sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID); |
---|
995 | |
---|
996 | while(count($arrRet) > 0) { |
---|
997 | $arrChildren = array_merge($arrChildren, $arrRet); |
---|
998 | $arrRet = $this->sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrRet); |
---|
999 | } |
---|
1000 | |
---|
1001 | return $arrChildren; |
---|
1002 | } |
---|
1003 | |
---|
1004 | /** |
---|
1005 | * 親ID直下の子IDをすべて取得する. |
---|
1006 | * |
---|
1007 | * @param array $arrData 親カテゴリの配列 |
---|
1008 | * @param string $pid_name 親ID名 |
---|
1009 | * @param string $id_name ID名 |
---|
1010 | * @param array $arrPID 親IDの配列 |
---|
1011 | * @return array 子IDの配列 |
---|
1012 | */ |
---|
1013 | function sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID) { |
---|
1014 | $arrChildren = array(); |
---|
1015 | $max = count($arrData); |
---|
1016 | |
---|
1017 | for($i = 0; $i < $max; $i++) { |
---|
1018 | foreach($arrPID as $val) { |
---|
1019 | if($arrData[$i][$pid_name] == $val) { |
---|
1020 | $arrChildren[] = $arrData[$i][$id_name]; |
---|
1021 | } |
---|
1022 | } |
---|
1023 | } |
---|
1024 | return $arrChildren; |
---|
1025 | } |
---|
1026 | |
---|
1027 | /** |
---|
1028 | * 所属するすべての階層の親IDを配列で返す. |
---|
1029 | * |
---|
1030 | * @param SC_Query $objQuery SC_Query インスタンス |
---|
1031 | * @param string $table テーブル名 |
---|
1032 | * @param string $pid_name 親ID名 |
---|
1033 | * @param string $id_name ID名 |
---|
1034 | * @param integer $id ID |
---|
1035 | * @return array 親IDの配列 |
---|
1036 | */ |
---|
1037 | function sfGetParents($objQuery, $table, $pid_name, $id_name, $id) { |
---|
1038 | $arrRet = $this->sfGetParentsArray($table, $pid_name, $id_name, $id); |
---|
1039 | // 配列の先頭1つを削除する。 |
---|
1040 | array_shift($arrRet); |
---|
1041 | return $arrRet; |
---|
1042 | } |
---|
1043 | |
---|
1044 | /** |
---|
1045 | * 階層構造のテーブルから親ID配列を取得する. |
---|
1046 | * |
---|
1047 | * @param string $table テーブル名 |
---|
1048 | * @param string $pid_name 親ID名 |
---|
1049 | * @param string $id_name ID名 |
---|
1050 | * @param integer $id ID |
---|
1051 | * @return array 親IDの配列 |
---|
1052 | */ |
---|
1053 | function sfGetParentsArray($table, $pid_name, $id_name, $id) { |
---|
1054 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1055 | $col = $pid_name . "," . $id_name; |
---|
1056 | $arrData = $objQuery->select($col, $table); |
---|
1057 | |
---|
1058 | $arrParents = array(); |
---|
1059 | $arrParents[] = $id; |
---|
1060 | $child = $id; |
---|
1061 | |
---|
1062 | $ret = SC_Utils::sfGetParentsArraySub($arrData, $pid_name, $id_name, $child); |
---|
1063 | |
---|
1064 | while($ret != "") { |
---|
1065 | $arrParents[] = $ret; |
---|
1066 | $ret = SC_Utils::sfGetParentsArraySub($arrData, $pid_name, $id_name, $ret); |
---|
1067 | } |
---|
1068 | |
---|
1069 | $arrParents = array_reverse($arrParents); |
---|
1070 | |
---|
1071 | return $arrParents; |
---|
1072 | } |
---|
1073 | |
---|
1074 | /** |
---|
1075 | * カテゴリから商品を検索する場合のWHERE文と値を返す. |
---|
1076 | * |
---|
1077 | * @param integer $category_id カテゴリID |
---|
1078 | * @return array 商品を検索する場合の配列 |
---|
1079 | */ |
---|
1080 | function sfGetCatWhere($category_id) { |
---|
1081 | // 子カテゴリIDの取得 |
---|
1082 | $arrRet = $this->sfGetChildsID("dtb_category", "parent_category_id", "category_id", $category_id); |
---|
1083 | $tmp_where = ""; |
---|
1084 | foreach ($arrRet as $val) { |
---|
1085 | if($tmp_where == "") { |
---|
1086 | $tmp_where.= "category_id IN ( ?"; |
---|
1087 | } else { |
---|
1088 | $tmp_where.= ",? "; |
---|
1089 | } |
---|
1090 | $arrval[] = $val; |
---|
1091 | } |
---|
1092 | $tmp_where.= " ) "; |
---|
1093 | return array($tmp_where, $arrval); |
---|
1094 | } |
---|
1095 | |
---|
1096 | /** |
---|
1097 | * 受注一時テーブルから情報を取得する. |
---|
1098 | * |
---|
1099 | * @param integer $order_temp_id 受注一時ID |
---|
1100 | * @return array 受注一時情報の配列 |
---|
1101 | */ |
---|
1102 | function sfGetOrderTemp($order_temp_id) { |
---|
1103 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1104 | $where = "order_temp_id = ?"; |
---|
1105 | $arrRet = $objQuery->select("*", "dtb_order_temp", $where, array($order_temp_id)); |
---|
1106 | return $arrRet[0]; |
---|
1107 | } |
---|
1108 | |
---|
1109 | /** |
---|
1110 | * SELECTボックス用リストを作成する. |
---|
1111 | * |
---|
1112 | * @param string $table テーブル名 |
---|
1113 | * @param string $keyname プライマリーキーのカラム名 |
---|
1114 | * @param string $valname データ内容のカラム名 |
---|
1115 | * @return array SELECT ボックス用リストの配列 |
---|
1116 | */ |
---|
1117 | function sfGetIDValueList($table, $keyname, $valname) { |
---|
1118 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1119 | $col = "$keyname, $valname"; |
---|
1120 | $objQuery->setWhere("del_flg = 0"); |
---|
1121 | $objQuery->setOrder("rank DESC"); |
---|
1122 | $arrList = $objQuery->select($col, $table); |
---|
1123 | $count = count($arrList); |
---|
1124 | for($cnt = 0; $cnt < $count; $cnt++) { |
---|
1125 | $key = $arrList[$cnt][$keyname]; |
---|
1126 | $val = $arrList[$cnt][$valname]; |
---|
1127 | $arrRet[$key] = $val; |
---|
1128 | } |
---|
1129 | return $arrRet; |
---|
1130 | } |
---|
1131 | |
---|
1132 | /** |
---|
1133 | * ランキングを上げる. |
---|
1134 | * |
---|
1135 | * @param string $table テーブル名 |
---|
1136 | * @param string $colname カラム名 |
---|
1137 | * @param string|integer $id テーブルのキー |
---|
1138 | * @param string $andwhere SQL の AND 条件である WHERE 句 |
---|
1139 | * @return void |
---|
1140 | */ |
---|
1141 | function sfRankUp($table, $colname, $id, $andwhere = "") { |
---|
1142 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1143 | $objQuery->begin(); |
---|
1144 | $where = "$colname = ?"; |
---|
1145 | if($andwhere != "") { |
---|
1146 | $where.= " AND $andwhere"; |
---|
1147 | } |
---|
1148 | // 対象項目のランクを取得 |
---|
1149 | $rank = $objQuery->get($table, "rank", $where, array($id)); |
---|
1150 | // ランクの最大値を取得 |
---|
1151 | $maxrank = $objQuery->max($table, "rank", $andwhere); |
---|
1152 | // ランクが最大値よりも小さい場合に実行する。 |
---|
1153 | if($rank < $maxrank) { |
---|
1154 | // ランクが一つ上のIDを取得する。 |
---|
1155 | $where = "rank = ?"; |
---|
1156 | if($andwhere != "") { |
---|
1157 | $where.= " AND $andwhere"; |
---|
1158 | } |
---|
1159 | $uprank = $rank + 1; |
---|
1160 | $up_id = $objQuery->get($table, $colname, $where, array($uprank)); |
---|
1161 | // ランク入れ替えの実行 |
---|
1162 | $sqlup = "UPDATE $table SET rank = ? WHERE $colname = ?"; |
---|
1163 | if($andwhere != "") { |
---|
1164 | $sqlup.= " AND $andwhere"; |
---|
1165 | } |
---|
1166 | $objQuery->exec($sqlup, array($rank + 1, $id)); |
---|
1167 | $objQuery->exec($sqlup, array($rank, $up_id)); |
---|
1168 | } |
---|
1169 | $objQuery->commit(); |
---|
1170 | } |
---|
1171 | |
---|
1172 | /** |
---|
1173 | * ランキングを下げる. |
---|
1174 | * |
---|
1175 | * @param string $table テーブル名 |
---|
1176 | * @param string $colname カラム名 |
---|
1177 | * @param string|integer $id テーブルのキー |
---|
1178 | * @param string $andwhere SQL の AND 条件である WHERE 句 |
---|
1179 | * @return void |
---|
1180 | */ |
---|
1181 | function sfRankDown($table, $colname, $id, $andwhere = "") { |
---|
1182 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1183 | $objQuery->begin(); |
---|
1184 | $where = "$colname = ?"; |
---|
1185 | if($andwhere != "") { |
---|
1186 | $where.= " AND $andwhere"; |
---|
1187 | } |
---|
1188 | // 対象項目のランクを取得 |
---|
1189 | $rank = $objQuery->get($table, "rank", $where, array($id)); |
---|
1190 | |
---|
1191 | // ランクが1(最小値)よりも大きい場合に実行する。 |
---|
1192 | if($rank > 1) { |
---|
1193 | // ランクが一つ下のIDを取得する。 |
---|
1194 | $where = "rank = ?"; |
---|
1195 | if($andwhere != "") { |
---|
1196 | $where.= " AND $andwhere"; |
---|
1197 | } |
---|
1198 | $downrank = $rank - 1; |
---|
1199 | $down_id = $objQuery->get($table, $colname, $where, array($downrank)); |
---|
1200 | // ランク入れ替えの実行 |
---|
1201 | $sqlup = "UPDATE $table SET rank = ? WHERE $colname = ?"; |
---|
1202 | if($andwhere != "") { |
---|
1203 | $sqlup.= " AND $andwhere"; |
---|
1204 | } |
---|
1205 | $objQuery->exec($sqlup, array($rank - 1, $id)); |
---|
1206 | $objQuery->exec($sqlup, array($rank, $down_id)); |
---|
1207 | } |
---|
1208 | $objQuery->commit(); |
---|
1209 | } |
---|
1210 | |
---|
1211 | /** |
---|
1212 | * 指定順位へ移動する. |
---|
1213 | * |
---|
1214 | * @param string $tableName テーブル名 |
---|
1215 | * @param string $keyIdColumn キーを保持するカラム名 |
---|
1216 | * @param string|integer $keyId キーの値 |
---|
1217 | * @param integer $pos 指定順位 |
---|
1218 | * @param string $where SQL の AND 条件である WHERE 句 |
---|
1219 | * @return void |
---|
1220 | */ |
---|
1221 | function sfMoveRank($tableName, $keyIdColumn, $keyId, $pos, $where = "") { |
---|
1222 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1223 | $objQuery->begin(); |
---|
1224 | |
---|
1225 | // 自身のランクを取得する |
---|
1226 | if($where != "") { |
---|
1227 | $getWhere = "$keyIdColumn = ? AND " . $where; |
---|
1228 | } else { |
---|
1229 | $getWhere = "$keyIdColumn = ?"; |
---|
1230 | } |
---|
1231 | $rank = $objQuery->get($tableName, "rank", $getWhere, array($keyId)); |
---|
1232 | |
---|
1233 | $max = $objQuery->max($tableName, "rank", $where); |
---|
1234 | |
---|
1235 | // 値の調整(逆順) |
---|
1236 | if($pos > $max) { |
---|
1237 | $position = 1; |
---|
1238 | } else if($pos < 1) { |
---|
1239 | $position = $max; |
---|
1240 | } else { |
---|
1241 | $position = $max - $pos + 1; |
---|
1242 | } |
---|
1243 | |
---|
1244 | //入れ替え先の順位が入れ換え元の順位より大きい場合 |
---|
1245 | if( $position > $rank ) $term = "rank - 1"; |
---|
1246 | |
---|
1247 | //入れ替え先の順位が入れ換え元の順位より小さい場合 |
---|
1248 | if( $position < $rank ) $term = "rank + 1"; |
---|
1249 | |
---|
1250 | // XXX 入れ替え先の順位が入れ替え元の順位と同じ場合 |
---|
1251 | if (!isset($term)) $term = "rank"; |
---|
1252 | |
---|
1253 | // 指定した順位の商品から移動させる商品までのrankを1つずらす |
---|
1254 | $sql = "UPDATE $tableName SET rank = $term WHERE rank BETWEEN ? AND ?"; |
---|
1255 | if($where != "") { |
---|
1256 | $sql.= " AND $where"; |
---|
1257 | } |
---|
1258 | |
---|
1259 | if( $position > $rank ) $objQuery->exec( $sql, array( $rank + 1, $position )); |
---|
1260 | if( $position < $rank ) $objQuery->exec( $sql, array( $position, $rank - 1 )); |
---|
1261 | |
---|
1262 | // 指定した順位へrankを書き換える。 |
---|
1263 | $sql = "UPDATE $tableName SET rank = ? WHERE $keyIdColumn = ? "; |
---|
1264 | if($where != "") { |
---|
1265 | $sql.= " AND $where"; |
---|
1266 | } |
---|
1267 | |
---|
1268 | $objQuery->exec( $sql, array( $position, $keyId ) ); |
---|
1269 | $objQuery->commit(); |
---|
1270 | } |
---|
1271 | |
---|
1272 | /** |
---|
1273 | * ランクを含むレコードを削除する. |
---|
1274 | * |
---|
1275 | * レコードごと削除する場合は、$deleteをtrueにする |
---|
1276 | * |
---|
1277 | * @param string $table テーブル名 |
---|
1278 | * @param string $colname カラム名 |
---|
1279 | * @param string|integer $id テーブルのキー |
---|
1280 | * @param string $andwhere SQL の AND 条件である WHERE 句 |
---|
1281 | * @param bool $delete レコードごと削除する場合 true, |
---|
1282 | * レコードごと削除しない場合 false |
---|
1283 | * @return void |
---|
1284 | */ |
---|
1285 | function sfDeleteRankRecord($table, $colname, $id, $andwhere = "", |
---|
1286 | $delete = false) { |
---|
1287 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1288 | $objQuery->begin(); |
---|
1289 | // 削除レコードのランクを取得する。 |
---|
1290 | $where = "$colname = ?"; |
---|
1291 | if($andwhere != "") { |
---|
1292 | $where.= " AND $andwhere"; |
---|
1293 | } |
---|
1294 | $rank = $objQuery->get($table, "rank", $where, array($id)); |
---|
1295 | |
---|
1296 | if(!$delete) { |
---|
1297 | // ランクを最下位にする、DELフラグON |
---|
1298 | $sqlup = "UPDATE $table SET rank = 0, del_flg = 1 "; |
---|
1299 | $sqlup.= "WHERE $colname = ?"; |
---|
1300 | // UPDATEの実行 |
---|
1301 | $objQuery->exec($sqlup, array($id)); |
---|
1302 | } else { |
---|
1303 | $objQuery->delete($table, "$colname = ?", array($id)); |
---|
1304 | } |
---|
1305 | |
---|
1306 | // 追加レコードのランクより上のレコードを一つずらす。 |
---|
1307 | $where = "rank > ?"; |
---|
1308 | if($andwhere != "") { |
---|
1309 | $where.= " AND $andwhere"; |
---|
1310 | } |
---|
1311 | $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where"; |
---|
1312 | $objQuery->exec($sqlup, array($rank)); |
---|
1313 | $objQuery->commit(); |
---|
1314 | } |
---|
1315 | |
---|
1316 | /** |
---|
1317 | * 親IDの配列を元に特定のカラムを取得する. |
---|
1318 | * |
---|
1319 | * @param SC_Query $objQuery SC_Query インスタンス |
---|
1320 | * @param string $table テーブル名 |
---|
1321 | * @param string $id_name ID名 |
---|
1322 | * @param string $col_name カラム名 |
---|
1323 | * @param array $arrId IDの配列 |
---|
1324 | * @return array 特定のカラムの配列 |
---|
1325 | */ |
---|
1326 | function sfGetParentsCol($objQuery, $table, $id_name, $col_name, $arrId ) { |
---|
1327 | $col = $col_name; |
---|
1328 | $len = count($arrId); |
---|
1329 | $where = ""; |
---|
1330 | |
---|
1331 | for($cnt = 0; $cnt < $len; $cnt++) { |
---|
1332 | if($where == "") { |
---|
1333 | $where = "$id_name = ?"; |
---|
1334 | } else { |
---|
1335 | $where.= " OR $id_name = ?"; |
---|
1336 | } |
---|
1337 | } |
---|
1338 | |
---|
1339 | $objQuery->setOrder("level"); |
---|
1340 | $arrRet = $objQuery->select($col, $table, $where, $arrId); |
---|
1341 | return $arrRet; |
---|
1342 | } |
---|
1343 | |
---|
1344 | /** |
---|
1345 | * カテゴリ変更時の移動処理を行う. |
---|
1346 | * |
---|
1347 | * @param SC_Query $objQuery SC_Query インスタンス |
---|
1348 | * @param string $table テーブル名 |
---|
1349 | * @param string $id_name ID名 |
---|
1350 | * @param string $cat_name カテゴリ名 |
---|
1351 | * @param integer $old_catid 旧カテゴリID |
---|
1352 | * @param integer $new_catid 新カテゴリID |
---|
1353 | * @param integer $id ID |
---|
1354 | * @return void |
---|
1355 | */ |
---|
1356 | function sfMoveCatRank($objQuery, $table, $id_name, $cat_name, $old_catid, $new_catid, $id) { |
---|
1357 | if ($old_catid == $new_catid) { |
---|
1358 | return; |
---|
1359 | } |
---|
1360 | // 旧カテゴリでのランク削除処理 |
---|
1361 | // 移動レコードのランクを取得する。 |
---|
1362 | $where = "$id_name = ?"; |
---|
1363 | $rank = $objQuery->get($table, "rank", $where, array($id)); |
---|
1364 | // 削除レコードのランクより上のレコードを一つ下にずらす。 |
---|
1365 | $where = "rank > ? AND $cat_name = ?"; |
---|
1366 | $sqlup = "UPDATE $table SET rank = (rank - 1) WHERE $where"; |
---|
1367 | $objQuery->exec($sqlup, array($rank, $old_catid)); |
---|
1368 | // 新カテゴリでの登録処理 |
---|
1369 | // 新カテゴリの最大ランクを取得する。 |
---|
1370 | $max_rank = $objQuery->max($table, "rank", "$cat_name = ?", array($new_catid)) + 1; |
---|
1371 | $where = "$id_name = ?"; |
---|
1372 | $sqlup = "UPDATE $table SET rank = ? WHERE $where"; |
---|
1373 | $objQuery->exec($sqlup, array($max_rank, $id)); |
---|
1374 | } |
---|
1375 | |
---|
1376 | /** |
---|
1377 | * お届け時間を取得する. |
---|
1378 | * |
---|
1379 | * @param integer $payment_id 支払い方法ID |
---|
1380 | * @return array お届け時間の配列 |
---|
1381 | */ |
---|
1382 | function sfGetDelivTime($payment_id = "") { |
---|
1383 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1384 | |
---|
1385 | $deliv_id = ""; |
---|
1386 | $arrRet = array(); |
---|
1387 | |
---|
1388 | if($payment_id != "") { |
---|
1389 | $where = "del_flg = 0 AND payment_id = ?"; |
---|
1390 | $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id)); |
---|
1391 | $deliv_id = $arrRet[0]['deliv_id']; |
---|
1392 | } |
---|
1393 | |
---|
1394 | if($deliv_id != "") { |
---|
1395 | $objQuery->setOrder("time_id"); |
---|
1396 | $where = "deliv_id = ?"; |
---|
1397 | $arrRet= $objQuery->select("time_id, deliv_time", "dtb_delivtime", $where, array($deliv_id)); |
---|
1398 | } |
---|
1399 | |
---|
1400 | return $arrRet; |
---|
1401 | } |
---|
1402 | |
---|
1403 | /** |
---|
1404 | * 都道府県、支払い方法から配送料金を取得する. |
---|
1405 | * |
---|
1406 | * @param array $arrData 各種情報 |
---|
1407 | * @return string 指定の都道府県, 支払い方法の配送料金 |
---|
1408 | */ |
---|
1409 | function sfGetDelivFee($arrData) { |
---|
1410 | $pref = $arrData['deliv_pref']; |
---|
1411 | $payment_id = isset($arrData['payment_id']) ? $arrData['payment_id'] : ""; |
---|
1412 | |
---|
1413 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1414 | |
---|
1415 | $deliv_id = ""; |
---|
1416 | |
---|
1417 | // 支払い方法が指定されている場合は、対応した配送業者を取得する |
---|
1418 | if($payment_id != "") { |
---|
1419 | $where = "del_flg = 0 AND payment_id = ?"; |
---|
1420 | $arrRet = $objQuery->select("deliv_id", "dtb_payment", $where, array($payment_id)); |
---|
1421 | $deliv_id = $arrRet[0]['deliv_id']; |
---|
1422 | // 支払い方法が指定されていない場合は、先頭の配送業者を取得する |
---|
1423 | } else { |
---|
1424 | $where = "del_flg = 0"; |
---|
1425 | $objQuery->setOrder("rank DESC"); |
---|
1426 | $objQuery->setLimitOffset(1); |
---|
1427 | $arrRet = $objQuery->select("deliv_id", "dtb_deliv", $where); |
---|
1428 | $deliv_id = $arrRet[0]['deliv_id']; |
---|
1429 | } |
---|
1430 | |
---|
1431 | // 配送業者から配送料を取得 |
---|
1432 | if($deliv_id != "") { |
---|
1433 | |
---|
1434 | // 都道府県が指定されていない場合は、東京都の番号を指定しておく |
---|
1435 | if($pref == "") { |
---|
1436 | $pref = 13; |
---|
1437 | } |
---|
1438 | |
---|
1439 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1440 | $where = "deliv_id = ? AND pref = ?"; |
---|
1441 | $arrRet= $objQuery->select("fee", "dtb_delivfee", $where, array($deliv_id, $pref)); |
---|
1442 | } |
---|
1443 | return $arrRet[0]['fee']; |
---|
1444 | } |
---|
1445 | |
---|
1446 | /** |
---|
1447 | * 集計情報を元に最終計算を行う. |
---|
1448 | * |
---|
1449 | * @param array $arrData 各種情報 |
---|
1450 | * @param LC_Page $objPage LC_Page インスタンス |
---|
1451 | * @param SC_CartSession $objCartSess SC_CartSession インスタンス |
---|
1452 | * @param null $dummy1 互換性確保用(決済モジュール互換のため) |
---|
1453 | * @param SC_Customer $objCustomer SC_Customer インスタンス |
---|
1454 | * @return array 最終計算後の配列 |
---|
1455 | */ |
---|
1456 | function sfTotalConfirm($arrData, &$objPage, &$objCartSess, $dummy1 = null, $objCustomer = "") { |
---|
1457 | // 店舗基本情報を取得する |
---|
1458 | $arrInfo = SC_Helper_DB_Ex::sf_getBasisData(); |
---|
1459 | |
---|
1460 | // 未定義変数を定義 |
---|
1461 | if (!isset($arrData['deliv_pref'])) $arrData['deliv_pref'] = ""; |
---|
1462 | if (!isset($arrData['payment_id'])) $arrData['payment_id'] = ""; |
---|
1463 | if (!isset($arrData['charge'])) $arrData['charge'] = ""; |
---|
1464 | if (!isset($arrData['use_point'])) $arrData['use_point'] = ""; |
---|
1465 | if (!isset($arrData['add_point'])) $arrData['add_point'] = 0; |
---|
1466 | |
---|
1467 | // 税金の取得 |
---|
1468 | $arrData['tax'] = $objPage->tpl_total_tax; |
---|
1469 | // 小計の取得 |
---|
1470 | $arrData['subtotal'] = $objPage->tpl_total_pretax; |
---|
1471 | |
---|
1472 | // 合計送料の取得 |
---|
1473 | $arrData['deliv_fee'] = 0; |
---|
1474 | |
---|
1475 | // 商品ごとの送料が有効の場合 |
---|
1476 | if (OPTION_PRODUCT_DELIV_FEE == 1) { |
---|
1477 | // 全商品の合計送料を加算する |
---|
1478 | $this->lfAddAllProductsDelivFee($arrData, $objPage, $objCartSess); |
---|
1479 | } |
---|
1480 | |
---|
1481 | // 配送業者の送料が有効の場合 |
---|
1482 | if (OPTION_DELIV_FEE == 1) { |
---|
1483 | // 都道府県、支払い方法から配送料金を加算する |
---|
1484 | $this->lfAddDelivFee($arrData); |
---|
1485 | } |
---|
1486 | |
---|
1487 | // 送料無料の購入数が設定されている場合 |
---|
1488 | if (DELIV_FREE_AMOUNT > 0) { |
---|
1489 | // 商品の合計数量 |
---|
1490 | $total_quantity = $objCartSess->getTotalQuantity(true); |
---|
1491 | |
---|
1492 | if($total_quantity >= DELIV_FREE_AMOUNT) { |
---|
1493 | $arrData['deliv_fee'] = 0; |
---|
1494 | } |
---|
1495 | } |
---|
1496 | |
---|
1497 | // ダウンロード商品のみの場合は送料無料 |
---|
1498 | if($this->chkCartDown($objCartSess)==2){ |
---|
1499 | $arrData['deliv_fee'] = 0; |
---|
1500 | } |
---|
1501 | |
---|
1502 | // 送料無料条件が設定されている場合 |
---|
1503 | if($arrInfo['free_rule'] > 0) { |
---|
1504 | // 小計が無料条件を超えている場合 |
---|
1505 | if($arrData['subtotal'] >= $arrInfo['free_rule']) { |
---|
1506 | $arrData['deliv_fee'] = 0; |
---|
1507 | } |
---|
1508 | } |
---|
1509 | |
---|
1510 | // 合計の計算 |
---|
1511 | $arrData['total'] = $objPage->tpl_total_pretax; // 商品合計 |
---|
1512 | $arrData['total']+= $arrData['deliv_fee']; // 送料 |
---|
1513 | $arrData['total']+= $arrData['charge']; // 手数料 |
---|
1514 | // お支払い合計 |
---|
1515 | $arrData['payment_total'] = $arrData['total'] - ($arrData['use_point'] * POINT_VALUE); |
---|
1516 | // 加算ポイントの計算 |
---|
1517 | if (USE_POINT !== false) { |
---|
1518 | $arrData['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($objPage->tpl_total_point, $arrData['use_point']); |
---|
1519 | |
---|
1520 | if($objCustomer != "") { |
---|
1521 | // 誕生日月であった場合 |
---|
1522 | if($objCustomer->isBirthMonth()) { |
---|
1523 | $arrData['birth_point'] = BIRTH_MONTH_POINT; |
---|
1524 | $arrData['add_point'] += $arrData['birth_point']; |
---|
1525 | } |
---|
1526 | } |
---|
1527 | } |
---|
1528 | |
---|
1529 | if($arrData['add_point'] < 0) { |
---|
1530 | $arrData['add_point'] = 0; |
---|
1531 | } |
---|
1532 | return $arrData; |
---|
1533 | } |
---|
1534 | |
---|
1535 | /** |
---|
1536 | * レコードの存在チェックを行う. |
---|
1537 | * |
---|
1538 | * @param string $table テーブル名 |
---|
1539 | * @param string $col カラム名 |
---|
1540 | * @param array $arrval 要素の配列 |
---|
1541 | * @param array $addwhere SQL の AND 条件である WHERE 句 |
---|
1542 | * @return bool レコードが存在する場合 true |
---|
1543 | */ |
---|
1544 | function sfIsRecord($table, $col, $arrval, $addwhere = "") { |
---|
1545 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1546 | $arrCol = split("[, ]", $col); |
---|
1547 | |
---|
1548 | $where = "del_flg = 0"; |
---|
1549 | |
---|
1550 | if($addwhere != "") { |
---|
1551 | $where.= " AND $addwhere"; |
---|
1552 | } |
---|
1553 | |
---|
1554 | foreach($arrCol as $val) { |
---|
1555 | if($val != "") { |
---|
1556 | if($where == "") { |
---|
1557 | $where = "$val = ?"; |
---|
1558 | } else { |
---|
1559 | $where.= " AND $val = ?"; |
---|
1560 | } |
---|
1561 | } |
---|
1562 | } |
---|
1563 | $ret = $objQuery->get($table, $col, $where, $arrval); |
---|
1564 | |
---|
1565 | if($ret != "") { |
---|
1566 | return true; |
---|
1567 | } |
---|
1568 | return false; |
---|
1569 | } |
---|
1570 | |
---|
1571 | /** |
---|
1572 | * メーカー商品数数の登録を行う. |
---|
1573 | * |
---|
1574 | * @param SC_Query $objQuery SC_Query インスタンス |
---|
1575 | * @return void |
---|
1576 | */ |
---|
1577 | function sfMaker_Count($objQuery){ |
---|
1578 | $sql = ""; |
---|
1579 | |
---|
1580 | //テーブル内容の削除 |
---|
1581 | $objQuery->query("DELETE FROM dtb_maker_count"); |
---|
1582 | |
---|
1583 | //各メーカーの商品数を数えて格納 |
---|
1584 | $sql = " INSERT INTO dtb_maker_count(maker_id, product_count, create_date) "; |
---|
1585 | $sql .= " SELECT T1.maker_id, count(T2.maker_id), now() "; |
---|
1586 | $sql .= " FROM dtb_maker AS T1 LEFT JOIN dtb_products AS T2"; |
---|
1587 | $sql .= " ON T1.maker_id = T2.maker_id "; |
---|
1588 | $sql .= " WHERE T2.del_flg = 0 AND T2.status = 1 "; |
---|
1589 | $sql .= " GROUP BY T1.maker_id, T2.maker_id "; |
---|
1590 | $objQuery->query($sql); |
---|
1591 | } |
---|
1592 | |
---|
1593 | /** |
---|
1594 | * 選択中の商品のメーカーを取得する. |
---|
1595 | * |
---|
1596 | * @param integer $product_id プロダクトID |
---|
1597 | * @param integer $maker_id メーカーID |
---|
1598 | * @return array 選択中の商品のメーカーIDの配列 |
---|
1599 | * |
---|
1600 | */ |
---|
1601 | function sfGetMakerId($product_id, $maker_id = 0, $closed = false) { |
---|
1602 | if ($closed) { |
---|
1603 | $status = ""; |
---|
1604 | } else { |
---|
1605 | $status = "status = 1"; |
---|
1606 | } |
---|
1607 | |
---|
1608 | if (!$this->g_maker_on) { |
---|
1609 | $this->g_maker_on = true; |
---|
1610 | $maker_id = (int) $maker_id; |
---|
1611 | $product_id = (int) $product_id; |
---|
1612 | if (SC_Utils_Ex::sfIsInt($maker_id) && $maker_id != 0 && $this->sfIsRecord("dtb_maker","maker_id", $maker_id)) { |
---|
1613 | $this->g_maker_id = array($maker_id); |
---|
1614 | } else if (SC_Utils_Ex::sfIsInt($product_id) && $product_id != 0 && $this->sfIsRecord("dtb_products","product_id", $product_id, $status)) { |
---|
1615 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1616 | $where = "product_id = ?"; |
---|
1617 | $maker_id = $objQuery->getCol("dtb_products", "maker_id", "product_id = ?", array($product_id)); |
---|
1618 | $this->g_maker_id = $maker_id; |
---|
1619 | } else { |
---|
1620 | // 不正な場合は、空の配列を返す。 |
---|
1621 | $this->g_maker_id = array(); |
---|
1622 | } |
---|
1623 | } |
---|
1624 | return $this->g_maker_id; |
---|
1625 | } |
---|
1626 | |
---|
1627 | /** |
---|
1628 | * メーカーの取得を行う. |
---|
1629 | * |
---|
1630 | * $products_check:true商品登録済みのものだけ取得する |
---|
1631 | * |
---|
1632 | * @param string $addwhere 追加する WHERE 句 |
---|
1633 | * @param bool $products_check 商品の存在するカテゴリのみ取得する場合 true |
---|
1634 | * @return array カテゴリツリーの配列 |
---|
1635 | */ |
---|
1636 | function sfGetMakerList($addwhere = "", $products_check = false) { |
---|
1637 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1638 | $where = "del_flg = 0"; |
---|
1639 | |
---|
1640 | if($addwhere != "") { |
---|
1641 | $where.= " AND $addwhere"; |
---|
1642 | } |
---|
1643 | |
---|
1644 | $objQuery->setOption("ORDER BY rank DESC"); |
---|
1645 | |
---|
1646 | if($products_check) { |
---|
1647 | $col = "T1.maker_id, name"; |
---|
1648 | $from = "dtb_maker AS T1 LEFT JOIN dtb_maker_count AS T2 ON T1.maker_id = T2.maker_id"; |
---|
1649 | $where .= " AND product_count > 0"; |
---|
1650 | } else { |
---|
1651 | $col = "maker_id, name"; |
---|
1652 | $from = "dtb_maker"; |
---|
1653 | } |
---|
1654 | |
---|
1655 | $arrRet = $objQuery->select($col, $from, $where); |
---|
1656 | |
---|
1657 | $max = count($arrRet); |
---|
1658 | for($cnt = 0; $cnt < $max; $cnt++) { |
---|
1659 | $id = $arrRet[$cnt]['maker_id']; |
---|
1660 | $name = $arrRet[$cnt]['name']; |
---|
1661 | $arrList[$id].= $name; |
---|
1662 | } |
---|
1663 | return $arrList; |
---|
1664 | } |
---|
1665 | |
---|
1666 | /** |
---|
1667 | * 全商品の合計送料を加算する |
---|
1668 | */ |
---|
1669 | function lfAddAllProductsDelivFee(&$arrData, &$objPage, &$objCartSess) { |
---|
1670 | $arrData['deliv_fee'] += $this->lfCalcAllProductsDelivFee($arrData, $objCartSess); |
---|
1671 | } |
---|
1672 | |
---|
1673 | /** |
---|
1674 | * 全商品の合計送料を計算する |
---|
1675 | */ |
---|
1676 | function lfCalcAllProductsDelivFee(&$arrData, &$objCartSess) { |
---|
1677 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1678 | $deliv_fee_total = 0; |
---|
1679 | $max = $objCartSess->getMax(); |
---|
1680 | for ($i = 0; $i <= $max; $i++) { |
---|
1681 | // 商品送料 |
---|
1682 | $deliv_fee = $objQuery->getOne('SELECT deliv_fee FROM dtb_products WHERE product_id = ?', array($_SESSION[$objCartSess->key][$i]['id'][0])); |
---|
1683 | // 数量 |
---|
1684 | $quantity = $_SESSION[$objCartSess->key][$i]['quantity']; |
---|
1685 | // 累積 |
---|
1686 | $deliv_fee_total += $deliv_fee * $quantity; |
---|
1687 | } |
---|
1688 | return $deliv_fee_total; |
---|
1689 | } |
---|
1690 | |
---|
1691 | /** |
---|
1692 | * 都道府県、支払い方法から配送料金を加算する. |
---|
1693 | * |
---|
1694 | * @param array $arrData 各種情報 |
---|
1695 | */ |
---|
1696 | function lfAddDelivFee(&$arrData) { |
---|
1697 | $arrData['deliv_fee'] += $this->sfGetDelivFee($arrData); |
---|
1698 | } |
---|
1699 | |
---|
1700 | /** |
---|
1701 | * 受注の名称列を更新する |
---|
1702 | * |
---|
1703 | * @param integer $order_id 更新対象の注文番号 |
---|
1704 | * @param boolean $temp_table 更新対象は「受注_Temp」か |
---|
1705 | * @static |
---|
1706 | */ |
---|
1707 | function sfUpdateOrderNameCol($order_id, $temp_table = false) { |
---|
1708 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1709 | |
---|
1710 | if ($temp_table) { |
---|
1711 | $tgt_table = 'dtb_order_temp'; |
---|
1712 | $sql_where = 'WHERE order_temp_id = ?'; |
---|
1713 | } else { |
---|
1714 | $tgt_table = 'dtb_order'; |
---|
1715 | $sql_where = 'WHERE order_id = ?'; |
---|
1716 | } |
---|
1717 | |
---|
1718 | $sql = <<< __EOS__ |
---|
1719 | UPDATE |
---|
1720 | {$tgt_table} |
---|
1721 | SET |
---|
1722 | payment_method = (SELECT payment_method FROM dtb_payment WHERE payment_id = {$tgt_table}.payment_id) |
---|
1723 | ,deliv_time = (SELECT deliv_time FROM dtb_delivtime WHERE time_id = {$tgt_table}.deliv_time_id AND deliv_id = {$tgt_table}.deliv_id) |
---|
1724 | $sql_where |
---|
1725 | __EOS__; |
---|
1726 | |
---|
1727 | $objQuery->query($sql, array($order_id)); |
---|
1728 | } |
---|
1729 | |
---|
1730 | /** |
---|
1731 | * 店舗基本情報に基づいて税金額を返す |
---|
1732 | * |
---|
1733 | * @param integer $price 計算対象の金額 |
---|
1734 | * @return integer 税金額 |
---|
1735 | */ |
---|
1736 | function sfTax($price) { |
---|
1737 | // 店舗基本情報を取得 |
---|
1738 | $CONF = SC_Helper_DB_Ex::sf_getBasisData(); |
---|
1739 | |
---|
1740 | return SC_Utils_Ex::sfTax($price, $CONF['tax'], $CONF['tax_rule']); |
---|
1741 | } |
---|
1742 | |
---|
1743 | /** |
---|
1744 | * 店舗基本情報に基づいて税金付与した金額を返す |
---|
1745 | * |
---|
1746 | * @param integer $price 計算対象の金額 |
---|
1747 | * @return integer 税金付与した金額 |
---|
1748 | */ |
---|
1749 | function sfPreTax($price, $tax = null, $tax_rule = null) { |
---|
1750 | // 店舗基本情報を取得 |
---|
1751 | $CONF = SC_Helper_DB_Ex::sf_getBasisData(); |
---|
1752 | |
---|
1753 | return SC_Utils_Ex::sfPreTax($price, $CONF['tax'], $CONF['tax_rule']); |
---|
1754 | } |
---|
1755 | |
---|
1756 | /** |
---|
1757 | * 店舗基本情報に基づいて加算ポイントを返す |
---|
1758 | * |
---|
1759 | * @param integer $totalpoint |
---|
1760 | * @param integer $use_point |
---|
1761 | * @return integer 加算ポイント |
---|
1762 | */ |
---|
1763 | function sfGetAddPoint($totalpoint, $use_point) { |
---|
1764 | // 店舗基本情報を取得 |
---|
1765 | $CONF = SC_Helper_DB_Ex::sf_getBasisData(); |
---|
1766 | |
---|
1767 | return SC_Utils_Ex::sfGetAddPoint($totalpoint, $use_point, $CONF['point_rate']); |
---|
1768 | } |
---|
1769 | |
---|
1770 | /** |
---|
1771 | * 受注.対応状況の更新 |
---|
1772 | * |
---|
1773 | * ・必ず呼び出し元でトランザクションブロックを開いておくこと。 |
---|
1774 | * |
---|
1775 | * @param integer $orderId 注文番号 |
---|
1776 | * @param integer|null $newStatus 対応状況 (null=変更無し) |
---|
1777 | * @param integer|null $newAddPoint 加算ポイント (null=変更無し) |
---|
1778 | * @param integer|null $newUsePoint 使用ポイント (null=変更無し) |
---|
1779 | * @return void |
---|
1780 | */ |
---|
1781 | function sfUpdateOrderStatus($orderId, $newStatus = null, $newAddPoint = null, $newUsePoint = null) { |
---|
1782 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1783 | |
---|
1784 | $arrOrderOld = $objQuery->getRow('dtb_order', 'status, add_point, use_point, customer_id', 'order_id = ?', array($orderId)); |
---|
1785 | |
---|
1786 | // 対応状況が変更無しの場合、DB値を引き継ぐ |
---|
1787 | if (is_null($newStatus)) { |
---|
1788 | $newStatus = $arrOrderOld['status']; |
---|
1789 | } |
---|
1790 | |
---|
1791 | // 使用ポイント、DB値を引き継ぐ |
---|
1792 | if (is_null($newUsePoint)) { |
---|
1793 | $newUsePoint = $arrOrderOld['use_point']; |
---|
1794 | } |
---|
1795 | |
---|
1796 | // 加算ポイント、DB値を引き継ぐ |
---|
1797 | if (is_null($newAddPoint)) { |
---|
1798 | $newAddPoint = $arrOrderOld['add_point']; |
---|
1799 | } |
---|
1800 | |
---|
1801 | if (USE_POINT !== false) { |
---|
1802 | // 顧客.ポイントの加減値 |
---|
1803 | $addCustomerPoint = 0; |
---|
1804 | |
---|
1805 | // ▼使用ポイント |
---|
1806 | // 変更前の対応状況が利用対象の場合、変更前の使用ポイント分を戻す |
---|
1807 | if (SC_Utils_Ex::sfIsUsePoint($arrOrderOld['status'])) { |
---|
1808 | $addCustomerPoint += $arrOrderOld['use_point']; |
---|
1809 | } |
---|
1810 | |
---|
1811 | // 変更後の対応状況が利用対象の場合、変更後の使用ポイント分を引く |
---|
1812 | if (SC_Utils_Ex::sfIsUsePoint($newStatus)) { |
---|
1813 | $addCustomerPoint -= $newUsePoint; |
---|
1814 | } |
---|
1815 | // ▲使用ポイント |
---|
1816 | |
---|
1817 | // ▼加算ポイント |
---|
1818 | // 変更前の対応状況が加算対象の場合、変更前の加算ポイント分を戻す |
---|
1819 | if (SC_Utils_Ex::sfIsAddPoint($arrOrderOld['status'])) { |
---|
1820 | $addCustomerPoint -= $arrOrderOld['add_point']; |
---|
1821 | } |
---|
1822 | |
---|
1823 | // 変更後の対応状況が加算対象の場合、変更後の加算ポイント分を足す |
---|
1824 | if (SC_Utils_Ex::sfIsAddPoint($newStatus)) { |
---|
1825 | $addCustomerPoint += $newAddPoint; |
---|
1826 | } |
---|
1827 | // ▲加算ポイント |
---|
1828 | |
---|
1829 | if ($addCustomerPoint != 0) { |
---|
1830 | // ▼顧客テーブルの更新 |
---|
1831 | $sqlval = array(); |
---|
1832 | $where = ''; |
---|
1833 | $arrVal = array(); |
---|
1834 | $arrRawSql = array(); |
---|
1835 | $arrRawSqlVal = array(); |
---|
1836 | |
---|
1837 | $sqlval['update_date'] = 'Now()'; |
---|
1838 | $arrRawSql['point'] = 'point + ?'; |
---|
1839 | $arrRawSqlVal[] = $addCustomerPoint; |
---|
1840 | $where .= 'customer_id = ?'; |
---|
1841 | $arrVal[] = $arrOrderOld['customer_id']; |
---|
1842 | |
---|
1843 | $objQuery->update('dtb_customer', $sqlval, $where, $arrVal, $arrRawSql, $arrRawSqlVal); |
---|
1844 | // ▲顧客テーブルの更新 |
---|
1845 | |
---|
1846 | // 顧客.ポイントをマイナスした場合、 |
---|
1847 | if ($addCustomerPoint < 0) { |
---|
1848 | $sql = 'SELECT point FROM dtb_customer WHERE customer_id = ?'; |
---|
1849 | $point = $objQuery->getOne($sql, array($arrOrderOld['customer_id'])); |
---|
1850 | // 変更後の顧客.ポイントがマイナスの場合、 |
---|
1851 | if ($point < 0) { |
---|
1852 | // ロールバック |
---|
1853 | $objQuery->rollback(); |
---|
1854 | // エラー |
---|
1855 | SC_Utils_Ex::sfDispSiteError(LACK_POINT); |
---|
1856 | } |
---|
1857 | } |
---|
1858 | } |
---|
1859 | } |
---|
1860 | |
---|
1861 | // ▼受注テーブルの更新 |
---|
1862 | $sqlval = array(); |
---|
1863 | if (USE_POINT !== false) { |
---|
1864 | $sqlval['add_point'] = $newAddPoint; |
---|
1865 | $sqlval['use_point'] = $newUsePoint; |
---|
1866 | } |
---|
1867 | // ステータスが発送済みに変更の場合、発送日を更新 |
---|
1868 | if ($arrOrderOld['status'] != ORDER_DELIV && $newStatus == ORDER_DELIV) { |
---|
1869 | $sqlval['commit_date'] = 'Now()'; |
---|
1870 | } |
---|
1871 | $sqlval['status'] = $newStatus; |
---|
1872 | $sqlval['update_date'] = 'Now()'; |
---|
1873 | |
---|
1874 | $objQuery->update('dtb_order', $sqlval, 'order_id = ?', array($orderId)); |
---|
1875 | // ▲受注テーブルの更新 |
---|
1876 | } |
---|
1877 | |
---|
1878 | /** |
---|
1879 | * 指定ファイルが存在する場合 SQL として実行 |
---|
1880 | * |
---|
1881 | * XXX プラグイン用に追加。将来消すかも。 |
---|
1882 | * |
---|
1883 | * @param string $sqlFilePath SQL ファイルのパス |
---|
1884 | * @return void |
---|
1885 | */ |
---|
1886 | function sfExecSqlByFile($sqlFilePath) { |
---|
1887 | if (file_exists($sqlFilePath)) { |
---|
1888 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1889 | |
---|
1890 | $sqls = file_get_contents($sqlFilePath); |
---|
1891 | if ($sqls === false) SC_Utils_Ex::sfDispException('ファイルは存在するが読み込めない'); |
---|
1892 | |
---|
1893 | foreach (explode(';', $sqls) as $sql) { |
---|
1894 | $sql = trim($sql); |
---|
1895 | if (strlen($sql) == 0) continue; |
---|
1896 | $objQuery->query($sql); |
---|
1897 | } |
---|
1898 | } |
---|
1899 | } |
---|
1900 | |
---|
1901 | /** |
---|
1902 | * 商品規格を設定しているか |
---|
1903 | * |
---|
1904 | * @param integer $product_id 商品ID |
---|
1905 | * @return bool 商品規格が存在する場合:true, それ以外:false |
---|
1906 | */ |
---|
1907 | function sfHasProductClass($product_id) { |
---|
1908 | if (!SC_Utils_Ex::sfIsInt($product_id)) return false; |
---|
1909 | |
---|
1910 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1911 | $where = 'product_id = ? AND class_combination_id IS NOT NULL'; |
---|
1912 | $count = $objQuery->count('dtb_products_class', $where, array($product_id)); |
---|
1913 | |
---|
1914 | return $count >= 1; |
---|
1915 | } |
---|
1916 | /** |
---|
1917 | * カート内の商品の販売方法判定処理 |
---|
1918 | * |
---|
1919 | * @param $objCartSess SC_CartSession カートセッション |
---|
1920 | * @return bool 0:ダウンロード販売無 1:ダウンロード販売無 2:全てダウンロード販売 |
---|
1921 | */ |
---|
1922 | function chkCartDown($objCartSess) { |
---|
1923 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
1924 | $down = false; |
---|
1925 | $nodown = false; |
---|
1926 | $ret = 0; |
---|
1927 | $arrID = $objCartSess->getAllProductID(); |
---|
1928 | if(!is_null($arrID)){ |
---|
1929 | //カート内のIDから販売方法を取得 |
---|
1930 | foreach ($arrID as $rec) { |
---|
1931 | $arrRet = $objQuery->select("down", "dtb_products", "product_id = " . $rec); |
---|
1932 | if ($arrRet[0]['down'] == "2"){ |
---|
1933 | $down = true; |
---|
1934 | }else{ |
---|
1935 | $nodown = true; |
---|
1936 | } |
---|
1937 | } |
---|
1938 | } |
---|
1939 | //混在 |
---|
1940 | if($nodown && $down){ |
---|
1941 | $ret = 1; |
---|
1942 | //全てダウンロード商品 |
---|
1943 | }else if(!$nodown && $down){ |
---|
1944 | $ret = 2; |
---|
1945 | } |
---|
1946 | return $ret; |
---|
1947 | } |
---|
1948 | |
---|
1949 | /* 会員情報の住所を一時受注テーブルへ */ |
---|
1950 | function sfRegistDelivData($uniqid, $objCustomer) { |
---|
1951 | |
---|
1952 | // 登録データの作成 |
---|
1953 | $sqlval['order_temp_id'] = $uniqid; |
---|
1954 | $sqlval['update_date'] = 'Now()'; |
---|
1955 | $sqlval['customer_id'] = $objCustomer->getValue('customer_id'); |
---|
1956 | $sqlval['deliv_check'] = '-1'; |
---|
1957 | $sqlval['order_name01'] = $objCustomer->getValue('name01'); |
---|
1958 | $sqlval['order_name02'] = $objCustomer->getValue('name02'); |
---|
1959 | $sqlval['order_kana01'] = $objCustomer->getValue('kana01'); |
---|
1960 | $sqlval['order_kana02'] = $objCustomer->getValue('kana02'); |
---|
1961 | $sqlval['order_zip01'] = $objCustomer->getValue('zip01'); |
---|
1962 | $sqlval['order_zip02'] = $objCustomer->getValue('zip02'); |
---|
1963 | $sqlval['order_pref'] = $objCustomer->getValue('pref'); |
---|
1964 | $sqlval['order_addr01'] = $objCustomer->getValue('addr01'); |
---|
1965 | $sqlval['order_addr02'] = $objCustomer->getValue('addr02'); |
---|
1966 | $sqlval['order_tel01'] = $objCustomer->getValue('tel01'); |
---|
1967 | $sqlval['order_tel02'] = $objCustomer->getValue('tel02'); |
---|
1968 | $sqlval['order_tel03'] = $objCustomer->getValue('tel03'); |
---|
1969 | $sqlval['order_fax01'] = $objCustomer->getValue('fax01'); |
---|
1970 | $sqlval['order_fax02'] = $objCustomer->getValue('fax02'); |
---|
1971 | $sqlval['order_fax03'] = $objCustomer->getValue('fax03'); |
---|
1972 | $sqlval['deliv_name01'] = $objCustomer->getValue('name01'); |
---|
1973 | $sqlval['deliv_name02'] = $objCustomer->getValue('name02'); |
---|
1974 | $sqlval['deliv_kana01'] = $objCustomer->getValue('kana01'); |
---|
1975 | $sqlval['deliv_kana02'] = $objCustomer->getValue('kana02'); |
---|
1976 | $sqlval['deliv_zip01'] = $objCustomer->getValue('zip01'); |
---|
1977 | $sqlval['deliv_zip02'] = $objCustomer->getValue('zip02'); |
---|
1978 | $sqlval['deliv_pref'] = $objCustomer->getValue('pref'); |
---|
1979 | $sqlval['deliv_addr01'] = $objCustomer->getValue('addr01'); |
---|
1980 | $sqlval['deliv_addr02'] = $objCustomer->getValue('addr02'); |
---|
1981 | $sqlval['deliv_tel01'] = $objCustomer->getValue('tel01'); |
---|
1982 | $sqlval['deliv_tel02'] = $objCustomer->getValue('tel02'); |
---|
1983 | $sqlval['deliv_tel03'] = $objCustomer->getValue('tel03'); |
---|
1984 | $sqlval['deliv_fax01'] = $objCustomer->getValue('fax01'); |
---|
1985 | $sqlval['deliv_fax02'] = $objCustomer->getValue('fax02'); |
---|
1986 | $sqlval['deliv_fax03'] = $objCustomer->getValue('fax03'); |
---|
1987 | |
---|
1988 | $this->sfRegistTempOrder($uniqid, $sqlval); |
---|
1989 | } |
---|
1990 | |
---|
1991 | |
---|
1992 | } |
---|
1993 | ?> |
---|