source: branches/version-2_13_0/data/class/pages/admin/LC_Page_Admin_Home.php @ 23126

Revision 23126, 9.8 KB checked in by m_uehara, 11 years ago (diff)

#2348 r23116 - r23125 をマージ

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