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/admin/LC_Page_Admin.php"); |
---|
26 | |
---|
27 | /** |
---|
28 | * 受注修正 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Admin_Order_Edit extends LC_Page_Admin { |
---|
35 | |
---|
36 | // {{{ properties |
---|
37 | |
---|
38 | /** 表示モード */ |
---|
39 | var $disp_mode; |
---|
40 | |
---|
41 | // }}} |
---|
42 | // {{{ functions |
---|
43 | |
---|
44 | /** |
---|
45 | * Page を初期化する. |
---|
46 | * |
---|
47 | * @return void |
---|
48 | */ |
---|
49 | function init() { |
---|
50 | parent::init(); |
---|
51 | $this->tpl_mainpage = 'order/edit.tpl'; |
---|
52 | $this->tpl_subnavi = 'order/subnavi.tpl'; |
---|
53 | $this->tpl_mainno = 'order'; |
---|
54 | $this->tpl_subno = 'index'; |
---|
55 | $this->tpl_subtitle = '受注管理'; |
---|
56 | if (empty($_GET['order_id']) && empty($_POST['order_id'])) { |
---|
57 | $this->tpl_subno = 'add'; |
---|
58 | $this->tpl_mode = 'add'; |
---|
59 | $this->tpl_subtitle = '新規受注入力'; |
---|
60 | } |
---|
61 | |
---|
62 | $masterData = new SC_DB_MasterData_Ex(); |
---|
63 | $this->arrPref = $masterData->getMasterData('mtb_pref'); |
---|
64 | $this->arrORDERSTATUS = $masterData->getMasterData("mtb_order_status"); |
---|
65 | |
---|
66 | $this->httpCacheControl('nocache'); |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * Page のプロセス. |
---|
71 | * |
---|
72 | * @return void |
---|
73 | */ |
---|
74 | function process() { |
---|
75 | $this->action(); |
---|
76 | $this->sendResponse(); |
---|
77 | } |
---|
78 | |
---|
79 | /** |
---|
80 | * Page のアクション. |
---|
81 | * |
---|
82 | * @return void |
---|
83 | */ |
---|
84 | function action() { |
---|
85 | $objSess = new SC_Session(); |
---|
86 | $objDb = new SC_Helper_DB_Ex(); |
---|
87 | $objDate = new SC_Date(1970); |
---|
88 | $objPurchase = new SC_Helper_Purchase_Ex(); |
---|
89 | $this->arrYearShippingDate = $objDate->getYear('', date('Y'), ''); |
---|
90 | $this->arrMonthShippingDate = $objDate->getMonth(true); |
---|
91 | $this->arrDayShippingDate = $objDate->getDay(true); |
---|
92 | |
---|
93 | // パラメータ管理クラス |
---|
94 | $this->objFormParam = new SC_FormParam(); |
---|
95 | // パラメータ情報の初期化 |
---|
96 | $this->lfInitParam(); |
---|
97 | |
---|
98 | // 認証可否の判定 |
---|
99 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
100 | |
---|
101 | // 検索パラメータの引き継ぎ |
---|
102 | foreach ($_POST as $key => $val) { |
---|
103 | if (ereg("^search_", $key)) { |
---|
104 | $this->arrSearchHidden[$key] = $val; |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | // 表示モード判定 |
---|
109 | if(isset($_GET['order_id']) && |
---|
110 | SC_Utils_Ex::sfIsInt($_GET['order_id'])) { |
---|
111 | $this->disp_mode = true; |
---|
112 | $order_id = $_GET['order_id']; |
---|
113 | } else { |
---|
114 | $order_id = $_POST['order_id']; |
---|
115 | } |
---|
116 | $this->tpl_order_id = $order_id; |
---|
117 | |
---|
118 | // DBから受注情報を読み込む |
---|
119 | $this->lfGetOrderData($order_id); |
---|
120 | |
---|
121 | switch($_POST['mode']) { |
---|
122 | case 'pre_edit': |
---|
123 | case 'order_id': |
---|
124 | break; |
---|
125 | case 'edit': |
---|
126 | case 'add': |
---|
127 | // POST情報で上書き |
---|
128 | $this->objFormParam->setParam($_POST); |
---|
129 | |
---|
130 | // 入力値の変換 |
---|
131 | $this->objFormParam->convParam(); |
---|
132 | $this->arrErr = $this->lfCheckError(); |
---|
133 | |
---|
134 | if(count($this->arrErr) == 0) { |
---|
135 | if ($_POST['mode'] == 'add') { |
---|
136 | $order_id = $this->lfRegistNewData(); |
---|
137 | |
---|
138 | $this->tpl_order_id = $order_id; |
---|
139 | $this->tpl_mode = 'edit'; |
---|
140 | |
---|
141 | $arrData['order_id'] = $order_id; |
---|
142 | $this->objFormParam->setParam($arrData); |
---|
143 | |
---|
144 | $text = "'新規受注を登録しました。'"; |
---|
145 | } else { |
---|
146 | $this->lfRegistData($_POST['order_id']); |
---|
147 | $text = "'受注履歴を編集しました。'"; |
---|
148 | } |
---|
149 | // DBから受注情報を再読込 |
---|
150 | $this->lfGetOrderData($order_id); |
---|
151 | $this->tpl_onload = "window.alert(".$text.");"; |
---|
152 | } |
---|
153 | break; |
---|
154 | // 再計算 |
---|
155 | case 'cheek': |
---|
156 | //支払い方法の選択 |
---|
157 | case 'payment': |
---|
158 | // POST情報で上書き |
---|
159 | $this->objFormParam->setParam($_POST); |
---|
160 | // 入力値の変換 |
---|
161 | $this->objFormParam->convParam(); |
---|
162 | $this->arrErr = $this->lfCheckError(); |
---|
163 | break; |
---|
164 | |
---|
165 | /* 商品削除*/ |
---|
166 | case 'delete_product': |
---|
167 | $delete_no = $_POST['delete_no']; |
---|
168 | foreach ($_POST AS $key=>$val) { |
---|
169 | if (is_array($val)) { |
---|
170 | foreach ($val AS $k=>$v) { |
---|
171 | if ($k != $delete_no) { |
---|
172 | $arrData[$key][] = $v; |
---|
173 | } |
---|
174 | } |
---|
175 | } else { |
---|
176 | $arrData[$key] = $val; |
---|
177 | } |
---|
178 | } |
---|
179 | // 情報上書き |
---|
180 | $this->objFormParam->setParam($arrData); |
---|
181 | // 入力値の変換 |
---|
182 | $this->objFormParam->convParam(); |
---|
183 | $this->arrErr = $this->lfCheckError(); |
---|
184 | break; |
---|
185 | /* 商品追加ポップアップより商品選択後、商品情報取得*/ |
---|
186 | case 'select_product_detail': |
---|
187 | // POST情報で上書き |
---|
188 | $this->objFormParam->setParam($_POST); |
---|
189 | if (!empty($_POST['add_product_class_id'])) { |
---|
190 | $this->lfInsertProduct($_POST['add_product_class_id']); |
---|
191 | } elseif (!empty($_POST['edit_product_class_id'])) { |
---|
192 | $this->lfUpdateProduct($_POST['edit_product_class_id'], $_POST['no']); |
---|
193 | } |
---|
194 | $arrData = $_POST; |
---|
195 | foreach ($this->arrForm AS $key=>$val) { |
---|
196 | if (is_array($val)) { |
---|
197 | $arrData[$key] = $this->arrForm[$key]['value']; |
---|
198 | } else { |
---|
199 | $arrData[$key] = $val; |
---|
200 | } |
---|
201 | } |
---|
202 | // 情報上書き |
---|
203 | $this->objFormParam->setParam($arrData); |
---|
204 | // 入力値の変換 |
---|
205 | $this->objFormParam->convParam(); |
---|
206 | $this->arrErr = $this->lfCheckError(); |
---|
207 | break; |
---|
208 | /* 顧客検索ポップアップより顧客指定後、顧客情報取得*/ |
---|
209 | case 'search_customer': |
---|
210 | // POST情報で上書き |
---|
211 | $this->objFormParam->setParam($_POST); |
---|
212 | |
---|
213 | // 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する |
---|
214 | $this->lfSetCustomerInfo($_POST['edit_customer_id']); |
---|
215 | |
---|
216 | break; |
---|
217 | |
---|
218 | // 複数配送設定表示 |
---|
219 | case 'multiple': |
---|
220 | $this->objFormParam->setParam($_POST); |
---|
221 | break; |
---|
222 | |
---|
223 | // 複数配送設定を反映 |
---|
224 | case 'multiple_set_to': |
---|
225 | $multipleSize = $_POST['multiple_size']; |
---|
226 | $this->lfInitMultipleParam($multipleSize); |
---|
227 | $this->objFormParam->setParam($_POST); |
---|
228 | $this->setMultipleItemTo($multipleSize); |
---|
229 | break; |
---|
230 | default: |
---|
231 | break; |
---|
232 | } |
---|
233 | |
---|
234 | // 支払い方法の取得 |
---|
235 | $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method"); |
---|
236 | |
---|
237 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
238 | // XXX 商品種別IDは0番目の配列を使用 |
---|
239 | $this->product_type_id = $this->arrForm['product_type_id']['value'][0]; |
---|
240 | $this->arrDelivTime = $objPurchase->getDelivTime($this->product_type_id); |
---|
241 | $this->product_count = count($this->arrForm['quantity']['value']); |
---|
242 | |
---|
243 | // アンカーを設定 |
---|
244 | if (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) { |
---|
245 | $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'"; |
---|
246 | } else { |
---|
247 | $anchor_hash = ""; |
---|
248 | } |
---|
249 | $this->tpl_onload .= $anchor_hash; |
---|
250 | |
---|
251 | $objSiteInfo = new SC_SiteInfo(); |
---|
252 | $this->arrInfo = $objSiteInfo->data; |
---|
253 | |
---|
254 | // 表示モード判定 |
---|
255 | if(!$this->disp_mode) { |
---|
256 | $this->setTemplate(MAIN_FRAME); |
---|
257 | } else { |
---|
258 | $this->setTemplate('order/disp.tpl'); |
---|
259 | } |
---|
260 | } |
---|
261 | |
---|
262 | /** |
---|
263 | * デストラクタ. |
---|
264 | * |
---|
265 | * @return void |
---|
266 | */ |
---|
267 | function destroy() { |
---|
268 | parent::destroy(); |
---|
269 | } |
---|
270 | |
---|
271 | /* パラメータ情報の初期化 */ |
---|
272 | function lfInitParam() { |
---|
273 | |
---|
274 | // お客様情報 |
---|
275 | $this->objFormParam->addParam("顧客名1", "order_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
276 | $this->objFormParam->addParam("顧客名2", "order_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
277 | $this->objFormParam->addParam("顧客名カナ1", "order_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
278 | $this->objFormParam->addParam("顧客名カナ2", "order_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
279 | $this->objFormParam->addParam("メールアドレス", "order_email", MTEXT_LEN, "KVCa", array("NO_SPTAB", "EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK")); |
---|
280 | $this->objFormParam->addParam("郵便番号1", "order_zip01", ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
281 | $this->objFormParam->addParam("郵便番号2", "order_zip02", ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
282 | $this->objFormParam->addParam("都道府県", "order_pref", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
283 | $this->objFormParam->addParam("住所1", "order_addr01", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
284 | $this->objFormParam->addParam("住所2", "order_addr02", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
285 | $this->objFormParam->addParam("電話番号1", "order_tel01", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
286 | $this->objFormParam->addParam("電話番号2", "order_tel02", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
287 | $this->objFormParam->addParam("電話番号3", "order_tel03", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
288 | |
---|
289 | // 受注商品情報 |
---|
290 | $this->objFormParam->addParam("値引き", "discount", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
291 | $this->objFormParam->addParam("送料", "deliv_fee", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
292 | $this->objFormParam->addParam("手数料", "charge", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
293 | |
---|
294 | // ポイント機能ON時のみ |
---|
295 | if (USE_POINT !== false) { |
---|
296 | $this->objFormParam->addParam("利用ポイント", "use_point", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
297 | } |
---|
298 | |
---|
299 | $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
300 | $this->objFormParam->addParam("対応状況", "status", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
301 | $this->objFormParam->addParam("お支払方法名称", "payment_method"); |
---|
302 | |
---|
303 | |
---|
304 | // 受注詳細情報 |
---|
305 | $this->objFormParam->addParam("商品種別ID", "product_type_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
306 | $this->objFormParam->addParam("単価", "price", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
307 | $this->objFormParam->addParam("数量", "quantity", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
308 | $this->objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
309 | $this->objFormParam->addParam("商品規格ID", "product_class_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
310 | $this->objFormParam->addParam("ポイント付与率", "point_rate"); |
---|
311 | $this->objFormParam->addParam("商品コード", "product_code"); |
---|
312 | $this->objFormParam->addParam("商品名", "product_name"); |
---|
313 | $this->objFormParam->addParam("規格名1", "classcategory_name1"); |
---|
314 | $this->objFormParam->addParam("規格名2", "classcategory_name2"); |
---|
315 | $this->objFormParam->addParam("メモ", "note", MTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK")); |
---|
316 | // DB読込用 |
---|
317 | $this->objFormParam->addParam("小計", "subtotal"); |
---|
318 | $this->objFormParam->addParam("合計", "total"); |
---|
319 | $this->objFormParam->addParam("支払い合計", "payment_total"); |
---|
320 | $this->objFormParam->addParam("加算ポイント", "add_point"); |
---|
321 | $this->objFormParam->addParam("お誕生日ポイント", "birth_point"); |
---|
322 | $this->objFormParam->addParam("消費税合計", "tax"); |
---|
323 | $this->objFormParam->addParam("最終保持ポイント", "total_point"); |
---|
324 | $this->objFormParam->addParam("顧客ID", "customer_id"); |
---|
325 | $this->objFormParam->addParam("現在のポイント", "point"); |
---|
326 | $this->objFormParam->addParam("注文番号", "order_id"); |
---|
327 | $this->objFormParam->addParam("受注日", "create_date"); |
---|
328 | $this->objFormParam->addParam("発送日", "commit_date"); |
---|
329 | $this->objFormParam->addParam("備考", "message"); |
---|
330 | $this->objFormParam->addParam("入金日", "payment_date"); |
---|
331 | } |
---|
332 | |
---|
333 | /** |
---|
334 | * お届け先用フォームの初期化 |
---|
335 | */ |
---|
336 | function lfInitShippingParam(&$arrShipping) { |
---|
337 | $this->objFormParam->addParam("配送数", "shipping_quantity", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
338 | foreach ($arrShipping as $shipping) { |
---|
339 | $this->objFormParam->addParam("配送ID", "shipping_id_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
340 | $this->objFormParam->addParam("お名前1", "shipping_name01_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
341 | $this->objFormParam->addParam("お名前2", "shipping_name02_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
342 | $this->objFormParam->addParam("お名前(フリガナ・姓)", "shipping_kana01_" . $shipping['shipping_id'], STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
343 | $this->objFormParam->addParam("お名前(フリガナ・名)", "shipping_kana02_" . $shipping['shipping_id'], STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
344 | $this->objFormParam->addParam("郵便番号1", "shipping_zip01_" . $shipping['shipping_id'], ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
345 | $this->objFormParam->addParam("郵便番号2", "shipping_zip02_" . $shipping['shipping_id'], ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
346 | $this->objFormParam->addParam("都道府県", "shipping_pref_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
347 | $this->objFormParam->addParam("住所1", "shipping_addr01_" . $shipping['shipping_id'], MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
348 | $this->objFormParam->addParam("住所2", "shipping_addr02_" . $shipping['shipping_id'], MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
349 | $this->objFormParam->addParam("電話番号1", "shipping_tel01_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
350 | $this->objFormParam->addParam("電話番号2", "shipping_tel02_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
351 | $this->objFormParam->addParam("電話番号3", "shipping_tel03_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
352 | $this->objFormParam->addParam("お届け時間ID", "time_id_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
353 | $this->objFormParam->addParam("お届け時間", "shipping_time_" . $shipping['shipping_id']); |
---|
354 | $this->objFormParam->addParam("お届け日(年)", "shipping_date_year_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
355 | $this->objFormParam->addParam("お届け日(月)", "shipping_date_month_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
356 | $this->objFormParam->addParam("お届け日(日)", "shipping_date_day_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
357 | $this->objFormParam->addParam("お届け日", "shipping_date_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
358 | $this->objFormParam->addParam("配送商品規格数", "shipping_product_quantity_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
359 | foreach ($shipping['shipment_item'] as $productClassId => $item) { |
---|
360 | $this->objFormParam->addParam("商品規格ID", "product_class_id_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
361 | $this->objFormParam->addParam("商品コード", "product_code_" . $shipping['shipping_id'] . '_' . $productClassId); |
---|
362 | $this->objFormParam->addParam("商品名", "product_name_" . $shipping['shipping_id'] . '_' . $productClassId); |
---|
363 | $this->objFormParam->addParam("規格名1", "classcategory_name1_" . $shipping['shipping_id'] . '_' . $productClassId); |
---|
364 | $this->objFormParam->addParam("規格名2", "classcategory_name2_" . $shipping['shipping_id'] . '_' . $productClassId); |
---|
365 | $this->objFormParam->addParam("単価", "price_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
366 | $this->objFormParam->addParam("数量", "quantity_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
367 | } |
---|
368 | } |
---|
369 | } |
---|
370 | |
---|
371 | /** |
---|
372 | * 複数配送用フォームの初期化 |
---|
373 | */ |
---|
374 | function lfInitMultipleParam($size) { |
---|
375 | for ($i = 0; $i < $size; $i++) { |
---|
376 | $this->objFormParam->addParam("商品規格ID", "multiple_product_class_id" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
377 | $this->objFormParam->addParam("商品コード", "multiple_product_code" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
378 | $this->objFormParam->addParam("商品名", "multiple_product_name" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
379 | $this->objFormParam->addParam("規格1", "multiple_classcategory_name1" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
380 | $this->objFormParam->addParam("規格2", "multiple_classcategory_name2" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
381 | $this->objFormParam->addParam("単価", "multiple_price" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
382 | $this->objFormParam->addParam("数量", "multiple_quantity" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
383 | $this->objFormParam->addParam("配送先住所", "multiple_shipping" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
384 | } |
---|
385 | } |
---|
386 | |
---|
387 | |
---|
388 | function setMultipleItemTo($size) { |
---|
389 | $arrShipmentItem = array(); |
---|
390 | for ($i = 0; $i < $size; $i++) { |
---|
391 | $shippingId = $this->objFormParam->getValue('multiple_shipping' . $i); |
---|
392 | $productClassId = $this->objFormParam->getValue('multiple_product_class_id' . $i); |
---|
393 | |
---|
394 | $name = $this->objFormParam->getValue('multiple_product_name' . $i); |
---|
395 | $code = $this->objFormParam->getValue('multiple_product_code' . $i); |
---|
396 | $class1 = $this->objFormParam->getValue('multiple_classcategory_name1' . $i); |
---|
397 | $class2 = $this->objFormParam->getValue('multiple_classcategory_name2' . $i); |
---|
398 | $price = $this->objFormParam->getValue('multiple_price' . $i); |
---|
399 | $quantity = $this->objFormParam->getValue('multiple_quantity' . $i); |
---|
400 | |
---|
401 | $arrShipmentItem[$shippingId][$productClassId]['shipping_id'] = $shippingId; |
---|
402 | $arrShipmentItem[$shippingId][$productClassId]['product_class_id'] = $productClassId; |
---|
403 | $arrShipmentItem[$shippingId][$productClassId]['classcategory_name1'] = $class1; |
---|
404 | $arrShipmentItem[$shippingId][$productClassId]['classcategory_name2'] = $class2; |
---|
405 | $arrShipmentItem[$shippingId][$productClassId]['price'] = $price; |
---|
406 | $arrShipmentItem[$shippingId][$productClassId]['quantity'] += $quantity; |
---|
407 | } |
---|
408 | |
---|
409 | $arrQuantity = array(); |
---|
410 | $this->arrShippingIds = array(); |
---|
411 | $this->arrProductClassIds = array(); |
---|
412 | foreach ($arrShipmentItem as $shippingId => $items) { |
---|
413 | |
---|
414 | $this->objFormParam->setValue('shipping_product_quantity' . '_' . $shippingId, count($items)); |
---|
415 | |
---|
416 | $this->arrShippingIds[] = $shippingId; |
---|
417 | $this->arrProductClassIds[] = array_keys($items); |
---|
418 | |
---|
419 | foreach ($items as $productClassId => $item) { |
---|
420 | $arrQuantity[$productClassId] += $item['quantity']; |
---|
421 | foreach ($item as $itemKey => $itemVal) { |
---|
422 | $this->objFormParam->setValue($itemKey . '_' . $shippingId . '_' . $productClassId, $itemVal); |
---|
423 | } |
---|
424 | } |
---|
425 | } |
---|
426 | |
---|
427 | // 受注商品の数量を変更 |
---|
428 | $dest = array(); |
---|
429 | foreach ($arrQuantity as $productClassId => $quantity) { |
---|
430 | foreach ($this->arrForm['product_class_id'] as $n => $orderProductClassId) { |
---|
431 | if ($productClassId == $orderProductClassId) { |
---|
432 | $dest['quantity'][$n] = $quantity; |
---|
433 | } |
---|
434 | } |
---|
435 | } |
---|
436 | |
---|
437 | $this->objFormParam->setParam($dest); |
---|
438 | } |
---|
439 | |
---|
440 | function lfGetOrderData($order_id) { |
---|
441 | if(SC_Utils_Ex::sfIsInt($order_id)) { |
---|
442 | // DBから受注情報を読み込む |
---|
443 | $objQuery = new SC_Query(); |
---|
444 | $objDb = new SC_Helper_DB_Ex(); |
---|
445 | $where = "order_id = ?"; |
---|
446 | $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id)); |
---|
447 | $this->objFormParam->setParam($arrRet[0]); |
---|
448 | list($db_point, $rollback_point) = $objDb->sfGetRollbackPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']); |
---|
449 | $this->objFormParam->setValue('total_point', $db_point); |
---|
450 | $this->objFormParam->setValue('point', $rollback_point); |
---|
451 | $this->arrForm = $arrRet[0]; |
---|
452 | |
---|
453 | // 受注詳細データの取得 |
---|
454 | $arrRet = $this->lfGetOrderDetail($order_id); |
---|
455 | $arrRet = SC_Utils_Ex::sfSwapArray($arrRet); |
---|
456 | $this->arrForm = array_merge($this->arrForm, $arrRet); |
---|
457 | $this->objFormParam->setParam($arrRet); |
---|
458 | |
---|
459 | $this->arrShipping = $this->lfGetShippingData($order_id); |
---|
460 | $this->lfInitShippingParam($this->arrShipping); |
---|
461 | |
---|
462 | $this->objFormParam->setValue('shipping_quantity', count($this->arrShipping)); |
---|
463 | |
---|
464 | // 配送情報の処理 |
---|
465 | foreach ($this->arrShipping as $shipping) { |
---|
466 | |
---|
467 | $this->arrShippingIds[] = $shipping['shipping_id']; |
---|
468 | $this->arrProductClassIds[] = array_keys($shipping['shipment_item']); |
---|
469 | |
---|
470 | // お届け日の取得 |
---|
471 | if (!SC_Utils_Ex::isBlank($shipping["shipping_date"])) { |
---|
472 | $ts = strtotime($shipping["shipping_date"]); |
---|
473 | $this->objFormParam->setValue('shipping_date_year_' . $shipping['shipping_id'], date("Y", $ts)); |
---|
474 | $this->objFormParam->setValue('shipping_date_month_' . $shipping['shipping_id'], date("n", $ts)); |
---|
475 | $this->objFormParam->setValue('shipping_date_day_' . $shipping['shipping_id'], date("j", $ts)); |
---|
476 | } |
---|
477 | |
---|
478 | // 配送内容の処理 |
---|
479 | foreach ($shipping as $shippingKey => $shippingVal) { |
---|
480 | |
---|
481 | $this->objFormParam->setValue($shippingKey . '_' . $shipping['shipping_id'], $shippingVal); |
---|
482 | |
---|
483 | $this->objFormParam->setValue('shipping_product_quantity' . '_' . $shipping['shipping_id'], count($shipping['shipment_item'])); |
---|
484 | |
---|
485 | // 配送商品の処理 |
---|
486 | foreach ($shipping['shipment_item'] as $productClassId => $item) { |
---|
487 | foreach ($item as $itemKey => $itemVal) { |
---|
488 | $this->objFormParam->setValue($itemKey . '_' . $shipping['shipping_id'] . '_' . $productClassId, $itemVal); |
---|
489 | } |
---|
490 | } |
---|
491 | } |
---|
492 | } |
---|
493 | |
---|
494 | // その他支払い情報を表示 |
---|
495 | if($this->arrForm["memo02"] != "") $this->arrForm["payment_info"] = unserialize($this->arrForm["memo02"]); |
---|
496 | if($this->arrForm["memo01"] == PAYMENT_CREDIT_ID){ |
---|
497 | $this->arrForm["payment_type"] = "クレジット決済"; |
---|
498 | }elseif($this->arrForm["memo01"] == PAYMENT_CONVENIENCE_ID){ |
---|
499 | $this->arrForm["payment_type"] = "コンビニ決済"; |
---|
500 | }else{ |
---|
501 | $this->arrForm["payment_type"] = "お支払い"; |
---|
502 | } |
---|
503 | // 受注データを表示用配列に代入(各EC-CUBEバージョンと決済モジュールとのデータ連携保全のため) |
---|
504 | $this->arrDisp = $this->arrForm; |
---|
505 | } |
---|
506 | } |
---|
507 | |
---|
508 | // 受注詳細データの取得 |
---|
509 | function lfGetOrderDetail($order_id) { |
---|
510 | $objQuery = new SC_Query(); |
---|
511 | $col = "T1.product_id, T1.product_class_id, T1.product_name, " |
---|
512 | . "T1.product_code, T1.classcategory_name1, T1.classcategory_name2, " |
---|
513 | . "T1.price, T1.quantity, T1.point_rate, T2.product_type_id"; |
---|
514 | $from = <<< __EOS__ |
---|
515 | dtb_order_detail T1 |
---|
516 | JOIN dtb_products_class T2 |
---|
517 | ON T1.product_class_id = T2.product_class_id |
---|
518 | __EOS__; |
---|
519 | $arrRet = $objQuery->select($col, $from, |
---|
520 | "order_id = ?", array($order_id)); |
---|
521 | return $arrRet; |
---|
522 | } |
---|
523 | |
---|
524 | /** |
---|
525 | * 配送情報の取得. |
---|
526 | * TODO リファクタリング |
---|
527 | */ |
---|
528 | function lfGetShippingData($orderId) { |
---|
529 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
530 | $objProduct = new SC_Product(); |
---|
531 | $objQuery->setOrder('shipping_id'); |
---|
532 | $arrRet = $objQuery->select("*", "dtb_shipping", "order_id = ?", array($orderId)); |
---|
533 | foreach (array_keys($arrRet) as $key) { |
---|
534 | $objQuery->setOrder('shipping_id'); |
---|
535 | $arrItems = $objQuery->select("*", "dtb_shipment_item", "order_id = ? AND shipping_id = ?", |
---|
536 | array($orderId, $arrRet[$key]['shipping_id'])); |
---|
537 | foreach ($arrItems as $itemKey => $arrDetail) { |
---|
538 | foreach ($arrDetail as $detailKey => $detailVal) { |
---|
539 | $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']][$detailKey] = $detailVal; |
---|
540 | } |
---|
541 | |
---|
542 | $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']]['productsClass'] =& $objProduct->getDetailAndProductsClass($arrDetail['product_class_id']); |
---|
543 | } |
---|
544 | } |
---|
545 | return $arrRet; |
---|
546 | } |
---|
547 | |
---|
548 | /* 入力内容のチェック */ |
---|
549 | function lfCheckError() { |
---|
550 | // 入力データを渡す。 |
---|
551 | $arrRet = $this->objFormParam->getHashArray(); |
---|
552 | $objErr = new SC_CheckError($arrRet); |
---|
553 | $objErr->arrErr = $this->objFormParam->checkError(); |
---|
554 | |
---|
555 | if (count($objErr->arrErr) >= 1) { |
---|
556 | return $objErr->arrErr; |
---|
557 | } |
---|
558 | |
---|
559 | return $this->lfCheek(); |
---|
560 | } |
---|
561 | |
---|
562 | /* 計算処理 */ |
---|
563 | function lfCheek() { |
---|
564 | $objDb = new SC_Helper_DB_Ex(); |
---|
565 | $arrVal = $this->objFormParam->getHashArray(); |
---|
566 | $arrErr = array(); |
---|
567 | |
---|
568 | // 商品の種類数 |
---|
569 | $max = count($arrVal['quantity']); |
---|
570 | $subtotal = 0; |
---|
571 | $totalpoint = 0; |
---|
572 | $totaltax = 0; |
---|
573 | for($i = 0; $i < $max; $i++) { |
---|
574 | // 小計の計算 |
---|
575 | $subtotal += SC_Helper_DB_Ex::sfCalcIncTax($arrVal['price'][$i]) * $arrVal['quantity'][$i]; |
---|
576 | // 小計の計算 |
---|
577 | $totaltax += SC_Helper_DB_Ex::sfTax($arrVal['price'][$i]) * $arrVal['quantity'][$i]; |
---|
578 | // 加算ポイントの計算 |
---|
579 | $totalpoint += SC_Utils_Ex::sfPrePoint($arrVal['price'][$i], $arrVal['point_rate'][$i]) * $arrVal['quantity'][$i]; |
---|
580 | } |
---|
581 | |
---|
582 | // 消費税 |
---|
583 | $arrVal['tax'] = $totaltax; |
---|
584 | // 小計 |
---|
585 | $arrVal['subtotal'] = $subtotal; |
---|
586 | // 合計 |
---|
587 | $arrVal['total'] = $subtotal - $arrVal['discount'] + $arrVal['deliv_fee'] + $arrVal['charge']; |
---|
588 | // お支払い合計 |
---|
589 | $arrVal['payment_total'] = $arrVal['total'] - ($arrVal['use_point'] * POINT_VALUE); |
---|
590 | |
---|
591 | // 加算ポイント |
---|
592 | $arrVal['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($totalpoint, $arrVal['use_point']); |
---|
593 | |
---|
594 | // 最終保持ポイント |
---|
595 | $arrVal['total_point'] = $this->objFormParam->getValue('point') - $arrVal['use_point'] + $arrVal['add_point']; |
---|
596 | |
---|
597 | if ($arrVal['total'] < 0) { |
---|
598 | $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />'; |
---|
599 | } |
---|
600 | |
---|
601 | if ($arrVal['payment_total'] < 0) { |
---|
602 | $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />'; |
---|
603 | } |
---|
604 | //新規追加受注のみ |
---|
605 | if ($_POST['mode'] == "add") { |
---|
606 | if ($arrVal['total_point'] < 0) { |
---|
607 | $arrErr['use_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />'; |
---|
608 | } |
---|
609 | } |
---|
610 | |
---|
611 | $this->objFormParam->setParam($arrVal); |
---|
612 | return $arrErr; |
---|
613 | } |
---|
614 | |
---|
615 | /** |
---|
616 | * DB更新処理 |
---|
617 | * |
---|
618 | * TODO リファクタリング |
---|
619 | * |
---|
620 | * @param integer $order_id 注文番号 |
---|
621 | * @return void |
---|
622 | */ |
---|
623 | function lfRegistData($order_id) { |
---|
624 | $objQuery = new SC_Query(); |
---|
625 | |
---|
626 | $sqlval = $this->lfMakeSqlvalForDtbOrder(); |
---|
627 | |
---|
628 | $where = "order_id = ?"; |
---|
629 | |
---|
630 | $objQuery->begin(); |
---|
631 | |
---|
632 | // 受注.対応状況の更新 |
---|
633 | SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, $sqlval['status'], $sqlval['add_point'], $sqlval['use_point']); |
---|
634 | unset($sqlval['status']); |
---|
635 | unset($sqlval['add_point']); |
---|
636 | unset($sqlval['use_point']); |
---|
637 | |
---|
638 | // 受注テーブルの更新 |
---|
639 | $this->registerOrder($sqlval, $order_id); |
---|
640 | |
---|
641 | // 受注テーブルの名称列を更新 |
---|
642 | //SC_Helper_DB_Ex::sfUpdateOrderNameCol($order_id); |
---|
643 | |
---|
644 | $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_class_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_name1", "classcategory_name2")); |
---|
645 | |
---|
646 | |
---|
647 | // 変更しようとしている商品情報とDBに登録してある商品情報を比較することで、更新すべき数量を計算 |
---|
648 | $max = count($arrDetail); |
---|
649 | $k = 0; |
---|
650 | $arrStockData = array(); |
---|
651 | for($i = 0; $i < $max; $i++) { |
---|
652 | if (!empty($arrDetail[$i]['product_id'])) { |
---|
653 | $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ? AND product_class_id = ?", array($order_id, $arrDetail[$i]['product_class_id'])); |
---|
654 | if (!empty($arrPreDetail) && $arrPreDetail[0]['quantity'] != $arrDetail[$i]['quantity']) { |
---|
655 | // 数量が変更された商品 |
---|
656 | $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id']; |
---|
657 | $arrStockData[$k]['quantity'] = $arrPreDetail[0]['quantity'] - $arrDetail[$i]['quantity']; |
---|
658 | ++$k; |
---|
659 | } elseif (empty($arrPreDetail)) { |
---|
660 | // 新しく追加された商品 もしくは 違う商品に変更された商品 |
---|
661 | $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id']; |
---|
662 | $arrStockData[$k]['quantity'] = -$arrDetail[$i]['quantity']; |
---|
663 | ++$k; |
---|
664 | } |
---|
665 | $objQuery->delete("dtb_order_detail", "order_id = ? AND product_class_id = ?", array($order_id, $arrDetail[$i]['product_class_id'])); |
---|
666 | } |
---|
667 | } |
---|
668 | |
---|
669 | // 上記の新しい商品のループでDELETEされなかった商品は、注文より削除された商品 |
---|
670 | $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ?", array($order_id)); |
---|
671 | foreach ($arrPreDetail AS $key=>$val) { |
---|
672 | $arrStockData[$k]['product_class_id'] = $val['product_class_id']; |
---|
673 | $arrStockData[$k]['quantity'] = $val['quantity']; |
---|
674 | ++$k; |
---|
675 | } |
---|
676 | |
---|
677 | // 受注詳細データの初期化 |
---|
678 | $objQuery->delete("dtb_order_detail", $where, array($order_id)); |
---|
679 | |
---|
680 | // 受注詳細データの更新 |
---|
681 | $max = count($arrDetail); |
---|
682 | for ($i = 0; $i < $max; $i++) { |
---|
683 | $sqlval = array(); |
---|
684 | $sqlval['order_id'] = $order_id; |
---|
685 | $sqlval['product_id'] = $arrDetail[$i]['product_id']; |
---|
686 | $sqlval['product_class_id'] = $arrDetail[$i]['product_class_id']; |
---|
687 | $sqlval['product_code'] = $arrDetail[$i]['product_code']; |
---|
688 | $sqlval['product_name'] = $arrDetail[$i]['product_name']; |
---|
689 | $sqlval['price'] = $arrDetail[$i]['price']; |
---|
690 | $sqlval['quantity'] = $arrDetail[$i]['quantity']; |
---|
691 | $sqlval['point_rate'] = $arrDetail[$i]['point_rate']; |
---|
692 | $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1']; |
---|
693 | $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2']; |
---|
694 | $objQuery->insert("dtb_order_detail", $sqlval); |
---|
695 | } |
---|
696 | |
---|
697 | // 在庫数調整 |
---|
698 | $status = $sqlval['status']; |
---|
699 | if (ORDER_DELIV != $status && ORDER_CANCEL != $status) { |
---|
700 | $stock_sql = "UPDATE dtb_products_class SET stock = stock + ? WHERE product_class_id = ?"; |
---|
701 | foreach ($arrStockData AS $key=>$val) { |
---|
702 | $stock_sqlval = array(); |
---|
703 | $stock_sqlval[] = $val['quantity']; |
---|
704 | $stock_sqlval[] = $val['product_class_id']; |
---|
705 | |
---|
706 | $objQuery->query($stock_sql, $stock_sqlval); |
---|
707 | } |
---|
708 | } |
---|
709 | |
---|
710 | // 配送情報の初期化 |
---|
711 | // FIXME UPDATE/INSERT にする |
---|
712 | $objQuery->delete('dtb_shipping', "order_id = ?", array($order_id)); |
---|
713 | $objQuery->delete('dtb_shipment_item', "order_id = ?", array($order_id)); |
---|
714 | |
---|
715 | $arrParams = $this->objFormParam->getHashArray(); |
---|
716 | // 配送ID の配列を取得 |
---|
717 | $shippingIds = array(); |
---|
718 | foreach (array_keys($arrParams) as $key) { |
---|
719 | if (preg_match('/^shipping_id_/', $key)) { |
---|
720 | $shippingIds[] = $arrParams[$key]; |
---|
721 | } |
---|
722 | } |
---|
723 | |
---|
724 | $cols = $objQuery->listTableFields('dtb_shipping'); |
---|
725 | foreach ($shippingIds as $shipping_id) { |
---|
726 | |
---|
727 | $arrParams['shipping_date_' . $shipping_id] = SC_Utils_Ex::sfGetTimestamp($arrParams['shipping_date_year_' . $shipping_id], |
---|
728 | $arrParams['shipping_date_month_' . $shipping_id], |
---|
729 | $arrParams['shipping_date_day_' . $shipping_id]); |
---|
730 | $dest = array(); |
---|
731 | foreach ($arrParams as $key => $val) { |
---|
732 | $key = preg_replace('/_' . $shipping_id . '$/', '', $key); |
---|
733 | if (in_array($key, $cols)) { |
---|
734 | $dest[$key] = $val; |
---|
735 | } |
---|
736 | } |
---|
737 | $dest['shipping_id'] = $shipping_id; |
---|
738 | $dest['order_id'] = $order_id; |
---|
739 | $dest['create_date'] = 'Now()'; |
---|
740 | $dest['update_date'] = 'Now()'; |
---|
741 | $objQuery->insert('dtb_shipping', $dest); |
---|
742 | |
---|
743 | // 商品規格ID の配列を取得 |
---|
744 | $productClassIds = array(); |
---|
745 | foreach (array_keys($arrParams) as $key) { |
---|
746 | if (preg_match('/^product_class_id_' . $shipping_id . '_/', $key)) { |
---|
747 | $productClassIds[] = $arrParams[$key]; |
---|
748 | } |
---|
749 | } |
---|
750 | |
---|
751 | foreach ($productClassIds as $product_class_id) { |
---|
752 | $item['shipping_id'] = $shipping_id; |
---|
753 | $item['order_id'] = $order_id; |
---|
754 | $item['product_class_id'] = $product_class_id; |
---|
755 | $item['product_name'] = $arrParams['product_name_' . $shipping_id . '_' . $product_class_id]; |
---|
756 | $item['product_code'] = $arrParams['product_code_' . $shipping_id . '_' . $product_class_id]; |
---|
757 | $item['classcategory_name1'] = $arrParams['classcategory_name1_' . $shipping_id . '_' . $product_class_id]; |
---|
758 | $item['classcategory_name2'] = $arrParams['classcategory_name2_' . $shipping_id . '_' . $product_class_id]; |
---|
759 | $item['price'] = $arrParams['price_' . $shipping_id . '_' . $product_class_id]; |
---|
760 | $item['quantity'] = $arrParams['quantity_' . $shipping_id . '_' . $product_class_id]; |
---|
761 | $objQuery->insert("dtb_shipment_item", $item); |
---|
762 | } |
---|
763 | } |
---|
764 | $objQuery->commit(); |
---|
765 | } |
---|
766 | |
---|
767 | /** |
---|
768 | * DB登録処理 |
---|
769 | * |
---|
770 | * @return integer 注文番号 |
---|
771 | */ |
---|
772 | function lfRegistNewData() { |
---|
773 | $objQuery = new SC_Query(); |
---|
774 | |
---|
775 | $sqlval = $this->lfMakeSqlvalForDtbOrder(); |
---|
776 | |
---|
777 | // ポイントは別登録 |
---|
778 | $addPoint = $sqlval['add_point']; |
---|
779 | $usePoint = $sqlval['use_point']; |
---|
780 | $sqlval['add_point'] = 0; |
---|
781 | $sqlval['use_point'] = 0; |
---|
782 | |
---|
783 | // customer_id |
---|
784 | if ($sqlval["customer_id"] == "") { |
---|
785 | $sqlval['customer_id'] = '0'; |
---|
786 | } |
---|
787 | |
---|
788 | $sqlval['create_date'] = 'Now()'; // 受注日 |
---|
789 | |
---|
790 | $objQuery->begin(); |
---|
791 | |
---|
792 | // 受注テーブルの登録 |
---|
793 | $order_id = $objQuery->nextVal('dtb_order_order_id'); |
---|
794 | $sqlval['order_id'] = $order_id; |
---|
795 | $objQuery->insert("dtb_order", $sqlval); |
---|
796 | |
---|
797 | |
---|
798 | // 受注.対応状況の更新 |
---|
799 | SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, null, $addPoint, $usePoint); |
---|
800 | |
---|
801 | // 受注テーブルの名称列を更新 |
---|
802 | SC_Helper_DB_Ex::sfUpdateOrderNameCol($order_id); |
---|
803 | |
---|
804 | // 受注詳細データの更新 |
---|
805 | $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_class_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_name1", "classcategory_name2")); |
---|
806 | $objQuery->delete("dtb_order_detail", 'order_id = ?', array($order_id)); |
---|
807 | |
---|
808 | $max = count($arrDetail); |
---|
809 | for ($i = 0; $i < $max; $i++) { |
---|
810 | $sqlval = array(); |
---|
811 | $sqlval['order_id'] = $order_id; |
---|
812 | $sqlval['product_id'] = $arrDetail[$i]['product_id']; |
---|
813 | $sqlval['product_class_id'] = $arrDetail[$i]['product_class_id']; |
---|
814 | $sqlval['product_code'] = $arrDetail[$i]['product_code']; |
---|
815 | $sqlval['product_name'] = $arrDetail[$i]['product_name']; |
---|
816 | $sqlval['price'] = $arrDetail[$i]['price']; |
---|
817 | $sqlval['quantity'] = $arrDetail[$i]['quantity']; |
---|
818 | $sqlval['point_rate'] = $arrDetail[$i]['point_rate']; |
---|
819 | $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1']; |
---|
820 | $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2']; |
---|
821 | |
---|
822 | $objQuery->insert("dtb_order_detail", $sqlval); |
---|
823 | |
---|
824 | |
---|
825 | // 在庫数減少処理 |
---|
826 | // 現在の実在庫数取得 |
---|
827 | $pre_stock = $objQuery->getOne("SELECT stock FROM dtb_products_class WHERE product_class_id = ?", array($arrDetail[$i]['product_class_id'])); |
---|
828 | |
---|
829 | $stock_sqlval = array(); |
---|
830 | $stock_sqlval['stock'] = intval($pre_stock - $arrDetail[$i]['quantity']); |
---|
831 | if ($stock_sqlval['stock'] === 0) { |
---|
832 | $stock_sqlval['stock'] = '0'; |
---|
833 | } |
---|
834 | |
---|
835 | $st_params = array(); |
---|
836 | $st_params[] = $arrDetail[$i]['product_class_id']; |
---|
837 | |
---|
838 | $objQuery->update("dtb_products_class", $stock_sqlval, 'product_class_id = ?', $st_params); |
---|
839 | } |
---|
840 | $objQuery->commit(); |
---|
841 | |
---|
842 | return $order_id; |
---|
843 | } |
---|
844 | |
---|
845 | /** |
---|
846 | * 受注を登録する |
---|
847 | */ |
---|
848 | function registerOrder($sqlval, $order_id) { |
---|
849 | $table = 'dtb_order'; |
---|
850 | $objQuery = SC_Query::getSingletonInstance(); |
---|
851 | $cols = $objQuery->listTableFields($table); |
---|
852 | $dest = array(); |
---|
853 | foreach ($sqlval as $key => $val) { |
---|
854 | if (in_array($key, $cols)) { |
---|
855 | $dest[$key] = $val; |
---|
856 | } |
---|
857 | } |
---|
858 | |
---|
859 | $exists = $objQuery->count("dtb_order", "order_id = ?", array($order_id)); |
---|
860 | if ($exists > 0) { |
---|
861 | $objQuery->update($table, $dest, "order_id = ?", array($order_id)); |
---|
862 | } else { |
---|
863 | // TODO |
---|
864 | $dest['order_id'] = $order_id; |
---|
865 | $result = $objQuery->insert($table, $dest); |
---|
866 | } |
---|
867 | } |
---|
868 | |
---|
869 | function lfInsertProduct($product_class_id) { |
---|
870 | $objProduct = new SC_Product(); |
---|
871 | $arrProduct = $this->lfGetProductsClass($objProduct->getDetailAndProductsClass($product_class_id)); |
---|
872 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
873 | $existes = false; |
---|
874 | $existes_key = NULL; |
---|
875 | // 既に同じ商品がないか、確認する |
---|
876 | if (!empty($this->arrForm['product_class_id']['value'])) { |
---|
877 | foreach ($this->arrForm['product_class_id']['value'] AS $key=>$val) { |
---|
878 | // 既に同じ商品がある場合 |
---|
879 | if ($val == $product_class_id) { |
---|
880 | $existes = true; |
---|
881 | $existes_key = $key; |
---|
882 | } |
---|
883 | } |
---|
884 | } |
---|
885 | |
---|
886 | if ($existes) { |
---|
887 | // 既に同じ商品がある場合 |
---|
888 | ++$this->arrForm['quantity']['value'][$existes_key]; |
---|
889 | } else { |
---|
890 | // 既に同じ商品がない場合 |
---|
891 | $this->lfSetProductData($arrProduct); |
---|
892 | } |
---|
893 | } |
---|
894 | |
---|
895 | function lfUpdateProduct($product_class_id, $no) { |
---|
896 | $objProduct = new SC_Product(); |
---|
897 | $arrProduct = $this->lfGetProductsClass($objProduct->getDetailAndProductsClass($product_class_id)); |
---|
898 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
899 | $this->lfSetProductData($arrProduct, $no); |
---|
900 | } |
---|
901 | |
---|
902 | function lfSetProductData($arrProduct, $no = null) { |
---|
903 | foreach ($arrProduct AS $key=>$val) { |
---|
904 | if (!is_array($this->arrForm[$key]['value'])) { |
---|
905 | unset($this->arrForm[$key]['value']); |
---|
906 | } |
---|
907 | if ($no === null) { |
---|
908 | $this->arrForm[$key]['value'][] = $val; |
---|
909 | } else { |
---|
910 | $this->arrForm[$key]['value'][$no] = $val; |
---|
911 | } |
---|
912 | } |
---|
913 | } |
---|
914 | |
---|
915 | function lfGetProductsClass($productsClass) { |
---|
916 | $arrProduct['price'] = $productsClass['price02']; |
---|
917 | $arrProduct['quantity'] = 1; |
---|
918 | $arrProduct['product_id'] = $productsClass['product_id']; |
---|
919 | $arrProduct['product_class_id'] = $productsClass['product_class_id']; |
---|
920 | $arrProduct['point_rate'] = $productsClass['point_rate']; |
---|
921 | $arrProduct['product_code'] = $productsClass['product_code']; |
---|
922 | $arrProduct['product_name'] = $productsClass['name']; |
---|
923 | $arrProduct['classcategory_name1'] = $productsClass['classcategory_name1']; |
---|
924 | $arrProduct['classcategory_name2'] = $productsClass['classcategory_name2']; |
---|
925 | |
---|
926 | return $arrProduct; |
---|
927 | } |
---|
928 | |
---|
929 | |
---|
930 | /** |
---|
931 | * 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する |
---|
932 | * @param int $edit_customer_id 顧客ID |
---|
933 | */ |
---|
934 | function lfSetCustomerInfo($edit_customer_id = ""){ |
---|
935 | // 顧客IDが指定されている場合のみ、処理を実行する |
---|
936 | if( $edit_customer_id === "" ) return ; |
---|
937 | |
---|
938 | // 検索で選択された顧客IDが入力されている場合 |
---|
939 | if( is_null($edit_customer_id) === false && 0 < strlen($edit_customer_id) && SC_Utils_Ex::sfIsInt($edit_customer_id) ){ |
---|
940 | $objQuery = new SC_Query(); |
---|
941 | |
---|
942 | // 顧客情報を取得する |
---|
943 | $arrCustomerInfo = $objQuery->select('*', 'dtb_customer', 'customer_id = ? AND del_flg = 0', array($edit_customer_id)); |
---|
944 | |
---|
945 | // 顧客情報を取得する事が出来たら、テンプレートに値を渡す |
---|
946 | if( 0 < count($arrCustomerInfo) && is_array($arrCustomerInfo) === true){ |
---|
947 | // カラム名にorder_を付ける(テンプレート側でorder_がついている為 |
---|
948 | foreach($arrCustomerInfo[0] as $index=>$customer_info){ |
---|
949 | // customer_idにはorder_を付けないようにする |
---|
950 | $order_index = ($index == 'customer_id') ? $index : 'order_'.$index; |
---|
951 | $arrCustomer[$order_index] = $customer_info; |
---|
952 | } |
---|
953 | } |
---|
954 | |
---|
955 | // hiddenに渡す |
---|
956 | $this->edit_customer_id = $edit_customer_id; |
---|
957 | |
---|
958 | // 受注日に現在の時刻を取得し、表示させる |
---|
959 | $create_date = $objQuery->getAll('SELECT now() as create_date;'); |
---|
960 | $arrCustomer['create_date'] = $create_date[0]['create_date']; |
---|
961 | |
---|
962 | // 情報上書き |
---|
963 | $this->objFormParam->setParam($arrCustomer); |
---|
964 | // 入力値の変換 |
---|
965 | $this->objFormParam->convParam(); |
---|
966 | } |
---|
967 | } |
---|
968 | |
---|
969 | /** |
---|
970 | * 受注テーブルの登録・更新用データの共通部分を作成する |
---|
971 | * |
---|
972 | * @return array |
---|
973 | */ |
---|
974 | function lfMakeSqlvalForDtbOrder() { |
---|
975 | |
---|
976 | // 入力データを取得する |
---|
977 | $sqlval = $this->objFormParam->getHashArray(); |
---|
978 | foreach ($sqlval as $key => $val) { |
---|
979 | // 配列は登録しない |
---|
980 | if (is_array($val)) { |
---|
981 | unset($sqlval[$key]); |
---|
982 | } |
---|
983 | } |
---|
984 | |
---|
985 | // 受注テーブルに書き込まない列を除去 |
---|
986 | unset($sqlval['total_point']); |
---|
987 | unset($sqlval['point']); |
---|
988 | unset($sqlval['commit_date']); |
---|
989 | |
---|
990 | // 更新日時 |
---|
991 | $sqlval['update_date'] = 'Now()'; |
---|
992 | |
---|
993 | return $sqlval; |
---|
994 | } |
---|
995 | } |
---|
996 | ?> |
---|