source: branches/comu-ver2/data/class/pages/admin/LC_Page_Admin_Home.php @ 17353

Revision 17353, 9.9 KB checked in by Seasoft, 16 years ago (diff)

サイト情報(サイトURLとバージョン)の強制送信を任意設定に変更。

  • 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-2007 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        $conn = new SC_DBConn();
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        // OSバージョンの取得
72        $this->os_version = php_uname('s') . ' ' . php_uname('r');
73
74        // 現在の会員数
75        $this->customer_cnt = $this->lfGetCustomerCnt($conn);
76
77        // 昨日の売上高
78        $this->order_yesterday_amount = $this->lfGetOrderYesterday($conn, "SUM");
79
80        // 昨日の売上件数
81        $this->order_yesterday_cnt = $this->lfGetOrderYesterday($conn, "COUNT");
82
83        // 今月の売上高
84        $this->order_month_amount = $this->lfGetOrderMonth($conn, "SUM");
85
86        // 今月の売上件数
87        $this->order_month_cnt = $this->lfGetOrderMonth($conn, "COUNT");
88
89        // 顧客の累計ポイント
90        $this->customer_point = $this->lfGetTotalCustomerPoint();
91
92        //昨日のレビュー書き込み数
93        $this->review_yesterday_cnt = $this->lfGetReviewYesterday($conn);
94
95        //レビュー書き込み非表示数
96        $this->review_nondisp_cnt = $this->lfGetReviewNonDisp($conn);
97
98        // 品切れ商品
99        $this->arrSoldout = $this->lfGetSoldOut();
100
101        // 新規受付一覧
102        $arrNewOrder = $this->lfGetNewOrder();
103
104        foreach ($arrNewOrder as $key => $val){
105            $arrNewOrder[$key]['create_date'] = str_replace("-", "/", substr($val['create_date'], 0,19));
106
107        }
108        $this->arrNewOrder = $arrNewOrder;
109
110        // お知らせ一覧の取得
111        $this->arrInfo = $this->lfGetInfo();
112
113        $objView->assignobj($this);
114        $objView->display(MAIN_FRAME);
115    }
116
117    /**
118     * デストラクタ.
119     *
120     * @return void
121     */
122    function destroy() {
123        parent::destroy();
124    }
125
126    // 会員数
127    function lfGetCustomerCnt($conn){
128
129        $sql = "SELECT COUNT(customer_id) FROM dtb_customer WHERE del_flg = 0 AND status = 2";
130        $return = $conn->getOne($sql);
131        return $return;
132    }
133
134    // 昨日の売上高・売上件数
135    function lfGetOrderYesterday($conn, $method){
136        if ( $method == 'SUM' or $method == 'COUNT'){
137            // postgresql と mysql とでSQLをわける
138            if (DB_TYPE == "pgsql") {
139                $sql = "SELECT ".$method."(total) FROM dtb_order
140                         WHERE del_flg = 0 AND to_char(create_date,'YYYY/MM/DD') = to_char(now() - interval '1 days','YYYY/MM/DD') AND status <> " . ORDER_CANCEL;
141            }else if (DB_TYPE == "mysql") {
142                $sql = "SELECT ".$method."(total) FROM dtb_order
143                         WHERE del_flg = 0 AND cast(create_date as date) = DATE_ADD(current_date, interval -1 day) AND status <> " . ORDER_CANCEL;
144            }
145            $return = $conn->getOne($sql);
146        }
147        return $return;
148    }
149
150    function lfGetOrderMonth($conn, $method){
151
152        $month = date("Y/m", mktime());
153
154        if ( $method == 'SUM' or $method == 'COUNT'){
155        // postgresql と mysql とでSQLをわける
156        if (DB_TYPE == "pgsql") {
157            $sql = "SELECT ".$method."(total) FROM dtb_order
158                     WHERE del_flg = 0 AND to_char(create_date,'YYYY/MM') = ?
159                     AND to_char(create_date,'YYYY/MM/DD') <> to_char(now(),'YYYY/MM/DD') AND status <> " . ORDER_CANCEL;
160        }else if (DB_TYPE == "mysql") {
161            $sql = "SELECT ".$method."(total) FROM dtb_order
162                     WHERE del_flg = 0 AND date_format(create_date, '%Y/%m') = ?
163                     AND date_format(create_date, '%Y/%m/%d') <> date_format(now(), '%Y/%m/%d') AND status <> " . ORDER_CANCEL;
164        }
165            $return = $conn->getOne($sql, array($month));
166        }
167        return $return;
168    }
169
170    function lfGetTotalCustomerPoint() {
171        $objQuery = new SC_Query();
172        $col = "SUM(point)";
173        $where = "del_flg = 0";
174        $from = "dtb_customer";
175        $ret = $objQuery->get($from, $col, $where);
176        return $ret;
177    }
178
179    function lfGetReviewYesterday($conn){
180        // postgresql と mysql とでSQLをわける
181        if (DB_TYPE == "pgsql") {
182            $sql = "SELECT COUNT(*) FROM dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id
183                     WHERE A.del_flg=0 AND B.del_flg = 0 AND to_char(A.create_date, 'YYYY/MM/DD') = to_char(now() - interval '1 days','YYYY/MM/DD')
184                     AND to_char(A.create_date,'YYYY/MM/DD') != to_char(now(),'YYYY/MM/DD')";
185        }else if (DB_TYPE == "mysql") {
186            $sql = "SELECT COUNT(*) FROM dtb_review AS A LEFT JOIN dtb_products AS B ON A.product_id = B.product_id
187                     WHERE A.del_flg = 0 AND B.del_flg = 0 AND cast(A.create_date as date) = DATE_ADD(current_date, interval -1 day)
188                     AND cast(A.create_date as date) != current_date";
189        }
190        $return = $conn->getOne($sql);
191        return $return;
192    }
193
194    function lfGetReviewNonDisp($conn){
195        $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";
196        $return = $conn->getOne($sql);
197        return $return;
198    }
199
200    // 品切れ商品番号の取得
201    function lfGetSoldOut() {
202        $objQuery = new SC_Query();
203        $where = "product_id IN (SELECT product_id FROM dtb_products_class WHERE stock_unlimited IS NULL AND stock <= 0)";
204        $arrRet = $objQuery->select("product_id, name", "dtb_products", $where);
205        return $arrRet;
206    }
207
208    // 新規受付一覧
209    function lfGetNewOrder() {
210        $objQuery = new SC_Query();
211        $sql = "SELECT
212                    ord.order_id,
213                    ord.customer_id,
214                    ord.order_name01 AS name01,
215                    ord.order_name02 AS name02,
216                    ord.total,
217                    ord.create_date,
218                    (SELECT
219                        det.product_name
220                    FROM
221                        dtb_order_detail AS det
222                    WHERE
223                        ord.order_id = det.order_id LIMIT 1
224                    ) AS product_name,
225                    (SELECT
226                        pay.payment_method
227                    FROM
228                        dtb_payment AS pay
229                    WHERE
230                        ord.payment_id = pay.payment_id
231                    ) AS payment_method
232                FROM (
233                    SELECT
234                        order_id,
235                        customer_id,
236                        order_name01,
237                        order_name02,
238                        total,
239                        create_date,
240                        payment_id
241                    FROM
242                        dtb_order AS ord
243                    WHERE
244                        del_flg = 0 AND status <> " . ORDER_CANCEL . "
245                    ORDER BY
246                        create_date DESC LIMIT 10 OFFSET 0
247                ) AS ord";
248        $arrRet = $objQuery->getAll($sql);
249        return $arrRet;
250    }
251
252    /**
253     * リリース情報を取得する.
254     *
255     * @return unknown
256     */
257    function lfGetInfo() {
258
259        // パラメータ「UPDATE_HTTP」が空文字の場合、処理しない。
260        // XXX これと別に on/off を持たせるべきか。
261        if (strlen(UPDATE_HTTP) == 0) return array();
262
263        $query = '';
264        // サイト情報の送信可否設定
265        // XXX インストール時に問い合わせて送信可否設定を行うように設定すべきか。
266        // XXX (URLは強制送信すべきではないと思うが)バージョンは強制送信すべきか。
267        if (UPDATE_SEND_SITE_INFO === true) {
268            $query = '?site_url=' . SITE_URL . '&eccube_version=' . ECCUBE_VERSION;
269        }
270
271        $url = UPDATE_HTTP . $query;
272        $jsonStr = @file_get_contents($url);
273
274        $objJson = new Services_JSON;
275        $arrTmpData = is_string($jsonStr) ? $objJson->decode($jsonStr) : null;
276
277        if (empty($arrTmpData)) {
278            SC_Utils_Ex::sfErrorHeader(">> 更新情報の取得に失敗しました。");
279            return array();
280        }
281
282        $arrInfo = array();
283        foreach ($arrTmpData as $objData) {
284            $arrInfo[] = get_object_vars($objData);
285        }
286
287        return $arrInfo;
288    }
289}
290?>
Note: See TracBrowser for help on using the repository browser.