source: branches/version-2_12-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_DeliveryInput.php @ 22537

Revision 22537, 12.1 KB checked in by pineray, 11 years ago (diff)

pageクラスからdtb_paymentテーブルを直接指定している箇所をなくす

以下のファイルが残っている.
LC_Page_Shopping_LoadPaymentModule.php
LC_Page_Admin_Home.php

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
RevLine 
[15297]1<?php
2/*
[16582]3 * This file is part of EC-CUBE
4 *
[22206]5 * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved.
[15297]6 *
7 * http://www.lockon.co.jp/
[16582]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.
[15297]22 */
23
24// {{{ requires
[20534]25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
[15297]26
27/**
[20911]28 * 配送方法設定 のページクラス.
[15297]29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
[20543]34class LC_Page_Admin_Basis_DeliveryInput extends LC_Page_Admin_Ex {
[15297]35    // }}}
36    // {{{ functions
37
38    /**
39     * Page を初期化する.
40     *
41     * @return void
42     */
43    function init() {
44        parent::init();
45        $this->tpl_mainpage = 'basis/delivery_input.tpl';
46        $this->tpl_subno = 'delivery';
47        $this->tpl_mainno = 'basis';
48        $masterData = new SC_DB_MasterData_Ex();
[19773]49        $this->arrPref = $masterData->getMasterData('mtb_pref');
[21481]50        $this->arrProductType = $masterData->getMasterData('mtb_product_type');
[22537]51        $this->arrPayments = SC_Helper_Payment_Ex::getIDValueList();
[20911]52        $this->tpl_maintitle = '基本情報管理';
53        $this->tpl_subtitle = '配送方法設定';
[20041]54        $this->mode = $this->getMode();
[15297]55    }
56
57    /**
58     * Page のプロセス.
59     *
60     * @return void
61     */
62    function process() {
[19661]63        $this->action();
64        $this->sendResponse();
65    }
66
67    /**
68     * Page のアクション.
69     *
70     * @return void
71     */
72    function action() {
[21592]73
[20307]74        $this->lfInitParam($this->mode, $objFormParam);
75        $objFormParam->setParam($_POST);
76
[18335]77        // 入力値の変換
[20307]78        $objFormParam->convParam();
79        $this->arrErr = $this->lfCheckError($objFormParam);
[15297]80
[18335]81        switch ($this->mode) {
82            case 'edit':
83                if (count($this->arrErr) == 0) {
[20307]84                    $objFormParam->setValue('deliv_id', $this->lfRegistData($objFormParam->getHashArray(), $_SESSION['member_id']));
[20911]85                    $this->tpl_onload = "window.alert('配送方法設定が完了しました。');";
[18335]86                }
87                break;
88            case 'pre_edit':
89                if (count($this->arrErr) > 0) {
[21582]90                    trigger_error('', E_USER_ERROR);
[18335]91                }
[20307]92                $this->lfGetDelivData($objFormParam);
[18335]93                break;
94            default:
95                break;
[15297]96        }
97
[20307]98        $this->arrForm = $objFormParam->getFormParamList();
[21592]99
[15297]100    }
101
102    /**
103     * デストラクタ.
104     *
105     * @return void
106     */
107    function destroy() {
108        parent::destroy();
109    }
110
[20970]111    /* パラメーター情報の初期化 */
[20307]112    function lfInitParam($mode, &$objFormParam) {
[21645]113        $objFormParam = new SC_FormParam_Ex();
[15297]114
[18335]115        switch ($mode) {
116            case 'edit':
[20307]117                $objFormParam->addParam('配送業者ID', 'deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
[21514]118                $objFormParam->addParam('配送業者名', 'name', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
119                $objFormParam->addParam('名称', 'service_name', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
120                $objFormParam->addParam('説明', 'remark', LLTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
[21515]121                $objFormParam->addParam('伝票No.確認URL', 'confirm_url', URL_LEN, 'n', array('URL_CHECK', 'MAX_LENGTH_CHECK'), 'http://');
[21514]122                $objFormParam->addParam('取扱商品種別', 'product_type_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
123                $objFormParam->addParam('取扱支払方法', 'payment_ids', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
[18335]124
[21441]125                for ($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
[21480]126                    $objFormParam->addParam("お届け時間$cnt", "deliv_time$cnt", STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
[18335]127                }
128
[21441]129                if (INPUT_DELIV_FEE) {
130                    for ($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
[21480]131                        $objFormParam->addParam("配送料金$cnt", "fee$cnt", PRICE_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
[18335]132                    }
133                }
134                break;
135
136            case 'pre_edit':
[20307]137                $objFormParam->addParam('配送業者ID', 'deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
[18335]138                break;
139
140            default:
141                break;
[15297]142        }
143    }
144
[17580]145    /**
146     * 配送情報を登録する
147     *
[20041]148     * @return $deliv_id
[17580]149     */
[20307]150    function lfRegistData($arrRet, $member_id) {
[20507]151        $objQuery =& SC_Query_Ex::getSingletonInstance();
[15297]152        $objQuery->begin();
153
154        // 入力データを渡す。
155        $sqlval['name'] = $arrRet['name'];
156        $sqlval['service_name'] = $arrRet['service_name'];
[20070]157        $sqlval['remark'] = $arrRet['remark'];
[15297]158        $sqlval['confirm_url'] = $arrRet['confirm_url'];
[19686]159        $sqlval['product_type_id'] = $arrRet['product_type_id'];
[20307]160        $sqlval['creator_id'] = $member_id;
[21185]161        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
[15297]162
[17580]163        // deliv_id が決まっていた場合
[21514]164        if ($arrRet['deliv_id'] != '') {
[20307]165            $deliv_id = $arrRet['deliv_id'];
[21514]166            $where = 'deliv_id = ?';
[21481]167            $objQuery->update('dtb_deliv', $sqlval, $where, array($deliv_id));
[17580]168
[18235]169            // お届け時間の登録
[21481]170            $table = 'dtb_delivtime';
[21514]171            $where = 'deliv_id = ? AND time_id = ?';
[21441]172            for ($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
[17580]173                $sqlval = array();
[21481]174                $keyname = 'deliv_time'.$cnt;
[21563]175                $arrWhereVal = array($deliv_id, $cnt);
[17580]176                // 既存データの有無を確認
[21563]177                $curData = $objQuery->select('*', $table, $where, $arrWhereVal);
[17580]178
[21514]179                if (strcmp($arrRet[$keyname], '') != 0) {
[17580]180                    $sqlval['deliv_time'] = $arrRet[$keyname];
181
182                    // 入力が空ではなく、DBに情報があれば更新
[21441]183                    if (count($curData)) {
[21563]184                        $objQuery->update($table, $sqlval, $where, $arrWhereVal);
[17580]185                    }
186                    // DBに情報がなければ登録
187                    else {
188                        $sqlval['deliv_id'] = $deliv_id;
[18023]189                        $sqlval['time_id'] = $cnt;
[17580]190                        $objQuery->insert($table, $sqlval);
191                    }
192                }
193                // 入力が空で、DBに情報がある場合は削除
[21441]194                else if (count($curData)) {
[21563]195                    $objQuery->delete($table, $where, $arrWhereVal);
[17580]196                }
197            }
198
199            // 配送料の登録
[21441]200            if (INPUT_DELIV_FEE) {
201                for ($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
[20538]202                    $keyname = 'fee'.$cnt;
[21514]203                    if (strcmp($arrRet[$keyname], '') != 0) {
[17580]204                        $sqlval = array('fee' => $arrRet[$keyname]);
[21514]205                        $objQuery->update('dtb_delivfee', $sqlval, 'deliv_id = ? AND fee_id = ?', array($deliv_id, $cnt));
[17580]206                    }
207                }
208            }
[21441]209        } else {
[15297]210            // 登録する配送業者IDの取得
[18788]211            $deliv_id = $objQuery->nextVal('dtb_deliv_deliv_id');
212            $sqlval['deliv_id'] = $deliv_id;
[21481]213            $sqlval['rank'] = $objQuery->max('rank', 'dtb_deliv') + 1;
[21185]214            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
[15297]215            // INSERTの実行
[21481]216            $objQuery->insert('dtb_deliv', $sqlval);
[15297]217
218            $sqlval = array();
[18235]219            // お届け時間の設定
[21441]220            for ($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
[17580]221                $keyname = "deliv_time$cnt";
[21514]222                if ($arrRet[$keyname] != '') {
[15297]223                    $sqlval['deliv_id'] = $deliv_id;
[18023]224                    $sqlval['time_id'] = $cnt;
[17580]225                    $sqlval['deliv_time'] = $arrRet[$keyname];
[15297]226                    // INSERTの実行
[21481]227                    $objQuery->insert('dtb_delivtime', $sqlval);
[15297]228                }
229            }
[17580]230
[21441]231            if (INPUT_DELIV_FEE) {
[17580]232                $sqlval = array();
233                // 配送料金の設定
[21441]234                for ($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
[17580]235                    $keyname = "fee$cnt";
[21514]236                    if ($arrRet[$keyname] != '') {
[17580]237                        $sqlval['deliv_id'] = $deliv_id;
238                        $sqlval['fee'] = $arrRet[$keyname];
239                        $sqlval['pref'] = $cnt;
240                        // INSERTの実行
[19686]241                        $sqlval['fee_id'] = $cnt;
[21481]242                        $objQuery->insert('dtb_delivfee', $sqlval);
[17580]243                    }
244                }
245            }
[15297]246        }
[20069]247
[20307]248        $objQuery->delete('dtb_payment_options', 'deliv_id = ?', array($arrRet['deliv_id']));
[20069]249        $sqlval = array();
250        $i = 1;
251        foreach ($arrRet['payment_ids'] as $val) {
252            $sqlval['deliv_id'] = $deliv_id;
253            $sqlval['payment_id'] = $val;
254            $sqlval['rank'] = $i;
255            $objQuery->insert('dtb_payment_options', $sqlval);
256            $i++;
257        }
[15297]258        $objQuery->commit();
259        return $deliv_id;
260    }
261
262    /* 配送業者情報の取得 */
[20307]263    function lfGetDelivData(&$objFormParam) {
[20507]264        $objQuery =& SC_Query_Ex::getSingletonInstance();
[18335]265
[20307]266        $deliv_id = $objFormParam->getValue('deliv_id');
267
[20970]268        // パラメーター情報の初期化
[20307]269        $this->lfInitParam('edit', $objFormParam);
[18335]270
[15297]271        // 配送業者一覧の取得
[21514]272        $col = 'deliv_id, name, service_name, remark, confirm_url, product_type_id';
273        $where = 'deliv_id = ?';
[21481]274        $table = 'dtb_deliv';
[15297]275        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
[20307]276        $objFormParam->setParam($arrRet[0]);
[18235]277        // お届け時間の取得
[21481]278        $col = 'deliv_time';
[21514]279        $where = 'deliv_id = ?  ORDER BY time_id';
[21481]280        $table = 'dtb_delivtime';
[15297]281        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
[20307]282        $objFormParam->setParamList($arrRet, 'deliv_time');
[15297]283        // 配送料金の取得
[20538]284        $col = 'fee';
[21514]285        $where = 'deliv_id = ? ORDER BY pref';
[21481]286        $table = 'dtb_delivfee';
[15297]287        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
[20307]288        $objFormParam->setParamList($arrRet, 'fee');
[20069]289        // 支払方法
290        $col = 'payment_id';
291        $where = 'deliv_id = ? ORDER BY rank';
292        $table = 'dtb_payment_options';
293        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
294        $arrPaymentIds = array();
295        foreach ($arrRet as $val) {
296            $arrPaymentIds[] = $val['payment_id'];
297        }
[20307]298        $objFormParam->setValue('payment_ids', $arrPaymentIds);
[15297]299    }
300
301    /* 入力内容のチェック */
[20307]302    function lfCheckError(&$objFormParam) {
[15297]303        // 入力データを渡す。
[20307]304        $arrRet =  $objFormParam->getHashArray();
[20503]305        $objErr = new SC_CheckError_Ex($arrRet);
[20307]306        $objErr->arrErr = $objFormParam->checkError();
[15297]307
[21531]308        if (!isset($objErr->arrErr['name'])) {
[21552]309            // 既存チェック
310            $objDb = new SC_Helper_DB_Ex();
311            if ($arrRet['deliv_id'] == '') {
312                $ret = $objDb->sfIsRecord('dtb_deliv', 'service_name', array($arrRet['service_name']));
313            } else {
[21750]314                $objQuery =& SC_Query_Ex::getSingletonInstance();
[21563]315                $ret = (($objQuery->count('dtb_deliv', 'deliv_id != ? AND service_name = ? ', array($arrRet['deliv_id'], $arrRet['service_name'])) > 0)? true : false);
[21552]316            }
317            if ($ret) {
318                $objErr->arrErr['service_name'] = '※ 同じ名称の組み合わせは登録できません。<br>';
319            }
[15297]320        }
321
322        return $objErr->arrErr;
323    }
324}
Note: See TracBrowser for help on using the repository browser.