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