source: branches/version-2_5-dev/data/class/pages/admin/LC_Page_Admin_Home.php @ 18789

Revision 18789, 8.1 KB checked in by nanasess, 14 years ago (diff)

DB_TYPE で条件分岐している箇所の抽象化(#801)

  • DB_TYPE で条件分岐している箇所の修正
  • SC_DB_DBFactory に関数を追加
    • getOrderYesterdaySql()
    • getOrderMonthSql()
    • getReviewYesterdaySql()
    • getSendHistoryWhereStartdateSql()
    • concatColumn()
  • SC_Utils::sfManualEscape() の実装を SC_Query::quote() に変更
  • 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/LC_Page.php";
26require_once DATA_PATH . 'module/Services/JSON.php';
27require_once DATA_PATH . 'module/Request.php';
28
29/**
30 * 管理画面ホーム のページクラス.
31 *
32 * @package Page
33 * @author LOCKON CO.,LTD.
34 * @version $Id$
35 */
36class LC_Page_Admin_Home extends LC_Page {
37
38    // }}}
39    // {{{ functions
40
41    /**
42     * Page を初期化する.
43     *
44     * @return void
45     */
46    function init() {
47        parent::init();
48        $this->tpl_mainpage = 'home.tpl';
49    }
50
51    /**
52     * Page のプロセス.
53     *
54     * @return void
55     */
56    function process() {
57        $objQuery = new SC_Query();
58        $objView = new SC_AdminView();
59        $objSess = new SC_Session();
60
61        // 認証可否の判定
62        SC_Utils_Ex::sfIsSuccess($objSess);
63
64        // DBバージョンの取得
65        $objDb = new SC_Helper_DB_Ex();
66        $this->db_version = $objDb->sfGetDBVersion();
67
68        // PHPバージョンの取得
69        $this->php_version = "PHP " . phpversion();
70
71        // 現在の会員数
72        $this->customer_cnt = $this->lfGetCustomerCnt($objQuery);
73
74        // 昨日の売上高
75        $this->order_yesterday_amount = $this->lfGetOrderYesterday($objQuery, "SUM");
76
77        // 昨日の売上件数
78        $this->order_yesterday_cnt = $this->lfGetOrderYesterday($objQuery, "COUNT");
79
80        // 今月の売上高
81        $this->order_month_amount = $this->lfGetOrderMonth($objQuery, "SUM");
82
83        // 今月の売上件数
84        $this->order_month_cnt = $this->lfGetOrderMonth($objQuery, "COUNT");
85
86        // 顧客の累計ポイント
87        $this->customer_point = $this->lfGetTotalCustomerPoint();
88
89        //昨日のレビュー書き込み数
90        $this->review_yesterday_cnt = $this->lfGetReviewYesterday($objQuery);
91
92        //レビュー書き込み非表示数
93        $this->review_nondisp_cnt = $this->lfGetReviewNonDisp($objQuery);
94
95        // 品切れ商品
96        $this->arrSoldout = $this->lfGetSoldOut();
97
98        // 新規受付一覧
99        $arrNewOrder = $this->lfGetNewOrder();
100
101        foreach ($arrNewOrder as $key => $val){
102            $arrNewOrder[$key]['create_date'] = str_replace("-", "/", substr($val['create_date'], 0,19));
103
104        }
105        $this->arrNewOrder = $arrNewOrder;
106
107        // お知らせ一覧の取得
108        $this->arrInfo = $this->lfGetInfo();
109
110        $objView->assignobj($this);
111        $objView->display(MAIN_FRAME);
112    }
113
114    /**
115     * デストラクタ.
116     *
117     * @return void
118     */
119    function destroy() {
120        parent::destroy();
121    }
122
123    // 会員数
124    function lfGetCustomerCnt(&$objQuery){
125
126        $sql = "SELECT COUNT(customer_id) FROM dtb_customer WHERE del_flg = 0 AND status = 2";
127        $return = $objQuery->getOne($sql);
128        return $return;
129    }
130
131    // 昨日の売上高・売上件数
132    function lfGetOrderYesterday(&$objQuery, $method){
133        if ( $method == 'SUM' or $method == 'COUNT'){
134            $dbFactory = SC_DB_DBFactory::getInstance();
135            $sql = $dbFactory->getOrderYesterdaySql($method);
136            $return = $objQuery->getOne($sql);
137        }
138        return $return;
139    }
140
141    function lfGetOrderMonth(&$objQuery, $method){
142
143        $month = date("Y/m", mktime());
144
145        if ( $method == 'SUM' or $method == 'COUNT'){
146            $dbFactory = SC_DB_DBFactory::getInstance();
147            $sql = $dbFactory->getOrderMonthSql($method);
148            $return = $objQuery->getOne($sql, array($month));
149        }
150        return $return;
151    }
152
153    function lfGetTotalCustomerPoint() {
154        $objQuery = new SC_Query();
155        $col = "SUM(point)";
156        $where = "del_flg = 0";
157        $from = "dtb_customer";
158        $ret = $objQuery->get($from, $col, $where);
159        return $ret;
160    }
161
162    function lfGetReviewYesterday(&$objQuery){
163        $dbFactory = SC_DB_DBFactory::getInstance();
164        $sql = $dbFactory->getReviewYesterdaySql();
165        $return = $objQuery->getOne($sql);
166        return $return;
167    }
168
169    function lfGetReviewNonDisp(&$objQuery){
170        $sql = "SELECT COUNT(*) FROM dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id WHERE A.del_flg=0 AND A.status=2 AND B.del_flg=0";
171        $return = $objQuery->getOne($sql);
172        return $return;
173    }
174
175    // 品切れ商品IDの取得
176    function lfGetSoldOut() {
177        $objQuery = new SC_Query();
178        $where = "product_id IN (SELECT product_id FROM dtb_products_class WHERE stock_unlimited = 0 AND stock <= 0)";
179        $arrRet = $objQuery->select("product_id, name", "dtb_products", $where);
180        return $arrRet;
181    }
182
183    // 新規受付一覧
184    function lfGetNewOrder() {
185        $objQuery = new SC_Query();
186        $sql = "SELECT
187                    ord.order_id,
188                    ord.customer_id,
189                    ord.order_name01 AS name01,
190                    ord.order_name02 AS name02,
191                    ord.total,
192                    ord.create_date,
193                    (SELECT
194                        det.product_name
195                    FROM
196                        dtb_order_detail AS det
197                    WHERE
198                        ord.order_id = det.order_id LIMIT 1
199                    ) AS product_name,
200                    (SELECT
201                        pay.payment_method
202                    FROM
203                        dtb_payment AS pay
204                    WHERE
205                        ord.payment_id = pay.payment_id
206                    ) AS payment_method
207                FROM (
208                    SELECT
209                        order_id,
210                        customer_id,
211                        order_name01,
212                        order_name02,
213                        total,
214                        create_date,
215                        payment_id
216                    FROM
217                        dtb_order AS ord
218                    WHERE
219                        del_flg = 0 AND status <> " . ORDER_CANCEL . "
220                    ORDER BY
221                        create_date DESC LIMIT 10 OFFSET 0
222                ) AS ord";
223        $arrRet = $objQuery->getAll($sql);
224        return $arrRet;
225    }
226
227    /**
228     * リリース情報を取得する.
229     *
230     * @return unknown
231     */
232    function lfGetInfo() {
233
234        // パラメータ「UPDATE_HTTP」が空文字の場合、処理しない。
235        // XXX これと別に on/off を持たせるべきか。
236        if (strlen(UPDATE_HTTP) == 0) return array();
237
238        $query = '';
239        // サイト情報の送信可否設定
240        // XXX インストール時に問い合わせて送信可否設定を行うように設定すべきか。
241        // XXX (URLは強制送信すべきではないと思うが)バージョンは強制送信すべきか。
242        if (UPDATE_SEND_SITE_INFO === true) {
243            $query = '?site_url=' . SITE_URL . '&eccube_version=' . ECCUBE_VERSION;
244        }
245
246        $url = UPDATE_HTTP . $query;
247        $jsonStr = @file_get_contents($url);
248
249        $objJson = new Services_JSON;
250        $arrTmpData = is_string($jsonStr) ? $objJson->decode($jsonStr) : null;
251
252        if (empty($arrTmpData)) {
253            SC_Utils_Ex::sfErrorHeader(">> 更新情報の取得に失敗しました。");
254            return array();
255        }
256
257        $arrInfo = array();
258        foreach ($arrTmpData as $objData) {
259            $arrInfo[] = get_object_vars($objData);
260        }
261
262        return $arrInfo;
263    }
264}
265?>
Note: See TracBrowser for help on using the repository browser.