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

Revision 20434, 9.9 KB checked in by nanasess, 13 years ago (diff)

#803(JSON モジュールの統一及び高速化)

  • 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
Line 
1
2<?php
3/*
4 * This file is part of EC-CUBE
5 *
6 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
7 *
8 * http://www.lockon.co.jp/
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 */
24
25// {{{ requires
26require_once CLASS_EX_REALDIR . "page_extends/admin/LC_Page_Admin_Ex.php";
27require_once DATA_REALDIR . '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_Admin_Ex {
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        $this->tpl_subtitle = 'ホーム';
50    }
51
52    /**
53     * Page のプロセス.
54     *
55     * @return void
56     */
57    function process() {
58        $this->action();
59        $this->sendResponse();
60    }
61
62    /**
63     * Page のアクション.
64     *
65     * @return void
66     */
67    function action() {
68
69        // DBバージョンの取得
70        $this->db_version = $this->lfGetDBVersion();
71
72        // PHPバージョンの取得
73        $this->php_version = $this->lfGetPHPVersion();
74
75        // 現在の会員数
76        $this->customer_cnt = $this->lfGetCustomerCnt();
77
78        // 昨日の売上高
79        $this->order_yesterday_amount = $this->lfGetOrderYesterday("SUM");
80
81        // 昨日の売上件数
82        $this->order_yesterday_cnt = $this->lfGetOrderYesterday("COUNT");
83
84        // 今月の売上高
85        $this->order_month_amount = $this->lfGetOrderMonth("SUM");
86
87        // 今月の売上件数
88        $this->order_month_cnt = $this->lfGetOrderMonth("COUNT");
89
90        // 顧客の累計ポイント
91        $this->customer_point = $this->lfGetTotalCustomerPoint();
92
93        //昨日のレビュー書き込み数
94        $this->review_yesterday_cnt = $this->lfGetReviewYesterday();
95
96        //レビュー書き込み非表示数
97        $this->review_nondisp_cnt = $this->lfGetReviewNonDisp();
98
99        // 品切れ商品
100        $this->arrSoldout = $this->lfGetSoldOut();
101
102        // 新規受付一覧
103        $this->arrNewOrder = $this->lfGetNewOrder();
104
105        // お知らせ一覧の取得
106        $this->arrInfo = $this->lfGetInfo();
107    }
108
109    /**
110     * デストラクタ.
111     *
112     * @return void
113     */
114    function destroy() {
115        parent::destroy();
116    }
117
118    /**
119     * PHPバージョンの取得
120     *
121     * @return string PHPバージョン情報
122     */
123    function lfGetPHPVersion() {
124        return "PHP " . phpversion();
125    }
126   
127    /**
128     * DBバージョンの取得
129     *
130     * @return mixed DBバージョン情報
131     */
132    function lfGetDBVersion() {
133        $objDb = new SC_Helper_DB_Ex();
134        return $objDb->sfGetDBVersion();
135    }
136
137    /**
138     * 現在の会員数の取得
139     *
140     * @return integer 会員数
141     */
142    function lfGetCustomerCnt(){
143        $objQuery =& SC_Query::getSingletonInstance();
144        $col = "COUNT(customer_id)";
145        $table = "dtb_customer";
146        $where = "del_flg = 0 AND status = 2";
147        return $objQuery->get($col, $table, $where);
148    }
149
150    /**
151     * 昨日の売上データの取得
152     *
153     * @param string $method 取得タイプ 件数:"COUNT" or 金額:"SUM"
154     * @return integer 結果数値
155     */
156    function lfGetOrderYesterday($method){
157        $objQuery =& SC_Query::getSingletonInstance();
158       
159        // TODO: DBFactory使わないでも共通化できそうな気もしますが
160        $dbFactory = SC_DB_DBFactory::getInstance();
161        $sql = $dbFactory->getOrderYesterdaySql($method);
162        return $objQuery->getOne($sql);
163    }
164
165    /**
166     * 今月の売上データの取得
167     *
168     * @param string $method 取得タイプ 件数:"COUNT" or 金額:"SUM"
169     * @return integer 結果数値
170     */
171    function lfGetOrderMonth($method){
172        $objQuery =& SC_Query::getSingletonInstance();
173        $month = date("Y/m", mktime());
174       
175        // TODO: DBFactory使わないでも共通化できそうな気もしますが
176        $dbFactory = SC_DB_DBFactory::getInstance();
177        $sql = $dbFactory->getOrderMonthSql($method);
178        return $objQuery->getOne($sql, array($month));
179    }
180
181    /**
182     * 顧客の保持ポイント合計の取得
183     *
184     * @return integer 顧客の保持ポイント合計
185     */
186    function lfGetTotalCustomerPoint() {
187        $objQuery =& SC_Query::getSingletonInstance();
188       
189        $col = "SUM(point)";
190        $where = "del_flg = 0";
191        $from = "dtb_customer";
192        return $objQuery->get($col, $from, $where);
193    }
194
195    /**
196     * 昨日のレビュー書き込み数の取得
197     *
198     * @return integer 昨日のレビュー書き込み数
199     */
200    function lfGetReviewYesterday(){
201        $objQuery =& SC_Query::getSingletonInstance();
202
203        // TODO: DBFactory使わないでも共通化できそうな気もしますが
204        $dbFactory = SC_DB_DBFactory::getInstance();
205        $sql = $dbFactory->getReviewYesterdaySql();
206        return $objQuery->getOne($sql);
207    }
208
209    /**
210     * レビュー書き込み非表示数の取得
211     *
212     * @return integer レビュー書き込み非表示数
213     */
214    function lfGetReviewNonDisp(){
215        $objQuery =& SC_Query::getSingletonInstance();
216       
217        $table = "dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id";
218        $where = "A.del_flg = 0 AND A.status = 2 AND B.del_flg = 0";
219        return $objQuery->count($table, $where);
220    }
221
222    /**
223     * 品切れ商品の取得
224     *
225     * @return array 品切れ商品一覧
226     */
227    function lfGetSoldOut() {
228        $objQuery =& SC_Query::getSingletonInstance();
229       
230        $cols = "product_id, name";
231        $table = "dtb_products";
232        $where = "product_id IN ("
233                  . "SELECT product_id FROM dtb_products_class "
234                  . "WHERE stock_unlimited = ? AND stock <= 0)";
235        return $objQuery->select($cols, $table, $where, array(UNLIMITED_FLG_LIMITED));
236    }
237
238    /**
239     * 新規受付一覧の取得
240     *
241     * @return array 新規受付一覧配列
242     */
243    function lfGetNewOrder() {
244        $objQuery =& SC_Query::getSingletonInstance();
245       
246        $sql = "SELECT
247                    ord.order_id,
248                    ord.customer_id,
249                    ord.order_name01 AS name01,
250                    ord.order_name02 AS name02,
251                    ord.total,
252                    ord.create_date,
253                    (SELECT
254                        det.product_name
255                    FROM
256                        dtb_order_detail AS det
257                    WHERE
258                        ord.order_id = det.order_id LIMIT 1
259                    ) AS product_name,
260                    (SELECT
261                        pay.payment_method
262                    FROM
263                        dtb_payment AS pay
264                    WHERE
265                        ord.payment_id = pay.payment_id
266                    ) AS payment_method
267                FROM (
268                    SELECT
269                        order_id,
270                        customer_id,
271                        order_name01,
272                        order_name02,
273                        total,
274                        create_date,
275                        payment_id
276                    FROM
277                        dtb_order AS ord
278                    WHERE
279                        del_flg = 0 AND status <> " . ORDER_CANCEL . "
280                    ORDER BY
281                        create_date DESC LIMIT 10 OFFSET 0
282                ) AS ord";
283        $arrNewOrder = $objQuery->getAll($sql);
284        foreach ($arrNewOrder as $key => $val){
285            $arrNewOrder[$key]['create_date'] = str_replace("-", "/", substr($val['create_date'], 0,19));
286
287        }
288        return $arrNewOrder;
289    }
290
291    /**
292     * リリース情報を取得する.
293     *
294     * @return array 取得した情報配列
295     */
296    function lfGetInfo() {
297        // 更新情報の取得ON/OFF確認
298        if (!ECCUBE_INFO) return array();
299
300        // パラメータ「UPDATE_HTTP」が空文字の場合、処理しない。
301        // XXX これと別に on/off を持たせるべきか。
302        if (strlen(UPDATE_HTTP) == 0) return array();
303
304        $query = '';
305        // サイト情報の送信可否設定
306        // XXX インストール時に問い合わせて送信可否設定を行うように設定すべきか。
307        // XXX (URLは強制送信すべきではないと思うが)バージョンは強制送信すべきか。
308        if (UPDATE_SEND_SITE_INFO === true) {
309            $query = '?site_url=' . HTTP_URL . '&eccube_version=' . ECCUBE_VERSION;
310        }
311
312        $url = UPDATE_HTTP . $query;
313
314        // タイムアウト時間設定
315        $context = array('http' => array('timeout' => HTTP_REQUEST_TIMEOUT));
316       
317        $jsonStr = @file_get_contents($url, false, stream_context_create($context));
318
319        $arrTmpData = is_string($jsonStr) ? SC_Utils_Ex::jsonDecode($jsonStr) : null;
320
321        if (empty($arrTmpData)) {
322            SC_Utils_Ex::sfErrorHeader(">> 更新情報の取得に失敗しました。");
323            return array();
324        }
325        $arrInfo = array();
326        foreach ($arrTmpData as $objData) {
327            $arrInfo[] = get_object_vars($objData);
328        }
329        return $arrInfo;
330    }
331}
332?>
Note: See TracBrowser for help on using the repository browser.