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