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