source: branches/version-2_5-dev/data/class/pages/admin/customer/LC_Page_Admin_Customer.php @ 19661

Revision 19661, 22.6 KB checked in by nanasess, 13 years ago (diff)

source:branches/camp/camp-2_5-E のマージ

  • スマートフォン対応(#787)
  • プラグイン機能(#494)
  • Property svn:eol-style set to LF
  • Property svn:keywords set to "Id Revision Date"
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
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
25require_once(CLASS_PATH . "pages/admin/LC_Page_Admin.php");
26
27/**
28 * 顧客管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Customer extends LC_Page_Admin {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'customer/index.tpl';
47        $this->tpl_mainno = 'customer';
48        $this->tpl_subnavi = 'customer/subnavi.tpl';
49        $this->tpl_subno = 'index';
50        $this->tpl_pager = TEMPLATE_DIR . 'admin/pager.tpl';
51        $this->tpl_subtitle = '顧客マスタ';
52
53        $masterData = new SC_DB_MasterData_Ex();
54        $this->arrPref = $masterData->getMasterData("mtb_pref",
55                             array("pref_id", "pref_name", "rank"));
56
57        $this->arrJob = $masterData->getMasterData("mtb_job");
58        $this->arrJob["不明"] = "不明";
59        $this->arrSex = $masterData->getMasterData("mtb_sex");
60        $this->arrPageRows = $masterData->getMasterData("mtb_page_rows");
61        $this->arrMAILMAGATYPE = $masterData->getMasterData("mtb_mail_magazine_type");
62        $this->arrHtmlmail[''] = "すべて";
63        $this->arrHtmlmail[1] = $this->arrMAILMAGATYPE[1];
64        $this->arrHtmlmail[2] = $this->arrMAILMAGATYPE[2];
65
66        $this->arrStatus[1] = "仮会員";
67        $this->arrStatus[2] = "本会員";
68
69        //---- CSVダウンロード用
70        $this->arrColumnCSV = array(
71            array(
72                "sql" => "customer_id",
73                "csv" => "customer_id",
74                "header" => "顧客ID"
75            ),
76            array(
77                "sql" => "name01",
78                "csv" => "name01",
79                "header" => "名前1"
80            ),
81            array(
82                "sql" => "name02",
83                "csv" => "name02",
84                "header" => "名前2"
85            ),
86            array(
87                "sql" => "kana01",
88                "csv" => "kana01",
89                "header" => "お名前(フリガナ・姓)"
90            ),
91            array(
92                "sql" => "kana02",
93                "csv" => "kana02",
94                "header" => "お名前(フリガナ・名)"
95            ),
96            array(
97                "sql" => "zip01",
98                "csv" => "zip01",
99                "header" => "郵便番号1"
100            ),
101            array(
102                "sql" => "zip02",
103                "csv" => "zip02",
104                "header" => "郵便番号2"
105            ),
106            array(
107                "sql" => "pref",
108                "csv" => "pref",
109                "header" => "都道府県"
110            ),
111            array(
112                "sql" => "addr01",
113                "csv" => "addr01",
114                "header" => "住所1"
115            ),
116            array(
117                "sql" => "addr02",
118                "csv" => "addr02",
119                "header" => "住所2"
120            ),
121            array(
122                "sql" => "email",
123                "csv" => "email",
124                "header" => "E-MAIL"
125            ),
126            array(
127                "sql" => "tel01",
128                "csv" => "tel01",
129                "header" => "TEL1"
130            ),
131            array(
132                "sql" => "tel02",
133                "csv" => "tel02",
134                "header" => "TEL2"
135            ),
136            array(
137                "sql" => "tel03",
138                "csv" => "tel03",
139                "header" => "TEL3"
140            ),
141            array(
142                "sql" => "fax01",
143                "csv" => "fax01",
144                "header" => "FAX1"
145            ),
146            array(
147                "sql" => "fax02",
148                "csv" => "fax02",
149                "header" => "FAX2"
150            ),
151            array(
152                "sql" => "fax03",
153                "csv" => "fax03",
154                "header" => "FAX3"
155            ),
156            array(
157                "sql" => "CASE WHEN sex = 1 THEN '男性' ELSE '女性' END AS sex",
158                "csv" => "sex",
159                "header" => "性別"
160            ),
161            array(
162                "sql" => "job",
163                "csv" => "job",
164                "header" => "職業"
165            ),
166            array(
167                "sql" => "cast(birth as date) AS birth",
168                "csv" => "birth",
169                "header" => "誕生日"
170            ),
171            array(
172                "sql" => "cast(first_buy_date as date) AS first_buy_date",
173                "csv" => "first_buy_date",
174                "header" => "初回購入日"
175            ),
176            array(
177                "sql" => "cast(last_buy_date as date) AS last_buy_date",
178                "csv" => "last_buy_date",
179                "header" => "最終購入日"
180            ),
181            array(
182                "sql" => "buy_times",
183                "csv" => "buy_times",
184                "header" => "購入回数"
185            ),
186            array(
187                "sql" => "point",
188                "csv" => "point",
189                "header" => "ポイント残高"
190            ),
191            array(
192                "sql" => "note",
193                "csv" => "note",
194                "header" => "備考"
195            ),
196            array(
197                "sql" => "cast(create_date as date) AS create_date",
198                "csv" => "create_date",
199                "header" => "登録日"
200            ),
201            array(
202                "sql" => "cast(update_date as date) AS update_date",
203                "csv" => "update_date",
204                "header" => "更新日"
205            ),
206        );
207        $this->httpCacheControl('nocache');
208    }
209
210    /**
211     * Page のプロセス.
212     *
213     * @return void
214     */
215    function process() {
216        $this->action();
217        $this->sendResponse();
218    }
219
220    /**
221     * Page のアクション.
222     *
223     * @return void
224     */
225    function action() {
226        //---- ページ初期設定
227        $objQuery = new SC_Query();
228        $objView = new SC_AdminView();
229        $objDate = new SC_Date(1901);
230        $objDb = new SC_Helper_DB_Ex();
231        $this->arrYear = $objDate->getYear();   // 日付プルダウン設定
232        $this->arrMonth = $objDate->getMonth();
233        $this->arrDay = $objDate->getDay();
234        $this->objDate = $objDate;
235
236        // 認証可否の判定
237        $objSess = new SC_Session();
238        SC_Utils_Ex::sfIsSuccess($objSess);
239
240        // POST値の引き継ぎ
241        $this->arrForm = $_POST;
242
243        // ページ送り用
244        $this->arrHidden['search_pageno'] =
245                isset($_POST['search_pageno']) ? $_POST['search_pageno'] : "";
246
247        // 検索ワードの引き継ぎ
248        foreach ($_POST as $key => $val) {
249            switch($key) {
250            case 'sex':
251            case 'status':
252                $this->arrHidden[$key] = SC_Utils_Ex::sfMergeParamCheckBoxes($val);
253                if(!is_array($val)) {
254                    $this->arrForm[$key] = split("-", $val);
255                }
256                break;
257            default:
258                $this->arrHidden[$key] = $val;
259                break;
260            }
261        }
262
263        if (!isset($_POST['mode'])) $_POST['mode'] = "";
264
265        // 顧客削除
266        if ($_POST['mode'] == "delete") {
267            $sql = "SELECT status,email FROM dtb_customer WHERE customer_id = ? AND del_flg = 0";
268            $result_customer = $objQuery->getAll($sql, array($_POST["edit_customer_id"]));
269
270            if ($result_customer[0]["status"] == 2) {           //本会員削除
271                $arrDel = array("del_flg" => 1, "update_date" => "NOW()");
272                $objQuery->conn->autoExecute("dtb_customer", $arrDel, "customer_id = " . SC_Utils_Ex::sfQuoteSmart($_POST["edit_customer_id"]) );
273            } elseif ($result_customer[0]["status"] == 1) {     //仮会員削除
274                $sql = "DELETE FROM dtb_customer WHERE customer_id = ?";
275                $objQuery->query($sql, array($_POST["edit_customer_id"]));
276            }
277        }
278        // 登録メール再送
279        if ($_POST['mode'] == "resend_mail") {
280            $arrRet = $objQuery->select("name01, name02, secret_key, email, email_mobile", "dtb_customer","customer_id = ? AND del_flg <> 1 AND status = 1", array($_POST["edit_customer_id"]));
281            if( is_array($arrRet) === true && count($arrRet) > 0 ){
282
283                $this->name01 = $arrRet[0]['name01'];
284                $this->name02 = $arrRet[0]['name02'];
285                $this->uniqid = $arrRet[0]['secret_key'];
286
287                $CONF = $objDb->sf_getBasisData();
288                $this->CONF = $CONF;
289                /**
290                 * 携帯メールアドレスが登録されていれば携帯サイトから仮会員登録したものと判定する。
291                 * TODO: とりあえずの簡易的な判定なので、将来的には判定ルーチンを修正した方が良い。
292                 */
293                if (!empty($arrRet[0]['email_mobile'])) {
294                    $objMailText = new SC_MobileView(false);
295                    $this->to_name01 = $arrRet[0]['name01'];
296                    $this->to_name02 = $arrRet[0]['name02'];
297                } else {
298                    $objMailText = new SC_SiteView(false);
299                }
300                $objMailText->assignobj($this);
301                $mailHelper = new SC_Helper_Mail_Ex();
302
303                $subject = $mailHelper->sfMakesubject('会員登録のご確認');
304                $toCustomerMail = $objMailText->fetch("mail_templates/customer_mail.tpl");
305
306                $objMail = new SC_SendMail();
307                $objMail->setItem(
308                                    ''                  // 宛先
309                                    , $subject          // サブジェクト
310                                    , $toCustomerMail   // 本文
311                                    , $CONF["email03"]  // 配送元アドレス
312                                    , $CONF["shop_name"]// 配送元 名前
313                                    , $CONF["email03"]  // reply_to
314                                    , $CONF["email04"]  // return_path
315                                    , $CONF["email04"]  //  Errors_to
316                                 );
317                // 宛先の設定
318                $name = $this->name01 . $this->name02 ." 様";
319                $objMail->setTo($arrRet[0]["email"], $name);
320                $objMail->sendMail();
321            }
322
323        }
324
325        if ($_POST['mode'] == "search" || $_POST['mode'] == "csv"  || $_POST['mode'] == "delete" || $_POST['mode'] == "delete_all" || $_POST['mode'] == "resend_mail") {
326
327            // 入力文字の強制変換
328            $this->lfConvertParam();
329            // エラーチェック
330            $this->arrErr = $this->lfCheckError($this->arrForm);
331
332            $where = "del_flg = 0";
333
334            /* 入力エラーなし */
335            if (count($this->arrErr) == 0) {
336
337                //-- 検索データ取得
338                $objSelect = new SC_CustomerList($this->arrForm, "customer");
339
340                // 表示件数設定
341                $page_rows = $this->arrForm['page_rows'];
342                if(is_numeric($page_rows)) {
343                    $page_max = $page_rows;
344                } else {
345                    $page_max = SEARCH_PMAX;
346                }
347
348                if (!isset($this->arrForm['search_pageno'])) $this->arrForm['search_pageno'] = "";
349
350                if ($this->arrForm['search_pageno'] == 0){
351                    $this->arrForm['search_pageno'] = 1;
352                }
353
354                $offset = $page_max * ($this->arrForm['search_pageno'] - 1);
355                $objSelect->setLimitOffset($page_max, $offset);
356
357                if ($_POST["mode"] == 'csv') {
358                    $searchSql = $objSelect->getListCSV($this->arrColumnCSV);
359                }else{
360                    $searchSql = $objSelect->getList();
361                }
362
363                $this->search_data = $objQuery->getAll($searchSql, $objSelect->arrVal);
364
365                switch($_POST['mode']) {
366                case 'csv':
367                    require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_CSV_Ex.php");
368
369                    $objCSV = new SC_Helper_CSV_Ex();
370                    $i = 0;
371                    $header = "";
372
373                    // CSVカラム取得
374                    $arrCsvOutput = ($objCSV->sfgetCsvOutput(2, 'status = 1'));
375
376                    if (count($arrCsvOutput) <= 0) break;
377
378                    foreach($arrCsvOutput as $data) {
379                        $arrColumn[] = $data["col"];
380                        if ($i != 0) $header .= ", ";
381                        $header .= $data["disp_name"];
382                        $i ++;
383                    }
384                    $header .= "\n";
385
386                    //- 都道府県/職業の変換
387                    for($i = 0; $i < count($this->search_data); $i ++) {
388                        $this->search_data[$i]["pref"] = $this->arrPref[ $this->search_data[$i]["pref"] ];
389                        $this->search_data[$i]["job"]  = $this->arrJob[ $this->search_data[$i]["job"] ];
390                    }
391
392                    //- CSV出力
393                    $data = SC_Utils_Ex::getCSVData($this->search_data, $arrColumn);
394
395
396                    // CSVを送信する。
397                    list($fime_name, $data) = SC_Utils_Ex::sfGetCSVData($head.$data);
398                    $this->sendResponseCSV($fime_name, $data);
399                    exit;
400                    break;
401                case 'delete_all':
402                    // 検索結果をすべて削除
403                    $where = "product_id IN (SELECT product_id FROM SC_Product::alldtlSQL() WHERE $where)";
404                    $sqlval['del_flg'] = 1;
405                    $objQuery->update("dtb_products", $sqlval, $where, $arrval);
406
407                    $sql = "SELECT status,email FROM dtb_customer WHERE customer_id = ? AND del_flg = 0";
408                    $result_customer = $objQuery->getAll($sql, array($_POST["del_customer_id"]));
409
410                    if ($result_customer[0]["status"] == 2) {           //本会員削除
411                        $arrDel = array("del_flg" => 1, "update_date" => "NOW()");
412                        $objQuery->conn->autoExecute("dtb_customer", $arrDel, "customer_id = " . SC_Utils_Ex::sfQuoteSmart($_POST["del_customer_id"]) );
413                    } elseif ($result_customer[0]["status"] == 1) {     //仮会員削除
414                        $sql = "DELETE FROM dtb_customer WHERE customer_id = ?";
415                        $objQuery->query($sql, array($_POST["del_customer_id"]));
416                    }
417
418                    break;
419                default:
420
421                    // 行数の取得
422                    $linemax = $objQuery->getOne( $objSelect->getListCount(), $objSelect->arrVal);
423                    $this->tpl_linemax = $linemax;              // 何件が該当しました。表示用
424
425                    // ページ送りの取得
426                    $objNavi = new SC_PageNavi($this->arrHidden['search_pageno'],
427                                               $linemax, $page_max,
428                                               "fnCustomerPage", NAVI_PMAX);
429                    $startno = $objNavi->start_row;
430                    $this->arrPagenavi = $objNavi->arrPagenavi;
431                }
432            }
433        }
434
435        $this->arrCatList = $objDb->sfGetCategoryList();
436    }
437
438    /**
439     * デストラクタ.
440     *
441     * @return void
442     */
443    function destroy() {
444        parent::destroy();
445    }
446
447    //---- 取得文字列の変換
448    function lfConvertParam() {
449        /*
450         *  文字列の変換
451         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
452         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
453         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
454         *  n :  「全角」数字を「半角(ハンカク)」に変換
455         *  a :  全角英数字を半角英数字に変換する
456         */
457        // カラム名とコンバート情報
458        $arrConvList['customer_id'] = "n" ;
459        $arrConvList['name'] = "aKV" ;
460        $arrConvList['pref'] = "n" ;
461        $arrConvList['kana'] = "CKV" ;
462        $arrConvList['b_start_year'] = "n" ;
463        $arrConvList['b_start_month'] = "n" ;
464        $arrConvList['b_start_day'] = "n" ;
465        $arrConvList['b_end_year'] = "n" ;
466        $arrConvList['b_end_month'] = "n" ;
467        $arrConvList['b_end_day'] = "n" ;
468        $arrConvList['tel'] = "n" ;
469        $arrConvList['birth_month'] = "n" ;
470        $arrConvList['email'] = "a" ;
471        $arrConvList['buy_total_from'] = "n" ;
472        $arrConvList['buy_total_to'] = "n" ;
473        $arrConvList['buy_times_from'] = "n" ;
474        $arrConvList['buy_times_to'] = "n" ;
475        $arrConvList['start_year'] = "n" ;
476        $arrConvList['start_month'] = "n" ;
477        $arrConvList['start_day'] = "n" ;
478        $arrConvList['end_year'] = "n" ;
479        $arrConvList['end_month'] = "n" ;
480        $arrConvList['end_day'] = "n" ;
481        $arrConvList['page_rows'] = "n" ;
482        $arrConvList['buy_start_year'] = "n" ;      // 最終購入日 START 年
483        $arrConvList['buy_start_month'] = "n" ;     // 最終購入日 START 月
484        $arrConvList['buy_start_day'] = "n" ;       // 最終購入日 START 日
485        $arrConvList['buy_end_year'] = "n" ;            // 最終購入日 END 年
486        $arrConvList['buy_end_month'] = "n" ;       // 最終購入日 END 月
487        $arrConvList['buy_end_day'] = "n" ;         // 最終購入日 END 日
488        $arrConvList['buy_product_name'] = "aKV" ;  // 購入商品名
489        $arrConvList['buy_product_code'] = "aKV" ;  // 購入商品コード
490        $arrConvList['category_id'] = "" ;          // カテゴリ
491
492        // 文字変換
493        foreach ($arrConvList as $key => $val) {
494            // POSTされてきた値のみ変換する。
495            if(isset($this->arrForm[$key])) {
496                $this->arrForm[$key] = mb_convert_kana($this->arrForm[$key] ,$val);
497            }
498        }
499    }
500
501    //---- 入力エラーチェック
502    function lfCheckError($array) {
503
504        $objErr = new SC_CheckError($array);
505
506        $objErr->doFunc(array("顧客コード", "customer_id", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
507        $objErr->doFunc(array("都道府県", "pref", 2), array("NUM_CHECK","MAX_LENGTH_CHECK"));
508        $objErr->doFunc(array("顧客名", "name", STEXT_LEN), array("MAX_LENGTH_CHECK"));
509        $objErr->doFunc(array("顧客名(カナ)", "kana", STEXT_LEN), array("SPTAB_CHECK" ,"MAX_LENGTH_CHECK", "KANABLANK_CHECK"));
510        $objErr->doFunc(array("誕生日(開始日)", "b_start_year", "b_start_month", "b_start_day"), array("CHECK_DATE"));
511        $objErr->doFunc(array("誕生日(終了日)", "b_end_year", "b_end_month", "b_end_day"), array("CHECK_DATE"));
512        $objErr->doFunc(array("誕生日(開始日)","誕生日(終了日)", "b_start_year", "b_start_month", "b_start_day", "b_end_year", "b_end_month", "b_end_day"), array("CHECK_SET_TERM"));
513        $objErr->doFunc(array("誕生月", "birth_month", 2), array("NUM_CHECK","MAX_LENGTH_CHECK"));
514        $objErr->doFunc(array('メールアドレス', "email", STEXT_LEN) ,array("EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
515        $objErr->doFunc(array('携帯メールアドレス', "email_mobile", STEXT_LEN) ,array("EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
516        $objErr->doFunc(array("電話番号", "tel", TEL_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
517        $objErr->doFunc(array("購入金額(開始)", "buy_total_from", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
518        $objErr->doFunc(array("購入金額(終了)", "buy_total_to", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
519        if ( (is_numeric($array["buy_total_from"]) && is_numeric($array["buy_total_to"]) ) && ($array["buy_total_from"] > $array["buy_total_to"]) ) $objErr->arrErr["buy_total_from"] .= "※ 購入金額の指定範囲が不正です。";
520        $objErr->doFunc(array("購入回数(開始)", "buy_times_from", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
521        $objErr->doFunc(array("購入回数(終了)", "buy_times_to", INT_LEN), array("NUM_CHECK","MAX_LENGTH_CHECK"));
522        if ( (is_numeric($array["buy_times_from"]) && is_numeric($array["buy_times_to"]) ) && ($array["buy_times_from"] > $array["buy_times_to"]) ) $objErr->arrErr["buy_times_from"] .= "※ 購入回数の指定範囲が不正です。";
523        $objErr->doFunc(array("登録・更新日(開始日)", "start_year", "start_month", "start_day",), array("CHECK_DATE"));
524        $objErr->doFunc(array("登録・更新日(終了日)", "end_year", "end_month", "end_day"), array("CHECK_DATE"));
525        $objErr->doFunc(array("登録・更新日(開始日)","登録・更新日(終了日)", "start_year", "start_month", "start_day", "end_year", "end_month", "end_day"), array("CHECK_SET_TERM"));
526        $objErr->doFunc(array("表示件数", "page_rows", 3), array("NUM_CHECK","MAX_LENGTH_CHECK"));
527        $objErr->doFunc(array("最終購入日(開始日)", "buy_start_year", "buy_start_month", "buy_start_day",), array("CHECK_DATE"));   //最終購入日(開始日)
528        $objErr->doFunc(array("最終購入(終了日)", "buy_end_year", "buy_end_month", "buy_end_day"), array("CHECK_DATE"));            //最終購入日(終了日)
529        //購入金額(from) > 購入金額(to) の場合はエラーとする
530        $objErr->doFunc(array("最終購入日(開始日)","登録・更新日(終了日)", "buy_start_year", "buy_start_month", "buy_start_day", "buy_end_year", "buy_end_month", "buy_end_day"), array("CHECK_SET_TERM"));
531        $objErr->doFunc(array("購入商品コード", "buy_product_code", STEXT_LEN), array("MAX_LENGTH_CHECK"));                     //購入商品コード
532        $objErr->doFunc(array("購入商品名", "buy_product_name", STEXT_LEN), array("MAX_LENGTH_CHECK"));                         //購入商品名称
533
534        return $objErr->arrErr;
535    }
536}
537?>
Note: See TracBrowser for help on using the repository browser.