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 | // {{{ requires |
---|
25 | require_once(CLASS_REALDIR . "pages/LC_Page.php"); |
---|
26 | |
---|
27 | /** |
---|
28 | * ご注文完了 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id:LC_Page_Shopping_Complete.php 15532 2007-08-31 14:39:46Z nanasess $ |
---|
33 | */ |
---|
34 | class LC_Page_Shopping_Complete extends LC_Page { |
---|
35 | |
---|
36 | // }}} |
---|
37 | // {{{ functions |
---|
38 | |
---|
39 | /** |
---|
40 | * Page を初期化する. |
---|
41 | * |
---|
42 | * @return void |
---|
43 | */ |
---|
44 | function init() { |
---|
45 | parent::init(); |
---|
46 | $this->tpl_title = "ご注文完了"; |
---|
47 | |
---|
48 | $masterData = new SC_DB_MasterData_Ex(); |
---|
49 | $this->arrCONVENIENCE = $masterData->getMasterData("mtb_convenience"); |
---|
50 | $this->arrCONVENIMESSAGE = $masterData->getMasterData("mtb_conveni_message"); |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * Page のプロセス. |
---|
55 | * |
---|
56 | * @return void |
---|
57 | */ |
---|
58 | function process() { |
---|
59 | parent::process(); |
---|
60 | $this->action(); |
---|
61 | $this->sendResponse(); |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | * Page のアクション. |
---|
66 | * |
---|
67 | * @return void |
---|
68 | */ |
---|
69 | function action() { |
---|
70 | $objView = new SC_SiteView(); |
---|
71 | $objSiteInfo = $objView->objSiteInfo; |
---|
72 | $this->arrInfo = $objSiteInfo->data; |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | * デストラクタ. |
---|
77 | * |
---|
78 | * @return void |
---|
79 | */ |
---|
80 | function destroy() { |
---|
81 | parent::destroy(); |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | * モバイルページを初期化する. |
---|
86 | * |
---|
87 | * @return void |
---|
88 | */ |
---|
89 | function mobileInit() { |
---|
90 | $this->init(); |
---|
91 | } |
---|
92 | |
---|
93 | /** |
---|
94 | * Page のプロセス(モバイル). |
---|
95 | * |
---|
96 | * @return void |
---|
97 | */ |
---|
98 | function mobileProcess() { |
---|
99 | parent::mobileProcess(); |
---|
100 | $this->mobileAction(); |
---|
101 | $this->sendResponse(); |
---|
102 | } |
---|
103 | /** |
---|
104 | * Page のプロセス(モバイル). |
---|
105 | * |
---|
106 | * @return void |
---|
107 | */ |
---|
108 | function mobileAction() { |
---|
109 | $objView = new SC_MobileView(); |
---|
110 | $this->objSiteSess = new SC_SiteSession(); |
---|
111 | $this->objCartSess = new SC_CartSession(); |
---|
112 | $objSiteInfo = $objView->objSiteInfo; |
---|
113 | $this->arrInfo = $objSiteInfo->data; |
---|
114 | $this->objCustomer = new SC_Customer(); |
---|
115 | $mailHelper = new SC_Helper_Mail_Ex(); |
---|
116 | |
---|
117 | // 前のページで正しく登録手続きが行われたか判定 |
---|
118 | SC_Utils_Ex::sfIsPrePage($this->objSiteSess); |
---|
119 | // ユーザユニークIDの取得と購入状態の正当性をチェック |
---|
120 | $uniqid = SC_Utils_Ex::sfCheckNormalAccess($this->objSiteSess, $this->objCartSess); |
---|
121 | if ($uniqid != "") { |
---|
122 | |
---|
123 | // 完了処理 |
---|
124 | $objQuery = new SC_Query(); |
---|
125 | $objQuery->begin(); |
---|
126 | $order_id = $this->lfDoComplete($objQuery, $uniqid); |
---|
127 | $objQuery->commit(); |
---|
128 | |
---|
129 | // セッションに保管されている情報を更新する |
---|
130 | $this->objCustomer->updateSession(); |
---|
131 | |
---|
132 | // 完了メール送信 |
---|
133 | if($order_id != "") { |
---|
134 | $mailHelper->sfSendOrderMail($order_id, '2'); |
---|
135 | } |
---|
136 | |
---|
137 | //その他情報の取得 |
---|
138 | $other_data = $objQuery->get("memo02", "dtb_order", "order_id = ? ", array($order_id)); |
---|
139 | if($other_data != "") { |
---|
140 | $arrOther = unserialize($other_data); |
---|
141 | |
---|
142 | // データを編集 |
---|
143 | foreach($arrOther as $key => $val){ |
---|
144 | // URLの場合にはリンクつきで表示させる |
---|
145 | if (preg_match('/^(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/', $val["value"])) { |
---|
146 | $arrOther[$key]["value"] = "<a href='". $val["value"]. "'>". $val["value"]. "</a>"; |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|
150 | $this->arrOther = $arrOther; |
---|
151 | |
---|
152 | } |
---|
153 | |
---|
154 | // アフィリエイト用コンバージョンタグの設定 |
---|
155 | $this->tpl_conv_page = AFF_SHOPPING_COMPLETE; |
---|
156 | $this->tpl_aff_option = "order_id=$order_id"; |
---|
157 | //合計価格の取得 |
---|
158 | $total = $objQuery->get("total", "dtb_order", "order_id = ? ", array($order_id)); |
---|
159 | if($total != "") { |
---|
160 | $this->tpl_aff_option.= "|total=$total"; |
---|
161 | } |
---|
162 | |
---|
163 | // TS連携モジュールの実行 |
---|
164 | if (function_exists('sfTSRequest')) { |
---|
165 | sfTSRequest($order_id); |
---|
166 | } |
---|
167 | } |
---|
168 | } |
---|
169 | |
---|
170 | |
---|
171 | // エビスタグ引渡し用データを生成する |
---|
172 | function lfGetEbisData($order_id) { |
---|
173 | $objQuery = new SC_Query(); |
---|
174 | $col = "customer_id, total, order_sex, order_job, to_number(to_char(age(current_timestamp, order_birth), 'YYY'), 999) AS order_age"; |
---|
175 | $arrRet = $objQuery->select($col, "dtb_order", "order_id = ?", array($order_id)); |
---|
176 | |
---|
177 | if($arrRet[0]['customer_id'] > 0) { |
---|
178 | // 会員番号 |
---|
179 | $arrEbis['m1id'] = $arrRet[0]['customer_id']; |
---|
180 | // 非会員or会員 |
---|
181 | $arrEbis['o5id'] = '1'; |
---|
182 | } else { |
---|
183 | // 会員番号 |
---|
184 | $arrEbis['m1id'] = ''; |
---|
185 | // 非会員or会員 |
---|
186 | $arrEbis['o5id'] = '2'; |
---|
187 | } |
---|
188 | |
---|
189 | // 購入金額 |
---|
190 | $arrEbis['a1id'] = $arrRet[0]['total']; |
---|
191 | // 性別 |
---|
192 | $arrEbis['o2id'] = $arrRet[0]['order_sex']; |
---|
193 | // 年齢 |
---|
194 | $arrEbis['o3id'] = $arrRet[0]['order_age']; |
---|
195 | // 職業 |
---|
196 | $arrEbis['o4id'] = $arrRet[0]['order_job']; |
---|
197 | |
---|
198 | $objQuery->setGroupBy("product_id"); |
---|
199 | $arrRet = $objQuery->select("product_id", "dtb_order_detail", "order_id = ?", array($order_id)); |
---|
200 | $arrProducts = sfSwapArray($arrRet); |
---|
201 | |
---|
202 | $line = ""; |
---|
203 | // 商品IDをアンダーバーで接続する。 |
---|
204 | foreach($arrProducts['product_id'] as $val) { |
---|
205 | if($line != "") { |
---|
206 | $line .= "_$val"; |
---|
207 | } else { |
---|
208 | $line .= "$val"; |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | // 商品ID |
---|
213 | $arrEbis['o1id'] = $line; |
---|
214 | |
---|
215 | return $arrEbis; |
---|
216 | } |
---|
217 | |
---|
218 | /** |
---|
219 | * 購入完了処理 |
---|
220 | * |
---|
221 | * @param object $objQuery |
---|
222 | * @param string $uniqid |
---|
223 | * @return string $order_id |
---|
224 | */ |
---|
225 | function lfDoComplete(&$objQuery, $uniqid) { |
---|
226 | $objDb = new SC_Helper_DB_Ex(); |
---|
227 | |
---|
228 | // 一時受注テーブルの読込 |
---|
229 | $arrData = $objDb->sfGetOrderTemp($uniqid); |
---|
230 | |
---|
231 | // 会員情報登録処理 |
---|
232 | if ($this->objCustomer->isLoginSuccess(true)) { |
---|
233 | // 新お届け先の登録 |
---|
234 | $this->lfSetNewAddr($uniqid, $this->objCustomer->getValue('customer_id')); |
---|
235 | // 購入集計を顧客テーブルに反映 |
---|
236 | $this->lfSetCustomerPurchase($this->objCustomer->getValue('customer_id'), $arrData, $objQuery); |
---|
237 | } else { |
---|
238 | // 購入時強制会員登録が有効の場合 |
---|
239 | if (PURCHASE_CUSTOMER_REGIST == '1') { |
---|
240 | // 会員登録 |
---|
241 | $customer_id = $this->lfRegistCustomer($arrData, $this->arrInfo); |
---|
242 | // 購入集計を顧客テーブルに反映 |
---|
243 | $this->lfSetCustomerPurchase($customer_id, $arrData, $objQuery); |
---|
244 | } |
---|
245 | } |
---|
246 | // 一時テーブルを受注テーブルに格納する |
---|
247 | $order_id = $this->lfRegistOrder($objQuery, $arrData); |
---|
248 | // カート商品を受注詳細テーブルに格納する |
---|
249 | $this->lfRegistOrderDetail($objQuery, $order_id, $this->objCartSess); |
---|
250 | // 受注一時テーブルの情報を削除する。 |
---|
251 | $this->lfDeleteTempOrder($objQuery, $uniqid); |
---|
252 | |
---|
253 | // セッションカート内の商品を削除する。 |
---|
254 | $this->objCartSess->delAllProducts(); |
---|
255 | // 注文一時IDを解除する。 |
---|
256 | $this->objSiteSess->unsetUniqId(); |
---|
257 | |
---|
258 | return $order_id; |
---|
259 | } |
---|
260 | |
---|
261 | // 会員登録 |
---|
262 | function lfRegistCustomer($arrData, $arrInfo) { |
---|
263 | $objQuery = new SC_Query(); |
---|
264 | |
---|
265 | //会員登録時に仮会員確認用のメールを送付するか |
---|
266 | $confirm_flg = CUSTOMER_CONFIRM_MAIL; |
---|
267 | |
---|
268 | // 購入時の会員登録 |
---|
269 | $sqlval['name01'] = $arrData['order_name01']; |
---|
270 | $sqlval['name02'] = $arrData['order_name02']; |
---|
271 | $sqlval['kana01'] = $arrData['order_kana01']; |
---|
272 | $sqlval['kana02'] = $arrData['order_kana02']; |
---|
273 | $sqlval['zip01'] = $arrData['order_zip01']; |
---|
274 | $sqlval['zip02'] = $arrData['order_zip02']; |
---|
275 | $sqlval['pref'] = $arrData['order_pref']; |
---|
276 | $sqlval['addr01'] = $arrData['order_addr01']; |
---|
277 | $sqlval['addr02'] = $arrData['order_addr02']; |
---|
278 | $sqlval['email'] = $arrData['order_email']; |
---|
279 | $sqlval['tel01'] = $arrData['order_tel01']; |
---|
280 | $sqlval['tel02'] = $arrData['order_tel02']; |
---|
281 | $sqlval['tel03'] = $arrData['order_tel03']; |
---|
282 | $sqlval['fax01'] = $arrData['order_fax01']; |
---|
283 | $sqlval['fax02'] = $arrData['order_fax02']; |
---|
284 | $sqlval['fax03'] = $arrData['order_fax03']; |
---|
285 | $sqlval['sex'] = $arrData['order_sex']; |
---|
286 | $sqlval['password'] = $arrData['password']; |
---|
287 | $sqlval['reminder'] = $arrData['reminder']; |
---|
288 | $sqlval['reminder_answer'] = $arrData['reminder_answer']; |
---|
289 | |
---|
290 | // 仮会員登録の場合 |
---|
291 | if ($confirm_flg == true) { |
---|
292 | // 重複しない会員登録キーを発行する。 |
---|
293 | $count = 1; |
---|
294 | while ($count != 0) { |
---|
295 | $uniqid = SC_Utils_Ex::sfGetUniqRandomId("t"); |
---|
296 | $count = $objQuery->count("dtb_customer", "secret_key = ?", array($uniqid)); |
---|
297 | } |
---|
298 | $sqlval["status"] = "1"; // 仮会員 |
---|
299 | //本会員登録 |
---|
300 | } else { |
---|
301 | // 重複しない会員登録キーを発行する。 |
---|
302 | $count = 1; |
---|
303 | while ($count != 0) { |
---|
304 | $uniqid = SC_Utils_Ex::sfGetUniqRandomId("r"); |
---|
305 | $count = $objQuery->count("dtb_customer", "secret_key = ?", array($uniqid)); |
---|
306 | } |
---|
307 | $sqlval["status"] = "2"; // 本会員 |
---|
308 | } |
---|
309 | |
---|
310 | // メルマガフラグ |
---|
311 | switch ($arrData["mailmaga_flg"]) { |
---|
312 | case 1: // HTMLメール |
---|
313 | $mail_flag = 4; |
---|
314 | break; |
---|
315 | case 2: // TEXTメール |
---|
316 | $mail_flag = 5; |
---|
317 | break; |
---|
318 | default: |
---|
319 | $mail_flag = 6; |
---|
320 | break; |
---|
321 | } |
---|
322 | $sqlval['mailmaga_flg'] = $mail_flag; |
---|
323 | |
---|
324 | // URL判定用キー |
---|
325 | $sqlval['secret_key'] = SC_Utils_Ex::sfGetUniqRandomId("t"); |
---|
326 | |
---|
327 | $sqlval['create_date'] = "now()"; |
---|
328 | $sqlval['update_date'] = "now()"; |
---|
329 | |
---|
330 | $sqlval['customer_id'] = $objQuery->nextVal('dtb_customer_customer_id'); |
---|
331 | $customer_id = $sqlval['customer_id']; |
---|
332 | |
---|
333 | $objQuery->insert("dtb_customer", $sqlval); |
---|
334 | |
---|
335 | // 登録完了メール送信 |
---|
336 | $objMailPage = $this; |
---|
337 | $objMailPage->name01 = $arrData['order_name01']; |
---|
338 | $objMailPage->name02 = $arrData['order_name02']; |
---|
339 | $objMailPage->CONF = $arrInfo; |
---|
340 | $objMailPage->uniqid = $sqlval['secret_key']; |
---|
341 | $objMailView = new SC_SiteView(); |
---|
342 | $objMailView->assignobj($objMailPage); |
---|
343 | $body = $objMailView->fetch("mail_templates/customer_mail.tpl"); |
---|
344 | |
---|
345 | $mailHelper = new SC_Helper_Mail_Ex(); |
---|
346 | |
---|
347 | //仮会員メール |
---|
348 | if ($confirm_flg == true) { |
---|
349 | $subject = $mailHelper->sfMakeSubject('会員登録のご確認'); |
---|
350 | $body = $objMailView->fetch('mail_templates/customer_mail.tpl'); |
---|
351 | //本会員メール |
---|
352 | } else { |
---|
353 | $subject = $mailHelper->sfMakeSubject('会員登録のご完了'); |
---|
354 | $body = $objMailView->fetch('mail_templates/customer_regist_mail.tpl'); |
---|
355 | // ログイン状態にする |
---|
356 | $this->objCustomer->setLogin($arrData['order_email']); |
---|
357 | } |
---|
358 | |
---|
359 | $objMail = new SC_SendMail(); |
---|
360 | $objMail->setItem( |
---|
361 | '' // 宛先 |
---|
362 | , $subject // サブジェクト |
---|
363 | , $body // 本文 |
---|
364 | , $arrInfo['email03'] // 配送元アドレス |
---|
365 | , $arrInfo['shop_name'] // 配送元 名前 |
---|
366 | , $arrInfo["email03"] // reply_to |
---|
367 | , $arrInfo["email04"] // return_path |
---|
368 | , $arrInfo["email04"] // Errors_to |
---|
369 | , $arrInfo["email01"] // Bcc |
---|
370 | ); |
---|
371 | // 宛先の設定 |
---|
372 | $name = $arrData['order_name01'] . $arrData['order_name02'] ." 様"; |
---|
373 | $objMail->setTo($arrData['order_email'], $name); |
---|
374 | $objMail->sendMail(); |
---|
375 | |
---|
376 | return $customer_id; |
---|
377 | } |
---|
378 | |
---|
379 | /** |
---|
380 | * 受注テーブルへ登録 |
---|
381 | * |
---|
382 | * @return integer 注文番号 |
---|
383 | */ |
---|
384 | function lfRegistOrder($objQuery, $arrData) { |
---|
385 | $objDb = new SC_Helper_DB_Ex(); |
---|
386 | $sqlval = $arrData; |
---|
387 | |
---|
388 | // 受注テーブルに書き込まない列を除去 |
---|
389 | unset($sqlval['mailmaga_flg']); // メルマガチェック |
---|
390 | unset($sqlval['deliv_check']); // 別のお届け先チェック |
---|
391 | unset($sqlval['point_check']); // ポイント利用チェック |
---|
392 | unset($sqlval['password']); // ログインパスワード |
---|
393 | unset($sqlval['reminder']); // リマインダー質問 |
---|
394 | unset($sqlval['reminder_answer']); // リマインダー答え |
---|
395 | unset($sqlval['mail_flag']); // メールフラグ |
---|
396 | unset($sqlval['session']); // セッション情報 |
---|
397 | |
---|
398 | //ダウンロード商品判定 |
---|
399 | $this->cartdown = $objDb->chkCartDown($this->objCartSess); |
---|
400 | |
---|
401 | // ポイントは別登録 |
---|
402 | $addPoint = $sqlval['add_point']; |
---|
403 | $usePoint = $sqlval['use_point']; |
---|
404 | $sqlval['add_point'] = 0; |
---|
405 | $sqlval['use_point'] = 0; |
---|
406 | |
---|
407 | // 合計金額が0円の場合、もしくはオンライン決済の場合は、注文ステータスをORDER_PRE_END[入金済み]にする |
---|
408 | if ( ( $sqlval['total'] == 0 ) or ( in_array($sqlval['payment_id'], split(",", ONLINE_PAYMENT)) == true ) ){ |
---|
409 | $sqlval = $this->lfchgPreEndStatus($sqlval); |
---|
410 | } |
---|
411 | if(strlen($sqlval['status']) == 0) { |
---|
412 | // 注文ステータス:指定が無ければ新規受付に設定 |
---|
413 | $sqlval['status'] = ORDER_NEW; |
---|
414 | } |
---|
415 | |
---|
416 | // 別のお届け先を指定していない場合、お届け先に登録住所をコピーする。 |
---|
417 | if ($arrData["deliv_check"] == "-1") { |
---|
418 | $sqlval['deliv_name01'] = $arrData['order_name01']; |
---|
419 | $sqlval['deliv_name02'] = $arrData['order_name02']; |
---|
420 | $sqlval['deliv_kana01'] = $arrData['order_kana01']; |
---|
421 | $sqlval['deliv_kana02'] = $arrData['order_kana02']; |
---|
422 | $sqlval['deliv_pref'] = $arrData['order_pref']; |
---|
423 | $sqlval['deliv_zip01'] = $arrData['order_zip01']; |
---|
424 | $sqlval['deliv_zip02'] = $arrData['order_zip02']; |
---|
425 | $sqlval['deliv_addr01'] = $arrData['order_addr01']; |
---|
426 | $sqlval['deliv_addr02'] = $arrData['order_addr02']; |
---|
427 | $sqlval['deliv_tel01'] = $arrData['order_tel01']; |
---|
428 | $sqlval['deliv_tel02'] = $arrData['order_tel02']; |
---|
429 | $sqlval['deliv_tel03'] = $arrData['order_tel03']; |
---|
430 | } |
---|
431 | |
---|
432 | $order_id = $arrData['order_id']; // 注文番号 |
---|
433 | $sqlval['create_date'] = 'Now()'; // 受注日 |
---|
434 | $sqlval['update_date'] = 'Now()'; // 更新日時 |
---|
435 | |
---|
436 | // 受注テーブルの登録 |
---|
437 | $objQuery->insert("dtb_order", $sqlval); |
---|
438 | |
---|
439 | // 受注.対応状況の更新 |
---|
440 | SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, null, $addPoint, $usePoint); |
---|
441 | |
---|
442 | return $order_id; |
---|
443 | } |
---|
444 | |
---|
445 | // 受注詳細テーブルへ登録 |
---|
446 | function lfRegistOrderDetail(&$objQuery, $order_id, &$objCartSess) { |
---|
447 | $objDb = new SC_Helper_DB_Ex(); |
---|
448 | // カート内情報の取得 |
---|
449 | $this->cartKey = $_SESSION['cartKey']; |
---|
450 | $arrCart = $objCartSess->getCartList($this->cartKey); |
---|
451 | $max = count($arrCart); |
---|
452 | |
---|
453 | // 既に存在する詳細レコードを消しておく。 |
---|
454 | $objQuery->delete("dtb_order_detail", "order_id = ?", array($order_id)); |
---|
455 | |
---|
456 | // 規格名一覧 |
---|
457 | $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name"); |
---|
458 | // 規格分類名一覧 |
---|
459 | $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); |
---|
460 | |
---|
461 | $objProduct = new SC_Product(); |
---|
462 | for ($i = 0; $i < $max; $i++) { |
---|
463 | // 商品規格情報の取得 |
---|
464 | $arrData = $objProduct->getDetailAndProductsClass($arrCart[$i]['id']); |
---|
465 | |
---|
466 | // 存在する商品のみ表示する。 |
---|
467 | if($arrData != "") { |
---|
468 | $sqlval['order_id'] = $order_id; |
---|
469 | $sqlval['product_id'] = $arrData['product_id']; |
---|
470 | $sqlval['product_class_id'] = $arrData['product_class_id']; |
---|
471 | $sqlval['product_name'] = $arrData['name']; |
---|
472 | $sqlval['product_code'] = $arrData['product_code']; |
---|
473 | $sqlval['classcategory_name1'] = $arrData['classcategory_name1']; |
---|
474 | $sqlval['classcategory_name2'] = $arrData['classcategory_name2']; |
---|
475 | $sqlval['point_rate'] = $arrCart[$i]['point_rate']; |
---|
476 | $sqlval['price'] = $arrCart[$i]['price']; |
---|
477 | $sqlval['quantity'] = $arrCart[$i]['quantity']; |
---|
478 | $this->lfReduceStock($objQuery, $arrCart[$i]['id'], $arrCart[$i]['quantity']); |
---|
479 | // INSERTの実行 |
---|
480 | $objQuery->insert("dtb_order_detail", $sqlval); |
---|
481 | } else { |
---|
482 | SC_Utils_Ex::sfDispSiteError(CART_NOT_FOUND); |
---|
483 | } |
---|
484 | } |
---|
485 | } |
---|
486 | |
---|
487 | /* 受注一時テーブルの削除 */ |
---|
488 | function lfDeleteTempOrder(&$objQuery, $uniqid) { |
---|
489 | $where = "order_temp_id = ?"; |
---|
490 | $sqlval['del_flg'] = 1; |
---|
491 | $objQuery->update("dtb_order_temp", $sqlval, $where, array($uniqid)); |
---|
492 | // $objQuery->delete("dtb_order_temp", $where, array($uniqid)); |
---|
493 | } |
---|
494 | |
---|
495 | // 受注一時テーブルの住所が登録済みテーブルと異なる場合は、別のお届け先に追加する |
---|
496 | function lfSetNewAddr($uniqid, $customer_id) { |
---|
497 | $objQuery = new SC_Query(); |
---|
498 | $diff = false; |
---|
499 | $find_same = false; |
---|
500 | |
---|
501 | $col = "deliv_name01,deliv_name02,deliv_kana01,deliv_kana02,deliv_tel01,deliv_tel02,deliv_tel03,deliv_zip01,deliv_zip02,deliv_pref,deliv_addr01,deliv_addr02"; |
---|
502 | $where = "order_temp_id = ?"; |
---|
503 | $arrRet = $objQuery->select($col, "dtb_order_temp", $where, array($uniqid)); |
---|
504 | |
---|
505 | // 要素名のdeliv_を削除する。 |
---|
506 | foreach($arrRet[0] as $key => $val) { |
---|
507 | $keyname = ereg_replace("^deliv_", "", $key); |
---|
508 | $arrNew[$keyname] = $val; |
---|
509 | } |
---|
510 | |
---|
511 | // 会員情報テーブルとの比較 |
---|
512 | $col = "name01,name02,kana01,kana02,tel01,tel02,tel03,zip01,zip02,pref,addr01,addr02"; |
---|
513 | $where = "customer_id = ?"; |
---|
514 | $arrCustomerAddr = $objQuery->select($col, "dtb_customer", $where, array($customer_id)); |
---|
515 | |
---|
516 | // 会員情報の住所と異なる場合 |
---|
517 | if($arrNew != $arrCustomerAddr[0]) { |
---|
518 | // 別のお届け先テーブルの住所と比較する |
---|
519 | $col = "name01,name02,kana01,kana02,tel01,tel02,tel03,zip01,zip02,pref,addr01,addr02"; |
---|
520 | $where = "customer_id = ?"; |
---|
521 | $arrOtherAddr = $objQuery->select($col, "dtb_other_deliv", $where, array($customer_id)); |
---|
522 | |
---|
523 | foreach($arrOtherAddr as $arrval) { |
---|
524 | if($arrNew == $arrval) { |
---|
525 | // すでに同じ住所が登録されている |
---|
526 | $find_same = true; |
---|
527 | } |
---|
528 | } |
---|
529 | |
---|
530 | if(!$find_same) { |
---|
531 | $diff = true; |
---|
532 | } |
---|
533 | } |
---|
534 | |
---|
535 | // 新しいお届け先が登録済みのものと異なる場合は別のお届け先テーブルに登録する |
---|
536 | if($diff) { |
---|
537 | $sqlval = $arrNew; |
---|
538 | $sqlval['customer_id'] = $customer_id; |
---|
539 | $sqlval['other_deliv_id'] = $objQuery->nextVal('dtb_other_deliv_other_deliv_id'); |
---|
540 | $objQuery->insert("dtb_other_deliv", $sqlval); |
---|
541 | } |
---|
542 | } |
---|
543 | |
---|
544 | /* 購入情報を会員テーブルに登録する */ |
---|
545 | function lfSetCustomerPurchase($customer_id, $arrData, &$objQuery) { |
---|
546 | $col = "first_buy_date, last_buy_date, buy_times, buy_total"; |
---|
547 | $where = "customer_id = ?"; |
---|
548 | $arrRet = $objQuery->select($col, "dtb_customer", $where, array($customer_id)); |
---|
549 | $sqlval = $arrRet[0]; |
---|
550 | |
---|
551 | if($sqlval['first_buy_date'] == "") { |
---|
552 | $sqlval['first_buy_date'] = "Now()"; |
---|
553 | } |
---|
554 | $sqlval['last_buy_date'] = "Now()"; |
---|
555 | $sqlval['buy_times']++; |
---|
556 | $sqlval['buy_total']+= $arrData['total']; |
---|
557 | |
---|
558 | $objQuery->update("dtb_customer", $sqlval, $where, array($customer_id)); |
---|
559 | } |
---|
560 | |
---|
561 | /** |
---|
562 | * 在庫を減らす処理 |
---|
563 | * |
---|
564 | * FIXME 件数カウントバッチは最後にまとめて実行すること. |
---|
565 | */ |
---|
566 | function lfReduceStock(&$objQuery, $product_class_id, $quantity) { |
---|
567 | $objDb = new SC_Helper_DB_Ex(); |
---|
568 | |
---|
569 | if (!SC_Utils_Ex::sfIsInt($quantity)) { |
---|
570 | $objQuery->rollback(); |
---|
571 | SC_Utils_Ex::sfDispException(); |
---|
572 | } |
---|
573 | |
---|
574 | $objProduct = new SC_Product(); |
---|
575 | $productsClass = $objProduct->getDetailAndProductsClass($product_class_id); |
---|
576 | |
---|
577 | if (($productsClass['stock_unlimited'] != '1' && $productsClass['stock'] < $quantity) |
---|
578 | || $quantity == 0) { |
---|
579 | // 売り切れエラー |
---|
580 | $objQuery->rollback(); |
---|
581 | SC_Utils_Ex::sfDispSiteError(SOLD_OUT, "", true); |
---|
582 | } |
---|
583 | |
---|
584 | // 在庫を減らす |
---|
585 | $arrRawSql = array(); |
---|
586 | $arrRawSql['stock'] = 'stock - ?'; |
---|
587 | $arrRawSqlVal[] = $quantity; |
---|
588 | $objQuery->update('dtb_products_class', array(), "product_class_id = ?", array($val['product_class_id']), $arrRawSql, $arrRawSqlVal); |
---|
589 | |
---|
590 | // 在庫無し商品の非表示対応 |
---|
591 | if (NOSTOCK_HIDDEN === true) { |
---|
592 | // 件数カウントバッチ実行 |
---|
593 | $objDb->sfCategory_Count($objQuery); |
---|
594 | } |
---|
595 | |
---|
596 | } |
---|
597 | |
---|
598 | // ステータスを入金済みにする |
---|
599 | function lfchgPreEndStatus($sqlval){ |
---|
600 | $sqlval['status'] = ORDER_PRE_END; |
---|
601 | $sqlval['payment_date'] = 'NOW()'; |
---|
602 | //ダウンロード商品のみの場合はORDER_DELIV[発送済み]にして発送時間を入れる |
---|
603 | if($this->cartdown == 2){ |
---|
604 | $sqlval['status'] = ORDER_DELIV; |
---|
605 | $sqlval['commit_date'] = 'NOW()'; |
---|
606 | } |
---|
607 | return $sqlval; |
---|
608 | } |
---|
609 | } |
---|
610 | ?> |
---|