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

Revision 20134, 10.0 KB checked in by AMUAMU, 13 years ago (diff)

#961 (リファクタリング [管理画面]ログイン/ホーム) ホーム画面の修正。
#674 (サイト情報の送信を任意に設定できるように) の実装。

  • 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_REALDIR . "pages/admin/LC_Page_Admin.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 {
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        // 認証可否の判定
70        SC_Utils_Ex::sfIsSuccess(new SC_Session());
71
72        // DBバージョンの取得
73        $this->db_version = $this->lfGetDBVersion();
74
75        // PHPバージョンの取得
76        $this->php_version = $this->lfGetPHPVersion();
77
78        // 現在の会員数
79        $this->customer_cnt = $this->lfGetCustomerCnt();
80
81        // 昨日の売上高
82        $this->order_yesterday_amount = $this->lfGetOrderYesterday("SUM");
83
84        // 昨日の売上件数
85        $this->order_yesterday_cnt = $this->lfGetOrderYesterday("COUNT");
86
87        // 今月の売上高
88        $this->order_month_amount = $this->lfGetOrderMonth("SUM");
89
90        // 今月の売上件数
91        $this->order_month_cnt = $this->lfGetOrderMonth("COUNT");
92
93        // 顧客の累計ポイント
94        $this->customer_point = $this->lfGetTotalCustomerPoint();
95
96        //昨日のレビュー書き込み数
97        $this->review_yesterday_cnt = $this->lfGetReviewYesterday();
98
99        //レビュー書き込み非表示数
100        $this->review_nondisp_cnt = $this->lfGetReviewNonDisp();
101
102        // 品切れ商品
103        $this->arrSoldout = $this->lfGetSoldOut();
104
105        // 新規受付一覧
106        $this->arrNewOrder = $this->lfGetNewOrder();
107
108        // お知らせ一覧の取得
109        $this->arrInfo = $this->lfGetInfo();
110    }
111
112    /**
113     * デストラクタ.
114     *
115     * @return void
116     */
117    function destroy() {
118        parent::destroy();
119    }
120
121    /**
122     * PHPバージョンの取得
123     *
124     * @return string PHPバージョン情報
125     */
126    function lfGetPHPVersion() {
127        return "PHP " . phpversion();
128    }
129   
130    /**
131     * DBバージョンの取得
132     *
133     * @return mixed DBバージョン情報
134     */
135    function lfGetDBVersion() {
136        $objDb = new SC_Helper_DB_Ex();
137        return $objDb->sfGetDBVersion();
138    }
139
140    /**
141     * 現在の会員数の取得
142     *
143     * @return integer 会員数
144     */
145    function lfGetCustomerCnt(){
146        $objQuery =& SC_Query::getSingletonInstance();
147        $col = "COUNT(customer_id)";
148        $table = "dtb_customer";
149        $where = "del_flg = 0 AND status = 2";
150        return $objQuery->get($col, $table, $where);
151    }
152
153    /**
154     * 昨日の売上データの取得
155     *
156     * @param string $method 取得タイプ 件数:"COUNT" or 金額:"SUM"
157     * @return integer 結果数値
158     */
159    function lfGetOrderYesterday($method){
160        $objQuery =& SC_Query::getSingletonInstance();
161       
162        // TODO: DBFactory使わないでも共通化できそうな気もしますが
163        $dbFactory = SC_DB_DBFactory::getInstance();
164        $sql = $dbFactory->getOrderYesterdaySql($method);
165        return $objQuery->getOne($sql);
166    }
167
168    /**
169     * 今月の売上データの取得
170     *
171     * @param string $method 取得タイプ 件数:"COUNT" or 金額:"SUM"
172     * @return integer 結果数値
173     */
174    function lfGetOrderMonth($method){
175        $objQuery =& SC_Query::getSingletonInstance();
176        $month = date("Y/m", mktime());
177       
178        // TODO: DBFactory使わないでも共通化できそうな気もしますが
179        $dbFactory = SC_DB_DBFactory::getInstance();
180        $sql = $dbFactory->getOrderMonthSql($method);
181        return $objQuery->getOne($sql, array($month));
182    }
183
184    /**
185     * 顧客の保持ポイント合計の取得
186     *
187     * @return integer 顧客の保持ポイント合計
188     */
189    function lfGetTotalCustomerPoint() {
190        $objQuery =& SC_Query::getSingletonInstance();
191       
192        $col = "SUM(point)";
193        $where = "del_flg = 0";
194        $from = "dtb_customer";
195        return $objQuery->get($col, $from, $where);
196    }
197
198    /**
199     * 昨日のレビュー書き込み数の取得
200     *
201     * @return integer 昨日のレビュー書き込み数
202     */
203    function lfGetReviewYesterday(){
204        $objQuery =& SC_Query::getSingletonInstance();
205
206        // TODO: DBFactory使わないでも共通化できそうな気もしますが
207        $dbFactory = SC_DB_DBFactory::getInstance();
208        $sql = $dbFactory->getReviewYesterdaySql();
209        return $objQuery->getOne($sql);
210    }
211
212    /**
213     * レビュー書き込み非表示数の取得
214     *
215     * @return integer レビュー書き込み非表示数
216     */
217    function lfGetReviewNonDisp(){
218        $objQuery =& SC_Query::getSingletonInstance();
219       
220        $table = "dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id";
221        $where = "A.del_flg = 0 AND A.status = 2 AND B.del_flg = 0";
222        return $objQuery->count($table, $where);
223    }
224
225    /**
226     * 品切れ商品の取得
227     *
228     * @return array 品切れ商品一覧
229     */
230    function lfGetSoldOut() {
231        $objQuery =& SC_Query::getSingletonInstance();
232       
233        $cols = "product_id, name";
234        $table = "dtb_products";
235        $where = "product_id IN ("
236                  . "SELECT product_id FROM dtb_products_class "
237                  . "WHERE stock_unlimited = ? AND stock <= 0)";
238        return $objQuery->select($cols, $table, $where, array(UNLIMITED_FLG_LIMITED));
239    }
240
241    /**
242     * 新規受付一覧の取得
243     *
244     * @return array 新規受付一覧配列
245     */
246    function lfGetNewOrder() {
247        $objQuery =& SC_Query::getSingletonInstance();
248       
249        $sql = "SELECT
250                    ord.order_id,
251                    ord.customer_id,
252                    ord.order_name01 AS name01,
253                    ord.order_name02 AS name02,
254                    ord.total,
255                    ord.create_date,
256                    (SELECT
257                        det.product_name
258                    FROM
259                        dtb_order_detail AS det
260                    WHERE
261                        ord.order_id = det.order_id LIMIT 1
262                    ) AS product_name,
263                    (SELECT
264                        pay.payment_method
265                    FROM
266                        dtb_payment AS pay
267                    WHERE
268                        ord.payment_id = pay.payment_id
269                    ) AS payment_method
270                FROM (
271                    SELECT
272                        order_id,
273                        customer_id,
274                        order_name01,
275                        order_name02,
276                        total,
277                        create_date,
278                        payment_id
279                    FROM
280                        dtb_order AS ord
281                    WHERE
282                        del_flg = 0 AND status <> " . ORDER_CANCEL . "
283                    ORDER BY
284                        create_date DESC LIMIT 10 OFFSET 0
285                ) AS ord";
286        $arrNewOrder = $objQuery->getAll($sql);
287        foreach ($arrNewOrder as $key => $val){
288            $arrNewOrder[$key]['create_date'] = str_replace("-", "/", substr($val['create_date'], 0,19));
289
290        }
291        return $arrNewOrder;
292    }
293
294    /**
295     * リリース情報を取得する.
296     *
297     * @return array 取得した情報配列
298     */
299    function lfGetInfo() {
300        // 更新情報の取得ON/OFF確認
301        if (!ECCUBE_INFO) return array();
302
303        // パラメータ「UPDATE_HTTP」が空文字の場合、処理しない。
304        // XXX これと別に on/off を持たせるべきか。
305        if (strlen(UPDATE_HTTP) == 0) return array();
306
307        $query = '';
308        // サイト情報の送信可否設定
309        // XXX インストール時に問い合わせて送信可否設定を行うように設定すべきか。
310        // XXX (URLは強制送信すべきではないと思うが)バージョンは強制送信すべきか。
311        if (UPDATE_SEND_SITE_INFO === true) {
312            $query = '?site_url=' . HTTP_URL . '&eccube_version=' . ECCUBE_VERSION;
313        }
314
315        $url = UPDATE_HTTP . $query;
316
317        // タイムアウト時間設定
318        $context = array('http' => array('timeout' => HTTP_REQUEST_TIMEOUT));
319       
320        $jsonStr = @file_get_contents($url, false, stream_context_create($context));
321
322        $objJson = new Services_JSON;
323        $arrTmpData = is_string($jsonStr) ? $objJson->decode($jsonStr) : null;
324
325        if (empty($arrTmpData)) {
326            SC_Utils_Ex::sfErrorHeader(">> 更新情報の取得に失敗しました。");
327            return array();
328        }
329        $arrInfo = array();
330        foreach ($arrTmpData as $objData) {
331            $arrInfo[] = get_object_vars($objData);
332        }
333        return $arrInfo;
334    }
335}
336?>
Note: See TracBrowser for help on using the repository browser.